1
0
mirror of https://github.com/opinkerfi/nagios-plugins.git synced 2024-12-23 01:23:55 +01:00

VB Scripts for WMI added

This commit is contained in:
Páll Guðjón Sigurðsson 2010-05-31 11:03:56 +00:00
parent 6ba2a12b32
commit e03f590221
21 changed files with 12893 additions and 0 deletions

View File

@ -0,0 +1,7 @@
File name: CHANGELOG.txt
Revision: HEAD
Date: December 5, 2008
Author: Dr. Dave Blunt at GroundWork Open Source Inc. (dblunt@groundworkopensource.com)
=============================================================================================
This file is deprecated. Please use 'WMI agentless plugins.pdf'.

View File

@ -0,0 +1,7 @@
File name: INSTALL.txt
Revision: HEAD
Date: December 5, 2008
Author: Dr. Dave Blunt at GroundWork Open Source Inc. (dblunt@groundworkopensource.com)
=============================================================================================
This file is deprecated. Please use 'WMI agentless plugins.pdf'.

View File

@ -0,0 +1,7 @@
File name: README.txt
Revision: HEAD
Date: December 5, 2008
Author: Dr. Dave Blunt at GroundWork Open Source Inc. (dblunt@groundworkopensource.com)
=============================================================================================
This file is deprecated. Please use 'WMI agentless plugins.pdf'.

Binary file not shown.

View File

@ -0,0 +1,896 @@
' Copyright 2007 GroundWork Open Source Inc.
'
' This program is free software; you can redistribute it and/or
' modify it under the terms of the GNU General Public License
' as published by the Free Software Foundation; version 2
' of the License.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
'
' Author Dr. Dave Blunt at GroundWork Open Source Inc. (dblunt@groundworkopensource.com)
'*************************************************************************************************
' Public Variable
'*************************************************************************************************
Const intOK = 0
Const intWarning = 1
Const intCritical = 2
Const intError = 3
Const intUnknown = 3
Dim argcountcommand
Dim arg(20)
Dim strComputer
Dim strClass
Dim strProp
Dim strInst
Dim warningValue
Dim warningValueString
Dim criticalValue
Dim criticalValueString
Dim strUser
Dim strPass
Dim strDomain
Dim strNameSpace
Dim strDescription
Dim strCommandName
Dim strResultTemp
Dim strResult
Dim strResult1
Dim strResult2
Dim intReturnTemp
Dim intReturn
Dim strResultTemp1
Dim strResultTemp2
Dim strResultTemp3
Dim strResultTemp4
Dim intReturnTemp1
Dim strPrefix
Dim returnValue
Dim strPropBase
Dim strNameTemp
Dim strPropNameTemp
Dim counterValueArray()
Dim timerValueTempArray()
Dim strNameArray()
Dim intValueArray()
Dim strPropName
Dim instanceArray()
Dim instanceArraySize
Dim warningArraySize
Dim criticalArraySize
Dim warningArray()
Dim criticalArray()
Dim instance
Dim propArray()
Dim propArraySize
Dim lWarningValue
Dim uWarningValue
Dim lCriticalValue
Dim uCriticalValue
Dim ArgCount
Dim strArgMain(10)
Dim strArgSortDes(10)
Dim strArgDetailDes(10)
Dim strArgExample(10)
Dim objWMIService, colWMI, colWMITemp, objWMI, objSWbemLocator
strComputer=""
strClass = ""
strProp = ""
strInst = ""
warningValue = -1
criticalValue = -1
strUser = ""
strPass = ""
strDomain = ""
intReturnTemp1 = 0
'*************************************************************************************************
' Functions and Subs
'*************************************************************************************************
'-------------------------------------------------------------------------------------------------
'Function Name: f_Error.
'Descripton: Display an error notice include : Error Number and Error Description.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Error()
nbrError = err.number
if (nbrError <> 0 ) then
Select Case nbrError
Case 462, -2147023174
strExitMsg = "Timeout connecting to WMI on this host! Error Number: " & nbrError & " Description: " & err.description
Case -2147024891
strExitMsg = "Authentication failure to remote host! Error Number: " & nbrError & " Description: " & err.description
Case -2147217392
strExitMsg = "Error! Number: " & nbrError & " Description: Invalid Class"
Case Else
strExitMsg = "Error! Number: " & nbrError & " Description: " & err.description
End Select
wscript.echo strExitMsg
wscript.quit(intUnknown)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_Help.
'Descripton: Display help of command include : Description, Arguments, Examples
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Help()
Dim str
str="Check 100NSEC TIMER. If your Local Machine has the same Administrator account and password as the Remote Machine then you don't have to use the two last parameters."&vbCrlF&vbCrlF
str=str&"cscript check_100nsec_timer.vbs -h hostname -class classname -prop property -inst instancename [-w warning_level -c critical_level] [-user username -pass password [-domain domain]]"&vbCrlF
str=str&vbCrlF
str=str&"-h [--help] Help."&vbCrlF
str=str&"-h hostname Host name."&vbCrlF
str=str&"-class classname Class name."&vbCrlF
str=str&"-prop property Property of Class."&vbCrlF
str=str&"-inst instance Needed Instance, can be * for all"&vbCrlF
str=str&"-w warning_level Warning threshold."&vbCrlF
str=str&"-c critical_level Critical threshold."&vbCrlF
str=str&"-user username Account Administrator on Remote Machine."&vbCrlF
str=str&"-pass password Password Account Administrator on Remote Machine."&vbCrlF
str=str&"-domain domain Domain Name of Remote Machine."&vbCrlF
str=str&vbCrlF
str=str&"Example: cscript check_100nsec_timer.vbs -h Ser1 -class Win32_PerfRawData_PerfOS_Processor -prop PercentUserTime -inst ""*"" -w 30 -c 70 [-user Ser1\Administrator -pass password -domain ITSP] "&vbCrlF
str=str&"Example: cscript check_100nsec_timer.vbs -h Ser1 -class Win32_PerfRawData_PerfOS_Processor -prop PercentUserTime -inst ""Name = '0'"" -w 30 -c 70 [-user Ser1\Administrator -pass password -domain ITSP] "
wscript.echo str
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetAllArg.
'Descripton: Get all of arguments from command.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetAllArg()
On Error Resume Next
Dim i
argcountcommand=WScript.Arguments.Count
for i=0 to argcountcommand-1
arg(i)=WScript.Arguments(i)
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetOneArg.
'Descripton: Get an argument from command.
'Input: Yes.
' strName: Name of argument
'Output: Value.
'-------------------------------------------------------------------------------------------------
Function f_GetOneArg(strName)
On Error Resume Next
Dim i
for i=0 to argcountcommand-1
if (Ucase(arg(i))=Ucase(strName)) then
f_GetOneArg=arg(i+1)
Exit Function
end if
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInstance.
'Descripton: Get infomation at Local Host.
'Input: instance.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetInstance(instance)
On Error Resume Next
strResultTemp1 = ""
strResultTemp2 = ""
strResultTemp = ""
intResultTemp = 0
strPropBase = ""
strInstanceTemp1 = ""
strInstanceTemp2 = ""
intInstanceTemp1 = 0
intInstanceTemp2 = 0
'Depend on strInfo parameters to get the result value
if(instance = "*") then
strQuery = "Select " & strProp & ", TimeStamp_Sys100NS" & " from " & strClass
Set colWMITemp = objWMIService.ExecQuery(strQuery)
Wscript.Sleep(1000)
Set colWMI = objWMIService.ExecQuery(strQuery)
else
'Depend on strInfo parameters to get the result value
intInstanceTemp1 = InStr(1,instance,"=")
strInstanceTemp1 = Mid(instance,1,intInstanceTemp1-1)
intInstanceTemp2 = Len(instance)
strInstanceTemp2 = Mid(instance,intInstanceTemp1+1,intInstanceTemp2-intInstanceTemp1)
instance=strInstanceTemp1 & "='" & strInstanceTemp2 & "'"
strQuery = "Select " & strProp & ", TimeStamp_Sys100NS" & " from " & strClass & " where " & instance
Set colWMITemp = objWMIService.ExecQuery(strQuery)
Wscript.Sleep(1000)
Set colWMI = objWMIService.ExecQuery(strQuery)
end if
count = -1
count = colWMI.count
if(count = -1) then
Wscript.Echo "Unknown - No data received from WMI;"
Wscript.Quit(intUnknown)
else
if(colWMI.count > 0) then
f_GetData()
strResultTemp1 = strResultTemp1 & strResultTemp3
strResultTemp2 = strResultTemp2 & strResultTemp4
intReturnTemp = intReturnTemp1
Exit Function
else
strResultTemp1 = "Unknown - " & instance &" query: No row returned."
intReturnTemp = intUnknown
Exit Function
end if
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetPrefix.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetPrefix(intValue)
On Error Resume Next
strPrefix = ""
If(warningValue <> "" And criticalValue = "") Then
If (IsNumeric(warningValue)) Then
If (Int(intValue) < Int(warningValue)) Then
returnValue=0
strPrefix= "OK - "
Else
returnValue=1
strPrefix= "Warning - "
End If
Else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
If(warningValue = "" And criticalValue <> "") Then
If (IsNumeric(criticalValue)) Then
If (Int(intValue) < Int(criticalValue)) Then
returnValue=0
strPrefix= "OK - "
Else
returnValue=2
strPrefix= "Critical - "
End If
Else
Wscript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
If (warningValue <> "" And criticalValue <> "") Then
If (IsNumeric(warningValue) And IsNumeric(criticalValue)) Then
if (Int(warningValue) < Int(criticalValue)) then
if (Int(intValue) < Int(warningValue)) then
returnValue=0
strPrefix= "OK - "
else
if (Int(intValue) < Int(criticalValue)) then
returnValue=1
strPrefix= "Warning - "
else
returnValue=2
strPrefix= "Critical - "
end if
end if
else
if (Int(intValue) > Int(warningValue)) then
returnValue=0
strPrefix= "OK - "
else
if (Int(intValue) > Int(criticalValue)) then
returnValue=1
strPrefix= "Warning - "
else
returnValue=2
strPrefix= "Critical - "
end if
end if
end If
Else
Wscript.Echo "Error! Arguments wrong, please verify -w -c parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetPrefixWithRange.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetPrefixWithRange(intValue)
On Error Resume Next
lWarningValue = ""
uWarningValue = ""
lCriticalValue= ""
uCriticalValue= ""
warningReturn = 0
criticalReturn = 0
If(warningValue <> "") Then
f_GetWarningValueFromRange(warningValue)
End If
If(criticalValue <> "") Then
f_GetCriticalValueFromRange(criticalValue)
End If
strPrefix = ""
'verify warning
If((lWarningValue <> "") And (uWarningValue <> "")) Then
If(Int(lWarningValue) <= Int(uWarningValue)) Then
If((Int(lWarningValue) >= Int(intValue)) Or (Int(intValue) >= Int(uWarningValue))) Then
warningReturn=1
End If
Else
If((Int(intValue) >= Int(uWarningValue) ) And (Int(intValue) <= Int(lWarningValue))) Then
warningReturn=1
End If
End If
End If
If((lWarningValue <> "") And (uWarningValue = "")) Then
If(Int(intValue) <= Int(lWarningValue)) Then
warningReturn=1
End If
End If
If((lWarningValue = "") And (uWarningValue <> "")) Then
If(Int(intValue) >= Int(uWarningValue)) Then
warningReturn=1
End If
End If
'verify critical
If((lCriticalValue <> "") And (uCriticalValue <> "")) Then
If(Int(lCriticalValue) <= Int(uCriticalValue)) Then
If((Int(lCriticalValue) >= Int(intValue)) Or (Int(intValue) >= Int(uCriticalValue))) Then
criticalReturn=2
End If
Else
If((Int(intValue) >= Int(uCriticalValue) ) And (Int(intValue) <= Int(lCriticalValue))) Then
criticalReturn=2
End If
End If
End If
If((lCriticalValue <> "") And (uCriticalValue = "")) Then
If(Int(intValue) <= Int(lCriticalValue)) Then
criticalReturn=2
End If
End If
If((lCriticalValue = "") And (uCriticalValue <> "")) Then
If(Int(intValue) >= Int(uCriticalValue)) Then
criticalReturn=2
End If
End If
'return result
If(criticalReturn = 2) Then
returnValue=2
strPrefix= "Critical - "
Else
If(warningReturn = 1) Then
returnValue=1
strPrefix= "Warning - "
Else
returnValue=0
strPrefix= "Ok - "
End If
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetWarningValueFromRange().
'Descripton: Get perform value at Local Host.
'Input: warningValueRange.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetWarningValueFromRange(warningValue)
On Error Resume Next
lWarningValue = ""
uWarningValue = ""
temp1 = 0
temp1 = InStr(1, warningValue, ":")
if(temp1 > 0) then
lWarningTemp = Mid(warningValue, 1, temp1 -1)
uWarningTemp = Mid(warningValue, temp1 +1, len(warningValue) - temp1)
if(IsNumeric(lWarningTemp) or IsNumeric(uWarningTemp)) then
lWarningValue = lWarningTemp
uWarningValue = uWarningTemp
else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
end if
else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetCriticalValueFromRange().
'Descripton: Get perform value at Local Host.
'Input: warningValueRange.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetCriticalValueFromRange(criticalValue)
On Error Resume Next
lCriticalValue = ""
uCriticalValue = ""
temp1 = 0
temp1 = InStr(1, criticalValue, ":")
if(temp1 > 0) then
lCriticalTemp = Mid(criticalValue, 1, temp1 -1)
uCriticalTemp = Mid(criticalValue, temp1 +1, len(criticalValue) - temp1)
if(IsNumeric(lCriticalTemp) or IsNumeric(uCriticalTemp)) then
lCriticalValue = lCriticalTemp
uCriticalValue = uCriticalTemp
else
Wscript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
end if
else
WScript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetData.
'Descripton: Format data the same as output.
'Input: no.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetData()
On Error Resume Next
ReDim strNameArray(Int(colWMI.count))
ReDim counterValueArray(Int(colWMI.count))
ReDim timerValueArray(Int(colWMI.count))
ReDim intValueArray(Int(colWMI.count))
strDisplay1 = ""
strDisplay2 = ""
strResultTemp3 = ""
strResultTemp4 = ""
'strResultTemp1 = ""
strNameTemp = ""
strPropNameTemp = ""
counterValueTemp = 0
timerValueTemp = 0
timeBaseTemp = 0
i, j = 0
For Each objWMITemp in colWMITemp
counterValueArray(i) = objWMITemp.Properties_(strProp)
timerValueArray(i) = objWMITemp.Properties_("TimeStamp_Sys100NS")
i = i + 1
Next
For Each objWMI in colWMI
strNameTemp = objWMI.Name
strPropNameTemp = objWMI.Properties_(strProp).Name
counterValueTemp = objWMI.Properties_(strProp)
timerValueTemp = objWMI.Properties_("TimeStamp_Sys100NS")
strNameArray(j) = strNameTemp
if((timerValueTemp - timerValueArray(j)) = 0) then
intValueArray(j) = 0
else
intValueArray(j) = (100 * (counterValueTemp - counterValueArray(j))) / (timerValueTemp - timerValueArray(j))
end if
j = j + 1
Next
for k = 0 to (Int(colWMI.count) - 1)
strName = strNameArray(k)
Dim strDSName
strDSName = f_FormatDSName(strName)
strPropName = strPropNameTemp
intValue = (intValueArray(k))
if((warningValue <> "") or (criticalValue <> "")) then
strDisplay1 = strName & " '" & strPropName & "'" & " = " & intValue & "; "
strDisplay2 = "'" & strDSName & "'" & "=" & intValue & ";" & warningValue & ";" & criticalValue & ";; "
If(InStr(1, warningValue, ":") > 0 Or InStr(1, criticalValue, ":") > 0) Then
f_GetPrefixWithRange(intValue)
Else
f_GetPrefix(intValue)
End If
strResultTemp3 = strResultTemp3 & strPrefix & strDisplay1
strResultTemp4 = strResultTemp4 & strDisplay2
if( intReturnTemp1 < returnValue) then
intReturnTemp1 = returnValue
end if
else
strResultTemp3 = strResultTemp3 & "OK - " & strName & " '" & strPropName & "'" & " = " & intValue & "; "
strResultTemp4 = ""
end if
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_FormatDSName.
'Descripton: Get infomation at Local Host.
'Input: strName.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_FormatDSName(strName)
On Error Resume Next
first = 1
position1 = 0
position1 = InStr(first, strName, "=")
Dim proc_name
proc_name = ""
If(position1 > 0) Then
proc_name = Mid(strName,position1+1,(Len(strName)-position1))
proc_name = Replace(proc_name,".","_")
proc_name = Replace(proc_name,"-","_")
proc_name = Mid(proc_name,1, 19)
Else
proc_name = Mid(strName,position1+1,(Len(strName)-position1))
proc_name = Replace(proc_name,".","_")
proc_name = Replace(proc_name,"-","_")
proc_name = Mid(proc_name,1, 19)
End If
f_FormatDSName = proc_name
Exit Function
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInformation.
'Descripton: Get information data.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_GetInformation()
On Error Resume Next
strResult = ""
strResult1 = ""
strResult2 = ""
intReturn = 0
instance = strInst
first=1
tam1=10
tam = -1
If(instanceArraySize > 0 and (warningArraySize > 1 Or criticalArraySize > 1)) Then
for i = 0 to instanceArraySize -1
instance = instanceArray(i)
warningValue = warningArray(i)
criticalValue = criticalArray(i)
f_GetInstance(instance)
strResult1 = strResult1 & strResultTemp1
strResult2 = strResult2 & strResultTemp2
if intReturn < intReturnTemp then
intReturn = intReturnTemp
end if
Next
Else
for i = 0 to instanceArraySize -1
instance = instanceArray(i)
f_GetInstance(instance)
strResult1 = strResult1 & strResultTemp1
strResult2 = strResult2 & strResultTemp2
if intReturn < intReturnTemp then
intReturn = intReturnTemp
end if
Next
end if
if(strResult2 = "") then
strResult = strResult1
else
strResult = strResult1 & "|" & strResult2
end if
Wscript.Echo strResult
Wscript.Quit(intReturn)
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInstances.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetInstances()
On Error Resume Next
first = 1
position = 0
instanceArraySize = 0
position = InStr(first, strInst, ",")
if (position = 0) then
instanceTemp = strInst
InstanceArraySize = 1
ReDim instanceArray(instanceArraySize)
instanceArray(0) = instanceTemp
else
do while (position > 0)
instanceTemp = Mid(strInst,first,position - first)
instanceArraySize = instanceArraySize + 1
ReDim Preserve instanceArray(instanceArraySize)
instanceArray(instanceArraySize -1) = Trim(instanceTemp)
first = position + 1
position = InStr(first, strInst, ",")
loop
instanceTemp = Mid(strInst,first,len(strInst))
instanceArraySize = instanceArraySize + 1
ReDim Preserve instanceArray(instanceArraySize)
instanceArray(instanceArraySize -1) = Trim(instanceTemp)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetWarningCriticalValues.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetWarningCriticalValues()
On Error Resume Next
position1 = 0
position2 = 0
position3 = 0
position4 = 0
temp1 = 1
temp2 = 1
warningArraySize = 0
criticalArraySize = 0
'get warning
position2 = InStr(temp1, warningValueString, ",")
If(position2 = 0) then
position2 = Len(warningValueString)+1
end if
If(position2 > position1) then
do while (position2 > position1)
warningPair = Mid(warningValueString, position1 + 1, (position2 - position1 -1))
warningArraySize = warningArraySize + 1
ReDim Preserve warningArray(warningArraySize)
warningArray(warningArraySize -1) = Trim(warningPair)
temp1 = position2 + 1
position1 = position2
position2 = InStr(temp1, warningValueString, ",")
If(position2 = 0) then
position2 = Len(warningValueString)+1
End If
loop
end If
If(Int(warningArraySize) < Int(instanceArraySize)) Then
ReDim Preserve warningArray(instanceArraySize)
For i = 0 To (instanceArraySize - warningArraySize - 1)
warningArray(warningArraySize +i) = warningArray(warningArraySize-1)
Next
warningArraySize = instanceArraySize
End If
'get critical
position4 = InStr(temp2, criticalValueString, ",")
If(position4 = 0) then
position4 = Len(criticalValueString)+1
end if
If(position4 > position3) then
do while (position4 > position3)
criticalPair = Mid(criticalValueString, position3 + 1, (position4 - position3 -1))
criticalArraySize = criticalArraySize + 1
ReDim Preserve criticalArray(criticalArraySize)
criticalArray(criticalArraySize -1) = Trim(criticalPair)
temp2 = position4 + 1
position3 = position4
position4 = InStr(temp2, criticalValueString, ",")
If(position4 = 0) then
position4 = Len(criticalValueString)+1
End If
loop
End If
If(Int(criticalArraySize) < Int(instanceArraySize)) Then
ReDim Preserve criticalArray(instanceArraySize)
For i = 0 To (instanceArraySize - criticalArraySize - 1)
criticalArray(criticalArraySize +i) = criticalArray(criticalArraySize-1)
Next
criticalArraySize = instanceArraySize
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_LocalPerfValue.
'Descripton: Get perform value at Local Host.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_LocalPerfValue()
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\" & strNameSpace)
f_Error()
'Set colInstances = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & strComputer & "\" & strNameSpace).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
f_GetInformation()
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_RemotePerfValue.
'Descripton: Get perform values at Remote Host.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_RemotePerfValue()
On Error Resume Next
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
if (strDomain = "") then
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass )
f_Error()
'Set colInstances = objSWbemLocator.ConnectServer(strComputer, strNamespace , strUser, strPass).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
else
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass,"MS_409","ntlmdomain:" + strDomain )
f_Error()
'Set colInstances = objSWbemLocator.ConnectServer(strComputer, strNamespace , strUser, strPass,"MS_409","ntlmdomain:" & strDomain ).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
end if
objWMIService.Security_.ImpersonationLevel = 3
f_Error()
f_GetInformation()
End Function
'*************************************************************************************************
' Main Function
'*************************************************************************************************
'/////////////////////
strCommandName="check_counter_bulk_count.vbs"
strDescription="Enumerate the needed windows host information."
'/////////////////////
strNameSpace = "root\cimv2"
f_GetAllArg()
tempCount = argcountcommand/2
f_Error()
strClass = ""
if ((UCase(arg(0))="-H") Or (UCase(arg(0))="--HELP")) and (argcountcommand=1) then
f_help()
else
if( ((argcountcommand Mod 2) = 0) and (3 < tempCount < 11)) then
strComputer = f_GetOneArg("-h")
strClass = f_GetOneArg("-class")
strProp = f_GetOneArg("-prop")
strInst = f_GetOneArg("-inst")
f_GetInstances()
warningValue = f_GetOneArg("-w")
warningValueString = f_GetOneArg("-w")
criticalValue = f_GetOneArg("-c")
criticalValueString = f_GetOneArg("-c")
If((warningValueString <> "") Or (criticalValueString <> "")) Then
f_GetWarningCriticalValues()
End if
strUser = f_GetOneArg("-user")
strPass = f_GetOneArg("-pass")
strDomain = f_GetOneArg("-domain")
if((strComputer = "") or (strClass = "") or (strProp = "") or (strInst = "")) then
Wscript.Echo "Error! Arguments wrong, require verify -h -class -prop -inst parameters"
Wscript.Quit(intError)
else
Select Case tempCount
Case 4:
f_LocalPerfValue()
Case 6:
if ((warningValue <> "") and (criticalValue <> "")) then
f_LocalPerfValue()
end if
if ((strUser <> "") and (strPass <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong, please verify -user -pass or -w -c parameters"
Wscript.Quit(intError)
end if
Case 8:
if ((strUser <> "") and (strPass <> "") and (warningValue <> "") and (criticalValue <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong for remote check, please verify -w -c -user -pass parameters"
Wscript.Quit(intError)
end if
Case 9:
if ((strUser <> "") and (strPass <> "") and (warningValue <> "") and (criticalValue <> "") and (strDomain <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong for remote check, please verify -w -c -user -pass -domain parameters"
Wscript.Quit(intError)
end if
Case Else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
End Select
end if
else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
end if
end if

View File

@ -0,0 +1,897 @@
' Copyright 2007 GroundWork Open Source Inc.
'
' This program is free software; you can redistribute it and/or
' modify it under the terms of the GNU General Public License
' as published by the Free Software Foundation; version 2
' of the License.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
'
' Author Dr. Dave Blunt at GroundWork Open Source Inc. (dblunt@groundworkopensource.com)
'*************************************************************************************************
' Public Variable
'*************************************************************************************************
Const intOK = 0
Const intWarning = 1
Const intCritical = 2
Const intError = 3
Const intUnknown = 3
Dim argcountcommand
Dim arg(20)
Dim strComputer
Dim strClass
Dim strProp
Dim strInst
Dim warningValue
Dim warningValueString
Dim criticalValue
Dim criticalValueString
Dim strUser
Dim strPass
Dim strDomain
Dim strNameSpace
Dim strDescription
Dim strCommandName
Dim strResultTemp
Dim strResult
Dim strResult1
Dim strResult2
Dim intReturnTemp
Dim intReturn
Dim strResultTemp1
Dim strResultTemp2
Dim strResultTemp3
Dim strResultTemp4
Dim intReturnTemp1
Dim strPrefix
Dim returnValue
Dim strPropBase
Dim strNameTemp
Dim strPropNameTemp
Dim timeBaseTemp
Dim counterValueArray()
Dim timerValueTempArray()
Dim strNameArray()
Dim intValueArray()
Dim strPropName
Dim instanceArray()
Dim instanceArraySize
Dim warningArraySize
Dim criticalArraySize
Dim warningArray()
Dim criticalArray()
Dim instance
Dim propArray()
Dim propArraySize
Dim lWarningValue
Dim uWarningValue
Dim lCriticalValue
Dim uCriticalValue
Dim ArgCount
Dim strArgMain(10)
Dim strArgSortDes(10)
Dim strArgDetailDes(10)
Dim strArgExample(10)
Dim objWMIService, colWMI, colWMITemp, objWMI, objSWbemLocator
strComputer=""
strClass = ""
strProp = ""
strInst = ""
warningValue = -1
criticalValue = -1
strUser = ""
strPass = ""
strDomain = ""
intReturnTemp1 = 0
'*************************************************************************************************
' Functions and Subs
'*************************************************************************************************
'-------------------------------------------------------------------------------------------------
'Function Name: f_Error.
'Descripton: Display an error notice include : Error Number and Error Description.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Error()
nbrError = err.number
if (nbrError <> 0 ) then
Select Case nbrError
Case 462, -2147023174
strExitMsg = "Timeout connecting to WMI on this host! Error Number: " & nbrError & " Description: " & err.description
Case -2147024891
strExitMsg = "Authentication failure to remote host! Error Number: " & nbrError & " Description: " & err.description
Case -2147217392
strExitMsg = "Error! Number: " & nbrError & " Description: Invalid Class"
Case Else
strExitMsg = "Error! Number: " & nbrError & " Description: " & err.description
End Select
wscript.echo strExitMsg
wscript.quit(intUnknown)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_Help.
'Descripton: Display help of command include : Description, Arguments, Examples
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Help()
Dim str
str="Check Counter bulk count. If your Local Machine has the same Administrator account and password as the Remote Machine then you don't have to use the two last parameters."&vbCrlF&vbCrlF
str=str&"cscript check_counter_bulk_count.vbs -h hostname -class classname -prop property -inst instancename [-w warning_level -c critical_level] [-user username -pass password [-domain domain]]"&vbCrlF
str=str&vbCrlF
str=str&"-h [--help] Help."&vbCrlF
str=str&"-h hostname Host name."&vbCrlF
str=str&"-class classname Class name."&vbCrlF
str=str&"-prop property Property of Class."&vbCrlF
str=str&"-inst instance Needed Instance, can be * for all"&vbCrlF
str=str&"-w warning_level Warning threshold."&vbCrlF
str=str&"-c critical_level Critical threshold."&vbCrlF
str=str&"-user username Account Administrator on Remote Machine."&vbCrlF
str=str&"-pass password Password Account Administrator on Remote Machine."&vbCrlF
str=str&"-domain domain Domain Name of Remote Machine."&vbCrlF
str=str&vbCrlF
str=str&"Example: cscript check_counter_bulk_count.vbs -h Ser1 -class Win32_PerfRawData_PerfOS_System -prop FileControlBytesPerSec -inst ""*"" -w 30 -c 70 [-user Ser1\Administrator -pass password -domain ITSP] "
wscript.echo str
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetAllArg.
'Descripton: Get all of arguments from command.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetAllArg()
On Error Resume Next
Dim i
argcountcommand=WScript.Arguments.Count
for i=0 to argcountcommand-1
arg(i)=WScript.Arguments(i)
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetOneArg.
'Descripton: Get an argument from command.
'Input: Yes.
' strName: Name of argument
'Output: Value.
'-------------------------------------------------------------------------------------------------
Function f_GetOneArg(strName)
On Error Resume Next
Dim i
for i=0 to argcountcommand-1
if (Ucase(arg(i))=Ucase(strName)) then
f_GetOneArg=arg(i+1)
Exit Function
end if
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInstance.
'Descripton: Get infomation at Local Host.
'Input: instance.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetInstance(instance)
On Error Resume Next
strResultTemp1 = ""
strResultTemp2 = ""
strResultTemp = ""
intResultTemp = 0
strPropBase = ""
strInstanceTemp1 = ""
strInstanceTemp2 = ""
intInstanceTemp1 = 0
intInstanceTemp2 = 0
'Depend on strInfo parameters to get the result value
if(instance = "*") then
strQuery = "Select " & strProp & ", TimeStamp_PerfTime, Frequency_PerfTime" & " from " & strClass
Set colWMITemp = objWMIService.ExecQuery(strQuery)
Wscript.Sleep(1000)
Set colWMI = objWMIService.ExecQuery(strQuery)
else
intInstanceTemp1 = InStr(1,instance,"=")
strInstanceTemp1 = Mid(instance,1,intInstanceTemp1-1)
intInstanceTemp2 = Len(instance)
strInstanceTemp2 = Mid(instance,intInstanceTemp1+1,intInstanceTemp2-intInstanceTemp1)
instance=strInstanceTemp1 & "='" & strInstanceTemp2 & "'"
strQuery = "Select " & strProp & ", TimeStamp_PerfTime, Frequency_PerfTime" & " from " & strClass & " where " & instance
Set colWMITemp = objWMIService.ExecQuery(strQuery)
Wscript.Sleep(1000)
Set colWMI = objWMIService.ExecQuery(strQuery)
end if
count = -1
count = colWMI.count
if(count = -1) then
Wscript.Echo "Unknown - No data received from WMI;"
Wscript.Quit(intUnknown)
else
if(colWMI.count > 0) then
f_GetData()
strResultTemp1 = strResultTemp1 & strResultTemp3
strResultTemp2 = strResultTemp2 & strResultTemp4
intReturnTemp = intReturnTemp1
Exit Function
else
strResultTemp1 = "Unknown - " & instance &" query: No row returned."
intReturnTemp = intUnknown
Exit Function
end if
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetPrefix.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetPrefix(intValue)
On Error Resume Next
strPrefix = ""
If(warningValue <> "" And criticalValue = "") Then
If (IsNumeric(warningValue)) Then
If (Int(intValue) < Int(warningValue)) Then
returnValue=0
strPrefix= "OK - "
Else
returnValue=1
strPrefix= "Warning - "
End If
Else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
If(warningValue = "" And criticalValue <> "") Then
If (IsNumeric(criticalValue)) Then
If (Int(intValue) < Int(criticalValue)) Then
returnValue=0
strPrefix= "OK - "
Else
returnValue=2
strPrefix= "Critical - "
End If
Else
Wscript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
If (warningValue <> "" And criticalValue <> "") Then
If (IsNumeric(warningValue) And IsNumeric(criticalValue)) Then
if (Int(warningValue) < Int(criticalValue)) then
if (Int(intValue) < Int(warningValue)) then
returnValue=0
strPrefix= "OK - "
else
if (Int(intValue) < Int(criticalValue)) then
returnValue=1
strPrefix= "Warning - "
else
returnValue=2
strPrefix= "Critical - "
end if
end if
else
if (Int(intValue) > Int(warningValue)) then
returnValue=0
strPrefix= "OK - "
else
if (Int(intValue) > Int(criticalValue)) then
returnValue=1
strPrefix= "Warning - "
else
returnValue=2
strPrefix= "Critical - "
end if
end if
end If
Else
Wscript.Echo "Error! Arguments wrong, please verify -w -c parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetPrefixWithRange.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetPrefixWithRange(intValue)
On Error Resume Next
lWarningValue = ""
uWarningValue = ""
lCriticalValue= ""
uCriticalValue= ""
warningReturn = 0
criticalReturn = 0
If(warningValue <> "") Then
f_GetWarningValueFromRange(warningValue)
End If
If(criticalValue <> "") Then
f_GetCriticalValueFromRange(criticalValue)
End If
strPrefix = ""
'verify warning
If((lWarningValue <> "") And (uWarningValue <> "")) Then
If(Int(lWarningValue) <= Int(uWarningValue)) Then
If((Int(lWarningValue) >= Int(intValue)) Or (Int(intValue) >= Int(uWarningValue))) Then
warningReturn=1
End If
Else
If((Int(intValue) >= Int(uWarningValue) ) And (Int(intValue) <= Int(lWarningValue))) Then
warningReturn=1
End If
End If
End If
If((lWarningValue <> "") And (uWarningValue = "")) Then
If(Int(intValue) <= Int(lWarningValue)) Then
warningReturn=1
End If
End If
If((lWarningValue = "") And (uWarningValue <> "")) Then
If(Int(intValue) >= Int(uWarningValue)) Then
warningReturn=1
End If
End If
'verify critical
If((lCriticalValue <> "") And (uCriticalValue <> "")) Then
If(Int(lCriticalValue) <= Int(uCriticalValue)) Then
If((Int(lCriticalValue) >= Int(intValue)) Or (Int(intValue) >= Int(uCriticalValue))) Then
criticalReturn=2
End If
Else
If((Int(intValue) >= Int(uCriticalValue) ) And (Int(intValue) <= Int(lCriticalValue))) Then
criticalReturn=2
End If
End If
End If
If((lCriticalValue <> "") And (uCriticalValue = "")) Then
If(Int(intValue) <= Int(lCriticalValue)) Then
criticalReturn=2
End If
End If
If((lCriticalValue = "") And (uCriticalValue <> "")) Then
If(Int(intValue) >= Int(uCriticalValue)) Then
criticalReturn=2
End If
End If
'return result
If(criticalReturn = 2) Then
returnValue=2
strPrefix= "Critical - "
Else
If(warningReturn = 1) Then
returnValue=1
strPrefix= "Warning - "
Else
returnValue=0
strPrefix= "Ok - "
End If
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetWarningValueFromRange().
'Descripton: Get perform value at Local Host.
'Input: warningValueRange.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetWarningValueFromRange(warningValue)
On Error Resume Next
lWarningValue = ""
uWarningValue = ""
temp1 = 0
temp1 = InStr(1, warningValue, ":")
if(temp1 > 0) then
lWarningTemp = Mid(warningValue, 1, temp1 -1)
uWarningTemp = Mid(warningValue, temp1 +1, len(warningValue) - temp1)
if(IsNumeric(lWarningTemp) or IsNumeric(uWarningTemp)) then
lWarningValue = lWarningTemp
uWarningValue = uWarningTemp
else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
end if
else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetCriticalValueFromRange().
'Descripton: Get perform value at Local Host.
'Input: warningValueRange.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetCriticalValueFromRange(criticalValue)
On Error Resume Next
lCriticalValue = ""
uCriticalValue = ""
temp1 = 0
temp1 = InStr(1, criticalValue, ":")
if(temp1 > 0) then
lCriticalTemp = Mid(criticalValue, 1, temp1 -1)
uCriticalTemp = Mid(criticalValue, temp1 +1, len(criticalValue) - temp1)
if(IsNumeric(lCriticalTemp) or IsNumeric(uCriticalTemp)) then
lCriticalValue = lCriticalTemp
uCriticalValue = uCriticalTemp
else
Wscript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
end if
else
WScript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetData.
'Descripton: Format data the same as output.
'Input: no.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetData()
On Error Resume Next
ReDim strNameArray(Int(colWMI.count))
ReDim counterValueArray(Int(colWMI.count))
ReDim timerValueArray(Int(colWMI.count))
ReDim intValueArray(Int(colWMI.count))
strDisplay1 = ""
strDisplay2 = ""
strResultTemp3 = ""
strResultTemp4 = ""
'strResultTemp1 = ""
strNameTemp = ""
strPropNameTemp = ""
counterValueTemp = 0
timerValueTemp = 0
timeBaseTemp = 0
i, j = 0
For Each objWMITemp in colWMITemp
counterValueArray(i) = objWMITemp.Properties_(strProp)
timerValueArray(i) = objWMITemp.Properties_("TimeStamp_PerfTime")
i = i + 1
Next
For Each objWMI in colWMI
strNameTemp = objWMI.Name
strPropNameTemp = objWMI.Properties_(strProp).Name
counterValueTemp = objWMI.Properties_(strProp)
timerValueTemp = objWMI.Properties_("TimeStamp_PerfTime")
timeBase = objWMI.Properties_("Frequency_PerfTime")
strNameArray(j) = strNameTemp
if((timerValueTemp - timerValueArray(j)) = 0) then
intValueArray(j) = 0
else
intValueArray(j) = (counterValueTemp - counterValueArray(j)) / ((timerValueTemp - timerValueArray(j)) / timeBase)
end if
j = j + 1
Next
for k = 0 to (Int(colWMI.count) - 1)
strName = strNameArray(k)
Dim strDSName
strDSName = f_FormatDSName(strName)
strPropName = strPropNameTemp
intValue = intValueArray(k)
if((warningValue <> "") and (criticalValue <> "")) then
strDisplay1 = strName & " '" & strPropName & "'" & " = " & intValue & "; "
strDisplay2 = "'" & strDSName & "'" & "=" & intValue & ";" & warningValue & ";" & criticalValue & ";; "
If(InStr(1, warningValue, ":") > 0 Or InStr(1, criticalValue, ":") > 0) Then
f_GetPrefixWithRange(intValue)
Else
f_GetPrefix(intValue)
End If
strResultTemp3 = strResultTemp3 & strPrefix & strDisplay1
strResultTemp4 = strResultTemp4 & strDisplay2
if( intReturnTemp1 < returnValue) then
intReturnTemp1 = returnValue
end if
else
strResultTemp3 = strResultTemp3 & "OK - " & strName & " '" & strPropName & "'" & " = " & intValue & "; "
strResultTemp4 = ""
end if
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_FormatDSName.
'Descripton: Get infomation at Local Host.
'Input: strName.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_FormatDSName(strName)
On Error Resume Next
first = 1
position1 = 0
position1 = InStr(first, strName, "=")
Dim proc_name
proc_name = ""
If(position1 > 0) Then
proc_name = Mid(strName,position1+1,(Len(strName)-position1))
proc_name = Replace(proc_name,".","_")
proc_name = Replace(proc_name,"-","_")
proc_name = Mid(proc_name,1, 19)
Else
proc_name = Mid(strName,position1+1,(Len(strName)-position1))
proc_name = Replace(proc_name,".","_")
proc_name = Replace(proc_name,"-","_")
proc_name = Mid(proc_name,1, 19)
End If
f_FormatDSName = proc_name
Exit Function
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInformation.
'Descripton: Get information data.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_GetInformation()
On Error Resume Next
strResult = ""
strResult1 = ""
strResult2 = ""
intReturn = 0
instance = strInst
first=1
tam1=10
tam = -1
If(instanceArraySize > 0 and (warningArraySize > 1 Or criticalArraySize > 1)) Then
for i = 0 to instanceArraySize -1
instance = instanceArray(i)
warningValue = warningArray(i)
criticalValue = criticalArray(i)
f_GetInstance(instance)
strResult1 = strResult1 & strResultTemp1
strResult2 = strResult2 & strResultTemp2
if intReturn < intReturnTemp then
intReturn = intReturnTemp
end if
Next
Else
for i = 0 to instanceArraySize -1
instance = instanceArray(i)
f_GetInstance(instance)
strResult1 = strResult1 & strResultTemp1
strResult2 = strResult2 & strResultTemp2
if intReturn < intReturnTemp then
intReturn = intReturnTemp
end if
Next
end if
if(strResult2 = "") then
strResult = strResult1
else
strResult = strResult1 & "|" & strResult2
end if
Wscript.Echo strResult
Wscript.Quit(intReturn)
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInstances.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetInstances()
On Error Resume Next
first = 1
position = 0
instanceArraySize = 0
position = InStr(first, strInst, ",")
if (position = 0) then
instanceTemp = strInst
InstanceArraySize = 1
ReDim instanceArray(instanceArraySize)
instanceArray(0) = instanceTemp
else
do while (position > 0)
instanceTemp = Mid(strInst,first,position - first)
instanceArraySize = instanceArraySize + 1
ReDim Preserve instanceArray(instanceArraySize)
instanceArray(instanceArraySize -1) = Trim(instanceTemp)
first = position + 1
position = InStr(first, strInst, ",")
loop
instanceTemp = Mid(strInst,first,len(strInst))
instanceArraySize = instanceArraySize + 1
ReDim Preserve instanceArray(instanceArraySize)
instanceArray(instanceArraySize -1) = Trim(instanceTemp)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetWarningCriticalValues.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetWarningCriticalValues()
On Error Resume Next
position1 = 0
position2 = 0
position3 = 0
position4 = 0
temp1 = 1
temp2 = 1
warningArraySize = 0
criticalArraySize = 0
'get warning
position2 = InStr(temp1, warningValueString, ",")
If(position2 = 0) then
position2 = Len(warningValueString)+1
end if
If(position2 > position1) then
do while (position2 > position1)
warningPair = Mid(warningValueString, position1 + 1, (position2 - position1 -1))
warningArraySize = warningArraySize + 1
ReDim Preserve warningArray(warningArraySize)
warningArray(warningArraySize -1) = Trim(warningPair)
temp1 = position2 + 1
position1 = position2
position2 = InStr(temp1, warningValueString, ",")
If(position2 = 0) then
position2 = Len(warningValueString)+1
End If
loop
end If
If(Int(warningArraySize) < Int(instanceArraySize)) Then
ReDim Preserve warningArray(instanceArraySize)
For i = 0 To (instanceArraySize - warningArraySize - 1)
warningArray(warningArraySize +i) = warningArray(warningArraySize-1)
Next
warningArraySize = instanceArraySize
End If
'get critical
position4 = InStr(temp2, criticalValueString, ",")
If(position4 = 0) then
position4 = Len(criticalValueString)+1
end if
If(position4 > position3) then
do while (position4 > position3)
criticalPair = Mid(criticalValueString, position3 + 1, (position4 - position3 -1))
criticalArraySize = criticalArraySize + 1
ReDim Preserve criticalArray(criticalArraySize)
criticalArray(criticalArraySize -1) = Trim(criticalPair)
temp2 = position4 + 1
position3 = position4
position4 = InStr(temp2, criticalValueString, ",")
If(position4 = 0) then
position4 = Len(criticalValueString)+1
End If
loop
End If
If(Int(criticalArraySize) < Int(instanceArraySize)) Then
ReDim Preserve criticalArray(instanceArraySize)
For i = 0 To (instanceArraySize - criticalArraySize - 1)
criticalArray(criticalArraySize +i) = criticalArray(criticalArraySize-1)
Next
criticalArraySize = instanceArraySize
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_LocalPerfValue.
'Descripton: Get perform value at Local Host.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_LocalPerfValue()
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\" & strNameSpace)
f_Error()
'Set colInstances = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & strComputer & "\" & strNameSpace).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
f_GetInformation()
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_RemotePerfValue.
'Descripton: Get perform values at Remote Host.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_RemotePerfValue()
On Error Resume Next
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
if (strDomain = "") then
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass )
f_Error()
'Set colInstances = objSWbemLocator.ConnectServer(strComputer, strNamespace , strUser, strPass).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
else
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass,"MS_409","ntlmdomain:" + strDomain )
f_Error()
'Set colInstances = objSWbemLocator.ConnectServer(strComputer, strNamespace , strUser, strPass,"MS_409","ntlmdomain:" & strDomain ).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
end if
objWMIService.Security_.ImpersonationLevel = 3
f_Error()
f_GetInformation()
End Function
'*************************************************************************************************
' Main Function
'*************************************************************************************************
'/////////////////////
strCommandName="check_counter_bulk_count.vbs"
strDescription="Enumerate the needed windows host information."
'/////////////////////
strNameSpace = "root\cimv2"
f_GetAllArg()
tempCount = argcountcommand/2
f_Error()
strClass = ""
if ((UCase(arg(0))="-H") Or (UCase(arg(0))="--HELP")) and (argcountcommand=1) then
f_help()
else
if( ((argcountcommand Mod 2) = 0) and (3 < tempCount < 11)) then
strComputer = f_GetOneArg("-h")
strClass = f_GetOneArg("-class")
strProp = f_GetOneArg("-prop")
strInst = f_GetOneArg("-inst")
f_GetInstances()
warningValue = f_GetOneArg("-w")
warningValueString = f_GetOneArg("-w")
criticalValue = f_GetOneArg("-c")
criticalValueString = f_GetOneArg("-c")
If((warningValueString <> "") Or (criticalValueString <> "")) Then
f_GetWarningCriticalValues()
End if
strUser = f_GetOneArg("-user")
strPass = f_GetOneArg("-pass")
strDomain = f_GetOneArg("-domain")
if((strComputer = "") or (strClass = "") or (strProp = "") or (strInst = "")) then
Wscript.Echo "Error! Arguments wrong, require verify -h -class -prop -inst parameters"
Wscript.Quit(intError)
else
Select Case tempCount
Case 4:
f_LocalPerfValue()
Case 6:
if ((warningValue <> "") and (criticalValue <> "")) then
f_LocalPerfValue()
end if
if ((strUser <> "") and (strPass <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong, please verify -user -pass or -w -c parameters"
Wscript.Quit(intError)
end if
Case 8:
if ((strUser <> "") and (strPass <> "") and (warningValue <> "") and (criticalValue <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong for remote check, please verify -w -c -user -pass parameters"
Wscript.Quit(intError)
end if
Case 9:
if ((strUser <> "") and (strPass <> "") and (warningValue <> "") and (criticalValue <> "") and (strDomain <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong for remote check, please verify -w -c -user -pass -domain parameters"
Wscript.Quit(intError)
end if
Case Else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
End Select
end if
else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
end if
end if

View File

@ -0,0 +1,895 @@
' Copyright 2007 GroundWork Open Source Inc.
'
' This program is free software; you can redistribute it and/or
' modify it under the terms of the GNU General Public License
' as published by the Free Software Foundation; version 2
' of the License.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
'
' Author Dr. Dave Blunt at GroundWork Open Source Inc. (dblunt@groundworkopensource.com)
'*************************************************************************************************
' Public Variable
'*************************************************************************************************
Const intOK = 0
Const intWarning = 1
Const intCritical = 2
Const intError = 3
Const intUnknown = 3
Dim argcountcommand
Dim arg(20)
Dim strComputer
Dim strClass
Dim strProp
Dim strInst
Dim warningValue
Dim warningValueString
Dim criticalValue
Dim criticalValueString
Dim strUser
Dim strPass
Dim strDomain
Dim strNameSpace
Dim strDescription
Dim strCommandName
Dim strResultTemp
Dim strResult
Dim strResult1
Dim strResult2
Dim intReturnTemp
Dim intReturn
Dim strResultTemp1
Dim strResultTemp2
Dim strResultTemp3
Dim strResultTemp4
Dim intReturnTemp1
Dim strPrefix
Dim returnValue
Dim strPropBase
Dim strNameTemp
Dim strPropNameTemp
Dim timeBaseTemp
Dim counterValueArray()
Dim timerValueTempArray()
Dim strNameArray()
Dim intValueArray()
Dim strPropName
Dim instanceArray()
Dim instanceArraySize
Dim warningArraySize
Dim criticalArraySize
Dim warningArray()
Dim criticalArray()
Dim instance
Dim propArray()
Dim propArraySize
Dim lWarningValue
Dim uWarningValue
Dim lCriticalValue
Dim uCriticalValue
Dim ArgCount
Dim strArgMain(10)
Dim strArgSortDes(10)
Dim strArgDetailDes(10)
Dim strArgExample(10)
Dim objWMIService, colWMI, colWMITemp, objWMI, objSWbemLocator
strComputer=""
strClass = ""
strProp = ""
strInst = ""
warningValue = -1
criticalValue = -1
strUser = ""
strPass = ""
strDomain = ""
intReturnTemp1 = 0
'*************************************************************************************************
' Functions and Subs
'*************************************************************************************************
'-------------------------------------------------------------------------------------------------
'Function Name: f_Error.
'Descripton: Display an error notice include : Error Number and Error Description.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Error()
nbrError = err.number
if (nbrError <> 0 ) then
Select Case nbrError
Case 462, -2147023174
strExitMsg = "Timeout connecting to WMI on this host! Error Number: " & nbrError & " Description: " & err.description
Case -2147024891
strExitMsg = "Authentication failure to remote host! Error Number: " & nbrError & " Description: " & err.description
Case -2147217392
strExitMsg = "Error! Number: " & nbrError & " Description: Invalid Class"
Case Else
strExitMsg = "Error! Number: " & nbrError & " Description: " & err.description
End Select
wscript.echo strExitMsg
wscript.quit(intUnknown)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_Help.
'Descripton: Display help of command include : Description, Arguments, Examples
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Help()
Dim str
str="Check Counter Counter. If your Local Machine has the same Administrator account and password as the Remote Machine then you don't have to use the two last parameters."&vbCrlF&vbCrlF
str=str&"cscript check_counter_counter.vbs -h hostname -class classname -prop property -inst instancename [-w warning_level -c critical_level] [-user username -pass password [-domain domain]]"&vbCrlF
str=str&vbCrlF
str=str&"-h [--help] Help."&vbCrlF
str=str&"-h hostname Host name."&vbCrlF
str=str&"-class classname Class name."&vbCrlF
str=str&"-prop property Property of Class."&vbCrlF
str=str&"-inst instance Needed Instance, can be * for all"&vbCrlF
str=str&"-w warning_level Warning threshold."&vbCrlF
str=str&"-c critical_level Critical threshold."&vbCrlF
str=str&"-user username Account Administrator on Remote Machine."&vbCrlF
str=str&"-pass password Password Account Administrator on Remote Machine."&vbCrlF
str=str&"-domain domain Domain Name of Remote Machine."&vbCrlF
str=str&vbCrlF
str=str&"Example: cscript check_counter_counter.vbs -h Ser1 -class Win32_PerfRawData_PerfOS_Processor -prop InterruptsPerSec -inst ""*"" -w 30 -c 70 [-user Ser1\Administrator -pass password -domain ITSP] "
str=str&"Example: cscript check_counter_counter.vbs -h Ser1 -class Win32_PerfRawData_PerfOS_Processor -prop InterruptsPerSec -inst ""Name = '0'"" -w 30 -c 70 [-user Ser1\Administrator -pass password -domain ITSP] "
wscript.echo str
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetAllArg.
'Descripton: Get all of arguments from command.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetAllArg()
On Error Resume Next
Dim i
argcountcommand=WScript.Arguments.Count
for i=0 to argcountcommand-1
arg(i)=WScript.Arguments(i)
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetOneArg.
'Descripton: Get an argument from command.
'Input: Yes.
' strName: Name of argument
'Output: Value.
'-------------------------------------------------------------------------------------------------
Function f_GetOneArg(strName)
On Error Resume Next
Dim i
for i=0 to argcountcommand-1
if (Ucase(arg(i))=Ucase(strName)) then
f_GetOneArg=arg(i+1)
Exit Function
end if
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInstance.
'Descripton: Get infomation at Local Host.
'Input: instance.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetInstance(instance)
On Error Resume Next
strResultTemp1 = ""
strResultTemp2 = ""
strResultTemp = ""
intResultTemp = 0
strPropBase = ""
strInstanceTemp1 = ""
strInstanceTemp2 = ""
intInstanceTemp1 = 0
intInstanceTemp2 = 0
'Depend on strInfo parameters to get the result value
if(instance = "*") then
strQuery = "Select " & strProp & ", TimeStamp_PerfTime, Frequency_PerfTime" & " from " & strClass
Set colWMITemp = objWMIService.ExecQuery(strQuery)
Wscript.Sleep(1000)
Set colWMI = objWMIService.ExecQuery(strQuery)
else
intInstanceTemp1 = InStr(1,instance,"=")
strInstanceTemp1 = Mid(instance,1,intInstanceTemp1-1)
intInstanceTemp2 = Len(instance)
strInstanceTemp2 = Mid(instance,intInstanceTemp1+1,intInstanceTemp2-intInstanceTemp1)
instance=strInstanceTemp1 & "='" & strInstanceTemp2 & "'"
strQuery = "Select " & strProp & ", TimeStamp_PerfTime, Frequency_PerfTime" & " from " & strClass & " where " & instance
Set colWMITemp = objWMIService.ExecQuery(strQuery)
Wscript.Sleep(1000)
Set colWMI = objWMIService.ExecQuery(strQuery)
end if
count = -1
count = colWMI.count
if(count = -1) then
Wscript.Echo "Unknown - No data received from WMI;"
Wscript.Quit(intUnknown)
else
if(colWMI.count > 0) then
f_GetData()
strResultTemp1 = strResultTemp1 & strResultTemp3
strResultTemp2 = strResultTemp2 & strResultTemp4
intReturnTemp = intReturnTemp1
Exit Function
else
strResultTemp1 = "Unknown - " & instance &" query: No row returned."
intReturnTemp = intUnknown
Exit Function
end if
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetPrefix.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetPrefix(intValue)
On Error Resume Next
strPrefix = ""
If(warningValue <> "" And criticalValue = "") Then
If (IsNumeric(warningValue)) Then
If (Int(intValue) < Int(warningValue)) Then
returnValue=0
strPrefix= "OK - "
Else
returnValue=1
strPrefix= "Warning - "
End If
Else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
If(warningValue = "" And criticalValue <> "") Then
If (IsNumeric(criticalValue)) Then
If (Int(intValue) < Int(criticalValue)) Then
returnValue=0
strPrefix= "OK - "
Else
returnValue=2
strPrefix= "Critical - "
End If
Else
Wscript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
If (warningValue <> "" And criticalValue <> "") Then
If (IsNumeric(warningValue) And IsNumeric(criticalValue)) Then
if (Int(warningValue) < Int(criticalValue)) then
if (Int(intValue) < Int(warningValue)) then
returnValue=0
strPrefix= "OK - "
else
if (Int(intValue) < Int(criticalValue)) then
returnValue=1
strPrefix= "Warning - "
else
returnValue=2
strPrefix= "Critical - "
end if
end if
else
if (Int(intValue) > Int(warningValue)) then
returnValue=0
strPrefix= "OK - "
else
if (Int(intValue) > Int(criticalValue)) then
returnValue=1
strPrefix= "Warning - "
else
returnValue=2
strPrefix= "Critical - "
end if
end if
end If
Else
Wscript.Echo "Error! Arguments wrong, please verify -w -c parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetPrefixWithRange.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetPrefixWithRange(intValue)
On Error Resume Next
lWarningValue = ""
uWarningValue = ""
lCriticalValue= ""
uCriticalValue= ""
warningReturn = 0
criticalReturn = 0
If(warningValue <> "") Then
f_GetWarningValueFromRange(warningValue)
End If
If(criticalValue <> "") Then
f_GetCriticalValueFromRange(criticalValue)
End If
strPrefix = ""
'verify warning
If((lWarningValue <> "") And (uWarningValue <> "")) Then
If(Int(lWarningValue) <= Int(uWarningValue)) Then
If((Int(lWarningValue) >= Int(intValue)) Or (Int(intValue) >= Int(uWarningValue))) Then
warningReturn=1
End If
Else
If((Int(intValue) >= Int(uWarningValue) ) And (Int(intValue) <= Int(lWarningValue))) Then
warningReturn=1
End If
End If
End If
If((lWarningValue <> "") And (uWarningValue = "")) Then
If(Int(intValue) <= Int(lWarningValue)) Then
warningReturn=1
End If
End If
If((lWarningValue = "") And (uWarningValue <> "")) Then
If(Int(intValue) >= Int(uWarningValue)) Then
warningReturn=1
End If
End If
'verify critical
If((lCriticalValue <> "") And (uCriticalValue <> "")) Then
If(Int(lCriticalValue) <= Int(uCriticalValue)) Then
If((Int(lCriticalValue) >= Int(intValue)) Or (Int(intValue) >= Int(uCriticalValue))) Then
criticalReturn=2
End If
Else
If((Int(intValue) >= Int(uCriticalValue) ) And (Int(intValue) <= Int(lCriticalValue))) Then
criticalReturn=2
End If
End If
End If
If((lCriticalValue <> "") And (uCriticalValue = "")) Then
If(Int(intValue) <= Int(lCriticalValue)) Then
criticalReturn=2
End If
End If
If((lCriticalValue = "") And (uCriticalValue <> "")) Then
If(Int(intValue) >= Int(uCriticalValue)) Then
criticalReturn=2
End If
End If
'return result
If(criticalReturn = 2) Then
returnValue=2
strPrefix= "Critical - "
Else
If(warningReturn = 1) Then
returnValue=1
strPrefix= "Warning - "
Else
returnValue=0
strPrefix= "Ok - "
End If
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetWarningValueFromRange().
'Descripton: Get perform value at Local Host.
'Input: warningValueRange.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetWarningValueFromRange(warningValue)
On Error Resume Next
lWarningValue = ""
uWarningValue = ""
temp1 = 0
temp1 = InStr(1, warningValue, ":")
if(temp1 > 0) then
lWarningTemp = Mid(warningValue, 1, temp1 -1)
uWarningTemp = Mid(warningValue, temp1 +1, len(warningValue) - temp1)
if(IsNumeric(lWarningTemp) or IsNumeric(uWarningTemp)) then
lWarningValue = lWarningTemp
uWarningValue = uWarningTemp
else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
end if
else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetCriticalValueFromRange().
'Descripton: Get perform value at Local Host.
'Input: warningValueRange.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetCriticalValueFromRange(criticalValue)
On Error Resume Next
lCriticalValue = ""
uCriticalValue = ""
temp1 = 0
temp1 = InStr(1, criticalValue, ":")
if(temp1 > 0) then
lCriticalTemp = Mid(criticalValue, 1, temp1 -1)
uCriticalTemp = Mid(criticalValue, temp1 +1, len(criticalValue) - temp1)
if(IsNumeric(lCriticalTemp) or IsNumeric(uCriticalTemp)) then
lCriticalValue = lCriticalTemp
uCriticalValue = uCriticalTemp
else
Wscript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
end if
else
WScript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetData.
'Descripton: Format data the same as output.
'Input: no.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetData()
On Error Resume Next
ReDim strNameArray(Int(colWMI.count))
ReDim counterValueArray(Int(colWMI.count))
ReDim timerValueArray(Int(colWMI.count))
ReDim intValueArray(Int(colWMI.count))
strDisplay1 = ""
strDisplay2 = ""
strResultTemp3 = ""
strResultTemp4 = ""
strNameTemp = ""
strPropNameTemp = ""
counterValueTemp = 0
timerValueTemp = 0
timeBaseTemp = 0
i, j = 0
For Each objWMITemp in colWMITemp
counterValueArray(i) = objWMITemp.Properties_(strProp)
timerValueArray(i) = objWMITemp.Properties_("TimeStamp_PerfTime")
i = i + 1
Next
For Each objWMI in colWMI
strNameTemp = objWMI.Name
strPropNameTemp = objWMI.Properties_(strProp).Name
counterValueTemp = objWMI.Properties_(strProp)
timerValueTemp = objWMI.Properties_("TimeStamp_PerfTime")
timeBase = objWMI.Properties_("Frequency_PerfTime")
strNameArray(j) = strNameTemp
if((timerValueTemp - timerValueArray(j)) = 0) then
intValueArray(j) = 0
else
intValueArray(j) = (counterValueTemp - counterValueArray(j)) / ((timerValueTemp - timerValueArray(j)) / timeBase)
end if
j = j + 1
Next
for k = 0 to (Int(colWMI.count) - 1)
strName = strNameArray(k)
Dim strDSName
strDSName = f_FormatDSName(strName)
strPropName = strPropNameTemp
intValue = (intValueArray(k))
if((warningValue <> "") and (criticalValue <> "")) then
strDisplay1 = strName & " '" & strPropName & "'" & " = " & intValue & "; "
strDisplay2 = "'" & strDSName & "'" & "=" & intValue & ";" & warningValue & ";" & criticalValue & ";; "
If(InStr(1, warningValue, ":") > 0 Or InStr(1, criticalValue, ":") > 0) Then
f_GetPrefixWithRange(intValue)
Else
f_GetPrefix(intValue)
End If
strResultTemp3 = strResultTemp3 & strPrefix & strDisplay1
strResultTemp4 = strResultTemp4 & strDisplay2
if( intReturnTemp1 < returnValue) then
intReturnTemp1 = returnValue
end if
else
strResultTemp3 = strResultTemp3 & "OK - " & strName & " '" & strPropName & "'" & " = " & intValue & "; "
strResultTemp4 = ""
end if
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_FormatDSName.
'Descripton: Get infomation at Local Host.
'Input: strName.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_FormatDSName(strName)
On Error Resume Next
first = 1
position1 = 0
position1 = InStr(first, strName, "=")
Dim proc_name
proc_name = ""
If(position1 > 0) Then
proc_name = Mid(strName,position1+1,(Len(strName)-position1))
proc_name = Replace(proc_name,".","_")
proc_name = Replace(proc_name,"-","_")
proc_name = Mid(proc_name,1, 19)
Else
proc_name = Mid(strName,position1+1,(Len(strName)-position1))
proc_name = Replace(proc_name,".","_")
proc_name = Replace(proc_name,"-","_")
proc_name = Mid(proc_name,1, 19)
End If
f_FormatDSName = proc_name
Exit Function
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInformation.
'Descripton: Get information data.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_GetInformation()
On Error Resume Next
strResult = ""
strResult1 = ""
strResult2 = ""
intReturn = 0
instance = strInst
first=1
tam1=10
tam = -1
If(instanceArraySize > 0 and (warningArraySize > 1 Or criticalArraySize > 1)) Then
for i = 0 to instanceArraySize -1
instance = instanceArray(i)
warningValue = warningArray(i)
criticalValue = criticalArray(i)
f_GetInstance(instance)
strResult1 = strResult1 & strResultTemp1
strResult2 = strResult2 & strResultTemp2
if intReturn < intReturnTemp then
intReturn = intReturnTemp
end if
Next
Else
for i = 0 to instanceArraySize -1
instance = instanceArray(i)
f_GetInstance(instance)
strResult1 = strResult1 & strResultTemp1
strResult2 = strResult2 & strResultTemp2
if intReturn < intReturnTemp then
intReturn = intReturnTemp
end if
Next
end if
if(strResult2 = "") then
strResult = strResult1
else
strResult = strResult1 & "|" & strResult2
end if
Wscript.Echo strResult
Wscript.Quit(intReturn)
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInstances.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetInstances()
On Error Resume Next
first = 1
position = 0
instanceArraySize = 0
position = InStr(first, strInst, ",")
if (position = 0) then
instanceTemp = strInst
InstanceArraySize = 1
ReDim instanceArray(instanceArraySize)
instanceArray(0) = instanceTemp
else
do while (position > 0)
instanceTemp = Mid(strInst,first,position - first)
instanceArraySize = instanceArraySize + 1
ReDim Preserve instanceArray(instanceArraySize)
instanceArray(instanceArraySize -1) = Trim(instanceTemp)
first = position + 1
position = InStr(first, strInst, ",")
loop
instanceTemp = Mid(strInst,first,len(strInst))
instanceArraySize = instanceArraySize + 1
ReDim Preserve instanceArray(instanceArraySize)
instanceArray(instanceArraySize -1) = Trim(instanceTemp)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetWarningCriticalValues.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetWarningCriticalValues()
On Error Resume Next
position1 = 0
position2 = 0
position3 = 0
position4 = 0
temp1 = 1
temp2 = 1
warningArraySize = 0
criticalArraySize = 0
'get warning
position2 = InStr(temp1, warningValueString, ",")
If(position2 = 0) then
position2 = Len(warningValueString)+1
end if
If(position2 > position1) then
do while (position2 > position1)
warningPair = Mid(warningValueString, position1 + 1, (position2 - position1 -1))
warningArraySize = warningArraySize + 1
ReDim Preserve warningArray(warningArraySize)
warningArray(warningArraySize -1) = Trim(warningPair)
temp1 = position2 + 1
position1 = position2
position2 = InStr(temp1, warningValueString, ",")
If(position2 = 0) then
position2 = Len(warningValueString)+1
End If
loop
end If
If(Int(warningArraySize) < Int(instanceArraySize)) Then
ReDim Preserve warningArray(instanceArraySize)
For i = 0 To (instanceArraySize - warningArraySize - 1)
warningArray(warningArraySize +i) = warningArray(warningArraySize-1)
Next
warningArraySize = instanceArraySize
End If
'get critical
position4 = InStr(temp2, criticalValueString, ",")
If(position4 = 0) then
position4 = Len(criticalValueString)+1
end if
If(position4 > position3) then
do while (position4 > position3)
criticalPair = Mid(criticalValueString, position3 + 1, (position4 - position3 -1))
criticalArraySize = criticalArraySize + 1
ReDim Preserve criticalArray(criticalArraySize)
criticalArray(criticalArraySize -1) = Trim(criticalPair)
temp2 = position4 + 1
position3 = position4
position4 = InStr(temp2, criticalValueString, ",")
If(position4 = 0) then
position4 = Len(criticalValueString)+1
End If
loop
End If
If(Int(criticalArraySize) < Int(instanceArraySize)) Then
ReDim Preserve criticalArray(instanceArraySize)
For i = 0 To (instanceArraySize - criticalArraySize - 1)
criticalArray(criticalArraySize +i) = criticalArray(criticalArraySize-1)
Next
criticalArraySize = instanceArraySize
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_LocalPerfValue.
'Descripton: Get perform value at Local Host.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_LocalPerfValue()
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\" & strNameSpace)
f_Error()
'Set colInstances = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & strComputer & "\" & strNameSpace).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
f_GetInformation()
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_RemotePerfValue.
'Descripton: Get perform values at Remote Host.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_RemotePerfValue()
On Error Resume Next
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
if (strDomain = "") then
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass )
f_Error()
'Set colInstances = objSWbemLocator.ConnectServer(strComputer, strNamespace , strUser, strPass).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
else
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass,"MS_409","ntlmdomain:" + strDomain )
f_Error()
'Set colInstances = objSWbemLocator.ConnectServer(strComputer, strNamespace , strUser, strPass,"MS_409","ntlmdomain:" & strDomain ).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
end if
objWMIService.Security_.ImpersonationLevel = 3
f_Error()
f_GetInformation()
End Function
'*************************************************************************************************
' Main Function
'*************************************************************************************************
'/////////////////////
strCommandName="check_counter_rawcount.vbs"
strDescription="Enumerate the needed windows host information."
'/////////////////////
strNameSpace = "root\cimv2"
f_GetAllArg()
tempCount = argcountcommand/2
f_Error()
strClass = ""
if ((UCase(arg(0))="-H") Or (UCase(arg(0))="--HELP")) and (argcountcommand=1) then
f_help()
else
if( ((argcountcommand Mod 2) = 0) and (3 < tempCount < 11)) then
strComputer = f_GetOneArg("-h")
strClass = f_GetOneArg("-class")
strProp = f_GetOneArg("-prop")
strInst = f_GetOneArg("-inst")
f_GetInstances()
warningValue = f_GetOneArg("-w")
warningValueString = f_GetOneArg("-w")
criticalValue = f_GetOneArg("-c")
criticalValueString = f_GetOneArg("-c")
If((warningValueString <> "") Or (criticalValueString <> "")) Then
f_GetWarningCriticalValues()
End if
strUser = f_GetOneArg("-user")
strPass = f_GetOneArg("-pass")
strDomain = f_GetOneArg("-domain")
if((strComputer = "") or (strClass = "") or (strProp = "") or (strInst = "")) then
Wscript.Echo "Error! Arguments wrong, require verify -h -class -prop -inst parameters"
Wscript.Quit(intError)
else
Select Case tempCount
Case 4:
f_LocalPerfValue()
Case 6:
if ((warningValue <> "") and (criticalValue <> "")) then
f_LocalPerfValue()
end if
if ((strUser <> "") and (strPass <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong, please verify -user -pass or -w -c parameters"
Wscript.Quit(intError)
end if
Case 8:
if ((strUser <> "") and (strPass <> "") and (warningValue <> "") and (criticalValue <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong for remote check, please verify -w -c -user -pass parameters"
Wscript.Quit(intError)
end if
Case 9:
if ((strUser <> "") and (strPass <> "") and (warningValue <> "") and (criticalValue <> "") and (strDomain <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong for remote check, please verify -w -c -user -pass -domain parameters"
Wscript.Quit(intError)
end if
Case Else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
End Select
end if
else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
end if
end if

View File

@ -0,0 +1,848 @@
' Copyright 2007 GroundWork Open Source Inc.
'
' This program is free software; you can redistribute it and/or
' modify it under the terms of the GNU General Public License
' as published by the Free Software Foundation; version 2
' of the License.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
'
' Author Dr. Dave Blunt at GroundWork Open Source Inc. (dblunt@groundworkopensource.com)
'*************************************************************************************************
' Public Variable
'*************************************************************************************************
Const intOK = 0
Const intWarning = 1
Const intCritical = 2
Const intError = 3
Const intUnknown = 3
Dim argcountcommand
Dim arg(20)
Dim strComputer
Dim strClass
Dim strProp
Dim strInst
Dim warningValue
Dim warningValueString
Dim criticalValue
Dim criticalValueString
Dim strUser
Dim strPass
Dim strDomain
Dim strNameSpace
Dim strDescription
Dim strCommandName
Dim strResultTemp
Dim strResult
Dim strResult1
Dim strResult2
Dim intReturnTemp
Dim intReturn
Dim strResultTemp1
Dim strResultTemp2
Dim strResultTemp3
Dim strResultTemp4
Dim intReturnTemp1
Dim strPrefix
Dim intValue
Dim returnValue
Dim strPropName
Dim instanceArray()
Dim instanceArraySize
Dim warningArraySize
Dim criticalArraySize
Dim warningArray()
Dim criticalArray()
Dim instance
Dim propArray()
Dim propArraySize
Dim lWarningValue
Dim uWarningValue
Dim lCriticalValue
Dim uCriticalValue
Dim ArgCount
Dim strArgMain(10)
Dim strArgSortDes(10)
Dim strArgDetailDes(10)
Dim strArgExample(10)
Dim objWMIService, colWMI,objWMI,objSWbemLocator
strComputer=""
strClass = ""
strProp = ""
strInst = ""
warningValue = -1
criticalValue = -1
strUser = ""
strPass = ""
strDomain = ""
intReturnTemp1 = 0
'*************************************************************************************************
' Functions and Subs
'*************************************************************************************************
'-------------------------------------------------------------------------------------------------
'Function Name: f_Error.
'Descripton: Display an error notice include : Error Number and Error Description.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Error()
nbrError = err.number
if (nbrError <> 0 ) then
Select Case nbrError
Case 462, -2147023174
strExitMsg = "Timeout connecting to WMI on this host! Error Number: " & nbrError & " Description: " & err.description
Case -2147024891
strExitMsg = "Authentication failure to remote host! Error Number: " & nbrError & " Description: " & err.description
Case -2147217392
strExitMsg = "Error! Number: " & nbrError & " Description: Invalid Class"
Case Else
strExitMsg = "Error! Number: " & nbrError & " Description: " & err.description
End Select
wscript.echo strExitMsg
wscript.quit(intUnknown)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_Help.
'Descripton: Display help of command include : Description, Arguments, Examples
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Help()
Dim str
str="Check Counter Large RawCount. If your Local Machine has the same Administrator account and password as the Remote Machine then you don't have to use the two last parameters."&vbCrlF&vbCrlF
str=str&"cscript check_counter_rawcount.vbs -h hostname -class classname -prop property -inst instancename [-w warning_level -c critical_level] [-user username -pass password [-domain domain]]"&vbCrlF
str=str&vbCrlF
str=str&"-h [--help] Help."&vbCrlF
str=str&"-h hostname Host name."&vbCrlF
str=str&"-class classname Class name."&vbCrlF
str=str&"-prop property Property of Class."&vbCrlF
str=str&"-inst instance Needed Instance."&vbCrlF
str=str&"-w warning_level Warning threshold."&vbCrlF
str=str&"-c critical_level Critical threshold."&vbCrlF
str=str&"-user username Account Administrator on Remote Machine."&vbCrlF
str=str&"-pass password Password Account Administrator on Remote Machine."&vbCrlF
str=str&"-domain domain Domain Name of Remote Machine."&vbCrlF
str=str&vbCrlF
str=str&"Example: cscript check_counter_large_rawcount.vbs -h Ser1 -class Win32_PerfRawData_PerfProc_Process -prop WorkingSet -inst ""*"" -w 30 -c 70 [-user Ser1\Administrator -pass password -domain ITSP] "
str=str&"Example: cscript check_counter_large_rawcount.vbs -h Ser1 -class Win32_PerfRawData_PerfProc_Process -prop WorkingSet -inst ""IDProcess = '3612', IDProcess = '2156'"" -w 30 -c 70 [-user Ser1\Administrator -pass password -domain ITSP] "
wscript.echo str
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetAllArg.
'Descripton: Get all of arguments from command.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetAllArg()
On Error Resume Next
Dim i
argcountcommand=WScript.Arguments.Count
for i=0 to argcountcommand-1
arg(i)=WScript.Arguments(i)
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetOneArg.
'Descripton: Get an argument from command.
'Input: Yes.
' strName: Name of argument
'Output: Value.
'-------------------------------------------------------------------------------------------------
Function f_GetOneArg(strName)
On Error Resume Next
Dim i
for i=0 to argcountcommand-1
if (Ucase(arg(i))=Ucase(strName)) then
f_GetOneArg=arg(i+1)
Exit Function
end if
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInstance.
'Descripton: Get infomation at Local Host.
'Input: instance.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetInstance(instance)
On Error Resume Next
strResultTemp1 = ""
strResultTemp2 = ""
strResultTemp = ""
intResultTemp = 0
strInstanceTemp1 = ""
strInstanceTemp2 = ""
intInstanceTemp1 = 0
intInstanceTemp2 = 0
'Depend on strInfo parameters to get the result value
if(instance = "*") then
strQuery = "Select " & strProp & " from " & strClass
Set colWMI = objWMIService.ExecQuery(strQuery)
else
intInstanceTemp1 = InStr(1,instance,"=")
strInstanceTemp1 = Mid(instance,1,intInstanceTemp1-1)
intInstanceTemp2 = Len(instance)
strInstanceTemp2 = Mid(instance,intInstanceTemp1+1,intInstanceTemp2-intInstanceTemp1)
instance=strInstanceTemp1 & "='" & strInstanceTemp2 & "'"
strQuery = "Select " & strProp & " from " & strClass & " where " & instance
Set colWMI = objWMIService.ExecQuery(strQuery)
end if
count = -1
count = colWMI.count
if(count = -1) then
Wscript.Echo "Unknown - No data received from WMI;"
Wscript.Quit(intUnknown)
else
if(colWMI.count > 0) then
f_FormatData(colWMI)
strResultTemp1 = strResultTemp1 & strResultTemp3
strResultTemp2 = strResultTemp2 & strResultTemp4
intReturnTemp = intReturnTemp1
Exit Function
else
strResultTemp1 = "Unknown - " & instance &" query: No row returned."
intReturnTemp = intUnknown
Exit Function
end if
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetPrefix.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetPrefix(intValue)
On Error Resume Next
strPrefix = ""
If(warningValue <> "" And criticalValue = "") Then
If (IsNumeric(warningValue)) Then
If (Int(intValue) < Int(warningValue)) Then
returnValue=0
strPrefix= "OK - "
Else
returnValue=1
strPrefix= "Warning - "
End If
Else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
If(warningValue = "" And criticalValue <> "") Then
If (IsNumeric(criticalValue)) Then
If (Int(intValue) < Int(criticalValue)) Then
returnValue=0
strPrefix= "OK - "
Else
returnValue=2
strPrefix= "Critical - "
End If
Else
Wscript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
If (warningValue <> "" And criticalValue <> "") Then
If (IsNumeric(warningValue) And IsNumeric(criticalValue)) Then
if (Int(warningValue) < Int(criticalValue)) then
if (Int(intValue) < Int(warningValue)) then
returnValue=0
strPrefix= "OK - "
else
if (Int(intValue) < Int(criticalValue)) then
returnValue=1
strPrefix= "Warning - "
else
returnValue=2
strPrefix= "Critical - "
end if
end if
else
if (Int(intValue) > Int(warningValue)) then
returnValue=0
strPrefix= "OK - "
else
if (Int(intValue) > Int(criticalValue)) then
returnValue=1
strPrefix= "Warning - "
else
returnValue=2
strPrefix= "Critical - "
end if
end if
end If
Else
Wscript.Echo "Error! Arguments wrong, please verify -w -c parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetPrefixWithRange.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetPrefixWithRange(intValue)
On Error Resume Next
lWarningValue = ""
uWarningValue = ""
lCriticalValue= ""
uCriticalValue= ""
warningReturn = 0
criticalReturn = 0
If(warningValue <> "") Then
f_GetWarningValueFromRange(warningValue)
End If
If(criticalValue <> "") Then
f_GetCriticalValueFromRange(criticalValue)
End If
strPrefix = ""
'verify warning
If((lWarningValue <> "") And (uWarningValue <> "")) Then
If(Int(lWarningValue) <= Int(uWarningValue)) Then
If((Int(lWarningValue) >= Int(intValue)) Or (Int(intValue) >= Int(uWarningValue))) Then
warningReturn=1
End If
Else
If((Int(intValue) >= Int(uWarningValue) ) And (Int(intValue) <= Int(lWarningValue))) Then
warningReturn=1
End If
End If
End If
If((lWarningValue <> "") And (uWarningValue = "")) Then
If(Int(intValue) <= Int(lWarningValue)) Then
warningReturn=1
End If
End If
If((lWarningValue = "") And (uWarningValue <> "")) Then
If(Int(intValue) >= Int(uWarningValue)) Then
warningReturn=1
End If
End If
'verify critical
If((lCriticalValue <> "") And (uCriticalValue <> "")) Then
If(Int(lCriticalValue) <= Int(uCriticalValue)) Then
If((Int(lCriticalValue) >= Int(intValue)) Or (Int(intValue) >= Int(uCriticalValue))) Then
criticalReturn=2
End If
Else
If((Int(intValue) >= Int(uCriticalValue) ) And (Int(intValue) <= Int(lCriticalValue))) Then
criticalReturn=2
End If
End If
End If
If((lCriticalValue <> "") And (uCriticalValue = "")) Then
If(Int(intValue) <= Int(lCriticalValue)) Then
criticalReturn=2
End If
End If
If((lCriticalValue = "") And (uCriticalValue <> "")) Then
If(Int(intValue) >= Int(uCriticalValue)) Then
criticalReturn=2
End If
End If
'return result
If(criticalReturn = 2) Then
returnValue=2
strPrefix= "Critical - "
Else
If(warningReturn = 1) Then
returnValue=1
strPrefix= "Warning - "
Else
returnValue=0
strPrefix= "Ok - "
End If
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetWarningValueFromRange().
'Descripton: Get perform value at Local Host.
'Input: warningValueRange.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetWarningValueFromRange(warningValue)
On Error Resume Next
lWarningValue = ""
uWarningValue = ""
temp1 = 0
temp1 = InStr(1, warningValue, ":")
if(temp1 > 0) then
lWarningTemp = Mid(warningValue, 1, temp1 -1)
uWarningTemp = Mid(warningValue, temp1 +1, len(warningValue) - temp1)
if(IsNumeric(lWarningTemp) or IsNumeric(uWarningTemp)) then
lWarningValue = lWarningTemp
uWarningValue = uWarningTemp
else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
end if
else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetCriticalValueFromRange().
'Descripton: Get perform value at Local Host.
'Input: warningValueRange.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetCriticalValueFromRange(criticalValue)
On Error Resume Next
lCriticalValue = ""
uCriticalValue = ""
temp1 = 0
temp1 = InStr(1, criticalValue, ":")
if(temp1 > 0) then
lCriticalTemp = Mid(criticalValue, 1, temp1 -1)
uCriticalTemp = Mid(criticalValue, temp1 +1, len(criticalValue) - temp1)
if(IsNumeric(lCriticalTemp) or IsNumeric(uCriticalTemp)) then
lCriticalValue = lCriticalTemp
uCriticalValue = uCriticalTemp
else
Wscript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
end if
else
WScript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_FormatData.
'Descripton: Format data the same as output.
'Input: service.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_FormatData(colWMI)
On Error Resume Next
strDisplay1 = ""
strDisplay2 = ""
strResultTemp3 = ""
strResultTemp4 = ""
For Each objWMI in colWMI
strName = objWMI.Name
strPropName = objWMI.Properties_(strProp).Name
intValue = objWMI.Properties_(strProp)
Dim strDSName
strDSName = f_FormatDSName(strName)
if((warningValue <> "") and (criticalValue <> "")) then
strDisplay1 = strName & " '" & strPropName & "'" & " = " & intValue & "; "
strDisplay2 = "'" &strDSName & "'" & "=" & intValue & ";" & warningValue & ";" & criticalValue & ";; "
If(InStr(1, warningValue, ":") > 0 Or InStr(1, criticalValue, ":") > 0) Then
f_GetPrefixWithRange(intValue)
Else
f_GetPrefix(intValue)
End If
strResultTemp3 = strResultTemp3 & strPrefix & strDisplay1
strResultTemp4 = strResultTemp4 & strDisplay2
if( intReturnTemp1 < returnValue) then
intReturnTemp1 = returnValue
end if
else
strResultTemp3 = strResultTemp3 & "OK - " & strName & " '" & strPropName & "'" & " = " & intValue & "; "
strResultTemp4 = ""
end if
Next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInstance.
'Descripton: Get infomation at Local Host.
'Input: instance.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_FormatDSName(strName)
On Error Resume Next
first = 1
position1 = 0
position1 = InStr(first, strName, "=")
Dim proc_name
proc_name = ""
If(position1 > 0) Then
proc_name = Mid(strName,position1+1,(Len(strName)-position1))
proc_name = Replace(proc_name,".","_")
proc_name = Replace(proc_name,"-","_")
proc_name = Mid(proc_name,1, 19)
Else
proc_name = Mid(strName,position1+1,(Len(strName)-position1))
proc_name = Replace(proc_name,".","_")
proc_name = Replace(proc_name,"-","_")
proc_name = Mid(proc_name,1, 19)
End If
f_FormatDSName = proc_name
Exit Function
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInformation.
'Descripton: Get information data.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_GetInformation()
On Error Resume Next
strResult = ""
strResult1 = ""
strResult2 = ""
intReturn = 0
If(instanceArraySize > 0 and (warningArraySize > 1 Or criticalArraySize > 1)) Then
for i = 0 to instanceArraySize -1
instance = instanceArray(i)
warningValue = warningArray(i)
criticalValue = criticalArray(i)
f_GetInstance(instance)
strResult1 = strResult1 & strResultTemp1
strResult2 = strResult2 & strResultTemp2
if intReturn < intReturnTemp then
intReturn = intReturnTemp
end if
Next
Else
for i = 0 to instanceArraySize -1
instance = instanceArray(i)
f_GetInstance(instance)
strResult1 = strResult1 & strResultTemp1
strResult2 = strResult2 & strResultTemp2
if intReturn < intReturnTemp then
intReturn = intReturnTemp
end if
Next
end if
if(strResult2 = "") then
strResult = strResult1
else
strResult = strResult1 & "|" & strResult2
end if
Wscript.Echo strResult
Wscript.Quit(intReturn)
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInstances.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetInstances()
On Error Resume Next
first = 1
position = 0
instanceArraySize = 0
position = InStr(first, strInst, ",")
if (position = 0) then
instanceTemp = strInst
InstanceArraySize = 1
ReDim instanceArray(instanceArraySize)
instanceArray(0) = instanceTemp
else
do while (position > 0)
instanceTemp = Mid(strInst,first,position - first)
instanceArraySize = instanceArraySize + 1
ReDim Preserve instanceArray(instanceArraySize)
instanceArray(instanceArraySize -1) = Trim(instanceTemp)
first = position + 1
position = InStr(first, strInst, ",")
loop
instanceTemp = Mid(strInst,first,len(strInst))
instanceArraySize = instanceArraySize + 1
ReDim Preserve instanceArray(instanceArraySize)
instanceArray(instanceArraySize -1) = Trim(instanceTemp)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetWarningCriticalValues.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetWarningCriticalValues()
On Error Resume Next
position1 = 0
position2 = 0
position3 = 0
position4 = 0
temp1 = 1
temp2 = 1
warningArraySize = 0
criticalArraySize = 0
'get warning
position2 = InStr(temp1, warningValueString, ",")
If(position2 = 0) then
position2 = Len(warningValueString)+1
end if
If(position2 > position1) then
do while (position2 > position1)
warningPair = Mid(warningValueString, position1 + 1, (position2 - position1 -1))
warningArraySize = warningArraySize + 1
ReDim Preserve warningArray(warningArraySize)
warningArray(warningArraySize -1) = Trim(warningPair)
temp1 = position2 + 1
position1 = position2
position2 = InStr(temp1, warningValueString, ",")
If(position2 = 0) then
position2 = Len(warningValueString)+1
End If
loop
end If
If(Int(warningArraySize) < Int(instanceArraySize)) Then
ReDim Preserve warningArray(instanceArraySize)
For i = 0 To (instanceArraySize - warningArraySize - 1)
warningArray(warningArraySize +i) = warningArray(warningArraySize-1)
Next
warningArraySize = instanceArraySize
End If
'get critical
position4 = InStr(temp2, criticalValueString, ",")
If(position4 = 0) then
position4 = Len(criticalValueString)+1
end if
If(position4 > position3) then
do while (position4 > position3)
criticalPair = Mid(criticalValueString, position3 + 1, (position4 - position3 -1))
criticalArraySize = criticalArraySize + 1
ReDim Preserve criticalArray(criticalArraySize)
criticalArray(criticalArraySize -1) = Trim(criticalPair)
temp2 = position4 + 1
position3 = position4
position4 = InStr(temp2, criticalValueString, ",")
If(position4 = 0) then
position4 = Len(criticalValueString)+1
End If
loop
End If
If(Int(criticalArraySize) < Int(instanceArraySize)) Then
ReDim Preserve criticalArray(instanceArraySize)
For i = 0 To (instanceArraySize - criticalArraySize - 1)
criticalArray(criticalArraySize +i) = criticalArray(criticalArraySize-1)
Next
criticalArraySize = instanceArraySize
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_LocalPerfValue.
'Descripton: Get perform value at Local Host.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_LocalPerfValue()
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\" & strNameSpace)
f_Error()
'Set colInstances = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & strComputer & "\" & strNameSpace).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
f_GetInformation()
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_RemotePerfValue.
'Descripton: Get perform values at Remote Host.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_RemotePerfValue()
On Error Resume Next
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
if (strDomain = "") then
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass )
f_Error()
'Set colInstances = objSWbemLocator.ConnectServer(strComputer, strNamespace , strUser, strPass).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
else
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass,"MS_409","ntlmdomain:" + strDomain )
f_Error()
'Set colInstances = objSWbemLocator.ConnectServer(strComputer, strNamespace , strUser, strPass,"MS_409","ntlmdomain:" & strDomain ).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
end if
objWMIService.Security_.ImpersonationLevel = 3
f_Error()
f_GetInformation()
End Function
'*************************************************************************************************
' Main Function
'*************************************************************************************************
'/////////////////////
strCommandName="check_counter_rawcount.vbs"
strDescription="Enumerate the needed windows host information."
'/////////////////////
strNameSpace = "root\cimv2"
f_GetAllArg()
tempCount = argcountcommand/2
f_Error()
strClass = ""
if ((UCase(arg(0))="-H") Or (UCase(arg(0))="--HELP")) and (argcountcommand=1) then
f_help()
else
if( ((argcountcommand Mod 2) = 0) and (3 < tempCount < 10)) then
strComputer = f_GetOneArg("-h")
strClass = f_GetOneArg("-class")
strProp = f_GetOneArg("-prop")
strInst = f_GetOneArg("-inst")
f_GetInstances()
warningValue = f_GetOneArg("-w")
warningValueString = f_GetOneArg("-w")
criticalValue = f_GetOneArg("-c")
criticalValueString = f_GetOneArg("-c")
If((warningValueString <> "") Or (criticalValueString <> "")) Then
f_GetWarningCriticalValues()
End if
strUser = f_GetOneArg("-user")
strPass = f_GetOneArg("-pass")
strDomain = f_GetOneArg("-domain")
if((strComputer = "") or (strClass = "") or (strProp = "") or (strInst = "")) then
Wscript.Echo "Error! Arguments wrong, require verify -h -class -prop -inst parameters"
Wscript.Quit(intError)
else
Select Case tempCount
Case 4:
f_LocalPerfValue()
Case 6:
if ((warningValue <> "") and (criticalValue <> "")) then
f_LocalPerfValue()
end if
if ((strUser <> "") and (strPass <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong, please verify -user -pass or -w -c parameters"
Wscript.Quit(intError)
end if
Case 8:
if ((strUser <> "") and (strPass <> "") and (warningValue <> "") and (criticalValue <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong for remote check, please verify -w -c -user -pass parameters"
Wscript.Quit(intError)
end if
Case 9:
if ((strUser <> "") and (strPass <> "") and (warningValue <> "") and (criticalValue <> "") and (strDomain <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong for remote check, please verify -w -c -user -pass -domain parameters"
Wscript.Quit(intError)
end if
Case Else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
End Select
end if
else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
end if
end if

View File

@ -0,0 +1,848 @@
' Copyright 2007 GroundWork Open Source Inc.
'
' This program is free software; you can redistribute it and/or
' modify it under the terms of the GNU General Public License
' as published by the Free Software Foundation; version 2
' of the License.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
'
' Author Dr. Dave Blunt at GroundWork Open Source Inc. (dblunt@groundworkopensource.com)
'*************************************************************************************************
' Public Variable
'*************************************************************************************************
Const intOK = 0
Const intWarning = 1
Const intCritical = 2
Const intError = 3
Const intUnknown = 3
Dim argcountcommand
Dim arg(20)
Dim strComputer
Dim strClass
Dim strProp
Dim strInst
Dim warningValue
Dim warningValueString
Dim criticalValue
Dim criticalValueString
Dim strUser
Dim strPass
Dim strDomain
Dim strNameSpace
Dim strDescription
Dim strCommandName
Dim strResultTemp
Dim strResult
Dim strResult1
Dim strResult2
Dim intReturnTemp
Dim intReturn
Dim strResultTemp1
Dim strResultTemp2
Dim strResultTemp3
Dim strResultTemp4
Dim intReturnTemp1
Dim strPrefix
Dim intValue
Dim returnValue
Dim strPropName
Dim instanceArray()
Dim instanceArraySize
Dim warningArraySize
Dim criticalArraySize
Dim warningArray()
Dim criticalArray()
Dim instance
Dim propArray()
Dim propArraySize
Dim lWarningValue
Dim uWarningValue
Dim lCriticalValue
Dim uCriticalValue
Dim ArgCount
Dim strArgMain(10)
Dim strArgSortDes(10)
Dim strArgDetailDes(10)
Dim strArgExample(10)
Dim objWMIService, colWMI,objWMI,objSWbemLocator
strComputer=""
strClass = ""
strProp = ""
strInst = ""
warningValue = -1
criticalValue = -1
strUser = ""
strPass = ""
strDomain = ""
intReturnTemp1 = 0
'*************************************************************************************************
' Functions and Subs
'*************************************************************************************************
'-------------------------------------------------------------------------------------------------
'Function Name: f_Error.
'Descripton: Display an error notice include : Error Number and Error Description.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Error()
nbrError = err.number
if (nbrError <> 0 ) then
Select Case nbrError
Case 462, -2147023174
strExitMsg = "Timeout connecting to WMI on this host! Error Number: " & nbrError & " Description: " & err.description
Case -2147024891
strExitMsg = "Authentication failure to remote host! Error Number: " & nbrError & " Description: " & err.description
Case -2147217392
strExitMsg = "Error! Number: " & nbrError & " Description: Invalid Class"
Case Else
strExitMsg = "Error! Number: " & nbrError & " Description: " & err.description
End Select
wscript.echo strExitMsg
wscript.quit(intUnknown)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_Help.
'Descripton: Display help of command include : Description, Arguments, Examples
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Help()
Dim str
str="Check Counter RawCount. If your Local Machine has the same Administrator account and password as the Remote Machine then you don't have to use the two last parameters."&vbCrlF&vbCrlF
str=str&"cscript check_counter_rawcount.vbs -h hostname -class classname -prop property -inst instancename [-w warning_level -c critical_level] [-user username -pass password [-domain domain]]"&vbCrlF
str=str&vbCrlF
str=str&"-h [--help] Help."&vbCrlF
str=str&"-h hostname Host name."&vbCrlF
str=str&"-class classname Class name."&vbCrlF
str=str&"-prop property Property of Class."&vbCrlF
str=str&"-inst instance Needed Instance."&vbCrlF
str=str&"-w warning_level Warning threshold."&vbCrlF
str=str&"-c critical_level Critical threshold."&vbCrlF
str=str&"-user username Account Administrator on Remote Machine."&vbCrlF
str=str&"-pass password Password Account Administrator on Remote Machine."&vbCrlF
str=str&"-domain domain Domain Name of Remote Machine."&vbCrlF
str=str&vbCrlF
str=str&"Example: cscript check_counter_rawcount.vbs -h Ser1 -class Win32_PerfRawData_PerfProc_Process -prop HandleCount -inst ""*"" -w 30 -c 70 [-user Ser1\Administrator -pass password -domain ITSP] "
str=str&"Example: cscript check_counter_rawcount.vbs -h Ser1 -class Win32_PerfRawData_PerfProc_Process -prop HandleCount -inst ""IDProcess = '3612', IDProcess = '2156'"" -w 30 -c 70 [-user Ser1\Administrator -pass password -domain ITSP] "
wscript.echo str
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetAllArg.
'Descripton: Get all of arguments from command.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetAllArg()
On Error Resume Next
Dim i
argcountcommand=WScript.Arguments.Count
for i=0 to argcountcommand-1
arg(i)=WScript.Arguments(i)
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetOneArg.
'Descripton: Get an argument from command.
'Input: Yes.
' strName: Name of argument
'Output: Value.
'-------------------------------------------------------------------------------------------------
Function f_GetOneArg(strName)
On Error Resume Next
Dim i
for i=0 to argcountcommand-1
if (Ucase(arg(i))=Ucase(strName)) then
f_GetOneArg=arg(i+1)
Exit Function
end if
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInstance.
'Descripton: Get infomation at Local Host.
'Input: instance.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetInstance(instance)
On Error Resume Next
strResultTemp1 = ""
strResultTemp2 = ""
strResultTemp = ""
intResultTemp = 0
strInstanceTemp1 = ""
strInstanceTemp2 = ""
intInstanceTemp1 = 0
intInstanceTemp2 = 0
'Depend on strInfo parameters to get the result value
if(instance = "*") then
strQuery = "Select " & strProp & " from " & strClass
Set colWMI = objWMIService.ExecQuery(strQuery)
else
intInstanceTemp1 = InStr(1,instance,"=")
strInstanceTemp1 = Mid(instance,1,intInstanceTemp1-1)
intInstanceTemp2 = Len(instance)
strInstanceTemp2 = Mid(instance,intInstanceTemp1+1,intInstanceTemp2-intInstanceTemp1)
instance=strInstanceTemp1 & "='" & strInstanceTemp2 & "'"
strQuery = "Select " & strProp & " from " & strClass & " where " & instance
Set colWMI = objWMIService.ExecQuery(strQuery)
end if
count = -1
count = colWMI.count
if(count = -1) then
Wscript.Echo "Unknown - No data received from WMI;"
Wscript.Quit(intUnknown)
else
if(colWMI.count > 0) then
f_FormatData(colWMI)
strResultTemp1 = strResultTemp1 & strResultTemp3
strResultTemp2 = strResultTemp2 & strResultTemp4
intReturnTemp = intReturnTemp1
Exit Function
else
strResultTemp1 = "Unknown - " & instance &" query: No row returned."
intReturnTemp = intUnknown
Exit Function
end if
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetPrefix.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetPrefix(intValue)
On Error Resume Next
strPrefix = ""
If(warningValue <> "" And criticalValue = "") Then
If (IsNumeric(warningValue)) Then
If (Int(intValue) < Int(warningValue)) Then
returnValue=0
strPrefix= "OK - "
Else
returnValue=1
strPrefix= "Warning - "
End If
Else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
If(warningValue = "" And criticalValue <> "") Then
If (IsNumeric(criticalValue)) Then
If (Int(intValue) < Int(criticalValue)) Then
returnValue=0
strPrefix= "OK - "
Else
returnValue=2
strPrefix= "Critical - "
End If
Else
Wscript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
If (warningValue <> "" And criticalValue <> "") Then
If (IsNumeric(warningValue) And IsNumeric(criticalValue)) Then
if (Int(warningValue) < Int(criticalValue)) then
if (Int(intValue) < Int(warningValue)) then
returnValue=0
strPrefix= "OK - "
else
if (Int(intValue) < Int(criticalValue)) then
returnValue=1
strPrefix= "Warning - "
else
returnValue=2
strPrefix= "Critical - "
end if
end if
else
if (Int(intValue) > Int(warningValue)) then
returnValue=0
strPrefix= "OK - "
else
if (Int(intValue) > Int(criticalValue)) then
returnValue=1
strPrefix= "Warning - "
else
returnValue=2
strPrefix= "Critical - "
end if
end if
end If
Else
Wscript.Echo "Error! Arguments wrong, please verify -w -c parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetPrefixWithRange.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetPrefixWithRange(intValue)
On Error Resume Next
lWarningValue = ""
uWarningValue = ""
lCriticalValue= ""
uCriticalValue= ""
warningReturn = 0
criticalReturn = 0
If(warningValue <> "") Then
f_GetWarningValueFromRange(warningValue)
End If
If(criticalValue <> "") Then
f_GetCriticalValueFromRange(criticalValue)
End If
strPrefix = ""
'verify warning
If((lWarningValue <> "") And (uWarningValue <> "")) Then
If(Int(lWarningValue) <= Int(uWarningValue)) Then
If((Int(lWarningValue) >= Int(intValue)) Or (Int(intValue) >= Int(uWarningValue))) Then
warningReturn=1
End If
Else
If((Int(intValue) >= Int(uWarningValue) ) And (Int(intValue) <= Int(lWarningValue))) Then
warningReturn=1
End If
End If
End If
If((lWarningValue <> "") And (uWarningValue = "")) Then
If(Int(intValue) <= Int(lWarningValue)) Then
warningReturn=1
End If
End If
If((lWarningValue = "") And (uWarningValue <> "")) Then
If(Int(intValue) >= Int(uWarningValue)) Then
warningReturn=1
End If
End If
'verify critical
If((lCriticalValue <> "") And (uCriticalValue <> "")) Then
If(Int(lCriticalValue) <= Int(uCriticalValue)) Then
If((Int(lCriticalValue) >= Int(intValue)) Or (Int(intValue) >= Int(uCriticalValue))) Then
criticalReturn=2
End If
Else
If((Int(intValue) >= Int(uCriticalValue) ) And (Int(intValue) <= Int(lCriticalValue))) Then
criticalReturn=2
End If
End If
End If
If((lCriticalValue <> "") And (uCriticalValue = "")) Then
If(Int(intValue) <= Int(lCriticalValue)) Then
criticalReturn=2
End If
End If
If((lCriticalValue = "") And (uCriticalValue <> "")) Then
If(Int(intValue) >= Int(uCriticalValue)) Then
criticalReturn=2
End If
End If
'return result
If(criticalReturn = 2) Then
returnValue=2
strPrefix= "Critical - "
Else
If(warningReturn = 1) Then
returnValue=1
strPrefix= "Warning - "
Else
returnValue=0
strPrefix= "Ok - "
End If
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetWarningValueFromRange().
'Descripton: Get perform value at Local Host.
'Input: warningValueRange.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetWarningValueFromRange(warningValue)
On Error Resume Next
lWarningValue = ""
uWarningValue = ""
temp1 = 0
temp1 = InStr(1, warningValue, ":")
if(temp1 > 0) then
lWarningTemp = Mid(warningValue, 1, temp1 -1)
uWarningTemp = Mid(warningValue, temp1 +1, len(warningValue) - temp1)
if(IsNumeric(lWarningTemp) or IsNumeric(uWarningTemp)) then
lWarningValue = lWarningTemp
uWarningValue = uWarningTemp
else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
end if
else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetCriticalValueFromRange().
'Descripton: Get perform value at Local Host.
'Input: warningValueRange.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetCriticalValueFromRange(criticalValue)
On Error Resume Next
lCriticalValue = ""
uCriticalValue = ""
temp1 = 0
temp1 = InStr(1, criticalValue, ":")
if(temp1 > 0) then
lCriticalTemp = Mid(criticalValue, 1, temp1 -1)
uCriticalTemp = Mid(criticalValue, temp1 +1, len(criticalValue) - temp1)
if(IsNumeric(lCriticalTemp) or IsNumeric(uCriticalTemp)) then
lCriticalValue = lCriticalTemp
uCriticalValue = uCriticalTemp
else
Wscript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
end if
else
WScript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_FormatData.
'Descripton: Format data the same as output.
'Input: service.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_FormatData(colWMI)
On Error Resume Next
strDisplay1 = ""
strDisplay2 = ""
strResultTemp3 = ""
strResultTemp4 = ""
For Each objWMI in colWMI
strName = objWMI.Name
strPropName = objWMI.Properties_(strProp).Name
intValue = objWMI.Properties_(strProp)
Dim strDSName
strDSName = f_FormatDSName(strName)
if((warningValue <> "") and (criticalValue <> "")) then
strDisplay1 = strName & " '" & strPropName & "'" & " = " & intValue & "; "
strDisplay2 = "'" &strDSName & "'" & "=" & intValue & ";" & warningValue & ";" & criticalValue & ";; "
If(InStr(1, warningValue, ":") > 0 Or InStr(1, criticalValue, ":") > 0) Then
f_GetPrefixWithRange(intValue)
Else
f_GetPrefix(intValue)
End If
strResultTemp3 = strResultTemp3 & strPrefix & strDisplay1
strResultTemp4 = strResultTemp4 & strDisplay2
if( intReturnTemp1 < returnValue) then
intReturnTemp1 = returnValue
end if
else
strResultTemp3 = strResultTemp3 & "OK - " & strName & " '" & strPropName & "'" & " = " & intValue & "; "
strResultTemp4 = ""
end if
Next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_FormatDSName.
'Descripton: Get infomation at Local Host.
'Input: strName.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_FormatDSName(strName)
On Error Resume Next
first = 1
position1 = 0
position1 = InStr(first, strName, "=")
Dim proc_name
proc_name = ""
If(position1 > 0) Then
proc_name = Mid(strName,position1+1,(Len(strName)-position1))
proc_name = Replace(proc_name,".","_")
proc_name = Replace(proc_name,"-","_")
proc_name = Mid(proc_name,1, 19)
Else
proc_name = Mid(strName,position1+1,(Len(strName)-position1))
proc_name = Replace(proc_name,".","_")
proc_name = Replace(proc_name,"-","_")
proc_name = Mid(proc_name,1, 19)
End If
f_FormatDSName = proc_name
Exit Function
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInformation.
'Descripton: Get information data.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_GetInformation()
On Error Resume Next
strResult = ""
strResult1 = ""
strResult2 = ""
intReturn = 0
If(instanceArraySize > 0 and (warningArraySize > 1 Or criticalArraySize > 1)) Then
for i = 0 to instanceArraySize -1
instance = instanceArray(i)
warningValue = warningArray(i)
criticalValue = criticalArray(i)
f_GetInstance(instance)
strResult1 = strResult1 & strResultTemp1
strResult2 = strResult2 & strResultTemp2
if intReturn < intReturnTemp then
intReturn = intReturnTemp
end if
Next
Else
for i = 0 to instanceArraySize -1
instance = instanceArray(i)
f_GetInstance(instance)
strResult1 = strResult1 & strResultTemp1
strResult2 = strResult2 & strResultTemp2
if intReturn < intReturnTemp then
intReturn = intReturnTemp
end if
Next
end if
if(strResult2 = "") then
strResult = strResult1
else
strResult = strResult1 & "|" & strResult2
end if
Wscript.Echo strResult
Wscript.Quit(intReturn)
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInstances.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetInstances()
On Error Resume Next
first = 1
position = 0
instanceArraySize = 0
position = InStr(first, strInst, ",")
if (position = 0) then
instanceTemp = strInst
InstanceArraySize = 1
ReDim instanceArray(instanceArraySize)
instanceArray(0) = instanceTemp
else
do while (position > 0)
instanceTemp = Mid(strInst,first,position - first)
instanceArraySize = instanceArraySize + 1
ReDim Preserve instanceArray(instanceArraySize)
instanceArray(instanceArraySize -1) = Trim(instanceTemp)
first = position + 1
position = InStr(first, strInst, ",")
loop
instanceTemp = Mid(strInst,first,len(strInst))
instanceArraySize = instanceArraySize + 1
ReDim Preserve instanceArray(instanceArraySize)
instanceArray(instanceArraySize -1) = Trim(instanceTemp)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetWarningCriticalValues.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetWarningCriticalValues()
On Error Resume Next
position1 = 0
position2 = 0
position3 = 0
position4 = 0
temp1 = 1
temp2 = 1
warningArraySize = 0
criticalArraySize = 0
'get warning
position2 = InStr(temp1, warningValueString, ",")
If(position2 = 0) then
position2 = Len(warningValueString)+1
end if
If(position2 > position1) then
do while (position2 > position1)
warningPair = Mid(warningValueString, position1 + 1, (position2 - position1 -1))
warningArraySize = warningArraySize + 1
ReDim Preserve warningArray(warningArraySize)
warningArray(warningArraySize -1) = Trim(warningPair)
temp1 = position2 + 1
position1 = position2
position2 = InStr(temp1, warningValueString, ",")
If(position2 = 0) then
position2 = Len(warningValueString)+1
End If
loop
end If
If(Int(warningArraySize) < Int(instanceArraySize)) Then
ReDim Preserve warningArray(instanceArraySize)
For i = 0 To (instanceArraySize - warningArraySize - 1)
warningArray(warningArraySize +i) = warningArray(warningArraySize-1)
Next
warningArraySize = instanceArraySize
End If
'get critical
position4 = InStr(temp2, criticalValueString, ",")
If(position4 = 0) then
position4 = Len(criticalValueString)+1
end if
If(position4 > position3) then
do while (position4 > position3)
criticalPair = Mid(criticalValueString, position3 + 1, (position4 - position3 -1))
criticalArraySize = criticalArraySize + 1
ReDim Preserve criticalArray(criticalArraySize)
criticalArray(criticalArraySize -1) = Trim(criticalPair)
temp2 = position4 + 1
position3 = position4
position4 = InStr(temp2, criticalValueString, ",")
If(position4 = 0) then
position4 = Len(criticalValueString)+1
End If
loop
End If
If(Int(criticalArraySize) < Int(instanceArraySize)) Then
ReDim Preserve criticalArray(instanceArraySize)
For i = 0 To (instanceArraySize - criticalArraySize - 1)
criticalArray(criticalArraySize +i) = criticalArray(criticalArraySize-1)
Next
criticalArraySize = instanceArraySize
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_LocalPerfValue.
'Descripton: Get perform value at Local Host.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_LocalPerfValue()
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\" & strNameSpace)
f_Error()
'Set colInstances = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & strComputer & "\" & strNameSpace).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
f_GetInformation()
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_RemotePerfValue.
'Descripton: Get perform values at Remote Host.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_RemotePerfValue()
On Error Resume Next
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
if (strDomain = "") then
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass )
f_Error()
'Set colInstances = objSWbemLocator.ConnectServer(strComputer, strNamespace , strUser, strPass).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
else
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass,"MS_409","ntlmdomain:" + strDomain )
f_Error()
'Set colInstances = objSWbemLocator.ConnectServer(strComputer, strNamespace , strUser, strPass,"MS_409","ntlmdomain:" & strDomain ).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
end if
objWMIService.Security_.ImpersonationLevel = 3
f_Error()
f_GetInformation()
End Function
'*************************************************************************************************
' Main Function
'*************************************************************************************************
'/////////////////////
strCommandName="check_counter_rawcount.vbs"
strDescription="Enumerate the needed windows host information."
'/////////////////////
strNameSpace = "root\cimv2"
f_GetAllArg()
tempCount = argcountcommand/2
f_Error()
strClass = ""
if ((UCase(arg(0))="-H") Or (UCase(arg(0))="--HELP")) and (argcountcommand=1) then
f_help()
else
if( ((argcountcommand Mod 2) = 0) and (3 < tempCount < 10)) then
strComputer = f_GetOneArg("-h")
strClass = f_GetOneArg("-class")
strProp = f_GetOneArg("-prop")
strInst = f_GetOneArg("-inst")
f_GetInstances()
warningValue = f_GetOneArg("-w")
warningValueString = f_GetOneArg("-w")
criticalValue = f_GetOneArg("-c")
criticalValueString = f_GetOneArg("-c")
If((warningValueString <> "") Or (criticalValueString <> "")) Then
f_GetWarningCriticalValues()
End if
strUser = f_GetOneArg("-user")
strPass = f_GetOneArg("-pass")
strDomain = f_GetOneArg("-domain")
if((strComputer = "") or (strClass = "") or (strProp = "") or (strInst = "")) then
Wscript.Echo "Error! Arguments wrong, require verify -h -class -prop -inst parameters"
Wscript.Quit(intError)
else
Select Case tempCount
Case 4:
f_LocalPerfValue()
Case 6:
if ((warningValue <> "") and (criticalValue <> "")) then
f_LocalPerfValue()
end if
if ((strUser <> "") and (strPass <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong, please verify -user -pass or -w -c parameters"
Wscript.Quit(intError)
end if
Case 8:
if ((strUser <> "") and (strPass <> "") and (warningValue <> "") and (criticalValue <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong for remote check, please verify -w -c -user -pass parameters"
Wscript.Quit(intError)
end if
Case 9:
if ((strUser <> "") and (strPass <> "") and (warningValue <> "") and (criticalValue <> "") and (strDomain <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong for remote check, please verify -w -c -user -pass -domain parameters"
Wscript.Quit(intError)
end if
Case Else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
End Select
end if
else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
end if
end if

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,965 @@
' Copyright 2007 GroundWork Open Source Inc.
'
' This program is free software; you can redistribute it and/or
' modify it under the terms of the GNU General Public License
' as published by the Free Software Foundation; version 2
' of the License.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
'
' Author Dr. Dave Blunt at GroundWork Open Source Inc. (dblunt@groundworkopensource.com)
'*************************************************************************************************
' Public Variable
'*************************************************************************************************
Const intOK = 0
Const intWarning = 1
Const intCritical = 2
Const intError = 3
Const intUnknown = 3
Dim argcountcommand
Dim arg(20)
Dim strComputer
Dim strClass
Dim strProp
Dim strDisks
Dim warningValue
Dim warningValueString
Dim criticalValue
Dim criticalValueString
Dim strUser
Dim strPass
Dim strDomain
Dim strNameSpace
Dim strDescription
Dim strCommandName
Dim strResultTemp
Dim strResult
Dim strResult1
Dim strResult2
Dim intReturnTemp
Dim intReturn
Dim strResultTemp1
Dim strResultTemp2
Dim strResultTemp3
Dim strResultTemp4
Dim intReturnTemp1
Dim strPrefix
Dim intValue
Dim returnValue
Dim strThresolds
Dim strThresoldPair
Dim instanceArray()
Dim instanceArraySize
Dim thresoldArraySize
Dim warningArraySize
Dim criticalArraySize
Dim warningArray()
Dim criticalArray()
Dim instance
Dim lWarningValue
Dim uWarningValue
Dim lCriticalValue
Dim uCriticalValue
Dim strDisplay1
Dim strDisplay2
Dim strName
Dim strPropName
Dim intAverageValue
Dim ArgCount
Dim strArgMain(10)
Dim strArgSortDes(10)
Dim strArgDetailDes(10)
Dim strArgExample(10)
Dim objWMIService, colWMI,objWMI,objSWbemLocator
strComputer=""
strClass = ""
strProp = ""
strInst = ""
warningValue = -1
criticalValue = -1
strUser = ""
strPass = ""
strDomain = ""
intReturnTemp1 = 0
'*************************************************************************************************
' Functions and Subs
'*************************************************************************************************
'-------------------------------------------------------------------------------------------------
'Function Name: f_Error.
'Descripton: Display an error notice include : Error Number and Error Description.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Error()
nbrError = err.number
if (nbrError <> 0 ) then
Select Case nbrError
Case 462, -2147023174
strExitMsg = "Timeout connecting to WMI on this host! Error Number: " & nbrError & " Description: " & err.description
Case -2147024891
strExitMsg = "Authentication failure to remote host! Error Number: " & nbrError & " Description: " & err.description
Case -2147217392
strExitMsg = "Error! Number: " & nbrError & " Description: Invalid Class"
Case Else
strExitMsg = "Error! Number: " & nbrError & " Description: " & err.description
End Select
wscript.echo strExitMsg
wscript.quit(intUnknown)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_Help.
'Descripton: Display help of command include : Description, Arguments, Examples
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Help()
Dim str
str="Check Disks Percentage Space Used. If your Local Machine has the same Administrator account and password as the Remote Machine then you don't have to use the two last parameters."&vbCrlF&vbCrlF
str=str&"cscript check_disks_percentage_space_used.vbs -h hostname -inst DeviceID [-w warning_level -c critical_level] [-t thresoldpairs] [-user username -pass password [-domain domain]]"&vbCrlF
str=str&vbCrlF
str=str&"-h [--help] Help."&vbCrlF
str=str&"-h hostname Host name."&vbCrlF
str=str&"-inst disks DeviceID Instance."&vbCrlF
str=str&"-w warning_level Warning threshold by percentage."&vbCrlF
str=str&"-c critical_level Critical threshold by percentage."&vbCrlF
str=str&"-t thresold pairs Threshold pairs for each instance. Note: each thresold pair enclosed by '{' and '}' characters, warning value and critical separated by ',' character"&vbCrlF
str=str&"-user username Account Administrator on Remote Machine."&vbCrlF
str=str&"-pass password Password Account Administrator on Remote Machine."&vbCrlF
str=str&"-domain domain Domain Name of Remote Machine."&vbCrlF
str=str&vbCrlF
str=str&"Example: cscript check_disks_percentage_space_used.vbs -h Ser1 -inst ""*"" -w 30 -c 70 [-user Ser1\Administrator -pass password -domain ITSP] " &vbCrlF
str=str&"Example: cscript check_disks_percentage_space_used.vbs -h Ser1 -inst ""C:, D:"" -w 30 -c 70 [-user Ser1\Administrator -pass password -domain ITSP] " &vbCrlF
str=str&"Example: cscript check_disks_percentage_space_used.vbs -h Ser1 -inst ""C:, D:"" -t ""70,90:50,80"" [-user Ser1\Administrator -pass password -domain ITSP] " &vbCrlF
wscript.echo str
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetAllArg.
'Descripton: Get all of arguments from command.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetAllArg()
On Error Resume Next
Dim i
argcountcommand=WScript.Arguments.Count
for i=0 to argcountcommand-1
arg(i)=WScript.Arguments(i)
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetOneArg.
'Descripton: Get an argument from command.
'Input: Yes.
' strName: Name of argument
'Output: Value.
'-------------------------------------------------------------------------------------------------
Function f_GetOneArg(strName)
On Error Resume Next
Dim i
for i=0 to argcountcommand-1
if (Ucase(arg(i))=Ucase(strName)) then
f_GetOneArg=arg(i+1)
Exit Function
end if
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInstance.
'Descripton: Get infomation at Local Host.
'Input: instance.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetInstance(instance)
On Error Resume Next
strResultTemp1 = ""
strResultTemp2 = ""
intResultTemp1 = 0
strResultTemp = ""
intResultTemp = 0
if(instance = "*") then
For Each objWMI in colWMI
strName = objWMI.Properties_("DeviceID")
strPropName = "Percentage Space Used"
intSize = objWMI.Properties_("Size")
intFreeSpace = objWMI.Properties_("FreeSpace")
if(intSize <> "") then
intValue = Int(((intSize - intFreeSpace)*100)/intSize)
else
intValue = 0
end if
f_Display()
strResultTemp1 = strResultTemp1 & strResultTemp3
strResultTemp2 = strResultTemp2 & strResultTemp4
Next
intReturnTemp = intReturnTemp1
Exit Function
else
For Each objWMI in colWMI
strName = objWMI.Properties_("DeviceID")
strPropName = "Percentage Space Used"
intSize = objWMI.Properties_("Size")
intFreeSpace = objWMI.Properties_("FreeSpace")
if(Ucase(Trim(strName)) = Ucase(Trim(instance))) then
if(intSize <> "") then
intValue = Int(((intSize - intFreeSpace)*100)/intSize)
else
intValue = 0
end if
f_Display()
strResultTemp1 = strResultTemp1 & strResultTemp3
strResultTemp2 = strResultTemp2 & strResultTemp4
intReturnTemp = intReturnTemp1
Exit Function
end if
Next
strResultTemp1 = "Unknown - " & instance & " no row returned."
intReturnTemp = intUnknown
Exit Function
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetPrefix.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetPrefix(intValue)
On Error Resume Next
strPrefix = ""
If(warningValue <> "" And criticalValue = "") Then
If (IsNumeric(warningValue)) Then
If (Int(intValue) < Int(warningValue)) Then
returnValue=0
strPrefix= "OK - "
Else
returnValue=1
strPrefix= "Warning - "
End If
Else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
If(warningValue = "" And criticalValue <> "") Then
If (IsNumeric(criticalValue)) Then
If (Int(intValue) < Int(criticalValue)) Then
returnValue=0
strPrefix= "OK - "
Else
returnValue=2
strPrefix= "Critical - "
End If
Else
Wscript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
If (warningValue <> "" And criticalValue <> "") Then
If (IsNumeric(warningValue) And IsNumeric(criticalValue)) Then
if (Int(warningValue) < Int(criticalValue)) then
if (Int(intValue) < Int(warningValue)) then
returnValue=0
strPrefix= "OK - "
else
if (Int(intValue) < Int(criticalValue)) then
returnValue=1
strPrefix= "Warning - "
else
returnValue=2
strPrefix= "Critical - "
end if
end if
else
if (Int(intValue) > Int(warningValue)) then
returnValue=0
strPrefix= "OK - "
else
if (Int(intValue) > Int(criticalValue)) then
returnValue=1
strPrefix= "Warning - "
else
returnValue=2
strPrefix= "Critical - "
end if
end if
end If
Else
Wscript.Echo "Error! Arguments wrong, please verify -w -c parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetPrefixWithRange.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetPrefixWithRange(intValue)
On Error Resume Next
lWarningValue = ""
uWarningValue = ""
lCriticalValue= ""
uCriticalValue= ""
warningReturn = 0
criticalReturn = 0
If(warningValue <> "") Then
f_GetWarningValueFromRange(warningValue)
End If
If(criticalValue <> "") Then
f_GetCriticalValueFromRange(criticalValue)
End If
strPrefix = ""
'verify warning
If((lWarningValue <> "") And (uWarningValue <> "")) Then
If(Int(lWarningValue) <= Int(uWarningValue)) Then
If((Int(lWarningValue) >= Int(intValue)) Or (Int(intValue) >= Int(uWarningValue))) Then
warningReturn=1
End If
Else
If((Int(intValue) >= Int(uWarningValue) ) And (Int(intValue) <= Int(lWarningValue))) Then
warningReturn=1
End If
End If
End If
If((lWarningValue <> "") And (uWarningValue = "")) Then
If(Int(intValue) <= Int(lWarningValue)) Then
warningReturn=1
End If
End If
If((lWarningValue = "") And (uWarningValue <> "")) Then
If(Int(intValue) >= Int(uWarningValue)) Then
warningReturn=1
End If
End If
'verify critical
If((lCriticalValue <> "") And (uCriticalValue <> "")) Then
If(Int(lCriticalValue) <= Int(uCriticalValue)) Then
If((Int(lCriticalValue) >= Int(intValue)) Or (Int(intValue) >= Int(uCriticalValue))) Then
criticalReturn=2
End If
Else
If((Int(intValue) >= Int(uCriticalValue) ) And (Int(intValue) <= Int(lCriticalValue))) Then
criticalReturn=2
End If
End If
End If
If((lCriticalValue <> "") And (uCriticalValue = "")) Then
If(Int(intValue) <= Int(lCriticalValue)) Then
criticalReturn=2
End If
End If
If((lCriticalValue = "") And (uCriticalValue <> "")) Then
If(Int(intValue) >= Int(uCriticalValue)) Then
criticalReturn=2
End If
End If
'return result
If(criticalReturn = 2) Then
returnValue=2
strPrefix= "Critical - "
Else
If(warningReturn = 1) Then
returnValue=1
strPrefix= "Warning - "
Else
returnValue=0
strPrefix= "Ok - "
End If
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetWarningValueFromRange().
'Descripton: Get perform value at Local Host.
'Input: warningValueRange.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetWarningValueFromRange(warningValue)
On Error Resume Next
lWarningValue = ""
uWarningValue = ""
temp1 = 0
temp1 = InStr(1, warningValue, ":")
if(temp1 > 0) then
lWarningTemp = Mid(warningValue, 1, temp1 -1)
uWarningTemp = Mid(warningValue, temp1 +1, len(warningValue) - temp1)
if(IsNumeric(lWarningTemp) or IsNumeric(uWarningTemp)) then
lWarningValue = lWarningTemp
uWarningValue = uWarningTemp
else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
end if
else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetCriticalValueFromRange().
'Descripton: Get perform value at Local Host.
'Input: warningValueRange.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetCriticalValueFromRange(criticalValue)
On Error Resume Next
lCriticalValue = ""
uCriticalValue = ""
temp1 = 0
temp1 = InStr(1, criticalValue, ":")
if(temp1 > 0) then
lCriticalTemp = Mid(criticalValue, 1, temp1 -1)
uCriticalTemp = Mid(criticalValue, temp1 +1, len(criticalValue) - temp1)
if(IsNumeric(lCriticalTemp) or IsNumeric(uCriticalTemp)) then
lCriticalValue = lCriticalTemp
uCriticalValue = uCriticalTemp
else
Wscript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
end if
else
WScript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_Display.
'Descripton: Format data the same as output.
'Input: service.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Display()
On Error Resume Next
strDisplay1 = ""
strDisplay2 = ""
strResultTemp3 = ""
strResultTemp4 = ""
'strName = instance
'strPropName = "Number of processes with "
'intValue = count
Dim strDSName
strDSName = f_FormatDSName(strName)
if((warningValue <> "") Or (criticalValue <> "")) then
strDisplay1 = strName & " '" & strPropName & "'" & " = " & intValue & "; "
strDisplay2 = "'" & strDSName & "'" & "=" & intValue & ";" & warningValue & ";" & criticalValue & ";; "
If(InStr(1, warningValue, ":") > 0 Or InStr(1, criticalValue, ":") > 0) Then
f_GetPrefixWithRange(intValue)
Else
f_GetPrefix(intValue)
End If
strResultTemp3 = strResultTemp3 & strPrefix & strDisplay1
strResultTemp4 = strResultTemp4 & strDisplay2
if( intReturnTemp1 < returnValue) then
intReturnTemp1 = returnValue
end if
else
strResultTemp3 = strResultTemp3 & "OK - " & strName & " '" & strPropName & "'" & " = " & intValue & "; "
strResultTemp4 = ""
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_FormatDSName.
'Descripton: Get infomation at Local Host.
'Input: strName.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_FormatDSName(strName)
On Error Resume Next
first = 1
position1 = 0
position1 = InStr(first, strName, "=")
Dim proc_name
proc_name = ""
If(position1 > 0) Then
proc_name = Mid(strName,position1+1,(Len(strName)-position1))
proc_name = Replace(proc_name,".","_")
proc_name = Replace(proc_name,"-","_")
proc_name = Replace(proc_name,":","")
proc_name = Mid(proc_name,1, 19)
Else
proc_name = Mid(strName,position1+1,(Len(strName)-position1))
proc_name = Replace(proc_name,".","_")
proc_name = Replace(proc_name,"-","_")
proc_name = Replace(proc_name,":","")
proc_name = Mid(proc_name,1, 19)
End If
f_FormatDSName = proc_name
Exit Function
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_ExecQuery.
'Descripton: Format data the same as output.
'Input: service.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_ExecQuery()
On Error Resume Next
strQuery = "Select " & strProp & " from " & strClass & " where DriveType = 3"
Set colWMI = objWMIService.ExecQuery(strQuery)
count = -1
count = colWMI.count
if(count = -1) then
Wscript.Echo "Unknown - No data received from WMI;"
Wscript.Quit(intUnknown)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInformation.
'Descripton: Get information data.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_GetInformation()
On Error Resume Next
strResult = ""
strResult1 = ""
strResult2 = ""
intReturn = 0
if(thresoldArraySize > 0 and (thresoldArraySize <> instanceArraySize)) then
Wscript.Echo "Error! Arguments wrong, number of instances and thresolds do not match."
Wscript.Quit(intError)
Exit Function
end if
If(thresoldArraySize > 0 and (thresoldArraySize = instanceArraySize)) then
for i = 0 to instanceArraySize -1
instance = instanceArray(i)
warningValue = warningArray(i)
criticalValue = criticalArray(i)
f_GetInstance(instance)
strResult1 = strResult1 & strResultTemp1
strResult2 = strResult2 & strResultTemp2
if intReturn < intReturnTemp then
intReturn = intReturnTemp
end if
Next
Else
If(instanceArraySize > 0 and (warningArraySize > 1 Or criticalArraySize > 1)) Then
for i = 0 to instanceArraySize -1
instance = instanceArray(i)
warningValue = warningArray(i)
criticalValue = criticalArray(i)
f_GetInstance(instance)
strResult1 = strResult1 & strResultTemp1
strResult2 = strResult2 & strResultTemp2
if intReturn < intReturnTemp then
intReturn = intReturnTemp
end if
Next
Else
for i = 0 to instanceArraySize -1
instance = instanceArray(i)
f_GetInstance(instance)
strResult1 = strResult1 & strResultTemp1
strResult2 = strResult2 & strResultTemp2
if intReturn < intReturnTemp then
intReturn = intReturnTemp
end if
Next
End If
End if
if(strResult2 = "") then
strResult = strResult1
else
strResult = strResult1 & "|" & strResult2
end if
Wscript.Echo strResult
Wscript.Quit(intReturn)
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInstances.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetInstances()
On Error Resume Next
first = 1
position = 0
instanceArraySize = 0
position = InStr(first, strInst, ",")
if (position = 0) then
instanceTemp = strInst
InstanceArraySize = 1
ReDim instanceArray(instanceArraySize)
instanceArray(0) = instanceTemp
else
do while (position > 0)
instanceTemp = Mid(strInst,first,position - first)
instanceArraySize = instanceArraySize + 1
ReDim Preserve instanceArray(instanceArraySize)
instanceArray(instanceArraySize -1) = Trim(instanceTemp)
first = position + 1
position = InStr(first, strInst, ",")
loop
instanceTemp = Mid(strInst,first,len(strInst))
instanceArraySize = instanceArraySize + 1
ReDim Preserve instanceArray(instanceArraySize)
instanceArray(instanceArraySize -1) = Trim(instanceTemp)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetWarningCriticalValues.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetWarningCriticalValues()
On Error Resume Next
position1 = 0
position2 = 0
position3 = 0
position4 = 0
temp1 = 1
temp2 = 1
warningArraySize = 0
criticalArraySize = 0
'get warning
position2 = InStr(temp1, warningValueString, ",")
If(position2 = 0) then
position2 = Len(warningValueString)+1
end if
If(position2 > position1) then
do while (position2 > position1)
warningPair = Mid(warningValueString, position1 + 1, (position2 - position1 -1))
warningArraySize = warningArraySize + 1
ReDim Preserve warningArray(warningArraySize)
warningArray(warningArraySize -1) = Trim(warningPair)
temp1 = position2 + 1
position1 = position2
position2 = InStr(temp1, warningValueString, ",")
If(position2 = 0) then
position2 = Len(warningValueString)+1
End If
loop
end If
If(Int(warningArraySize) < Int(instanceArraySize)) Then
ReDim Preserve warningArray(instanceArraySize)
For i = 0 To (instanceArraySize - warningArraySize - 1)
warningArray(warningArraySize +i) = warningArray(warningArraySize-1)
Next
warningArraySize = instanceArraySize
End If
'get critical
position4 = InStr(temp2, criticalValueString, ",")
If(position4 = 0) then
position4 = Len(criticalValueString)+1
end if
If(position4 > position3) then
do while (position4 > position3)
criticalPair = Mid(criticalValueString, position3 + 1, (position4 - position3 -1))
criticalArraySize = criticalArraySize + 1
ReDim Preserve criticalArray(criticalArraySize)
criticalArray(criticalArraySize -1) = Trim(criticalPair)
temp2 = position4 + 1
position3 = position4
position4 = InStr(temp2, criticalValueString, ",")
If(position4 = 0) then
position4 = Len(criticalValueString)+1
End If
loop
End If
If(Int(criticalArraySize) < Int(instanceArraySize)) Then
ReDim Preserve criticalArray(instanceArraySize)
For i = 0 To (instanceArraySize - criticalArraySize - 1)
criticalArray(criticalArraySize +i) = criticalArray(criticalArraySize-1)
Next
criticalArraySize = instanceArraySize
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetThresolds.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetThresolds()
On Error Resume Next
first = 1
position1 = 0
position2 = 0
temp = 1
temp1 = 0
thresoldArraySize = 0
position2 = InStr(temp, strThresolds, ":")
If(position2 = 0) then
position2 = Len(strThresolds)+1
end if
if(position2 > position1) then
do while (position2 > position1)
thresoldPair = Mid(strThresolds, position1 + 1, (position2 - position1 -1))
temp1 = InStr(1, thresoldPair, ",")
if(temp1 > 0) then
warningTemp = Mid(thresoldPair, 1, temp1 -1)
criticalTemp = Mid(thresoldPair, temp1 +1, len(thresoldPair) - temp1)
if(IsNumeric(warningTemp) or IsNumeric(criticalTemp)) then
thresoldArraySize = thresoldArraySize + 1
ReDim Preserve warningArray(thresoldArraySize)
ReDim Preserve criticalArray(thresoldArraySize)
warningArray(thresoldArraySize -1) = Trim(warningTemp)
criticalArray(thresoldArraySize -1) = Trim(criticalTemp)
else
Wscript.Echo "Error! Arguments wrong, please verify -t parameter"
Wscript.Quit(intError)
Exit Function
end if
Else
Wscript.Echo "Error! Arguments wrong, please verify -t parameter"
Wscript.Quit(intError)
Exit Function
end if
temp = position2 + 1
position1 = position2
position2 = InStr(temp, strThresolds, ":")
if(position2 = 0) then
position2 = Len(strThresolds)+1
end if
loop
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_LocalPerfValue.
'Descripton: Get perform value at Local Host.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_LocalPerfValue()
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\" & strNameSpace)
f_Error()
f_ExecQuery()
'f_GetInstances()
f_GetInformation()
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_RemotePerfValue.
'Descripton: Get perform values at Remote Host.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_RemotePerfValue()
On Error Resume Next
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
if (strDomain = "") then
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass )
f_Error()
else
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass,"MS_409","ntlmdomain:" + strDomain )
f_Error()
end if
objWMIService.Security_.ImpersonationLevel = 3
f_Error()
f_ExecQuery()
'f_GetInstances()
f_GetInformation()
End Function
'*************************************************************************************************
' Main Function
'*************************************************************************************************
'/////////////////////
strCommandName="check_disks_percentage_space_used.vbs"
strDescription="Enumerate the needed windows host information."
'/////////////////////
strNameSpace = "root\cimv2"
strClass = "Win32_LogicalDisk"
strProp = "DeviceID, Size, FreeSpace"
f_GetAllArg()
tempCount = argcountcommand/2
f_Error()
if ((UCase(arg(0))="-H") Or (UCase(arg(0))="--HELP")) and (argcountcommand=1) then
f_help()
else
if( ((argcountcommand Mod 2) = 0) and (1 < tempCount < 8)) then
strComputer = f_GetOneArg("-h")
strInst = f_GetOneArg("-inst")
f_GetInstances()
warningValue = f_GetOneArg("-w")
warningValueString = f_GetOneArg("-w")
criticalValue = f_GetOneArg("-c")
criticalValueString = f_GetOneArg("-c")
If((warningValueString <> "") Or (criticalValueString <> "")) Then
f_GetWarningCriticalValues()
End if
strThresolds = f_GetOneArg("-t")
strUser = f_GetOneArg("-user")
strPass = f_GetOneArg("-pass")
strDomain = f_GetOneArg("-domain")
if((strComputer = "") or (strInst = "")) then
Wscript.Echo "Error! Arguments wrong, require verify -h -inst parameters"
Wscript.Quit(intError)
else
Select Case tempCount
Case 2:
f_LocalPerfValue()
Case 3:
if(strThresolds <> "") then
f_GetThresolds()
f_LocalPerfValue()
else
Wscript.Echo "Error! Arguments wrong, please verify -t parameters"
Wscript.Quit(intError)
end if
Case 4:
if ((warningValue <> "") and (criticalValue <> "")) then
f_LocalPerfValue()
end if
if ((strUser <> "") and (strPass <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong, please verify -user -pass or -w -c parameters"
Wscript.Quit(intError)
end if
Case 5:
if ((strUser <> "") and (strPass <> "") and (strThresolds <> "")) then
f_GetThresolds()
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong, please verify -user -pass or -t parameters"
Wscript.Quit(intError)
end if
Case 6:
if ((strUser <> "") and (strPass <> "") and (warningValue <> "") and (criticalValue <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong for remote check, please verify -w -c -user -pass parameters"
Wscript.Quit(intError)
end if
Case 7:
if ((strUser <> "") and (strPass <> "") and (warningValue <> "") and (criticalValue <> "") and (strDomain <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong for remote check, please verify -w -c -user -pass -domain parameters"
Wscript.Quit(intError)
end if
Case Else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
End Select
end if
else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
end if
end if

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,841 @@
' Copyright 2007 GroundWork Open Source Inc.
'
' This program is free software; you can redistribute it and/or
' modify it under the terms of the GNU General Public License
' as published by the Free Software Foundation; version 2
' of the License.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
'
' Author Dr. Dave Blunt at GroundWork Open Source Inc. (dblunt@groundworkopensource.com)
'*************************************************************************************************
' Public Variable
'*************************************************************************************************
Const intOK = 0
Const intWarning = 1
Const intCritical = 2
Const intError = 3
Const intUnknown = 3
Dim argcountcommand
Dim arg(20)
Dim strComputer
Dim strClass
Dim strProp
Dim strInst
Dim warningValue
Dim warningValueString
Dim criticalValue
Dim criticalValueString
Dim strUser
Dim strPass
Dim strDomain
Dim strNameSpace
Dim strDescription
Dim strCommandName
Dim strResultTemp
Dim strResult
Dim strResult1
Dim strResult2
Dim intReturnTemp
Dim intReturn
Dim strResultTemp1
Dim strResultTemp2
Dim strResultTemp3
Dim strResultTemp4
Dim intReturnTemp1
Dim strPrefix
Dim intValue
Dim returnValue
Dim instance
Dim instanceArray()
Dim instanceArraySize
Dim warningArraySize
Dim criticalArraySize
Dim warningArray()
Dim criticalArray()
Dim lWarningValue
Dim uWarningValue
Dim lCriticalValue
Dim uCriticalValue
Dim ArgCount
Dim strArgMain(10)
Dim strArgSortDes(10)
Dim strArgDetailDes(10)
Dim strArgExample(10)
Dim objWMIService, colWMI,objWMI,objSWbemLocator
strComputer=""
strClass = ""
strProp = ""
strInst = ""
warningValue = -1
criticalValue = -1
strUser = ""
strPass = ""
strDomain = ""
intReturnTemp1 = 0
'*************************************************************************************************
' Functions and Subs
'*************************************************************************************************
'-------------------------------------------------------------------------------------------------
'Function Name: f_Error.
'Descripton: Display an error notice include : Error Number and Error Description.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Error()
nbrError = err.number
if (nbrError <> 0 ) then
Select Case nbrError
Case 462, -2147023174
strExitMsg = "Timeout connecting to WMI on this host! Error Number: " & nbrError & " Description: " & err.description
Case -2147024891
strExitMsg = "Authentication failure to remote host! Error Number: " & nbrError & " Description: " & err.description
Case -2147217392
strExitMsg = "Error! Number: " & nbrError & " Description: Invalid Class"
Case Else
strExitMsg = "Error! Number: " & nbrError & " Description: " & err.description
End Select
wscript.echo strExitMsg
wscript.quit(intUnknown)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_Help.
'Descripton: Display help of command include : Description, Arguments, Examples
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Help()
Dim str
str="Check Number of Processes. If your Local Machine has the same Administrator account and password as the Remote Machine then you don't have to use the two last parameters."&vbCrlF&vbCrlF
str=str&"cscript check_proc_num.vbs -h hostname -inst instancename [-w warning_level -c critical_level] [-user username -pass password [-domain domain]]"&vbCrlF
str=str&vbCrlF
str=str&"-h [--help] Help."&vbCrlF
str=str&"-h hostname Host name."&vbCrlF
str=str&"-inst instance Needed Instance."&vbCrlF
str=str&"-w warning_level Warning threshold."&vbCrlF
str=str&"-c critical_level Critical threshold."&vbCrlF
str=str&"-user username Account Administrator on Remote Machine."&vbCrlF
str=str&"-pass password Password Account Administrator on Remote Machine."&vbCrlF
str=str&"-domain domain Domain Name of Remote Machine."&vbCrlF
str=str&vbCrlF
str=str&"Example: cscript check_proc_num.vbs -h Ser1 -inst ""cmd.exe"" -w 5 -c 10 [-user Ser1\Administrator -pass password -domain ITSP] "
str=str&"Example: cscript check_proc_num.vbs -h Ser1 -inst ""cmd.exe,firefox.exe"" -w 5 -c 10 [-user Ser1\Administrator -pass password -domain ITSP] "
wscript.echo str
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetAllArg.
'Descripton: Get all of arguments from command.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetAllArg()
On Error Resume Next
Dim i
argcountcommand=WScript.Arguments.Count
for i=0 to argcountcommand-1
arg(i)=WScript.Arguments(i)
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetOneArg.
'Descripton: Get an argument from command.
'Input: Yes.
' strName: Name of argument
'Output: Value.
'-------------------------------------------------------------------------------------------------
Function f_GetOneArg(strName)
On Error Resume Next
Dim i
for i=0 to argcountcommand-1
if (Ucase(arg(i))=Ucase(strName)) then
f_GetOneArg=arg(i+1)
Exit Function
end if
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInstance.
'Descripton: Get infomation at Local Host.
'Input: instance.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetInstance(instance)
On Error Resume Next
strResultTemp = ""
strResultTemp1 = ""
strResultTemp2 = ""
intResultTemp = 0
strInstanceTemp1 = ""
strInstanceTemp2 = ""
intInstanceTemp1 = 0
intInstanceTemp2 = 0
'Depend on strInfo parameters to get the result value
intInstanceTemp1 = InStr(1,instance,"=")
strInstanceTemp1 = Mid(instance,1,intInstanceTemp1-1)
intInstanceTemp2 = Len(instance)
strInstanceTemp2 = Mid(instance,intInstanceTemp1+1,intInstanceTemp2-intInstanceTemp1)
instance=strInstanceTemp1 & "='" & strInstanceTemp2 & "'"
strQuery = "Select " & strProp & " from " & strClass & " where " & instance
Set colWMI = objWMIService.ExecQuery(strQuery)
count = -1
count = colWMI.count
if(count = -1) then
Wscript.Echo "Unknown - No data received from WMI;"
Wscript.Quit(intUnknown)
else
if(colWMI.count > 0) then
f_FormatData(colWMI.count)
strResultTemp1 = strResultTemp1 & strResultTemp3
strResultTemp2 = strResultTemp2 & strResultTemp4
intReturnTemp = intReturnTemp1
Exit Function
else
f_FormatData(0)
strResultTemp1 = strResultTemp1 & strResultTemp3
strResultTemp2 = strResultTemp2 & strResultTemp4
intReturnTemp = intReturnTemp1
Exit Function
end if
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetPrefix.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetPrefix(intValue)
On Error Resume Next
strPrefix = ""
If(warningValue <> "" And criticalValue = "") Then
If (IsNumeric(warningValue)) Then
If (Int(intValue) < Int(warningValue)) Then
returnValue=0
strPrefix= "OK - "
Else
returnValue=1
strPrefix= "Warning - "
End If
Else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
If(warningValue = "" And criticalValue <> "") Then
If (IsNumeric(criticalValue)) Then
If (Int(intValue) < Int(criticalValue)) Then
returnValue=0
strPrefix= "OK - "
Else
returnValue=2
strPrefix= "Critical - "
End If
Else
Wscript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
If (warningValue <> "" And criticalValue <> "") Then
If (IsNumeric(warningValue) And IsNumeric(criticalValue)) Then
if (Int(warningValue) < Int(criticalValue)) then
if (Int(intValue) < Int(warningValue)) then
returnValue=0
strPrefix= "OK - "
else
if (Int(intValue) < Int(criticalValue)) then
returnValue=1
strPrefix= "Warning - "
else
returnValue=2
strPrefix= "Critical - "
end if
end if
else
if (Int(intValue) > Int(warningValue)) then
returnValue=0
strPrefix= "OK - "
else
if (Int(intValue) > Int(criticalValue)) then
returnValue=1
strPrefix= "Warning - "
else
returnValue=2
strPrefix= "Critical - "
end if
end if
end If
Else
Wscript.Echo "Error! Arguments wrong, please verify -w -c parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetPrefixWithRange.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetPrefixWithRange(intValue)
On Error Resume Next
lWarningValue = ""
uWarningValue = ""
lCriticalValue= ""
uCriticalValue= ""
warningReturn = 0
criticalReturn = 0
If(warningValue <> "") Then
f_GetWarningValueFromRange(warningValue)
End If
If(criticalValue <> "") Then
f_GetCriticalValueFromRange(criticalValue)
End If
strPrefix = ""
'verify warning
If((lWarningValue <> "") And (uWarningValue <> "")) Then
If(Int(lWarningValue) <= Int(uWarningValue)) Then
If((Int(lWarningValue) >= Int(intValue)) Or (Int(intValue) >= Int(uWarningValue))) Then
warningReturn=1
End If
Else
If((Int(intValue) >= Int(uWarningValue) ) And (Int(intValue) <= Int(lWarningValue))) Then
warningReturn=1
End If
End If
End If
If((lWarningValue <> "") And (uWarningValue = "")) Then
If(Int(intValue) <= Int(lWarningValue)) Then
warningReturn=1
End If
End If
If((lWarningValue = "") And (uWarningValue <> "")) Then
If(Int(intValue) >= Int(uWarningValue)) Then
warningReturn=1
End If
End If
'verify critical
If((lCriticalValue <> "") And (uCriticalValue <> "")) Then
If(Int(lCriticalValue) <= Int(uCriticalValue)) Then
If((Int(lCriticalValue) >= Int(intValue)) Or (Int(intValue) >= Int(uCriticalValue))) Then
criticalReturn=2
End If
Else
If((Int(intValue) >= Int(uCriticalValue) ) And (Int(intValue) <= Int(lCriticalValue))) Then
criticalReturn=2
End If
End If
End If
If((lCriticalValue <> "") And (uCriticalValue = "")) Then
If(Int(intValue) <= Int(lCriticalValue)) Then
criticalReturn=2
End If
End If
If((lCriticalValue = "") And (uCriticalValue <> "")) Then
If(Int(intValue) >= Int(uCriticalValue)) Then
criticalReturn=2
End If
End If
'return result
If(criticalReturn = 2) Then
returnValue=2
strPrefix= "Critical - "
Else
If(warningReturn = 1) Then
returnValue=1
strPrefix= "Warning - "
Else
returnValue=0
strPrefix= "Ok - "
End If
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetWarningValueFromRange().
'Descripton: Get perform value at Local Host.
'Input: warningValueRange.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetWarningValueFromRange(warningValue)
On Error Resume Next
lWarningValue = ""
uWarningValue = ""
temp1 = 0
temp1 = InStr(1, warningValue, ":")
if(temp1 > 0) then
lWarningTemp = Mid(warningValue, 1, temp1 -1)
uWarningTemp = Mid(warningValue, temp1 +1, len(warningValue) - temp1)
if(IsNumeric(lWarningTemp) or IsNumeric(uWarningTemp)) then
lWarningValue = lWarningTemp
uWarningValue = uWarningTemp
else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
end if
else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetCriticalValueFromRange().
'Descripton: Get perform value at Local Host.
'Input: warningValueRange.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetCriticalValueFromRange(criticalValue)
On Error Resume Next
lCriticalValue = ""
uCriticalValue = ""
temp1 = 0
temp1 = InStr(1, criticalValue, ":")
if(temp1 > 0) then
lCriticalTemp = Mid(criticalValue, 1, temp1 -1)
uCriticalTemp = Mid(criticalValue, temp1 +1, len(criticalValue) - temp1)
if(IsNumeric(lCriticalTemp) or IsNumeric(uCriticalTemp)) then
lCriticalValue = lCriticalTemp
uCriticalValue = uCriticalTemp
else
Wscript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
end if
else
WScript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_FormatData.
'Descripton: Format data the same as output.
'Input: service.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_FormatData(count)
On Error Resume Next
strDisplay1 = ""
strDisplay2 = ""
strResultTemp3 = ""
strResultTemp4 = ""
strName = instance
strPropName = "Number of processes with "
intValue = count
Dim strDSName
strDSName = f_FormatDSName(strName)
if((warningValue <> "") Or (criticalValue <> "")) then
strDisplay1 = strPropName & strName & " = " & intValue & "; "
strDisplay2 = "'" & strDSName & "'" & "=" & intValue & ";" & warningValue & ";" & criticalValue & ";; "
If(InStr(1, warningValue, ":") > 0 Or InStr(1, criticalValue, ":") > 0) Then
f_GetPrefixWithRange(intValue)
Else
f_GetPrefix(intValue)
End If
strResultTemp3 = strResultTemp3 & strPrefix & strDisplay1
strResultTemp4 = strResultTemp4 & strDisplay2
if( intReturnTemp1 < returnValue) then
intReturnTemp1 = returnValue
end if
else
strResultTemp3 = strResultTemp3 & "OK - " & strPropName & strName & " = " & intValue & "; "
strResultTemp4 = ""
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_FormatDSName.
'Descripton: Get infomation at Local Host.
'Input: strName.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_FormatDSName(strName)
On Error Resume Next
first = 1
position1 = 0
position1 = InStr(first, strName, "=")
Dim proc_name
proc_name = ""
If(position1 > 0) Then
proc_name = Mid(strName,position1+1,(Len(strName)-position1))
proc_name = Replace(proc_name,".","_")
proc_name = Replace(proc_name,"-","_")
proc_name = Mid(proc_name,1, 19)
Else
proc_name = Mid(strName,position1+1,(Len(strName)-position1))
proc_name = Replace(proc_name,".","_")
proc_name = Replace(proc_name,"-","_")
proc_name = Mid(proc_name,1, 19)
End If
f_FormatDSName = proc_name
Exit Function
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInformation.
'Descripton: Get information data.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_GetInformation()
On Error Resume Next
strResult = ""
strResult1 = ""
strResult2 = ""
intReturn = 0
If(instanceArraySize > 0 and (warningArraySize > 1 Or criticalArraySize > 1)) Then
for i = 0 to instanceArraySize -1
instance = instanceArray(i)
warningValue = warningArray(i)
criticalValue = criticalArray(i)
f_GetInstance(instance)
strResult1 = strResult1 & strResultTemp1
strResult2 = strResult2 & strResultTemp2
if intReturn < intReturnTemp then
intReturn = intReturnTemp
end if
Next
Else
for i = 0 to instanceArraySize -1
instance = instanceArray(i)
f_GetInstance(instance)
strResult1 = strResult1 & strResultTemp1
strResult2 = strResult2 & strResultTemp2
if intReturn < intReturnTemp then
intReturn = intReturnTemp
end if
Next
end if
if(strResult2 = "") then
strResult = strResult1
else
strResult = strResult1 & "|" & strResult2
end if
Wscript.Echo strResult
Wscript.Quit(intReturn)
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInstances.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetInstances()
On Error Resume Next
first = 1
position = 0
instanceArraySize = 0
position = InStr(first, strInst, ",")
if (position = 0) then
instanceTemp = strInst
InstanceArraySize = 1
ReDim instanceArray(instanceArraySize)
instanceArray(0) = instanceTemp
else
do while (position > 0)
instanceTemp = Mid(strInst,first,position - first)
instanceArraySize = instanceArraySize + 1
ReDim Preserve instanceArray(instanceArraySize)
instanceArray(instanceArraySize -1) = Trim(instanceTemp)
first = position + 1
position = InStr(first, strInst, ",")
loop
instanceTemp = Mid(strInst,first,len(strInst))
instanceArraySize = instanceArraySize + 1
ReDim Preserve instanceArray(instanceArraySize)
instanceArray(instanceArraySize -1) = Trim(instanceTemp)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetWarningCriticalValues.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetWarningCriticalValues()
On Error Resume Next
position1 = 0
position2 = 0
position3 = 0
position4 = 0
temp1 = 1
temp2 = 1
warningArraySize = 0
criticalArraySize = 0
'get warning
position2 = InStr(temp1, warningValueString, ",")
If(position2 = 0) then
position2 = Len(warningValueString)+1
end if
If(position2 > position1) then
do while (position2 > position1)
warningPair = Mid(warningValueString, position1 + 1, (position2 - position1 -1))
warningArraySize = warningArraySize + 1
ReDim Preserve warningArray(warningArraySize)
warningArray(warningArraySize -1) = Trim(warningPair)
temp1 = position2 + 1
position1 = position2
position2 = InStr(temp1, warningValueString, ",")
If(position2 = 0) then
position2 = Len(warningValueString)+1
End If
loop
end If
If(Int(warningArraySize) < Int(instanceArraySize)) Then
ReDim Preserve warningArray(instanceArraySize)
For i = 0 To (instanceArraySize - warningArraySize - 1)
warningArray(warningArraySize +i) = warningArray(warningArraySize-1)
Next
warningArraySize = instanceArraySize
End If
'get critical
position4 = InStr(temp2, criticalValueString, ",")
If(position4 = 0) then
position4 = Len(criticalValueString)+1
end if
If(position4 > position3) then
do while (position4 > position3)
criticalPair = Mid(criticalValueString, position3 + 1, (position4 - position3 -1))
criticalArraySize = criticalArraySize + 1
ReDim Preserve criticalArray(criticalArraySize)
criticalArray(criticalArraySize -1) = Trim(criticalPair)
temp2 = position4 + 1
position3 = position4
position4 = InStr(temp2, criticalValueString, ",")
If(position4 = 0) then
position4 = Len(criticalValueString)+1
End If
loop
End If
If(Int(criticalArraySize) < Int(instanceArraySize)) Then
ReDim Preserve criticalArray(instanceArraySize)
For i = 0 To (instanceArraySize - criticalArraySize - 1)
criticalArray(criticalArraySize +i) = criticalArray(criticalArraySize-1)
Next
criticalArraySize = instanceArraySize
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_LocalPerfValue.
'Descripton: Get perform value at Local Host.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_LocalPerfValue()
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\" & strNameSpace)
f_Error()
'Set colInstances = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & strComputer & "\" & strNameSpace).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
f_GetInformation()
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_RemotePerfValue.
'Descripton: Get perform values at Remote Host.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_RemotePerfValue()
On Error Resume Next
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
if (strDomain = "") then
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass )
f_Error()
'Set colInstances = objSWbemLocator.ConnectServer(strComputer, strNamespace , strUser, strPass).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
else
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass,"MS_409","ntlmdomain:" + strDomain )
f_Error()
'Set colInstances = objSWbemLocator.ConnectServer(strComputer, strNamespace , strUser, strPass,"MS_409","ntlmdomain:" & strDomain ).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
end if
objWMIService.Security_.ImpersonationLevel = 3
f_Error()
f_GetInformation()
End Function
'*************************************************************************************************
' Main Function
'*************************************************************************************************
'/////////////////////
strCommandName="check_proc_num.vbs"
strDescription="Check number processes of a process."
'/////////////////////
strNameSpace = "root\cimv2"
strClass = "Win32_Process"
strProp = "Name"
f_GetAllArg()
tempCount = argcountcommand/2
f_Error()
if ((UCase(arg(0))="-H") Or (UCase(arg(0))="--HELP")) and (argcountcommand=1) then
f_help()
else
if( ((argcountcommand Mod 2) = 0) and (1 < tempCount < 8)) then
strComputer = f_GetOneArg("-h")
strInst = f_GetOneArg("-inst")
f_GetInstances()
warningValue = f_GetOneArg("-w")
warningValueString = f_GetOneArg("-w")
criticalValue = f_GetOneArg("-c")
criticalValueString = f_GetOneArg("-c")
If((warningValueString <> "") Or (criticalValueString <> "")) Then
f_GetWarningCriticalValues()
End if
strUser = f_GetOneArg("-user")
strPass = f_GetOneArg("-pass")
strDomain = f_GetOneArg("-domain")
if((strComputer = "") or (strInst = "")) then
Wscript.Echo "Error! Arguments wrong, require verify -h -inst parameters"
Wscript.Quit(intError)
else
Select Case tempCount
Case 2:
f_LocalPerfValue()
Case 3:
f_LocalPerfValue()
Case 4:
if ((warningValue <> "") and (criticalValue <> "") ) then
f_LocalPerfValue()
end if
if ((strUser <> "") and (strPass <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong, please verify -user -pass or -w -c parameters"
Wscript.Quit(intError)
end if
Case 6:
if ((strUser <> "") and (strPass <> "") and (warningValue <> "") and (criticalValue <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong for remote check, please verify -w -c -user -pass parameters"
Wscript.Quit(intError)
end if
Case 7:
if ((strUser <> "") and (strPass <> "") and (warningValue <> "") and (criticalValue <> "") and (strDomain <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong for remote check, please verify -w -c -user -pass -domain parameters"
Wscript.Quit(intError)
end if
Case Else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
End Select
end if
else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
end if
end if

View File

@ -0,0 +1,856 @@
' Copyright 2007 GroundWork Open Source Inc.
'
' This program is free software; you can redistribute it and/or
' modify it under the terms of the GNU General Public License
' as published by the Free Software Foundation; version 2
' of the License.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
'
' Author Dr. Dave Blunt at GroundWork Open Source Inc. (dblunt@groundworkopensource.com)
'*************************************************************************************************
' Public Variable
'*************************************************************************************************
Const intOK = 0
Const intWarning = 1
Const intCritical = 2
Const intError = 3
Const intUnknown = 3
Dim argcountcommand
Dim arg(20)
Dim strComputer
Dim strClass
Dim strProp
Dim strInst
Dim warningValue
Dim warningValueString
Dim criticalValue
Dim criticalValueString
Dim strUser
Dim strPass
Dim strDomain
Dim strNameSpace
Dim strDescription
Dim strCommandName
Dim strResultTemp
Dim strResult
Dim strResult1
Dim strResult2
Dim intReturnTemp
Dim intReturn
Dim strResultTemp1
Dim strResultTemp2
Dim strResultTemp3
Dim strResultTemp4
Dim intReturnTemp1
Dim strPrefix
Dim intValue
Dim returnValue
Dim strPropBase
Dim strPropName
Dim instanceArray()
Dim instanceArraySize
Dim warningArraySize
Dim criticalArraySize
Dim warningArray()
Dim criticalArray()
Dim instance
Dim propArray()
Dim propArraySize
Dim lWarningValue
Dim uWarningValue
Dim lCriticalValue
Dim uCriticalValue
Dim ArgCount
Dim strArgMain(10)
Dim strArgSortDes(10)
Dim strArgDetailDes(10)
Dim strArgExample(10)
Dim objWMIService, colWMI,objWMI,objSWbemLocator
strComputer=""
strClass = ""
strProp = ""
strInst = ""
warningValue = -1
criticalValue = -1
strUser = ""
strPass = ""
strDomain = ""
intReturnTemp1 = 0
'*************************************************************************************************
' Functions and Subs
'*************************************************************************************************
'-------------------------------------------------------------------------------------------------
'Function Name: f_Error.
'Descripton: Display an error notice include : Error Number and Error Description.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Error()
nbrError = err.number
if (nbrError <> 0 ) then
Select Case nbrError
Case 462, -2147023174
strExitMsg = "Timeout connecting to WMI on this host! Error Number: " & nbrError & " Description: " & err.description
Case -2147024891
strExitMsg = "Authentication failure to remote host! Error Number: " & nbrError & " Description: " & err.description
Case -2147217392
strExitMsg = "Error! Number: " & nbrError & " Description: Invalid Class"
Case Else
strExitMsg = "Error! Number: " & nbrError & " Description: " & err.description
End Select
wscript.echo strExitMsg
wscript.quit(intUnknown)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_Help.
'Descripton: Display help of command include : Description, Arguments, Examples
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Help()
Dim str
str="Check Raw Fraction. If your Local Machine has the same Administrator account and password as the Remote Machine then you don't have to use the two last parameters."&vbCrlF&vbCrlF
str=str&"cscript check_raw_fraction.vbs -h hostname -class classname -prop property -inst instancename [-w warning_level -c critical_level] [-user username -pass password [-domain domain]]"&vbCrlF
str=str&vbCrlF
str=str&"-h [--help] Help."&vbCrlF
str=str&"-h hostname Host name."&vbCrlF
str=str&"-class classname Class name."&vbCrlF
str=str&"-prop property Property of Class."&vbCrlF
str=str&"-inst instance Needed Instance."&vbCrlF
str=str&"-w warning_level Warning threshold."&vbCrlF
str=str&"-c critical_level Critical threshold."&vbCrlF
str=str&"-user username Account Administrator on Remote Machine."&vbCrlF
str=str&"-pass password Password Account Administrator on Remote Machine."&vbCrlF
str=str&"-domain domain Domain Name of Remote Machine."&vbCrlF
str=str&vbCrlF
str=str&"Example: cscript check_raw_fraction.vbs -h Ser1 -class Win32_PerfRawData_PerfDisk_LogicalDisk -prop PercentFreeSpace -inst ""*"" -w 30 -c 70 [-user Ser1\Administrator -pass password -domain ITSP] " &vbCrlF
str=str&"Example: cscript check_raw_fraction.vbs -h Ser1 -class Win32_PerfRawData_PerfDisk_LogicalDisk -prop PercentFreeSpace -inst ""name=C:"" -w 30 -c 70 [-user Ser1\Administrator -pass password -domain ITSP] "
wscript.echo str
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetAllArg.
'Descripton: Get all of arguments from command.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetAllArg()
On Error Resume Next
Dim i
argcountcommand=WScript.Arguments.Count
for i=0 to argcountcommand-1
arg(i)=WScript.Arguments(i)
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetOneArg.
'Descripton: Get an argument from command.
'Input: Yes.
' strName: Name of argument
'Output: Value.
'-------------------------------------------------------------------------------------------------
Function f_GetOneArg(strName)
On Error Resume Next
Dim i
for i=0 to argcountcommand-1
if (Ucase(arg(i))=Ucase(strName)) then
f_GetOneArg=arg(i+1)
Exit Function
end if
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInstance.
'Descripton: Get infomation at Local Host.
'Input: instance.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetInstance(instance)
On Error Resume Next
strResultTemp1 = ""
strResultTemp2 = ""
strResultTemp = ""
intResultTemp = 0
strInstanceTemp1 = ""
strInstanceTemp2 = ""
intInstanceTemp1 = 0
intInstanceTemp2 = 0
strPropBase = ""
strPropBase = strProp & "_Base"
'Depend on strInfo parameters to get the result value
if(instance = "*") then
strQuery = "Select " & strProp & ", " & strPropBase & " from " & strClass
Set colWMI = objWMIService.ExecQuery(strQuery)
else
intInstanceTemp1 = InStr(1,instance,"=")
strInstanceTemp1 = Mid(instance,1,intInstanceTemp1-1)
intInstanceTemp2 = Len(instance)
strInstanceTemp2 = Mid(instance,intInstanceTemp1+1,intInstanceTemp2-intInstanceTemp1)
instance=strInstanceTemp1 & "='" & strInstanceTemp2 & "'"
strQuery = "Select " & strProp & ", " & strPropBase & " from " & strClass & " where " & instance
Set colWMI = objWMIService.ExecQuery(strQuery)
end if
count = -1
count = colWMI.count
if(count = -1) then
Wscript.Echo "Unknown - No data received from WMI;"
Wscript.Quit(intUnknown)
else
if(colWMI.count > 0) then
f_FormatData(colWMI)
strResultTemp1 = strResultTemp1 & strResultTemp3
strResultTemp2 = strResultTemp2 & strResultTemp4
intReturnTemp = intReturnTemp1
Exit Function
else
strResultTemp1 = "Unknown - " & instance &" query: No row returned."
intReturnTemp = intUnknown
Exit Function
end if
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetPrefix.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetPrefix(intValue)
On Error Resume Next
strPrefix = ""
If(warningValue <> "" And criticalValue = "") Then
If (IsNumeric(warningValue)) Then
If (Int(intValue) < Int(warningValue)) Then
returnValue=0
strPrefix= "OK - "
Else
returnValue=1
strPrefix= "Warning - "
End If
Else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
If(warningValue = "" And criticalValue <> "") Then
If (IsNumeric(criticalValue)) Then
If (Int(intValue) < Int(criticalValue)) Then
returnValue=0
strPrefix= "OK - "
Else
returnValue=2
strPrefix= "Critical - "
End If
Else
Wscript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
If (warningValue <> "" And criticalValue <> "") Then
If (IsNumeric(warningValue) And IsNumeric(criticalValue)) Then
if (Int(warningValue) < Int(criticalValue)) then
if (Int(intValue) < Int(warningValue)) then
returnValue=0
strPrefix= "OK - "
else
if (Int(intValue) < Int(criticalValue)) then
returnValue=1
strPrefix= "Warning - "
else
returnValue=2
strPrefix= "Critical - "
end if
end if
else
if (Int(intValue) > Int(warningValue)) then
returnValue=0
strPrefix= "OK - "
else
if (Int(intValue) > Int(criticalValue)) then
returnValue=1
strPrefix= "Warning - "
else
returnValue=2
strPrefix= "Critical - "
end if
end if
end If
Else
Wscript.Echo "Error! Arguments wrong, please verify -w -c parameter"
Wscript.Quit(intError)
Exit Function
End If
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetPrefixWithRange.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetPrefixWithRange(intValue)
On Error Resume Next
lWarningValue = ""
uWarningValue = ""
lCriticalValue= ""
uCriticalValue= ""
warningReturn = 0
criticalReturn = 0
If(warningValue <> "") Then
f_GetWarningValueFromRange(warningValue)
End If
If(criticalValue <> "") Then
f_GetCriticalValueFromRange(criticalValue)
End If
strPrefix = ""
'verify warning
If((lWarningValue <> "") And (uWarningValue <> "")) Then
If(Int(lWarningValue) <= Int(uWarningValue)) Then
If((Int(lWarningValue) >= Int(intValue)) Or (Int(intValue) >= Int(uWarningValue))) Then
warningReturn=1
End If
Else
If((Int(intValue) >= Int(uWarningValue) ) And (Int(intValue) <= Int(lWarningValue))) Then
warningReturn=1
End If
End If
End If
If((lWarningValue <> "") And (uWarningValue = "")) Then
If(Int(intValue) <= Int(lWarningValue)) Then
warningReturn=1
End If
End If
If((lWarningValue = "") And (uWarningValue <> "")) Then
If(Int(intValue) >= Int(uWarningValue)) Then
warningReturn=1
End If
End If
'verify critical
If((lCriticalValue <> "") And (uCriticalValue <> "")) Then
If(Int(lCriticalValue) <= Int(uCriticalValue)) Then
If((Int(lCriticalValue) >= Int(intValue)) Or (Int(intValue) >= Int(uCriticalValue))) Then
criticalReturn=2
End If
Else
If((Int(intValue) >= Int(uCriticalValue) ) And (Int(intValue) <= Int(lCriticalValue))) Then
criticalReturn=2
End If
End If
End If
If((lCriticalValue <> "") And (uCriticalValue = "")) Then
If(Int(intValue) <= Int(lCriticalValue)) Then
criticalReturn=2
End If
End If
If((lCriticalValue = "") And (uCriticalValue <> "")) Then
If(Int(intValue) >= Int(uCriticalValue)) Then
criticalReturn=2
End If
End If
'return result
If(criticalReturn = 2) Then
returnValue=2
strPrefix= "Critical - "
Else
If(warningReturn = 1) Then
returnValue=1
strPrefix= "Warning - "
Else
returnValue=0
strPrefix= "Ok - "
End If
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetWarningValueFromRange().
'Descripton: Get perform value at Local Host.
'Input: warningValueRange.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetWarningValueFromRange(warningValue)
On Error Resume Next
lWarningValue = ""
uWarningValue = ""
temp1 = 0
temp1 = InStr(1, warningValue, ":")
if(temp1 > 0) then
lWarningTemp = Mid(warningValue, 1, temp1 -1)
uWarningTemp = Mid(warningValue, temp1 +1, len(warningValue) - temp1)
if(IsNumeric(lWarningTemp) or IsNumeric(uWarningTemp)) then
lWarningValue = lWarningTemp
uWarningValue = uWarningTemp
else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
end if
else
Wscript.Echo "Error! Arguments wrong, please verify -w parameter"
Wscript.Quit(intError)
Exit Function
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetCriticalValueFromRange().
'Descripton: Get perform value at Local Host.
'Input: warningValueRange.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetCriticalValueFromRange(criticalValue)
On Error Resume Next
lCriticalValue = ""
uCriticalValue = ""
temp1 = 0
temp1 = InStr(1, criticalValue, ":")
if(temp1 > 0) then
lCriticalTemp = Mid(criticalValue, 1, temp1 -1)
uCriticalTemp = Mid(criticalValue, temp1 +1, len(criticalValue) - temp1)
if(IsNumeric(lCriticalTemp) or IsNumeric(uCriticalTemp)) then
lCriticalValue = lCriticalTemp
uCriticalValue = uCriticalTemp
else
Wscript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
end if
else
WScript.Echo "Error! Arguments wrong, please verify -c parameter"
Wscript.Quit(intError)
Exit Function
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_FormatData.
'Descripton: Format data the same as output.
'Input: service.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_FormatData(colWMI)
On Error Resume Next
strDisplay1 = ""
strDisplay2 = ""
strResultTemp3 = ""
strResultTemp4 = ""
For Each objWMI in colWMI
strName = objWMI.Name
strPropName = objWMI.Properties_(strProp).Name
intValueRaw = objWMI.Properties_(strProp)
intValueBase = objWMI.Properties_(strPropBase)
intValue = Int((100 * intValueRaw)/intValueBase)
Dim strDSName
strDSName = f_FormatDSName(strName)
if((warningValue <> "") and (criticalValue <> "")) then
strDisplay1 = strName & " '" & strPropName & "'" & " = " & intValue & "; "
strDisplay2 = "'" &strDSName & "'" & "=" & intValue & ";" & warningValue & ";" & criticalValue & ";; "
If(InStr(1, warningValue, ":") > 0 Or InStr(1, criticalValue, ":") > 0) Then
f_GetPrefixWithRange(intValue)
Else
f_GetPrefix(intValue)
End If
strResultTemp3 = strResultTemp3 & strPrefix & strDisplay1
strResultTemp4 = strResultTemp4 & strDisplay2
if( intReturnTemp1 < returnValue) then
intReturnTemp1 = returnValue
end if
else
strResultTemp3 = strResultTemp3 & "OK - " & strName & " '" & strPropName & "'" & " = " & intValue & "; "
strResultTemp4 = ""
end if
Next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_FormatDSName.
'Descripton: Get infomation at Local Host.
'Input: strName.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_FormatDSName(strName)
On Error Resume Next
first = 1
position1 = 0
position1 = InStr(first, strName, "=")
Dim proc_name
proc_name = ""
If(position1 > 0) Then
proc_name = Mid(strName,position1+1,(Len(strName)-position1))
proc_name = Replace(proc_name,".","_")
proc_name = Replace(proc_name,"-","_")
proc_name = Mid(proc_name,1, 19)
Else
proc_name = Mid(strName,position1+1,(Len(strName)-position1))
proc_name = Replace(proc_name,".","_")
proc_name = Replace(proc_name,"-","_")
proc_name = Mid(proc_name,1, 19)
End If
f_FormatDSName = proc_name
Exit Function
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInformation.
'Descripton: Get information data.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_GetInformation()
On Error Resume Next
strResult = ""
strResult1 = ""
strResult2 = ""
intReturn = 0
If(instanceArraySize > 0 and (warningArraySize > 1 Or criticalArraySize > 1)) Then
for i = 0 to instanceArraySize -1
instance = instanceArray(i)
warningValue = warningArray(i)
criticalValue = criticalArray(i)
f_GetInstance(instance)
strResult1 = strResult1 & strResultTemp1
strResult2 = strResult2 & strResultTemp2
if intReturn < intReturnTemp then
intReturn = intReturnTemp
end if
Next
Else
for i = 0 to instanceArraySize -1
instance = instanceArray(i)
f_GetInstance(instance)
strResult1 = strResult1 & strResultTemp1
strResult2 = strResult2 & strResultTemp2
if intReturn < intReturnTemp then
intReturn = intReturnTemp
end if
Next
end if
if(strResult2 = "") then
strResult = strResult1
else
strResult = strResult1 & "|" & strResult2
end if
Wscript.Echo strResult
Wscript.Quit(intReturn)
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInstances.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetInstances()
On Error Resume Next
first = 1
position = 0
instanceArraySize = 0
position = InStr(first, strInst, ",")
if (position = 0) then
instanceTemp = strInst
InstanceArraySize = 1
ReDim instanceArray(instanceArraySize)
instanceArray(0) = instanceTemp
else
do while (position > 0)
instanceTemp = Mid(strInst,first,position - first)
instanceArraySize = instanceArraySize + 1
ReDim Preserve instanceArray(instanceArraySize)
instanceArray(instanceArraySize -1) = Trim(instanceTemp)
first = position + 1
position = InStr(first, strInst, ",")
loop
instanceTemp = Mid(strInst,first,len(strInst))
instanceArraySize = instanceArraySize + 1
ReDim Preserve instanceArray(instanceArraySize)
instanceArray(instanceArraySize -1) = Trim(instanceTemp)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetWarningCriticalValues.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetWarningCriticalValues()
On Error Resume Next
position1 = 0
position2 = 0
position3 = 0
position4 = 0
temp1 = 1
temp2 = 1
warningArraySize = 0
criticalArraySize = 0
'get warning
position2 = InStr(temp1, warningValueString, ",")
If(position2 = 0) then
position2 = Len(warningValueString)+1
end if
If(position2 > position1) then
do while (position2 > position1)
warningPair = Mid(warningValueString, position1 + 1, (position2 - position1 -1))
warningArraySize = warningArraySize + 1
ReDim Preserve warningArray(warningArraySize)
warningArray(warningArraySize -1) = Trim(warningPair)
temp1 = position2 + 1
position1 = position2
position2 = InStr(temp1, warningValueString, ",")
If(position2 = 0) then
position2 = Len(warningValueString)+1
End If
loop
end If
If(Int(warningArraySize) < Int(instanceArraySize)) Then
ReDim Preserve warningArray(instanceArraySize)
For i = 0 To (instanceArraySize - warningArraySize - 1)
warningArray(warningArraySize +i) = warningArray(warningArraySize-1)
Next
warningArraySize = instanceArraySize
End If
'get critical
position4 = InStr(temp2, criticalValueString, ",")
If(position4 = 0) then
position4 = Len(criticalValueString)+1
end if
If(position4 > position3) then
do while (position4 > position3)
criticalPair = Mid(criticalValueString, position3 + 1, (position4 - position3 -1))
criticalArraySize = criticalArraySize + 1
ReDim Preserve criticalArray(criticalArraySize)
criticalArray(criticalArraySize -1) = Trim(criticalPair)
temp2 = position4 + 1
position3 = position4
position4 = InStr(temp2, criticalValueString, ",")
If(position4 = 0) then
position4 = Len(criticalValueString)+1
End If
loop
End If
If(Int(criticalArraySize) < Int(instanceArraySize)) Then
ReDim Preserve criticalArray(instanceArraySize)
For i = 0 To (instanceArraySize - criticalArraySize - 1)
criticalArray(criticalArraySize +i) = criticalArray(criticalArraySize-1)
Next
criticalArraySize = instanceArraySize
End If
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_LocalPerfValue.
'Descripton: Get perform value at Local Host.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_LocalPerfValue()
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\" & strNameSpace)
f_Error()
'Set colInstances = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & strComputer & "\" & strNameSpace).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
f_GetInformation()
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_RemotePerfValue.
'Descripton: Get perform values at Remote Host.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_RemotePerfValue()
On Error Resume Next
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
if (strDomain = "") then
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass )
f_Error()
'Set colInstances = objSWbemLocator.ConnectServer(strComputer, strNamespace , strUser, strPass).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
else
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass,"MS_409","ntlmdomain:" + strDomain )
f_Error()
'Set colInstances = objSWbemLocator.ConnectServer(strComputer, strNamespace , strUser, strPass,"MS_409","ntlmdomain:" & strDomain ).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
end if
objWMIService.Security_.ImpersonationLevel = 3
f_Error()
f_GetInformation()
End Function
'*************************************************************************************************
' Main Function
'*************************************************************************************************
'/////////////////////
strCommandName="check_counter_rawcount.vbs"
strDescription="Enumerate the needed windows host information."
'/////////////////////
strNameSpace = "root\cimv2"
f_GetAllArg()
tempCount = argcountcommand/2
f_Error()
strClass = ""
if ((UCase(arg(0))="-H") Or (UCase(arg(0))="--HELP")) and (argcountcommand=1) then
f_help()
else
if( ((argcountcommand Mod 2) = 0) and (3 < tempCount < 10)) then
strComputer = f_GetOneArg("-h")
strClass = f_GetOneArg("-class")
strProp = f_GetOneArg("-prop")
strInst = f_GetOneArg("-inst")
f_GetInstances()
warningValue = f_GetOneArg("-w")
warningValueString = f_GetOneArg("-w")
criticalValue = f_GetOneArg("-c")
criticalValueString = f_GetOneArg("-c")
If((warningValueString <> "") Or (criticalValueString <> "")) Then
f_GetWarningCriticalValues()
End if
strUser = f_GetOneArg("-user")
strPass = f_GetOneArg("-pass")
strDomain = f_GetOneArg("-domain")
if((strComputer = "") or (strClass = "") or (strProp = "") or (strInst = "")) then
Wscript.Echo "Error! Arguments wrong, require verify -h -class -prop -inst parameters"
Wscript.Quit(intError)
else
Select Case tempCount
Case 4:
f_LocalPerfValue()
Case 6:
if ((warningValue <> "") and (criticalValue <> "")) then
f_LocalPerfValue()
end if
if ((strUser <> "") and (strPass <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong, please verify -user -pass or -w -c parameters"
Wscript.Quit(intError)
end if
Case 8:
if ((strUser <> "") and (strPass <> "") and (warningValue <> "") and (criticalValue <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong for remote check, please verify -w -c -user -pass parameters"
Wscript.Quit(intError)
end if
Case 9:
if ((strUser <> "") and (strPass <> "") and (warningValue <> "") and (criticalValue <> "") and (strDomain <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong for remote check, please verify -w -c -user -pass -domain parameters"
Wscript.Quit(intError)
end if
Case Else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
End Select
end if
else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
end if
end if

View File

@ -0,0 +1,468 @@
' Copyright 2007 GroundWork Open Source Inc.
'
' This program is free software; you can redistribute it and/or
' modify it under the terms of the GNU General Public License
' as published by the Free Software Foundation; version 2
' of the License.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
'
' Author Dr. Dave Blunt at GroundWork Open Source Inc. (dblunt@groundworkopensource.com)
'*************************************************************************************************
' Public Variable
'*************************************************************************************************
Const intOK = 0
Const intWarning = 1
Const intCritical = 2
Const intError = 3
Const intUnknown = 3
Dim argcountcommand
Dim arg(20)
Dim strComputer
Dim strClass
Dim strProp
Dim strInst
Dim warningValue
Dim criticalValue
Dim strUser
Dim strPass
Dim strDomain
Dim strNameSpace
Dim strDescription
Dim strCommandName
Dim strResultTemp
Dim strResult1
Dim strResult2
Dim intReturnTemp
Dim intReturn
Dim strPrefix
Dim intValue
Dim returnValue
Dim instance
Dim instanceArray()
Dim instanceArraySize
Dim ArgCount
Dim strArgMain(10)
Dim strArgSortDes(10)
Dim strArgDetailDes(10)
Dim strArgExample(10)
Dim objWMIService, colWMI,objWMI,objSWbemLocator
strComputer=""
strClass = ""
strProp = ""
strInst = ""
strUser = ""
strPass = ""
strDomain = ""
'*************************************************************************************************
' Functions and Subs
'*************************************************************************************************
'-------------------------------------------------------------------------------------------------
'Function Name: f_Error.
'Descripton: Display an error notice include : Error Number and Error Description.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Error()
if (err.number <>0 ) then
if err.number = -2147023174 then
Wscript.echo "Critical - Timeout connecting to WMI on this host! Error Number: " & err.number & " Description: " & err.Description
WScript.Quit(intCritical)
else
if err.number = -2147024891 then
Wscript.echo "Authentication failure to remote host! Error Number: " & err.number & " Description: " & err.description
else
if err.number = 462 then
Wscript.echo "Critical - Timeout connecting to WMI on this host! Error Number: " & err.number & " Description: " & err.Description
WScript.Quit(intCritical)
else
if err.number=-2147217392 then
Wscript.echo "Error! Error Number: -2147217392 Description: Invalid Class"
else
Wscript.echo "Error! Error Number: " & err.number & " Description: " & err.description
end if
end if
end if
end if
Wscript.Quit(intError)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_Help.
'Descripton: Display help of command include : Description, Arguments, Examples
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Help()
Dim str
str="Check State of a Service. If your Local Machine has the same Administrator account and password as the Remote Machine then you don't have to use the two last parameters."&vbCrlF&vbCrlF
str=str&"cscript check_services_states.vbs -h hostname -inst instancename [-user username -pass password [-domain domain]]"&vbCrlF
str=str&vbCrlF
str=str&"-h [--help] Help."&vbCrlF
str=str&"-h hostname Host name."&vbCrlF
str=str&"-inst instance Needed Instance."&vbCrlF
str=str&"-user username Account Administrator on Remote Machine."&vbCrlF
str=str&"-pass password Password Account Administrator on Remote Machine."&vbCrlF
str=str&"-domain domain Domain Name of Remote Machine."&vbCrlF
str=str&vbCrlF
str=str&"Note: information can be one or multiple services, or *." & vbCrlF
str=str&"And if get multiple services, the information must be enclosed in multiple quotes and separate by commas." & vbCrlF
str=str&"Example: cscript check_services_states.vbs -h Ser1 -inst ""WINS,wmi"" [-user SER1\Administrator -pass password] " & vbCrlF
wscript.echo str
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetAllArg.
'Descripton: Get all of arguments from command.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetAllArg()
On Error Resume Next
Dim i
argcountcommand=WScript.Arguments.Count
for i=0 to argcountcommand-1
arg(i)=WScript.Arguments(i)
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetOneArg.
'Descripton: Get an argument from command.
'Input: Yes.
' strName: Name of argument
'Output: Value.
'-------------------------------------------------------------------------------------------------
Function f_GetOneArg(strName)
On Error Resume Next
Dim i
for i=0 to argcountcommand-1
if (Ucase(arg(i))=Ucase(strName)) then
f_GetOneArg=arg(i+1)
Exit Function
end if
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetOneInstance.
'Descripton: Get infomation at Local Host.
'Input: instance.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetOneInstance()
On Error Resume Next
if(instance = "*") then
for Each objWMI In colWMI
strOut = strOut & objWMI.Name & ": " & objWMI.State & "; "
next
strResultTemp = strOut
Wscript.Echo strResultTemp
Wscript.Quit(intOk)
Exit Function
else
for Each objWMI In colWMI
if(Ucase(instance) = Ucase(objWMI.Name)) then
startMode=objWMI.StartMode
if((startMode = "Disabled") or (startMode = "Manual")) then
Wscript.Echo "OK - " & objWMI.Name & ": " & objWMI.State & " and " & startMode
Wscript.Quit(intOk)
Exit Function
else
if(objWMI.State = "Running") then
Wscript.Echo "OK - " & objWMI.Name & ": " & objWMI.State
Wscript.Quit(intOk)
Exit Function
else
Wscript.Echo "Critical - " & objWMI.Name & ": " & objWMI.State
Wscript.Quit(intCritical)
Exit Function
end if
end if
end if
next
Wscript.Echo "Unknown - " & instance & ": not installed"
Wscript.Quit(intUnknown)
Exit Function
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetMultiInstance.
'Descripton: Get infomation at Local Host.
'Input: instance.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetMultiInstance()
On Error Resume Next
strResultTemp = ""
intResultTemp = 0
for Each objWMI In colWMI
if(Ucase(instance) = Ucase(objWMI.Name)) then
startMode=objWMI.StartMode
if((startMode = "Disabled") or (startMode = "Manual")) then
strResultTemp = "OK - " & objWMI.Name & ": " & objWMI.State & " and " & startMode
intReturnTemp = intOk
Exit Function
else
if(objWMI.State = "Running" ) then
strResultTemp = "OK - " & objWMI.Name & ": " & objWMI.State
intReturnTemp = intOk
Exit Function
else
strResultTemp = "Critical - " & objWMI.Name & ": " & objWMI.State
intReturnTemp = intCritical
Exit Function
end if
end if
end if
next
strResultTemp = "Unknown - " & instance & ": not installed"
intReturnTemp = intUnknown
Exit Function
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_ExecQuery.
'Descripton: Execute query.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_ExecQuery()
On Error Resume Next
strQuery = "Select " & strProp & " from " & strClass
Set colWMI = objWMIService.ExecQuery(strQuery)
count = -1
count = colWMI.count
if(count = -1) then
Wscript.Echo "Error! Invalid " & strProp & " property."
Wscript.Quit(intError)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInstances.
'Descripton: Get Prefix.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetInstances()
On Error Resume Next
first = 1
position = 0
instanceArraySize = 0
position = InStr(first, strInst, ",")
if (position = 0) then
instanceTemp = strInst
InstanceArraySize = 1
ReDim instanceArray(instanceArraySize)
instanceArray(0) = instanceTemp
else
do while (position > 0)
instanceTemp = Mid(strInst,first,position - first)
instanceArraySize = instanceArraySize + 1
ReDim Preserve instanceArray(instanceArraySize)
instanceArray(instanceArraySize -1) = Trim(instanceTemp)
first = position + 1
position = InStr(first, strInst, ",")
loop
instanceTemp = Mid(strInst,first,len(strInst))
instanceArraySize = instanceArraySize + 1
ReDim Preserve instanceArray(instanceArraySize)
instanceArray(instanceArraySize -1) = Trim(instanceTemp)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInformation.
'Descripton: Get information data.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_GetInformation()
On Error Resume Next
strResult1 = ""
strResult2 = ""
intReturn = 0
if(instanceArraySize = 1) then
instance = instanceArray(0)
f_GetOneInstance()
else
for i = 0 to instanceArraySize -1
instance = instanceArray(i)
f_GetMultiInstance()
if intReturn < intReturnTemp then
intReturn = intReturnTemp
end if
if(intReturnTemp > 0) then
strResult2 = strResult2 & strResultTemp & "; "
else
strResult1 = strResult1 & strResultTemp & "; "
end if
next
Wscript.Echo strResult2 & strResult1
Wscript.Quit(intReturn)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_LocalPerfValue.
'Descripton: Get perform value at Local Host.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_LocalPerfValue()
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\" & strNameSpace)
f_Error()
'Set colInstances = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & strComputer & "\" & strNameSpace).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
f_ExecQuery()
f_GetInstances()
f_GetInformation()
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_RemotePerfValue.
'Descripton: Get perform values at Remote Host.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_RemotePerfValue()
On Error Resume Next
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
if (strDomain = "") then
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass )
f_Error()
'Set colInstances = objSWbemLocator.ConnectServer(strComputer, strNamespace , strUser, strPass).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
else
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass,"MS_409","ntlmdomain:" + strDomain )
f_Error()
'Set colInstances = objSWbemLocator.ConnectServer(strComputer, strNamespace , strUser, strPass,"MS_409","ntlmdomain:" & strDomain ).InstancesOf(strClass)
'For Each objInstance in colInstances
'Next
'f_Error()
end if
objWMIService.Security_.ImpersonationLevel = 3
f_Error()
f_ExecQuery()
f_GetInstances()
f_GetInformation()
End Function
'*************************************************************************************************
' Main Function
'*************************************************************************************************
'/////////////////////
strCommandName="check_services_states.vbs"
strDescription="Check state of one or multi services."
'/////////////////////
strNameSpace = "root\cimv2"
strClass = "Win32_Service"
strProp = "Name, State, StartMode"
f_GetAllArg()
tempCount = argcountcommand/2
f_Error()
if ((UCase(arg(0))="-H") Or (UCase(arg(0))="--HELP")) and (argcountcommand=1) then
f_help()
else
if( ((argcountcommand Mod 2) = 0) and (1 < tempCount < 6)) then
strComputer = f_GetOneArg("-h")
strInst = f_GetOneArg("-inst")
strUser = f_GetOneArg("-user")
strPass = f_GetOneArg("-pass")
strDomain = f_GetOneArg("-domain")
if((strComputer = "") or (strInst = "")) then
Wscript.Echo "Error! Arguments wrong, require verify -h -inst parameters"
Wscript.Quit(intError)
else
Select Case tempCount
Case 2:
f_LocalPerfValue()
Case 4:
if ((strUser <> "") and (strPass <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong, please verify -user -pass parameters"
Wscript.Quit(intError)
end if
Case 5:
if ((strUser <> "") and (strPass <> "") and (strDomain <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong for remote check, please verify -w -c -user -pass -domain parameters"
Wscript.Quit(intError)
end if
Case Else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
End Select
end if
else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
end if
end if

View File

@ -0,0 +1,601 @@
' Copyright 2007 GroundWork Open Source Inc.
'
' This program is free software; you can redistribute it and/or
' modify it under the terms of the GNU General Public License
' as published by the Free Software Foundation; version 2
' of the License.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
'
' Author Dr. Dave Blunt at GroundWork Open Source Inc. (dblunt@groundworkopensource.com)
'*************************************************************************************************
' Public Variable
'*************************************************************************************************
Const intOK = 0
Const intUnknown = 3
Const intError = 3
Dim argcountcommand
Dim arg(20)
Dim strComputer
Dim strUser
Dim strPass
Dim strNameSpace
Dim strDescription
Dim strCommandName
Dim strResultTemp
Dim strResult
Dim ArgCount
Dim strArgMain(10)
Dim strArgSortDes(10)
Dim strArgDetailDes(10)
Dim strArgExample(10)
strInfo=""
'*************************************************************************************************
' Functions and Subs
'*************************************************************************************************
'-------------------------------------------------------------------------------------------------
'Function Name: f_Error.
'Descripton: Display an error notice include : Error Number and Error Description.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Error()
nbrError = err.number
if (nbrError <> 0 ) then
Select Case nbrError
Case 462, -2147023174
strExitMsg = "Timeout connecting to WMI on this host! Error Number: " & nbrError & " Description: " & err.description
Case -2147024891
strExitMsg = "Authentication failure to remote host! Error Number: " & nbrError & " Description: " & err.description
Case -2147217392
strExitMsg = "Error! Number: " & nbrError & " Description: Invalid Class"
Case Else
strExitMsg = "Error! Number: " & nbrError & " Description: " & err.description
End Select
wscript.echo strExitMsg
wscript.quit(intUnknown)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_Help.
'Descripton: Display help of command include : Description, Arguments, Examples
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Help()
Dim strHelp
Dim i
Dim strtemp1
Dim strtemp2
Dim strtemp3
strHelp=""
strtemp1=""
strtemp2=""
strtemp3=""
for i=1 to ArgCount
strtemp1=strtemp1 & " " & strArgMain(i) & " " & strArgSortDes(i)
strtemp2=strtemp2 & strArgMain(i) & " " & strArgSortDes(i) & " " & strArgDetailDes(i) & "." & vbCrlF
strtemp3=strtemp3 & " " & strArgMain(i) & " " & strArgExample(i)
next
'/////////////////////
strHelp=strHelp & strDescription & " If your Local Machine has the same Administrator account and password as the Remote Machine then you don't have to use the two (three) last parameters."&vbCrlF&vbCrlF
strHelp=strHelp & "cscript " & strCommandName & strtemp1 & " [-user username -pass password -domain domain]"
strHelp=strHelp & vbCrlF
strHelp=strHelp & strtemp2
strHelp=strHelp & "-user username Account Administrator on Remote Machine." & vbCrlF
strHelp=strHelp & "-pass password Password Account Administrator on Remote Machine." & vbCrlF
strHelp=strHelp & "-domain domain Domain Name on Remote Machine." & vbCrlF
strHelp=strHelp & vbCrlF
strHelp=strHelp & "Example: cscript " & strCommandName & strtemp3 & " [-user Ser1\Administrator -pass password -domain workgroup]." & vbCrlF
strHelp=strHelp & vbCrlF
strHelp=strHelp & "For Help Command: cscript " & strCommandName & " -h (or --help)." & vbCrlF
strHelp=strHelp & vbCrlF
strHelp=strHelp & "Note: information can be one or multiple of network_interfaces, logical_disks, installed_services, running_processes, all_processors or *." & vbCrlF
strHelp=strHelp & "And if get multiple infomation, the information must be enclosed in multiple quotes and separate by commas." & vbCrlF
strHelp=strHelp & "Example: cscript get_computer_info.vbs -h Ser1 -i ""network_interfaces,logical_disks,install_services"" [-user SER1\Administrator -pass password] " & vbCrlF
Wscript.echo strHelp
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetAllArg.
'Descripton: Get all of arguments from command.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetAllArg()
On Error Resume Next
Dim i
argcountcommand=WScript.Arguments.Count
for i=0 to argcountcommand-1
arg(i)=WScript.Arguments(i)
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetOneArg.
'Descripton: Get an argument from command.
'Input: Yes.
' strName: Name of argument
'Output: Value.
'-------------------------------------------------------------------------------------------------
Function f_GetOneArg(strName)
On Error Resume Next
Dim i
for i=0 to argcountcommand-1
if (Ucase(arg(i))=Ucase(strName)) then
f_GetOneArg=arg(i+1)
Exit Function
end if
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_TestLocalCommand.
'Descripton: Test structure of command run at local host.
'Input: No.
'Output: Yes.
'-------------------------------------------------------------------------------------------------
Function f_TestLocalCommand()
On Error Resume Next
Dim i,j
Dim temp
Dim count
Dim check(10)
count=0
for j=1 to ArgCount
check(j)=0
next
if (argcountcommand<>ArgCount*2) then
f_TestLocalCommand=0
else
for i=0 to argcountcommand-1
if (i mod 2=0) then
temp=UCase(arg(i))
for j=1 to ArgCount
if (temp=UCase(strArgMain)) and (check(j)=0) then
check(j)=1
count=count+1
j=ArgCount
end if
next
end if
next
if count=ArgCount then
f_TestLocalCommand=1
else
f_TestLocalCommand=0
end if
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_TestRemoteCommand.
'Descripton: Test structure of command run at remote host.
'Input: No.
'Output: Yes.
'-------------------------------------------------------------------------------------------------
Function f_TestRemoteCommand()
On Error Resume Next
Dim i,j
Dim temp
Dim count
Dim check(10)
Dim extra(5)
count=0
for j=1 to ArgCount
check(j)=0
next
for j=1 to 3
extra(j)=0
next
if (argcountcommand=(ArgCount+2)*2) or (argcountcommand=(ArgCount+3)*2) then
for i=0 to argcountcommand-1
if (i mod 2=0) then
temp=UCase(arg(i))
if (temp="-USER" and extra(1)=0) then
extra(1)=1
count=count+1
else
if (temp="-PASS" and extra(2)=0) then
extra(2)=1
count=count+1
else
if (temp="-DOMAIN" and extra(3)=0) then
extra(3)=1
count=count+1
else
for j=1 to ArgCount
if (temp=UCase(strArgMain)) and (check(j)=0) then
check(j)=1
count=count+1
j=ArgCount
end if
next
end if
end if
end if
end if
next
if (count*2=argcountcommand) then
f_TestRemoteCommand=1
else
f_TestRemoteCommand=0
end if
else
f_TestremoteCommand=0
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_LocalInfo.
'Descripton: Get infomation at Local Host.
'Input: info.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_LocalInfo(info)
On Error Resume Next
Dim objWMIService, colWMI,objWMI
strResultTemp = ""
strOut = ""
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\" & strNameSpace)
f_Error()
'Depend on strInfo parameters to get the result value
if(info = "*") then
Set colWMI = objWMIService.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface")
for Each objWMI In colWMI
strOut = strOut & objWMI.Name & ", "
next
Set colWMI = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
for Each objWMI In colWMI
strOut1 = strOut1 & objWMI.Name & ", "
next
Set colWMI = objWMIService.ExecQuery("Select * from Win32_BaseService")
for Each objWMI In colWMI
strOut2 = strOut2 & objWMI.Name & ", "
next
Set colWMI = objWMIService.ExecQuery("Select * from Win32_Process")
for Each objWMI In colWMI
strOut3 = strOut3 & objWMI.Name & ", "
next
Set colWMI = objWMIService.ExecQuery("Select * from Win32_Processor")
for Each objWMI In colWMI
strOut4 = strOut4 & objWMI.Name & ", "
next
strResultTemp = "; Network Interfaces: " & strOut & "; Logical Disks: " & strOut1 &_
"; Installed services: " & strOut2 & "; Running Processes: " & strOut3 &_
"; All Processors: " & strOut4
Exit Function
end if
if(info = "network_interfaces") then
Set colWMI = objWMIService.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface")
for Each objWMI In colWMI
strOut = strOut & objWMI.Name & ", "
next
strResultTemp = "; Network Interfaces: " & strOut
Exit Function
else
if(info = "logical_disks") then
Set colWMI = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
for Each objWMI In colWMI
strOut = strOut & objWMI.Name & ", "
next
strResultTemp = "; Logical Disks: " & strOut
Exit Function
else
if(info = "installed_services") then
Set colWMI = objWMIService.ExecQuery("Select * from Win32_BaseService")
for Each objWMI In colWMI
strOut = strOut & objWMI.Name & ", "
next
strResultTemp = "; Installed Services: " & strOut
Exit Function
else
if(info = "running_processes") then
Set colWMI = objWMIService.ExecQuery("Select * from Win32_Process")
for Each objWMI In colWMI
strOut = strOut & objWMI.Name & ", "
next
strResultTemp = "; Running Processes: " & strOut
Exit Function
else
if(info = "all_processors") then
Set colWMI = objWMIService.ExecQuery("Select * from Win32_Processor")
for Each objWMI In colWMI
strOut = strOut & objWMI.Name & ", "
next
strResultTemp = "; All Processors: " & strOut
Exit Function
else
f_Error()
Wscript.echo "Error! Arguments are wrong."
Wscript.Quit(3)
end if
end if
end if
end if
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_RemoteInfo.
'Descripton: Get infomation at Remote Host.
'Input: info.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_RemoteInfo(info)
On Error Resume Next
Dim objWMIService, colWMI,objWMI,objSWbemLocator
Dim strDomain
strResultTemp = ""
strOut = ""
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
if ((ArgCount+2)*2=ArgCountCommand) then
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass )
f_Error()
else
strDomain=f_GetOneArg("-domain")
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass,"MS_409","ntlmdomain:" + strDomain )
f_Error()
end if
objWMIService.Security_.ImpersonationLevel = 3
f_Error()
'Depend on strInfo parameters to get the result value
if(info = "*") then
Set colWMI = objWMIService.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface")
for Each objWMI In colWMI
strOut = strOut & objWMI.Name & ", "
next
Set colWMI = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
for Each objWMI In colWMI
strOut1 = strOut1 & objWMI.Name & ", "
next
Set colWMI = objWMIService.ExecQuery("Select * from Win32_BaseService")
for Each objWMI In colWMI
strOut2 = strOut2 & objWMI.Name & ", "
next
Set colWMI = objWMIService.ExecQuery("Select * from Win32_Process")
for Each objWMI In colWMI
strOut3 = strOut3 & objWMI.Name & ", "
next
Set colWMI = objWMIService.ExecQuery("Select * from Win32_Processor")
for Each objWMI In colWMI
strOut4 = strOut4 & objWMI.Name & ", "
next
strResultTemp = "; Network Interfaces: " & strOut & "; Logical Disks: " & strOut1 &_
"; Installed services: " & strOut2 & "; Running Processes: " & strOut3 &_
"; All Processors: " & strOut4
Exit Function
end if
if(info = "network_interfaces") then
Set colWMI = objWMIService.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface")
for Each objWMI In colWMI
strOut = strOut & objWMI.Name & ", "
next
strResultTemp = "; Network Interfaces: " & strOut
Exit Function
else
if(info = "logical_disks") then
Set colWMI = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
for Each objWMI In colWMI
strOut = strOut & objWMI.Name & ", "
next
strResultTemp = "; Logical Disks: " & strOut
Exit Function
else
if(info = "installed_services") then
Set colWMI = objWMIService.ExecQuery("Select * from Win32_BaseService")
for Each objWMI In colWMI
strOut = strOut & objWMI.Name & ", "
next
strResultTemp = "; Installed Services: " & strOut
Exit Function
else
if(info = "running_processes") then
Set colWMI = objWMIService.ExecQuery("Select * from Win32_Process")
for Each objWMI In colWMI
strOut = strOut & objWMI.Name & ", "
next
strResultTemp = "; Running Processes: " & strOut
Exit Function
else
if(info = "all_processors") then
Set colWMI = objWMIService.ExecQuery("Select * from Win32_Processor")
for Each objWMI In colWMI
strOut = strOut & objWMI.Name & ", "
next
strResultTemp = "; All Processors: " & strOut
Exit Function
else
f_Error()
Wscript.echo "Error! Arguments are wrong."
Wscript.Quit(3)
end if
end if
end if
end if
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_LocalPerfValue.
'Descripton: Get perform value at Local Host.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_LocalPerfValue()
On Error Resume Next
strResult = ""
info = strInfo
'sProcess = arg(3)
first=1
tam1=10
if (len(strInfo)>0) then
do while (tam1>0)
tam1=InStr(first,strInfo,",")
if (tam1>0) then
tam2=Mid(strInfo,first,tam1-first)
first=tam1+1
info = tam2
f_LocalInfo(Trim(info))
strResult = strResult & strResultTemp
end if
Loop
tam2=Mid(strInfo,first,len(strInfo))
info = tam2
f_LocalInfo(Trim(info))
strResult = strResult & strResultTemp
end if
strResult = "Host name: " & strComputer & strResult
Wscript.Echo strResult
Wscript.Quit(intOK)
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_RemotePerfValue.
'Descripton: Get perform values at Remote Host.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_RemotePerfValue()
On Error Resume Next
strResult = ""
info = strInfo
first=1
tam1=10
if (len(strInfo)>0) then
do while (tam1>0)
tam1=InStr(first,strInfo,",")
if (tam1>0) then
tam2=Mid(strInfo,first,tam1-first)
first=tam1+1
info = tam2
f_RemoteInfo(Trim(info))
strResult = strResult & strResultTemp
end if
Loop
tam2=Mid(strInfo,first,len(strInfo))
info = tam2
f_RemoteInfo(Trim(info))
strResult = strResult & strResultTemp
end if
strResult = "Host name: " & strComputer & strResult
Wscript.Echo strResult
Wscript.Quit(intOK)
End Function
'*************************************************************************************************
' Main Function
'*************************************************************************************************
'/////////////////////
strCommandName="get_computer_info.vbs"
strDescription="Enumerate the needed windows host information."
'/////////////////////
ArgCount=2
strArgMain(1)= "-h"
strArgSortDes(1)= "hostname"
strArgDetailDes(1)= " Host name"
strArgExample(1)= "Ser1"
strArgMain(2)= "-i"
strArgSortDes(2)= "information"
strArgDetailDes(2)= " The needed information"
strArgExample(2)= "installed_services"
strNameSpace = "root\cimv2"
f_GetAllArg()
f_Error()
if ((UCase(arg(0))="-H") Or (UCase(arg(0))="--HELP")) and (argcountcommand=1) then
f_help()
else
if (f_TestLocalCommand()) then
strComputer=f_GetOneArg("-h")
if(strComputer = "localhost") then
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in colItems
strComputer = objItem.DNSHostName
Next
end if
strInfo=f_GetOneArg("-i")
f_LocalPerfValue()
f_Error()
else
if (f_TestRemoteCommand()) then
strComputer=f_GetOneArg("-h")
strInfo=f_GetOneArg("-i")
strUser=f_GetOneArg("-user")
strPass=f_GetOneArg("-pass")
f_RemotePerfValue()
f_Error()
else
f_Error()
Wscript.echo "Error! Arguments are wrong."
Wscript.Quit(intError)
end if
end if
end if

View File

@ -0,0 +1,141 @@
' Copyright 2007 GroundWork Open Source Inc.
'
' This program is free software; you can redistribute it and/or
' modify it under the terms of the GNU General Public License
' as published by the Free Software Foundation; version 2
' of the License.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
'
' Author Dr. Dave Blunt at GroundWork Open Source Inc. (dblunt@groundworkopensource.com)
'*************************************************************************************************
' Public Variable
'*************************************************************************************************
Const intOK = 0
Const intCritical = 2
Const intError = 3
Const intUnknown = 3
Dim arg(20)
i = 0
strComputer = "."
strNamespace = "root\cimv2"
strClass="Win32_Service"
strProperty = ""
strUser = ""
strPass = ""
strNameList = ""
countertypeFound = 0
'*************************************************************************************************
' Functions and Subs
'*************************************************************************************************
'-------------------------------------------------------------------------------------------------
'Function Name: f_Error.
'Descripton: Display an error notice include : Error Number and Error Description.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Error()
nbrError = err.number
if (nbrError <> 0 ) then
Select Case nbrError
Case 462, -2147023174
strExitMsg = "Timeout connecting to WMI on this host! Error Number: " & nbrError & " Description: " & err.description
Case -2147024891
strExitMsg = "Authentication failure to remote host! Error Number: " & nbrError & " Description: " & err.description
Case -2147217392
strExitMsg = "Error! Number: " & nbrError & " Description: Invalid Class"
Case Else
strExitMsg = "Error! Number: " & nbrError & " Description: " & err.description
End Select
wscript.echo strExitMsg
wscript.quit(intUnknown)
end if
End Function
'*************************************************************************************************
' Main Function
'*************************************************************************************************
On Error Resume Next
For i=0 to WScript.Arguments.Count-1
arg(i)=WScript.Arguments( i )
Next
if (i=3) then
strComputer=arg(0)
strClass=arg(1)
strProperty=arg(2)
else
if (i=5) then
strComputer=arg(0)
strClass=arg(1)
strProperty=arg(2)
strUser=arg(3)
strPass=arg(4)
else
if (i=2) then
strComputer=arg(0)
strClass=arg(1)
else
if (i=4) then
strComputer=arg(0)
strClass=arg(1)
strUser=arg(2)
strPass=arg(3)
else
wscript.echo "Usage: get_counter_type.vbs <hostname> <class> [<property>] [<user> <password>]"
wscript.quit(3)
end if
end if
end if
end if
if (strUser <> "") then
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNamespace , strUser, strPass )
f_Error()
Set objClass = objWMIService.Get(strClass)
f_Error()
else
set objWMIService = GetObject("winmgmts:\\" & strComputer & "\" & strNamespace)
f_Error()
set objClass = GetObject("winmgmts:\\" & strComputer & "\" & strNamespace & ":" & strClass)
end if
f_Error()
For Each objClassProperty In objClass.Properties_
If (strProperty<>"") Then
If objClassProperty.Name = strProperty Then
For Each objQualifier in ObjClassProperty.Qualifiers_
If objQualifier.Name = "countertype" Then
countertypeFound = 1
wscript.echo "Property " & objClassProperty.Name & " countertype = " & objQualifier.Value
End If
Next
End If
Else
strNameList = strNameList & objClassProperty.Name & " "
End If
Next
if (strProperty="") then
wscript.echo strNameList
else
if (countertypeFound=0) then
wscript.echo "Property " & strProperty & " does not have a defined countertype."
end if
end if

View File

@ -0,0 +1,329 @@
' Copyright 2007 GroundWork Open Source Inc.
'
' This program is free software; you can redistribute it and/or
' modify it under the terms of the GNU General Public License
' as published by the Free Software Foundation; version 2
' of the License.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
'
' Author Dr. Dave Blunt at GroundWork Open Source Inc. (dblunt@groundworkopensource.com)
'*************************************************************************************************
' Public Variable
'*************************************************************************************************
Const intOK = 0
Const intCritical = 2
Const intError = 3
Const intUnknown = 3
Dim argcountcommand
Dim arg(20)
Dim strComputer
Dim strClass
Dim strProp
Dim strUser
Dim strPass
Dim strDomain
Dim strNameSpace
Dim strDescription
Dim strCommandName
Dim strResultTemp
Dim strResult
Dim strResult1
Dim strResult2
Dim intReturnTemp
Dim intReturn
Dim strResultTemp1
Dim strResultTemp2
Dim strResultTemp3
Dim strResultTemp4
Dim intReturnTemp1
Dim strPrefix
Dim intValue
Dim returnValue
Dim instanceArray()
Dim instanceArraySize
Dim thresoldArraySize
Dim instance
Dim strDisplay1
Dim strDisplay2
Dim strName
Dim strPropName
Dim intAverageValue
Dim ArgCount
Dim strArgMain(10)
Dim strArgSortDes(10)
Dim strArgDetailDes(10)
Dim strArgExample(10)
Dim objWMIService, colWMI,objWMI,objSWbemLocator
strComputer=""
strClass = ""
strProp = ""
strUser = ""
strPass = ""
strDomain = ""
'*************************************************************************************************
' Functions and Subs
'*************************************************************************************************
'-------------------------------------------------------------------------------------------------
'Function Name: f_Error.
'Descripton: Display an error notice include : Error Number and Error Description.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Error()
nbrError = err.number
if (nbrError <> 0 ) then
Select Case nbrError
Case 462, -2147023174
strExitMsg = "Timeout connecting to WMI on this host! Error Number: " & nbrError & " Description: " & err.description
Case -2147024891
strExitMsg = "Authentication failure to remote host! Error Number: " & nbrError & " Description: " & err.description
Case -2147217392
strExitMsg = "Error! Number: " & nbrError & " Description: Invalid Class"
Case Else
strExitMsg = "Error! Number: " & nbrError & " Description: " & err.description
End Select
wscript.echo strExitMsg
wscript.quit(intUnknown)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_Help.
'Descripton: Display help of command include : Description, Arguments, Examples
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_Help()
Dim str
str="Verify connection to target host via WMI. If your Local Machine has the same Administrator account and password as the Remote Machine then you don't have to use the two last parameters."&vbCrlF&vbCrlF
str=str&"cscript verify_wmi_status.vbs -h hostname [-user username -pass password [-domain domain]]"&vbCrlF
str=str&vbCrlF
str=str&"-h [--help] Help."&vbCrlF
str=str&"-h hostname Host name."&vbCrlF
str=str&"-user username Account Administrator on Remote Machine."&vbCrlF
str=str&"-pass password Password Account Administrator on Remote Machine."&vbCrlF
str=str&"-domain domain Domain Name of Remote Machine."&vbCrlF
str=str&vbCrlF
str=str&"Example: cscript verify_wmi_status.vbs -h Ser1 [-user Ser1\Administrator -pass password -domain ITSP] " &vbCrlF
wscript.echo str
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetAllArg.
'Descripton: Get all of arguments from command.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_GetAllArg()
On Error Resume Next
Dim i
argcountcommand=WScript.Arguments.Count
for i=0 to argcountcommand-1
arg(i)=WScript.Arguments(i)
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetOneArg.
'Descripton: Get an argument from command.
'Input: Yes.
' strName: Name of argument
'Output: Value.
'-------------------------------------------------------------------------------------------------
Function f_GetOneArg(strName)
On Error Resume Next
Dim i
for i=0 to argcountcommand-1
if (Ucase(arg(i))=Ucase(strName)) then
f_GetOneArg=arg(i+1)
Exit Function
end if
next
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_ExecQuery.
'Descripton: Format data the same as output.
'Input: service.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_ExecQuery()
On Error Resume Next
strQuery = "Select " & strProp & " from " & strClass
Set colWMI = objWMIService.ExecQuery(strQuery)
count = -1
count = colWMI.count
if(count = -1) then
Wscript.Echo "Error! Invalid " & strProp & " properties."
Wscript.Quit(intError)
end if
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_GetInformation.
'Descripton: Get information data.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_GetInformation()
On Error Resume Next
strResult = ""
intReturn = 0
for Each objInstance in colWMI
strResult = strResult & "" & objInstance.Caption & ", SP " & objInstance.ServicePackMajorVersion & "." & objInstance.ServicePackMinorVersion
Next
strResult = "OK - " & strResult
Wscript.Echo strResult
Wscript.Quit(intReturn)
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_LocalPerfValue.
'Descripton: Get perform value at Local Host.
'Input: No.
'Output: No.
'-------------------------------------------------------------------------------------------------
Function f_LocalPerfValue()
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\" & strNameSpace)
f_Error()
Set colInstances = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & strComputer & "\" & strNameSpace).InstancesOf(strClass)
For Each objInstance in colInstances
Next
f_Error()
f_ExecQuery()
f_GetInformation()
End Function
'-------------------------------------------------------------------------------------------------
'Function Name: f_RemotePerfValue.
'Descripton: Get perform values at Remote Host.
'Input: No.
'Output: Values.
'-------------------------------------------------------------------------------------------------
Function f_RemotePerfValue()
On Error Resume Next
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
if (strDomain = "") then
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass )
f_Error()
Set colInstances = objSWbemLocator.ConnectServer(strComputer, strNamespace , strUser, strPass).InstancesOf(strClass)
For Each objInstance in colInstances
Next
f_Error()
else
Set objWMIService = objSWbemLocator.ConnectServer _
(strComputer, strNameSpace , strUser, strPass,"MS_409","ntlmdomain:" + strDomain )
f_Error()
Set colInstances = objSWbemLocator.ConnectServer(strComputer, strNamespace , strUser, strPass,"MS_409","ntlmdomain:" & strDomain ).InstancesOf(strClass)
For Each objInstance in colInstances
Next
f_Error()
end if
objWMIService.Security_.ImpersonationLevel = 3
f_Error()
f_ExecQuery()
f_GetInstances()
f_GetInformation()
End Function
'*************************************************************************************************
' Main Function
'*************************************************************************************************
'/////////////////////
strCommandName="verify_wmi_status.vbs"
strDescription="Verify target host WMI status."
'/////////////////////
strNameSpace = "root\cimv2"
strClass = "Win32_OperatingSystem"
strProp = "Caption,ServicePackMajorVersion,ServicePackMinorVersion"
f_GetAllArg()
tempCount = argcountcommand/2
f_Error()
if ((UCase(arg(0))="-H") Or (UCase(arg(0))="--HELP")) and (argcountcommand=1) then
f_help()
else
if( ((argcountcommand Mod 2) = 0) and (1 < tempCount < 5)) then
strComputer = f_GetOneArg("-h")
strUser = f_GetOneArg("-user")
strPass = f_GetOneArg("-pass")
strDomain = f_GetOneArg("-domain")
if((strComputer = "")) then
Wscript.Echo "Error! Arguments wrong, require verify -h parameter"
Wscript.Quit(intError)
else
Select Case tempCount
Case 1:
f_LocalPerfValue()
Case 3:
if ((strUser <> "") and (strPass <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong, please verify -user -pass parameters"
Wscript.Quit(intError)
end if
Case 4:
if ((strUser <> "") and (strPass <> "") and (strDomain <> "")) then
f_RemotePerfValue()
else
Wscript.Echo "Error! Arguments wrong, please verify -user -pass -domain parameters"
Wscript.Quit(intError)
end if
Case Else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
End Select
end if
else
Wscript.Echo "Error! Arguments wrong, please type -h for Help"
Wscript.Quit(intError)
end if
end if

182
nsclient/trunk/wmi.ini Normal file
View File

@ -0,0 +1,182 @@
[External Scripts]
# =================================
# Enumeration checks
# =================================
show_net=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\get_computer_info.vbs -h "$ARG1$" -i network_interfaces
show_net_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\get_computer_info.vbs -h "$ARG1$" -i network_interfaces -user "$ARG2$" -pass "$ARG3$"
show_disks=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\get_computer_info.vbs -h "$ARG1$" -i logical_disks
show_disks_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\get_computer_info.vbs -h "$ARG1$" -i logical_disks -user "$ARG2$" -pass "$ARG3$"
show_procs=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\get_computer_info.vbs -h "$ARG1$" -i running_processes
show_procs_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\get_computer_info.vbs -h "$ARG1$" -i running_processes -user "$ARG2$" -pass "$ARG3$"
show_cpus=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\get_computer_info.vbs -h "$ARG1$" -i all_processors
show_cpus_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\get_computer_info.vbs -h "$ARG1$" -i all_processors -user "$ARG2$" -pass "$ARG3$"
show_properties=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\get_counter_type.vbs "$ARG1$" "$ARG2$"
show_properties_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\get_counter_type.vbs "$ARG1$" "$ARG2$" "$ARG3$" "$ARG4$"
show_property_type=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\get_counter_type.vbs "$ARG1$" "$ARG2$" "$ARG3$"
show_property_type_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\get_counter_type.vbs "$ARG1$" "$ARG2$" "$ARG3$" "$ARG4$" "$ARG5$"
show_os=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\verify_wmi_status.vbs -h "$ARG1$"
show_os_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\verify_wmi_status.vbs -h "$ARG1$" -user "$ARG2$" -pass "$ARG3$"
# Example calls from check_nrpe:
# ./check_nrpe -H <IP1> -c show_properties -a <IP2> Win32_PerfRawData_PerfOS_Memory
# ./check_nrpe -H <IP1> -c show_property_type -a <IP2> Win32_PerfRawData_PerfOS_Memory WriteCopiesPersec
# =================================
# Disk percentage used checks
# =================================
get_disk=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_disks_percentage_space_used.vbs -h "$ARG1$" -inst "$ARG2$" -t "$ARG3$"
get_disk_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_disks_percentage_space_used.vbs -h "$ARG1$" -inst "$ARG2$" -t "$ARG3$" -user "$ARG4$" -pass "$ARG5$"
# Example call from check_nrpe:
# ./check_nrpe -H <IP1> -c get_disk -a <IP2> C:,D: 80,90:70,60
# =================================
# Memory percentage used checks
# =================================
get_mem=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_memory_percentage_space_used.vbs -h "$ARG1$" -inst "$ARG2$" -t "$ARG3$"
get_mem_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_memory_percentage_space_used.vbs -h "$ARG1$" -inst "$ARG2$" -t "$ARG3$" -user "$ARG4$" -pass "$ARG5$"
# Example call from check_nrpe:
# ./check_nrpe -H <IP1> -c get_mem -a <IP2> RAM,_TOTAL 80,90:80,90
# =================================
# CPU Load checks
# =================================
get_cpu=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_cpu_load_percentage.vbs -h "$ARG1$" -inst "$ARG2$" -t "$ARG3$"
get_cpu_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_cpu_load_percentage.vbs -h "$ARG1$" -inst "$ARG2$" -t "$ARG3$" -user "$ARG4$" -pass "$ARG5$"
# Example call from check_nrpe:
# ./check_nrpe -H <IP1> -c get_cpu -a <IP2> CPU0 80,90
# =================================
# Network IO checks
# =================================
get_netio=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_network_io.vbs -h "$ARG1$" -inst "$ARG2$" -prop "$ARG3$" -t "$ARG4$"
get_netio_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_network_io.vbs -h "$ARG1$" -inst "$ARG2$" -prop "$ARG3$" -t "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
# Example call from check_nrpe:
# ./check_nrpe -H <IP1> -c get_netio -a <IP2> "MS TCP Loopback Interface" "BytesReceivedPerSec" 300,1000
# =================================
# Disk IO checks
# =================================
get_diskio=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_disks_io.vbs -h "$ARG1$" -inst "$ARG2$" -prop "$ARG3$" -t "$ARG4$"
get_diskio_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_disks_io.vbs -h "$ARG1$" -inst "$ARG2$" -prop "$ARG3$" -t "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
# Example call from check_nrpe:
# ./check_nrpe -H <IP1> -c get_diskio -a <IP2> C: "DiskReadBytesPerSec,DiskWriteBytesPerSec" 300,1000:500,2000
# =================================
# Service checks
# =================================
get_service=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_services_states.vbs -h "$ARG1$" -inst "$ARG2$"
get_service_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_services_states.vbs -h "$ARG1$" -inst "$ARG2$" -user "$ARG3$" -pass "$ARG4$"
# Example call from check_nrpe:
# ./check_nrpe -H <IP1> -c get_service -a <IP2> winmgmt,msdtc
# =================================
# Process checks
# =================================
get_process=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_proc_num.vbs -h "$ARG1$" -inst "$ARG2$" -w "$ARG3$" -c "$ARG4$"
get_process_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_proc_num.vbs -h "$ARG1$" -inst "$ARG2$" -w "$ARG3$" -c "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
# Example call from check_nrpe:
# ./check_nrpe -H <IP1> -c get_process -a <IP2> Name=svchost.exe,Name=cmd.exe 15 20
# (at present this plug-in does not support thresholds as minimums)
# =================================
# Counter checks
# =================================
get_100nsec_timer=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_100nsec_timer.vbs -h "$ARG1$" -class "$ARG2$" -inst "$ARG3$" -prop "$ARG4$" -w "$ARG5$" -c "$ARG6$"
get_100nsec_timer_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_100nsec_timer.vbs -h "$ARG1$" -class "$ARG2$" -inst "$ARG3$" -prop "$ARG4$" -w "$ARG5$" -c "$ARG6$" -user "$ARG7$" -pass "$ARG8$"
get_counter_bulk_count=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_bulk_count.vbs -h "$ARG1$" -class "$ARG2$" -inst "$ARG3$" -prop "$ARG4$" -w "$ARG5$" -c "$ARG6$"
get_counter_bulk_count_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_bulk_count.vbs -h "$ARG1$" -class "$ARG2$" -inst "$ARG3$" -prop "$ARG4$" -w "$ARG5$" -c "$ARG6$" -user "$ARG7$" -pass "$ARG8$"
get_counter_counter=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "$ARG2$" -inst "$ARG3$" -prop "$ARG4$" -w "$ARG5$" -c "$ARG6$"
get_counter_counter_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "$ARG2$" -inst "$ARG3$" -prop "$ARG4$" -w "$ARG5$" -c "$ARG6$" -user "$ARG7$" -pass "$ARG8$"
get_counter_large_rawcount=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_large_rawcount.vbs -h "$ARG1$" -class "$ARG2$" -inst "$ARG3$" -prop "$ARG4$" -w "$ARG5$" -c "$ARG6$"
get_counter_large_rawcount_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_large_rawcount.vbs -h "$ARG1$" -class "$ARG2$" -inst "$ARG3$" -prop "$ARG4$" -w "$ARG5$" -c "$ARG6$" -user "$ARG7$" -pass "$ARG8$"
get_counter_rawcount=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "$ARG2$" -inst "$ARG3$" -prop "$ARG4$" -w "$ARG5$" -c "$ARG6$"
get_counter_rawcount_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "$ARG2$" -inst "$ARG3$" -prop "$ARG4$" -w "$ARG5$" -c "$ARG6$" -user "$ARG7$" -pass "$ARG8$"
get_raw_fraction=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_raw_fraction.vbs -h "$ARG1$" -class "$ARG2$" -inst "$ARG3$" -prop "$ARG4$" -w "$ARG5$" -c "$ARG6$"
get_raw_fraction_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_raw_fraction.vbs -h "$ARG1$" -class "$ARG2$" -inst "$ARG3$" -prop "$ARG4$" -w "$ARG5$" -c "$ARG6$" -user "$ARG7$" -pass "$ARG8$"
# Example calls from check_nrpe:
# ./check_nrpe -H <IP1> -c get_100nsec_timer -a <IP2> Win32_PerfRawData_PerfOS_Processor Name=_Total PercentUserTime 80 90
# ./check_nrpe -H <IP1> -c get_counter_bulk_count -a <IP2> Win32_PerfRawData_PerfOS_System '*' FileControlBytesPerSec 50000 100000
# ./check_nrpe -H <IP1> -c get_counter_counter -a <IP2> Win32_PerfRawData_PerfOS_Processor Name=0,Name=1 InterruptsPerSec 20000 30000
# ./check_nrpe -H <IP1> -c get_counter_large_rawcount -a <IP2> Win32_PerfRawData_PerfProc_Process Name=spoolsv WorkingSet 10000000 20000000
# ./check_nrpe -H <IP1> -c get_counter_rawcount -a <IP2> Win32_PerfRawData_PerfProc_Process Name=spoolsv HandleCount 200 400
# ./check_nrpe -H <IP1> -c get_raw_fraction -a <IP2> Win32_PerfRawData_PerfDisk_LogicalDisk Name=C: PercentFreeSpace 40 60
# Note: The above counter plug-ins are also used further below for obtaining information about specific Windows applications. At present the
# plug-ins don't supprt thresholds as minimums. Refer to http://windowssdk.msdn.microsoft.com/en-us/library/ms758298.aspx
# for documentation on performance counter types.
# =================================
# Updated checks from V1
# =================================
get_swapping=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_PerfOS_Memory" -inst "*" -prop "PagesPerSec" -w "$ARG2$" -c "$ARG3$"
get_swapping_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_PerfOS_Memory" -inst "*" -prop "PagesPerSec" -w "$ARG2$" -c "$ARG3$" -user "$ARG4$" -pass "$ARG5$"
get_disktransfers=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_PerfDisk_PhysicalDisk" -inst "$ARG2$" -prop "DiskTransfersPersec" -w "$ARG3$" -c "$ARG4$"
get_disktransfers_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_PerfDisk_PhysicalDisk" -inst "$ARG2$" -prop "DiskTransfersPersec" -w "$ARG3$" -c "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
get_printqueue=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_Spooler_PrintQueue" -inst "$ARG2$" -prop "Jobs" -w "$ARG3$" -c "$ARG4$"
get_printqueue_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_Spooler_PrintQueue" -inst "$ARG2$" -prop "Jobs" -w "$ARG3$" -c "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
get_exchange_mbox_recvq=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSExchangeIS_MSExchangeISMailbox" -inst "Name=_Total" -prop "ReceiveQueueSize" -w "$ARG2$" -c "$ARG3$"
get_exchange_mbox_recvq_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSExchangeIS_MSExchangeISMailbox" -inst "Name=_Total" -prop "ReceiveQueueSize" -w "$ARG2$" -c "$ARG3$" -user "$ARG4$" -pass "$ARG5$"
get_exchange_mbox_sendq=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSExchangeIS_MSExchangeISMailbox" -inst "Name=_Total" -prop "SendQueueSize" -w "$ARG2$" -c "$ARG3$"
get_exchange_mbox_sendq_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSExchangeIS_MSExchangeISMailbox" -inst "Name=_Total" -prop "SendQueueSize" -w "$ARG2$" -c "$ARG3$" -user "$ARG4$" -pass "$ARG5$"
get_exchange_pub_recvq=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSExchangeIS_MSExchangeISPublic" -inst "Name=_Total" -prop "ReceiveQueueSize" -w "$ARG2$" -c "$ARG3$"
get_exchange_pub_recvq_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSExchangeIS_MSExchangeISPublic" -inst "Name=_Total" -prop "ReceiveQueueSize" -w "$ARG2$" -c "$ARG3$" -user "$ARG4$" -pass "$ARG5$"
get_exchange_pub_sendq=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSExchangeIS_MSExchangeISPublic" -inst "Name=_Total" -prop "SendQueueSize" -w "$ARG2$" -c "$ARG3$"
get_exchange_pub_sendq_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSExchangeIS_MSExchangeISPublic" -inst "Name=_Total" -prop "SendQueueSize" -w "$ARG2$" -c "$ARG3$" -user "$ARG4$" -pass "$ARG5$"
get_exchange_mta_workq=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSExchangeMTA_MSExchangeMTA" -inst "*" -prop "WorkQueueLength" -w "$ARG2$" -c "$ARG3$"
get_exchange_mta_workq_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSExchangeMTA_MSExchangeMTA" -inst "*" -prop "WorkQueueLength" -w "$ARG2$" -c "$ARG3$" -user "$ARG4$" -pass "$ARG5$"
get_iis_bytes_received=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_bulk_count.vbs -h "$ARG1$" -class "Win32_PerfRawData_W3SVC_WebService" -inst "$ARG2$" -prop "BytesReceivedPersec" -w "$ARG3$" -c "$ARG4$"
get_iis_bytes_received_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_bulk_count.vbs -h "$ARG1$" -class "Win32_PerfRawData_W3SVC_WebService" -inst "$ARG2$" -prop "BytesReceivedPersec" -w "$ARG3$" -c "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
get_iis_bytes_sent=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_bulk_count.vbs -h "$ARG1$" -class "Win32_PerfRawData_W3SVC_WebService" -inst "$ARG2$" -prop "BytesSentPersec" -w "$ARG3$" -c "$ARG4$"
get_iis_bytes_sent_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_bulk_count.vbs -h "$ARG1$" -class "Win32_PerfRawData_W3SVC_WebService" -inst "$ARG2$" -prop "BytesSentPersec" -w "$ARG3$" -c "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
get_iis_bytes_total=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_bulk_count.vbs -h "$ARG1$" -class "Win32_PerfRawData_W3SVC_WebService" -inst "$ARG2$" -prop "BytesTotalPersec" -w "$ARG3$" -c "$ARG4$"
get_iis_bytes_total_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_bulk_count.vbs -h "$ARG1$" -class "Win32_PerfRawData_W3SVC_WebService" -inst "$ARG2$" -prop "BytesTotalPersec" -w "$ARG3$" -c "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
get_iis_currentconnections=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_W3SVC_WebService" -inst "$ARG2$" -prop "CurrentConnections" -w "$ARG3$" -c "$ARG4$"
get_iis_currentconnections_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_W3SVC_WebService" -inst "$ARG2$" -prop "CurrentConnections" -w "$ARG3$" -c "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
get_iis_curnonanonusers=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_W3SVC_WebService" -inst "$ARG2$" -prop "CurrentNonAnonymousUsers" -w "$ARG3$" -c "$ARG4$"
get_iis_curnonanonusers_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_W3SVC_WebService" -inst "$ARG2$" -prop "CurrentNonAnonymousUsers" -w "$ARG3$" -c "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
get_iis_get_requests=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_W3SVC_WebService" -inst "$ARG2$" -prop "GetRequestsPersec" -w "$ARG3$" -c "$ARG4$"
get_iis_get_requests_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_W3SVC_WebService" -inst "$ARG2$" -prop "GetRequestsPersec" -w "$ARG3$" -c "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
get_iis_maximumconnections=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_W3SVC_WebService" -inst "$ARG2$" -prop "MaximumConnections" -w "$ARG3$" -c "$ARG4$"
get_iis_maximumconnections_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_W3SVC_WebService" -inst "$ARG2$" -prop "MaximumConnections" -w "$ARG3$" -c "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
get_iis_post_requests=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_W3SVC_WebService" -inst "$ARG2$" -prop "PostRequestsPersec" -w "$ARG3$" -c "$ARG4$"
get_iis_post_requests_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_W3SVC_WebService" -inst "$ARG2$" -prop "PostRequestsPersec" -w "$ARG3$" -c "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
get_iis_privatebytes=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_large_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_PerfProc_Process" -inst "Name=inetinfo" -prop "PrivateBytes" -w "$ARG2$" -c "$ARG3$"
get_iis_privatebytes_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_large_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_PerfProc_Process" -inst "Name=inetinfo" -prop "PrivateBytes" -w "$ARG2$" -c "$ARG3$" -user "$ARG4$" -pass "$ARG5$"
get_iis_totalnotfounderrors=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_W3SVC_WebService" -inst "$ARG2$" -prop "TotalNotFoundErrors" -w "$ARG3$" -c "$ARG4$"
get_iis_totalnotfounderrors_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_W3SVC_WebService" -inst "$ARG2$" -prop "TotalNotFoundErrors" -w "$ARG3$" -c "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
get_mssql_buf_cache_hit=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_raw_fraction.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerBufferManager" -inst "*" -prop "Buffercachehitratio" -w "$ARG2$" -c "$ARG3$"
get_mssql_buf_cache_hit_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_raw_fraction.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerBufferManager" -inst "*" -prop "Buffercachehitratio" -w "$ARG2$" -c "$ARG3$" -user "$ARG4$" -pass "$ARG5$"
get_mssql_deadlocks=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerLocks" -inst "$ARG2$" -prop "NumberofDeadlocksPersec" -w "$ARG3$" -c "$ARG4$"
get_mssql_deadlocks_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerLocks" -inst "$ARG2$" -prop "NumberofDeadlocksPersec" -w "$ARG3$" -c "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
get_mssql_fullscans=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerAccessMethods" -inst "*" -prop "FullScansPersec" -w "$ARG2$" -c "$ARG3$"
get_mssql_fullscans_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerAccessMethods" -inst "*" -prop "FullScansPersec" -w "$ARG2$" -c "$ARG3$" -user "$ARG4$" -pass "$ARG5$"
get_mssql_latch_waits=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerLatches" -inst "*" -prop "Latchwaitspersec" -w "$ARG2$" -c "$ARG3$"
get_mssql_latch_waits_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerLatches" -inst "*" -prop "Latchwaitspersec" -w "$ARG2$" -c "$ARG3$" -user "$ARG4$" -pass "$ARG5$"
get_mssql_lock_wait_time=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerLocks" -inst "$ARG2$" -prop "LockWaitTimems" -w "$ARG3$" -c "$ARG4$"
get_mssql_lock_wait_time_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerLocks" -inst "$ARG2$" -prop "LockWaitTimems" -w "$ARG3$" -c "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
get_mssql_lock_waits=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerLocks" -inst "$ARG2$" -prop "LockWaitsPersec" -w "$ARG3$" -c "$ARG4$"
get_mssql_lock_waits_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerLocks" -inst "$ARG2$" -prop "LockWaitsPersec" -w "$ARG3$" -c "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
get_mssql_log_growth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases" -inst "$ARG2$" -prop "LogGrowths" -w "$ARG3$" -c "$ARG4$"
get_mssql_log_growth_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases" -inst "$ARG2$" -prop "LogGrowths" -w "$ARG3$" -c "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
get_mssql_log_used=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases" -inst "$ARG2$" -prop "PercentLogUsed" -w "$ARG3$" -c "$ARG4$"
get_mssql_log_used_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases" -inst "$ARG2$" -prop "PercentLogUsed" -w "$ARG3$" -c "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
get_mssql_memgrantspending=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerMemoryManager" -inst "*" -prop "MemoryGrantsPending" -w "$ARG2$" -c "$ARG3$"
get_mssql_memgrantspending_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerMemoryManager" -inst "*" -prop "MemoryGrantsPending" -w "$ARG2$" -c "$ARG3$" -user "$ARG4$" -pass "$ARG5$"
get_mssql_transactions=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases" -inst "$ARG2$" -prop "TransactionsPersec" -w "$ARG3$" -c "$ARG4$"
get_mssql_transactions_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_counter.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases" -inst "$ARG2$" -prop "TransactionsPersec" -w "$ARG3$" -c "$ARG4$" -user "$ARG5$" -pass "$ARG6$"
get_mssql_users=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerGeneralStatistics" -inst "*" -prop "UserConnections" -w "$ARG2$" -c "$ARG3$"
get_mssql_users_auth=cscript.exe //nologo //T:60 c:\nrpe_nt\plugins\v2\check_counter_rawcount.vbs -h "$ARG1$" -class "Win32_PerfRawData_MSSQLSERVER_SQLServerGeneralStatistics" -inst "*" -prop "UserConnections" -w "$ARG2$" -c "$ARG3$" -user "$ARG4$" -pass "$ARG5$"