Page 1 of 4

used/free ips per scope on the DHCP Server

Posted: Tue Dec 10, 2019 1:12 am
by grayloglearn
Hi Team,

we would like to monitor the used/free ip address per scope on the DHCP server. This will help us to check us how many are free in each scope and how may are used. Do we have such script for this to get the valid data??

We are using the nsclient++ in windows server. Can someone help with the scripts. so that we will check, the script should give output saying as per scope how many are free and how many are used.

Re: used/free ips per scope on the DHCP Server

Posted: Tue Dec 10, 2019 4:29 pm
by mbellerue
Do you already have a plugin that is supposed to check the DHCP scopes? We can try troubleshooting it, if you have one.

Otherwise, I found a Powershell script on the Nagios Exchange that might suit your needs.
https://exchange.nagios.org/directory/P ... es/details

Re: used/free ips per scope on the DHCP Server

Posted: Wed Dec 11, 2019 4:13 am
by grayloglearn
We have used the attached script and we executed that script in windows and we are able to get the data. but when we call from nagios the below errors we are getting.

[root@nagihpc ~]# /usr/local/nagios/libexec/check_nrpe -H DHCPCORP02 -t 120 -c check_DHCP_perscope
Missing expression after unary operator '-'.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : MissingExpressionAfterOperator


And the below are command we have enabled in nsclient.ini

check_DHCP_perscope=cmd /c echo scripts\fari\check_DHCP_perscope.ps1;exit($lastexitcode) | powershell.exe -command –

Re: used/free ips per scope on the DHCP Server

Posted: Wed Dec 11, 2019 12:50 pm
by mbellerue
Okay, I put that code into Powershell ISE, and gave it a once over. I'm not seeing any syntax errors. If you load that script into Powershell ISE (best to copy/paste the text of the script into ISE) and just run the script, what is the output?

Re: used/free ips per scope on the DHCP Server

Posted: Thu Dec 12, 2019 4:40 pm
by mbellerue
That is a lot of output in that script. I'm wondering if there's too much for NRPE to return properly. Let's try narrowing it down to just one scope. Add -a 'one-dhcp-scope-name' to your check_nrpe command. And of course replace "one-dhcp-scope-name" with one of your actual DHCP scope names. See what that gives you, and if you wouldn't mind sending the results of the command back, that would be great. That can be here or in a PM.

Re: used/free ips per scope on the DHCP Server

Posted: Thu Dec 12, 2019 9:29 pm
by grayloglearn
Hi Team,

We don't want go individually we want to check all scopes details should come in single. Let us know how to resolve this.
How the output is coming in windows server while we executing the entire should come in nagios console. Please help on this. If we go individual scope if we have 1000 scope we need to enable 1000 services. Hope you understand.

While we executing the script in windows server the same should display in nagios console. Please help on this. how we can resolve that syntax issue.

[root@nagiht ~]# /usr/local/nagios/libexec/check_nrpe -H DHCPCORP02 -t 120 -c check_DHCP_perscope
Missing expression after unary operator '-'.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : MissingExpressionAfterOperator

Re: used/free ips per scope on the DHCP Server

Posted: Fri Dec 13, 2019 11:00 am
by mbellerue
Oh absolutely I understand. It looked like you had quite a number of DHCP scopes, and that would indeed be a large number of services to create. Another way to go about this would be to make a passive check. If you have an agent like NCPA on your Windows server, it could run the Powershell script, and send the results back via NRDP. You would definitely want this to be a volatile service, and have state stalking enabled.

Does that sound like something you'd like to try?

Re: used/free ips per scope on the DHCP Server

Posted: Sun Dec 15, 2019 8:27 pm
by grayloglearn
Could you please help with to resolve the syntax error. Let us resolve the syntax error first. How to resolve this. We want to resolve the issue. I think if we can resolve this we will get the data from windows server. I know there is huge rows are showing after executing the script.

kindly help us why this error is showing.

[root@nagiht ~]# /usr/local/nagios/libexec/check_nrpe -H DHCPCORP02 -t 120 -c check_DHCP_perscope
Missing expression after unary operator '-'.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : MissingExpressionAfterOperator

Re: used/free ips per scope on the DHCP Server

Posted: Mon Dec 16, 2019 11:28 am
by mbellerue
Well, it could be how ps1 scripts get piped into Powershell, rather than just having Powershell call them. In your nsclient.ini file, try setting up your check like this,

Code: Select all

check_DHCP_perscope = powershell.exe -command C:\Program` Files\NSClient++\scripts\check_DHCP_perscope.ps1

Re: used/free ips per scope on the DHCP Server

Posted: Wed Dec 18, 2019 2:03 am
by grayloglearn
Hi Team,we are getting below error

[root@nagi~]# /usr/local/nagios/libexec/check_nrpe -H dhcpcrp02 -t 120 -c check_DHCP_perscope
C:\Program : The term 'C:\Program' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:1

+ C:\Program Files\NSClient++\scripts\far\check_DHCP_perscope.ps1
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Program:String) [], CommandN
otFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

we have added line as below
check_DHCP_perscope = powershell.exe -command C:\Program Files\NSClient++\scripts\far\check_DHCP_perscope.ps1