This is a short example for a very simple event handler. In Nagios this is a little bit more complicated ;).
The example makes use of the check_multi feature to execute child checks sequently.
Simple, isn't it?
check_multi -f start_process.cmd -s PROC=<process> -s ARGS=<args>
The start_proc.cmd file is available in the check_multi package or here.
# # start_process.cmd # # (c) Matthias Flacke, 5.4.2008 # # starts process if not already started and checks result # # check_multi -f start_proc.cmd -s PROC=<process> -s ARGS=<args> # # 1. check for process command [ proc_before ] = check_procs -c 1: -C "$PROC$" -a "$ARGS$" # # 2. start process in background eeval [ start_proc ] = \ ( $STATE_proc_before$ != 0 ) \ ? ( system("$PROC$ $ARGS$ &") != 0 ) \ ? "- failed: $?" \ : "- done" \ : "- not necessary, already running" # # 3. check process again (ok, maybe redundant ;-)) command [ proc_after ] = check_procs -c 1: -C "$PROC$" -a "$ARGS$" # # 4. state evaluation state [ OK ] = proc_before == OK && proc_after == OK state [ WARNING ] = proc_before != OK && proc_after == OK state [ CRITICAL ] = start_proc =~/failed/ || proc_after == CRITICAL
nagios@thinkpad:~> check_multi -f etc/start_process.cmd -s PROC=nsca -s ARGS="-c /usr/local/nagios/etc/nsca.cfg" WARNING - 3 plugins checked, 1 critical (proc_before), 2 ok [ 1] proc_before PROCS CRITICAL: 0 processes with command name 'nsca', args '-c /usr/local/nagios/etc/nsca.cfg' [ 2] start_proc - done [ 3] proc_after PROCS OK: 1 process with command name 'nsca', args '-c /usr/local/nagios/etc/nsca.cfg'
nagios@thinkpad:~> check_multi -f etc/start_process.cmd -s PROC=nsca -s ARGS="-c /usr/local/nagios/etc/nsca.cfg" OK - 3 plugins checked, 3 ok [ 1] proc_before PROCS OK: 1 process with command name 'nsca', args '-c /usr/local/nagios/etc/nsca.cfg' [ 2] start_proc - not necessary, already running [ 3] proc_after PROCS OK: 1 process with command name 'nsca', args '-c /usr/local/nagios/etc/nsca.cfg'