Developer forum

Forum » CMS - Standard features » Monitoring Health - extend

Monitoring Health - extend

Nuno Aguiar
Nuno Aguiar
Reply

Hi,

 

We loved the new "Health" node in Monitoring available in DW 9.9! 

 

Is there a way for us to add custom validations to it?

 

Best Regards,

Nuno Aguiar


Replies

 
Dynamicweb Employee
Vladimir Shushunov
Reply
This post has been marked as an answer

Hi Nuno,

You can write your own Health provider - an inheritor of HealthProviderBase class

A simple example:
 

    [AddInName("My custom health provider")]
    [AddInIcon(Core.UI.Icons.KnownIcon.Calculator)]
    [AddInUseParameterGrouping(true), AddInUseParameterOrdering(true)]
    public class HealthProviderExample : HealthProviderBase
    {
        private readonly Dictionary<int, Check> CheckList = new Dictionary<int, Check> {
            { 1, new Check() { Id=1, Description = "Antispam creates hidden input fields which are filled by bots (but not users)", Name = "Antispam: Forms for Editors", CheckWhatWasRun = "/Globalsettings/System/Security/FormAntiSpam" } }
        };

        private static readonly Dictionary<int, Action<Check>> ChekActions = new Dictionary<int, Action<Check>> {
            { 1, (check) => ExecuteCheck(check, true, CheckState.Error)},
        };

        public override IEnumerable<Check> GetCheckList()
        {
            return CheckList.Values;
        }

        public override Check RunCheck(int checkId)
        {
            Check check = CheckList[checkId];
            ChekActions[checkId].Invoke(check);

            return check;
        }

        private static void ExecuteCheck(Check check, bool recommendedValue, CheckState severityState)
        {
            var actualValue = SystemConfiguration.Instance.GetBoolean(check.CheckWhatWasRun);
            if (recommendedValue == actualValue)
            {
                check.State = CheckState.Ok;
            }
            else
            {
                check.State = severityState;
            }
            check.CheckWhatWasRun += $"{Environment.NewLine}Recommended value: {recommendedValue}";
            check.CheckWhatWasRun += $"{Environment.NewLine}Actual value: {actualValue}";
        }
    }

Best regards, Vladimir

 

Votes for this answer: 1
 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Vladimir,

 

Thank you. This will come in handy for sure.

 

Nuno Aguiar

 

You must be logged in to post in the forum