SPServer 上の SPHA 結果に関するモニターの種類

Microsoft.SharePoint.Foundation.2010.MonitorType.SPHARule.SPServer (UnitMonitorType)

3 段階の状態をとる、SPServer 上の SPHARule 監視に関するモニターの種類です。

Element properties:

RunAsMicrosoft.SharePoint.Foundation.2010.AdminAccount
AccessibilityPublic
Support Monitor RecalculateTrue

Member Modules:

ID Module Type TypeId RunAs 
DataSource DataSource Microsoft.SharePoint.Foundation.2010.TimedScript.FilteredPropertyBagProvider Default
ErrorFilter ConditionDetection System.ExpressionFilter Default
SuccessFilter ConditionDetection System.ExpressionFilter Default
WarningFilter ConditionDetection System.ExpressionFilter Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$IntervalSecondsこのモニターを実行する間隔 (秒) を表します。リソースの競合によるモニターの失敗を防げる程度に長い間隔を設定する必要があります。
SyncTimestring$Config/SyncTime$SyncTimeSPServer SPHARule の SyncTime (開始時刻) プロパティです。SyncTime は "HH:mm" の形式を持つ文字列値です。特定のワークフローの正確な実行時刻は、SyncTime、IntervalSeconds、および管理パック インポート時刻の 3 つを組み合わせて決定されます。たとえば、IntervalSeconds = 21600 (6 時間)、SyncTime = "01:15" の場合、当該ワークフローは午前 1:15、午前 7:15、午後 1:15、午後 7:15 に実行される可能性があります。午前 1:15 から午前 7:15 の間に管理パックがインポートされると、ワークフローは午前 7:15 に開始されます。また、午後 1:15 から午後 7:15 の間に管理パックがインポートされると、ワークフローは午後 7:15 に開始されます。ただし、実際の開始時刻はネットワークの遅延など他の要因によって変動することがあります。
TimeoutSecondsint$Config/TimeoutSeconds$TimeoutSeconds監視処理 1 回ごとの実行時間に関するタイムアウト値 (秒) です。必要なオブジェクトのモニター状態更新が完了する程度に長く、IntervalSeconds より短いタイムアウト値を設定する必要があります。
DebugTracebool$Config/DebugTrace$DebugTraceSPServer の SharePoint Health Analyzer (SPHA) モニターの DebugTrace プロパティです。この値が true に設定されている場合、このモジュールは Windows イベント ログにデバッグ トレースを書き込みます。

Source Code:

<UnitMonitorType ID="Microsoft.SharePoint.Foundation.2010.MonitorType.SPHARule.SPServer" Accessibility="Public" RunAs="Microsoft.SharePoint.Foundation.2010.AdminAccount">
<MonitorTypeStates>
<MonitorTypeState ID="Error" NoDetection="false"/>
<MonitorTypeState ID="Warning" NoDetection="false"/>
<MonitorTypeState ID="Success" NoDetection="false"/>
</MonitorTypeStates>
<Configuration>
<xsd:element name="Category" type="xsd:string"/>
<xsd:element name="IntervalSeconds" type="xsd:integer"/>
<xsd:element name="SyncTime" type="xsd:string"/>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element name="DebugTrace" type="xsd:boolean"/>
<xsd:element name="FilterValue" 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="DebugTrace" Selector="$Config/DebugTrace$" ParameterType="bool"/>
</OverrideableParameters>
<MonitorImplementation>
<MemberModules>
<DataSource ID="DataSource" TypeID="Microsoft.SharePoint.Foundation.2010.TimedScript.FilteredPropertyBagProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime>$Config/SyncTime$</SyncTime>
<ScriptName>WSSBPAMonitorSPServer.ps1</ScriptName>
<Arguments>$Target/Property[Type="Microsoft.SharePoint.Foundation.2010.SPServer"]/ComputerID$</Arguments>
<ScriptBody><Script>$error.Clear()
$ErrorActionPreference = "SilentlyContinue"

$global:EventObject = New-Object Diagnostics.EventLog
$global:EventObject.Source = "Operations Manager"

function global:Write-Event ([string] $LogContent, $LogType = [Diagnostics.EventLogEntryType]::Information)
{
if ($error)
{
$error.Clear()
$LogType = [Diagnostics.EventLogEntryType]::Error
}

$EventObject.WriteEntry($LogContent, $LogType)
}

function global:LogScriptTime($InvocationObj)
{
$dtEnd = [DateTime]::Now

$msg = @"
[Debug] {0} ended.
Current User: {1}
Current PID: {2}
start time: {3}
stop time: {4}
time taken: {5}
"@ -f $InvocationObj.MyCommand,
[Environment]::UserName,
$pid,
$dtStart,
$dtEnd,
(New-TimeSpan $dtStart $dtEnd).TotalMilliseconds

Write-Event $msg
}

function global:GetDebugSetting($DebugTrace)
{

if ($DebugTrace.ToUpper() -eq "TRUE")
{
$global:Debug = $True;
}
else
{
$global:Debug = $False;
}

}

GetDebugSetting $Args[1]

function global:LogMessage($Message)
{

$Message = "[Debug] {0} `r`n{1}" -f $MyInvocation.ScriptName, $Message
Write-Event $Message
}

if ($global:Debug) {
$msg = "Powershell script {0} execution starting...`r`nArguments:{1} {2}" -f $MyInvocation.MyCommand, $args[0], $args[1]
LogMessage $msg

$dtStart = [DateTime]::Now
}

function Handle-Errors([string] $ErrMsg = [String]::Empty, [bool] $IsExit = $true)
{
if (!$error)
{
return
}

$IsLog = $true

if ("" -eq $ErrMsg)
{
$IsLog = $false
}
else
{
$IsLog = $true
}

if ($IsLog)
{
$ErrorString = ""
if (!$IsExit)
{
$ErrorString = "{0} Monitoring script {1} continues under this error! " -f $MyInvocation.MyCommand, $ErrMsg
}
else
{
$ErrorString = "{0} Monitoring script {1} was terminated! " -f $MyInvocation.MyCommand, $ErrMsg
}

$Exception = $error[$error.Count - 1]
if ($Exception.InvocationInfo)
{
$ErrorString += @"
Current User: {0}
Current PID: {1}
InvocationInfo.MyCommand: {2}
InvocationInfo.ScriptLineNumber: {3}
InvocationInfo.OffsetInLine: {4}
InvocationInfo.ScriptName: {5}
InvocationInfo.Line: {6}
InvocationInfo.PositionMessage: {7}
InvocationInfo.InvocationName: {8}
InvocationInfo.PipelineLength: {9}
InvocationInfo.PipelinePosition: {10}
"@ -f [Environment]::UserName,
$pid,
$Exception.InvocationInfo.MyCommand,
$Exception.InvocationInfo.ScriptLineNumber,
$Exception.InvocationInfo.OffsetInLine,
$Exception.InvocationInfo.ScriptName,
$Exception.InvocationInfo.Line,
$Exception.InvocationInfo.PositionMessage,
$Exception.InvocationInfo.InvocationName,
$Exception.InvocationInfo.PipelineLength,
$Exception.InvocationInfo.PipelinePosition
}
if ($Exception.Exception)
{
$Exception = $Exception.Exception
}
if (!$Exception.InnerException)
{
$ErrType = "Error"
}
else
{
$ErrType = $Exception.InnerException.GetType().FullName
}

$EventObject.WriteEntry(("{0} `n{1}`n{2}" -f $ErrType, $ErrorString, $Exception.Message), [System.Diagnostics.EventLogEntryType]::Error)
}

if ($IsExit)
{
break
}

$error.Clear()
}

$oAPI = New-Object -comObject "MOM.ScriptAPI"
Handle-Errors "Error loading MOM.ScriptAPI COM object "

$WSSAssembly = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
Handle-Errors ""
if (!$WSSAssembly)
{
break
}

if ($WSSAssembly.GetName().Version.Major -ne 14)
{
break
}

$RuleLocSeverities = @{}
$RuleLocSeverities["RuleExecutionFailure"] = [Microsoft.SharePoint.Administration.Health.SPHealthAnalyzer]::GetLocalizedSeverity([Microsoft.SharePoint.Administration.Health.SPHealthCheckErrorLevel]::RuleExecutionFailure)
$RuleLocSeverities["Error"] = [Microsoft.SharePoint.Administration.Health.SPHealthAnalyzer]::GetLocalizedSeverity([Microsoft.SharePoint.Administration.Health.SPHealthCheckErrorLevel]::Error)
$RuleLocSeverities["Warning"] = [Microsoft.SharePoint.Administration.Health.SPHealthAnalyzer]::GetLocalizedSeverity([Microsoft.SharePoint.Administration.Health.SPHealthCheckErrorLevel]::Warning)
$RuleLocSeverities["Information"] = [Microsoft.SharePoint.Administration.Health.SPHealthAnalyzer]::GetLocalizedSeverity([Microsoft.SharePoint.Administration.Health.SPHealthCheckErrorLevel]::Information)
$RuleLocSeverities["Success"] = [Microsoft.SharePoint.Administration.Health.SPHealthAnalyzer]::GetLocalizedSeverity([Microsoft.SharePoint.Administration.Health.SPHealthCheckErrorLevel]::Success)

$RuleStatesFromLocSeverities = @{}
$RuleStatesFromLocSeverities[$RuleLocSeverities["RuleExecutionFailure"]] = "WARNING"
$RuleStatesFromLocSeverities[$RuleLocSeverities["Error"]] = "ERROR"
$RuleStatesFromLocSeverities[$RuleLocSeverities["Warning"]] = "WARNING"
$RuleStatesFromLocSeverities[$RuleLocSeverities["Information"]] = "SUCCESS"
$RuleStatesFromLocSeverities[$RuleLocSeverities["Success"]] = "SUCCESS"

function global:GetSPHARuleState($ErrorLevel)
{
$RuleState = $RuleStatesFromLocSeverities[$ErrorLevel]

return $RuleState
}

function global:GetHealthRuleProperty([string] $HealthRuleType, [string] $HealthRulePropertyName)
{

if (!$HealthRuleType -or !$HealthRulePropertyName)
{
Handle-Errors "Must pass 2 parameters to function GetHealthRuleProperty()"
return [String]::Empty
}

$HealtuRulePropertyValue = "{0} Property {1} Not Found" -f $HealthRuleType, $HealthRulePropertyName

foreach ($HealthRule in $HealthRules)
{
if ($HealthRule["HealthRuleType"].ToUpper() -eq $HealthRuleType.ToUpper())
{
$HealthRulePropertyValue = $HealthRule[$HealthRulePropertyName]
break
}
}
Handle-Errors "Error in function GetHealthRuleProperty({0}, {1}) " -f $HealthRuleType, $HealthRulePropetyName

return $HealthRulePropertyValue
}

function global:GetComputerNameWithoutDomain([string] $ComputerName)
{

if (!$ComputerName)
{
Handle-Errors "Must pass 1 parameter to function GetComputerNameWithoutDomain()"
break
}

$ComputerNameOnly = $ComputerName
if ($ComputerName.IndexOf(".") -ge 0)
{
$ComputerNameOnly = $ComputerName.SubString(0, $ComputerName.IndexOf("."))
}
return $ComputerNameOnly
}

$HealthReports = [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]::Local.HealthReports
if (!$HealthReports)
{
$ErrMsg = @"
Error in {0}:
Failed to get SharePoint Health Reports.
Make sure user {1} have enough permission or SharePoint is configured correctly and the database server is running.
Other issues might also cause this failure. Please see Microsoft SharePoint Server 2010 Management Pack Guide.docx for more information.
"@ -f $MyInvocation.MyCommand, [Environment]::UserName
$EventObject.WriteEntry($ErrMsg, [System.Diagnostics.EventLogEntryType]::Warning)
break;
}

$HealthReportQuery = new-object Microsoft.SharePoint.SPQuery
$HealthReportQuery.ViewFields = "&lt;FieldRef Name='HealthReportSeverity'/&gt;&lt;FieldRef Name='Title'/&gt;&lt;FieldRef Name='HealthReportCategory'/&gt;&lt;FieldRef Name='HealthRuleType'/&gt;&lt;FieldRef Name='Modified'/&gt;&lt;FieldRef Name='HealthReportServers'/&gt;"

$HealthReportQuery.Query = "&lt;OrderBy&gt;&lt;FieldRef Name='Title' /&gt;&lt;FieldRef Name='Modified' Ascending='FALSE' /&gt;&lt;/OrderBy&gt;"
$HealthReports = $HealthReports.GetItems($HealthReportQuery)
Handle-Errors "Error loading Microsoft SharePoint Foundation 2010 HealthReports "
if (!$HealthReports)
{
break
}

$ComputerName = $args[0]
if (!$ComputerName)
{

if ($global:Debug) { LogMessage "Passed in argument ComputerName is null" }
break
}

$ComputerName = GetComputerNameWithoutDomain($ComputerName)

$HealthRuleQuery = new-object Microsoft.SharePoint.SPQuery
$HealthRuleQuery.ViewFields = "&lt;FieldRef Name='Title'/&gt;&lt;FieldRef Name='HealthRuleScope'/&gt;&lt;FieldRef Name='HealthRuleCheckEnabled'/&gt;&lt;FieldRef Name='HealthReportCategory'/&gt;&lt;FieldRef Name='HealthRuleType'/&gt;&lt;FieldRef Name='HealthRuleSchedule'/&gt;&lt;FieldRef Name='HealthRuleService'/&gt;&lt;FieldRef Name='HealthRuleAutoRepairEnabled'/&gt;"
$HealthRules = [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]::Local.HealthRules
if (!$HealthRules)
{
$ErrMsg = @"
Error in {0}:
Failed to get SharePoint Health Rules.
Make sure user {1} have enough permission or SharePoint is configured correctly and the database server is running.
Other issues might also cause this failure. Please see Microsoft SharePoint Foundation 2010 Management Pack Guide.docx for more information.
"@ -f $MyInvocation.MyCommand, [Environment]::UserName
$EventObject.WriteEntry($ErrMsg, [System.Diagnostics.EventLogEntryType]::Warning)
break;
}
$HealthRules = $HealthRules.GetItems($HealthRuleQuery)
Handle-Errors "Error loading Microsoft SharePoint Foundation 2010 HealthRules."
if (!$HealthRules)
{
if ($global:Debug) { LogMessage "[Microsoft.SharePoint.Administration.SPAdministrationWebApplication]::Local.HealthRules returns null" }
break
}

$SuccessCounts = @(0, 0, 0, 0, 0)
$WarningCounts = @(0, 0, 0, 0, 0)
$ErrorCounts = @(0, 0, 0, 0, 0)

$RuleLocCategories = @{}
$RuleLocCategories["Availability"] = [Microsoft.SharePoint.Administration.Health.SPHealthAnalyzer]::GetLocalizedCategory([Microsoft.SharePoint.Administration.Health.SPHealthCategory]::Availability)
$RuleLocCategories["Configuration"] = [Microsoft.SharePoint.Administration.Health.SPHealthAnalyzer]::GetLocalizedCategory([Microsoft.SharePoint.Administration.Health.SPHealthCategory]::Configuration)
$RuleLocCategories["Performance"] = [Microsoft.SharePoint.Administration.Health.SPHealthAnalyzer]::GetLocalizedCategory([Microsoft.SharePoint.Administration.Health.SPHealthCategory]::Performance)
$RuleLocCategories["Security"] = [Microsoft.SharePoint.Administration.Health.SPHealthAnalyzer]::GetLocalizedCategory([Microsoft.SharePoint.Administration.Health.SPHealthCategory]::Security)
$RuleLocCategories["Custom"] = [Microsoft.SharePoint.Administration.Health.SPHealthAnalyzer]::GetLocalizedCategory([Microsoft.SharePoint.Administration.Health.SPHealthCategory]::Custom)

$RuleStates = @{Availability = "Unknown"; Configuration = "Unknown"; Performance = "Unknown"; Security = "Unknown"; Custom = "Unknown"}
$RuleCategories = @{Availability = 0; Configuration = 1; Performance = 2; Security = 3; Custom = 4}

$SPHARuleLocScopes = @{}
$SPHARuleLocScopes["Any"] = [Microsoft.SharePoint.Administration.Health.SPHealthAnalyzer]::GetLocalizedScope([Microsoft.SharePoint.Administration.Health.SPHealthCheckScope]::Any)
$SPHARuleLocScopes["All"] = [Microsoft.SharePoint.Administration.Health.SPHealthAnalyzer]::GetLocalizedScope([Microsoft.SharePoint.Administration.Health.SPHealthCheckScope]::All)

if ($global:Debug) { $FailingRulesAll = $null }

foreach ($Category in $RuleCategories.Keys)
{
$oBag = $oAPI.CreatePropertyBag()
$oBag.AddValue("FilterValue", $Category)
$FailingRules = $null

$LastReportTitle = $null
foreach ($HealthReport in $HealthReports)
{

if ($LastReportTitle -eq $HealthReport.Title)
{
continue;
}

$RuleCategory = $HealthReport["HealthReportCategory"]

if ($RuleCategory -eq $RuleLocCategories[$Category])
{
$RuleType = $HealthReport["HealthRuleType"]

$RuleScope = GetHealthRuleProperty $RuleType "HealthRuleScope"
$RuleEnabled = GetHealthRuleProperty $RuleType "HealthRuleCheckEnabled"

if ($RuleScope -eq $SPHARuleLocScopes["All"] -and $RuleEnabled)
{
$Found = $false

if ($HealthReport["HealthReportServers"])
{
$FailingServers = $HealthReport["HealthReportServers"].Split("`n")
for ($j = 0; $j -lt $FailingServers.length; $j++)
{
if ($FailingServers[$j].Trim().ToUpper() -eq $ComputerName.ToUpper())
{
$Found = $true
break
}
}
}

if ($Found)
{
$ErrorLevel = $HealthReport["HealthReportSeverity"]

switch ($ErrorLevel)
{
$RuleLocSeverities["RuleExecutionFailure"]
{
$WarningCounts[$RuleCategories[$Category]]++
}
$RuleLocSeverities["Error"]
{
$ErrorCounts[$RuleCategories[$Category]]++
}
$RuleLocSeverities["Warning"]
{
$WarningCounts[$RuleCategories[$Category]]++
}
$RuleLocSeverities["Information"]
{
$SuccessCounts[$RuleCategories[$Category]]++
}
$RuleLocSeverities["Success"]
{
$SuccessCounts[$RuleCategories[$Category]]++
}
}
$RuleState = GetSPHARuleState($ErrorLevel)
if ($RuleState -ne "SUCCESS")
{
$oBag.AddValue($HealthReport.Title, $RuleState)
$FailingRules += $HealthReport.Title + "`n"
}
}
else
{

$SuccessCounts[$RuleCategories[$Category]]++
}
Handle-Errors "Failed to get SPHA Health Report property" $false
}
}
$LastReportTitle = $HealthReport.Title
}

if ($ErrorCounts[$RuleCategories[$Category]] -gt 0)
{
$RuleStates[$Category] = "Error"
}
elseif ($WarningCounts[$RuleCategories[$Category]] -gt 0)
{
$RuleStates[$Category] = "Warning"
}
elseif ($SuccessCounts[$RuleCategories[$Category]] -gt 0)
{
$RuleStates[$Category] = "Success"
}

$oBag.AddValue("Status", $RuleStates[$Category])
if ($FailingRules)
{
$oBag.AddValue("Failing Rules", $FailingRules)
if ($global:Debug) { $FailingRulesAll += $Category + "`n" + $FailingRules }
}
$oAPI.AddItem($oBag)
Handle-Errors "Failed to get Health Report property" $false
}

$oAPI.ReturnItems()

Handle-Errors "Failed to submit PropertyBag data to SCOM Agent" $false

if ($global:Debug) {
$msg = @"
Current User: {0}
Current PID: {1}
SPServer SPHA Availability Status: {2}
SPServer SPHA Configuration Status: {3}
SPServer SPHA Performance Status: {4}
SPServer SPHA Security Status: {5}
SPServer SPHA Custom Status: {6}
"@ -f [Environment]::UserName,
$pid,
$RuleStates["Availability"],
$RuleStates["Configuration"],
$RuleStates["Performance"],
$RuleStates["Security"],
$RuleStates["Custom"]

$dtEnd = [DateTime]::Now
$msg += @"
SPServer SPHA Failing Rules: {0}
start time: {1}
stop time: {2}
time taken: {3}
Powershell script {4} execution ended.
"@ -f $FailingRulesAll,
$dtStart,
$dtEnd,
(New-TimeSpan $dtStart $dtEnd).TotalMilliseconds,
$MyInvocation.MyCommand

LogMessage $msg
}
</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<DebugTrace>$Config/DebugTrace$</DebugTrace>
<FilterValue>$Config/FilterValue$</FilterValue>
</DataSource>
<ConditionDetection ID="ErrorFilter" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='Status']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">ERROR</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
<ConditionDetection ID="WarningFilter" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='Status']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">WARNING</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
<ConditionDetection ID="SuccessFilter" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='Status']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">SUCCESS</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
</MemberModules>
<RegularDetections>
<RegularDetection MonitorTypeStateID="Error">
<Node ID="ErrorFilter">
<Node ID="DataSource"/>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="Warning">
<Node ID="WarningFilter">
<Node ID="DataSource"/>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="Success">
<Node ID="SuccessFilter">
<Node ID="DataSource"/>
</Node>
</RegularDetection>
</RegularDetections>
<OnDemandDetections>
<OnDemandDetection MonitorTypeStateID="Error">
<Node ID="ErrorFilter">
<Node ID="DataSource"/>
</Node>
</OnDemandDetection>
<OnDemandDetection MonitorTypeStateID="Warning">
<Node ID="WarningFilter">
<Node ID="DataSource"/>
</Node>
</OnDemandDetection>
<OnDemandDetection MonitorTypeStateID="Success">
<Node ID="SuccessFilter">
<Node ID="DataSource"/>
</Node>
</OnDemandDetection>
</OnDemandDetections>
</MonitorImplementation>
</UnitMonitorType>