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
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:
Deployment: