[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Integrating Monit alerts in ServiceNow
From: |
Lutz Mader |
Subject: |
Re: Integrating Monit alerts in ServiceNow |
Date: |
Sat, 15 Sep 2018 00:07:43 +0200 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 |
Hi again,
I use $MONIT_SERVICE and $MONIT_EVENT only.
The first step is I try to get the sys_id based on the resource name
($MONIT_SERVICE), then I update the table field ($MONIT_EVENT).
The used $MONIT_SERVICE names are unique, this is the reason I can use
the names.
# ServiceNow init.
SNCMD="curl"
SNLOG="../../logs/servnow.log"
SNURL='https://myinstance.service-now.intern/api/now/table/'
:
# Get the used sys_id
# {"result":[{"sys_id":"ca83c3816f054b0027e0cc60cb1f4e8e"}]}
data='/table_name'
data=$data'?sysparm_query=name='"${$MONIT_SERVICE}"
data=$data'&sysparm_fields=sys_id'
data=$data'&sysparm_limit=1"'
data=$data' --request GET'
data=$data' --insecure --user "user":"password"'
data=$data' --silent --show-error'
echo ${SNCMD} '"'"${SNURL}${data}" >> ${SNLOG} 2>&1
result=`${SNCMD} '"'"${SNURL}${data}" >> ${SNLOG} 2>&1`
sysid=`echo "$result" | sed -n -e 's/.*{"sys_id":"\(.*\)"}.*/\1/p'`
if [ -n "$sysid" ]; then
data='/table_name/'"${sysid}"
data=$data'?sysparm_display_value=true'
data=$data'&sysparm_exclude_reference_link=true'
data=$data'&sysparm_fields=name%2Cmonit_event"'
data=$data' --request PUT --header "Accept:application/json"'
data=$data' --header "Content-Type:application/json"'
data=$data' --data "{\"monit_event\":\"'"${$MONIT_EVENT}"'\"}"'
data=$data' --insecure --user "user":"password"'
data=$data' --silent --show-error'
# ServiceNow call.
echo ${SNCMD} '"'"${SNURL}${data}" >> ${SNLOG} 2>&1
result=`${SNCMD} '"'"${SNURL}${data}" >> ${SNLOG} 2>&1`
rc=$(($rc + $?))
fi
This is a snipped of the whole code only.
To get the status from monit I add an additional "not exist" rule to the
check process statements.
check process Manager with pidfile "/var/run/em.pid"
:
if not exist then restart
if not exist then exec "/usr/local/monit/scripts/servnow.sh"
else if succeeded then exec "/usr/local/monit/scripts/servnow.sh"
On the other hand, M/Monit is useful to get some more status information
more easy.
A suggestion only,
Lutz
- Re: Integrating Monit alerts in ServiceNow,
Lutz Mader <=