2019-10-27 22:10:55 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
ICINGA_HOSTNAME="vin.openfest.org/icingaweb2"
|
2019-10-29 05:50:19 +02:00
|
|
|
SLACK_WEBHOOK_URL="https://hooks.slack.com/services/some/other/tocken"
|
|
|
|
SLACK_CHANNEL="#noc"
|
2019-10-27 22:10:55 +02:00
|
|
|
SLACK_BOTNAME="icinga2"
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$NOTIFICATIONTYPE" = "ACKNOWLEDGEMENT" ] || [ "$NOTIFICATIONTYPE" = "DOWNTIMESTART" ] || [ "$NOTIFICATIONTYPE" = "DOWNTIMEEND" ]
|
|
|
|
then
|
|
|
|
COLOR="#FFB6C1"
|
2019-10-29 05:50:19 +02:00
|
|
|
read -d '' PAYLOAD << EOF
|
2019-10-27 22:10:55 +02:00
|
|
|
{
|
|
|
|
"channel": "${SLACK_CHANNEL}",
|
|
|
|
"username": "${SLACK_BOTNAME}",
|
|
|
|
"attachments": [
|
|
|
|
{
|
|
|
|
"fallback": "${NOTIFICATIONTYPE}: ${SERVICESTATE}: ${HOSTDISPLAYNAME} - ${SERVICEDISPLAYNAME}",
|
|
|
|
"color": "${COLOR}",
|
|
|
|
"fields": [
|
|
|
|
{
|
|
|
|
"title": "${NOTIFICATIONTYPE}",
|
|
|
|
"value": "${NOTIFICATIONCOMMENT} - ${NOTIFICATIONAUTHORNAME}"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "Service output",
|
|
|
|
"value": "${SERVICEOUTPUT}",
|
|
|
|
"short": false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "Host",
|
|
|
|
"value": "<${ICINGA_HOSTNAME}/monitoring/host/services?host=${HOSTNAME}|${HOSTDISPLAYNAME}>",
|
|
|
|
"short": true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "Service",
|
|
|
|
"value": "<${ICINGA_HOSTNAME}/monitoring/service/show?host=${HOSTNAME}&service=${SERVICEDESC}|${SERVICEDISPLAYNAME}>",
|
|
|
|
"short": true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "State",
|
|
|
|
"value": "${SERVICESTATE}",
|
|
|
|
"short": true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
else
|
|
|
|
|
|
|
|
#Set the message icon based on ICINGA service state
|
|
|
|
if [ "$SERVICESTATE" = "CRITICAL" ]
|
|
|
|
then
|
|
|
|
COLOR="danger"
|
|
|
|
elif [ "$SERVICESTATE" = "WARNING" ]
|
|
|
|
then
|
|
|
|
COLOR="warning"
|
|
|
|
elif [ "$SERVICESTATE" = "OK" ]
|
|
|
|
then
|
|
|
|
COLOR="good"
|
|
|
|
elif [ "$SERVICESTATE" = "UNKNOWN" ]
|
|
|
|
then
|
|
|
|
COLOR="#800080"
|
|
|
|
else
|
|
|
|
COLOR=""
|
|
|
|
fi
|
|
|
|
|
|
|
|
#Send message to Slack
|
|
|
|
read -d '' PAYLOAD << EOF
|
|
|
|
{
|
|
|
|
"channel": "${SLACK_CHANNEL}",
|
|
|
|
"username": "${SLACK_BOTNAME}",
|
|
|
|
"attachments": [
|
|
|
|
{
|
|
|
|
"fallback": "${SERVICESTATE}: ${HOSTDISPLAYNAME} - ${SERVICEDISPLAYNAME}",
|
|
|
|
"color": "${COLOR}",
|
|
|
|
"fields": [
|
|
|
|
{
|
|
|
|
"title": "Service output",
|
|
|
|
"value": "${SERVICEOUTPUT}",
|
|
|
|
"short": false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "Host",
|
|
|
|
"value": "<${ICINGA_HOSTNAME}/monitoring/host/services?host=${HOSTNAME}|${HOSTDISPLAYNAME}>",
|
|
|
|
"short": true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "Service",
|
|
|
|
"value": "<${ICINGA_HOSTNAME}/monitoring/service/show?host=${HOSTNAME}&service=${SERVICEDESC}|${SERVICEDISPLAYNAME}>",
|
|
|
|
"short": true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "State",
|
|
|
|
"value": "${SERVICESTATE}",
|
|
|
|
"short": true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
curl --connect-timeout 30 --max-time 60 -s -S -X POST -H 'Content-type: application/json' --data "${PAYLOAD}" "${SLACK_WEBHOOK_URL}"
|