notifications_via_pushover
Inhaltsverzeichnis
Notifications via Pushover
Neue Version für WATO
Siehe: http://mathias-kettner.de/checkmk_flexible_notifications.html
Nach local/share/check_mk/notifications kopieren und executable setzen.
#!/bin/sh date >> /tmp/sm.log # set | grep NOTIFY >> /tmp/sm.log SITE="$NOTIFY_OMD_SITE" OBJECT="$NOTIFY_WHAT" TYPE="$NOTIFY_NOTIFICATIONTYPE" case "$OBJECT" in HOST) # Host HOST="$NOTIFY_HOSTNAME" OUTPUT="$NOTIFY_HOSTOUTPUT" STATE="$NOTIFY_HOSTSTATE" ;; SERVICE) # Service HOST="$NOTIFY_HOSTNAME" SERVICE="$NOTIFY_SERVICEDESC" OUTPUT="$NOTIFY_SERVICEOUTPUT" STATE="$NOTIFY_SERVICESTATE" ;; *) exit 1 ;; esac # Pushover Parameter https://pushover.net/api URL="https://api.pushover.net/1/messages.json" TOKEN="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" USER="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" SEND=1 TITLE="OMD $SITE" case "$STATE" in WARNING | UNKNOWN | UNREACHABLE) PRIORITY=0 ;; CRITICAL | DOWN) PRIORITY=1 ;; OK | UP) PRIORITY=-1 ;; *) PRIORITY=-1 ;; esac case "$OBJECT" in HOST) case "$TYPE" in PROBLEM) MESSAGE="$HOST: $STATE - $OUTPUT" ;; RECOVERY) # vorerst keine Recovery-Messages ;; *) SEND=0 ;; esac ;; SERVICE) case "$TYPE" in PROBLEM) MESSAGE="$SERVICE@$HOST: $STATE - $OUTPUT" ;; RECOVERY) # vorerst keine Recovery-Messages ;; *) SEND=0 ;; esac ;; *) SEND=0 ;; esac if [ $SEND ]; then echo "/usr/bin/curl -s -F 'token=$TOKEN' -F 'user=$USER' -F 'priority=$PRIORITY' -F 'title=$TITLE' -F 'message=$MESSAGE' $URL" >> /tmp/sm.log /usr/bin/curl -s -F "token=$TOKEN" -F "user=$USER" -F "priority=$PRIORITY" -F "title=$TITLE" -F "message=$MESSAGE" $URL fi
Alte Version für manuelle Config
#!/bin/sh SITE="$1" # Sitename OBJECT="$2" # H = Host S = Service TYPE="$3" # $NOTIFICATIONTYPE$ http://nagios.sourceforge.net/docs/3_0/macrolist.html#notificationtype STATE="$4" # $HOSTSTATE$ / $SERVICESTATE$ http://nagios.sourceforge.net/docs/3_0/macrolist.html#hoststate # http://nagios.sourceforge.net/docs/3_0/macrolist.html#servicestate case "$OBJECT" in H) # Host HOST="$5" # $HOSTNAME$ http://nagios.sourceforge.net/docs/3_0/macrolist.html#hostname shift 5 ;; S) # Service HOST="$5" # $HOSTNAME$ http://nagios.sourceforge.net/docs/3_0/macrolist.html#hostname SERVICE="$6" # $SERVICEDESC$ http://nagios.sourceforge.net/docs/3_0/macrolist.html#servicedesc shift 6 ;; *) exit 1 ;; esac OUTPUT="$@" # $SERVICEOUTPUT$ http://nagios.sourceforge.net/docs/3_0/macrolist.html#serviceoutput # Pushover Parameter https://pushover.net/api URL="https://api.pushover.net/1/messages.json" TOKEN="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" USER="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" SEND=1 TITLE="Nagios - $SITE" case "$STATE" in WARNING | UNKNOWN | UNREACHABLE) PRIORITY=0 ;; CRITICAL | DOWN) PRIORITY=1 ;; OK) PRIORITY=-1 ;; *) PRIORITY=-1 ;; esac case "$OBJECT" in H) case "$TYPE" in PROBLEM) MESSAGE="$HOST: $STATE - $OUTPUT" ;; RECOVERY) # vorerst keine Recovery-Messages ;; *) SEND=0 ;; esac ;; S) case "$TYPE" in PROBLEM) MESSAGE="$SERVICE@$HOST: $STATE - $OUTPUT" ;; RECOVERY) # vorerst keine Recovery-Messages ;; *) SEND=0 ;; esac ;; *) SEND=0 ;; esac if [ $SEND ]; then /usr/bin/curl -s -F "token=$TOKEN" -F "user=$USER" -F "priority=$PRIORITY" -F "title=$TITLE" -F "message=$MESSAGE" $URL fi
Nagios Config
define command { command_name notify-host command_line /usr/local/bin/sendmessage MHC H $NOTIFICATIONTYPE$ $HOSTSTATE$ $HOSTNAME$ '$HOSTOUTPUT$' } define command { command_name notify-service command_line /usr/local/bin/sendmessage MHC H $NOTIFICATIONTYPE$ $SERVICESTATE$ $HOSTNAME$ $SERVICEDESC$ '$SERVICEOUTPUT$' } define timeperiod{ timeperiod_name 24x7 alias 24 Hours A Day, 7 Days A Week sunday 00:00-24:00 monday 00:00-24:00 tuesday 00:00-24:00 wednesday 00:00-24:00 thursday 00:00-24:00 friday 00:00-24:00 saturday 00:00-24:00 } define contact { contact_name root alias Root service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c host_notification_options d,u service_notification_commands notify-service host_notification_commands notify-host } define contactgroup { contactgroup_name notification_group alias notification_group members root }
check_mk Config
extra_host_conf['contact_groups'] = [ ('notification_group',ALL_HOSTS), ]
Notifications erst wenn ein Problem für mehr als 5 Minuten vorliegt:
extra_host_conf['first_notification_delay'] = [ ('5',ALL_HOSTS), ]
notifications_via_pushover.txt · Zuletzt geändert: 2017/03/17 11:37 von 127.0.0.1