Skip to content

Instantly share code, notes, and snippets.

@haslinger
Last active February 10, 2017 15:28
Show Gist options
  • Save haslinger/aa082adf360905a4dbc23f96012ca4f2 to your computer and use it in GitHub Desktop.
Save haslinger/aa082adf360905a4dbc23f96012ca4f2 to your computer and use it in GitHub Desktop.
Using monit and a bash script to monitor another monit instance

Readme

Monit seems to block basic authentication requests from other monit instances with 501-not implemented for whatever reason (selling Mmonit? :-))

Let's solve this with a small bash script that leverages curl to download the status file in xml format and xmllint to parse the status file for the relevant status flag.

if everything goes fine, this shell script return silently.

Otherwise it fails with error code 1 resulting in a status error that can be picked up by monit. When the remote monit instance comes back to live, the script succeeds again, and we get another email for the new status change.

check program monit-floridsdorf with path /etc/monit/my_bash_check_script
if changed status then alert
# if status != 0 then alert # would only send mail on failure, not on recovery, but this every cycle ;-)
#! /bin/bash
set -e
monit_status=$(curl -s -u username:password http://my.monit.server:2812/_status?format=xml | xmllint --xpath '/monit/service[@type="5"]/status/text()' -)
if [ $monit_status -ne 0 ]
then
echo "monit server status <> 0"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment