Fetch monit status in JSON

I wanted to use monit as my desktop-alerting system, meaning that when a service or a machine is unreachable on my personnal network, I’d see a red dot somewhere on my desktop. Why not nagios you’d ask? because my needs are not worth the hassle.

Unfortunately, monit does not have simple and nice little desktop apps like nagstamon, so I decided to write my own.

It does not seem to be well known, but monit publishes a special URI that shows a status report in XML when the mini-HTTP status server is enabled. The JSON one is only available for the commercial product they sell, M/Monit, so I wrote this small utility to manipulate status values in a JSON format and show a status report within your shell console.

It will read a ~/.getmonitrc configuration file with the following format:

{
  "MyNet": {
    "url": "https://mynet.net/monit/_status?format=xml",
    "user": "foo",
    "passwd": "My Extreme Password"
  }
}

The script itself can be fetched from this gist url, it is used like this:

$ python getmonit.py 
✘  global status

$ python getmonit.py v
✔  senate
✔  home
✔  coruscant
✔  starkiller
✔  tatooine
✘  sidious

$ python getmonit.py vv
✔  senate
✔  home
  ✓  icmp
  ✓  port 443/HTTP
  ✓  port 22/SSH
✔  coruscant
  ✓  icmp
  ✓  port 22/SSH
✔  starkiller
  ✓  icmp
  ✓  port 22/SSH
✔  tatooine
  ✓  icmp
✘  sidious
  ✗  icmp
  ✗  port 22/SSH

The output is actually colored, you can see it here.