﻿<?xml version="1.0" encoding="utf-8"?><ManagementPack ContentReadable="true" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <Manifest>
    <Identity>
      <ID>Service.Monitor.MP</ID>
      <Version>1.0.0.0</Version>
    </Identity>
    <Name>Service Monitor MP</Name>
    <References>
      <Reference Alias="MicrosoftWindowsLibrary6062780">
        <ID>Microsoft.Windows.Library</ID>
        <Version>6.0.6278.0</Version>
        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
      </Reference>
      <Reference Alias="SystemLibrary6062780">
        <ID>System.Library</ID>
        <Version>6.0.6278.0</Version>
        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
      </Reference>
      <Reference Alias="SystemCenter">
        <ID>Microsoft.SystemCenter.Library</ID>
        <Version>6.0.6278.0</Version>
        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
      </Reference>
      <Reference Alias="Health">
        <ID>System.Health.Library</ID>
        <Version>6.0.6278.0</Version>
        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
      </Reference>
    </References>
  </Manifest>
  <Monitoring>
    <Monitors>
      <UnitMonitor ID="UIGeneratedMonitora49a8079ab924df1bd1def5f41cfe4a4" Accessibility="Public" Enabled="false" Target="MicrosoftWindowsLibrary6062780!Microsoft.Windows.Computer" ParentMonitorID="Health!System.Health.ConfigurationState" Remotable="true" Priority="Normal" TypeID="MicrosoftWindowsLibrary6062780!Microsoft.Windows.TimedScript.TwoStateMonitorType" ConfirmDelivery="false">
        <Category>Custom</Category>
        <AlertSettings AlertMessage="UIGeneratedMonitora49a8079ab924df1bd1def5f41cfe4a4_AlertMessageResourceID">
          <AlertOnState>Warning</AlertOnState>
          <AutoResolve>true</AutoResolve>
          <AlertPriority>Normal</AlertPriority>
          <AlertSeverity>Warning</AlertSeverity>
          <AlertParameters>
            <AlertParameter1>$Data/Context/Property[@Name='ServiceName']$</AlertParameter1>
            <AlertParameter2>$Data/Context/Property[@Name='StartMode']$</AlertParameter2>
            <AlertParameter3>$Data/Context/Property[@Name='State']$</AlertParameter3>
          </AlertParameters>
        </AlertSettings>
        <OperationalStates>
          <OperationalState ID="UIGeneratedOpStateId8226591b671d49e793d778d881c5ab7a" MonitorTypeStateID="Success" HealthState="Success" />
          <OperationalState ID="UIGeneratedOpStateId14ee3637d58744e5864974b358367fbb" MonitorTypeStateID="Error" HealthState="Warning" />
        </OperationalStates>
        <Configuration>
          <IntervalSeconds>60</IntervalSeconds>
          <SyncTime />
          <ScriptName>ServiceCheck.vbs</ScriptName>
          <Arguments>ServiceName</Arguments>
          <ScriptBody>Dim oAPI, oBag,strComputer
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()
set oArgs=wscript.arguments
strComputer="."
ServName=oArgs(0)

Set namespace=GetObject("winmgmts:\\"&amp; strComputer &amp; "\root\cimv2")
set servinfo=namespace.ExecQuery("select * from win32_service where name =" &amp; """" &amp; servname &amp; """")

for each objservice in servinfo

Call oBag.AddValue("ServiceName",ServName)
Call oBag.AddValue("State",objservice.State)
Call oBag.AddValue("StartMode",objservice.StartMode)
Call oAPI.Return(oBag)

next</ScriptBody>
          <TimeoutSeconds>60</TimeoutSeconds>
          <ErrorExpression>
            <Or>
              <Expression>
                <SimpleExpression>
                  <ValueExpression>
                    <XPathQuery Type="String">Property[@Name='State']</XPathQuery>
                  </ValueExpression>
                  <Operator>NotEqual</Operator>
                  <ValueExpression>
                    <Value Type="String">Stopped</Value>
                  </ValueExpression>
                </SimpleExpression>
              </Expression>
              <Expression>
                <SimpleExpression>
                  <ValueExpression>
                    <XPathQuery Type="String">Property[@Name='StartMode']</XPathQuery>
                  </ValueExpression>
                  <Operator>NotEqual</Operator>
                  <ValueExpression>
                    <Value Type="String">Disabled</Value>
                  </ValueExpression>
                </SimpleExpression>
              </Expression>
            </Or>
          </ErrorExpression>
          <SuccessExpression>
            <And>
              <Expression>
                <SimpleExpression>
                  <ValueExpression>
                    <XPathQuery Type="String">Property[@Name='State']</XPathQuery>
                  </ValueExpression>
                  <Operator>Equal</Operator>
                  <ValueExpression>
                    <Value Type="String">Stopped</Value>
                  </ValueExpression>
                </SimpleExpression>
              </Expression>
              <Expression>
                <SimpleExpression>
                  <ValueExpression>
                    <XPathQuery Type="String">Property[@Name='StartMode']</XPathQuery>
                  </ValueExpression>
                  <Operator>Equal</Operator>
                  <ValueExpression>
                    <Value Type="String">Disabled</Value>
                  </ValueExpression>
                </SimpleExpression>
              </Expression>
            </And>
          </SuccessExpression>
        </Configuration>
      </UnitMonitor>
      <UnitMonitor ID="UIGeneratedMonitor0110cf2cb5b748fbb80ce0d42711afb2" Accessibility="Public" Enabled="false" Target="MicrosoftWindowsLibrary6062780!Microsoft.Windows.Computer" ParentMonitorID="Health!System.Health.ConfigurationState" Remotable="true" Priority="Normal" TypeID="MicrosoftWindowsLibrary6062780!Microsoft.Windows.TimedScript.ThreeStateMonitorType" ConfirmDelivery="false">
        <Category>Custom</Category>
        <AlertSettings AlertMessage="UIGeneratedMonitor0110cf2cb5b748fbb80ce0d42711afb2_AlertMessageResourceID">
          <AlertOnState>Warning</AlertOnState>
          <AutoResolve>true</AutoResolve>
          <AlertPriority>Normal</AlertPriority>
          <AlertSeverity>MatchMonitorHealth</AlertSeverity>
          <AlertParameters>
            <AlertParameter1>$Data/Context/Property[@Name='ServiceName']$</AlertParameter1>
          </AlertParameters>
        </AlertSettings>
        <OperationalStates>
          <OperationalState ID="UIGeneratedOpStateId1fa4053f8d7345fb93294cc16f073dc0" MonitorTypeStateID="Success" HealthState="Success" />
          <OperationalState ID="UIGeneratedOpStateIdec16a6fb79244e349d6eaf29998c10da" MonitorTypeStateID="Warning" HealthState="Warning" />
          <OperationalState ID="UIGeneratedOpStateId13b430b25a1040889ae969d72c4f0749" MonitorTypeStateID="Error" HealthState="Error" />
        </OperationalStates>
        <Configuration>
          <IntervalSeconds>60</IntervalSeconds>
          <SyncTime />
          <ScriptName>ServiceMonitor.vbs</ScriptName>
          <Arguments>ServiceName</Arguments>
          <ScriptBody>Dim oAPI, oBag,strComputer
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()
set oArgs=wscript.arguments
strComputer="."
ServName=oArgs(0)

Set namespace=GetObject("winmgmts:\\"&amp; strComputer &amp; "\root\cimv2")
set servinfo=namespace.ExecQuery("select * from win32_service where name =" &amp; """" &amp; servname &amp; """")

for each objservice in servinfo

Call oBag.AddValue("ServiceName",ServName)
Call oBag.AddValue("State",objservice.State)
Call oBag.AddValue("StartMode",objservice.StartMode)
Call oAPI.Return(oBag)

next</ScriptBody>
          <TimeoutSeconds>60</TimeoutSeconds>
          <ErrorExpression>
            <SimpleExpression>
              <ValueExpression>
                <XPathQuery Type="String">Property[@Name='State']</XPathQuery>
              </ValueExpression>
              <Operator>NotEqual</Operator>
              <ValueExpression>
                <Value Type="String">Stopped</Value>
              </ValueExpression>
            </SimpleExpression>
          </ErrorExpression>
          <WarningExpression>
            <And>
              <Expression>
                <SimpleExpression>
                  <ValueExpression>
                    <XPathQuery Type="String">Property[@Name='StartMode']</XPathQuery>
                  </ValueExpression>
                  <Operator>NotEqual</Operator>
                  <ValueExpression>
                    <Value Type="String">Disabled</Value>
                  </ValueExpression>
                </SimpleExpression>
              </Expression>
              <Expression>
                <SimpleExpression>
                  <ValueExpression>
                    <XPathQuery Type="String">Property[@Name='State']</XPathQuery>
                  </ValueExpression>
                  <Operator>Equal</Operator>
                  <ValueExpression>
                    <Value Type="String">Stopped</Value>
                  </ValueExpression>
                </SimpleExpression>
              </Expression>
            </And>
          </WarningExpression>
          <SuccessExpression>
            <And>
              <Expression>
                <SimpleExpression>
                  <ValueExpression>
                    <XPathQuery Type="String">Property[@Name='StartMode']</XPathQuery>
                  </ValueExpression>
                  <Operator>Equal</Operator>
                  <ValueExpression>
                    <Value Type="String">Disabled</Value>
                  </ValueExpression>
                </SimpleExpression>
              </Expression>
              <Expression>
                <SimpleExpression>
                  <ValueExpression>
                    <XPathQuery Type="String">Property[@Name='State']</XPathQuery>
                  </ValueExpression>
                  <Operator>Equal</Operator>
                  <ValueExpression>
                    <Value Type="String">Stopped</Value>
                  </ValueExpression>
                </SimpleExpression>
              </Expression>
            </And>
          </SuccessExpression>
        </Configuration>
      </UnitMonitor>
    </Monitors>
  </Monitoring>
  <Presentation>
    <Folders>
      <Folder ID="Folder_252d9f75c0b64852b1916943277b6f29" Accessibility="Public" ParentFolder="SystemCenter!Microsoft.SystemCenter.Monitoring.ViewFolder.Root" />
    </Folders>
    <StringResources>
      <StringResource ID="UIGeneratedMonitora49a8079ab924df1bd1def5f41cfe4a4_AlertMessageResourceID" />
      <StringResource ID="UIGeneratedMonitor0110cf2cb5b748fbb80ce0d42711afb2_AlertMessageResourceID" />
    </StringResources>
  </Presentation>
  <LanguagePacks>
    <LanguagePack ID="ENU" IsDefault="false">
      <DisplayStrings>
        <DisplayString ElementID="Service.Monitor.MP">
          <Name>Service Monitor MP</Name>
          <Description>This Management Pack contains two monitors which will monitor to verify that a specified service is stopped and disabled:

Service disabled and stopped - two-state monitor:
If the specified service is not Stopped AND Disabled, the computer will be put in a Warning state and a Warning alert will be generated.  When the service is stopped and disabled, the computer will be put in a Healthy state.

Service disabled and stopped - three-state monitor:
If the specified service is not Disabled, the computer will be put in a Warning state and a Warning alert will be generated.  If the specified service is not Stopped, the computer wil be put in a critical state and a Critical alert will be generated.  When the service is stopped and disabled, the computer will be put in a Healthy state.

Usage:
Both monitors are targeted at the Windows Computer class and roll up to the Configuration Health.  Both monitors are disabled by default.  They are configured to check the service every 1 minute.

To enable one of the monitors, add an Override for the Computer or Group you wish to monitor and set the following Override parameters:

Enabled=True
Script Arguments = &lt;Service Name&gt;</Description>
        </DisplayString>
        <DisplayString ElementID="Folder_252d9f75c0b64852b1916943277b6f29">
          <Name>Service Monitor MP</Name>
        </DisplayString>
        <DisplayString ElementID="UIGeneratedMonitora49a8079ab924df1bd1def5f41cfe4a4">
          <Name>Service disabled and stopped - two-state monitor</Name>
          <Description>If the specified service is not Stopped AND Disabled, the computer will be put in a Warning state and a Warning alert will be generated.  When the service is stopped and disabled, the computer will be put in a Healthy state.

To enable, add an Override for the Computer or Group you wish to monitor and set the following Override parameters:

Enabled=True
Script Arguments = &lt;Service Name&gt;</Description>
        </DisplayString>
        <DisplayString ElementID="UIGeneratedMonitora49a8079ab924df1bd1def5f41cfe4a4" SubElementID="UIGeneratedOpStateId8226591b671d49e793d778d881c5ab7a">
          <Name>Healthy</Name>
        </DisplayString>
        <DisplayString ElementID="UIGeneratedMonitora49a8079ab924df1bd1def5f41cfe4a4" SubElementID="UIGeneratedOpStateId14ee3637d58744e5864974b358367fbb">
          <Name>Unhealthy</Name>
        </DisplayString>
        <DisplayString ElementID="UIGeneratedMonitora49a8079ab924df1bd1def5f41cfe4a4_AlertMessageResourceID">
          <Name>Service is not stopped and disabled</Name>
          <Description>{0} service is set to {1} and is currently {2}.</Description>
        </DisplayString>
        <DisplayString ElementID="UIGeneratedMonitor0110cf2cb5b748fbb80ce0d42711afb2">
          <Name>Service disabled and stopped - three-state monitor</Name>
          <Description>If the specified service is not Disabled, the computer will be put in a Warning state and a Warning alert will be generated.  If the specified service is not Stopped, the computer wil be put in a critical state and a Critical alert will be generated.  When the service is stopped and disabled, the computer will be put in a Healthy state.

To enable, add an Override for the Computer or Group you wish to monitor and set the following Override parameters:

Enabled=True
Script Arguments = &lt;Service Name&gt;</Description>
        </DisplayString>
        <DisplayString ElementID="UIGeneratedMonitor0110cf2cb5b748fbb80ce0d42711afb2" SubElementID="UIGeneratedOpStateIdec16a6fb79244e349d6eaf29998c10da">
          <Name>Degraded</Name>
        </DisplayString>
        <DisplayString ElementID="UIGeneratedMonitor0110cf2cb5b748fbb80ce0d42711afb2" SubElementID="UIGeneratedOpStateId13b430b25a1040889ae969d72c4f0749">
          <Name>Unhealthy</Name>
        </DisplayString>
        <DisplayString ElementID="UIGeneratedMonitor0110cf2cb5b748fbb80ce0d42711afb2" SubElementID="UIGeneratedOpStateId1fa4053f8d7345fb93294cc16f073dc0">
          <Name>Healthy</Name>
        </DisplayString>
        <DisplayString ElementID="UIGeneratedMonitor0110cf2cb5b748fbb80ce0d42711afb2_AlertMessageResourceID">
          <Name>Service is not disabled and stopped</Name>
          <Description>{0} service is not Disabled and Stopped.</Description>
        </DisplayString>
      </DisplayStrings>
    </LanguagePack>
  </LanguagePacks>
</ManagementPack>