netwatch-notify: support note in notification

This commit is contained in:
Christian Hesse 2023-03-20 12:18:32 +01:00
parent 3b5026ea8d
commit 650c362ed9
4 changed files with 16 additions and 1 deletions

View file

@ -88,6 +88,13 @@ powered off, but accessibility is of interest.
Go and get your coffee ☕️ before sending the print job.
### Add a note in notification
For some extra information it is possible to add a text note. This is
included verbatim into the notification.
/tool/netwatch/add comment="notify, name=example, note=Do not touch!" host=10.0.0.31;
Also notification settings are required for
[e-mail](mod/notification-email.md),
[matrix](mod/notification-matrix.md) and/or

View file

@ -12,7 +12,7 @@
:local 0 "global-functions";
# expected configuration version
:global ExpectedConfigVersion 95;
:global ExpectedConfigVersion 96;
# global variables not to be changed by user
:global GlobalFunctionsReady false;

View file

@ -112,6 +112,9 @@ $ScriptLock $0;
:local Message ("The " . $Type . " '" . $Name . "' (" . $HostDetails . \
") is up since " . $HostVal->"since" . ".\n" . \
"It was down for " . $CountDown . " checks since " . ($Metric->"since") . ".");
:if ([ :typeof ($HostInfo->"note") ] = "str") do={
:set Message ($Message . "\n\nNote:\n" . ($HostInfo->"note"));
}
:if ([ :typeof ($HostInfo->"up-hook") ] = "str") do={
:set Message ($Message . "\n\n" . [ $NetwatchNotifyHook $Name $Type "up" \
($HostInfo->"up-hook") ]);
@ -162,6 +165,9 @@ $ScriptLock $0;
($ParentUp = false || $ParentUp > 2) && $Metric->"notified" != true) do={
:local Message ("The " . $Type . " '" . $Name . "' (" . $HostDetails . \
") is down since " . $HostVal->"since" . ".");
:if ([ :typeof ($HostInfo->"note") ] = "str") do={
:set Message ($Message . "\n\nNote:\n" . ($HostInfo->"note"));
}
:if ([ :typeof ($HostInfo->"down-hook") ] = "str") do={
:set Message ($Message . "\n\n" . [ $NetwatchNotifyHook $Name $Type "down" \
($HostInfo->"down-hook") ]);

View file

@ -9,8 +9,10 @@
# Changes for global-config to be added to notification on script updates
:global GlobalConfigChanges {
96="Added support for notes in 'netwatch-notify', these are included verbatim into the notification.";
};
# Migration steps to be applied on script updates
:global GlobalConfigMigration {
0;
};