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

Add action script on alert #132

Closed
nicolargo opened this issue Dec 1, 2012 · 12 comments
Closed

Add action script on alert #132

nicolargo opened this issue Dec 1, 2012 · 12 comments

Comments

@nicolargo
Copy link
Owner

Upon trigger (for exemple critical alert on free diskspace) a mail will be sent to a administrator.

@mxjeff
Copy link

mxjeff commented Jan 3, 2013

Better than the antique mail technology why don't you make it more general, more abstract. Launching a python script for isntance.

Then it allows users to send xmpp|mail messages, write a log, play sound, send sms etc… : )

cheers

@nicolargo
Copy link
Owner Author

Like your idea...

@rvrignaud
Copy link

@mxjeff : yes, I agree. It would be more convenient. Maybe we could add a Hubot (http://hubot.github.com/) plugin.

@jrenner
Copy link
Contributor

jrenner commented Mar 6, 2013

How would the python script be configured? For example, what if the user wants t choose to play a sound and send an sms, but no email?

@rvrignaud
Copy link

config file ?

@mxjeff
Copy link

mxjeff commented Mar 6, 2013

It could be as simple as string to give to subprocess.Popen(). Then one can write a script in plain shell, perl or python to perform whatever action is required.

Glances could set some env. var. to pass some info to the external process being call.
Another solution would be to set positional arguments within subprocess call :

subprocess.Popen([script_defined_in_conf, some, pos, arg])

I say, keep it simple and powerful enough for users to do whatever they want.

@jrenner
Copy link
Contributor

jrenner commented Mar 7, 2013

How about something like this?

import subprocess

commands = ["python custom_sendmail.py -addr test@example.com",
            "python make_an_alarm_noise.py",]

print "Something is wrong, run alarm commands"
for cmd in commands:
    formatted_cmd = cmd.split()
    print "Running: '%s'" % formatted_cmd
    subprocess.Popen(formatted_cmd)

@darionyaphet
Copy link

config file's path would be set at the programing init ?

@nicolargo
Copy link
Owner Author

As a bonus, you can also use stats values as {{mustache}} tag in the command line:

 [fs]
# Default limits for free filesytem space in %
# Default values if not defined: 50/70/90
careful=20
careful_action=echo {{mnt_point}} {{used}}/{{size}} > /tmp/fs.alert
warning=70
critical=90

@nicolargo
Copy link
Owner Author

Feature available on the develop branch (commit: 283af00).

Should be beta-tested with a maximum of case.

Feature documentation:

Glances can trigger actions on events.

By action, we mean all shell command line. For example, if you want to execute the foo.py script if the last 5 minutes load are critical then add the action line to the Glances configuration file:

[load]
critical=5.0
critical_action=python /path/to/foo.py

All the stats are usable in the command line by the use of the {{mustache}} syntax. Another example to create a log file containing used vs total disk space if a warning space trigger is reached:

[fs]
warning=70
warning_action=echo {{mnt_point}} {{used}}/{{size}} > /tmp/fs.alert

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 for the stats list)

How to install the develop branch: https://github.com/nicolargo/glances/wiki/Install-and-test-Glances-DEVELOP-version

@APalau82
Copy link

APalau82 commented Oct 11, 2017

Hi
I would like to cumulate an action with cron to be alerted when fs size is in warning status.
But while running glances with cron (* * * * * /usr/bin/glances) the {{mustaches}} values are not replaced by the real values. 'fs.alert' file litterally prints : "{{mnt_point}} {{used}}/{{size}}".
While running manually glances, the output is correct : / 1571274752/3102470144

By the way if glances starts automatically with cron does it mean that it never stops ?
Thanks

@PascalSalesch
Copy link

Is it available in master already?

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

No branches or pull requests

7 participants