diff --git a/roles/nagios_server/files/nagios/commands/notify.cfg b/roles/nagios_server/files/nagios/commands/notify.cfg index fe0a50ffcb..16247ca828 100644 --- a/roles/nagios_server/files/nagios/commands/notify.cfg +++ b/roles/nagios_server/files/nagios/commands/notify.cfg @@ -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 diff --git a/roles/nagios_server/files/nagios/configs/escalations.cfg b/roles/nagios_server/files/nagios/configs/escalations.cfg index 0232815da0..9582de5235 100644 --- a/roles/nagios_server/files/nagios/configs/escalations.cfg +++ b/roles/nagios_server/files/nagios/configs/escalations.cfg @@ -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 diff --git a/roles/nagios_server/files/nagios/contactgroups/fedora-sysadmin-matrixbot.cfg b/roles/nagios_server/files/nagios/contactgroups/fedora-sysadmin-matrixbot.cfg new file mode 100644 index 0000000000..dec8d27e40 --- /dev/null +++ b/roles/nagios_server/files/nagios/contactgroups/fedora-sysadmin-matrixbot.cfg @@ -0,0 +1,6 @@ +define contactgroup{ + contactgroup_name fedora-sysadmin-matrixbot + alias Fedora Sysadmin Matrix Contacts + members matrixbot + + } diff --git a/roles/nagios_server/files/nagios/contacts/matrixbot.cfg b/roles/nagios_server/files/nagios/contacts/matrixbot.cfg new file mode 100644 index 0000000000..59e31c98ca --- /dev/null +++ b/roles/nagios_server/files/nagios/contacts/matrixbot.cfg @@ -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 +} diff --git a/roles/nagios_server/tasks/main.yml b/roles/nagios_server/tasks/main.yml index 68092aa018..33c4877185 100644 --- a/roles/nagios_server/tasks/main.yml +++ b/roles/nagios_server/tasks/main.yml @@ -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/ diff --git a/roles/nagios_server/templates/nagios/scripts/matrix-notify.sh.j2 b/roles/nagios_server/templates/nagios/scripts/matrix-notify.sh.j2 new file mode 100644 index 0000000000..1e68513b70 --- /dev/null +++ b/roles/nagios_server/templates/nagios/scripts/matrix-notify.sh.j2 @@ -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" \ No newline at end of file