Docu review done: Fri 26 Jan 2024 04:39:17 PM CET

Table of content

Hints

Eventhandler

Service output

If you want to use the serivce output inside of an eventhandler, make sure that you don’t ( or ) in the message, otherwiese you will see messages like this in the nagios.log and nagios will not execute the eventhandler:

[<timestamp>] SERVICE EVENT HANDLER: <hostname>;<service name>;<service state>;<service type>;<service retrys>;<eventhandler name>!<list of paramters>
[<timestamp>] wproc: SERVICE EVENTHANDLER job <job pid> from worker Core Worker <worker pid> is a non-check helper but exited with return code 2
[<timestamp>] wproc:   early_timeout=0; exited_ok=1; wait_status=512; error_code=0;
[<timestamp>] wproc:   stderr line 01: /bin/sh: 1: Syntax error: "(" unexpected

Convert nagios log timestamp to human readable

$ cat /var/log/nagios/nagios.log | perl -pe 's/(\d+)/localtime($1)/e'

Schedule force recheck of service on all hosts

$ now=$(date +%s)
$ commandfile='/etc/nagios/var/rw/nagios.cmd'
$ service_name="check_ssh_host_certificate"

$ hostlist=$(cat /etc/nagios3/objects/*hosts.cfg | grep host_name | grep -vE "^#|<excludedservers>" | awk '{print $2}')
$ for host in ${hostlist}
$ do
$     printf "[%lu] SCHEDULE_FORCED_SVC_CHECK;${host};${service_name};1110741500\n" ${now} > "${commandfile}"
$ done

Balk downtime

$ fromnowone=$(date +%s)
$ fourHourdown=$(date +%s --date="$(date +4hour)")
$ commandfile='/etc/nagios/var/rw/nagios.cmd'
servicedescription="check_notification_active_mon"

$ hostlist=$(cat /etc/nagios3/objects/*hosts.cfg | grep host_name | grep -vE "^#|<excludedservers>" | awk '{print $2}')
$ for host in ${hostlist}
$ do
#                           SCHEDULE_SVC_DOWNTIME;<host_name>;<serv_desc>                     ;<start_t>    ;<end_t>        ;<fixed>;<trigger_id>;<duration>;<author>;<comment>
$    /usr/bin/printf "[%lu] SCHEDULE_SVC_DOWNTIME;${hostlist};${check_notification_active_mon};${formnowone};${fourHourdown};1;0;7200;${whoami};Service has entered a period of scheduled downtime\n" ${formnowone} >> ${commandfile}
$ done

Balk removal downtime

$ now=$(date +%s)
$ commandfile='/etc/nagios/var/rw/nagios.cmd'

#                  DEL_SVC_DOWNTIME;<downtime_id>
$ /bin/printf "[%lu] DEL_SVC_DOWNTIME;1\n" $now > $commandfile