Error with custom service macros and event handling.

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Error with custom service macros and event handling.

Post by abrist »

Have you considered using the $SERVICEPROBLEMID$ and $HOSTPROBLEMID$ in nagios for tracking? These are unique numbers that track problems internally in nagios.
http://nagios.sourceforge.net/docs/3_0/macrolist.html
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
User avatar
j1johnson
Posts: 7
Joined: Mon Mar 10, 2014 3:55 pm
Location: Maine, USA

Re: Error with custom service macros and event handling.

Post by j1johnson »

Well, progress has been made!

Here are the services:

Code: Select all

        _SERVICE                restart_sw114
        _CLASSIFICATIONID       SC_WORKFLOW_PORTAL
        _HIERARCHYPATH          SC_APP_SYS "\\" SC_WORKFLOW_PORTAL
        _CLASSSTRUCTUREID       5642
        _DESCRIP                'sw114 DeltaSession Manager has stopped running.'
        _FR1CODE                'Unknown - code issue.'
        _FR2CODE                'Restart standalone java process.'
        _PROBLEMCODE            'Standalone sw114 process terminated on its own.'
        _IMPACT                 3
        _INTERNALPRIORITY       4
        _REPORTEDPRIORITY       3
        _URGENCY                3
        _OWNER                  AR333
        _OWNERGROUP             WASTEAM
Here is command definition:

Code: Select all

define command {
        command_name restart-service-maximo
        command_line /usr/bin/printf "%b" "$NAGIOS_SERVICESTATE\n$NAGIOS_HOSTADDRESS\n\"$NAGIOS__SERVICECLASSIFICATIONID\"\n\"$NAGIOS__SERVICEHIERARCHYPATH\"\n\"$NAGIOS__SERVICECLASSSTRUCTUREID\"\n\"$NAGIOS__SERVICEDESCRIP\"\n\"$NAGIOS__SERVICEFR1CODE\"\n\"$NAGIOS__SERVICEFR2CODE\"\n\"$NAGIOS__SERVICEPROBLEMCODE\"\n\"$NAGIOS__SERVICEIMPACT\"\n\"$NAGIOS__SERVICEINTERNALPRIORITY\"\n\"$NAGIOS__SERVICEREPORTEDPRIORITY\"\n\"$NAGIOS__SERVICEURGENCY\"\n\"$NAGIOS__SERVICEOWNER\"\n\"$NAGIOS__SERVICEOWNERGROUP\"\n$NAGIOS_SERVICEPROBLEMID" | $USER1$/restartserviceMaximo2.sh
}
Here is the script that takes in all the variables - restartserviceMaximo2.sh

Code: Select all

#!/bin/bash

ARRAY=()
while read -r LINE
do
    ARRAY+=("$LINE")
done

SERVICESTATE=${ARRAY[0]}
HOSTADDRESS=${ARRAY[1]}
SERVICECLASSIFICATIONID=${ARRAY[2]}
HIERARCHYPATH=${ARRAY[3]}
CLASSSTRUCTUREID=${ARRAY[4]}
DESCRIPTION=${ARRAY[5]}
FR1CODE=${ARRAY[6]}
FR2CODE=${ARRAY[7]}
PROBLEMCODE=${ARRAY[8]}
IMPACT=${ARRAY[9]}
INTERNALPRIORITY=${ARRAY[10]}
REPORTEDPRIORITY=${ARRAY[11]}
URGENCY=${ARRAY[12]}
OWNER=${ARRAY[13]}
OWNERGROUP=${ARRAY[14]}
SVCPROBLEMID=${ARRAY[15]}

case "$SERVICESTATE" in
        OK)
                ;;
        WARNING)
                ;;
        UNKNOWN)
                ;;
        CRITICAL)
                echo "$SERVICESTATE $HOSTADDRESS $SERVICECLASSIFICATIONID $HIERARCHYPATH $CLASSSTRUCTUREID $DESCRIPTION $FR1CODE $FR2CODE $PROBLEMCODE $IMPACT $INTERNALPRIORITY $REPORTEDPRIORITY $URGENCY $OWNER $OWNERGROUP $SVCPROBLEMID" > /tmp/newvars2.txt
                #for LINE in "${ARRAY[@]}"
                #do
                #    echo "$LINE" >> /tmp/newvars2.txt
                #done
                ;;
esac

exit 0;
And here is the output:
CRITICAL 10.14.172.238 "SC_WORKFLOW_PORTAL" "SC_APP_SYS \ SC_WORKFLOW_PORTAL" "5642" "sw114 DeltaSession Manager has stopped running." "Unknown - code issue." "Restart standalone java process." "Standalone sw114 process terminated on its own." "3" "4" "3" "3" "AR333" "WASTEAM"
The only thing that isn't coming across is the last field in the command - $NAGIOS_SERVICEPROBLEMID. I've tried $NAGIOS_SERVICEPROBLEMID, $NAGIOS__SERVICEPROBLEMID and $SERVICEPROBLEMID and nothing is coming across. Any suggestions for getting the $SERVICEPROBLEMID to come across?

Thanks!

- Jim
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Error with custom service macros and event handling.

Post by abrist »

As these are built-in macros, you should be able to add them to the command like so:

Code: Select all

define command {
        command_name restart-service-maximo
        command_line /usr/bin/printf "%b" "$NAGIOS_SERVICESTATE\n$NAGIOS_HOSTADDRESS\n\"$NAGIOS__SERVICECLASSIFICATIONID\"\n\"$NAGIOS__SERVICEHIERARCHYPATH\"\n\"$NAGIOS__SERVICECLASSSTRUCTUREID\"\n\"$NAGIOS__SERVICEDESCRIP\"\n\"$NAGIOS__SERVICEFR1CODE\"\n\"$NAGIOS__SERVICEFR2CODE\"\n\"$NAGIOS__SERVICEPROBLEMCODE\"\n\"$NAGIOS__SERVICEIMPACT\"\n\"$NAGIOS__SERVICEINTERNALPRIORITY\"\n\"$NAGIOS__SERVICEREPORTEDPRIORITY\"\n\"$NAGIOS__SERVICEURGENCY\"\n\"$NAGIOS__SERVICEOWNER\"\n\"$NAGIOS__SERVICEOWNERGROUP\"\n$SERVICEPROBLEMID$" | $USER1$/restartserviceMaximo2.sh
}
Note the bookended "$": $SERVICEPROBLEMID$
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked