Windows

check_dhcp_free.vbs

Description:

Get Free Ip From Windows 2003 or 2008 DHCP Server, this script read this command “netsh dhcp server show mibinfo”

Current Version

1.0

Last Release Date

2011-10-21

Compatible With

  • Nagios 2.x
  • Nagios 3.x
  • Nagios XI
  • Nagios Fusion

Owner


Project Files
Project Photos
Project Notes
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
Reviews (3) Add a Review
Portuguese Version - Not necessary subnet argument
by thomasemr, July 31, 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)



French Language
by jbmainson, December 31, 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)



Perfekt Work
by Tonosinai, February 29, 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



Add a Review

You must be logged in to submit a review.

Thank you for your review!

Your review has been submitted and is pending approval.

Recommend

To:


From:


Thank you for your recommendation!

Your recommendation has been sent.

Project Stats
Rating
4.8 (5)
Favorites
0
Views
171,697