0

我为 SCOM 2012 R2 创建了一个 MP,它应该在 powershell 中使用 ssh 连接到设备,获取两个目录的文件和哈希列表,比较它们,并返回“通过”或“失败”的结果。我正在使用来自的 'ssh-sessions' 模块

http://www.powershelladmin.com/wiki/SSH_from_PowerShell_using_the_SSH.NET_library

基本管理包来自

https://gallery.technet.microsoft.com/Sample-Management-Pack-17b76379

如果我从管理服务器手动运行脚本,它工作正常,但如果我把它放在 MP 中,并观察我的设备是否有传入的 SSH 连接,什么都不会发生。我试过直接指定设备的名称,以及传入$Target/Property[Type="System!System.Entity"]/DisplayName$,但似乎都不起作用。我不知道为什么 SCOM 没有启动脚本。

MP Xml 下面。

TIA

    <?xml version="1.0" encoding="utf-16"?><ManagementPack xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ContentReadable="true" SchemaVersion="2.0" OriginalSchemaVersion="1.0" RevisionId="f9713a18-16ab-43ce-872e-41e6493ee5a7">
  <Manifest>
    <Identity>
      <ID>Sample.Powershell.Monitor.Type.MP.v2</ID>
      <Version>1.0.1.19</Version>
    </Identity>
    <Name>Sample.Powershell.Monitor.Type.MP.v2</Name>
    <References>
      <Reference Alias="NetworkManagement">
        <ID>System.NetworkManagement.Library</ID>
        <Version>7.1.10226.0</Version>
        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
      </Reference>
      <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.8433.0</Version>
        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
      </Reference>
      <Reference Alias="Health">
        <ID>System.Health.Library</ID>
        <Version>7.0.8433.0</Version>
        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
      </Reference>
    </References>
  </Manifest>
  <TypeDefinitions>
    <ModuleTypes>
      <DataSourceModuleType ID="Wei.Out.There.TimedPowershell.v2.PropertyBagProvider" Accessibility="Public" Batching="false">
        <Configuration><xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IntervalSeconds" type="xsd:integer" /><xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="SyncTime" type="xsd:string" /><xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer" /><xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ScriptName" type="xsd:string" /><xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ScriptBody" type="xsd:string" /><xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="0" name="Arguments" type="xsd:string" /></Configuration>
        <OverrideableParameters>
          <OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int" />
          <OverrideableParameter ID="SyncTime" Selector="$Config/SyncTime$" ParameterType="string" />
          <OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int" />
          <OverrideableParameter ID="Arguments" Selector="$Config/Arguments$" 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="PSProbe" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe"><ScriptName>$Config/ScriptName$</ScriptName><ScriptBody>$Config/ScriptBody$</ScriptBody><Parameters><Parameter><Name>Arguments</Name><Value>$Config/Arguments$</Value></Parameter></Parameters><TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds></ProbeAction>
            </MemberModules>
            <Composition>
              <Node ID="PSProbe">
                <Node ID="Scheduler" />
              </Node>
            </Composition>
          </Composite>
        </ModuleImplementation>
        <OutputType>System!System.PropertyBagData</OutputType>
      </DataSourceModuleType>
    </ModuleTypes>
    <MonitorTypes>
      <UnitMonitorType ID="Wei.Out.There.TimedPowershell.v2.TwoStateMonitorType" Accessibility="Public">
        <MonitorTypeStates>
          <MonitorTypeState ID="Error" NoDetection="false" />
          <MonitorTypeState ID="Success" NoDetection="false" />
        </MonitorTypeStates>
        <Configuration>
          <IncludeSchemaTypes>
            <SchemaType>System!System.ExpressionEvaluatorSchema</SchemaType>
          </IncludeSchemaTypes><xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IntervalSeconds" type="xsd:integer" /><xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="SyncTime" type="xsd:string" /><xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer" /><xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ScriptName" type="xsd:string" /><xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="0" name="Arguments" type="xsd:string" /><xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ScriptBody" type="xsd:string" /><xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ErrorExpression" type="ExpressionType" /><xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="SuccessExpression" type="ExpressionType" /></Configuration>
        <OverrideableParameters>
          <OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int" />
          <OverrideableParameter ID="SyncTime" Selector="$Config/SyncTime$" ParameterType="string" />
          <OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int" />
          <OverrideableParameter ID="Arguments" Selector="$Config/Arguments$" ParameterType="string" />
        </OverrideableParameters>
        <MonitorImplementation>
          <MemberModules>
            <DataSource ID="Datasource" TypeID="Wei.Out.There.TimedPowershell.v2.PropertyBagProvider"><IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds><SyncTime>$Config/SyncTime$</SyncTime><TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds><ScriptName>$Config/ScriptName$</ScriptName><ScriptBody>$Config/ScriptBody$</ScriptBody><Arguments>$Config/Arguments$</Arguments></DataSource>
            <ConditionDetection ID="ErrorFilter" TypeID="System!System.ExpressionFilter"><Expression>$Config/ErrorExpression$</Expression></ConditionDetection>
            <ConditionDetection ID="SuccessFilter" TypeID="System!System.ExpressionFilter"><Expression>$Config/SuccessExpression$</Expression></ConditionDetection>
          </MemberModules>
          <RegularDetections>
            <RegularDetection MonitorTypeStateID="Error">
              <Node ID="ErrorFilter">
                <Node ID="Datasource" />
              </Node>
            </RegularDetection>
            <RegularDetection MonitorTypeStateID="Success">
              <Node ID="SuccessFilter">
                <Node ID="Datasource" />
              </Node>
            </RegularDetection>
          </RegularDetections>
        </MonitorImplementation>
      </UnitMonitorType>
    </MonitorTypes>
  </TypeDefinitions>
  <Monitoring>
    <Monitors>
      <UnitMonitor ID="UIGeneratedMonitor6114f31ea0204cebb73ba690f5b7bf76" Accessibility="Public" Enabled="false" Target="System!System.NetworkDevice" ParentMonitorID="Health!System.Health.AvailabilityState" Remotable="true" Priority="Normal" TypeID="Wei.Out.There.TimedPowershell.v2.TwoStateMonitorType" ConfirmDelivery="false">
        <Category>Custom</Category>
        <AlertSettings AlertMessage="UIGeneratedMonitor6114f31ea0204cebb73ba690f5b7bf76_AlertMessageResourceID">
          <AlertOnState>Error</AlertOnState>
          <AutoResolve>true</AutoResolve>
          <AlertPriority>Normal</AlertPriority>
          <AlertSeverity>Error</AlertSeverity>
        </AlertSettings>
        <OperationalStates>
          <OperationalState ID="UIGeneratedOpStateIdead1cc99f95d42dfb032788f9c21c73d" MonitorTypeStateID="Success" HealthState="Success" />
          <OperationalState ID="UIGeneratedOpStateIdbf37121688a540c3894e6bcfd1cb4264" MonitorTypeStateID="Error" HealthState="Error" />
        </OperationalStates>
        <Configuration><IntervalSeconds>600</IntervalSeconds>
<SyncTime></SyncTime>
<TimeoutSeconds>60</TimeoutSeconds>
<ScriptName>test.ps1</ScriptName>
<Arguments>pitest.utwn.net</Arguments>
<ScriptBody>param([string]$CompName)
$OMModuleName = "ssh-sessions"
$OMPowerShellKey = "HKLM:\SOFTWARE\Microsoft\System Center Operations Manager\12\Setup\Powershell\V2" #Valid for OM12 and OM16
$OMModulePath = Join-Path (Get-ItemProperty $OMPowerShellKey).InstallDirectory $OMModuleName
Import-Module $OMModulePath

# load ssh module
#import-module ssh-sessions

# set up api to report back to scom

$API = new-object -comObject 'MOM.ScriptAPI'

$Bag = $API.CreatePropertyBag()

#set up connection to test pi

new-sshsession -ComputerName $CompName -Username x -Password y

# get list of files in /tmp, /pictures

$tmp = Invoke-SshCommand -InvokeOnAll -Command 'cd /storage/tmp && md5sum *.*' | sort-object
$pictures = Invoke-SshCommand -InvokeOnAll -Command 'cd /storage/pictures && md5sum *.*' | sort-object

#compare arrays of filenames , hashes

$diff=$null
$diff = compare-object -ReferenceObject $tmp -DifferenceObject $pictures

if ($diff -eq $null)
{
   $Bag.addvalue("State","PASS")

}

else
{

  $Bag.addvalue("State","FAIL")
}

$Bag
start-sleep 30
Remove-SshSession -RemoveAll
</ScriptBody>
<ErrorExpression>
  <SimpleExpression>
    <ValueExpression>
      <XPathQuery Type="String">Property[@Name='State']</XPathQuery>
    </ValueExpression>
    <Operator>Equal</Operator>
    <ValueExpression>
      <Value Type="String">FAIL</Value>
    </ValueExpression>
  </SimpleExpression>
</ErrorExpression>
<SuccessExpression>
  <SimpleExpression>
    <ValueExpression>
      <XPathQuery Type="String">Property[@Name='State']</XPathQuery>
    </ValueExpression>
    <Operator>Equal</Operator>
    <ValueExpression>
      <Value Type="String">PASS</Value>
    </ValueExpression>
  </SimpleExpression>
</SuccessExpression></Configuration>
      </UnitMonitor>
    </Monitors>
    <Overrides>
      <MonitorPropertyOverride ID="OverrideForMonitorUIGeneratedMonitor6114f31ea0204cebb73ba690f5b7bf76ForContextSystemNetworkManagementNodebddcd850a7db460a9172482041b68d05" Context="NetworkManagement!System.NetworkManagement.Node" ContextInstance="5f349164-9db8-5740-ccc7-0ce05af95612" Enforced="false" Monitor="UIGeneratedMonitor6114f31ea0204cebb73ba690f5b7bf76" Property="Enabled">
        <Value>true</Value>
      </MonitorPropertyOverride>
    </Overrides>
  </Monitoring>
</ManagementPack>
4

1 回答 1

0

问题是您的 Monitor Target 错误(System!System.NetworkDevice 仅限于 SCOM 2007)。对于 SCOM 2012 及更高版本,您应该使用 System.NetworkManagement.Library 中的 System.NetworkManagement.Node 类。

所以你的单元监视器应该是这样的:

<Monitoring>
<Monitors>
  <UnitMonitor ID="UIGeneratedMonitor6114f31ea0204cebb73ba690f5b7bf76" Accessibility="Public" Enabled="false" Target="NetworkManagement!System.NetworkManagement.Node" ...

贝努瓦

于 2017-06-28T20:05:51.750 回答