Export (0) Print
Expand All

SPHealthAnalysisRule Class

An abstract base class that provides a definition for a SharePoint Health Analyzer rule.


Namespace:  Microsoft.SharePoint.Administration.Health
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
Public MustInherit Class SPHealthAnalysisRule
Dim instance As SPHealthAnalysisRule

A SharePoint Health Analyzer rule is a a concrete subclass that inherits from either one of two abstract classes: SPHealthAnalysisRule or SPRepairableHealthAnalysisRule. The only difference between these two classes is that while both have a Check() method to detect a problem, the SPRepairableHealthAnalysisRule class also has a Repair() method to correct the problem found by the Check method.

When you create a subclass of the SPHealthAnalysisRule class, you must override and implement the Summary, Explanation, Remedy, Category, and ErrorLevel properties as well as the Check() method. If you want the rule to run automatically under a timer job, you should override and implement the AutomaticExecutionParameters property as well. Implementation of the remaining members of the class is optional.

The following example creates a rule that checks whether the local server is joined to the server farm.

Imports Microsoft.SharePoint.Administration
Imports Microsoft.SharePoint.Administration.Health

Namespace Sample.HealthRules
    Public NotInheritable Class LocalJoinedToFarm
        Inherits SPHealthAnalysisRule

        Public Overrides ReadOnly Property Summary() As String
                Return "The local server is not joined to a SharePoint server farm."
            End Get
        End Property

        Public Overrides ReadOnly Property Explanation() As String
                Return "SharePoint is installed on this server, but the installation will not function until the server has been joined to a SharePoint server farm."
            End Get
        End Property

        Public Overrides ReadOnly Property Remedy() As String
                Return "Run the SharePoint Products and Technologies Configuration Wizard and follow the prompts to create a new farm or to join this server to an existing farm."
            End Get
        End Property

        Public Overrides ReadOnly Property Category() As SPHealthCategory
                Return SPHealthCategory.Configuration
            End Get
        End Property

        Public Overrides ReadOnly Property ErrorLevel() As SPHealthCheckErrorLevel
                Return SPHealthCheckErrorLevel.Error
            End Get
        End Property

        Public Overrides ReadOnly Property AutomaticExecutionParameters() As SPHealthAnalysisRuleAutomaticExecutionParameters
                Dim retval As New SPHealthAnalysisRuleAutomaticExecutionParameters()
                retval.Schedule = SPHealthCheckSchedule.Hourly
                retval.Scope = SPHealthCheckScope.All
                retval.ServiceType = GetType(SPTimerService)
                retval.RepairAutomatically = False
                Return retval
            End Get
        End Property

        Public Overrides Function Check() As SPHealthCheckStatus
            Return If(SPFarm.Joined, SPHealthCheckStatus.Passed, SPHealthCheckStatus.Failed)
        End Function
    End Class

End Namespace

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
© 2014 Microsoft