[英]SCOM 2012 R2 Powershell script monitor not running
I've created a MP for SCOM 2012 R2 that is supposed to connect to a device using ssh in powershell, get a list of files and hashes for two directories, compare them, and return a result of 'PASS' or 'FAIL'. 我为SCOM 2012 R2创建了一个MP,该MP应该在powershell中使用ssh连接到设备,获取两个目录的文件和哈希列表,进行比较,并返回“ PASS”或“ FAIL”的结果。 I'm using the 'ssh-sessions' module from 我正在使用来自的``ssh-sessions''模块
http://www.powershelladmin.com/wiki/SSH_from_PowerShell_using_the_SSH.NET_library . http://www.powershelladmin.com/wiki/SSH_from_PowerShell_using_the_SSH.NET_library 。
The base management pack is from 基本管理包来自
https://gallery.technet.microsoft.com/Sample-Management-Pack-17b76379 . https://gallery.technet.microsoft.com/Sample-Management-Pack-17b76379 。
If I manually run the script from the management server, it works fine, but if I put it in the MP, and watch my device for an incoming SSH connection, nothing happens. 如果我从管理服务器手动运行该脚本,则可以正常运行,但是如果将其放入MP中,并监视我的设备是否有传入的SSH连接,则什么都不会发生。 I've tried directly specifying the device's name, as well as passing in $Target/Property[Type="System!System.Entity"]/DisplayName$
, but neither seems to work. 我已经尝试过直接指定设备的名称,以及传递$Target/Property[Type="System!System.Entity"]/DisplayName$
,但似乎都不起作用。 I'm stuck as to why SCOM isn't launching the script. 我对SCOM不启动脚本的原因感到困惑。
MP Xml below. 下面的MP Xml。
TIA 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>
The problem is that your Monitor Target is wrong (the System!System.NetworkDevice is limited to SCOM 2007). 问题是您的Monitor Target错误(System!System.NetworkDevice限于SCOM 2007)。 For SCOM 2012 and up, you should use the class System.NetworkManagement.Node from the System.NetworkManagement.Library. 对于SCOM 2012及更高版本,应使用System.NetworkManagement.Library中的类System.NetworkManagement.Node。
So your Unit Monitor should look like this: 因此,您的单元监视器应如下所示:
<Monitoring>
<Monitors>
<UnitMonitor ID="UIGeneratedMonitor6114f31ea0204cebb73ba690f5b7bf76" Accessibility="Public" Enabled="false" Target="NetworkManagement!System.NetworkManagement.Node" ...
Benoit 伯努瓦
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.