monit-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem using monit with curl


From: Lutz Mader
Subject: Re: Problem using monit with curl
Date: Sun, 19 Jul 2020 15:05:59 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:60.0) Gecko/20100101 Thunderbird/60.4.0

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 

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]