Custom variables inside of Commands

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
mirann
Posts: 6
Joined: Sun Aug 25, 2013 9:54 pm

Custom variables inside of Commands

Post 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?
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Custom variables inside of Commands

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
mirann
Posts: 6
Joined: Sun Aug 25, 2013 9:54 pm

Re: Custom variables inside of Commands

Post 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?
You do not have the required permissions to view the files attached to this post.
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Custom variables inside of Commands

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
mirann
Posts: 6
Joined: Sun Aug 25, 2013 9:54 pm

Re: Custom variables inside of Commands

Post by mirann »

That did it. I could have sworn I tried that variation, but I guess not.
Thanks for your help!
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Custom variables inside of Commands

Post 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
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked