Skip to content

Commit b834699

Browse files
committed
update docs
1 parent 2fc42c2 commit b834699

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

docs/plugins.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,29 @@ await plugin.my_plugin.actions.action_name({"key": "value"})
3434
## Notifications
3535
Notifications are used by monitors, usually to notify about an event. Each notification has it's own settings and behaviors.
3636

37-
Notifications must inherit from the `src.notifications.base_notification.BaseNotification` class. The method `reactions_list` must return a list of reactions that will trigger an action. Each reaction is a tuple with the reaction name and a list of coroutines that must be called when the reaction is triggered.
37+
Notifications must have the structure defined by the `src.notifications.base_notification.BaseNotification` **protocol**. The method `reactions_list` returns a list of reactions that will trigger an action. Each reaction is a tuple with the reaction name and a list of coroutines that must be called when the reaction is triggered.
3838

39-
Example:
39+
Notification base structure:
4040
```python
41-
def reactions_list(self) -> list[tuple[str, list[Coroutine | partial[Coroutine]]]]:
42-
"""Get a list of events that the notification will react to"""
43-
return [
44-
("alert_acknowledged", [handle_event_acknowledged]),
45-
("alert_created", [handle_event_created]),
46-
("alert_solved", [handle_event_solved]),
47-
]
41+
class Notification:
42+
min_priority_to_send: int = 5
43+
44+
def reactions_list(self) -> list[tuple[str, list[Coroutine | partial[Coroutine]]]]:
45+
...
46+
```
47+
48+
A notification can have more parameters necessary to control their behavior. An example of a notification implementation is:
49+
```python
50+
class MyNotification:
51+
min_priority_to_send: int = 5
52+
53+
def reactions_list(self) -> list[tuple[str, list[Coroutine | partial[Coroutine]]]]:
54+
"""Get a list of events that the notification will react to"""
55+
return [
56+
("alert_acknowledged", [handle_event_acknowledged]),
57+
("alert_created", [handle_event_created]),
58+
("alert_solved", [handle_event_solved]),
59+
]
4860
```
4961

5062
The reaction functions must follow the same structure presented in the [Monitor](./monitors.md) documentation.

0 commit comments

Comments
 (0)