How are Global Event Handler Command Variables different than macros? Is there a different write-up for Command Variables (other than what's on the "XI Global Event Handler" PDF)?
According to "Introduction to Event Handlers" PDF:
$USER1$/event_handler_test.sh $HOSTNAME$ $HOSTSTATE$ $HOSTSTATETYPE$ $HOSTOUTPUT$
According to Global Event Handler Component default configuration:
/tmp/host_change_handler.sh --host="%host%" --hoststate=%hoststate% --hoststateid=%hoststateid% --lasthoststate=%lasthoststate% --lasthoststateid=%lasthoststateid% --hoststatetype=%hoststatetype% --currentattempt=%currentattempt% --maxattempts=%maxattempts% --hosteventid=%hosteventid% --hostproblemid=%hostproblemid% --hostoutput="%hostoutput%" --hostdowntime=%hostdowntime%
Command Variables vs. Macros
-
slansing
- Posts: 7698
- Joined: Mon Apr 23, 2012 4:28 pm
- Location: Travelling through time and space...
Re: Command Variables vs. Macros
There is actually quite a bit of detail on this subject found through the core object definitions documentation:
http://nagios.sourceforge.net/docs/3_0/macros.html
http://nagios.sourceforge.net/docs/3_0/ ... tvars.html
http://nagios.sourceforge.net/docs/3_0/macrolist.html
If you have specific questions on use cases beyond what is shown on those pagers or elsewhere in the documentation tree let us know! Some of it might be answered in your other post.
http://nagios.sourceforge.net/docs/3_0/macros.html
http://nagios.sourceforge.net/docs/3_0/ ... tvars.html
http://nagios.sourceforge.net/docs/3_0/macrolist.html
If you have specific questions on use cases beyond what is shown on those pagers or elsewhere in the documentation tree let us know! Some of it might be answered in your other post.
Re: Command Variables vs. Macros
OK, how do we define variables in event handlers?
According to "Introduction to Event Handlers" PDF, macros are defined as such (see below), but how would we do the same using variables? %HOST% %HOSTSTATE% %HOSTSTATETYPE% %HOSTOUTPUT%
----------------------------------------------------------------------------------------------------------------------------
$USER1$/event_handler_test.sh $HOSTNAME$ $HOSTSTATE$ $HOSTSTATETYPE$ $HOSTOUTPUT$
#!/bin/bash
HOSTNAME=$1
HOSTSTATE=$2
HOSTSTATETYPE=$3
HOSTOUTPUT=$4
DATE=$(date) #sets the DATE variable to the output of the 'date' command
echo "The host $HOSTNAME has changed to a $HOSTSTATETYPE $HOSTSTATE state at $DATE with the error:
$HOSTOUTPUT" > /tmp/hostinfo.txt
----------------------------------------------------------------------------------------------------------------------------
Furthermore, snmptraps can reference these macros according to NAGIOS-NOTIFY-MIB
i.e. /usr/bin/snmptrap -v 2c -c public 192.168.x.x '' NAGIOS-NOTIFY-MIB::nSvcEvent nSvcHostname s "$HOSTNAME"
How would I do do this with variables?
Thanks,
-klee
According to "Introduction to Event Handlers" PDF, macros are defined as such (see below), but how would we do the same using variables? %HOST% %HOSTSTATE% %HOSTSTATETYPE% %HOSTOUTPUT%
----------------------------------------------------------------------------------------------------------------------------
$USER1$/event_handler_test.sh $HOSTNAME$ $HOSTSTATE$ $HOSTSTATETYPE$ $HOSTOUTPUT$
#!/bin/bash
HOSTNAME=$1
HOSTSTATE=$2
HOSTSTATETYPE=$3
HOSTOUTPUT=$4
DATE=$(date) #sets the DATE variable to the output of the 'date' command
echo "The host $HOSTNAME has changed to a $HOSTSTATETYPE $HOSTSTATE state at $DATE with the error:
$HOSTOUTPUT" > /tmp/hostinfo.txt
----------------------------------------------------------------------------------------------------------------------------
Furthermore, snmptraps can reference these macros according to NAGIOS-NOTIFY-MIB
i.e. /usr/bin/snmptrap -v 2c -c public 192.168.x.x '' NAGIOS-NOTIFY-MIB::nSvcEvent nSvcHostname s "$HOSTNAME"
How would I do do this with variables?
Thanks,
-klee
Re: Command Variables vs. Macros
The XI global event handler variables are specific to the XI global event hander UI. The same is true for the XI notification message variables.klee wrote:According to "Introduction to Event Handlers" PDF, macros are defined as such (see below), but how would we do the same using variables? %HOST% %HOSTSTATE% %HOSTSTATETYPE% %HOSTOUTPUT%
Most other portions of XI - at least those that are directly related to core, will still use the core macros and syntax.
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.
"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.
Re: Command Variables vs. Macros
Thanks abrist,
XI global event hander UI: meaning how they are set here, yes?
-------------------------------------------------------------------------------------------------------------------------
/tmp/host_change_handler.sh --host="%host%" --hoststate=%hoststate% --hoststateid=%hoststateid% --lasthoststate=%lasthoststate% --lasthoststateid=%lasthoststateid% --hoststatetype=%hoststatetype% --currentattempt=%currentattempt% --maxattempts=%maxattempts% --hosteventid=%hosteventid% --hostproblemid=%hostproblemid% --hostoutput="%hostoutput%" --hostdowntime=%hostdowntime%
/usr/local/nagios/libexec/nms_global_service_event_handler.sh --host="%host%" --service="%service%" --hoststate=%hoststate% --servicestate=%servicestate% --servicestateid=%servicestateid% --lastservicestate=%lastservicestate% --lastservicestateid=%lastservicestateid% --servicestatetype=%servicestatetype% --currentattempt=%currentattempt% --maxattempts=%maxattempts% --serviceeventid=%serviceeventid% --serviceproblemid=%serviceproblemid% --serviceoutput="%serviceoutput%"
-------------------------------------------------------------------------------------------------------------------------
How do they have to be referenced inside of the event handler script?
XI global event hander UI: meaning how they are set here, yes?
-------------------------------------------------------------------------------------------------------------------------
/tmp/host_change_handler.sh --host="%host%" --hoststate=%hoststate% --hoststateid=%hoststateid% --lasthoststate=%lasthoststate% --lasthoststateid=%lasthoststateid% --hoststatetype=%hoststatetype% --currentattempt=%currentattempt% --maxattempts=%maxattempts% --hosteventid=%hosteventid% --hostproblemid=%hostproblemid% --hostoutput="%hostoutput%" --hostdowntime=%hostdowntime%
/usr/local/nagios/libexec/nms_global_service_event_handler.sh --host="%host%" --service="%service%" --hoststate=%hoststate% --servicestate=%servicestate% --servicestateid=%servicestateid% --lastservicestate=%lastservicestate% --lastservicestateid=%lastservicestateid% --servicestatetype=%servicestatetype% --currentattempt=%currentattempt% --maxattempts=%maxattempts% --serviceeventid=%serviceeventid% --serviceproblemid=%serviceproblemid% --serviceoutput="%serviceoutput%"
-------------------------------------------------------------------------------------------------------------------------
How do they have to be referenced inside of the event handler script?
Re: Command Variables vs. Macros
The percentage variable mappings are only valid for the XI event handler php scripts. I think we talk about your use case on a different thread. If you want to use the XI global event handler UI, you need to change the event handler mappings and command back to default.
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.
"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.
Re: Command Variables vs. Macros
Hi abrist,
I did change the event handler mappings and command back to default.
But I don't understand what you mean by "XI event handler php scripts".
Can you please elaborate?
Thanks,
-klee
I did change the event handler mappings and command back to default.
But I don't understand what you mean by "XI event handler php scripts".
Can you please elaborate?
Thanks,
-klee
Re: Command Variables vs. Macros
Specifically the event handler commands in nagios.cfg:
If you are using the XI gloabal event handler, you can just use the variables without the mapping: %host%, %hoststate%, etc.
Code: Select all
global_host_event_handler=xi_host_event_handler
global_service_event_handler=xi_service_event_handlerFormer 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.
"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.
Re: Command Variables vs. Macros
Yes, I did switch these configurations back in /usr/local/nagios/etc/nagios.cfg. I'm not sure exactly what xi_host_event_handler & xi_service_event_handler are, or how to access them though...
global_host_event_handler=xi_host_event_handler
global_service_event_handler=xi_service_event_handler
Plus, the only change I made is which scripts get called. So if I indeed "can just use the variables without the mapping: %host%, %hoststate%, etc.", how do I reference these variables within the bash script? Thanks Much, -klee
/usr/local/nagios/libexec/nms_global_host_event_handler.sh --host="%host%" --hoststate=%hoststate% --hoststateid=%hoststateid% --lasthoststate=%lasthoststate% --lasthoststateid=%lasthoststateid% --hoststatetype=%hoststatetype% --currentattempt=%currentattempt% --maxattempts=%maxattempts% --hosteventid=%hosteventid% --hostproblemid=%hostproblemid% --hostoutput="%hostoutput%" --hostdowntime=%hostdowntime%
/usr/local/nagios/libexec/nms_global_service_event_handler.sh --host="%host%" --service="%service%" --hoststate=%hoststate% --servicestate=%servicestate% --servicestateid=%servicestateid% --lastservicestate=%lastservicestate% --lastservicestateid=%lastservicestateid% --servicestatetype=%servicestatetype% --currentattempt=%currentattempt% --maxattempts=%maxattempts% --serviceeventid=%serviceeventid% --serviceproblemid=%serviceproblemid% --serviceoutput="%serviceoutput%" --servicedowntime=%servicedowntime%
global_host_event_handler=xi_host_event_handler
global_service_event_handler=xi_service_event_handler
Plus, the only change I made is which scripts get called. So if I indeed "can just use the variables without the mapping: %host%, %hoststate%, etc.", how do I reference these variables within the bash script? Thanks Much, -klee
/usr/local/nagios/libexec/nms_global_host_event_handler.sh --host="%host%" --hoststate=%hoststate% --hoststateid=%hoststateid% --lasthoststate=%lasthoststate% --lasthoststateid=%lasthoststateid% --hoststatetype=%hoststatetype% --currentattempt=%currentattempt% --maxattempts=%maxattempts% --hosteventid=%hosteventid% --hostproblemid=%hostproblemid% --hostoutput="%hostoutput%" --hostdowntime=%hostdowntime%
/usr/local/nagios/libexec/nms_global_service_event_handler.sh --host="%host%" --service="%service%" --hoststate=%hoststate% --servicestate=%servicestate% --servicestateid=%servicestateid% --lastservicestate=%lastservicestate% --lastservicestateid=%lastservicestateid% --servicestatetype=%servicestatetype% --currentattempt=%currentattempt% --maxattempts=%maxattempts% --serviceeventid=%serviceeventid% --serviceproblemid=%serviceproblemid% --serviceoutput="%serviceoutput%" --servicedowntime=%servicedowntime%
Re: Command Variables vs. Macros
Are you configuring the following command in the global event handler ui (Admin --> Manage Components --> Global Event Handlers --> Edit)?
The script would then handle these like passed variables:
You pass these variables to the bash script and then process them in the bash script as you would any other. For example, in the global event handler ui, lets set a script to be passed %host% and %hoststate%:klee wrote: /usr/local/nagios/libexec/nms_global_host_event_handler.sh --host="%host%" --hoststate=%hoststate% --hoststateid=%hoststateid% --lasthoststate=%lasthoststate% --lasthoststateid=%lasthoststateid% --hoststatetype=%hoststatetype% --currentattempt=%currentattempt% --maxattempts=%maxattempts% --hosteventid=%hosteventid% --hostproblemid=%hostproblemid% --hostoutput="%hostoutput%" --hostdowntime=%hostdowntime%
Code: Select all
/path/to/event/script.sh %host% %hoststate%Code: Select all
#!/bin/bash
HOST=$1
HOSTSTATE=$2
echo "The host: $HOST is in state: $HOSTSTATE"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.
"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.