Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to push many monitors at once #64

Open
hillout opened this issue Dec 5, 2023 · 3 comments
Open

Unable to push many monitors at once #64

hillout opened this issue Dec 5, 2023 · 3 comments

Comments

@hillout
Copy link

hillout commented Dec 5, 2023

Hi, thanks for your project.

I made a script which is creating many monitors at once, but max that I get is 6 successful, the rest of them which fails get reply with json: {"detail":"'version'"}, logs are saying: [7] [CRITICAL] 'version'. I tried to increase pauses to 30 sec between requests, but no luck.

Here is my script:

#!/bin/bash

UPTIME_USER="admin"
UPTIME_API_PASSWORD="admin"
UPTIME_URL="http://localhost:8000"
TOKEN_FILE=./token

# Putting the list of desired monitors
MONITOR_TYPE="ping"
project_id_array=(
    "server01.domain.org"
    "server02.domain.org"
    "server03.domain.org"
    "server04.domain.org"
    "server05.domain.org"
    "server06.domain.org"
    "server07.domain.org"
    "server08.domain.org"
)

# Check the file with token
if [ -f "${TOKEN_FILE}" ]; then
    # If exists, read from it
    TOKEN=$(cat "${TOKEN_FILE}")
else
    # If there is no file, get a new token..
    TOKEN=$(curl -s -L -X POST -H "Content-Type: application/x-www-form-urlencoded" \
        --data "username=${UPTIME_USER}&password=${UPTIME_API_PASSWORD}" \
        "${UPTIME_URL}/login/access-token" | jq -r '.access_token')

    # ..and save it to token file
    echo "${TOKEN}" > "${TOKEN_FILE}"
fi


# Cycle for adding monitors
for project_id in "${project_id_array[@]}"; do
    echo "Create monitor in Uptime Kuma for ${project_id}"

    RESULT=$(curl -s -X POST -H "Content-Type: application/json" \
        -H "Authorization: Bearer ${TOKEN}" \
        -d '{"name": "'${project_id}'",
            "pathName": "'${project_id}'",
            "hostname": "'${project_id}'",
            "maxretries": 3,
            "active": true,
            "forceInactive": false,
            "type": "'${MONITOR_TYPE}'",
            "timeout": 0,
            "interval": 60,
            "retryInterval": 60,
            "resendInterval": 0,
            "packetSize": 56
            }' \
        "${UPTIME_URL}/monitors")

    # Check if token is valid, if no - delete the token file and ask user to run the script again
    if [[ $RESULT == *"invalid credentials"* ]]; then
        echo "Invalid Credentials"
        rm -f "${TOKEN_FILE}"
        echo "Please run the script again"
        break
    fi

    # If token is OK, show monitor ID
    monitor_id=$(echo "$RESULT" | jq -r '.monitorID')
    echo "Monitor ID: ${monitor_id}"
# Making a pause between next requests
    sleep 3
done

Deployment:

version: "3.9"
services:
  kuma:
    container_name: uptime-kuma
    image: louislam/uptime-kuma:latest
    ports:
      - "3001:3001"
    restart: always
    volumes:
      - uptime-kuma:/app/data

  api:
    container_name: backend
    image: medaziz11/uptimekuma_restapi
    volumes:
      - api:/db
    restart: always
    environment:
      - KUMA_SERVER=http://uptime-kuma:3001
      - KUMA_USERNAME=admin
      - KUMA_PASSWORD=Cdewsxzaq2002
      - ADMIN_PASSWORD=admin
      - ACCESS_TOKEN_EXPIRATION=60
    depends_on:
      - kuma
    ports:
      - "8000:8000"
volumes:
  uptime-kuma:
  api:
@Morishiri
Copy link

I deployed older kuma version, then it works. Seems version in error message is a hint for incompatible API.

@hillout
Copy link
Author

hillout commented Dec 20, 2023

@Morishiri Hi, what exact version did you use?

@Morishiri
Copy link

@hillout I used 1.21.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants