<WriteActionModuleType ID="SMSv4_Monitor_Site_System_Summarizer" Accessibility="Internal" Comment="{62CAC8EE-9013-482D-91BC-D61FC7AF1CB4}">
<Configuration>
<IncludeSchemaTypes>
<SchemaType>MomBackwardCompatibility!System.Mom.BackwardCompatibility.AlertGenerationSchema</SchemaType>
</IncludeSchemaTypes>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="AlertGeneration" type="AlertGenerationType"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="InvokerType" type="xsd:integer"/>
</Configuration>
<ModuleImplementation>
<Composite>
<MemberModules>
<WriteAction ID="RunScriptAction" TypeID="MomBackwardCompatibility!System.Mom.BackwardCompatibility.ScriptResponse">
<AlertGeneration>$Config/AlertGeneration$</AlertGeneration>
<InvokerType>$Config/InvokerType$</InvokerType>
<Body><Script>
'*******************************************************************************
' Script Name - ConfigMgr 2007 Monitor Site System Summarizer
'
' Purpose - Monitor specific SMS Site System Summarizer status on SMSv4
' Site Systems and raise appropriate events. SMS 2.0 Site Systems
' are ignored.
'
' The following additional events can be raised:
'
' 1100 - An event used only for debugging or tracing.
' 1101 - Script executed successfully.
' 1102 - An error occurred in executing this script.
' 1105 - Accessed denied due to connection failure or permissions.
' 1106 - SMS Site System is possibly down.
' 1107 - SMS Site System has less than 5% free physical disk space
' 1108 - SMS SQL database has less than 5% free data file space and no autogrow
' 1109 - SMS SQL database has less than 5% free log file space and no autogrow
'
' Assumptions - This script will runs on a system with the SMS WMI Provider
' installed. The system can therefore be either an SMS Primary
' Site Server or Remote Provider.
'
' This script does not support agentless mode and will silently
' terminate.
'
' The agent will be enabled for proxying for other computers.
'
' Parameters - None
'
' Change Hist - Date Version Description
' -------- --------------- -----------
' 08/27/03 02.50.0058.0000 Added Change History.
' 03/17/04 02.50.0169.0000 Added check for agentless mode.
' 05/17/04 05.0.2700.0000 Added event proxying.
' 04/23/05 05.0.2754.0000 Updated for SMSv4.
' 08/18/07 6.0.5000.2 Added event tracing support.
'
' (c) Copyright 2007, Microsoft Corp., All Rights Reserved
'*******************************************************************************
Const EVENT_ID_SITE_SYSTEM_DOWN = 1106 'SMS Site System is possibly down.
Const EVENT_ID_SITE_SYSTEM_FREE_DISK_SPACE = 1107 'SMS Site System has less than 5% free physical disk space
Const EVENT_ID_SITE_SYSTEM_FREE_SQL_DATA_SPACE = 1108 'SMS SQL database has less than 5% free data file space and no autogrow
Const EVENT_ID_SITE_SYSTEM_FREE_SQL_LOG_SPACE = 1109 'SMS SQL database has less than 5% free log file space and no autogrow
Const SCRIPT_NAME = "ConfigMgr 2007 Monitor Site System Summarizer"
' Global variables
'=================
Sub Main()
Dim bEventTracing
On Error Resume Next
LogMessage DBG_TRACE, ScriptContext.Name & " script starting at local time: " & CStr(Time)
'Check if event tracing is configured. If it is, raise a start event.
'=====================================================================
bEventTracing = IsEventTracingEnabled()
If (bEventTracing = True) Then
LogEvent EVENT_ID_NOTANEVENT, EVENT_TYPE_INFORMATION, "started at local time: " & CStr(Time)
End If
'This script does not support agentless monitoring.
'==================================================
If ScriptContext.IsTargetAgentless Then
Exit Sub
End If
'Check the Site System Summarizer table in the SMS SQL database for
'this machine's site.
'==============================================================
CheckSiteSystemSummarizer
If 0 <> Err.number Then
ScriptError "check Site System Summarizer table in the SMS SQL database." & GetErrorString(Err)
End If
If (bEventTracing = True) Then
LogEvent EVENT_ID_SCRIPTSUCCESS, EVENT_TYPE_INFORMATION, "completed at local time: " & CStr(Time)
End If
LogMessage DBG_TRACE, ScriptContext.Name & " script completed at local time: " & CStr(Time)
End Sub
'******************************************************************************
' Name: CheckSiteSystemSummarizer
'
' Purpose: Check the Site System Summarizer table in the SMS SQL database
' for this machine's site.
'
' Parameters: None
'
' Returns: Nothing
'
Sub CheckSiteSystemSummarizer()
Dim oWbemService
Dim oWbemContext
Dim oInstance
Dim oInstanceSet
Dim strQuery
On Error Resume Next
'Connect to the SMS site namespace.
'==================================
Set oWbemService = GetConnectionToSite()
If Err Then
Exit Sub
End If
'Query for site systems with monitored conditions.
'=================================================
strQuery = GetSMSSSiteSystemSummarizerQuery()
Set oWbemContext = CreateObject("WbemScripting.SWbemNamedValueSet")
oWbemContext.Add "NOLOCK", True
Set oInstanceSet = oWbemService.ExecQuery(strQuery,, _
wbemFlagReturnImmediately + wbemFlagForwardOnly, _
oWbemContext)
If Not IsEmpty(oInstanceSet) Then
For Each oInstance In oInstanceSet
If Not IsEmpty(oInstance) Then
CreateEvents oInstance
End If
Next
Set oInstanceSet = Nothing
End If
'Cleanup
'=======
Set oWbemContext = Nothing
Set oWbemService = Nothing
End Sub
'******************************************************************************
' Name: GetConnectionToSite
'
' Purpose: Gets the Wbem Services object for the local provider's site.
'
' Parameters: None
'
' Returns: Object, the object to return or nothing
'
Function GetConnectionToSite()
Dim oWbemService
Dim oWbemLocator
Dim strMachine, strSiteCode
Dim strQuery
On Error Resume Next
Err.Clear
'Get the SMS Provider information for the provider that is installed
'on this machine.
'===================================================================
GetLocalSMSProviderInfo strMachine, strSiteCode
If Err Then
Set GetConnectionToSite = Nothing
Exit Function
End If
'Connect to the site's SMS namespace through the locally installed
'provider. This will simplify the security model since the MOM Agent
'running under Local System will always be able to access this
'provider. The provider will then know how to connect to the
'appropriate SMS database.
'====================================================================
Set oWbemLocator = CreateObject("WbemScripting.SWbemLocator")
If Err Then
Set GetConnectionToSite = Nothing
Exit Function
End If
Set oWbemService = oWbemLocator.ConnectServer(strMachine, "root\sms\site_" & strSiteCode)
If Err Then
Set GetConnectionToSite = Nothing
Exit Function
End If
Set GetConnectionToSite = oWbemService
'Cleanup
'=======
Set oWbemLocator = Nothing
Set oWbemService = Nothing
End Function
'******************************************************************************
' Name: GetLocalSMSProviderInfo
'
' Purpose: Gets the SMS Provider information for the local provider. If
' the current machine is an SMS Site Server, this information
' will for this machine's SMS site. If the current machine is
' a Remote Provider and SQL Server that is shared, it will not be.
'
' Parameters: strMachine The machine that the provider is installed on,
' the current machine.
' strSiteCode The SMS site that the provider supports.
'
' Returns: strSiteCode, strSiteCode
'
Sub GetLocalSMSProviderInfo(strMachine, strSiteCode)
Dim oService
Dim oProviderLocation
Dim oProviderLocationSet
Dim strQuery
Dim strCurrentMachine
On Error Resume Next
Err.Clear
'Get this machine's name.
'========================
strCurrentMachine = GetCurrentSystem()
If Err Then
Exit Sub
End If
'Connect to the WMI SMS namespace for this machine.
'==================================================
Set oService = GetObject("winmgmts:root\sms")
If Err Then
Exit Sub
End If
'Query for the SMS Provider location information for the current
'machine, the locally installed SMS Provider.
'===============================================================
strQuery = "select * from SMS_ProviderLocation where Machine='" & strCurrentMachine & "'"
Set oProviderLocationSet = oService.ExecQuery(strQuery)
If Not IsEmpty(oProviderLocationSet) Then
For Each oProviderLocation In oProviderLocationSet
'******************************************************************************
' Name: GetCurrentSystem
'
' Purpose: Gets the name of the current system.
'
' Parameters: None
'
' Returns: String, current system name
'
Function GetCurrentSystem()
'Get the instances of computer system under the WMI CIMV2 namespace.
'There will be only one for the current system.
'===================================================================
Set oComputerSystemSet = GetObject("winmgmts:").InstancesOf("Win32_ComputerSystem")
If Err Then
Exit Function
End If
If Not IsEmpty(oComputerSystemSet) Then
For Each oComputerSystem In oComputerSystemSet
GetCurrentSystem = oComputerSystem.Name
Next
Set oComputerSystemSet = Nothing
End If
End Function
'******************************************************************************
' Name: GetSMSSSiteSystemSummarizerQuery
'
' Purpose: Gets query string for monitoring the SMS Site System Summarizer.
'
' Parameters: None
'
' Returns: String, a query
'
Function GetSMSSSiteSystemSummarizerQuery()
'Note the query should be distinct specifying SiteObject, SiteCide
'and Role but the query will contain the distinct qualifier just to
'insure that no duplicate events are raised
'==================================================================
GetSMSSSiteSystemSummarizerQuery = "select distinct " & _
"System.NetbiosName, " & _
"System.ResourceDomainORWorkgroup, " & _
"SiteSystemSummarizer.SiteCode, " & _
"SiteSystemSummarizer.SiteObject, " & _
"SiteSystemSummarizer.ObjectType, " & _
"SiteSystemSummarizer.Role, " & _
"SiteSystemSummarizer.DownSince, " & _
"SiteSystemSummarizer.PercentFree " & _
"from SMS_SiteSystemSummarizer as SiteSystemSummarizer " & _
"join SMS_SystemResourceList as Resource on SiteSystemSummarizer.SiteCode=Resource.SiteCode " & _
"and SiteSystemSummarizer.Role=Resource.RoleName " & _
"and SiteSystemSummarizer.SiteSystem=Resource.NALPath " & _
"join SMS_R_System as System on System.NetbiosName=Resource.ServerName " & _
"join SMS_Site as Site on SiteSystemSummarizer.SiteCode=Site.SiteCode " & _
"where (Site.Version like ""4.00.%"") and " & _
"((SiteSystemSummarizer.DownSince <> NULL) or " & _
"((SiteSystemSummarizer.PercentFree > 0) and (SiteSystemSummarizer.PercentFree < 5)))"
End Function
'******************************************************************************
' Name: CreateEvents
'
' Purpose: To generate MOM events for the SMS Site System found in the
' specified SMS site system instance.
'
' Parameters: oInstance, a object with an embedded SMS Site System Summarizer
' object and System object meeting the query criteria and
' containing only the properties specified in the query that
' returned it from WMI.
'
Sub CreateEvents(oInstance)
Dim lEventNumber
Dim lEventType
On Error Resume Next
'Create events if the Site System is down.
'=========================================
'Create events if the Site System has less than 5% free space of
'
' Physical disk
' SQL data file
' SQL log file
'
'Note, that SQL Servers with autogrow are not handled. The WMI
'query against the Site System Summarizer excludes these systems.
'================================================================
If ((oInstance.SiteSystemSummarizer.PercentFree > 0) And _
(oInstance.SiteSystemSummarizer.PercentFree < 5)) Then
Select Case (oInstance.SiteSystemSummarizer.ObjectType)
'******************************************************************************
' Name: GetErrorString
'
' Purpose: Attempts to find the description for an error if an error with
' no description is passed in.
'
' Parameters: oErr, the error object
'
' Return: String, the description for the error. (Includes the error code.)
'
Function GetErrorString(oErr)
Dim lErr, strErr
lErr = oErr
strErr = oErr.Description
On Error Resume Next
If 0 >= Len(strErr) Then
' If we don't have an error description, then check to see if the error
' is a 0x8007xxxx error. If it is, then look it up.
Const ErrorMask = &HFFFF0000
Const HiWord8007 = &H80070000
Const LoWordMask = 65535 ' This is equivalent to 0x0000FFFF
If (lErr And ErrorMask) = HiWord8007 Then
' Attempt to use 'net helpmsg' to get a description for the error.
Dim oShell
Set oShell = CreateObject("WScript.Shell")
If Err = 0 Then
Dim oExec
Set oExec = oShell.Exec("net helpmsg " & (lErr And LoWordMask))
Dim strMessage, i
Do
strMessage = oExec.stdout.ReadLine()
i = i + 1
Loop While (Len(strMessage) = 0) And (i < 5)
strErr = strMessage
End If
End If
End If
GetErrorString = vbCrLf & "The error returned was: '" & strErr & "' " & lErr & " (0x" & Hex(lErr) & ")"
End Function
'******************************************************************************
' Name: ScriptError
'
' Purpose: To generate a warning about a runtime script error.
'
' Parameters: strError, the description of the error
'
Sub ScriptError(strError)
LogEvent EVENT_ID_SCRIPTERROR, EVENT_TYPE_WARNING, "encountered a runtime error." & vbCrLf & "Failed to " & strError
End Sub
'******************************************************************************
' Name: AccessError
'
' Purpose: To generate a warning about an access/permissions error.
'
' Parameters: strError, the description of the error
' strNameSpace, the WMI name space root
'
Sub AccessError(strError, strNameSpace)
LogEvent EVENT_ID_ACCESSDENIED, EVENT_TYPE_WARNING, "encountered a permissions error." & vbCrLf & _
"The script failed to " & strError & " in the naming context '" & _
strNameSpace & "' because access was denied. Alter the permissions for this " & _
"name space so that the script." & vbCrLf & _
GetErrorString(Err)
End Sub
'******************************************************************************
' Name: LogEvent
'
' Purpose: To generate a MOM event
'
' Parameters: lEventID, the event code
' lEventType, the severity of the event
' strMessage, the message to include in the event
'
Sub LogEvent(lEventID, lEventType, strMessage)
'******************************************************************************
' Name: CreateEvent
'
' Purpose: To generate a MOM event with parameters containing values from
' the properties in the specified SMS site system object.
'
' Parameters: lEventNumber, the event number
' lEventType, the severity of the event
' oInstance, a object with an embedded SMS Site System Summarizer
' object and System object meeting the query criteria and
' containing only the properties specified in the query that
' returned it from WMI.
'
Sub CreateEvent(lEventNumber, lEventType, oInstance)
Dim oEvent
Dim strShareName
Dim strComputerName
Dim strEventMessage
On Error Resume Next
'Get SMS Site System and MOM event objects.
'==========================================
Set oEvent = ScriptContext.CreateEvent
'Initialize common event properties.
'===================================
'oEvent.SourceDomain = "DOMAIN" ' Domain of SourceComputer
'oEvent.SourceComputer = "MachineName" ' Must be a MOM Agent
oEvent.LoggingDomain = oInstance.System.ResourceDomainORWorkgroup ' Domain of LoggingComputer
oEvent.LoggingComputer = oInstance.System.NetbiosName ' Doesn't have to be a MOM Agent
strEventMessage = "SMS Site System " & strComputerName & _
" with role " & "'" & oInstance.SiteSystemSummarizer.Role & "'" & _
" is possibly down."
Case EVENT_ID_SITE_SYSTEM_FREE_DISK_SPACE
strEventMessage = "SMS Site System " & strComputerName & _
" has less than 5% free physical disk space on device " & strShareName & "."
Case EVENT_ID_SITE_SYSTEM_FREE_SQL_DATA_SPACE
strEventMessage = "SMS SQL database for site " & oInstance.SiteSystemSummarizer.SiteCode & _
" on system " & strComputerName & _
" has less than 5% free data file space and is not set to autogrow."
Case EVENT_ID_SITE_SYSTEM_FREE_SQL_LOG_SPACE
strEventMessage = "SMS SQL database for site " & oInstance.SiteSystemSummarizer.SiteCode & _
" on system " & strComputerName & _
" has less than 5% free log file space and is not set to autogrow."
End Select
oEvent.Message = strEventMessage
'Submit, raise, this event to MOM.
'=================================
ScriptContext.Submit oEvent
'Cleanup
'=======
Set oEvent = Nothing
End Sub
'******************************************************************************
' Name: GetShareName
'
' Purpose: Gets the share from the specified SiteObject NAL path.
'
' Parameters: None
'
' Returns: String, a device, share.
'
Function GetShareName(strSiteObject)
Dim intServerCharPos
Dim intShareCharPos
Dim intBackSlashCharPos
On Error Resume Next
Err.Clear
'Searching from the end of SiteObject NAL path find the beginning of
'the \\Server\Share\ path components.
'===================================================================
intServerCharPos = InStrRev(strSiteObject, "\\")
'Searching forward from \\Server\Share\ find the beginning
'character positions for Server and Share path components.
'=========================================================
'******************************************************************************
' Name: GetComputerName
'
' Purpose: Gets the computer from the specified SiteObject NAL path.
'
' Parameters: None
'
' Returns: String, a query
'
Function GetComputerName(strSiteObject)
Dim intServerCharPos
Dim intBackSlashCharPos
On Error Resume Next
Err.Clear
'Searching from the end of SiteObject NAL path find the beginning of
'the \\Server\Share\ path components.
'===================================================================
intServerCharPos = InStrRev(strSiteObject, "\\")
'Searching forward from \\Server\Share\ find the beginning
'character positions for Server and its trailing back slash.
'===========================================================
'******************************************************************************
' Name: IsEventTracingEnabled
'
' Purpose: Returns the state of the EventTracingEnabled registry setting.
' This setting is directs scripts raise additional tracing MOM
' events i.e. start and completion events.
'
' Checks for the EventTracingEnabled registry value under the
' following registry paths. If the DWORD values exists, it is read.
'
' HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft Operations Manager
' HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft Operations Manager
'
' Parameters: None
'
' Returns: True if the value exists and is set to 1 else False.
'
Function IsEventTracingEnabled()