2017-05-05 28 views
0

我已經爲SCOM 2012 R2創建了一個MP,它應該在PowerShell中使用ssh連接到設備,獲取兩個目錄的文件和哈希列表,比較它們並返回'PASS'或'FAIL'的結果。我正在使用'ssh-sessions'模塊,從SCOM 2012 R2 Powershell腳本監視器沒有運行

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> 

回答

0

的問題是,你的監視對象是錯誤的(系統!System.NetworkDevice僅限於2007年SCOM)。對於SCOM 2012及更高版本,您應該使用System.NetworkManagement.Library中的類System.NetworkManagement.Node。

所以,你的設備監測器應該是這樣的:

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

伯努瓦