Page 1 of 1

Custom variables inside of Commands

Posted: Tue Oct 20, 2020 2:37 pm
by mirann
Hey folks,
We are looking to do integration with Pagerduty in Nagios XI, and we were hoping to make use of some already defined Free Variables. We have the integration working, but the custom variable doesn't seem to come through.

In our Service and Host Templates, we have defined '_env' in the Free Variables screen. We currently are able to use this field when sending email by calling it as %env% in the Notification Template.
I've tried afew different ways, but none of them seem to actually call the content of the variable, they just send the name.

An example of the code being used, the last bit is my concern. The rest works just fine.

Code: Select all

/usr/share/pdagent-integrations/bin/pd-nagios -n service -k $CONTACTPAGER$ -t "$NOTIFICATIONTYPE$" -f SERVICEDESC="$SERVICEDESC$" -f SERVICESTATE="$SERVICESTATE$" -f HOSTNAME="$HOSTNAME$" -f SERVICEOUTPUT="$SERVICEOUTPUT$" -f SERVINSTANCE="$env$"
Is it possible to call custom variables through the commands setup in CCM?

Re: Custom variables inside of Commands

Posted: Wed Oct 21, 2020 1:52 pm
by benjaminsmith
Hi,
Is it possible to call custom variables through the commands setup in CCM?
Yeah, this can be done, the naming convention will change depending on if it's a host or service object. Take a look at the following guide for a detailed explanation ( see page 8).

https://assets.nagios.com/downloads/nag ... iables.pdf

So, if your free available is named _myvar, and it's a host object, you would actually reference $_HOSTMYVAR$.

The Nagios Core doc is pretty helpful here as well.

https://assets.nagios.com/downloads/nag ... tvars.html

Let me know if you get it going or if you need more assistance.

Benjamin

Re: Custom variables inside of Commands

Posted: Tue Oct 27, 2020 9:50 am
by mirann
Thanks for the info. I've made the changes as described, but still not getting the expected results.
The variable I'm trying to get "_env" is defined in a Host Template only.
I'm able to get this variable to output into email using this setup in the Notification window.
notifications.PNG
I have the PagerDuty commands set like this:
commands.PNG
But the output to PagerDuty shows up like this:
serviceenv.PNG
Any thoughts?

Re: Custom variables inside of Commands

Posted: Wed Oct 28, 2020 2:03 pm
by benjaminsmith
Hi,

The other case is for passing values into those notification templates in Nagios XI that are used by PHPmailer. For the case of Pager Duty, you can drop the usage of notification variables %myvariable%and pass the system level macro to the command $_HOSTENV$ instead. In this case, you'll be using the custom variable as a macro.

Let us know if that works now.

Benjamin

Re: Custom variables inside of Commands

Posted: Wed Oct 28, 2020 3:54 pm
by mirann
That did it. I could have sworn I tried that variation, but I guess not.
Thanks for your help!

Re: Custom variables inside of Commands

Posted: Wed Oct 28, 2020 4:29 pm
by scottwilkerson
mirann wrote:That did it. I could have sworn I tried that variation, but I guess not.
Thanks for your help!
Great!

Locking thread