Implement Health checks for your custom modules
The Sitefinity CMS Health check service helps you assess the vital functions of your Sitefinity CMS site. Out of the box the Health check service covers the following system components:
- System Bootstrap
- Start Up
- Database access
- NLB communication
- Internet connectivity
- Redis check
For more information about the out of the box Health check types, see Overview: Health check service
If you have developed custom modules for your Sitefinity CMS website you can also benefit from the Health check service and integrate custom Health checks in your module code. This way you extend the scope of the Health check service and can use it as a centralized mechanism for verifying the vital functions of core Sitefinity CMS functionality, as well as your custom module components.
Implement a custom Health Check
The Health check API enables you to implement custom health checks and cover your specific use cases. To create a custom health check, you must add a new class to your solution and inherit from HealthCheckBase
. HealthCheckBase
requires you to implement the RunCore
method, which is where you place your health check logic. RunCore
is an async method, thus you must return a Task
in your logic.
For example, here’s how you can implement a custom health check, which verifies whether your Sitefinity CMS website can successfully connect to a configured LDAP membership provider:
Add the Health Check to your custom module
To register the custom Health check in your custom module, you must instruct Sitefinity CMS to look for the configuration types inside the custom module configuration class. Inside the module configuration class you must add a new configuration property that will hold the collection of health checks for this module, implement the IHealthCheckConfig
interface, and finally populate the collection of Health checks for this module.
To demonstrate this concept let’s go ahead and register the custom LdapConnectionCheck
, shown in the previous paragraph, in a custom module.
Modify your custom module class and override GetConfigTypes
First you must modify your module class and override the GetConfigTypes
method. Inside the overridden GetConfigTypes
return the type of your module configuration class:
Modify your module configuration class and implement IHealthCheckConfig
Next you must modify your module configuration class. Start by adding a new ConfigurationProperty
in your custom module configuration class, named HealthChecks. This property will hold a dictionary of the Health checks you want to run for the module. Sitefinity CMS reads this configuration property and executes any registered Health checks for this module. The property must be of type ConfigElementDictionary<string, CheckConfigElement>
, and you need to mark it with the ConfigurationProperty
and ObjectInfo
attributes. For the ConfigurationProperty
attribute value you must specify the configuration property name – “healthChecks”. The ObjectInfo
attribute controls how this property will be displayed in the Sitefinity CMS Advanced settings UI. Specify the type to be ConfigDescriptions
and write the Title and the Description of this configuration property, which will appear in the UI.
Next, inherit from the IHealthCheckConfig
interface. This interface requires you to implement the HealthCheckConfigElements
member in your custom module configuration class. Inside the HealthCheckConfigElements
implementation return the Values
of the HealthChecks
property you added on the previous step.
Finally, you need to override the OnPropertiesInitialized
method of your custom module configuration class and add the desired Health checks to the HealthChecks
property. Health checks are added to the HealthChecks
collection as objects of type CheckConfigElement
, and you must specify the Name
, Enabled
, and Type
properties.
The following sample demonstrates the implementation of the above described logic in a blank module configuration class:
As a result, when you request the Health Check service endpoint you’ve configured for your Sitefinity CMS website, you should see the custom health check execution result in the collection of Health Checks:
For more information about setting up the Health check service endpoint, see Health check service.