
Nagios – Monitoring the scope of our DHCP
What's up txabales!!! How do we usually find out that a DHCP server is down or a scope is full?? Thank you to our dear users, No? As the idea is that our users are the last to notice any problems in our organization (apart from the bosses)… we will take advantage of our monitoring facility based in Nagios or Centreon to control yet another critical point in an organization, DHCP Service!
Apart from monitoring the DHCP service itself that is booted (We already know how to do it), we will rely this time on a Nagios Exchange script which will allow us to measure the health status of the service, using a small script in VBS (Visual Basic Script), We will be able to check each area and its free or busy addresses! We will have to rely on NRPE, since this VBS must be run on every DHCP server, therefore, Download the script 'check_dhcp_scope.vbs’ in the default path of NSCLient scripts ++, if you need help with NRPE, Check out This document!
By the way, I usually modify this script so that in the output of the command it gets the free IPs and the occupied IPs, therefore, If we modify the following lines we would have, but this is optional, eh! I leave you with the changes I make:
Line 75:
[SourceCode]StrOut=Strout&SubnetIP&" is Critical ("&FreeIP&" Free). |Free="&FreeIP&" Busy="&UsedIP[/SourceCode]
Line 79:
[SourceCode]StrOut=Strout&SubnetIP&" is Critical ("&FreeIP&" Free). |Free="&FreeIP&" Busy="&UsedIP[/SourceCode]
Line 96:
[SourceCode]wscript.echo scopecount&" Scopes OK – Free IPs: " &FreeIP& " – IPs Busy: " &UsedIP& "|Free="&FreeIP&" Busy="&UsedIP[/SourceCode]
And if the DHCP server is in another language, for example in Spanish, we must also modify the line 61:
[SourceCode]If you are instigating(oldstr2,"Subnet") then[/SourceCode]
If we open a cmd on the DHCP server and go to the NSClient++ scripts directory, we can run it and see how it responds!
Therefore, as usual, We will modify the file 'nsclient.ini’ defining the script it will run and its alias, Something like this:
[SourceCode][/settings/external scripts/scripts]
check_dhcp = cscript.exe //T:30 //NoLogo scripts\check_dhcp_scope.vbs
[/settings/external scripts/alias]
check_dhcp = check_dhcp[/SourceCode]
Not forgetting to restart the 'NSClient ++' service, Yes? To reload the settings we just applied!
Therefore, if we want to test and validate that the previous steps have been carried out correctly, we will be able to test it from the Nagios shell directly, as usual, We are located in the path of the plugins and we will execute the following to verify that everything will go well:
[SourceCode]./check_nrpe -H DIRECCION_IP_SERVIDOR_DHCP -C check_dhcp[/SourceCode]
And all that remains is to define the Service that will monitor this, we're going to Centreon, a “Configuration” > “Services”, and we add a new one or clone an existing one and modify what is necessary:
- Description: We indicate the name of the monitored service, something that we associate at a glance with what is being monitored, in my case something like 'DHCP Scope'’ it will.
- Linked with Hosts: We relate this Service to the Host where it will run, which will obviously be the DHCP server(s).
- Template: Normally we will associate some template with the service, or the generic one that has the rest of the options configured, Notification Type, Check-up period…
- Check Command: We selected from the combo the already famous 'check_nrpe’ that will allow us to execute the same thing we did by shell, this command was already registered in the initial NRPE document that you will have seen In this document.
- Args: In this case, will be the alias that we have previously defined in the 'nsclient.ini’ server where this will run, in this case 'check_dhcp'.
We record with “Save”,
And after recording the Centreon setup, Export and restart the files as we already know 😉 (And if not, review previous docus that you will see), Well, going to the “Monitoring” we will already see the monitored status, both the DHCP Scopes where we already see and will paint in the graphs the number of free IP addresses, like the busy ones. What I said, it will also be common to monitor if the Windows DHCP Service is up or has fallen, To do this, you can take a look at This other document! Enjoy!