Home Directory

Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

Directory

thomasemr

Reviews(1)
check_dhcp_free.vbs
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)