navi-0.1: A utility program for sending system notifications.
Safe HaskellSafe-Inferred
LanguageGHC2021

Navi.Event

Description

This module provides functionality for handling events.

Synopsis

Event type

data Event result Source #

Event represents sending notifications. An event will:

  1. Query for information (i.e. run a shell command).
  2. Parse the result.
  3. Raise an alert if the result matches some condition.

Constructors

MkEvent 

Fields

Instances

Instances details
(k ~ A_Lens, a ~ ErrorNote, b ~ ErrorNote) => LabelOptic "errorNote" k (Event result) (Event result) a b Source # 
Instance details

Defined in Navi.Event.Types

Methods

labelOptic :: Optic k NoIx (Event result) (Event result) a b Source #

(k ~ A_Lens, a ~ Text, b ~ Text) => LabelOptic "name" k (Event result) (Event result) a b Source # 
Instance details

Defined in Navi.Event.Types

Methods

labelOptic :: Optic k NoIx (Event result) (Event result) a b Source #

(k ~ A_Lens, a ~ PollInterval, b ~ PollInterval) => LabelOptic "pollInterval" k (Event result) (Event result) a b Source # 
Instance details

Defined in Navi.Event.Types

Methods

labelOptic :: Optic k NoIx (Event result) (Event result) a b Source #

(k ~ A_Lens, a ~ (result -> Maybe NaviNote), b ~ (result -> Maybe NaviNote)) => LabelOptic "raiseAlert" k (Event result) (Event result) a b Source # 
Instance details

Defined in Navi.Event.Types

Methods

labelOptic :: Optic k NoIx (Event result) (Event result) a b Source #

(k ~ A_Lens, a ~ RepeatEvent result, b ~ RepeatEvent result) => LabelOptic "repeatEvent" k (Event result) (Event result) a b Source # 
Instance details

Defined in Navi.Event.Types

Methods

labelOptic :: Optic k NoIx (Event result) (Event result) a b Source #

(k ~ A_Lens, a ~ ServiceType result, b ~ ServiceType result) => LabelOptic "serviceType" k (Event result) (Event result) a b Source # 
Instance details

Defined in Navi.Event.Types

Methods

labelOptic :: Optic k NoIx (Event result) (Event result) a b Source #

Show (Event result) Source # 
Instance details

Defined in Navi.Event.Types

Methods

showsPrec :: Int -> Event result -> ShowS Source #

show :: Event result -> String Source #

showList :: [Event result] -> ShowS Source #

data AnyEvent where Source #

Existentially quantifies result type on an Event. Used so that we can store different events in the same list.

Constructors

MkAnyEvent :: (Eq result, Show result) => Event result -> AnyEvent 

Instances

Instances details
Show AnyEvent Source # 
Instance details

Defined in Navi.Event.Types

runEvent :: (HasCallStack, MonadLoggerNamespace m, MonadSTM m, MonadSystemInfo m, Show result) => Event result -> m (EventSuccess result) Source #

Runs an event, i.e.,

  1. Queries the system via MonadSystemInfo.
  2. Returns the parsed result.

Results

data EventSuccess result Source #

Holds the Event data used after an event is successfully run.

Since: 0.1

Constructors

MkEventSuccess 

Fields

Instances

Instances details
(k ~ A_Lens, a ~ (result -> Maybe NaviNote), b ~ (result -> Maybe NaviNote)) => LabelOptic "raiseAlert" k (EventSuccess result) (EventSuccess result) a b Source # 
Instance details

Defined in Navi.Event.Types

Methods

labelOptic :: Optic k NoIx (EventSuccess result) (EventSuccess result) a b Source #

(k ~ A_Lens, a ~ RepeatEvent result, b ~ RepeatEvent result) => LabelOptic "repeatEvent" k (EventSuccess result) (EventSuccess result) a b Source # 
Instance details

Defined in Navi.Event.Types

Methods

labelOptic :: Optic k NoIx (EventSuccess result) (EventSuccess result) a b Source #

(k ~ A_Lens, a ~ result, b ~ result) => LabelOptic "result" k (EventSuccess result) (EventSuccess result) a b Source # 
Instance details

Defined in Navi.Event.Types

Methods

labelOptic :: Optic k NoIx (EventSuccess result) (EventSuccess result) a b Source #

data EventError Source #

Represents an error when querying an Event.

Constructors

MkEventError 

Fields

Instances

Instances details
Exception EventError Source # 
Instance details

Defined in Navi.Event.Types

Show EventError Source # 
Instance details

Defined in Navi.Event.Types

Eq EventError Source # 
Instance details

Defined in Navi.Event.Types

(k ~ A_Lens, a ~ Text, b ~ Text) => LabelOptic "long" k EventError EventError a b Source # 
Instance details

Defined in Navi.Event.Types

(k ~ A_Lens, a ~ Text, b ~ Text) => LabelOptic "name" k EventError EventError a b Source # 
Instance details

Defined in Navi.Event.Types

(k ~ A_Lens, a ~ Text, b ~ Text) => LabelOptic "short" k EventError EventError a b Source # 
Instance details

Defined in Navi.Event.Types

Caching previous events/errors

data RepeatEvent a Source #

Determines if we are allowed to send off duplicate notifications simultaneously. If we are not, then NoRepeats holds the last trigger so that we can detect duplicates.

Constructors

NoRepeats !(IORef (Maybe a)) 
AllowRepeats 

Instances

Instances details
Show (RepeatEvent a) Source # 
Instance details

Defined in Navi.Event.Types

data ErrorNote Source #

Determines if we should send notifications for errors and, if so, if we allow repeats.

Constructors

NoErrNote 
AllowErrNote !(RepeatEvent ()) 

Instances

Instances details
Show ErrorNote Source # 
Instance details

Defined in Navi.Event.Types

blockRepeat :: (Eq a, MonadLoggerNamespace m, MonadIORef m, Show a) => RepeatEvent a -> a -> m Bool Source #

Determines if we should block the event. The semantics are:

  1. AllowRepeats: never block (returns False).
  2. NoRepeats: block only if the parameter a equals the previous a stored in our ref.

blockErr :: (MonadLoggerNamespace m, MonadIORef m) => ErrorNote -> m Bool Source #

Determines if we should block the error event. The semantics are:

  1. NoErrNote: always block (returns True).
  2. AllowErrNote AllowRepeats: never block (returns False).
  3. AllowErrNote NoRepeats: block only if we have sent a notifcation for this error before.

updatePrevTrigger :: (Eq a, MonadIORef m) => RepeatEvent a -> a -> m () Source #

If the reference is NoRepeats then we overwrite the previous reference with the new parameter. Otherwise we do nothing.