ActiveRoles Service: General response - Script

Quest.One.ActiveRoles.Rules.Event.ServiceGeneralResponse (Rule)

Element properties:

TargetMicrosoft.Windows.Computer
CategoryEventCollection
EnabledTrue
Alert GenerateFalse
RemotableTrue

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedScript.EventProvider Default
WriteToDB WriteAction Microsoft.SystemCenter.CollectEvent Default
WriteToDW WriteAction Microsoft.SystemCenter.DataWarehouse.PublishEventData Default

Source Code:

<Rule ID="Quest.One.ActiveRoles.Rules.Event.ServiceGeneralResponse" Enabled="true" Target="Windows!Microsoft.Windows.Computer" ConfirmDelivery="false" Remotable="true" Priority="Normal" DiscardLevel="100">
<Category>EventCollection</Category>
<DataSources>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.EventProvider">
<IntervalSeconds>300</IntervalSeconds>
<SyncTime/>
<ScriptName>ARSPServiceGeneralResponse.vbs</ScriptName>
<Arguments>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$ True</Arguments>
<ScriptBody><Script><![CDATA['*************************************************************************
' Script Name - ActiveRoles Service: General response
'
' Purpose - Monitors the general responsiveness of ActiveRoles Service on Local host
'
' Assumptions - Script is run by a timed event
'
' Parameters - ComputerName - Computer name
' LogSuccessEvent - True/False value to indicates to log an
' an event for script success
' (useful for demos and debugging)
'
' (c) Copyright 2004-2012, Quest Software, All Rights Reserved
'*************************************************************************

Option Explicit

' Product name dependent constants
Const EDM_UNAVAILABLE_STRING = "ActiveRoles Service is unavailable."
Const EDM_AVAILABLE_STRING = "ActiveRoles Service is available."
Const EDM_EMPTY_SCHEMA_VERSION_STRING = "ActiveRoles Schema Version is empty."
Const EDM_SERVICE_IS_NOT_STARTED_STRING = "ActiveRoles Service is not started."
Const EDM_SERVICE_IS_NOT_INSTALLED_STRING = "ActiveRoles Service is not installed."
Const EDM_SERVICE_NAME_STRING = "arssvc"
Const SCRIPT_NAME = "ActiveRoles Service: General response"

' Event Constants
Const EVENT_TYPE_SUCCESS = 0
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4

' Event IDs
Const EDM_UNAVAILABLE_EVENT_ID = 1000
Const WMI_IS_REQUIED_EVENT_ID = 2000
Const EDM_AVAILABLE_EVENT_ID = 3000

' Other Constants
Dim sSeparator
sSeparator = vbCRLF & vbCRLF & "Details:" & vbCRLF

Dim ComputerName, bLogSuccessEvent
ComputerName = WScript.Arguments(0)
bLogSuccessEvent = CBool(WScript.Arguments(1))

Dim sRGContainerAdsPath
sRGContainerAdsPath = "EDMS://" + ComputerName + "/CN=Administration Services,CN=Server Configuration,CN=Configuration"

Main

Sub Main()
On Error Resume Next

Dim oRGContainer, oEDMS

Dim oParams

Dim sMessage
Dim nSchemaVer

' Check that EDM service is installed and is started
sMessage = CheckEDMService
If Len(sMessage) <> 0 Then
CreateEvent EDM_UNAVAILABLE_EVENT_ID, EVENT_TYPE_ERROR, SCRIPT_NAME, sMessage
Exit Sub
End If

' Check that EDM service is completely started
Set oEDMS = GetObject("EDMS:")
Set oRGContainer = oEDMS.OpenDSObject (sRGContainerAdsPath, "", "", &H8000&)
If Err.Number <> 0 Then
sMessage = EDM_UNAVAILABLE_STRING & sSeparator & Err.Description
CreateEvent EDM_UNAVAILABLE_EVENT_ID, EVENT_TYPE_ERROR, SCRIPT_NAME, sMessage
Exit Sub
End If

' Get EDM schema version to check EDM service availability
nSchemaVer = GetEDMSchemaVersion

If Err.Number <> 0 Then
sMessage = EDM_UNAVAILABLE_STRING & sSeparator & Err.Description
CreateEvent EDM_UNAVAILABLE_EVENT_ID, EVENT_TYPE_ERROR, SCRIPT_NAME, sMessage
Else
If Len(nSchemaVer) = 0 Then
sMessage = EDM_UNAVAILABLE_STRING & sSeparator & EDM_EMPTY_SCHEMA_VERSION_STRING
CreateEvent EDM_UNAVAILABLE_EVENT_ID, EVENT_TYPE_ERROR, SCRIPT_NAME, sMessage
Else
If bLogSuccessEvent Then
sMessage = EDM_AVAILABLE_STRING
CreateEvent EDM_AVAILABLE_EVENT_ID, EVENT_TYPE_INFORMATION, SCRIPT_NAME, sMessage
End If
End If
End If

End Sub

Function GetEDMSchemaVersion()

Dim oEDMS, oRootDSE, oSchema
Dim sSchemaNC, sSchemaVer

' bind to EDM
Set oEDMS = GetObject("EDMS:")

Set oRootDSE = oEDMS.OpenDSObject ("EDMS://" & ComputerName & "/" & "RootDSE", "", "", &H8000&)
oRootDSE.GetInfoEx Array("schemaNamingContext"), 0
sSchemaNC = oRootDSE.Get ("schemaNamingContext")

Set oSchema = oEDMS.OpenDSObject ("EDMS://" & ComputerName & "/" & sSchemaNC, "", "", &H8000&)

oSchema.GetInfoEx Array("edsaSchemaVersion"), 0
GetEDMSchemaVersion = oSchema.Get ("edsaSchemaVersion")

End Function

Sub CreateEvent(lngEventID, lngEventType, strEventSource, sMessage)
Dim oAPI, oBag
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue("EventId", lngEventID)
Call oBag.AddValue("EventType", lngEventType)
Call oBag.AddValue("EventSource", strEventSource)
Call oBag.AddValue("EventLog", sMessage)
Call oAPI.Return(oBag)
End Sub

Function CheckEDMService()

On Error Resume Next

Dim oWmiSvc, colItems, oEdmSvc, path

CheckEDMService = ""

' Check that ActiveRoles Service is installed and started
path = "WINMGMTS:{impersonationLevel=impersonate}!\\" & ComputerName & "\root\cimv2:Win32_Service='" & EDM_SERVICE_NAME_STRING & "'"
Set oEdmSvc = GetObject(path)

If oEdmSvc Is Nothing Then
CheckEDMService = EDM_UNAVAILABLE_STRING & sSeparator & EDM_SERVICE_IS_NOT_INSTALLED_STRING
Exit Function
End If

If oEdmSvc.Started = false Then
CheckEDMService = EDM_UNAVAILABLE_STRING & sSeparator & EDM_SERVICE_IS_NOT_STARTED_STRING
End If

Set oEdmSvc = Nothing

End Function





]]></Script></ScriptBody>
<TimeoutSeconds>240</TimeoutSeconds>
<EventOriginId>$MPElement$</EventOriginId>
<PublisherId>$MPElement$</PublisherId>
<PublisherName>EDM</PublisherName>
<Channel>EDM Server</Channel>
<LoggingComputer>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</LoggingComputer>
<EventNumber>$Data/Property[@Name='EventId']$</EventNumber>
<EventCategory>0</EventCategory>
<EventLevel>$Data/Property[@Name='EventType']$</EventLevel>
<UserName/>
<Description>$Data/Property[@Name='EventLog']$</Description>
<Params/>
</DataSource>
</DataSources>
<WriteActions>
<WriteAction ID="WriteToDB" TypeID="SC!Microsoft.SystemCenter.CollectEvent"/>
<WriteAction ID="WriteToDW" TypeID="SCDW!Microsoft.SystemCenter.DataWarehouse.PublishEventData"/>
</WriteActions>
</Rule>