Monit with Slack notifications
Monit is a small Open Source utility for managing and monitoring Unix systems. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations.
Slack is a platform for team communication: everything in one place, instantly searchable, available wherever you go.
Monit with Slack Notifications
On a normal monit setup, monit sends out emails when an alert is triggered. Since email is getting a bit too ’90s, it’s way more intuitive to receive alerts via push notifications on your phone or chat client. Slack has many service integrations and also a Incoming Webhooks integration. This way you can receive those Monit alerts in a specific chatroom. Enable the mobile Slack application on you phone, enable push notifications on that specific channel and you’re all set.
Make sure you have:
- Monit installed (on a Unix system)
- A Slack account where you can enable integrations
- Slack mobile applications installed (to receive push notifications)
Create an Incoming Webhook integration
Login to your Slack account and add a new Incoming Webhook integrations.
This way you’ll get an unique webhook URL like this:
Notification shell script
Instead of triggering email alerts we will trigger a shell script. This shell script does a simpel http POST onto the webhook with our alert.
I’ve created this in
Execute the following commands to make the script executable:
Don’t forget to replace
https://YYYYY.slack.com/services/hooks/incoming-webhook?token=XXXXXXXXXXXXXXXXX with your unique webhook URL and replace
#monit with the channel of your choice.
Swap emails for Slack notifications
Since there is no native solution to set this notification as a default notification for all alerts, you should set this on all your monit service configurations files. For example in
Don’t forget to add the
else if succeeded then part, or you’ll not receive notifications when thing are fine again.
Restart your Monit, restart Nginx and you’ll see a PID changed message.
A native solution
At first I tried a native solution. There is a specific Monit branch with Slack Notifications included.
All you need to do is add the following line at the bottom of
But this isn’t very customizable.
Big up to the developer of Monit and this pull-request.
Thanks for reading
Feel free to leave a comment if you have remarks or like this post