Move nagios notifications to Matrix

Signed-off-by: Leo Puvilland <leo@craftcat.dev>
This commit is contained in:
Leo Puvilland 2023-12-18 14:31:32 -08:00
parent 92ce28f253
commit 5aafc6a1d2
No known key found for this signature in database
GPG key ID: 20EA96682F9368EB
6 changed files with 41 additions and 2 deletions

View file

@ -34,6 +34,12 @@ define command{
command_line /usr/bin/printf "%b" "#fedora-noc $NOTIFICATIONTYPE$ - $HOSTNAME$ is $HOSTSTATE$: $HOSTOUTPUT$ ($$(hostname -s)) $HOSTACKAUTHOR$ $SERVICEACKAUTHOR$" | /usr/local/bin/irc-colorize.py | nc -w 1 value02 5050
}
# 'host-notify-by-matrixbot' command definition
define command{
command_name host-notify-by-matrixbot
command_line /usr/bin/echo '{"notificationtype": "$NOTIFICATIONTYPE$", "hostname": "$HOSTNAME$", "servicestate": "$HOSTSTATE$", "serviceoutput": "$HOSTOUTPUT$", "hostackauthor": "$HOSTACKAUTHOR$", "serviceackauthor": "$SERVICEACKAUTHOR$"}' | /usr/local/bin/matrix-notify.sh false
}
# 'notify-by-email' command definition
define command{
command_name notify-by-email
@ -46,6 +52,12 @@ define command{
command_line /usr/bin/printf "%b" "#fedora-noc $NOTIFICATIONTYPE$ - $HOSTNAME$/$SERVICEDESC$ is $SERVICESTATE$: $SERVICEOUTPUT$ ($$(hostname -s)) $HOSTACKAUTHOR$ $SERVICEACKAUTHOR$" | /usr/local/bin/irc-colorize.py | nc -w 1 value02 5050
}
# 'notify-by-matrixbot' command definition
define command{
command_name notify-by-matrixbot
command_line /usr/bin/echo '{"notificationtype": "$NOTIFICATIONTYPE$", "hostname": "$HOSTNAME$", "servicedesc": "$SERVICEDESC$", "servicestate": "$HOSTSTATE$", "serviceoutput": "$HOSTOUTPUT$", "hostackauthor": "$HOSTACKAUTHOR$", "serviceackauthor": "$SERVICEACKAUTHOR$"}' | /usr/local/bin/matrix-notify.sh true
}
# 'host-notify-by-fedmsg' command definition
define command{
command_name host-notify-by-fedmsg

View file

@ -1,7 +1,7 @@
define hostescalation{
host_name *
hostgroup_name *
contact_groups fedora-sysadmin-email,fedora-sysadmin-emergency,fedora-sysadmin-ircbot
contact_groups fedora-sysadmin-email,fedora-sysadmin-emergency,fedora-sysadmin-ircbot,fedora-sysadmin-matrixbot
first_notification 2
last_notification 0
notification_interval 60
@ -13,7 +13,7 @@ define hostescalation{
define serviceescalation{
host_name *
service_description *
contact_groups fedora-sysadmin-email,fedora-sysadmin-emergency,fedora-sysadmin-ircbot
contact_groups fedora-sysadmin-email,fedora-sysadmin-emergency,fedora-sysadmin-ircbot,fedora-sysadmin-matrixbot
first_notification 2
last_notification 0
notification_interval 60

View file

@ -0,0 +1,6 @@
define contactgroup{
contactgroup_name fedora-sysadmin-matrixbot
alias Fedora Sysadmin Matrix Contacts
members matrixbot
}

View file

@ -0,0 +1,10 @@
define contact{
contact_name matrixbot
alias NON
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-by-matrixbot
host_notification_commands host-notify-by-matrixbot
}

View file

@ -153,6 +153,13 @@
- nagios_server
notify: restart nagios
- name: Copy Matrix-Notify script
copy: src=scripts/matrix-notify.sh dest=/usr/local/bin/
mode: '700'
tags:
- nagios_config
- nagios_server
## Copy over the contacts
- name: Copy /etc/nagios/contacts
synchronize: src=nagios/contacts/ dest=/etc/nagios/contacts/

View file

@ -0,0 +1,4 @@
#!/bin/bash
stdin=$(cat)
curl -X POST -H "Content-Type: application/json" -u {{ matrix_nonbot_auth }} https://maubot.apps.ocp.fedoraproject.org/plugin/nonbot-nagios/send?service=$1 -d "$stdin"