From b0eaf3505ba0e1269646f9b5287b49b7efd1539a Mon Sep 17 00:00:00 2001 From: Aleksandra Jovovic Date: Tue, 24 Nov 2020 11:03:12 +0000 Subject: [PATCH] Features/health rules only (#38) * refactor app health rules (#27) * Feature/containerHealthRules (#28) * Feature/disable node hr (#29) * microservice health rules * Merge action-suppression and port-bugfix to develop from feature b; * Add action suppression upload from file; Typos; * Add suppress action config; * Add actions folder and example file; * Dash layout * Adding detele action suppression; * Controller port as parameter takes precedence; * Port controller; * Update create and delete action suppression; Update config; * Action suppression bugfix missing functions and folders; Save uploaded actions; * Action suppression adding proxy; Fix empty proxy; Backup only uploaded files; * Update action suppression help; * Rename dir healthrules to health_rules; * Add modules dir; Add health rule update / delete sh; * Add health rule only and delete options; * Update refs to HRs; Add debug echo; * Add delete health rule func; Remove debug from HR modules; * Add health rule vars to docker env and k8s configMap; * Remove health rule function from configMyApp; Update readme with argbash; * Delete HR from comma separated list; * HR override, support previous version of env. var; * Add git actions for health rules; * Update delete HR test case - delete multiple; * Update folder name in test case; * Add SIM HR to test case; * Test case update include sim flag; * Remove feature branch from actions; Co-authored-by: Israel Ogbole --- .github/workflows/QAConfigMyApp.yml | 46 +++++++ README.md | 4 + config.json | 8 +- configMyApp.sh | 46 +------ docker/env.list | 12 +- .../Application/Agent-Availability.json | 0 .../BusinessTransaction-ErrorRate.json | 0 .../BusinessTransaction-ResponseTime.json | 0 .../Application/RemoteService-ErrorRate.json | 0 .../RemoteService-ResponseTime.json | 0 .../ServiceEndPoint-ErrorRate.json | 0 .../ServiceEndPoint-ResponseTime.json | 0 .../Application/Tiers-ErrorRate.json | 0 .../Application/Tiers-ResponseTime.json | 0 .../CpuUtilisationTooHigh.json | 0 .../MemoryUtilisationTooHigh.json | 0 kubernetes/cma-configmap.yaml | 11 +- modules/actions/.gitkeep | 0 modules/health_rules/delete_health_rules.sh | 65 ++++++++++ modules/health_rules/upload_health_rules.sh | 89 ++++++++++++++ start.sh | 113 ++++++++++++++---- 21 files changed, 325 insertions(+), 69 deletions(-) rename {healthrules => health_rules}/Application/Agent-Availability.json (100%) rename {healthrules => health_rules}/Application/BusinessTransaction-ErrorRate.json (100%) rename {healthrules => health_rules}/Application/BusinessTransaction-ResponseTime.json (100%) rename {healthrules => health_rules}/Application/RemoteService-ErrorRate.json (100%) rename {healthrules => health_rules}/Application/RemoteService-ResponseTime.json (100%) rename {healthrules => health_rules}/Application/ServiceEndPoint-ErrorRate.json (100%) rename {healthrules => health_rules}/Application/ServiceEndPoint-ResponseTime.json (100%) rename {healthrules => health_rules}/Application/Tiers-ErrorRate.json (100%) rename {healthrules => health_rules}/Application/Tiers-ResponseTime.json (100%) rename {healthrules => health_rules}/ServerVisibility/CpuUtilisationTooHigh.json (100%) rename {healthrules => health_rules}/ServerVisibility/MemoryUtilisationTooHigh.json (100%) create mode 100644 modules/actions/.gitkeep create mode 100755 modules/health_rules/delete_health_rules.sh create mode 100755 modules/health_rules/upload_health_rules.sh diff --git a/.github/workflows/QAConfigMyApp.yml b/.github/workflows/QAConfigMyApp.yml index 49e66b4..f8d241a 100644 --- a/.github/workflows/QAConfigMyApp.yml +++ b/.github/workflows/QAConfigMyApp.yml @@ -63,6 +63,52 @@ jobs: curl https://gist.githubusercontent.com/iogbole/48e7568454b066132700c4fe039c2cff/raw/4aa417193e7ce9f3cce2410e67d525761cb6d678/gistfile1.txt -o ./custom_dashboards/CustomDashboard_vanilla.json export CMA_UPLOAD_CUSTOM_DASHBOARD=true ./start.sh -a IoT_API -c configmyappdemo-2044no-uzyczrm0.appd-cx.com -p appd -u appd + + - name: TestCase7- health rules only - no overwrite - parameters + env: + CMA_USE_HTTPS: false + run: | + echo Running health rules only, get values from runtime parameters, + ./start.sh -a Jenkins_API -c configmyappdemo-2044no-uzyczrm0.appd-cx.com -p appd -u appd --health-rules-only --no-health-rules-overwrite + + - name: TestCase8- health rules only - overwrite - env variables + env: + CMA_USE_HTTPS: false + CMA_HEALTH_RULES_OVERWRITE: true + CMA_HEALTH_RULES_ONLY: true + run: | + echo Running health rules only, get values from environment variables, + ./start.sh -a Jenkins_API -c configmyappdemo-2044no-uzyczrm0.appd-cx.com -p appd -u appd + + - name: TestCase9- health rules only - overwrite default - config + env: + CMA_USE_HTTPS: false + run: | + cp config.json config.json.bkp + curl https://gist.githubusercontent.com/AlexJov/63ccb17421208679ef63b55afafea712/raw/b8e5ebc5399a8d7df5422ff07c49c892f0c3bd63/config.json -o ./config.json + echo Running health rules only, get values from config, + ./start.sh -a Jenkins_API -c configmyappdemo-2044no-uzyczrm0.appd-cx.com -p appd -u appd + cp config.json.bkp config.json + + - name: TestCase10- delete health rules, existing, + env: + CMA_USE_HTTPS: false + run: | + curl https://gist.githubusercontent.com/AlexJov/d65f5e436bd54dd53aaad679f6b8d8e9/raw/57f3d2ec115f7411944b934c735f57a6a276d44b/Agent%2520Availability%2520to%2520Delete.json -o ./health_rules/Application/AgentAvailabilityToDelete.json + curl https://gist.githubusercontent.com/AlexJov/03317fd4271325fbd6678dded2df6e91/raw/bb33a4b3abcaed762f1a5b262586183c6efd4402/CpuUtilisationTooHighToDelete.json -o ./health_rules/ServerVisibility/CpuUtilisationTooHighToDelete.json + + echo Running health rules only, import additional health rules, + ./start.sh -a Jenkins_API -c configmyappdemo-2044no-uzyczrm0.appd-cx.com -p appd -u appd --include-sim --health-rules-only + + echo Delete health rules: + ./start.sh -c http://configmyappdemo-2044no-uzyczrm0.appd-cx.com/ -a Jenkins_API -u appd -p appd --health-rules-delete "Agent Availability to Delete, Server Health: CPU Utilisation is too high to Delete" + + - name: TestCase11- delete health rules, non existing + env: + CMA_USE_HTTPS: false + run: | + echo Delete health rules, delete health rules from TestCase10, + ./start.sh -c http://configmyappdemo-2044no-uzyczrm0.appd-cx.com/ -a Jenkins_API -u appd -p appd --health-rules-delete "There is no this rule name" diff --git a/README.md b/README.md index 7d3eabb..9064dba 100755 --- a/README.md +++ b/README.md @@ -15,3 +15,7 @@ ConfigMyApp is wrapper on supported AppDynamics RESTful APIs. # Official Documentation Please refer to the official documentation for further details + +# Generate input parameters + +https://argbash.io/generate diff --git a/config.json b/config.json index bbbdd38..d54b8f3 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,4 @@ { - "overwrite_health_rules": false, "are_passwords_encoded": false, "branding": [ @@ -33,6 +32,13 @@ "upload_custom_dashboard": false } ], + "health_rules": [ + { + "health_rules_only": false, + "health_rules_overwrite": false, + "health_rules_delete": "" + } + ], "action_suppression": [ { "suppress_action": false, diff --git a/configMyApp.sh b/configMyApp.sh index 40035f5..c47c4a4 100755 --- a/configMyApp.sh +++ b/configMyApp.sh @@ -58,7 +58,7 @@ _include_database=${5} _database_name=${6} _include_sim=${7} _configure_bt=${8} -_overwrite_health_rules=${9} +_health_rules_overwrite=${9} _bt_only=${10} _enable_branding=${11} @@ -192,33 +192,6 @@ function func_cleanup() { rm -rf $tempFolder } -function func_import_health_rules(){ - local appId=$1 - local folderPath=$2 - - # get all current health rules for application - allHealthRules=$(curl -s --user ${_user_credentials} ${_controller_url}/alerting/rest/v1/applications/${appId}/health-rules ${_proxy_details}) - - for f in $folderPath; do - echo "Processing $f health rule template" - # get health rule name from json file - healthRuleName=$(jq -r '.name' <$f) - # use it to get health rule id (if exists) - healthRuleId=$(jq --arg hrName "$healthRuleName" '.[] | select(.name == $hrName) | .id' <<<$allHealthRules) - - # create new if health rule id does not exist - if [ "${healthRuleId}" == "" ]; then - httpCode=$(curl -s -o /dev/null -w "%{http_code}" -X POST --user ${_user_credentials} ${_controller_url}/alerting/rest/v1/applications/${appId}/health-rules --header "Content-Type: application/json" --data "@${f}" ${_proxy_details}) - func_check_http_status $httpCode "Error occured while importing server health rules." - # overwrite existing health rule only if flag is true - elif [ "${_overwrite_health_rules}" = true ]; then - httpCode=$(curl -s -o /dev/null -w "%{http_code}" -X PUT --user ${_user_credentials} ${_controller_url}/alerting/rest/v1/applications/${appId}/health-rules/${healthRuleId} --header "Content-Type: application/json" --data "@${f}" ${_proxy_details}) - func_check_http_status $httpCode "Error occured while importing server health rules." - fi - - done -} - ### END FUNCTIONS ### url=${_controller_url}${endpoint} @@ -255,20 +228,8 @@ if [ "${_bt_only}" = true ]; then else # proceed as normal - # Server Visibility health rules - if [ "${_include_sim}" = true ]; then - echo "Creating Server Visibility Health Rules...Please wait" - echo "" - - func_import_health_rules $appId "${serverVizHealthRuleFile}" - fi - - # Application health rules - echo "" - echo "Creating ${_application_name} Health Rules..." - sleep 1 - - func_import_health_rules $appId "${applicationHealthRule}" + # Health rules + source ./modules/health_rules/upload_health_rules.sh "$_controller_url" "$_user_credentials" "$_application_name" "$_proxy_details" "$_health_rules_overwrite" "$_include_sim" echo "" sleep 1 @@ -276,7 +237,6 @@ else echo "" echo "Processing Dashboard Template." - sleep 1 echo "" # Dashboard diff --git a/docker/env.list b/docker/env.list index d99b1f5..dbec430 100644 --- a/docker/env.list +++ b/docker/env.list @@ -12,9 +12,19 @@ CMA_INCLUDE_DATABASE=true CMA_DATABASE_NAME=ConfigMyApp CMA_INCLUDE_SIM=true #CMA_CONFIGURE_BT=true -CMA_OVERWRITE_HEALTH_RULES=true #CMA_BT_ONLY=true +CMA_HEALTH_RULES_ONLY=false +CMA_HEALTH_RULES_OVERWRITE=true +#CMA_HEALTH_RULES_DELETE="health rule name" + +CMA_SUPPRESS_ACTION=false +#CMA_SUPPRESS_START=2020-01-31T12:00:00+0000 +#CMA_SUPPRESS_DURATION=60 +#CMA_SUPPRESS_NAME="Action Suppression" +#CMA_SUPPRESS_UPLOAD_FILES=false +#CMA_SUPPRESS_DELETE=false + #CMA_USE_PROXY=false #CMA_PROXY_URL=localhost #CMA_PROXY_PORT=8080 diff --git a/healthrules/Application/Agent-Availability.json b/health_rules/Application/Agent-Availability.json similarity index 100% rename from healthrules/Application/Agent-Availability.json rename to health_rules/Application/Agent-Availability.json diff --git a/healthrules/Application/BusinessTransaction-ErrorRate.json b/health_rules/Application/BusinessTransaction-ErrorRate.json similarity index 100% rename from healthrules/Application/BusinessTransaction-ErrorRate.json rename to health_rules/Application/BusinessTransaction-ErrorRate.json diff --git a/healthrules/Application/BusinessTransaction-ResponseTime.json b/health_rules/Application/BusinessTransaction-ResponseTime.json similarity index 100% rename from healthrules/Application/BusinessTransaction-ResponseTime.json rename to health_rules/Application/BusinessTransaction-ResponseTime.json diff --git a/healthrules/Application/RemoteService-ErrorRate.json b/health_rules/Application/RemoteService-ErrorRate.json similarity index 100% rename from healthrules/Application/RemoteService-ErrorRate.json rename to health_rules/Application/RemoteService-ErrorRate.json diff --git a/healthrules/Application/RemoteService-ResponseTime.json b/health_rules/Application/RemoteService-ResponseTime.json similarity index 100% rename from healthrules/Application/RemoteService-ResponseTime.json rename to health_rules/Application/RemoteService-ResponseTime.json diff --git a/healthrules/Application/ServiceEndPoint-ErrorRate.json b/health_rules/Application/ServiceEndPoint-ErrorRate.json similarity index 100% rename from healthrules/Application/ServiceEndPoint-ErrorRate.json rename to health_rules/Application/ServiceEndPoint-ErrorRate.json diff --git a/healthrules/Application/ServiceEndPoint-ResponseTime.json b/health_rules/Application/ServiceEndPoint-ResponseTime.json similarity index 100% rename from healthrules/Application/ServiceEndPoint-ResponseTime.json rename to health_rules/Application/ServiceEndPoint-ResponseTime.json diff --git a/healthrules/Application/Tiers-ErrorRate.json b/health_rules/Application/Tiers-ErrorRate.json similarity index 100% rename from healthrules/Application/Tiers-ErrorRate.json rename to health_rules/Application/Tiers-ErrorRate.json diff --git a/healthrules/Application/Tiers-ResponseTime.json b/health_rules/Application/Tiers-ResponseTime.json similarity index 100% rename from healthrules/Application/Tiers-ResponseTime.json rename to health_rules/Application/Tiers-ResponseTime.json diff --git a/healthrules/ServerVisibility/CpuUtilisationTooHigh.json b/health_rules/ServerVisibility/CpuUtilisationTooHigh.json similarity index 100% rename from healthrules/ServerVisibility/CpuUtilisationTooHigh.json rename to health_rules/ServerVisibility/CpuUtilisationTooHigh.json diff --git a/healthrules/ServerVisibility/MemoryUtilisationTooHigh.json b/health_rules/ServerVisibility/MemoryUtilisationTooHigh.json similarity index 100% rename from healthrules/ServerVisibility/MemoryUtilisationTooHigh.json rename to health_rules/ServerVisibility/MemoryUtilisationTooHigh.json diff --git a/kubernetes/cma-configmap.yaml b/kubernetes/cma-configmap.yaml index e88ea36..a30bd33 100644 --- a/kubernetes/cma-configmap.yaml +++ b/kubernetes/cma-configmap.yaml @@ -14,12 +14,21 @@ data: #CMA_BACKGROUND_NAME: "bg.png" #CMA_DATABASE_NAME: ConfigMyApp #CMA_INCLUDE_DATABASE: "true" - #CMA_OVERWRITE_HEALTH_RULES: "true" #CMA_PROXY_PORT: "8080" #CMA_PROXY_URL: localhost #CMA_USE_ENCODED_CREDENTIALS: "false" #CMA_USE_PROXY: "false" #CMA_BT_ONLY + #CMA_HEALTH_RULES_ONLY: "false" + #CMA_HEALTH_RULES_OVERWRITE: "true" + #CMA_HEALTH_RULES_DELETE + #CMA_SUPPRESS_ACTION=false + #CMA_SUPPRESS_START=2020-01-31T12:00:00+0000 + #CMA_SUPPRESS_DURATION=60 + #CMA_SUPPRESS_NAME="Action Suppression" + #CMA_SUPPRESS_UPLOAD_FILES=false + #CMA_SUPPRESS_DELETE=false + kind: ConfigMap metadata: creationTimestamp: null diff --git a/modules/actions/.gitkeep b/modules/actions/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/modules/health_rules/delete_health_rules.sh b/modules/health_rules/delete_health_rules.sh new file mode 100755 index 0000000..34f79d5 --- /dev/null +++ b/modules/health_rules/delete_health_rules.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +# 1. INPUT PARAMETERS +_controller_url=${1} # hostname + /controller +_user_credentials=${2} # ${username}:${password} + +_application_name=${3} +_proxy_details=${4} + +_health_rules_delete=${5} + +# 2. FUNCTIONS +function func_check_http_status() { + local http_code=$1 + local message_on_failure=$2 + #echo "HTTP status code: $http_code" + if [[ $http_code -lt 200 ]] || [[ $http_code -gt 299 ]]; then + echo "${dt} ERROR "{$http_code: $message_on_failure}"" >> error.log + echo "$http_code: $message_on_failure" + func_cleanup + exit 1 + fi +} + +function func_delete_health_rules(){ + local appId=$1 + local healthRulesToDelete="$2" + + # get all current health rules for application + allHealthRules=$(curl -s --user ${_user_credentials} ${_controller_url}/alerting/rest/v1/applications/${appId}/health-rules ${_proxy_details}) + + echo $healthRulesToDelete | sed -n 1'p' | tr ',' '\n' | while read hrName; do + echo "Deleting '$hrName' health rule..." + + # get health rule id (if exists) + healthRuleId=$(jq --arg hrName "$hrName" '.[] | select(.name == $hrName) | .id' <<<$allHealthRules) + + # delete if health rule exists + if [ ! -z "${healthRuleId// }" ]; then + httpCode=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE --user ${_user_credentials} ${_controller_url}/alerting/rest/v1/applications/${appId}/health-rules/${healthRuleId} ${_proxy_details}) + func_check_http_status $httpCode "Error occured while deleting health rule '${hrName}'." + echo "done" + else + echo "Health rule '$hrName' not found. No action performed." + fi + + done +} + +# 3. PREPARE +# check if App exist +allApplications=$(curl -s --user ${_user_credentials} ${_controller_url}/rest/applications?output=JSON $_proxy_details) + +applicationObject=$(jq --arg appName "$_application_name" '.[] | select(.name == $appName)' <<<$allApplications) + +if [ "$applicationObject" = "" ]; then + func_check_http_status 404 "Application '"$_application_name"' not found. Aborting..." +fi + +appId=$(jq '.id' <<<$applicationObject) + +#All conditions met.. + +# 4. EXECUTE +func_delete_health_rules $appId "${_health_rules_delete}" \ No newline at end of file diff --git a/modules/health_rules/upload_health_rules.sh b/modules/health_rules/upload_health_rules.sh new file mode 100755 index 0000000..30828db --- /dev/null +++ b/modules/health_rules/upload_health_rules.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +# 1. INPUT PARAMETERS +_controller_url=${1} # hostname + /controller +_user_credentials=${2} # ${username}:${password} + +_application_name=${3} +_proxy_details=${4} + +_health_rules_overwrite=${5} +_include_sim=${6} + +#init HR templates +serverVizHealthRuleFile="./health_rules/ServerVisibility/*.json" +applicationHealthRule="./health_rules/Application/*.json" + +# 2. FUNCTIONS +function func_check_http_status() { + local http_code=$1 + local message_on_failure=$2 + #echo "HTTP status code: $http_code" + if [[ $http_code -lt 200 ]] || [[ $http_code -gt 299 ]]; then + echo "${dt} ERROR "{$http_code: $message_on_failure}"" >> error.log + echo "$http_code: $message_on_failure" + exit 1 + fi +} + +function func_import_health_rules(){ + local appId=$1 + local folderPath=$2 + + # get all current health rules for application + allHealthRules=$(curl -s --user ${_user_credentials} ${_controller_url}/alerting/rest/v1/applications/${appId}/health-rules ${_proxy_details}) + + for f in $folderPath; do + echo "Processing $f health rule template" + # get health rule name from json file + healthRuleName=$(jq -r '.name' <$f) + # use it to get health rule id (if exists) + healthRuleId=$(jq --arg hrName "$healthRuleName" '.[] | select(.name == $hrName) | .id' <<<$allHealthRules) + + # create new if health rule id does not exist + if [ "${healthRuleId}" == "" ]; then + httpCode=$(curl -s -o /dev/null -w "%{http_code}" -X POST --user ${_user_credentials} ${_controller_url}/alerting/rest/v1/applications/${appId}/health-rules --header "Content-Type: application/json" --data "@${f}" ${_proxy_details}) + func_check_http_status $httpCode "Error occured while importing health rule ${healthRuleName}." + # overwrite existing health rule only if flag is true + elif [ "${_health_rules_overwrite}" = true ]; then + httpCode=$(curl -s -o /dev/null -w "%{http_code}" -X PUT --user ${_user_credentials} ${_controller_url}/alerting/rest/v1/applications/${appId}/health-rules/${healthRuleId} --header "Content-Type: application/json" --data "@${f}" ${_proxy_details}) + func_check_http_status $httpCode "Error occured while importing server rule ${healthRuleName}." + fi + + done +} + +# 3. PREPARE +# check if App exist +allApplications=$(curl -s --user ${_user_credentials} ${_controller_url}/rest/applications?output=JSON $_proxy_details) + +applicationObject=$(jq --arg appName "$_application_name" '.[] | select(.name == $appName)' <<<$allApplications) + +if [ "$applicationObject" = "" ]; then + func_check_http_status 404 "Application '"$_application_name"' not found. Aborting..." +fi + +appId=$(jq '.id' <<<$applicationObject) + +#All conditions met.. + +# 4. EXECUTE + +# Server Visibility health rules +if [ "${_include_sim}" = true ]; then + echo "Creating Server Visibility Health Rules...Please wait" + echo "" + + func_import_health_rules $appId "${serverVizHealthRuleFile}" +fi + +# Application health rules +echo "" +echo "Creating ${_application_name} Health Rules..." +sleep 1 + +func_import_health_rules $appId "${applicationHealthRule}" + + + + diff --git a/start.sh b/start.sh index f18022b..e105db5 100755 --- a/start.sh +++ b/start.sh @@ -27,7 +27,7 @@ begins_with_short_option() # THE DEFAULTS INITIALIZATION - OPTIONALS _arg_use_encoded_credentials=false -_arg_overwrite_health_rules=true + _arg_controller_host= _arg_controller_port=8090 @@ -49,6 +49,10 @@ _arg_configure_bt=false _arg_bt_only=false +_arg_health_rules_only=false +_arg_health_rules_overwrite=true +_arg_health_rules_delete= + _arg_use_branding=true _arg_logo_name= _arg_background_name= @@ -66,7 +70,6 @@ _arg_debug=false _arg_controller_port_explicitly_set=false _arg_use_encoded_credentials_explicitly_set=false -_arg_overwrite_health_rules_explicitly_set=false _arg_use_https_explicitly_set=false _arg_account_explicitly_set=false _arg_use_proxy_explicitly_set=false @@ -78,6 +81,9 @@ _arg_bt_only_explicitly_set=false _arg_suppress_action_explicitly_set=false _arg_suppress_upload_files_explicitly_set=false _arg_upload_custom_dashboard_explicitly_set=false +_arg_health_rules_only_explicitly_set=false +_arg_health_rules_overwrite_explicitly_set=false + print_help() { @@ -112,9 +118,14 @@ print_help() printf '\t%s\n' "-d, --database-name: mandatory if include-database set to true (no default)" printf '\t%s\n' "-s, --include-sim, --no-include-sim: include server visibility (${_arg_include_sim} by default)" printf '\t%s\n' "-b, --configure-bt, --no-configure-bt: configure busness transactions (${_arg_configure_bt} by default)" - printf '\t%s\n' "--overwrite-health-rules, --no-overwrite-health-rules: overwrite health rules (${_arg_overwrite_health_rules} by default)" + #printf '\t%s\n' "--health-rules-overwrite, --no-health-rules-overwrite: overwrite health rules (${_arg_health_rules_overwrite} by default)" printf '\t%s\n' "--bt-only, --no-bt-only: Configure business transactions only (${_arg_bt_only} by default)" + printf '%s\n' "Health rules options:" + printf '\t%s\n' "--health-rules-only, --no-health-rules-only: configure health rules only (${_arg_health_rules_only} by default)" + printf '\t%s\n' "--health-rules-overwrite, --no-health-rules-overwrite: overwrite health rules if exist (${_arg_health_rules_overwrite} by default)" + printf '\t%s\n' "--health-rules-delete: health rule names to delete, array of strings (no default)" + printf '%s\n' "Action suppression options:" printf '\t%s\n' "--suppress-action, --no-suppress-action: use application action suppression (${_arg_suppress_action} by default)" printf '\t%s\n' "--suppress-start: application suppression start date in \"yyyy-MM-ddThh:mm:ss+0000\" format (GMT) (current datetime by default)" @@ -145,11 +156,6 @@ parse_commandline() _arg_use_encoded_credentials=true test "${1:0:5}" = "--no-" && _arg_use_encoded_credentials=false ;; - --no-overwrite-health-rules|--overwrite-health-rules) - _arg_overwrite_health_rules_explicitly_set=true - _arg_overwrite_health_rules=true - test "${1:0:5}" = "--no-" && _arg_overwrite_health_rules=false - ;; --no-bt-only|--bt-only) _arg_bt_only_explicitly_set=true _arg_bt_only=true @@ -311,6 +317,24 @@ parse_commandline() --background-name=*) _arg_background_name="${_key##--background-name=}" ;; + --no-health-rules-only|--health-rules-only) + _arg_health_rules_only=true + _arg_health_rules_only_explicitly_set=true + test "${1:0:5}" = "--no-" && _arg_health_rules_only=false + ;; + --no-health-rules-overwrite|--health-rules-overwrite) + _arg_health_rules_overwrite=true + _arg_health_rules_overwrite_explicitly_set=true + test "${1:0:5}" = "--no-" && _arg_health_rules_overwrite=false + ;; + --health-rules-delete) + test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1 + _arg_health_rules_delete="$2" + shift + ;; + --health-rules-delete=*) + _arg_health_rules_delete="${_key##--health-rules-delete=}" + ;; --no-suppress-action|--suppress-action) _arg_suppress_action=true _arg_suppress_action_explicitly_set=true @@ -415,9 +439,13 @@ handle_expected_values_for_args() if ([ ! $_arg_use_encoded_credentials = false ] && [ ! $_arg_use_encoded_credentials = true ] ); then _PRINT_HELP=no die "FATAL ERROR: -use-encoded-credentials value \"${_arg_use_encoded_credentials}\" not recognized" 1 fi + + if ([ ! $_arg_health_rules_only = false ] && [ ! $_arg_health_rules_only = true ] ); then + _PRINT_HELP=no die "FATAL ERROR: --health-rules-only value \"${_arg_health_rules_only}\" not recognized" 1 + fi - if ([ ! $_arg_overwrite_health_rules = false ] && [ ! $_arg_overwrite_health_rules = true ] ); then - _PRINT_HELP=no die "FATAL ERROR: --overwrite-health-rules value \"${_arg_overwrite_health_rules}\" not recognized" 1 + if ([ ! $_arg_health_rules_overwrite = false ] && [ ! $_arg_health_rules_overwrite = true ] ); then + _PRINT_HELP=no die "FATAL ERROR: --health-rules-overwrite value \"${_arg_health_rules_overwrite}\" not recognized" 1 fi if ([ ! $_arg_use_https = false ] && [ ! $_arg_use_https = true ] ); then @@ -461,9 +489,6 @@ parse_commandline "$@" if ([ $_arg_use_encoded_credentials_explicitly_set = false ] && [ ! -z "${CMA_USE_ENCODED_CREDENTIALS// }" ]); then _arg_use_encoded_credentials=${CMA_USE_ENCODED_CREDENTIALS} fi -if ([ $_arg_overwrite_health_rules_explicitly_set = false ] && [ ! -z "${CMA_OVERWRITE_HEALTH_RULES// }" ]); then - _arg_overwrite_health_rules=${CMA_OVERWRITE_HEALTH_RULES} -fi # controller if ([ -z "${_arg_controller_host// }" ] && [ ! -z "${CMA_CONTROLLER_HOST// }" ]); then @@ -529,6 +554,22 @@ if ([ $_arg_bt_only_explicitly_set = false ] && [ ! -z "${CMA_BT_ONLY// }" ]); t _arg_bt_only=${CMA_BT_ONLY} fi +# health rules +if ([[ $_arg_health_rules_only_explicitly_set = false ]] && [ ! -z "${CMA_HEALTH_RULES_ONLY// }" ]); then + _arg_health_rules_only=${CMA_HEALTH_RULES_ONLY} +fi +# backwards compatability for varaible name +if ([[ $_arg_health_rules_overwrite_explicitly_set = false ]] && [ -z "${CMA_OVERWRITE_HEALTH_RULES// }" ]); then + _arg_health_rules_overwrite=${CMA_OVERWRITE_HEALTH_RULES} +fi +# but override with newer version if provided +if ([[ $_arg_health_rules_overwrite_explicitly_set = false ]] && [ ! -z "${CMA_HEALTH_RULES_OVERWRITE// }" ]); then + _arg_health_rules_overwrite=${CMA_HEALTH_RULES_OVERWRITE} +fi +if ([[ -z "${_arg_health_rules_delete// }" ]] && [ ! -z "${CMA_HEALTH_RULES_DELETE// }" ]); then + _arg_health_rules_delete=${CMA_HEALTH_RULES_DELETE} +fi + # action suppression if ([ $_arg_suppress_action_explicitly_set = false ] && [ ! -z "${CMA_SUPPRESS_ACTION// }" ]); then _arg_suppress_action=${CMA_SUPPRESS_ACTION} @@ -562,9 +603,9 @@ conf_file="config.json" if ([ $_arg_use_encoded_credentials_explicitly_set = false ] && [ -z "${CMA_USE_ENCODED_CREDENTIALS}" ]); then _arg_use_encoded_credentials=$(jq -r '.are_passwords_encoded' <${conf_file}) fi -if ([ $_arg_overwrite_health_rules_explicitly_set = false ] && [ -z "${CMA_OVERWRITE_HEALTH_RULES}" ]); then - _arg_overwrite_health_rules=$(jq -r '.overwrite_health_rules' <${conf_file}) -fi +# if ([ $_arg_health_rules_overwrite_explicitly_set = false ] && [ -z "${CMA_OVERWRITE_HEALTH_RULES}" ]); then +# _arg_health_rules_overwrite=$(jq -r '.overwrite_health_rules' <${conf_file}) +# fi # controller if [[ -z "${_arg_controller_host// }" ]]; then @@ -632,6 +673,17 @@ if ([[ $_arg_bt_only_explicitly_set = false ]] && [ -z "${CMA_BT_ONLY// }" ]); t _arg_bt_only=$(jq -r '.configuration[].bt_only' <${conf_file}) fi +# health rules +if ([[ $_arg_health_rules_only_explicitly_set = false ]] && [ -z "${CMA_HEALTH_RULES_ONLY// }" ]); then + _arg_health_rules_only=$(jq -r '.health_rules[].health_rules_only' <${conf_file}) +fi +if ([[ $_arg_health_rules_overwrite_explicitly_set = false ]] && [ -z "${CMA_HEALTH_RULES_OVERWRITE// }" ]); then + _arg_health_rules_overwrite=$(jq -r '.health_rules[].health_rules_overwrite' <${conf_file}) +fi +if [[ -z "${_arg_health_rules_delete// }" ]]; then + _arg_health_rules_delete=$(jq -r '.health_rules[].health_rules_delete' <${conf_file}) +fi + # action suppression if ([[ $_arg_suppress_action_explicitly_set = false ]] && [ -z "${CMA_SUPPRESS_ACTION// }" ]); then _arg_suppress_action=$(jq -r '.action_suppression[].suppress_action' <${conf_file}) @@ -674,7 +726,7 @@ handle_mandatory_args if [ $_arg_debug = true ]; then echo "Value of --use-encoded-credentials: $_arg_use_encoded_credentials" - echo "Value of --overwrite-health-rules: $_arg_overwrite_health_rules" + echo "Value of --health-rules-overwrite: $_arg_health_rules_overwrite" echo "Value of --controller-host: $_arg_controller_host" echo "Value of --controller-port: $_arg_controller_port" @@ -695,6 +747,10 @@ if [ $_arg_debug = true ]; then echo "Value of --configure-bt: $_arg_configure_bt" echo "Value of --bt-only: $_arg_bt_only" + echo "Value of --health-rules-only: ${_arg_health_rules_only}" + echo "Value of --health-rules-overwrite: ${_arg_health_rules_overwrite}" + echo "Value of --health-rules-delete: ${_arg_health_rules_delete}" + echo "Value of --suppress-action: $_arg_suppress_action" echo "Value of --suppress-start: $_arg_suppress_start" echo "Value of --suppress-duration: $_arg_suppress_duration" @@ -780,7 +836,7 @@ fi if [ $_arg_suppress_upload_files = true ]; then ./api_actions/upload-files-action-suppression.sh "$_arg_controller_url" "$_arg_user_credentials" "$_arg_proxy_details" "$_arg_application_name" - exit 0 # only upload files + exit 0 # only upload action suppression files fi if [[ ! -z "${_arg_suppress_delete// }" ]]; then @@ -788,15 +844,26 @@ if [[ ! -z "${_arg_suppress_delete// }" ]]; then exit 0 # only delete action suppression fi -### 5 ACTION SUPRESSION ### +### 5 CUSTOM DASHBOARDS ### if [ $_arg_upload_custom_dashboard = true ]; then ./dashboards/upload_custom_dashboard.sh "$_arg_controller_url" "$_arg_user_credentials" "$_arg_application_name" "$_arg_proxy_details" "$_arg_debug" - exit 0 # only upload files + exit 0 # only upload custom dahboard files +fi + +### 6 HEALTH RULES ### +if [ $_arg_health_rules_only = true ]; then + ./modules/health_rules/upload_health_rules.sh "$_arg_controller_url" "$_arg_user_credentials" "$_arg_application_name" "$_arg_proxy_details" "$_arg_health_rules_overwrite" "$_arg_include_sim" + exit 0 # only upload health rules +fi + +if [ ! -z "${_arg_health_rules_delete// }" ]; then + ./modules/health_rules/delete_health_rules.sh "$_arg_controller_url" "$_arg_user_credentials" "$_arg_application_name" "$_arg_proxy_details" "$_arg_health_rules_delete" + exit 0 # only delete health rules fi ### 6 EXECUTE CMA SCRIPT ### -./configMyApp.sh "$_arg_controller_url" "$_arg_user_credentials" "$_arg_proxy_details" "$_arg_application_name" "$_arg_include_database" "$_arg_database_name" "$_arg_include_sim" "$_arg_configure_bt" "$_arg_overwrite_health_rules" "$_arg_bt_only" "$_arg_use_branding" "$_arg_logo_name" "$_arg_background_name" +./configMyApp.sh "$_arg_controller_url" "$_arg_user_credentials" "$_arg_proxy_details" "$_arg_application_name" "$_arg_include_database" "$_arg_database_name" "$_arg_include_sim" "$_arg_configure_bt" "$_arg_health_rules_overwrite" "$_arg_bt_only" "$_arg_use_branding" "$_arg_logo_name" "$_arg_background_name" - # <-- needed, do not delete -# ] <-- needed, do not delete \ No newline at end of file +# ] <-- needed, do not delete + # <-- needed, do not delete \ No newline at end of file