Typ av övervakare för Windows Server 2012 BPA
Microsoft.Windows.Server.6.2.Monitoring.MonitorType (UnitMonitorType)
Typ av övervakare för Windows Server 2012
Element properties: Member Modules:
Overrideable Parameters:
Source Code: <UnitMonitorType ID="Microsoft.Windows.Server.6.2.Monitoring.MonitorType" Accessibility="Internal">
<MonitorTypeStates>
<MonitorTypeState ID="Healthy" NoDetection="false"/>
<MonitorTypeState ID="Warning" NoDetection="false"/>
<MonitorTypeState ID="Error" NoDetection="false"/>
</MonitorTypeStates>
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="Interval" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="Interval" Selector="$Config/Interval$" ParameterType="int"/>
</OverrideableParameters>
<MonitorImplementation>
<MemberModules>
<DataSource ID="Scheduler" TypeID="System!System.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval>$Config/Interval$</Interval>
<SyncTime/>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="PA" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagProbe">
<ScriptName>Microsoft.Windows.Server.2012.Monitoring.BPA.RunBPA.Script.ps1</ScriptName>
<ScriptBody><Script>
$ErrorActionPreference = "Stop"
# Event type constants
$EVENT_TYPE_LOG = 0
$EVENT_TYPE_ERROR = 1
$EVENT_TYPE_WARNING = 2
$EVENT_TYPE_INFORMATION = 4
# Typed property bag constants
$PROPERTY_TYPE_ALERT = 0
$PROPERTY_TYPE_EVENT = 1
$PROPERTY_TYPE_PERFORMANCE = 2
$PROPERTY_TYPE_STATE = 3
# State type constants
$STATE_SUCCESS = "Success"
$STATE_WARNING = "Warning"
$STATE_ERROR = "Error"
$momAPI = new-object -comObject MOM.ScriptAPI
# Enter condition is to have set StateProperty variable and Message variable is optional when STATE_SUCCESS
function CreateStatePropertyBag
{
param ($StateProperty = $StateProperty, $Message = $Message)
if ($StateProperty -ne $STATE_SUCCESS -and $StateProperty -ne $STATE_WARNING -and $StateProperty -ne $STATE_ERROR)
{
Write-Warning "$SCRIPT_NAME - State property is not properly defined: $StateProperty"
return
}
$StatePropertyBag = $momAPI.CreateTypedPropertyBag($PROPERTY_TYPE_STATE)
if ($StatePropertyBag -eq $null)
{
Write-Warning "$SCRIPT_NAME - Unable to create state property bag"
return
}
$StatePropertyBag.AddValue('State', $StateProperty)
Write-Verbose "$SCRIPT_NAME - added state property bag value for state $StateProperty"
if ($Message -ne $null)
{
$StatePropertyBag.AddValue('Message', $Message)
Write-Verbose "$SCRIPT_NAME - added state property bag value for message $Message"
}
# Submitting state property bag
$StatePropertyBag
Write-Host "$SCRIPT_NAME - state property bag returned"
}
function SafeImportModule
{
param ($ModuleName = $ModuleName)
$LOCAL_SYSTEM_SRC = "SafetyImportModule"
$LOCAL_SYSTEM_ID = 104
$NestedModulesMarker = "NestedModules*"
$AssemblyMarker = "dll"
$LoadedAssemblies = @()
$Module = Get-Module -ListAvailable | Where-Object {$_.Name -eq $ModuleName}
if ($Module -ne $null)
{
$NestedModulesString = cat $Module.Path | Where-object {$_ -like $NestedModulesMarker}
$AssemblyCollection = $NestedModulesString.Split((",","'"),[System.StringSplitOptions]::RemoveEmptyEntries) | Where-Object {$_.Contains($AssemblyMarker)}
foreach ($AssemblyName in $AssemblyCollection)
{
$AssemblyFullPath = Join-Path $Module.ModuleBase $AssemblyName
try
{
$Assembly = [System.Reflection.Assembly]::LoadFile($AssemblyFullPath)
Import-Module -Assembly $Assembly
$LoadedAssemblies += $Assembly.Location
}
catch [System.IO.FileLoadException]
{
$momAPI.LogScriptEvent($LOCAL_SYSTEM_SRC, $LOCAL_SYSTEM_ID, $EVENT_TYPE_ERROR, $SCRIPT_NAME + "Could not load {0}" -f $AssemblyFullPath)
exit
}
catch [System.IO.FileNotFoundException]
{
$momAPI.LogScriptEvent($LOCAL_SYSTEM_SRC, $LOCAL_SYSTEM_ID, $EVENT_TYPE_ERROR, $SCRIPT_NAME + "File {0} Not Found" -f $AssemblyFullPath)
exit
}
}
}
return $LoadedAssemblies
}
function RemoveImportedAssembly
{
param ($AssemblyName = $AssemblyName)
$Modules = Get-Module
foreach($Module in $Modules)
{
if ($Module.Path -eq $AssemblyName)
{
Remove-Module $Module
}
}
}
function Get-InstalledFeatures
{
$ModelsToRun = @()
if ((Get-WindowsFeature ADRMS).Installed) {
$ModelsToRun += "Microsoft/Windows/ADRMS"
}
if ((Get-WindowsFeature Application-Server).Installed) {
$ModelsToRun += "Microsoft/Windows/ApplicationServer"
}
if ((Get-WindowsFeature AD-Certificate).Installed) {
$ModelsToRun += "Microsoft/Windows/CertificateServices"
}
if ((Get-WindowsFeature DHCP).Installed) {
$ModelsToRun += "Microsoft/Windows/DHCPServer"
}
if ((Get-WindowsFeature AD-Domain-Services).Installed) {
$ModelsToRun += "Microsoft/Windows/DirectoryServices"
}
if ((Get-WindowsFeature DNS).Installed) {
$ModelsToRun += "Microsoft/Windows/DNSServer"
}
if ((Get-WindowsFeature File-Services).Installed) {
$ModelsToRun += "Microsoft/Windows/FileServices"
}
if ((Get-WindowsFeature Hyper-V).Installed) {
$ModelsToRun += "Microsoft/Windows/Hyper-V"
}
if ((Get-WindowsFeature ADLDS).Installed) {
$ModelsToRun += "Microsoft/Windows/LightweightDirectoryServices"
}
if ((Get-WindowsFeature MSMQ).Installed) {
$ModelsToRun += "Microsoft/Windows/MSMQ"
}
if ((Get-WindowsFeature NPAS).Installed) {
$ModelsToRun += "Microsoft/Windows/NPAS"
}
if ((Get-WindowsFeature Remote-Desktop-Services).Installed) {
$ModelsToRun += "Microsoft/Windows/TerminalServices"
}
if ((Get-WindowsFeature Web-Server).Installed) {
$ModelsToRun += "Microsoft/Windows/WebServer"
}
if ((Get-WindowsFeature OOB-WSUS).Installed) {
$ModelsToRun += "Microsoft/Windows/WSUS"
}
if ((Get-WindowsFeature UpdateServices).Installed) {
$ModelsToRun += "Microsoft/Windows/UpdateServices"
}
if ((Get-WindowsFeature VolumeActivation).Installed) {
$ModelsToRun += "Microsoft/Windows/UpdateServices"
}
return $ModelsToRun
}
$Models = Get-InstalledFeatures
$DESCRIPTION_NOMODULES = "There are no Best Practices Analyzer modules founded."
$DESCRIPTION_WARNING = "Best Practices Analyzer compliance verification was complete successfully with {0} warnings and {1} errors."
$DESCRIPTION_ERROR = "Best Practices Analyzer can't complete compiance verification."
$ModuleName = "BestPractices"
$ImportedAssemblies = SafeImportModule($ModuleName)
$State = $STATE_SUCCESS
$WarningRulesCount = 0
$ErrorRulesCount = 0
$Description = $DESCRIPTION_NOMODULES
if ($Models -ne $null -and $Models.Count -ne 0)
{
try
{
$Details = $Models | Invoke-BPAModel
foreach ($Detail in $Details)
{
If ($State -ne $STATE_ERROR)
{
if (-not $Detail.Success)
{
$State = $STATE_ERROR
$Description = $DESCRIPTION_ERROR
}
elseif (($Detail.Detail.WarningMessages -ne 0) -or ($Detail.Detail.ErrorMessages -ne 0))
{
$State = $STATE_WARNING
$WarningRulesCount += $Detail.Detail.WarningMessages
$ErrorRulesCount += $Detail.Detail.ErrorMessages
}
}
}
If ($State -eq $STATE_WARNING)
{
$Description = $DESCRIPTION_WARNING -f $WarningRulesCount, $ErrorRulesCount
}
}
catch [System.Exception]
{
$Description = $_.ToString()
$State = $STATE_ERROR
}
finally
{
foreach ($ImportedAssembly in $ImportedAssemblies)
{
RemoveImportedAssembly($ImportedAssembly)
}
CreateStatePropertyBag -StateProperty $State -Message $Description
}
}
</Script> </ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</ProbeAction>
<ProbeAction ID="PassThrough" TypeID="System!System.PassThroughProbe"/>
<ConditionDetection ID="FilterHealthy" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='State']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">Success</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
<ConditionDetection ID="FilterWarning" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='State']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">Warning</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
<ConditionDetection ID="FilterError" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='State']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">Error</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
</MemberModules>
<RegularDetections>
<RegularDetection MonitorTypeStateID="Healthy">
<Node ID="FilterHealthy">
<Node ID="PA">
<Node ID="Scheduler"/>
</Node>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="Warning">
<Node ID="FilterWarning">
<Node ID="PA">
<Node ID="Scheduler"/>
</Node>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="Error">
<Node ID="FilterError">
<Node ID="PA">
<Node ID="Scheduler"/>
</Node>
</Node>
</RegularDetection>
</RegularDetections>
<OnDemandDetections>
<OnDemandDetection MonitorTypeStateID="Healthy">
<Node ID="FilterHealthy">
<Node ID="PA">
<Node ID="PassThrough"/>
</Node>
</Node>
</OnDemandDetection>
<OnDemandDetection MonitorTypeStateID="Warning">
<Node ID="FilterWarning">
<Node ID="PA">
<Node ID="PassThrough"/>
</Node>
</Node>
</OnDemandDetection>
<OnDemandDetection MonitorTypeStateID="Error">
<Node ID="FilterError">
<Node ID="PA">
<Node ID="PassThrough"/>
</Node>
</Node>
</OnDemandDetection>
</OnDemandDetections>
</MonitorImplementation>
</UnitMonitorType>