Score:0

What is the correct way to check monit status/summary success/failure

bw flag

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?

lutzmad avatar
ug flag
Can you tell me the Monit version, the html output should not be displayed.
lutzmad avatar
ug flag
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".
Score:0
ug flag

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.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.