I am looking for a way to easily define one-time notifications of some events that take place on a Linux box. Events might include things like: file /tmp/my.lock is unlinked
or process 666 finished
or, maybe, something more complicated, like process 'backup.sh' closed file 'backup.tgz' AND process 'backup.sh' exited with return code 0
.
Notifications should be also flexible. Like, notify 192.168.0.100 via org.freedesktop.Notifications.Notify
or notify [email protected] via email
.
Actually, it's something like Nagios, but designed for non-repeating events, with minimal, almost zero cost of task creation. Am I a dreamer? Should I write it myself? Or should I simply use shell scripting?
Nagios can exactly notify the events just one time.
We use it to open tickets.
Just set notification_interval = 0 (for both service and host) and you'll get the email/sms just once.
Just to add some more input to the should I write it myself question, you could create either a FIFO or flat file to use as a custom log, and add commands to your custom scripts that write important output to that log file. Or alternatively, you could create a simple script that periodically checks the status of important files and processes, and sends its output to that log.
To create the FIFO on the server:
To read the logs from the server:
Source these functions into your custom scripts to easily write to the log:
And then write entries to the log by issuing these commands:
You can similarly add a shell function that uses
sendmail
(or similar) to mail you.I would think a combination of
inotifywatch
,ps
,logger
andsyslog
in some custom scripts might do the trick.