'------------------------------------------------------------------------------ ' IIS v6 Check state of an application pool ' ========================================= ' ' Author: Vincent BESANCON (vincent.besancon@faurecia.com) ' Usage: ' check_iis_apppool_state.vbs ' - The name of the application pool. ' ' It returns: ' - OK if state is running. ' - CRITICAL if state is stopped. ' - WARNING if state is stopping or starting. ' - UNKNOWN for all the others (app pool not found, etc...). ' ' Nagios Agent configuration (NSC.INI): ' check_iis_apppool_state=cscript.exe //nologo //T:60 scripts\check_iis_apppool_state.vbs $ARG1$ '------------------------------------------------------------------------------ ' ' Args strArgAppPool = Wscript.Arguments.Unnamed.Item(0) ' Establish the connection to the WMI provider Set oWMIService = GetObject("winmgmts:root\microsoftiisv2") ' Search the AppPool passed as argument in the list of application pools Set strQueryAppPools = oWMIService.ExecQuery("Select * from IIsApplicationPoolSetting where Name='W3SVC/AppPools/" & strArgAppPool & "'") ' Enumerate the pools noError = False For Each oAppPool in strQueryAppPools noError = True ' Create nice messages for pool states Select Case oAppPool.AppPoolState Case 1 poolState = "Starting" outputStatus = "WARNING: " outputCode = 1 Case 2 poolState = "Running" outputStatus = "OK: " outputCode = 0 Case 3 poolState = "Stopping" outputStatus = "WARNING: " outputCode = 1 Case 4 poolState = "Stopped" outputStatus = "CRITICAL: " outputCode = 2 Case else poolState = "unknown" outputStatus = "UNKNOWN: " outputCode = 3 End Select ' Create a clear name for the pool (remove the leading info) poolName = Replace(oAppPool.Name, "W3SVC/AppPools/", "") ' Output Wscript.Echo outputStatus & poolName & ", State: " & poolState Next ' Error handling If Not noError Then ' Error message Wscript.echo "UNKNOWN: Error during the WMI query for app pool " & strArgAppPool & " !" ' Exit & return code WScript.Quit(3) Else ' Clean exit WScript.Quit(outputCode) End If