Running a monitor during business hours

One question I’ve been asked from customers of mine is how to run specific monitors only during business hours. Let’s say I want to check CPU performance only from 7:00 to 19:00 Monday to Friday. This was easy with MOM 2005, but has been lost with OpsMgr 2007. Actually it’s not lost but needs some manual work to be done for your own rules or monitors and a lot of work for rules and monitors exported in sealed MPs. First of all, this post won’t talk about rules since this topic has been covered by Boris Yanushpolsky in this post “Configuring rules to run during business hours only“.

To achieve the same result with a monitor you just need to build a composite module with a System.SchedulerFilter condition in your workflow. Alas the OpsMgr team didn’t think to the opportunity to create a composite data source with a Scheduler and a SchedulerFilter and use it as the base scheduler data source and that’s a pity. And indeed this could have been a good idea. So for sealed MPs you should:

  1. Export the MP in XML format
  2. Disable the original monitor
  3. Create you own MP
  4. Do some cut and paste from the exported one not forgetting to put a reference to it in your MP
  5. Add a SchedulerFilter to the monitor workflow

I suspect no one will try this mess on a regular basis.

But what Microsoft didn’t do you can do in your MPs. Let’s say we have a monitor based on a script that needs to run on a schedule, but only during business hours. The basic workflow of your monitor is typically based on just one step of type Microsoft.Windows.TimedScript.PropertyBagProvider. This precooked data source is the combination of a Scheduler and Script Probe, what we need to do is to recombine the two with a condition detection in the middle.

So what today is:

<DataSourceModuleType ID=”My.Script” Accessibility=”Internal” Batching=”false”>
        <Configuration> …
        <OverrideableParameters> …

        <ModuleImplementation Isolation=”Any”>
              <DataSource ID=”Script” TypeID=”Windows!Microsoft.Windows.TimedScript.PropertyBagProvider”> …
              <Node ID=”Script” />


Should become like this:          

              <Node ID=”Script”>
                <Node ID=”Filter”>
                <Node ID=”Scheduler”/>

The scheduler triggers based on its configuration, the Filter lets the trigger pass only during business hours and in turns the script runs only during the intended time.

Let’s expand our code with a more complete example. The example schedules a script that basically writes an event in the eventlog and returns a property bag to run only Monday to Friday from 7.00 to 19.00:

      <DataSourceModuleType ID=”Progel.Test.Filter.DS” Accessibility=”Internal” Batching=”false”>
        <xsd:element xmlns:xsd=”” name=”IntervalSeconds” type=”xsd:int” />
        <xsd:element xmlns:xsd=”” name=”SyncTime” type=”xsd:string” />
        <xsd:element xmlns:xsd=”” name=”Message” type=”xsd:string” />
        <xsd:element xmlns:xsd=”” name=”From” type=”xsd:string” />
        <xsd:element xmlns:xsd=”” name=”To” type=”xsd:string” />
          <OverrideableParameter ID=”IntervalSeconds” Selector=”$Config/IntervalSeconds$” ParameterType=”int” />
          <OverrideableParameter ID=”SyncTime” Selector=”$Config/SyncTime$” ParameterType=”string” />
          <OverrideableParameter ID=”Message” Selector=”$Config/Message$” ParameterType=”string” />
          <OverrideableParameter ID=”From” Selector=”$Config/From$” ParameterType=”string” />
          <OverrideableParameter ID=”To” Selector=”$Config/To$” ParameterType=”string” />
        <ModuleImplementation Isolation=”Any”>
                          <DataSource ID=”Scheduler” TypeID=”System!System.Scheduler”><Scheduler>
            </SimpleReccuringSchedule><ExcludeDates /></Scheduler></DataSource>

            <ProbeAction ID=”Script” TypeID=”Windows!Microsoft.Windows.ScriptPropertyBagProbe”>
Set g_API = CreateObject(“MOM.ScriptAPI”)
    Set oArgs = WScript.Arguments
    for I=0 to oArgs.Count -1
     sCmdLine = sCmdLine & ” ” & oArgs(I)
    LogEvent 100,1,”Starting script. ” & sCmdLine
    Set oBag= g_API.CreatePropertyBag()
    Call oBag.AddValue(“Message”, oARgs(0))
    Call oBag.AddValue(“RowLength”, CInt(oArgs(0)))
    Call g_API.Return(oBag)

Sub LogEvent(eventID, eventType, msg)
    WScript.Echo “Logging event. ” & WScript.ScriptName & ” EventID: ” & eventID & ” eventType: ” & eventType & ” –> ” & msg
    Call g_API.LogScriptEvent(WScript.ScriptName,eventID,eventType, msg)
End Sub
             <ConditionDetection ID=”Filter” TypeID=”System!System.SchedulerFilter”>
                      <ExcludeDates />
              <Node ID=”Script”>
                <Node ID=”Filter”>
                <Node ID=”Scheduler”/>

Now you can build your own monitor based on this datasource, you can add one more parameter for the DaysOfWeekMask so that it can be overridden and so on. Hope this can help.


  1. #1 by snajgel on October 5, 2009 - 12:13 pm

    Daniel, is it possible to get this as a sample MP just like the one for a service and web site.


  2. #5 by Lehugo on June 24, 2009 - 9:21 am

    Ok. I have a workarround to do it with the GUI without changing the XML file.

    First i create a time commands rule (Execute a script) where i can define business hours. The script should create an event log in case of error(eventcreate command).

    Then i create a event log two state monitor.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: