Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Came across multiple environments where monitoring needs to be run on UTC business hours but not on local time.
Herewith we create a PowerShell script base module can be used in any monitor or rule as scheduled trigger.
The Module takes three parameters below:
- IntervalSeconds to run monitor/Rule i.e. pool time in Seconds (Example: 120 )
- UTC Start time in HH:MM format in 24-hour clock (example: 11:20)
- UTC End time in HH:MM format in 24-hour clock (example: 14:40)
The scheduler will stop processing monitoring/rule time between start time and end time.
The data source module has three sub module as below:
PowerShell script:
Param($StartTime,$EndTime)
$api = new-object -comObject 'MOM.ScriptAPI'
$api.LogScriptEvent('MyScript.ps1',20,4,$computerName)
$bag = $api.CreatePropertyBag()
$flag=0
$bag.AddValue('FilterStartTime',$StartTime.tostring())
$bag.AddValue('FilterEndTime',$EndTime.tostring())
$endflag=0
[Datetime]$StartTime=$StartTime
[Datetime]$EndTime= $EndTime
[Datetime]$midnight="23:59"
[Datetime]$Daystart="00:00"
if($StartTime -gt $EndTime)
{
$endflag=1
}
$date=Get-Date
$bag.AddValue('LocalTIme',$date.tostring())
$utc=$date.ToUniversalTime()
$bag.AddValue('UTCTime',$utc.tostring())
if($endflag -eq 0)
{
if(($utc -ge $StartTime) -and ($utc -le $EndTime))
{
$flag=1
}
}
else
{
if((($utc -ge $StartTime) -and ($utc -le $midnight)) -or (($utc -ge $Daystart) -and ($utc -le $EndTime)) )
{
$flag=1
}
}
$bag.AddValue('flag',$flag)
$bag
Module Output property bag:
MP file:
Did not find a way to upload File, copy below XML to XML file with name UtcTime.Schedule.xml
<?xml version="1.0" encoding="utf-8"?><ManagementPack ContentReadable="true" SchemaVersion="2.0" OriginalSchemaVersion="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<Manifest>
<Identity>
<ID>UtcTime.Schedule</ID>
</Identity>
<Name>UtcTime.Schedule</Name>
<References>
<Reference Alias="Windows">
<ID>Microsoft.Windows.Library</ID>
<Version>7.5.8501.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
<Reference Alias="System">
<ID>System.Library</ID>
<Version>7.5.8501.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
<Reference Alias="SC">
<ID>Microsoft.SystemCenter.Library</ID>
<Version>7.0.8437.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
<Reference Alias="Health">
<ID>System.Health.Library</ID>
<Version>7.0.8437.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
</References>
</Manifest>
<TypeDefinitions>
<ModuleTypes>
<DataSourceModuleType ID="UtcTime.Schedule.DS" Accessibility="Public" Batching="false">
<Configuration>
<xsd:element minOccurs="1" name="IntervalSeconds" type="xsd:integer" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
<xsd:element minOccurs="0" name="SyncTime" type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema" /> <xsd:element minOccurs="1" name="FilterStartTime" type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
<xsd:element minOccurs="1" name="FilterEndTime" type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int" />
<OverrideableParameter ID="FilterStartTime" Selector="$Config/FilterStartTime$" ParameterType="string" />
<OverrideableParameter ID="FilterEndTime" Selector="$Config/FilterEndTime$" ParameterType="string" />
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="Scheduler" TypeID="System!System.SimpleScheduler">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime>$Config/SyncTime$</SyncTime>
</DataSource>
<ProbeAction ID="Utc.TimeCaluclator" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagProbe">
<ScriptName>UtcTimeCalulator.ps1</ScriptName>
<ScriptBody>
Param($StartTime,$EndTime)
$api = new-object -comObject 'MOM.ScriptAPI'
$api.LogScriptEvent('MyScript.ps1',20,4,$computerName)
$bag = $api.CreatePropertyBag()
$flag=0
$bag.AddValue('FilterStartTime',$StartTime.tostring())
$bag.AddValue('FilterEndTime',$EndTime.tostring())
$endflag=0
[Datetime]$StartTime=$StartTime
[Datetime]$EndTime= $EndTime
[Datetime]$midnight="23:59"
[Datetime]$Daystart="00:00"
if($StartTime -gt $EndTime)
{
$endflag=1
}
$date=Get-Date
$bag.AddValue('LocalTIme',$date.tostring())
$utc=$date.ToUniversalTime()
$bag.AddValue('UTCTime',$utc.tostring())
if($endflag -eq 0)
{
if(($utc -ge $StartTime) -and ($utc -le $EndTime))
{
$flag=1
}
}
else
{
if((($utc -ge $StartTime) -and ($utc -le $midnight)) -or (($utc -ge $Daystart) -and ($utc -le $EndTime)) )
{
$flag=1
}
}
$bag.AddValue('flag',$flag)
$bag
</ScriptBody>
<Parameters>
<Parameter>
<Name>StartTime</Name>
<Value>$Config/FilterStartTime$</Value>
</Parameter>
<Parameter>
<Name>EndTime</Name>
<Value>$Config/FilterEndTime$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>20</TimeoutSeconds>
</ProbeAction>
<ConditionDetection ID="Checkflag" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='flag']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">0</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
</MemberModules>
<Composition>
<Node ID="Checkflag">
<Node ID="Utc.TimeCaluclator">
<Node ID="Scheduler" />
</Node>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.BaseData</OutputType>
</DataSourceModuleType>
</ModuleTypes>
</TypeDefinitions>
<LanguagePacks>
<LanguagePack ID="ENU" IsDefault="true">
<DisplayStrings>
<DisplayString ElementID="UtcTime.Schedule">
<Name>UtcTime.Schedule</Name>
</DisplayString>
<DisplayString ElementID="UtcTime.Schedule.DS">
<Name>UtcTime.Schedule.DS</Name>
</DisplayString>
<DisplayString ElementID="UtcTime.Schedule.Testrule" SubElementID="DS">
<Name>UtcTime.Schedule.DS</Name>
</DisplayString>
</DisplayStrings>
</LanguagePack>
</LanguagePacks>
</ManagementPack>
How to use this model for monitoring and rules:
- Seal below MP using a certificate.
Refer link: https://technet.microsoft.com/en-us/library/hh457550(v=sc.12).aspx - Add sealed MP as a reference in MP where monitor and rule need to be created.
Refer link: https://technet.microsoft.com/en-us/library/ff719641.aspx - Use UTC time scheduler instead of System.Scheduler and System.SimpleScheduler
- Configure Start time and End Time in HH:MM time.
Use of this module:
- You can stop monitoring in given time interval.
- Enable monitoring to run UTC time than local time
- Filterstarttime and Filterendtimer can be overridden.