From 650c362ed903209bb2144b3d4a89f46ca4865a38 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 20 Mar 2023 12:18:32 +0100 Subject: netwatch-notify: support note in notification --- doc/netwatch-notify.md | 7 +++++++ global-functions.rsc | 2 +- netwatch-notify.rsc | 6 ++++++ news-and-changes.rsc | 2 ++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/netwatch-notify.md b/doc/netwatch-notify.md index 5bbd657..aa1204a 100644 --- a/doc/netwatch-notify.md +++ b/doc/netwatch-notify.md @@ -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 diff --git a/global-functions.rsc b/global-functions.rsc index 6e3f00a..512cf34 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -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; diff --git a/netwatch-notify.rsc b/netwatch-notify.rsc index d04d23f..3f47304 100644 --- a/netwatch-notify.rsc +++ b/netwatch-notify.rsc @@ -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") ]); diff --git a/news-and-changes.rsc b/news-and-changes.rsc index e532496..e809db2 100644 --- a/news-and-changes.rsc +++ b/news-and-changes.rsc @@ -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; }; -- cgit v1.2.3-54-g00ecf