Monthly Archives: February 2016

How about Advanced instead of just Simple (System.SimpleScheduler)

Monitoring configurations that require being active on a specific schedule can be dealt in various ways.

One possibility is to take care of the scheduling while implementing the Monitor Type, inserting System.SchedulerFilter condition detection modules in the regular detections for monitor states. Depending on what workflows you are configuring, this might be the right and only approach.

But sometimes, if you can control your starting point (data source), you would be better off (read efficient) having the scheduling implemented right there, at beginning. To explain a bit better, with an example: instead of performing a check with a script at a certain interval and then drop the findings because outside of the schedule, the propose is to execute the script according to the active schedule and not waste resources for nothing, when results do not matter anyhow.

The System.Library Management Pack does not have such Datasource module, but it does provide the right building blocks to create one.
Use the following module to initiate a workflow at a regular interval, on a schedule of your choice.

<DataSourceModuleType ID="System.AdvancedScheduler" Accessibility="Public" Batching="false">
	<Configuration>
	  <IncludeSchemaTypes>
		<SchemaType>System!System.ExpressionEvaluatorSchema</SchemaType>
	  </IncludeSchemaTypes>
	  <xsd:element name="IntervalSeconds" type="xsd:int"/>
	  <xsd:element name="SyncTime" type="xsd:string"/>
	  <xsd:element name="Schedule" type="PublicSchedulerType" />
	</Configuration>
	<OverrideableParameters>
	  <OverrideableParameter ID="IntervalSeconds" ParameterType="int" Selector="$Config/IntervalSeconds$"/>
	  <OverrideableParameter ID="SyncTime" ParameterType="string" Selector="$Config/SyncTime$"/>
	</OverrideableParameters>
	<ModuleImplementation Isolation="Any">
	  <Composite>
		<MemberModules>
		  <DataSource TypeID="System!System.SimpleScheduler" ID="DS1">
			<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
			<SyncTime>$Config/SyncTime$</SyncTime>
		  </DataSource>
		  <ConditionDetection ID="OnScheduleCD" TypeID="System!System.SchedulerFilter">
			<SchedulerFilter>
			  <ProcessDataMode>OnSchedule</ProcessDataMode>
			  <Schedule>$Config/Schedule$</Schedule>
			  <UseCurrentTime>true</UseCurrentTime>
			</SchedulerFilter>
		  </ConditionDetection>
		</MemberModules>
		<Composition>
		  <Node ID="OnScheduleCD">
			<Node ID="DS1"/>
		  </Node>
		</Composition>
	  </Composite>
	</ModuleImplementation>
	<OutputType>System!System.TriggerData</OutputType>
</DataSourceModuleType> 

And here is an example of usage: the rule below will log an event in Application log every 5 minutes on Mon and Tue between 8-9pm and Fri between 10-11pm. Not exactly useful other than getting you started in the right direction.

<Rule ID="Testing.System.AdvancedScheduler" Enabled="true" Target="SystemCenter!Microsoft.SystemCenter.RootManagementServer" ConfirmDelivery="false" Remotable="true" Priority="Normal" DiscardLevel="100">
	<Category>Custom</Category>
	<DataSources>
	  <DataSource ID="Scheduler" TypeID="System.AdvancedScheduler">
		<IntervalSeconds>300</IntervalSeconds>
		<SyncTime></SyncTime>
		<Schedule>
		  <WeeklySchedule>
			<Windows>
			  <Daily>
				<Start>20:00</Start>
				<End>21:00</End>
				<DaysOfWeekMask>6</DaysOfWeekMask>
			  </Daily>
			  <Daily>
				<Start>22:00</Start>
				<End>23:00</End>
				<DaysOfWeekMask>32</DaysOfWeekMask>
			  </Daily>
			</Windows>
		  </WeeklySchedule>
		  <ExcludeDates/>
		</Schedule>
	  </DataSource>
	</DataSources>
	<WriteActions>
	  <WriteAction ID="ExecuteCommand" TypeID="System!System.CommandExecuter">
		<ApplicationName>c:\windows\system32\eventcreate.exe</ApplicationName>
		<WorkingDirectory>c:\windows\system32</WorkingDirectory>
		<CommandLine>/T Information /ID 1 /L Application /D "Testing System.AdvancedScheduler"</CommandLine>
		<TimeoutSeconds>15</TimeoutSeconds>
		<RequireOutput>true</RequireOutput>
		<Files />
	  </WriteAction>
	</WriteActions>
</Rule>