NagiosXI 5.7 custom variables in notifications best practice
Posted: Fri Jan 15, 2021 10:58 am
I am trying to populate the "client" variable from Nagios to Pagerduty. I know I can do this from pdagent with the -f flag but do you know what variable I can use or where I can set that variable in Nagios itself?
Here is a sample of my notification command:
/usr/share/pdagent-integrations/bin/pd-nagios -n host -k $CONTACTPAGER$ -t "$NOTIFICATIONTYPE$" -f HOSTNAME="$HOSTNAME$" -f HOSTSTATE="$HOSTSTATE$" -f client="$??????$" -f client_url="%xiserverurl%"
I would like "client" to be set to the client name for the instance. I have never seen this set anywhere in Nagios so I was hoping for some direction in the best place to set this variable and even better, if it could be set via a script. I currently have the "pager" variable defined in the "pagerduty" contact and could likely set it there but I would prefer that I get some guidance on best practices. I have never seen a way to set any variables via the API so if this is not possible, could I add this as a request for a future version?
I would also like to set "client_url" to the server name. I found the %xiserverurl% in this document:
https://assets.nagios.com/downloads/nag ... =209668515
It is not the correct format that I can tell. Is there a way to reference this in a notification? Currently we use IP addresses for the server url in the config as we do not have DNS at these sites. Will this variable just return that IP address or is there a way to set it in the gui to a name that will not resolve but still not break the system? Basically, if I change the Nagios URL, will it break anything? Is there an alternate method to get the real server hostname from the OS and add it to a notification?
Here is a sample of my notification command:
/usr/share/pdagent-integrations/bin/pd-nagios -n host -k $CONTACTPAGER$ -t "$NOTIFICATIONTYPE$" -f HOSTNAME="$HOSTNAME$" -f HOSTSTATE="$HOSTSTATE$" -f client="$??????$" -f client_url="%xiserverurl%"
I would like "client" to be set to the client name for the instance. I have never seen this set anywhere in Nagios so I was hoping for some direction in the best place to set this variable and even better, if it could be set via a script. I currently have the "pager" variable defined in the "pagerduty" contact and could likely set it there but I would prefer that I get some guidance on best practices. I have never seen a way to set any variables via the API so if this is not possible, could I add this as a request for a future version?
I would also like to set "client_url" to the server name. I found the %xiserverurl% in this document:
https://assets.nagios.com/downloads/nag ... =209668515
It is not the correct format that I can tell. Is there a way to reference this in a notification? Currently we use IP addresses for the server url in the config as we do not have DNS at these sites. Will this variable just return that IP address or is there a way to set it in the gui to a name that will not resolve but still not break the system? Basically, if I change the Nagios URL, will it break anything? Is there an alternate method to get the real server hostname from the OS and add it to a notification?