This is a guide on how to add the same service to multiple hosts. Let’s say you’ve decided you want to monitor the Windows Page File Usage on all of your existing windows hosts.
- You have already configured one of your existing hosts with this service check
- This existing service is how you want all of your other hosts configured
1) Using Host Groups
2) Using the XI Config Import Prep Tool
In both examples the following will apply:
- Existing “Template” Host: testhost
- Existing “Template” Service: Page File Usage
- Existing Destination Host #1: server01.mydomain.local
- Existing Destination Host #2: server02.mydomain.local
- Existing Destination Host #3: server03.mydomain.local
- Existing Destination Host #4: server04.mydomain.local
Summary
Nagios XI allows you to create a service that "runs" on a host group instead of a host. When used this way, all the members of that group have this service check applied.
Pros
- Super Quick
- All hosts can have this service configuration changed and it would be applied to all hosts in one step
- Great for applying a standard
- ANY change to this service and it would be applied to all hosts in one step
- If you wanted to customise this service for any host you would need to a)Remove the Host from the host group, b)Duplicate the service and apply it directly to the host
This group will contain all the members that you want the service check to run on.
Open Nagios XI and login as nagiosadmin
- Click the Configure link on the blue bar
- Click the Core Configuration Manager (CCM) link on the left
- Login to CCM as nagiosadmin
- Under the Monitoring menu click Host Groups
- Click the Add New button
- Host group name: host_template_services
- Description: Hosts that use a template service
- Click the Members list Modify icon
- Add the hosts server01.mydomain.local, server02.mydomain.local, server03.mydomain.local and server04.mydomain.local to the Selected pane
- Click the Save button
- Click the Apply Configuration button
- Wait while the changes are applied
- If all goes OK you will receive a Success message
I already have the service Page File Usage defined on testhost. We'll make a copy of this to use as our service for the host group.
- Under the Monitoring menu click Services
- Use the Config name filter to select testhost
- Click the Copy icon for the Page File Usage service
- Use the Config name filter to select testhost (1)
- Click the Modify icon for the Page File Usage service
- Config Name: standard_page_file_usage
- Click the Hosts list Modify icon
- Move the host testhost from the Selected pane to the Available pane
- Click the Save button
- Click the Host Groups list Modify icon
- Move the group host_template_services from the Available pane to the Selected pane
- Click the Save button
- Tick the Active box
- Click the Save button
- Click the Apply Configuration button
- Wait while the changes are applied
- If all goes OK you will receive a Success message
- Click the Home link
- Click the Service Detail link
Note: You can speed this screen update by restarting the Monitoring Engine
You will also notice that when you view each hosts services there will NOT be a Page File Usage service.
That completes this section Using Host Groups to add the same service to multiple hosts.
Using the XI Config Import Prep Tool
Summary
If you wanted to specifically have a service created for each host then this could become a tedious task with lots of hosts. This is a guide on how to help you automate this process.
Pros
- Each host has a service created for Page File Usage
- Great when your service checks require customisations that are specific to each host
- Takes about 15 minutes to complete the task for xxx amount of hosts
- Takes about 15 minutes to complete the task (not that long when you consider the manual option)
- Not the best way to apply a standard
This guide has been created using a Windows 7 PC and hence some additional windows utilities may need to be downloaded. When you need to edit config files listed in the steps below, Notepad will suffice for this.
This guide is based on a running virtual machine of Nagios XI downloaded from the Nagios Enterprise website. If you have your own Nagios XI installation on another Linux distribution and I’m sure if you follow these steps you’ll work out how to adapt it to your installation.
WinSCP is used to transfer the service config file we create into your Nagios XI server http://winscp.net/eng/download.php.
Putty is used to remotely access your Nagios XI server http://www.chiark.greenend.org.uk/~sgtatham/putty/.
WinSCP and Putty
The first time you connect to the Nagios XI server it will present a warning dialog box about the Nagios XI host not being in the local cache, click Yes and you will not be prompted again.
All the steps I use with WinSCP are done using the Commander view. To enable this do the following:
- Click Options > Preferences
- Click Interface on the left menu
- Select the Commander radio button
- Click OK
Obtain Original Config File
Using WinSCP we will retrieve the existing service definition Page File Usage for testhost
Open WinSCP
- Hostname: IP address of your Nagios XI server
- Username: root
- Password: Your root Password (nagiosxi by default)
- Click the Login button
- Click in the right pane
- Click the Open directory/bookmark icon [Remote > Goto > Open directory/bookmark]
- In the remote directory type in /usr/local/nagios/etc/services
- Click OK
- In the left pane browse to C:\Temp (create this directory if it does not exist)
- Drag the testhost.cfg file from the right pane to the left pane
- Click the Copy button
- Wait for the file to copy
- You can minimize WinSCP for the time being, we’ll use it again shortly
The following step can be automated using PowerShell and is explained in detail later on. Following the steps below will help you understand the process before you try to upscale it.
- Open Windows Explorer to C:\Temp
- Rename testhost.cfg to servicesimport.cfg
- Edit servicesimport.cfg
- If the original host testhost had multiple service definitions they will all appear in this file. You need to delete everything except the Page File Usage service. This is all that you should be left with (mine may differ to yours):
Code: Select all
define service {
host_name testhost
service_description Page File Usage
use alert_service_24x7,check_service_24x7,xiwizard_windowsserver_nsclient_service
check_command check_xi_service_nsclient!!COUNTER!-l "\\Paging File(_Total)\\% Usage","Paging File usage is %.2f %%" -w 70 -c 90!!!!!
_xiwizard windowsserver
register 1
}
Make the following change
- host_name server01.mydomain.local
- Highlight all of the text and copy it
- Paste it three times after the original service definition
- host_name server02.mydomain.local
- host_name server03.mydomain.local
- host_name server04.mydomain.local
Code: Select all
define service {
host_name server01.mydomain.local
service_description Page File Usage
use alert_service_24x7,check_service_24x7,xiwizard_windowsserver_nsclient_service
check_command check_xi_service_nsclient!!COUNTER!-l "\\Paging File(_Total)\\% Usage","Paging File usage is %.2f %%" -w 70 -c 90!!!!!
_xiwizard windowsserver
register 1
}
define service {
host_name server02.mydomain.local
service_description Page File Usage
use alert_service_24x7,check_service_24x7,xiwizard_windowsserver_nsclient_service
check_command check_xi_service_nsclient!!COUNTER!-l "\\Paging File(_Total)\\% Usage","Paging File usage is %.2f %%" -w 70 -c 90!!!!!
_xiwizard windowsserver
register 1
}
define service {
host_name server03.mydomain.local
service_description Page File Usage
use alert_service_24x7,check_service_24x7,xiwizard_windowsserver_nsclient_service
check_command check_xi_service_nsclient!!COUNTER!-l "\\Paging File(_Total)\\% Usage","Paging File usage is %.2f %%" -w 70 -c 90!!!!!
_xiwizard windowsserver
register 1
}
define service {
host_name server04.mydomain.local
service_description Page File Usage
use alert_service_24x7,check_service_24x7,xiwizard_windowsserver_nsclient_service
check_command check_xi_service_nsclient!!COUNTER!-l "\\Paging File(_Total)\\% Usage","Paging File usage is %.2f %%" -w 70 -c 90!!!!!
_xiwizard windowsserver
register 1
}
Prepare The Configuration Files
Return to your WinSCP session
- Click the Open directory/bookmark icon [Remote > Goto > Open directory/bookmark]
- In the remote directory type in /usr/local/nagios/etc
- Click OK
- Press F7
- Type cfgprep
- Click OK
- Double click cfgprep
- Press F7
- Type orig
- Click OK
- Double click orig
- In the left pane browse to C:\Temp
- Drag the servicesimport.cfg file from the left pane to the right pane
- Click the Copy button
- Wait for the file to copy
Start a Putty session that connects to your Nagios XI server
- Username: root
- Password: Your root Password (nagiosxi by default)
- Type cd /usr/local/nagios/etc/cfgprep/ and press Enter
- Type php /usr/local/nagiosxi/tools/xiprepimport.php orig/servicesimport.cfg and press Enter
- Type ls -al and press Enter
You should see results like this: - -rw-r--r-- 1 root root 347 Apr 25 22:10 server01.mydomain.local.cfg
- -rw-r--r-- 1 root root 347 Apr 25 22:10 server02.mydomain.local.cfg
- -rw-r--r-- 1 root root 347 Apr 25 22:10 server03.mydomain.local.cfg
- -rw-r--r-- 1 root root 347 Apr 25 22:10 server04.mydomain.local.cfg
These are the configuration files that have been created to import into Nagios XI
Import The Configuration Files
Open Nagios XI and login as nagiosadmin
- Click the Configure link on the blue bar
- Click the Core Configuration Manager (CCM) link on the left
- Login to CCM as nagiosadmin
- Click the menu Tools and then Import Config Files
You should now see your new files listed in the import file list - Hold down CTRL and click:
/usr/local/nagios/etc/cfgprep/server01.mydomain.local.cfg
/usr/local/nagios/etc/cfgprep/server02.mydomain.local.cfg
/usr/local/nagios/etc/cfgprep/server03.mydomain.local.cfg
/usr/local/nagios/etc/cfgprep/server04.mydomain.local.cfg - Click the Import button
If all goes well it will display the message underneath the Import button
Code: Select all
Entry config_name::server01.mydomain.local inside tbl_service successfully inserted Entry config_name::server02.mydomain.local inside tbl_service successfully inserted Entry config_name::server03.mydomain.local inside tbl_service successfully inserted Entry config_name::server04.mydomain.local inside tbl_service successfully inserted
- In the Tools menu on the left click Write Config Files
- Click the Go button for Write monitoring data
Wait while it performs the action, if all is OK it will report success - Click the Go button for Write additional data
Wait while it performs the action, if all is OK it will report success - Click the Go button for Check configuration files
Wait while it performs the action
Depending on your existing config, there may be lots of warnings, this is OK
Total Errors should be 0
Example:Code: Select all
Total Warnings: 207 Total Errors: 0
- In the Quick Tools menu on the left click Apply Configuration
- Click the Apply Configuration button
- Wait while the changes are applied
- If all goes OK you will receive a Success message
Check Service Definitions
- In the Monitoring menu on the left click Services
- Use the Config name filter to select server01.mydomain.local
- Here you should see the new Page File Usage service
- Check the other hosts to confirm they all exist
- After a couple of minutes they should start appearing in Service Detail window (access this from the Home link)
Some files were created during the import process and are no longer required. In this example, the following files were created and should be deleted:
- /usr/local/nagios/etc/cfgprep/orig/servicesimport.cfg
- /usr/local/nagios/etc/cfgprep/servicesimport.cfg
- /usr/local/nagios/etc/cfgprep/server01.mydomain.local.cfg
- /usr/local/nagios/etc/cfgprep/server02.mydomain.local.cfg
- /usr/local/nagios/etc/cfgprep/server03.mydomain.local.cfg
- /usr/local/nagios/etc/cfgprep/server04.mydomain.local.cfg
This section will explain how to use PowerShell to speed up the creation of the servicesimport.cfg file. This will save lots of time if you have a gazillion hosts

Create A List Of Hosts
Start a Putty session that connects to your Nagios XI server
- Username: root
- Password: Your root Password (nagiosxi by default)
- Type cd /tmp and press Enter
- Type ls /usr/local/nagios/etc/hosts -1 >hostlist.csv and press Enter
Open WinSCP
- Hostname: IP address of your Nagios XI server
- Username: root
- Password: Your root Password (nagiosxi by default)
- Click the Login button
- Click in the right pane
- Click the Open directory/bookmark icon [Remote > Goto > Open directory/bookmark]
- In the remote directory type in /tmp
- Click OK
- In the left pane browse to C:\Temp
- Drag the hostlist.csv file from the right pane to the left pane
- Click the Copy button
- Wait for the file to copy
Edit The Host List
- Browse to C:\Temp
- Double click hostlist.csv to open it Notepad
- Press Ctrl + H
- Find what: .cfg
- Replace with: Leave this field empty
- Click the Replace All button
- Click the Cancel button
- Remove any hosts that you DO NOT want the new service to be applied to (like localhost)
- Go to the very beginning of the file
- Add this line so it is the first line of the file
- hostname
- Save the file and Close Notepad
- Open Notepad
- Paste the following into Notepad
Code: Select all
$ConfirmPreference = "None"
$list = Import-Csv "C:\Temp\hostlist.txt"
$ServicesImportFile = "C:\Temp\servicesimport.cfg"
Remove-Item $ServicesImportFile
foreach($entry in $list)
{
Write-Output "define service {" | Out-File $ServicesImportFile -Append -Encoding ASCII
Write-Output " host_name $($entry.hostname)" | Out-File $ServicesImportFile -Append -Encoding ASCII
Write-Output " service_description Page File Usage" | Out-File $ServicesImportFile -Append -Encoding ASCII
Write-Output " use alert_service_24x7,check_service_24x7,xiwizard_windowsserver_nsclient_service" | Out-File $ServicesImportFile -Append -Encoding ASCII
Write-Output " check_command check_xi_service_nsclient!!COUNTER!-l `"\\Paging File(_Total)\\% Usage`",`"Paging File usage is %.2f %%`" -w 70 -c 90!!!!!" | Out-File $ServicesImportFile -Append -Encoding ASCII
Write-Output " _xiwizard windowsserver" | Out-File $ServicesImportFile -Append -Encoding ASCII
Write-Output " register 1" | Out-File $ServicesImportFile -Append -Encoding ASCII
Write-Output " }" | Out-File $ServicesImportFile -Append -Encoding ASCII
Write-Output "" | Out-File $ServicesImportFile -Append -Encoding ASCII
}
NOTE 2: Some additional characters have been added
- Whenever a quotation mark (") is used [inside of quotation marks] an escape character (`) will precede it
- What this does it prevents PowerShell from mistaking the quotation mark as the end of the output
- Specifically:
Write-Output " check_command check_xi_service_nsclient!!COUNTER!-l `"\\Paging File(_Total)\\% Usage`",`"Paging File usage is %.2f %%`" -w 70 -c 90!!!!!" - The quotation marks at the begining and end DO NOT get an escape character (`)
- Save this file as C:\Temp\CreateImportConfig.ps1
- Close Notepad
Run PowerShell as Administrator
- Type cd \temp and press Enter
- Type Set-ExecutionPolicy -ExecutionPolicy Bypass and press Enter
- Press Enter to accept the default answer of Y
Note: If you are not running as Administrator you will get an access denied error message - Type .\CreateImportConfig.ps1 and press Enter
- The script will run relatively quickly and you will end up with a new file called C:\Temp\servicesimport.cfg
- Type notepad C:\Temp\servicesimport.cfg and press Enter
Here you will see the contents of the services that you are going to create in Nagios XI. - Close Notepad
Continue on following the steps in the section Prepare The Configuration Files to complete the import process.
How Can I Use The CentOS ShellTo Automate The Creation Of servicesimport.cfg
Unfortunately my linux experience is minimal; I would appreciate someone telling me how so I could include it in this guide.
Other Notes
The flexibility of Nagios XI is what makes applying configurations in bulk a less time consuming task. This process can easily be applied to create hosts, groups, etc.
The key thing to know is explained on the Import Config Files screen:
- To prevent errors or misconfigurations, you should import your configurations in an useful order. We recommend to do it like this:
commands -> timeperiods -> contacttemplates -> contacts -> contactgroups -> hosttemplates -> hosts -> hostgroups -> servicetemplates -> services -> servicegroups