We will configure Monit to constantly watch the CARP status. If it detects a change (e.g., from MASTER to BACKUP), it will run a script that sends a "ping" to a special Uptime Kuma monitor.
OPNsense1-CARP-MASTER-Status.http://192.168.8.60:3001/api/push/xxxxxxxx.+ Add.Check_CARP_Master_Statusif status != 0 then alert.Exec/usr/local/opnsense/scripts/monit/check_carp.sh (We will create this script next).This is the most technical part. You will need to SSH into your OPNsense firewall and choose option 8 for ‘Shell’ (or use the web GUI's System -> Diagnostics -> Command Prompt).
Create a new file/folder:
# Create a folder if it does not exist
mkdir -p /usr/local/opnsense/scripts/monit
# Create an empty folder
touch /usr/local/opnsense/scripts/monit/check_carp.sh
# Make it executable
chmod +x /usr/local/opnsense/scripts/monit/check_carp.sh
Edit the file (using vi or ee from the shell, or by pasting into the command prompt's ‘Execute Shell Command’ box):
#!/bin/sh
# Set this to the specific VHID you want to monitor.
VHID_TO_CHECK=1
# Paste your Uptime Kuma Push URL here
PUSH_URL="http://192.168.8.60:3001/api/push/xxxxxxxx?status=up&msg=OK&ping="
# Define full paths to commands to ensure they are found by Monit's minimal environment
IFCONFIG_CMD="/sbin/ifconfig"
GREP_CMD="/usr/bin/grep"
CURL_CMD="/usr/local/bin/curl"
# Check if the specific CARP VHID is in MASTER state using full paths
if ${IFCONFIG_CMD} | ${GREP_CMD} "carp: MASTER" | ${GREP_CMD} -q "vhid ${VHID_TO_CHECK}"; then
# If we are MASTER for this specific VHID, send the "up" signal to Uptime Kuma
${CURL_CMD} -sS --fail -m 10 "$PUSH_URL" > /dev/null
# Exit with status 0 (OK) for Monit
exit 0
else
# If not MASTER for this specific VHID, do nothing and exit with a failure code.
# Uptime Kuma will time out and report the monitor as down.
exit 1
fi
+ Add button to create a new service.CARP_Master_Check_Program (or any descriptive name you like).Custom from the dropdown list./usr/local/opnsense/scripts/monit/check_carp.shCheck_CARP_Master_Status. This is the critical step that links the program to the test.# Ensure that the script is executable - need to see 'x' in the permissions
ls -lah /usr/local/opnsense/scripts/check_carp.sh
# Confim monit is running
service monit status
# Check monit service
monit status
# Check monit's syntax check
monit -t
Now, every minute or two, Monit will run this script. If the firewall is the CARP master, the script will send a successful "ping" to Uptime Kuma, and the monitor will show as "Up". If the firewall fails over and is no longer the master, the script won't send the ping, and your Uptime Kuma monitor will go down after its configured grace period.