Progel.Windows.ScheduledTasks.2008.Monitoring.Script

Progel.Windows.ScheduledTasks.2008.Monitoring.Script (ProbeActionModuleType)

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
MonitorJobProbe ProbeAction Microsoft.Windows.ScriptPropertyBagProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TimeoutSecondsint$Config/TimeoutSeconds$TimeoutSeconds
LogSuccessEventbool$Config/LogSuccessEvent$LogSuccessEvent

Source Code:

<ProbeActionModuleType ID="Progel.Windows.ScheduledTasks.2008.Monitoring.Script" Accessibility="Internal" Batching="false" PassThrough="false">
<Configuration>
<xsd:element minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element minOccurs="1" name="ManagementGroupName" type="xsd:string"/>
<xsd:element minOccurs="1" name="LogSuccessEvent" type="xsd:boolean"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="LogSuccessEvent" Selector="$Config/LogSuccessEvent$" ParameterType="bool"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="MonitorJobProbe" TypeID="Windows!Microsoft.Windows.ScriptPropertyBagProbe">
<ScriptName>Progel.Windows.ScheduledTasks.2008.Monitoring.vbs</ScriptName>
<Arguments>$Config/ManagementGroupName$ $Config/LogSuccessEvent$</Arguments>
<ScriptBody><Script>


'*************************************************************************
' Script Name - Progel.Windows.ScheduledTasks.2008.Monitoring.vbs
'
' Purpose - Discovers a Scheduled Tasks
'
' (c) Copyright 2009, Progel srl, All Rights Reserved
' Proprietary and confidential to Progel srl
'*************************************************************************

Option explicit
SetLocale("en-us")

Const SCRIPT_VER = "1.2"


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

Const FAILURE_EVENT_ID = 675 'errore generico nello script
Const SUCCESS_EVENT_ID = 676
Const START_EVENT_ID = 677
Const STOP_EVENT_ID = 678

' TypedPropertyBag
const PerformanceDataType = 2
const StateDataType = 3

'Variables
Dim oArgs,SourceType,SourceID,ManagedEntityId,TargetPricipalName,TargetDisplayName,P_LogSuccessEvent,dtStart,lExitCode,sStatus,lStatus,P_ManagementGroup
Dim service,rootFolder

dtStart = Now

Set oArgs = WScript.Arguments
if oArgs.Count &lt; 1 Then
Wscript.Quit -1
End If

P_ManagementGroup = oArgs(0)
P_LogSuccessEvent = cbool(oArgs(1))

Dim oAPI,oBag
Set oAPI = CreateObject("Mom.ScriptAPI")

If (true = P_LogSuccessEvent) Then
LogParams
End IF

Set service = CreateObject("Schedule.Service")
call service.Connect()

Set rootFolder = service.GetFolder("\")

ProcessFolder rootFolder

Set rootFolder = Nothing

on error resume next

oAPI.ReturnItems

If (true = P_LogSuccessEvent) Then
Call LogEvent(STOP_EVENT_ID,EVENT_TYPE_SUCCESS, "has completed successfully in " &amp; DateDiff("s", dtStart, Now) &amp; " seconds.")
End IF

Sub ProcessFolder(Folder)
Dim registeredTask,SubFolder

For Each registeredTask In Folder.GetTasks(1)

if registeredTask.Enabled = True then

set oBag = oAPI.CreateTypedPropertyBag(StateDataType)

lExitCode = clng(registeredTask.LastTaskResult)

if (registeredTask.LastRunTime) = cdate(0) Then
lExitCode = "0"
end if

oBag.AddValue "JobName", registeredTask.Name
oBag.AddValue "JobStatus", registeredTask.State
oBag.AddValue "LastRun", cstr(registeredTask.LastRunTime)
oBag.AddValue "NextRun", cstr(registeredTask.NextRunTime)

oBag.AddValue "ExitCode", cstr(lExitCode)
oBag.AddValue "ExitCodeHex", "0x" &amp; fmt(CStr(Hex(lExitCode)))

oAPI.AddItem oBag

Set oBag = Nothing
end if

Next

For Each SubFolder In folder.GetFolders(1)
ProcessFolder SubFolder
next

End sub

Function fmt(sStat)
Dim lSize,i

lSize = Len(sStat)

for i = lSize to 7
sStat = "0" &amp; sStat
next

fmt=sStat

End Function

Sub LogParams
DIm scmdLine, I, oArgs
sCmdLine = ""
Set oArgs = WScript.Arguments
for I=0 to oArgs.Count -1
sCmdLine = sCmdLine &amp; " " &amp; oArgs(I)
next
LogEvent START_EVENT_ID,EVENT_TYPE_SUCCESS,"Starting script. " &amp; sCmdLine
End Sub

Sub LogEvent(eventID, eventType, msg)
WScript.Echo "Logging event. " &amp; Wscript.ScriptName &amp; " Version : " &amp; SCRIPT_VER &amp; " EventID: " &amp; eventID &amp; " eventType: " &amp; eventType &amp; " --&gt; " &amp; msg
Call oAPI.LogScriptEvent(Wscript.ScriptName,eventID,eventType, " Version : " &amp; SCRIPT_VER &amp; " " &amp; msg)
End Sub



</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="MonitorJobProbe"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
<InputType>System!System.BaseData</InputType>
</ProbeActionModuleType>