Share this post

Table of Contents

Custom Variables in Nagios XI

|

Picture of Michael Bellerue
Michael Bellerue
Technical Sales Engineer
This image shows the Core Config Manager section of the Nagios XI web interface. A host definition is open to the Misc Settings tab, and the Manage Custom Variables menu is in the foreground.

These days, having a Configuration Management Database (CMDB) is a must. While Nagios XI is not built for managing your configurations, you can put some helpful information about your hosts and services into Nagios XI using Custom Variables. Once the custom variables are there, the information will be right at your fingertips in the very moment you need it most.

How To Configure Custom Variables

Custom variables can be created on an individual host or service, or they can be configured in a host or service template.

To start off, let’s look at how to create custom variables. In this example, we will add them to a host in Nagios XI interface.

  1. Hover over the gear icon on the left menu, and select the Core Config manager.
  2. In the Core Config Manager, click on Hosts
  3. Select a host you want to give custom information. This will bring you to the Host Management screen.
  4. In this screen, select the Misc Settings tab, and then click on the Manage Custom Variables button in the right column. This will bring up a Manage Custom Variables window.
  5. Here you have a Name field and a Value field.
    • Things to keep in mind when filling out the Name field
      • The beginning of the variable name should always be an underscore ( _ )
      • It is best practice for the variable names to be all lower case, or all upper case
      • Avoid special characters like spaces, and ampersands
  6. With those in mind, let’s create a variable named _ncpa_token.
    • You can see here I used an underscore in place of a space.
  7. For the Value, we’ll want whatever the host’s NCPA token actually is. In my case, I use a super secure token, ‘ASecretToken’.

Ideas For Using Custom Variables

Custom Variables can be referenced in host or service checks, Event Handlers, and through Nagios XI’s API. Any piece of information you think is relevant to the host or service can be placed via a custom variable. It might be a Dell service tag ID for a server or maybe the Windows service name of a service you are monitoring, for use with an Event Handler to attempt to restart the service.

Image of the Nagios XI Core Configuration Manager, looking at a Host Template, under Misc Settings, the Manage Custom Variables menu is up. Among the custom variables shown are '_ncpa_port', '_ncpa_token', '_cpu_warning', and '_cpu_critical'
Here I have added custom variable to a Host Template defining the NCPA port number and secret token, as well as CPU warning and critical thresholds.

Custom variables can be assigned to hosts or services. Personally, I’m a fan of assigning variables to hosts, because you can create a generalized service check referenced by multiple hosts (typically known as Hostgroup Inheritance). Then when Nagios runs a service check for any host with the specific custom variable, it will pull the custom variable from the host and insert it into the service check.

Image of Nagios XI Core Configuration Manager looking at a specific Service Check. Highlighted items are the 'Manage Hosts' button showing 0, the 'Manage Host Groups' button showing 1, the $ARG1$ position showing '$_HOSTNCPA_PORT$', the $ARG2$ position showing '$_HOSTNCPA_TOKEN$', the $ARG4$ position showing '-w $_HOSTCPU_WARNING$ -c $_HOST' and then it cuts off, but presumably it is '-c $_HOSTCPU_CRITICAL$'
This service is assigned to a hostgroup rather than a host, thus this service is distributed via Hostgroup Inheritance. In the service check arguments section, you can see I am referring to some of those custom host variables.

Note: In the previous image, the variables were defined like, _ncpa_port, lower case, with an underscore in front. When referencing the variables, it’s _HOSTNCPA_PORT, capitalized with underscore host in front denoting it is a custom variable defined at the host level.

This type of setup will add a ton of value for:

  • Customers who need a different secret token for each system running NCPA
  • Customers who are utilizing Hostgroup Inheritance
  • Customers who need or want certain data to be available at a couple of clicks

When looking at dashboards in Nagios XI, you may find a host has gone down. Depending on the dashlet you are looking at, you can click into the host and see all of the custom variables you have defined for the host. This can be very useful for network operation centers where you may have a process for ordering replacement hardware for your servers. Not having to access another application to get the system’s manufacturer ID number could help System Administrators get parts ordered faster.

Image showing the Custom Variables tab in the Host Status Detail page in Nagios XI. The host in question has several custom variables defined, including 'cpu_critical', 'cpu_warning', 'ncpa_port', and 'ncpa_token'.
The Custom Variables tab in the Host Status Detail screen for a specific server.

Additionally, automating workflows based around the status of a given host or its service checks could be created by pulling custom variable information from Nagios XI’s API. For example, host variables for Ansible could be defined as custom variables in Nagios XI. Then Ansible could use Nagios XI as an Ansible inventory source, and have connection information centralized in Nagios XI.

Image showing the output of the ansible-inventory command. The output shows a host with some Ansible specific information associated with it, such as 'ansible_connection', 'ansible_ssh_private_key_file', and 'ansible_user'.
This is the ansible-inventory command querying Nagios XI’s API for a list of hosts and custom variables.

With custom variables, the only limitation is your imagination!