From d776a8e23941757dc851ed380fef4bcf401e8579 Mon Sep 17 00:00:00 2001 From: Eric Loyd Date: Fri, 23 Aug 2024 16:37:46 -0400 Subject: [PATCH] Fixed typos and rearranged help a bit --- napi | 10 ++++------ notify-by-ntfy.sh | 12 ++++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/napi b/napi index 1df17ae..f6b5650 100755 --- a/napi +++ b/napi @@ -34,7 +34,7 @@ APIinfo["config/servicegroup"]=".[]" APIinfo["config/command"]=".[]" APIinfo["config/contact"]=".contact[]" APIinfo["config/contactgroup"]=".[]" -APIinfo["config/timeperiod"]="" +APIinfo["config/timeperiod"]=".[]" APIinfo["objects/hoststatus"]=".hoststatus[]" APIinfo["objects/servicestatus"]=".servicestatus[]" @@ -139,15 +139,15 @@ print_help() { Ex: name=in:localhost,nagios,testhost - Displays any matching name with the comma-separated list. Note: Multiple --col selectors are not valid at this time -cnn current_notification_number= - --cname command_name]=<...> - --cline command_line]=<...> + --cname command_name=<...> + --cline command_line=<...> --ctrace Take the --cname given, get its --cline, and replace arguments to show a valid command (whew!) -cg|--contactgroup contact_groups= -cn|--configname config_name= ... comment | downtime | contact | host | service | hostgroup | ... --create doCreate="true" --apply If we're creating something, then Apply Configuration - -D = + -D = This will take anything listed as a Nagios configuration directive and search for it -f|--fields JQ-valid list of fields to show= --file load JSON from= --helpopt Show help for command options @@ -178,8 +178,6 @@ print_help() { --stype 0, 1 (SOFT or HARD) --test Don't call the API, just show what would happen -v|--verbose verbose=\$((\$verbose + 1)) - [...] [...]=<...> NOTE: This will take anything listed as a Nagios configuration directive and search for it - HELP_EOF exit } diff --git a/notify-by-ntfy.sh b/notify-by-ntfy.sh index c7b2c6d..3244824 100644 --- a/notify-by-ntfy.sh +++ b/notify-by-ntfy.sh @@ -8,6 +8,7 @@ message="" tag="exclamation" priority="3" state="" +testMode="" case "$NAGIOS_NOTIFICATIONTYPE" in PROBLEM) tag="bangbang";; @@ -45,10 +46,21 @@ do_service() { while [ -n "$1" ]; do case "$1" in -t|--type) alertType="$2"; shift 2;; + --test) testMode="true"; shift 1;; *) shift 1;; esac done +if [ -n "$testMode" ]; then + NAGIOS_NOTIFICATIONTYPE="Test" + NAGIOS_HOSTNAME="FakeHost" + NAGIOS_HOSTSTATE="OK" + NAGIOS_SERVICEDESC="FakeService" + NAGIOS_HOSTALIAS="FakeHostAlias" + NAGIOS_SERVICESTATE="OK" + NAGIOS_LONGDATETIME="Today" +fi + case "$alertType" in h|host|host) do_host;; s|svc|service) do_service;;