The official Nagios Slack plugin is terrible, requiring multiple random perl dependencies. This uses a simple curl script in conjunction with a Webhook to post notifications directly.
This method is far simpler and allows you to maintain your Nagios configuration in a single location. The way it's set up also allows the script to be re-used for multiple channels if necessary.
- Go to the Apps and Integrations page within Slack, search for Incoming Webhooks and hit Add Configuration
- Select the channel you wish to post alerts to and hit Add Incoming Webhook Integration
- Make a note of the Webhook URL (You'll need the part past the https://hooks.slack.com/services/ bit. e.g - T07B2S2CC/B1HDDQ83A/naizPgXARIlUSixE0RUL93Oy)
- Change the Customize Name field to: nagios-alerts
- Change the icon to the icon.png image in this repository.
- Hit Save Settings
Add the following line to your Nagios configuration and modify the details:
define command {
command_name notify-host-slack-mychannel1
command_line /bin/bash /path/to/nagios-monitoring-scripts/notification_slack.sh -a "$NOTIFICATIONTYPE$" -b "$HOSTNAME$" -c "$HOSTSTATE$" -d "$HOSTOUTPUT$" -y "CHANNEL_NAME_HERE" -z "WEBHOOK_ADDRESS_HERE"
}
define command {
command_name notify-service-slack-mychannel1
command_line /bin/bash /path/to/nagios-monitoring-scripts/notification_slack.sh -a "$NOTIFICATIONTYPE$" -b "$HOSTNAME$" -e "$SERVICEDESC$" -f "$SERVICESTATE$" -g "$SERVICEOUTPUT$" -y "CHANNEL_NAME_HERE" -z "WEBHOOK_ADDRESS_HERE"
}Open the notification_slack.sh script and modify the SLACK_HOSTNAME and MONITORING_URL variables to your environment.
This script has been tested on multiple servers with different versions of curl.
Please fork and contribute if you find any bugs.
