BigBoot / AutoKuma

AutoKuma is a utility that automates the creation of Uptime Kuma monitors based on Docker container labels. With AutoKuma, you can eliminate the need for manual monitor creation in the Uptime Kuma UI.
MIT License
312 stars 15 forks source link

Before Kuma adds the monitors, how to add a notification? #48

Closed 0neTX closed 6 months ago

0neTX commented 6 months ago

Hi,

Thanks for this useful project.

I am deploying uptime-kuma and autokuma using docker compose and static monitor definition. When I start docker compose, I notice an error when adding the monitors because the notification configuration does not exist.

This is the log:

 ✔ Container uptimekuma-autokuma-1  Created                                                                                                                                                                                                                                                                                                                                                                                                    0.0s 
Attaching to autokuma-1
autokuma-1  |
autokuma-1  |                 .:::.                                      .:::.
autokuma-1  |               .===-====:                                :-===--==:
autokuma-1  |              .==.    .:==-.        ..........         :==-.    .==:
autokuma-1  |              -=-        :===--====================---==:        -==
autokuma-1  |              -=-          :===-..              ..:===-          :==
autokuma-1  |              -=-            ::                    .-.           -==
autokuma-1  |              :==                                                ==-
autokuma-1  |               ==.                                              .==.
autokuma-1  |              :==-                                              -==-
autokuma-1  |             .====.                                             ====-
autokuma-1  |             ==-                                                  .==:
autokuma-1  |            :==                                                    ===
autokuma-1  |            -==                                                    -==
autokuma-1  |            -==                                                    :==
autokuma-1  |            -==               ..        ...       ..               -==
autokuma-1  |            .==.             :===     -=====.    ====              ==-
autokuma-1  |             ===              .:.   :==-  :==-    ::              :==.
autokuma-1  |             .==:                  :==:    .==-                  .==:
autokuma-1  |              .==.                :==:      .==-                .==-
autokuma-1  |               .==:              .==:        .==:              .==:
autokuma-1  |                .==-             ==-          :==             :==:
autokuma-1  |                 .-==:          :==            -=-          .-==.
autokuma-1  |                   .===.        ==.   .::::..   ==.       .-==:
autokuma-1  |                     :===.     :=-  ==========. :==     .-==:
autokuma-1  |                       .===:   ==.  -=========  .==.  .-==:
autokuma-1  |                         .-==-:==    .======:    ==-:===:
autokuma-1  |                            :-===:      ...     .====:.
autokuma-1  |                               :==-.          .-==:
autokuma-1  |                                 :====---:--====:
autokuma-1  |                                    .::----::.
autokuma-1  |                             _           _  __
autokuma-1  |               /\           | |         | |/ /
autokuma-1  |              /  \    _   _ | |_   ___  | ' /  _   _  _ __ ___    __ _
autokuma-1  |             / /\ \  | | | || __| / _ \ |  <  | | | || '_ ` _ \  / _` |
autokuma-1  |            / ____ \ | |_| || |_ | (_) || . \ | |_| || | | | | || (_| |
autokuma-1  |           /_/    \_\ \__,_| \__| \___/ |_|\_\ \__,_||_| |_| |_| \__,_|
autokuma-1  |                                                                 v0.6.0
autokuma-1  | INFO [autokuma::sync] Creating new monitor: webtop
autokuma-1  | INFO [autokuma::sync] Creating new monitor: adguard
autokuma-1  | WARN [autokuma::sync] Encountered error during sync: Server responded with an error: insert into `monitor_notification` (`monitor_id`, `notification_id`) values (2, '1') - SQLITE_CONSTRAINT: FOREIGN KEY constraint failed
autokuma-1  | INFO [autokuma::sync] Creating new monitor: mydomain-xyz
autokuma-1  | WARN [autokuma::sync] Encountered error during sync: Server responded with an error: insert into `monitor_notification` (`monitor_id`, `notification_id`) values (3, '1') - SQLITE_CONSTRAINT: FOREIGN KEY constraint failed
autokuma-1  | INFO [autokuma::sync] Creating new monitor: photo-mydomain-xyz
autokuma-1  | WARN [autokuma::sync] Encountered error during sync: Server responded with an error: insert into `monitor_notification` (`monitor_id`, `notification_id`) values (4, '1') - SQLITE_CONSTRAINT: FOREIGN KEY constraint failed
autokuma-1  | INFO [autokuma::sync] Creating new monitor: fritzbox
autokuma-1  | WARN [autokuma::sync] Encountered error during sync: Server responded with an error: insert into `monitor_notification` (`monitor_id`, `notification_id`) values (5, '1') - SQLITE_CONSTRAINT: FOREIGN KEY constraint failed
autokuma-1  | INFO [autokuma::sync] Creating new monitor: photo-mydomain-xyz
autokuma-1  | WARN [autokuma::sync] Encountered error during sync: Server responded with an error: insert into `monitor_notification` (`monitor_id`, `notification_id`) values (6, '1') - SQLITE_CONSTRAINT: FOREIGN KEY constraint failed

This is the docker compose:

services:
  uptime-kuma:
    image: louislam/uptime-kuma:1
    container_name: uptime-kuma
    networks:
      uptime-kuma:
        aliases:
          - kuma    
    volumes:
      - ./uptime-kuma-data:/app/data
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - 3001:3001  
    restart: always

  autokuma:
    image: ghcr.io/bigboot/autokuma:latest
    restart: no
    networks:
      uptime-kuma:    
    environment:
      AUTOKUMA__KUMA__URL: http://kuma:3001
      AUTOKUMA__SYNC_INTERVAL: 15
      AUTOKUMA__KUMA__CALL_TIMEOUT: 20

      AUTOKUMA__STATIC_MONITORS: /var/monitors
      AUTOKUMA__KUMA__USERNAME: redacted
      AUTOKUMA__KUMA__PASSWORD: redacted
      AUTOKUMA__DOCKER__SOCKET: /var/run/docker.sock
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./monitors:/var/monitors

networks:
  uptime-kuma:

This is the notification configuration: notification.json

{
    "id": 1,
    "type": "notification",
    "name": "UptimeKuma Alert",
    "active": true,
    "userId": 1,
    "isDefault": true,
    "config": {
        "applyExisting": true,
        "isDefault": true,
        "name": "UptimeKuma Alert",
        "telegramBotToken": "redacted token",
        "telegramChatID": redacted chatid number,
        "telegramProtectContent": true,
        "type": "telegram"
    }
}

How can I add the notification settings before creating the monitors?

Another problem I noticed is that the container adds all the static monitors defined in a loop. In other words, it continuously creates new monitors.

This is an example of a static monitor config:

{
    "type": "http",
    "name": "mydomain.zyz",
    "interval": 60,
    "active": true,
    "maxretries": 3,
    "retryInterval": 30,
    "upsideDown": false,
    "notificationIDList": {
        "1": true
    },
    "accepted_statuscodes": [
        "200-299"
    ],
    "url": "https://www.mydomain.zyz/",
    "timeout": 48,
    "resendInterval": 0,
    "expiryNotification": true,
    "ignoreTls": false,
    "maxredirects": 10,
    "method": "GET",
    "httpBodyEncoding": "json"
}

Best Regards

BigBoot commented 6 months ago

Hi,

How can I add the notification settings before creating the monitors?

You will have to manually create the notification either using the webui or kuma CLI, unfortunately with the current approach of autokuma it's not possible to add notifications.

Another problem I noticed is that the container adds all the static monitors defined in a loop. In other words, it continuously creates new monitors.

I can't really do much here, uptime kuma partially creates the monitor but then retuns an error... maybe I could mark "failed" monitors and exclude them in future syncs, but then ephemeral errors would result in monitors never being created...

0neTX commented 6 months ago

Thanks so much for your help

I resolved it using kuma-cli as you suggest me, but I haven't found a docker image that has "kuma-cli" . I had to create it manually by compiling the Docker-cli file.

BigBoot commented 6 months ago

Oh btw the cli image is named just kuma

0neTX commented 6 months ago

Sorry, this url https://github.com/BigBoot/AutoKuma/pkgs/container/kuma doesn't work for me.

Also I tryed to pull the docker image:

docker pull ghcr.io/bigboot/kuma
Using default tag: latest
Error response from daemon: Head "https://ghcr.io/v2/bigboot/kuma/manifests/latest": unauthorized

I couldn't found the url for the kuma image.

BigBoot commented 6 months ago

Oh looks like you need to set every package to public individually, good to know. Should be public now :sweat_smile:

0neTX commented 6 months ago

It's working. I`ll try to use this image for the init configuration. Thanks so much for your help.

docker pull ghcr.io/bigboot/kuma
Using default tag: latest
latest: Pulling from bigboot/kuma
b0a0cf830b12: Already exists
f50fd9a1035a: Pull complete
5ab036799866: Pull complete
Digest: sha256:ec67d62b3b7de1ca2d1fec673a1053e27ce5679a23b4efcfc6e6003f906e69f9
Status: Downloaded newer image for ghcr.io/bigboot/kuma:latest
ghcr.io/bigboot/kuma:latest