Can you tell me how i can use "Free variable" on service, pass to event handeler script ?
I have service with Free variable _NCPAPort,_NCPAToken, that variable need pass to event handeler script witch call NCPA script "check_ncpa.py"
At command definition i tray $_SERVICENCPAToken$, $_SERVICE_NCPAToken$, $_NCPAToken$. With no value at script.
Service and event configuration:
Code: Select all
define service {
host_name XXXXXTESTXXXXXX
service_description OS cpu usage
use xiwizard_passive_service
max_check_attempts 1
check_interval 1
retry_interval 1
check_period xi_timeperiod_24x7
event_handler event_handlers_winCPU
event_handler_enabled 1
notification_interval 60
notification_period xi_timeperiod_24x7
notifications_enabled 0
_NCPAPort 5693
_NCPAToken NCPAtoken
_xiwizard passiveobject
register 1
}Code: Select all
define command {
command_name event_handlers_winCPU
command_line $USER1$/event_hendler_execute.sh "$HOSTNAME$" "$HOSTADDRESS$" "$SERVICEDESC$" "$SERVICESTATE$" "$SERVICESTATETYPE$" "$_SERVICENCPAToken$" "$_SERVICENCPAPort$"
}Code: Select all
#!/bin/bash
# $SERVICESTATE$ A string indicating the current state of the service ("OK", "WARNING", "UNKNOWN", or "CRITICAL").
# $SERVICESTATEID$ A number that corresponds to the current state of the service: 0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN.
# $SERVICEDESC$ The long name/description of the service (i.e. "Main Website"). This value is taken from the service_description directive of the service definition.
# Service TECHCONTACT $_SERVICETECHCONTACT$
# Host MAC_ADDRESS $_HOSTMAC_ADDRESS$
# $USER1$/event_hendler_execute.sh $HOSTNAME$ $HOSTADDRESS$ $SERVICEDESC$ $SERVICESTATE$ $STATETYPE$ $_SERVICE_NCPA_Token$ $_SERVICE_NCPA_Port$
DATE=$(date)
Hostname="$1"
HostIP="$2"
ServiceDes="$3"
ServiceState="$4"
ServiceStateType="$5"
NCPAtoken="$6"
NCPAport="$7"
NCPAbin="/usr/local/nagios/libexec/check_ncpa.py"
LogFile="/var/tmp/event_exec_Handler.log"
echo -e "$DATE Debug: \t$1 .. $2 .. $3 .. $4 .. $5 .. $6 .. $7 ..end.." > $LogFile
echo -e "$DATE Debug: \tHostname=$Hostname, HostIP=$HostIP, SeviceDes=$ServiceDes, ServiceState=$ServiceState, ServiceStateType=$ServiceStateType, NCPAtoken=$NCPAtoken, NCPAport=$NCPAport ..end.." > $LogFile
if [[ "$ServiceStateType" == "HARD" && "$ServiceState" == "CRITICAL" ]]; then
echo -e "$DATE Spoustim: \tHostname=$Hostname, HostIP=$HostIP, SeviceDes=$ServiceDes, ServiceState=$ServiceState, ServiceStateType=$ServiceStateType" > $LogFile
#$NCPAbin -H $HostIP -P $NCPAport -t $NCPAtoken -M agent/plugin/Event_handler_win_CPU.ps1 > $LogFile
echo -e "$DATE Konec: \tHostname=$Hostname." > $LogFile
exit 0
else
echo -e "$DATE Neprovadim: \tHostname=$Hostname, SeviceDes=$ServiceDes, ServiceState=$ServiceState, ServiceStateType=$ServiceStateType" > $LogFile
exit 0
fiCode: Select all
tail -f /var/tmp/event_exec_Handler.log 2> /dev/null
Mon Jan 11 10:51:42 CET 2016 Debug: XXXXXXXXXXXXXXX .. XXXXXXXXXXXXXXX .. OS cpu usage .. CRITICAL .. HARD .. $ .. $ ..end..
Mon Jan 11 10:51:42 CET 2016 Debug: Hostname=XXXXXXXXXXXXXXX, HostIP=XXXXXXXXXXXXXXX, SeviceDes=OS cpu usage, ServiceState=CRITICAL, ServiceStateType=HARD, NCPAtoken=$, NCPAport=$ ..end..
Mon Jan 11 10:51:42 CET 2016 Spoustim: Hostname=XXXXXXXXXXXXXXX, HostIP=XXXXXXXXXXXXXXX, SeviceDes=OS cpu usage, ServiceState=CRITICAL, ServiceStateType=HARD
Mon Jan 11 10:51:42 CET 2016 Konec: Hostname=XXXXXXXXXXXXXXX.
So, how i can pass my free variable to this script ?
thx
Michal.