Can you redirect monit alerts to MQTT

179 Views Asked by At

Can you redirect monit alerts to MQTT?

The work-around with exec mosquitto_pub -h .. -u .. -P .. -t .. -m .. is cumbersome.

1

There are 1 best solutions below

1
boppy On

I see two ways:

1. Helperscript

Where you include all the config to an executable file like /opt/monit_helper/send-mqtt.sh with your mosquitto_pub command in it.

#!/bin/bash
mosquitto_pub -h .. -u .. -P .. -t "${2:-monitoring}" -m "$1"

So you can use exec /opt/monit_helper/send-mqtt.sh "my cool message" or /opt/monit_helper/send-mqtt.sh "my even cooler message" "my awesome topic" (topic falls back to monitoring if not set manually).

2. Use E-Mail (and/or fake it)

Since I was not happy with only the exec option, but wanted all the info monit is sending by e-mail I wrote a fake SMTP-Server that can handle the e-mails sent by monit and runs whatever you want it to run.

You'll find it at https://github.com/boppy/nitmo.fakesmtp - It basically is just a bash script. See the .sh file, lines 14..45 for config ideas/examples.