The simples way you can do this is to use the check_procs sctipt that you can find in nagios-plugins package.
The following command will let you know if the python module 'app.py' is running.
/usr/lib/nagios/plugins/check_procs -c 1:1 -a app.py -C python
The -c
argument lets you set the critical range. 1:1
will trigger a critical status if there is more or less than 1 process that matches running.
The -a
argument will filter based on processes that contain the args 'app.py'
The -C
argument will make sure that the process is a python process
You can create a command definition to use the check across you nagios installation. Mine looks like this:
# 'check_single_proc' command definition
define command{
command_name check_single_proc
command_line /usr/lib/nagios/plugins/check_procs -C $ARG1$ -a $ARG2$ -c 1:1
}
Last thing is to create service definition.
define service {
use generic-service
host_name server_hostname
service_description app.py
check_command check_single_proc!python!app.py
}
And you are done.
REFERENCE: check_procs plugin manpage
http://nagiosplugins.org/man/check_procs