Re: Integrating Monit alerts in ServiceNow

Lutz Mader <[email protected]>
Newsgroups gmane.comp.monitoring.monit.general
Message-ID <[email protected]>
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


-- 
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general
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.