glances icon indicating copy to clipboard operation
glances copied to clipboard

I could use a little bit of help setting an action for a gotify alert, almost there I think

Open Japhys opened this issue 7 months ago • 9 comments

I am using the docker version of Glances

Ihave this in my glances.conf

[sensors]
# Documentation: https://glances.readthedocs.io/en/latest/aoa/sensors.html
disable=False
# Set the refresh multiplicator for the sensors
# By default refresh every Glances refresh * 3 (increase to reduce CPU consumption)
#refresh=3
# Hide some sensors (comma separated list of regexp)
hide=unknown.*
# Show only the following sensors (comma separated list of regexp)
#show=CPU.*
# Sensors core thresholds (in Celsius...)
# By default values are grabbed from the system
# Overwrite thresholds for a specific sensor
#temperature_core_Ambient_careful=45
#temperature_core_Ambient_warning=65
#temperature_core_Ambient_critical=80
#temperature_core_Ambient_log=False
# Overwrite thresholds for a specific type of sensor
temperature_core_careful=45
temperature_core_warning=65
temperature_core_critical=88
temperature_core_critical_action=/srv/glances/actions.d/gotify_notify.sh
# Temperatures threshold in °C for hddtemp
# Default values if not defined: 45/52/60
#temperature_hdd_careful=45
#temperature_hdd_warning=52
#temperature_hdd_critical=60
# Battery threshold in %
# Default values if not defined: 70/80/90
#battery_careful=70
#battery_warning=80
#battery_critical=90
# Fan speed threshold in RPM
#fan_speed_careful=100
# Sensors alias
#alias=core 0:CPU Core 0,core 1:CPU Core 1

I have a folder action.d and within the folder: gotify_notify.sh with content for a simple example. I also made it executable

#!/bin/bash

# Variables
GOTIFY_URL="https://hl-gotify.example.com/message?token=xxxxxxxx"  
TITLE="Glances Alert"
MESSAGE="Temp above 88 celsius"

# Send notification
curl -X POST "$GOTIFY_URL" \
     -H "Content-Type: application/json" \
     -d "{\"title\":\"$TITLE\", \"message\":\"$MESSAGE\", \"priority\":5}"

The script itself works, I get the notification. But how do I make this work with Glances? What am I missing.

A bt of help would be very much appreciated

Japhys avatar May 15 '25 14:05 Japhys

Hi @Japhys

it should work...

Do you have any relevant information in the Glances log file ?

A log should be generated when an action is triggered, or if an error occurs.

nicolargo avatar May 16 '25 09:05 nicolargo

Hi @nicolargo

Thanks! That helped, but still not quite there. I did

sudo docker exec -it glances-glances-1 cat /tmp/glances-root.log

I see the actions are indeed triggered

2025-05-16 14:49:54,702 -- INFO -- Action triggered for sensors_temperature_core (careful): /srv/glances/actions.d/gotify_notify.sh
2025-05-16 14:49:54,703 -- ERROR -- Action error for sensors_temperature_core (careful): [Errno 2] No such file or directory: '/srv/glances/actions.d/gotify_notify.sh'
2025-05-16 14:50:25,092 -- INFO -- Action triggered for sensors_temperature_core (careful): /srv/glances/actions.d/gotify_notify.sh
2025-05-16 14:50:25,093 -- ERROR -- Action error for sensors_temperature_core (careful): [Errno 2] No such file or directory: '/srv/glances/actions.d/gotify_notify.sh'

The file does work on the host machine when I execute it

/srv/glances/actions.d/gotify_notify.sh

My docker file:

version: '3.8'

services:
  glances:
    image: nicolargo/glances:latest
    volumes:
      - /srv/glances:/etc/glances
      - /var/run/docker.sock:/var/run/docker.sock:ro
    environment:
      GLANCES_OPT: "-w"
    ports:
      - 61208:61208
    pid: host
    restart: unless-stopped
    networks:
      - homelab
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:61208"]
      interval: 30s
      timeout: 10s
      retries: 3

networks:
  homelab:
    external: true

I checked and the file was mapped correctly

$ sudo docker exec -it glances-glances-1 ls /etc/glances/actions.d
gotify_notify.sh

So why does it not find it? I think I should maybe use this in my conf file instead of referencing the host location?

temperature_core_careful_action=/bin/bash /etc/glances/actions.d/gotify_notify.sh

Checked in container, seems to be updated correctly

sudo docker exec -it glances-glances-1 cat /etc/glances/glances.conf

(Set this low to trigger a lot of actions)

# Overwrite thresholds for a specific type of sensor
temperature_core_careful=40
temperature_core_careful_action=/bin/bash /etc/glances/actions.d/gotify_notify.sh
temperature_core_warning=65
temperature_core_critical=88

However when I do this I still get the same error and the error still refers to /srv/glances/actions.d/gotify_notify.sh

Should this not be /etc/....?

2025-05-16 15:41:39,698 -- ERROR -- Action error for sensors_temperature_core (careful): [Errno 2] No such file or directory: '/srv/glances/actions.d/gotify_notify.sh'

I am a bit confused now :)

Japhys avatar May 16 '25 15:05 Japhys

In your Docker file you mount /srv/glances in /etc/glances. So you add to run the Glances action from /etc/glances/actions.d/gotify_notify.sh not /srv/glances/actions.d/gotify_notify.sh.

nicolargo avatar May 16 '25 16:05 nicolargo

Thanks I tried that because it made sense to me, that's why I was confused to still see this error in the log, after changing the conf file to /etc/glances/actions.d/gotify_notify.sh

2025-05-16 15:41:39,698 -- ERROR -- Action error for sensors_temperature_core (careful): [Errno 2] No such file or directory: '/srv/glances/actions.d/gotify_notify.sh'

Japhys avatar May 16 '25 16:05 Japhys

Nope you don't. Log message said that you try to run srv/glances/actions.d/gotify_notify.sh

nicolargo avatar May 16 '25 17:05 nicolargo

That's what I thought, I must be going mad. Maybe I am missing something, I apologize, still earning Docker

File on host Image

File in container. Image Image

Oke after restarting container once more I do see the right path, still an error though

Image

sudo docker exec -it glances-glances-1 ls /etc/glances/actions.d
gotify_notify.sh

Must be missing something really stupid

Japhys avatar May 16 '25 17:05 Japhys

Is this running o, when you run:

sudo docker exec -it glances-glances-1 /bin/bash /etc/glances/actions.d/gotify_notify.sh

?

nicolargo avatar May 18 '25 16:05 nicolargo

I am afraid not.

Japhys@Server:~$ sudo docker exec -it glances-glances-1 /bin/bash /etc/glances/actions.d/gotify_notify.sh
OCI runtime exec failed: exec failed: unable to start container process: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown
Japhys@Server:~$ sudo docker exec -it glances-glances-1 /etc/glances/actions.d/gotify_notify.sh
exec /etc/glances/actions.d/gotify_notify.sh: no such file or directory
bart@Server:~$ sudo docker exec -it glances-glances-1 ls /etc/glances/actions.d/
gotify_notify.sh
Japhys@Server:~$ sudo docker exec -it glances-glances-1 chmod +x /etc/glances/actions.d/gotify_notify.sh
Japhys@Server:~$ sudo docker exec -it glances-glances-1 /etc/glances/actions.d/gotify_notify.sh
exec /etc/glances/actions.d/gotify_notify.sh: no such file or directory

(I am going on a holiday, when I am back I will try to do this from scratch)

Japhys avatar May 20 '25 09:05 Japhys

This issue is stale because it has been open for 3 months with no activity.

github-actions[bot] avatar Aug 24 '25 02:08 github-actions[bot]