![Picture of Shamas Demoret](https://library.nagios.com/wp-content/uploads/2024/11/Shamas-Demoret-Grayscale.webp)
Table of Contents
Take Action! Leverage Custom Quick Actions in Nagios XI
- Updated on
![Picture of Shamas Demoret](https://library.nagios.com/wp-content/uploads/2024/11/Shamas-Demoret-Grayscale.webp)
![A graphic of custom quick actions in nagios xi](https://library.nagios.com/wp-content/uploads/2025/01/take-action.png)
You may already be familiar with the event handlers function of Nagios XI, which enables you to execute automated scripted actions in response to problems Nagios detects. This automated method enables you to do anything from pushing information to your ticketing system to restarting key system services XI finds to be in a stopped state.
But did you know that Nagios XI also provides a built-in way to execute scripts and navigate to URLs by clicking on icons in the Quick Actions section of your Hosts Status and Service Status Detail pages? In this article we’ll take a look at the powerful Nagios XI Actions component.
Setting Up Your Actions
To begin setting up your custom Actions, navigate to Admin -> System Extensions -> Manage Components -> Actions, and click the gear icon:
![Take Action! Leverage Custom Quick Actions in Nagios XI 1 A picture of the Nagios XI menu, with the path to the Actions component highlighted.](https://library.nagios.com/wp-content/uploads/2025/01/Actions-getting-to-1024x437.png)
Here you can view, create, and edit your Actions. You’ll notice that a couple of simple example Actions are already present, designed to run a Google search for your Host Names or Service Names, and a button at the bottom of the menu to add a row (+ Add Row), which you’ll click to add a new Action.
In this article we’ll use the example of Actions which will start and stop the spooler service on a Windows host we’re monitoring with NCPA (the Nagios Cross Platform Agent):
![Take Action! Leverage Custom Quick Actions in Nagios XI 2 A look at the settings for an Action which will be used to restart the spooler service on an Windows machine.](https://library.nagios.com/wp-content/uploads/2025/01/Actions-spooler-action-settings-1024x330.png)
For Object Type, we’ve selected ‘Service’, so that our icon will appear on any Nagios services that match our other settings. For Host, we’ve selected a Windows host, placing the Host Name between forward slashes. For Service, we’ve selected the ‘Spooler’ Service Name on the Windows host, also between forward slashes. Note that you can also choose to apply the Action to entire Hostgroups and Servicegroups to quickly add an icon and function to many objects.
Action Text defines how our icon will be labelled in Status Detail pages it appears on. For Action Type we’ve selected ‘Command’, so that XI knows we wish to execute a command when our Action icon is clicked. Just below in the URL/Command field, we’ve added: /usr/local/nagios/libexec/check_ncpa.py -H 192.168.123.45 -P 5693 -t sometoken -M 'plugins/start_service.bat' -a spooler
This command executes the check_ncpa.py
plugin with all of the arguments that follow. Of course in your commands, you’ll want to include your own Windows IP address after -H
, your own token after -t
, the name of the plugin you wish to execute via check_ncpa.py after -M
, and the name of the system service to restart after -a
in the event that you’re executing the plugin via NCPA. You can also restart Windows services with NRPE on NSClient++, Linux services with NCPA or NRPE, or with no agent at all using methods like SSH, so there are many options.
The restart_service.bat script we wish to execute lives in: C:\Program Files\Nagios\NCPA\plugins
on our Windows host, and contains the following text:
@echo off
net start %1
@exit 0
The -a
argument we pass when XI executes the check_ncpa.py plugin will take the place of the %1
portion of our script, in this case spooler
.
Finally, in the Code section on the far right of our Action settings, we’ve pared down the example code as follows:
if ('%servicestateid%'!='0') {
$img = '/nagiosxi/images/wizardwand.png';
$showlink = true;
} else {
$showlink = false;
}
We removed the leading and trailing /*
and */
to uncomment the code, and set it so that if the state of the service (the %servicestateid%
macro, see pages 12 and 13 of the guide for a complete list) is either warning or critical, the icon will appear. However, if the state of the service is OK, the icon will be hidden. In Nagios, an OK state returns a 0, a Warning state a 1, and a Critical state a 2. So, !='0'
means any state other than 0/OK will make our icon appear.
Alternately, to make the icon appear if the system service is in an OK state (for example if you wanted an option to stop one that was currently running), you would use ('%servicestateid%'=='0')
. For our icon, we’ve chosen wizardwand.png
. There are a wide variety of icons you can choose from in the following directory: /usr/local/nagiosxi/html/images
Some that are well-suited for use in your custom Actions are:
d_restart.gif, d_start.gif, d_stop.gif, editsettings.png (a wrench), eye.png, server_go.png,
transmit.png, transmit_add.png, transmit_go.png, transmit_delete.png, wizardwand.png,
lightning.png
Although many are sized correctly to work as Actions icons, the following are too large and will cause issues, so should be avoided:
apple-touch-icon.png, apple-touch-icon-precomposed.png, close_large.png,
close_large_hover.png, config_wizard.png,favicon-32.32.png, footer_lodyas.png,
footer_lodyas_dark.png, glyphicons-halflings.png, glyphicons-halflings-white.png,
loginsplash.png, nagios_critial_larg.png, nagios_logo_white.transbg.png, nagios_ok_large.png,
nagios_pending_large.png, nagios_unknown_large.png,nagios_warning_large.png,nagiosxi-logo
small.png, pending_medium.png, shattered.png, tacdisabled,png, tacdisabledi.png,
tacdisabledu.png, tacenabled.png, tacenabledu.png, techsupport-splash.png, techsupport
splash2.png
Simply replace wizardwand.png
in the above snippet with the name of whichever icon you’d like to use to customize your Actions icon. Once your settings are in place, make sure that the Enable custom actions in Nagios XI checkbox is clicked at the top of the menu, that the Enabled checkbox is clicked for your new Action, and then click Apply Settings at the bottom of the menu.
Take Action!
Now that we’ve set up our Action, let’s see it…in action! Here’s a look at the ‘Spooler’ Service Status Detail page when the Windows service is found to be stopped. As you can see, a ‘Start Spooler’ action with a wizard wand icon is now available in the Quick Actions section:
![Take Action! Leverage Custom Quick Actions in Nagios XI 3 The 'Start Spooler' action icon in the Service Status Detail page for a Windows host.](https://library.nagios.com/wp-content/uploads/2025/01/Windows-Actions-Spooler.png)
To restart spooler, all we need to do is click the icon. This will execute our service_restart.sh
script, and a new tab will open showing us the output:
![Take Action! Leverage Custom Quick Actions in Nagios XI 4 The output from running the Start Spooler Action, showing success.](https://library.nagios.com/wp-content/uploads/2025/01/Actions-starting-spooler.png)
Adding to this example, we’ve also set up a second Action to stop spooler when it is running. The Code section of our Stop Spooler action is much like our Start Spooler code, but is looking for a an OK/running state, and is using the lightning.png icon:
if ('%servicestateid%'=='0') {
$img = '/nagiosxi/images/lightning.png';
$showlink = true;
} else {
$showlink = false;
}
![Take Action! Leverage Custom Quick Actions in Nagios XI 5 An image of the Stop Spooler Action, using a lightning bolt icon](https://library.nagios.com/wp-content/uploads/2025/01/Actions-stop_lightning.png)
Our Command is almost identical, but is calling a stop_service.bat
script rather than a start_service.bat
script which contains:
@echo off
net stop %1
@exit 0
Actions URLs
The Actions component can also be used to add a clickable link to any URL you wish in your Status Detail pages. For example, linking to internal Knowledge Base resources related to the monitored object, a ticketing interface, or the webpage being monitored in the case of website monitoring. This guide explains how to set up Actions URLs, a quick and easy process.
Since Actions can execute anything you can script for, and link to external URLs, the possibilities are virtually endless! The Nagios XI Actions component is sure to prove valuable by helping you carry out common management and remediation tasks on your monitored systems and applications with the click of a button.
Share this post
Tags: