Monit posting alerts to pushover with curl

Started by packetSniffer, March 03, 2024, 01:58:03 AM

Previous topic - Next topic
I'm trying to figure out how to get pushover working on my opnsense system.

I installed curl with pkg

I have followed the instructions here and a created .monitrc but updated it to reflect that pushover.sh is in /root
https://mmonit.com/wiki/MMonit/PushoverNotification
I create /root/.monitrc
and
/root/pushover.sh

I update the location of curl to be correct and confirm the script runs with blank data when I run it manually.
I can't find check_mysql.sh on the filesystem, nor am I certain this implementation is using mysql.   

Anyone have ideas for next steps? 
I would really like to get away from SMTP

Ok so I found the config in /usr/local/etc/monitrc and that helped me understand a little more.

I see that file is auto generated by opnsense - it looks like what I would want to do is replace "then alert" with "then exec ..." on each of the items which is less than ideal.  How would I do this so it gets auto generated each time instead of just in this text file?

April 27, 2024, 06:15:50 PM #2 Last Edit: April 27, 2024, 07:12:17 PM by ack_too_damn_high
I mostly figured this out last night and I think I found a UI bug in 23.7.10_1

When using the opnsense monit Web UI - it doesn't quote the path used in the exec statement.
Every example of exec in the Monit Manual says the path should be quoted, but the UI complains if this is attempted.
https://mmonit.com/monit/documentation/monit.html

/usr/local/etc/monitrc is overwritten by save/apply in webUI.
This will break exec statement- So make a new configuration file


/usr/local/etc/monit.opensense.d/000-customconfig.conf


check host myserver.domain.com address 8.8.8.8
   if failed ping count 3 then exec "/usr/local/etc/monitpush.sh"
   if failed port 443 protocol https and certificate valid > 30 days then exec "/usr/local/etc/monitpush.sh"


Pretty sure you can put this straight in the custom config with quotes instead of using a script.
Here's the curl:

/usr/local/etc/monitpush.sh

#!/bin/sh
/usr/local/bin/curl -s \
  -F "token=TOKEN" \
  -F "user=USERKEY" \
  --form-string "title=$MONIT_HOST - $MONIT_EVENT" \
  --form-string "message=$MONIT_DATE - $MONIT_DESCRIPTION" \
  https://api.pushover.net/1/messages.json


---
addendum;
Heres the config checker
configctl monit check
The smart thing to do is run this as non-root
from manual:

if failed <test> then exec "/usr/local/bin/sms.sh"
      as uid "nobody" and gid "nobody"
      repeat every 5 cycles