Nagios/Event Handler
< Nagios
Beispiel eine Nagios Event Handlers zum Löschen von Dateien auf dem zu überwachenden Rechner.
Normale Konfiguration
Definition des Event Handlers in der normalen Nagios Konfiguration:
Service Check (per NRPE):
define service{ use service-workhours ; Name of service template to use host_name myhost1 contact_groups admins service_description DISK_ROOT check_command check_nrpe_ssl!check_disk1 event_handler remote_delete_files normal_check_interval 15 }
Event Handler Kommando:
define command{ command_name remote_delete_files command_line /data/nagios/plugins/eventhandler/remote_delete_files $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$ $HOSTADDRESS$ }
Konfiguration bei Check_MK
######################################## # Event handlers, similar to usage of flap_detection_enabled # see http://www.monitoring-portal.org/wbb/index.php?page=Thread&threadID=23590, # http://www.mail-archive.com/checkmk-en@lists.mathias-kettner.de/msg06807.html ######################################## # enable event handler on all MyHosts for all fs_ service checks (also fs_/data etc.) extra_service_conf["event_handler_enabled"] = [ ( "1", ["MyHosts"], ALL_HOSTS, ["fs_"] ), ] # set event handler for root filesystems on hosts extra_service_conf["event_handler"] = [ ( "remote_delete_files", ["MyHosts"], ALL_HOSTS, ["fs_/$"]), ]
Event Handler Scripte
Event Handler Script:
#!/bin/sh
#
case "$1" in
OK)
# The service just came back up, so don't do anything...
;;
WARNING)
# We want to delete logs and traces even it is only a WARNING
# Is this a "soft" or a "hard" state?
case "$2" in
# We're in a "hard" state
HARD)
echo -n "Deleting logs and traces on remote machine (1st hard warning state)..."
# Call the remote deletion script
/data/nagios/plugins/remote_delete_logs_and_traces.sh "$4"
;;
esac
;;
UNKNOWN)
# We don't know what might be causing an unknown error, so don't do anything...
;;
CRITICAL)
# Is this a "soft" or a "hard" state?
case "$2" in
# We're in a "hard" state
HARD)
echo -n "Deleting logs and traces on remote machine (1st hard critical state)..."
# Call the remote deletion script
/data/nagios/plugins/remote_delete_logs_and_traces.sh "$4"
;;
esac
;;
esac
exit 0
Löschscript (läuft auf Nagios Server mit entsprechender SSH Public Key Authentifizierung zum Host):
#!/bin/sh
sshcmd=/usr/bin/ssh
sshuser=myuser1
remotecmdlogs="/usr/local/bin/delete_log.sh"
$sshcmd $sshuser@"${1}" nohup $remotecmdlogs > /dev/null&
if [ "$?" -ne "0" ]; then
echo "Sorry, something went wrong while deleting logs!"
exit 1
fi
exit 0