New MPToolPSStateMonitor - AndreasSobczyk/MPTool GitHub Wiki
#New-MPToolPSStateMonitor Creates SCOM PowerShell three state monitor for availability State. The monitor will get create auto resolving alerts that match monitor health. The alert message can be definded in the script using $scomMessage variable. Returns object of type [Microsoft.EnterpriseManagement.Configuration.ManagementPackUnitMonitorType]
###Parameters
- ManagementServerFQDN [string] – FQDN of the management server to connect.
Example - "scomms01.contoso.com" - ManagementPackName [string] – Name of the management pack.
Example - "Contoso.VMSwitch.Monitoring” - MonitorName [string] – Name of the monitor.
Example - "Contoso.VMSwitch.Monitor” - MonitorDisplayName [string] – (Optional) Display name of the monitor.
Example - "Contoso VMSwitch Monitor” - MonitorDescription [string] – (Optional) Description of the monitor.
Example - " Monitor for VM compliance in vmm logical switches” - TargetClassName [string] – Name of the target class.
Example - "Contoso.SCVMM.VMSwitch” - TargetClassMPName [string] – (Optional) Name of the management pack for the target class.
Example – “Contoso.SCVMM.Discovery” - TargetClassMPAlias [string] –(Optional) Alias for the management pack for the target class.
Example – “ContosoVMMDiscovery” - IntervalSeconds [int] – Monitor interval.
Example - 86000 - TimeoutSeconds [int] – Script Timeout.
Example - 45 - Script [string] – PowerShell script for the monitor. This script must create a string variable called $scomState with the monitor string value, options is OK, WARNING or, ERROR. A secondary string variable name $scomMessage can be used to return alert messages.
Example -
@'Get-SCVMMServer $env:COMPUTERNAME | Out-Null
$Status = get-scvirtualnetwork | ? {($_.Name -eq $Switchname) -and ($_.VMhost.ToString() -eq $VMHost)}
if ($Status.LogicalSwitchComplianceStatus -eq "Compliant")
{
$scomState = "OK";
}
else
{
$scomState = "ERROR";
}
$scomMessage = $SwitchName + " Status: " + $Status.LogicalSwitchComplianceStatus;
'@
- ScriptParameters [array] – (Optional) Script input parameters is used to get property values from the target class or the target class’s host. The parameters name must match a property on the target class or it’s host.
Example - @("Switchname","VMHost") - Enabled [boolean] – (Optional) Enabled setting for the monitor $true / $false. Default is $false
###Example Creates a powershell state monitor for the target class "Contoso.SCVMM.VMSwitch" in the management pack "Contoso.VMSwitch.Monitoring". The Monitor will check the Logical Switch Compliance Status for the instance of the target class. If not compliant and alert is created with critical severity
New-MPToolPSStateMonitor -ManagementServerFQDN scom01.contoso.com `
-ManagementPackName "Contoso.VMSwitch.Monitoring" `
-MonitorName "Contoso.VMSwitch.Monitor" `
-TargetClassName "Contoso.SCVMM.VMSwitch" `
-IntervalSeconds 86000 `
-TimeoutSeconds 45 `
-Script @'
Get-SCVMMServer $env:COMPUTERNAME | Out-Null
$Status = get-scvirtualnetwork | ? {($_.Name -eq $Switchname) -and ($_.VMhost.ToString() -eq $VMHost)}
if ($Status.LogicalSwitchComplianceStatus -eq "Compliant")
{
$scomState = "OK";
}
else
{
$scomState = "ERROR";
}
$scomMessage = $SwitchName + " Status: " + $Status.LogicalSwitchComplianceStatus;
'@ `
-ScriptParameters @("Switchname","VMHost") `
-Enabled $true