Skip to content

System Monitor

Leonard Sperry edited this page Apr 13, 2024 · 11 revisions

Updates for V6 and notifications coming soon.


Version 2.1 ships with a new set of features to help you monitor your instance. All you need to do to use these features is add a class to your project that implements the 'ISystemMonitor` interface. It is recommended to only have one implementation.

public interface ISystemMonitor
{
    Task BadEntityStateDiscovered(IEnumerable<BadEntityState> badStates);
    Task StateHandlerInitialized();
    Task UnhandledException(AutomationMetaData automationMetaData, Exception exception);
    Task HaNotificationUpdate(HaNotification notification, CancellationToken ct) => Task.CompletedTask;
}

Each of the above methods will be called by the framework at the appropriate time. You can inject IHaServices into your implementation for sending alerts or notifying you on any channel you choose.

See Example

BadEntityStateDiscovered

If you have the EntityTracker enabled in your Configuration, this method will be called when an entity becomes nonresponsive. Specifically, it will be called when the entity cannot be found or entity's state is set to one of the following values:

  • unknown
  • unavailable
  • none

The entities that will be checked come from all enabled automations and are a distinct list of all entity IDs returned by the automation's TriggerEntityIds() method and the AdditionalEntitiesToTrack property of its metadata.

The BadEntityState model has two properties.

public record BadEntityState(string EntityId, HaEntityState? State = null);

The EntityId will always be set to the entity which is being checked. If the entity cannot be found, the HaEntityState will be null, otherwise it will be set and its state will be one of the states listed above.

StateHandlerInitialized

During a restart, it can take up to a minute for the Kafkaflow consumers to become active. This method will be called once in the lifetime of your applicaiton when the State Handler becomes active.

UnhandledException

When an automation triggers and does not handle an exception, this method will be called with metadata associated with the automation and the exception that was thrown. Even if you do not specify metadata, your automation will be wrapped in an automation wrapper which will have information for you to inspect.

HaNotificationUpdate

Assuming you have set up your home assistant integration with HaKafkaNet using the package in the Getting Started instructions, this method will be called every time there is a persistent notification update in Home Assistant.