Re: Problem using monit with curl
Lutz Mader <[email protected]>
| Newsgroups | gmane.comp.monitoring.monit.general |
|---|---|
| Message-ID | <[email protected]> |
Hello Norbert, I append some sample scripts to get the summary, the status or do some actions on monit to the mail. Have a look to use the right user and password, the samples use "admin" with "monit", the port is 2812. summary.sh host [service] status.sh host [service] doaction.sh host start|stop|monitor|unmonitor [service] The scripts are very easy and samples only. The use of the scripts takes place on your own risk. Nobody can be made under any circumstances liable for damages to hardware and software, lost data and others directly or indirectly by the use of the software emerging damages. If you do not agree with these conditions, you may not use or distribute these scripts. With regards, Lutz
summary.sh
(application/x-sh, 1 KB)
#!/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
status.sh
(application/x-sh, 981 B)
#!/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 /_status 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"
${SERVICE}format=text&securitytoken=${TOKEN}
MONIT
return
doaction.sh
(application/x-sh, 1.1 KB)
#!/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
ACTION="$2"
else
ACTION='monitor'
fi
if [ -n "$3" ]; then
SERVICE="service=$3&"
else
SERVICE=""
fi
# The escape character.
ESC=`printf '\033'` # Esc x1B 033 
cat <<MONIT | \
curl -k -X "POST /_doaction 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'
action=${ACTION}&${SERVICE}format=text&securitytoken=${TOKEN}
MONIT
return