diff options
author | Gaspard d'Hautefeuille <github@dhautefeuille.eu> | 2020-06-22 20:19:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-22 20:19:36 +0100 |
commit | 4d032cf7982fc56d436cc89a1e089867668429bf (patch) | |
tree | 8b88254c387b42e4891a95bd906e45d17cfe928f /docs | |
parent | bf1aa0256edc2388acd90a8dce57b7ed9424d799 (diff) |
Add email action for space trigger critical
Diffstat (limited to 'docs')
-rw-r--r-- | docs/aoa/actions.rst | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/docs/aoa/actions.rst b/docs/aoa/actions.rst index b83f1737..d52ba2ab 100644 --- a/docs/aoa/actions.rst +++ b/docs/aoa/actions.rst @@ -25,10 +25,40 @@ reached: [fs] warning=70 warning_action=echo {{mnt_point}} {{used}}/{{size}} > /tmp/fs.alert + +A last example would be to create a log file +containing the total user disk space usage for a device and notify by email each time a space trigger critical is +reached: + +.. code-block:: ini + + [fs] + critical=90 + critical_action_repeat=echo {{device_name}} {{percent}} > /tmp/fs.alert && python /etc/glances/actions.d/fs-critical.py + +Within ``/etc/glances/actions.d/fs-critical.py``: + +.. code-block:: python + + import subprocess + from requests import get + + fs_alert = open('/tmp/fs.alert', 'r').readline().strip().split(' ') + device = fs_alert[0] + percent = fs_alert[1] + system = subprocess.check_output(['uname', '-rn']).decode('utf-8').strip() + ip = get('https://api.ipify.org').text + + body = 'Used user disk space for ' + device + ' is at ' + percent + '%.\nPlease cleanup the filesystem to clear the alert.\nServer: ' + str(system)+ '.\nIP address: ' + ip + ps = subprocess.Popen(('echo', '-e', body), stdout=subprocess.PIPE) + subprocess.call(['mail', '-s', 'CRITICAL: disk usage above 90%', '-r', 'postmaster@example.com', 'glances@example.com'], stdin=ps.stdout) + + + .. note:: You can use all the stats for the current plugin. See - https://github.com/nicolargo/glances/wiki/The-Glances-2.x-API-How-to + https://github.com/nicolargo/glances/wiki/The-Glances-RESTFULL-JSON-API for the stats list. It is also possible to repeat action until the end of the alert. |