0

I have monit utility on production for monitoring several daemons (our micro-services). I'm trying to figure the best way to unmonitor/monitor my daemons while updating them. So, basically I need something like this, pseudo-code:

has_monit = false
if `monit watches daemon-xxx` then
  has_monit = true
  monit unmonitor daemon-xxx
endif
apt-get install xxx.deb
if has_monit then
  monit monitor deamon-xxx
endif

Unfortunately it seems that monit summary daemon-xxx is always return exit code 0 regardless it was success or failure, and prints raw html about failure, e.g.

[bialix@server ~]$ sudo monit summary xxx
<html><head><title>400 Bad Request</title></head><body bgcolor=#FFFFFF><h2>Bad Request</h2>Service 'xxx' not found<hr><a href='http://mmonit.com/monit/'><font size=-1>monit 5.30.0</font></a></body></html>
[bialix@server ~]$ echo $?
0

It seems exit code 1 only if monit is not running.

What is the right way here? Parsing the output of monit summary?

  • Can you tell me the Monit version, the html output should not be displayed. – lutzmad Aug 31 '23 at 07:12
  • I found the answer in the html output, it is monit 5.30.0, sorry. The html output problem was fix with monit 5.31.0, some more information are available from "https://bitbucket.org/tildeslash/monit/issues/1025/command-error-handling-does-not-work-well". – lutzmad Aug 31 '23 at 09:03

1 Answers1

0

You are right. The exit code of Monit is the status of the command entered.

You get "1" if the resource is not defined, or any other internal problem only.

A suggestion, I use "monit -B summary xxxx" to get the service status and parse the command output. The option "-B" is the batch command line mode and remove the output tables and colours.

lutzmad
  • 196
  • 4