From c94e433b0b952033dbf4811c9d4adbf7605497f4 Mon Sep 17 00:00:00 2001 From: Eric Loyd Date: Wed, 10 Jul 2024 14:09:47 -0400 Subject: [PATCH] I believe the -o i option is now global to all currently selectable options --- api.sh | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/api.sh b/api.sh index 2351319..ef7572c 100755 --- a/api.sh +++ b/api.sh @@ -234,8 +234,22 @@ if [ -n "$mySave" ]; then exit fi +# Helper functions for creating our jqString +# First, we need to know if our tests should be case-sensitive or not +jq_check_case() { + thing="$*" + if [ -n "$thing" ]; then + val=" | test(\"$thing\"" + [[ "$cmdOptions" =~ "i," ]] && val+="; \"i\"" + echo "$val)" + else + echo "" + fi +} + +# Do we need to add host limits to the query? jq_add_host() { - [ -n "$myHost" ] && jqString="$jqString | select(.host_name | test(\"$myHost\"))" + [ -n "$myHost" ] && jqString="$jqString | select(.host_name $(jq_check_case $myHost))" } # Otherwise, let's parse the JSON data here @@ -245,8 +259,8 @@ jqString=${APIinfo[$myAPI/$myAPIep]} case "$myAPIep" in servicestatus) jq_add_host - [ -n "$myService" ] && jqString="$jqString | select(.service_description | test(\"$myService\"))" - [ -n "$myCommand" ] && jqString="$jqString | select(.check_command | test(\"$myCommand\"))" + [ -n "$myService" ] && jqString="$jqString | select(.service_description $(jq_check_case $myService))" + [ -n "$myCommand" ] && jqString="$jqString | select(.check_command $(jq_check_case $mycommand))" [ -n "$myHG" ] && jqString="$jqString | select(.hostgroup_name==\"$myHG\")" [ -n "$mySG" ] && jqString="$jqString | select(.servicegroup_name==\"$mySG\")" ;; @@ -259,22 +273,22 @@ case "$myAPIep" in ;; service) jq_add_host - [ -n "$myService" ] && jqString="$jqString | select(.service_description | test(\"$myService\"))" - [ -n "$myConfigName" ] && jqString="$jqString | select(.check_command | test(\"$myConfigName\"))" - [ -n "$myCommand" ] && jqString="$jqString | select(.check_command | test(\"$myCommand\"))" + [ -n "$myService" ] && jqString="$jqString | select(.service_description $(jq_check_case $myService))" + [ -n "$myConfigName" ] && jqString="$jqString | select(.check_command $(jq_check_case $myConfigName))" + [ -n "$myCommand" ] && jqString="$jqString | select(.check_command $(jq_check_case $myCommand))" ;; hostgroupmembers) jq_add_host - [ -n "$myHG" ] && jqString="$jqString | select(.hostgroup_name | test(\"$myHG\"))" + [ -n "$myHG" ] && jqString="$jqString | select(.hostgroup_name $(jq_check_case $myHG))" [[ $cmdOptions =~ "h," ]] && jqString="$jqString | .members[] | .[] | .host_name" [[ $cmdOptions =~ "o," ]] && jqString="$jqString | .members[] | .[] | .host_object_id" ;; servicegroup) jq_add_host - [ -n "$mySG" ] && jqString="$jqString | select(.servicegroup_name==\"$mySG\")" + [ -n "$mySG" ] && jqString="$jqString | select(.servicegroup_name $(jq_check_case $mySG))" ;; contactgroup) - [ -n "$myCG" ] && jqString="$jqString | select(.contactgroup_name==\"$myCG\")" + [ -n "$myCG" ] && jqString="$jqString | select(.contactgroup_name $(jq_check_case $myCG))" ;; esac [ -n "$myFields" ] && jqString="$jqString | $myFields"