Тип базового монитора доступности сервера VMM с помощью Powershell 2.0 (System Center 2016 Virtual Machine Manager)

Microsoft.SystemCenter.VirtualMachineManager.2016.VMMServerReachableUnitMonitorType (UnitMonitorType)

Этот тип монитора позволяет определить включение и доступность удаленного взаимодействия PowerShell 2.0 на сервере управления VMM

Element properties:

RunAsDefault
AccessibilityInternal
Support Monitor RecalculateFalse

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.Scheduler Default
Probe ProbeAction Microsoft.SystemCenter.VirtualMachineManager.2016.PowerShellProbeActionModuleType Default
CDOnCritical ConditionDetection System.ExpressionFilter Default
CDOnhealthy ConditionDetection System.ExpressionFilter Default

Overrideable Parameters:

IDParameterTypeSelector
VMMServerstring$Config/VMMServer$
IntervalSecondsint$Config/IntervalSeconds$
TimeoutSecondsint$Config/TimeoutSeconds$

Source Code:

<UnitMonitorType ID="Microsoft.SystemCenter.VirtualMachineManager.2016.VMMServerReachableUnitMonitorType" Accessibility="Internal">
<MonitorTypeStates>
<MonitorTypeState ID="VMMServerReachable" NoDetection="false"/>
<MonitorTypeState ID="VMMServerNotReachable" NoDetection="false"/>
</MonitorTypeStates>
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="VMMServer" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="VMMServer" Selector="$Config/VMMServer$" ParameterType="string"/>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<MonitorImplementation>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval>$Config/IntervalSeconds$</Interval>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="Probe" TypeID="Microsoft.SystemCenter.VirtualMachineManager.2016.PowerShellProbeActionModuleType">
<Parameters>
<Parameter>
<Name>VMMServer</Name>
<Value>$Config/VMMServer$</Value>
</Parameter>
<Parameter>
<Name>domain</Name>
<Value>$RunAs[Name="PROV2Library!Microsoft.SystemCenter.VirtualMachineManager.2012.VMMServerConnectionRunAsProfile"]/Domain$</Value>
</Parameter>
<Parameter>
<Name>username</Name>
<Value>$RunAs[Name="PROV2Library!Microsoft.SystemCenter.VirtualMachineManager.2012.VMMServerConnectionRunAsProfile"]/UserName$</Value>
</Parameter>
<Parameter>
<Name>pass</Name>
<Value>$RunAs[Name="PROV2Library!Microsoft.SystemCenter.VirtualMachineManager.2012.VMMServerConnectionRunAsProfile"]/Password$</Value>
</Parameter>
</Parameters>
<ScriptBody><Script>param($VMMServer, $domain, $username, $pass)
$session = $null;
Try
{

$oAPI = New-Object -comObject 'MOM.ScriptAPI'
$pBag = $oAPI.CreatePropertyBag()

$evt = New-Object System.Diagnostics.Eventlog("Application");
$evt.Source = "VMM.2016.ServerReachability";
$errorevent = [System.Diagnostics.EventLogEntryType]::Error;
$infoevent = [System.Diagnostics.EventLogEntryType]::Information;

$evt.WriteEntry("VMMServer Reachable Monitor VMMServer is:" + $VMMServer, $infoevent, 25931);

$error.Clear();

$cred = $null;
if ($domain -AND $username -AND $pass)
{
#Append domain to get domain\username
$domainUser = $domain + "\" + $username;

#Create Cred object
$securePass = ConvertTo-SecureString -AsPlainText $pass -force
$cred = New-Object System.Management.Automation.PSCredential $domainUser, $securePass;
}

# return VMMServerName for AlertMessage DisplayString
$pBag.AddValue('VMMServerName', $VMMServer)

####### Remote Session
if ($cred -ne $null)
{
$session = New-PSSession -ComputerName $VMMServer -Authentication Default -Credential $cred;
if ($error.Count -ne 0)
{
$evt.WriteEntry($error, $errorevent, 25931);
$pBag.AddValue('VMMServer Connection', 'NotReachable')
}
else
{
$vmm = $null;
$vmm = Invoke-Command -Session $session -ArgumentList $VMMServer -ScriptBlock {
$modulePath = get-itemproperty -path "hklm:\software\microsoft\microsoft system center virtual machine manager administrator console\Setup";
Import-Module ($modulePath.InstallPath + "bin\psModules\virtualmachinemanagercore\virtualmachinemanagercore.psd1");
$vmmServer = Get-SCVMMServer -ComputerName $args[0];
$vmmServer } ;

if ($error.Count -ne 0)
{
$evt.WriteEntry($error, $errorevent, 25932);
$pBag.AddValue('VMMServer Connection', 'NotReachable')
}
else
{
if ($vmm -ne $null)
{
$pBag.AddValue('VMMServer Connection', 'Reachable')
}
else
{
$pBag.AddValue('VMMServer Connection', 'NotReachable')
}
}
}
}
else
{
$pBag.AddValue('VMMServer Connection', 'NotReachable')
}

$pBag
}
Finally
{
if ($session -ne $null)
{
$vmm = Invoke-Command -Session $session -ScriptBlock {
if ($vmmServer -ne $null)
{
$vmmServer.Disconnect();
}
};
Remove-PSSession $session;
}
}</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
<ConditionDetection ID="CDOnhealthy" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='VMMServer Connection']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">Reachable</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
<ConditionDetection ID="CDOnCritical" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='VMMServer Connection']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">NotReachable</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
</MemberModules>
<RegularDetections>
<RegularDetection MonitorTypeStateID="VMMServerReachable">
<Node ID="CDOnhealthy">
<Node ID="Probe">
<Node ID="DS"/>
</Node>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="VMMServerNotReachable">
<Node ID="CDOnCritical">
<Node ID="Probe">
<Node ID="DS"/>
</Node>
</Node>
</RegularDetection>
</RegularDetections>
</MonitorImplementation>
</UnitMonitorType>