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 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
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
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.
Implement health check connectivity for your custom Search services
If you are developing a custom search service to use with Sitefinity CMS, and you want to include it in the health check service, you have to perform the following steps:
- Make sure you have a Search service connectivity health check added in your health check service configuration. For more information about adding health checks, see Health check service. Having a Search service connectivity health check added instructs Sitefinity CMS to check the implementation of the currently configured search service for the website and test its connectivity.
- Implement the connectivity check inside your custom search service. This is done via implementing the
ISearchServiceConnectivity interface. The interface requires you to implement the
TestConnectivity method in your custom search service class. The impementation depends on your use case cenario - you can check whether there is a ping to the search service, if it's an external one, or whether it can read/write to the search index. The method should return a boolean value indicating whether connectivity check is successful or not. For example, this is the default implementation for the
TestConnectivity method in Sitefinity CMS:
public virtual bool TestConnectivity()
var responce = this.elasticClient.Ping();
NOTE: If you are extending the out of the box
AzureSearchService types, they already implement the
ISearchServiceConnectivity interface, thus you don't need to explicitly implement the
TestConnectivity method in your class. You can override it if you need to change the default logic.