Monitortyp "Agentversion"
Microsoft.SystemCenter.Agent.Configuration.MinRequiredVersionCheckMonitorType (UnitMonitorType)
Mit diesem Monitortyp wird die Agentversion überprüft und eine Warnung generiert, wenn die Version eines Agents niedriger als die bereitgestellte Mindestversion ist.
Element properties: Member Modules:
Overrideable Parameters:
Source Code: <UnitMonitorType ID="Microsoft.SystemCenter.Agent.Configuration.MinRequiredVersionCheckMonitorType" Accessibility="Internal">
<MonitorTypeStates>
<MonitorTypeState ID="UpgradeNotRequired" NoDetection="false"/>
<MonitorTypeState ID="UpgradeRequired" NoDetection="false"/>
</MonitorTypeStates>
<Configuration>
<xsd:element minOccurs="1" maxOccurs="1" name="RequiredVersion" type="xsd:string"/>
<xsd:element minOccurs="1" maxOccurs="1" name="ComputerName" type="xsd:string"/>
<xsd:element minOccurs="1" maxOccurs="1" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element minOccurs="1" maxOccurs="1" name="TimeoutSeconds" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="RequiredVersion" Selector="$Config/RequiredVersion$" ParameterType="string"/>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<MonitorImplementation>
<MemberModules>
<DataSource ID="SchedulerDS" TypeID="System!System.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval>$Config/IntervalSeconds$</Interval>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="ScriptProbe" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagProbe">
<ScriptName>AgentMinRequiredVersionCheck.ps1</ScriptName>
<ScriptBody><Script>
Param($ComputerName, $RequiredVersion)
#Event log variables
$SCRIPT_EVENT_ID = 3000
$CN_SCOM_SUCCESS = 0
$CN_SCOM_ERROR = 1
$CN_SCOM_WARNING = 2
$CN_SCOM_INFORMATION = 4
$oAPI = New-Object -ComObject "MOM.ScriptAPI"
$key = "hklm:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup\"
$agentVersion = Get-ItemProperty $key -ErrorAction SilentlyContinue | Get-ItemProperty
$agentVersion = $agentVersion.AgentVersion
if($agentVersion -eq $null)
{
$key = "hklm:\Wow6432Node\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup\"
$agentVersion = Get-ItemProperty $key -ErrorAction SilentlyContinue | Get-ItemProperty
$agentVersion = $agentVersion.AgentVersion
if($agentVersion -eq $null)
{
$key = "hklm:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup\"
$agentVersion = Get-ItemProperty $key -ErrorAction SilentlyContinue | Get-ItemProperty
$agentVersion = $agentVersion.ServerVersion
if($agentVersion -eq $null)
{
$message = $("An error occurred while reading the registry: " + $key + "ServerVersion")
$oAPI.LogScriptEvent("AgentMinRequiredVersionCheck.ps1", $SCRIPT_EVENT_ID, $CN_SCOM_ERROR, $message)
}
}
}
if($agentVersion -ne $null -and $agentVersion -ne "")
{
$oPropertyBag = $oAPI.CreatePropertyBag()
if($oPropertyBag -ne $null)
{
$agentVersionParts = $agentVersion.Split(".")
$requiredVersionParts = $RequiredVersion.Split(".")
$agentVersionLength = $agentVersionParts.Count
$requiredVersionLength = $requiredVersionParts.Count
if($requiredVersionLength -lt $agentVersionLength)
{
$RequiredVersion = CompleteVersionString $RequiredVersion, $agentVersionLength - $requiredVersionLength
$requiredVersionParts = $RequiredVersion.Split(".")
}
elseIf($requiredVersionLength -gt $agentVersionLength)
{
$agentVersion = CompleteVersionString $agentVersion, $requiredVersionLength - $agentVersionLength
$agentVersionParts = $agentVersion.Split(".")
}
$agentVersionLength = $agentVersionParts.Count
$requiresUpgrade = $false
for($i=0;$i -lt $agentVersionLength;$i++)
{
$agentPart = [int]$agentVersionParts[$i]
if($agentPart -eq $null)
{
$agentPart = 0
}
$requiredPart = [int]$requiredVersionParts[$i]
if($requiredPart -eq $null)
{
$requiredPart = 0
}
if($agentPart -lt $requiredPart)
{
# Requires upgrade
$requiresUpgrade = $true
break
}
elseif($agentPart -gt $requiredPart)
{
# Does not require upgrade
break
}
}
# exit with property bag
$oPropertyBag.AddValue("UpgradeRequired", $requiresUpgrade)
$oPropertyBag.AddValue("CurrentVersion", $agentVersion)
$oPropertyBag.AddValue("RequiredVersion", $RequiredVersion)
$oPropertyBag
}
else
{
$message = "Unable to create propertybag in script."
$oAPI.LogScriptEvent("AgentMinRequiredVersionCheck.ps1", $SCRIPT_EVENT_ID, $CN_SCOM_ERROR, $message)
}
}
else
{
$message = "Agent Version not found in Registry."
$oAPI.LogScriptEvent("AgentMinRequiredVersionCheck.ps1", $SCRIPT_EVENT_ID, $CN_SCOM_ERROR, $message)
}
</Script> </ScriptBody>
<Parameters>
<Parameter>
<Name>ComputerName</Name>
<Value>$Config/ComputerName$</Value>
</Parameter>
<Parameter>
<Name>RequiredVersion</Name>
<Value>$Config/RequiredVersion$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
<ProbeAction ID="PassThrough" TypeID="System!System.PassThroughProbe"/>
<ConditionDetection ID="FilterUpgradeRequired" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Boolean">//DataItem/Property[@Name="UpgradeRequired"]</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Boolean">true</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
<ConditionDetection ID="FilterUpgradeNotRequired" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Boolean">//DataItem/Property[@Name="UpgradeRequired"]</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Boolean">false</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
</MemberModules>
<RegularDetections>
<RegularDetection MonitorTypeStateID="UpgradeNotRequired">
<Node ID="FilterUpgradeNotRequired">
<Node ID="ScriptProbe">
<Node ID="SchedulerDS"/>
</Node>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="UpgradeRequired">
<Node ID="FilterUpgradeRequired">
<Node ID="ScriptProbe">
<Node ID="SchedulerDS"/>
</Node>
</Node>
</RegularDetection>
</RegularDetections>
<OnDemandDetections>
<OnDemandDetection MonitorTypeStateID="UpgradeNotRequired">
<Node ID="FilterUpgradeNotRequired">
<Node ID="ScriptProbe">
<Node ID="PassThrough"/>
</Node>
</Node>
</OnDemandDetection>
<OnDemandDetection MonitorTypeStateID="UpgradeRequired">
<Node ID="FilterUpgradeRequired">
<Node ID="ScriptProbe">
<Node ID="PassThrough"/>
</Node>
</Node>
</OnDemandDetection>
</OnDemandDetections>
</MonitorImplementation>
</UnitMonitorType>