diff --git a/playbooks/prod_web.yml b/playbooks/prod_web.yml index 3d55a90..50a507d 100755 --- a/playbooks/prod_web.yml +++ b/playbooks/prod_web.yml @@ -181,9 +181,9 @@ - name: check_by_ssh command: "$USER1$/check_by_ssh -H $HOSTADDRESS$ -F /opt/nagios/etc/ssh_config -t 30 -q -i /opt/nagios/etc/id_ed25519 -l nagios-checker -C \"$ARG1$\"" - name: notify-host-by-matrix - command: "/usr/bin/printf \"%b\" \"$NOTIFICATIONTYPE$ - $HOSTNAME$ is $HOSTSTATE$\\nAddress: $HOSTADDRESS$\\nInfo: $HOSTOUTPUT$\\nDate/Time: $LONGDATETIME$\" | /opt/Custom-Nagios-Plugins/notify-by-matrix" + command: "/usr/bin/printf \"%b\" \"$NOTIFICATIONTYPE$\\n$HOSTNAME$ is $HOSTSTATE$\\nAddress: $HOSTADDRESS$\\nInfo: $HOSTOUTPUT$\\nDate/Time: $LONGDATETIME$\" | /opt/Custom-Nagios-Plugins/notify-by-matrix" - name: notify-service-by-matrix - command: "/usr/bin/printf \"%b\" \"$NOTIFICATIONTYPE$ - Service $HOSTALIAS$ - $SERVICEDESC$ is $SERVICESTATE$\\nInfo: $SERVICEOUTPUT$\\nDate/Time: $LONGDATETIME$\" | /opt/Custom-Nagios-Plugins/notify-by-matrix" + command: "/usr/bin/printf \"%b\" \"$NOTIFICATIONTYPE$\\nService $HOSTALIAS$ - $SERVICEDESC$ is $SERVICESTATE$\\nInfo: $SERVICEOUTPUT$\\nDate/Time: $LONGDATETIME$\" | /opt/Custom-Nagios-Plugins/notify-by-matrix" nagios_services: # Agentless checks - name: HTTP diff --git a/roles/nagios/templates/notify-by-matrix b/roles/nagios/templates/notify-by-matrix index 86323fa..c501011 100644 --- a/roles/nagios/templates/notify-by-matrix +++ b/roles/nagios/templates/notify-by-matrix @@ -16,6 +16,53 @@ MX_ROOM="{{ nagios_matrix_room }}" # Get a TXN to prefix this particular message with MX_TXN="$(date "+%s")$(( RANDOM % 9999 ))" +# Read the first line from STDIN +# This is supposed to be the NOTIFICATIONTYPE +read notiftype +prefix="" +# https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/macrolist.html#notificationtype +case "$notiftype" in + PROBLEM) + # Large Red Circle (U+1F534) + prefix="🔴" + ;; + RECOVERY) + # Large Green Circle (U+1F7E2) + prefix="🟢" + ;; + ACKNOWLEDGEMENT) + # Symbol For Acknowledge (U+2406) + prefix="␆" + ;; + FLAPPINGSTART) + # Large Orange Circle (U+1F7E0) + prefix="🟠" + ;; + FLAPPINGSTOP) + # Large Green Circle (U+1F7E2) + prefix="🟢" + ;; + FLAPPINGDISABLED) + # Bell with Cancellation Stroke (U+1F515) + prefix="🔕" + ;; + DOWNTIMESTART) + # Bell with Cancellation Stroke (U+1F515) + prefix="🔕" + ;; + DOWNTIMEEND) + # Bell (U+1F514) + prefix="🔔" + ;; + DOWNTIMECANCELLED) + # Bell (U+1F514) + prefix="🔔" + ;; + *) + prefix="$notiftype - " + ;; +esac + # Read a message from STDIN # NOTE: This is dangerous and stupid and unsanitized read message @@ -29,6 +76,6 @@ curl -X PUT \ --header 'Accept: application/json' \ -d "{ \"msgtype\": \"m.text\", - \"body\": \"$message\" + \"body\": \"$prefix $message\" }" \ "$MX_SERVER/_matrix/client/unstable/rooms/$MX_ROOM/send/m.room.message/$MX_TXN?access_token=$MX_TOKEN"