Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
check_dhcp_free.vbs
1.0
2011-10-21
- Nagios 2.x
- Nagios 3.x
- Nagios XI
- Nagios Fusion
171713
File | Description |
---|---|
check_dhcp_free.vbs | check_dhcp_free.vbs |
Meet The New Nagios Core Services Platform
Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.
Monitoring Made Magically Better
- Nagios Core on Overdrive
- Powerful Monitoring Dashboards
- Time-Saving Configuration Wizards
- Open Source Powered Monitoring On Steroids
- And So Much More!
Script encargado de tomando el resultado de un comando en el servidor windows 2003 o 2008, filtrar las ips disponibles en los segmentos de DHCP configurados y retornar el porcentaje de uso.
Integracion con NSClient++, en la seccion [External Scripts] de NSC.ini, incluir la linea:
check_dhcp_free_4=cscript.exe -T:120 -NoLogo scriptscheck_dhcp_free.vbs 172.22.4.0 85 90
Ejemplo de uso desde el servidor dhcp por consola:
cscript check_dhcp_free.vbs <% warning usado> <% critical usado>
Ejemplo: cscript -NoLogo check_dhcp_free.vbs 172.22.4.0 80 90
WARNING: # Ips libres: 80 (89% usado) del segmento: 172.22.4.0 | 'Ips Usadas % 172.22.4.0'=89;80;90;0;100
Integracion con NSClient++, en la seccion [External Scripts] de NSC.ini, incluir la linea:
check_dhcp_free_4=cscript.exe -T:120 -NoLogo scriptscheck_dhcp_free.vbs 172.22.4.0 85 90
Ejemplo de uso desde el servidor dhcp por consola:
cscript check_dhcp_free.vbs
Ejemplo: cscript -NoLogo check_dhcp_free.vbs 172.22.4.0 80 90
WARNING: # Ips libres: 80 (89% usado) del segmento: 172.22.4.0 | 'Ips Usadas % 172.22.4.0'=89;80;90;0;100
Reviews (3)
bythomasemr, July 5, 2013
Portuguese version
This script is not necessary to pass the subnet argument
On Error Resume Next
'**************************************************************
' Ejecugtar el comando en el servidor para ver que redes existen:
' netsh dhcp server show mibinfo
'**************************************************************
'Variables
Dim sendMessageResultCriticalWarning, sendMessageOK, sendMessageResultOK, sendMessageResultCritical, sendMessagewarning, sendMessagecritical, sendMessageResultWarning, i_warning, i_critical, i_ok, current_path, command, command2, strLine, IPsTotal, IPsUso, IPsLivres, IPsLivrespercetual, sendMessage, warning, critical, segmento, IPsocupadaspercentual
'**************************************************************
'Const for return val's
Const intOK = 0
Const intWarning = 1
Const intCritical = 2
Const intUnknown = 3
warning = WScript.Arguments(0)
warning = Int(warning)
critical = WScript.Arguments(1)
critical = Int(critical)
Subnet = "Subnet"
Set fso = CreateObject("Scripting.FileSystemObject")
current_path = fso.GetParentFolderName(wscript.ScriptFullName)
' Comando para chequeo
command = "netsh dhcp server show mibinfo"
Set objShell = CreateObject("WScript.Shell")
Set objWshScriptExec = objShell.Exec(command)
Set objStdOut = objWshScriptExec.StdOut
i_critical = 0
i_ok = 0
i_warning = 0
'Verificar o IPs em Uso e IPs Livres , calcula total etc...
Do until objStdOut.AtEndOfStream
strLine = objStdOut.ReadLine
If InStr(strLine,Subnet) > 0 Then
strScope_array = Split(strLine, "Subnet")
strScope_array2 = Split(strScope_array(1), " ")
strScope = strScope_array2(2)
IPsTotal = 0
IPsUso = 0
IPsLivres = 0
IPsLivrespercetual = 0
IPsocupadaspercentual = 0
' No. of Addresses in use
strLine = objStdOut.ReadLine
IPsUso_array = Split(strLine, ".")
IPsUso_array2 = Split(IPsUso_array(1), " ")
IPsUso = IPsUso_array2(6)
' No. of free Addresses
strLine = objStdOut.ReadLine
IPsLivres_array = Split(strLine, ".")
IPsLivres_array2 = Split(IPsLivres_array(1), " ")
IPsLivres = IPsLivres_array2(5)
IPsUso=Int(IPsUso)
IPsLivres=Int(IPsLivres)
IPsTotal=Int(IPsTotal)
IPsTotal = IPsUso + IPsLivres
IPsLivrespercetual = (IPsLivres*100)/IPsTotal
IPsLivrespercetual=Int(IPsLivrespercetual)
IPsocupadaspercentual = (100-IPsLivrespercetual)
' Validaciones
'Critical
If IPsocupadaspercentual >= critical Then
sendMessagecritical = " # ESCOPO: " & strScope & " IPs livres: " & IPsLivres & " (" & IPsLivrespercetual & "%) Ips Usados: " & IPsUso & " (" & IPsocupadaspercentual & "%) "
sendMessageResultCritical = sendMessageResultCritical + sendMessagecritical
i_critical = i_critical + 1
End If
'Warning
If IPsocupadaspercentual >= warning AND IPsocupadaspercentual 0 Then
WScript.Echo ("WARNING: " + sendMessageResultWarning)
Wscript.Quit(intWarning)
End If
If i_ok > 0 Then
WScript.Echo ("OK: " + sendMessageResultOK)
Wscript.Quit(intOK)
End If
'Si llega hasta aqui, no se conoce el error
sendMessage = "UNKNOWN: Erro no Script"
WScript.Echo sendMessage
Wscript.Quit(intUnknown)
This script is not necessary to pass the subnet argument
On Error Resume Next
'**************************************************************
' Ejecugtar el comando en el servidor para ver que redes existen:
' netsh dhcp server show mibinfo
'**************************************************************
'Variables
Dim sendMessageResultCriticalWarning, sendMessageOK, sendMessageResultOK, sendMessageResultCritical, sendMessagewarning, sendMessagecritical, sendMessageResultWarning, i_warning, i_critical, i_ok, current_path, command, command2, strLine, IPsTotal, IPsUso, IPsLivres, IPsLivrespercetual, sendMessage, warning, critical, segmento, IPsocupadaspercentual
'**************************************************************
'Const for return val's
Const intOK = 0
Const intWarning = 1
Const intCritical = 2
Const intUnknown = 3
warning = WScript.Arguments(0)
warning = Int(warning)
critical = WScript.Arguments(1)
critical = Int(critical)
Subnet = "Subnet"
Set fso = CreateObject("Scripting.FileSystemObject")
current_path = fso.GetParentFolderName(wscript.ScriptFullName)
' Comando para chequeo
command = "netsh dhcp server show mibinfo"
Set objShell = CreateObject("WScript.Shell")
Set objWshScriptExec = objShell.Exec(command)
Set objStdOut = objWshScriptExec.StdOut
i_critical = 0
i_ok = 0
i_warning = 0
'Verificar o IPs em Uso e IPs Livres , calcula total etc...
Do until objStdOut.AtEndOfStream
strLine = objStdOut.ReadLine
If InStr(strLine,Subnet) > 0 Then
strScope_array = Split(strLine, "Subnet")
strScope_array2 = Split(strScope_array(1), " ")
strScope = strScope_array2(2)
IPsTotal = 0
IPsUso = 0
IPsLivres = 0
IPsLivrespercetual = 0
IPsocupadaspercentual = 0
' No. of Addresses in use
strLine = objStdOut.ReadLine
IPsUso_array = Split(strLine, ".")
IPsUso_array2 = Split(IPsUso_array(1), " ")
IPsUso = IPsUso_array2(6)
' No. of free Addresses
strLine = objStdOut.ReadLine
IPsLivres_array = Split(strLine, ".")
IPsLivres_array2 = Split(IPsLivres_array(1), " ")
IPsLivres = IPsLivres_array2(5)
IPsUso=Int(IPsUso)
IPsLivres=Int(IPsLivres)
IPsTotal=Int(IPsTotal)
IPsTotal = IPsUso + IPsLivres
IPsLivrespercetual = (IPsLivres*100)/IPsTotal
IPsLivrespercetual=Int(IPsLivrespercetual)
IPsocupadaspercentual = (100-IPsLivrespercetual)
' Validaciones
'Critical
If IPsocupadaspercentual >= critical Then
sendMessagecritical = " # ESCOPO: " & strScope & " IPs livres: " & IPsLivres & " (" & IPsLivrespercetual & "%) Ips Usados: " & IPsUso & " (" & IPsocupadaspercentual & "%) "
sendMessageResultCritical = sendMessageResultCritical + sendMessagecritical
i_critical = i_critical + 1
End If
'Warning
If IPsocupadaspercentual >= warning AND IPsocupadaspercentual 0 Then
WScript.Echo ("WARNING: " + sendMessageResultWarning)
Wscript.Quit(intWarning)
End If
If i_ok > 0 Then
WScript.Echo ("OK: " + sendMessageResultOK)
Wscript.Quit(intOK)
End If
'Si llega hasta aqui, no se conoce el error
sendMessage = "UNKNOWN: Erro no Script"
WScript.Echo sendMessage
Wscript.Quit(intUnknown)
byjbmainson, December 21, 2012
Good plugin, rewrited for French language (special chars ...) :
' No. of Addresses in use
strLine = objStdOut.ReadLine
mTab = Split(strLine, "=")
mTab2 = Split(mTab(1), " ")
mTab3 = Split(mTab2(1), ".")
IPsUso = mTab3(0)
' No. of free Addresses
strLine = objStdOut.ReadLine
mTab = Split(strLine, "=")
mTab2 = Split(mTab(1), " ")
mTab3 = Split(mTab2(1), ".")
IPsLibres = mTab3(0)
' No. of Addresses in use
strLine = objStdOut.ReadLine
mTab = Split(strLine, "=")
mTab2 = Split(mTab(1), " ")
mTab3 = Split(mTab2(1), ".")
IPsUso = mTab3(0)
' No. of free Addresses
strLine = objStdOut.ReadLine
mTab = Split(strLine, "=")
mTab2 = Split(mTab(1), " ")
mTab3 = Split(mTab2(1), ".")
IPsLibres = mTab3(0)
byTonosinai, February 22, 2012
This plugin is working excellent. For use on System with german language it is neccessary to modify the arrays due to missing ".".
code;
IPsUso_array2 = Split(IPsUso_array(0), " ") ;It is array(0) because of the missing "." after "Anzahl" (Englisch Version is "No.")
IPsLibres_array2 = Split(IPsLibres_array(0), " ")
;Same here
This should also work on systems with other languages.
Kind regards
Stefan
code;
IPsUso_array2 = Split(IPsUso_array(0), " ") ;It is array(0) because of the missing "." after "Anzahl" (Englisch Version is "No.")
IPsLibres_array2 = Split(IPsLibres_array(0), " ")
;Same here
This should also work on systems with other languages.
Kind regards
Stefan