diff options
author | Christian Hesse <mail@eworm.de> | 2021-07-08 13:02:57 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2021-07-08 13:02:57 +0200 |
commit | 87ce4a86b7d06df746c5ecd70dc59ba4d8b88037 (patch) | |
tree | 06ffb4623c8a8794c2c61183d68a39225e6a47dc | |
parent | 1eb337d87f899945237e9b8406d2073ee9ba9b97 (diff) |
netwatch-notify: add error handling for hooks
We already had syntax validation, but a script with valid synctax can
still fail to run...
-rw-r--r-- | netwatch-notify | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/netwatch-notify b/netwatch-notify index c630678..9e269c2 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -66,7 +66,11 @@ :if ([ $ValidateSyntax ($HostInfo->"up-hook") ] = true) do={ $LogPrintExit2 info $0 ("Running hook on host " . $HostName . " up: " . ($HostInfo->"up-hook")) false; :set Message ($Message . "\n\nRunning hook:\n" . $HostInfo->"up-hook"); - [ :parse ($HostInfo->"up-hook") ]; + :do { + [ :parse ($HostInfo->"up-hook") ]; + } on-error={ + $LogPrintExit2 warning $0 ("The up-hook for host " . $HostName . " failed to run.") false; + } } else={ $LogPrintExit2 warning $0 ("The up-hook for host " . $HostName . " failed syntax validation.") false; } @@ -106,7 +110,11 @@ :if ([ $ValidateSyntax ($HostInfo->"down-hook") ] = true) do={ $LogPrintExit2 info $0 ("Running hook on host " . $HostName . " down: " . ($HostInfo->"down-hook")) false; :set Message ($Message . "\n\nRunning hook:\n" . $HostInfo->"down-hook"); - [ :parse ($HostInfo->"down-hook") ]; + :do { + [ :parse ($HostInfo->"down-hook") ]; + } on-error={ + $LogPrintExit2 warning $0 ("The down-hook for host " . $HostName . " failed to run.") false; + } } else={ $LogPrintExit2 warning $0 ("The down-hook for host " . $HostName . " failed syntax validation.") false; } |