Re: Problem using monit with curl

Lutz Mader <[email protected]>
Newsgroups gmane.comp.monitoring.monit.general
Message-ID <[email protected]>
Hello Norbert,
your problem, this is for M/Monit the central Server for Monit.

> A bit of search brought me to
> 	https://mmonit.com/documentation/http-api/Examples/cURL
> which seems exactely what I want to do, alas, the very first invocation
> given

> Could someone please explain how to set up read/write access to monit
> via curl? It seems that the wiki page/documentation is incorrect.

The Monit interface is not documented well, but very simple to handle.
But it is more useful to use the M/Monit server to handle this request.

With regards,
Lutz

Appendage:
A simple script to get the summary.
$1 is the monit hostname (the port is 2812)
$2 is a service or nothing

A simple sample script only:
#!/bin/ksh

OS=`uname -s | tr 'A-Z' 'a-z'`
if [ "$OS" = 'aix' ] ; then
  TOKEN=`date '+%Y%m%d%H%M%S'"$$""$RANDOM" | openssl md5 | cut -d ' ' -f 2`
elif [ "$OS" = 'darwin' ] ; then
  TOKEN=`md5 -q -s "\`date '+%Y%m%d%H%M%S'\`""$$""$RANDOM"`
elif [ "$OS" = 'linux' ] ; then
  TOKEN=`date '+%Y%m%d%H%M%S'\""$$""$RANDOM" | md5sum -t - | cut -d ' '
-f 1`
else
  TOKEN=`date '+%Y%m%d%H%M%S'\""$$""$RANDOM" | md5sum -t - | cut -d ' '
-f 1`
fi

if [ -n "$1" ]; then
  HOST="$1"
else
  HOST=`hostname`
fi

if [ -n "$2" ]; then
  SERVICE="service=$2&"
else
  SERVICE=""
fi

# The escape character.
ESC=`printf '\033'`    # Esc x1B 033 &#27;

cat <<MONIT | \
curl -k -X "POST /_summary HTTP/1.0" -H "Content-Type:
application/x-www-form-urlencoded" \
-b "securitytoken=${TOKEN}" \
-u admin:monit -d @- https://${HOST}:2812 | \
sed -e '/<.*html>/,/<\/html>/s/.*<\/h2>\(.*\)<hr>.*/\1/' | \
sed -e "s/${ESC}\[[0-9][0-9]*\;*[0-9]*[Km]//g" | \
sed -e 's/[─│├┼┤┌┬┐└┴┘]//g' | sed -e '/^$/d'
${SERVICE}format=text&securitytoken=${TOKEN}
MONIT

return
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.