Skip to content

Commit

Permalink
microservices health rules (#32)
Browse files Browse the repository at this point in the history
* 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

Co-authored-by: alex_jov <aleksjovovic@gmail.com>
  • Loading branch information
iogbole and AlexJov committed Aug 11, 2020
1 parent efe90e4 commit f0c2b95
Show file tree
Hide file tree
Showing 11 changed files with 265 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Setup/Applications/*
.vscode/*
zz_demoflow*
business_transactions/uploaded/*
api_actions/uploaded/*.json
9 changes: 9 additions & 0 deletions api_actions/action-suppression-payload-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "_action_suppression_name",
"disableAgentReporting": true,
"startTime": "_action_suppression_start",
"endTime": "_action_suppression_end",
"affects": {
"affectedInfoType": "APPLICATION"
}
}
17 changes: 17 additions & 0 deletions api_actions/actions/tiers_action.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "CMA-suppression-tiers-nodes-test",
"disableAgentReporting": true,
"startTime": "2020-09-06T18:33:14+0000",
"endTime": "2020-09-06T19:33:14+0000",
"affects": {
"affectedInfoType": "TIERS_NODES",
"affectedEntities": {
"tierNodeType": "NODE",
"nodeType": "ALL_NODES",
"affectedNodes": {
"affectedNodeScope": "NODES_OF_SPECIFIC_TIERS",
"specificTiers": ["Web"]
}
}
}
}
68 changes: 68 additions & 0 deletions api_actions/application-action-suppression.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

# 1. INPUT PARAMETERS
_controller_url=${1} # hostname + /controller
_user_credentials=${2} # ${username}:${password}

_action_suppression_start=${3}
_action_suppression_duration=${4}

_application_name=${5}

# 2. FUNCTIONS
function func_check_http_response(){
local http_message_body="$1"
local string_success_response_contains="$2"
if [[ "$http_message_body" =~ "$string_success_response_contains" ]]; then # contains
echo "Success..."
else
echo "${dt} ERROR "{$http_message_body}"" >> error.log
echo "ERROR $http_message_body"
exit 1
fi
}

# 3. PREPARE REQUEST
dt=$(date '+%Y-%m-%d_%H-%M-%S')

_payload_path="./api_actions/uploaded/action-suppression-payload-${dt}.json"
_template_path="./api_actions/action-suppression-payload-template.json"

_header="Content-Type: application/json; charset=utf8"

_action_suppression_name="CMA-suppression-${dt}"


echo | date -d "today" >/dev/null 2>&1
if [ $? -eq 0 ]; then
# GNU
_action_suppression_end=$(date -d "${_action_suppression_start} +${_action_suppression_duration} minutes" "+%FT%T+0000")
else
# Mac
_action_suppression_end=$(date -j -v +${_action_suppression_duration}M -f "%Y-%M-%dT%H:%M:%S+0000" "${_action_suppression_start}" "+%FT%T+0000")
fi

# populate the payload template
sed -e "s/_action_suppression_name/${_action_suppression_name}/g" -e "s/_action_suppression_start/${_action_suppression_start}/g" -e "s/_action_suppression_end/${_action_suppression_end}/g" "${_template_path}" > "${_payload_path}"

# application id
allApplications=$(curl -s --user ${_user_credentials} ${_controller_url}/rest/applications?output=JSON)

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

application_id=$(jq '.id' <<< $applicationObject)
_resource_url="alerting/rest/v1/applications/${application_id}/action-suppressions"

# 4. SEND A CREATE REQUEST
echo "Uploading application supression action"
response=$(curl -s -X POST --user $_user_credentials $_controller_url/$_resource_url -H "${_header}" --data "@${_payload_path}" )

# 5. CHECK RESULT
expected_response='"id":' # returns id on success
func_check_http_response "\{$response}" $expected_response

#echo "response is: $response"
59 changes: 59 additions & 0 deletions api_actions/upload-files-action-suppression.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

# 1. INPUT PARAMETERS
_controller_url=${1} # hostname + /controller
_user_credentials=${2} # ${username}:${password}

_application_name=${3}

# 2. FUNCTIONS
function func_check_http_response(){
local http_message_body="$1"
local string_success_response_contains="$2"
if [[ "$http_message_body" =~ "$string_success_response_contains" ]]; then # contains
echo "Success..."
else
echo "${dt} ERROR "{$http_message_body}"" >> error.log
echo "ERROR $http_message_body"
#exit 1
fi
}

# 3. PREPARE REQUEST
dt=$(date '+%Y-%m-%d_%H-%M-%S')

_header="Content-Type: application/json; charset=utf8"


# application id
allApplications=$(curl -s --user ${_user_credentials} ${_controller_url}/rest/applications?output=JSON)

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

_application_id=$(jq '.id' <<< $applicationObject)
_resource_url="alerting/rest/v1/applications/${_application_id}/action-suppressions"

_action_suppression_files="./api_actions/actions/*.json"


for f in $_action_suppression_files; do
echo "Processing $f action suppression file"

_payload_path=$f

# 4. SEND A CREATE REQUEST
response=$(curl -s -X POST --user $_user_credentials $_controller_url/$_resource_url -H "${_header}" --data "@${_payload_path}" )

# 5. CHECK RESULT
expected_response='"id":' # returns id on success
func_check_http_response "\{$response}" $expected_response

# echo "response is: $response"

done


8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,13 @@
"configure_bt": false,
"bt_only": false
}
],
"action_suppression": [
{
"suppress_action": false,
"suppress_start": "",
"suppress_duration": "",
"suppress_upload_files": false
}
]
}
2 changes: 1 addition & 1 deletion dashboards/CustomDashboard_noDB_noSIM_vanilla.json
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@
"width": 372,
"minHeight": 0,
"minWidth": 0,
"x": 133,
"x": 105,
"y": 0,
"label": null,
"description": null,
Expand Down
2 changes: 1 addition & 1 deletion dashboards/CustomDashboard_noDB_vanilla.json
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@
"width": 372,
"minHeight": 0,
"minWidth": 0,
"x": 133,
"x": 105,
"y": 0,
"label": null,
"description": null,
Expand Down
2 changes: 1 addition & 1 deletion dashboards/CustomDashboard_noSIM_vanilla.json
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@
"width": 372,
"minHeight": 0,
"minWidth": 0,
"x": 133,
"x": 105,
"y": 0,
"label": null,
"description": null,
Expand Down
2 changes: 1 addition & 1 deletion dashboards/CustomDashboard_vanilla.json
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@
"width": 372,
"minHeight": 0,
"minWidth": 0,
"x": 133,
"x": 105,
"y": 0,
"label": null,
"description": null,
Expand Down
103 changes: 99 additions & 4 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,14 @@ _arg_use_branding=true
_arg_logo_name=
_arg_background_name=

_arg_suppress_action=false
_arg_suppress_start=
_arg_suppress_duration=
_arg_suppress_upload_files=false

_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
Expand All @@ -65,6 +71,8 @@ _arg_include_sim_explicitly_set=false
_arg_configure_bt_explicitly_set=false
_arg_use_branding_explicitly_set=false
_arg_bt_only_explicitly_set=false
_arg_suppress_action_explicitly_set=false
_arg_suppress_upload_files_explicitly_set=false

print_help()
{
Expand Down Expand Up @@ -102,6 +110,12 @@ print_help()
printf '\t%s\n' "--overwrite-health-rules, --no-overwrite-health-rules: overwrite health rules (${_arg_overwrite_health_rules} by default)"
printf '\t%s\n' "--bt-only, --no-bt-only: Configure business transactions only (${_arg_bt_only} by 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), mandatory if suppress-action set to true (current datetime by default)"
printf '\t%s\n' "--suppress-duration: application suppression duration in minutes, mandatory if suppress-action is set to true (one hour by default)"
printf '\t%s\n' "--suppress-upload-files, --no-suppress-upload-files: upload action suppression files from a folder (${_arg_suppress_upload_files} by default)"

printf '%s\n' "Help options:"
printf '\t%s\n' "-h, --help: Prints help"
printf '\t%s\n' "--debug, --no-debug: Run in debug mode (${_arg_debug} by default)"
Expand Down Expand Up @@ -141,6 +155,7 @@ parse_commandline()
_arg_controller_host="${_key##-c}"
;;
-P|--controller-port)
_arg_controller_port_explicitly_set=true
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_controller_port="$2"
shift
Expand Down Expand Up @@ -282,6 +297,32 @@ parse_commandline()
--background-name=*)
_arg_background_name="${_key##--background-name=}"
;;
--no-suppress-action|--suppress-action)
_arg_suppress_action=true
_arg_suppress_action_explicitly_set=true
test "${1:0:5}" = "--no-" && _arg_suppress_action=false
;;
--suppress-start)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_suppress_start="$2"
shift
;;
--suppress-start=*)
_arg_suppress_start="${_key##--suppress-start=}"
;;
--suppress-duration)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_suppress_duration="$2"
shift
;;
--suppress-duration=*)
_arg_suppress_duration="${_key##--suppress-duration=}"
;;
--no-suppress-upload-files|--suppress-upload-files)
_arg_suppress_upload_files=true
_arg_suppress_upload_files_explicitly_set=true
test "${1:0:5}" = "--no-" && _arg_suppress_upload_files=false
;;
-h|--help)
print_help
exit 0
Expand Down Expand Up @@ -393,7 +434,7 @@ fi
if ([ -z "${_arg_controller_host// }" ] && [ ! -z "${CMA_CONTROLLER_HOST// }" ]); then
_arg_controller_host=${CMA_CONTROLLER_HOST}
fi
if ([ -z "${_arg_controller_port// }" ] && [ ! -z "${CMA_CONTROLLER_PORT// }" ]); then
if ([ $_arg_controller_port_explicitly_set = false ] && [ ! -z "${CMA_CONTROLLER_PORT// }" ]); then
_arg_controller_port=${CMA_CONTROLLER_PORT}
fi
if ([ $_arg_use_https_explicitly_set = false ] && [ ! -z "${CMA_USE_HTTPS// }" ]); then
Expand Down Expand Up @@ -453,6 +494,21 @@ if ([ $_arg_bt_only_explicitly_set = false ] && [ ! -z "${CMA_BT_ONLY// }" ]); t
_arg_bt_only=${CMA_BT_ONLY}
fi

# action suppression
if ([ $_arg_suppress_action_explicitly_set = false ] && [ ! -z "${CMA_SUPPRESS_ACTION// }" ]); then
_arg_suppress_action=${CMA_SUPPRESS_ACTION}
fi
if ([ -z "${_arg_suppress_start// }" ] && [ ! -z "${CMA_SUPPRESS_START// }" ]); then
_arg_suppress_start=${CMA_SUPPRESS_START}
fi
if ([ -z "${_arg_suppress_duration// }" ] && [ ! -z "${CMA_SUPPRESS_DURATION// }" ]); then
_arg_suppress_duration=${CMA_SUPPRESS_DURATION}
fi
if ([ $_arg_suppress_upload_files_explicitly_set = false ] && [ ! -z "${CMA_SUPPRESS_UPLOAD_FILES// }" ]); then
_arg_suppress_upload_files=${CMA_SUPPRESS_UPLOAD_FILES}
fi


# 1.3 If value not set replace with configuration file values
conf_file="config.json"

Expand All @@ -470,7 +526,7 @@ if [[ -z "${_arg_controller_host// }" ]]; then
_arg_controller_host=$(jq -r '.controller_details[].host' <${conf_file})
fi

if [[ -z "${_arg_controller_port// }" ]]; then
if ([ $_arg_controller_port_explicitly_set = false ] && [ -z "${CMA_CONTROLLER_PORT}" ]); then
_arg_controller_port=$(jq -r '.controller_details[].port' <${conf_file})
fi

Expand Down Expand Up @@ -531,6 +587,19 @@ if ([[ $_arg_bt_only_explicitly_set = false ]] && [ -z "${CMA_BT_ONLY// }" ]); t
_arg_bt_only=$(jq -r '.configuration[].bt_only' <${conf_file})
fi

if ([[ $_arg_suppress_action_explicitly_set = false ]] && [ -z "${CMA_SUPPRESS_ACTION// }" ]); then
_arg_suppress_action=$(jq -r '.action_suppression[].suppress_action' <${conf_file})
fi
if [[ -z "${_arg_suppress_start// }" ]]; then
_arg_suppress_start=$(jq -r '.action_suppression[].suppress_start' <${conf_file})
fi
if [[ -z "${_arg_suppress_duration// }" ]]; then
_arg_suppress_duration=$(jq -r '.action_suppression[].suppress_duration' <${conf_file})
fi
if ([[ $_arg_suppress_upload_files_explicitly_set = false ]] && [ -z "${CMA_SUPPRESS_UPLOAD_FILES// }" ]); then
_arg_suppress_upload_files=$(jq -r '.action_suppression[].suppress_upload_files' <${conf_file})
fi

### 2 VALIDATE ###

# 2.1 Check if values are in expected ranges
Expand Down Expand Up @@ -575,7 +644,7 @@ if [ $_arg_debug = true ]; then

fi

### 3 PREPARE PARAMETERS AND EXECUTE SCRIPT ###
### 3 PREPARE PARAMETERS ###

# 3.1 Prepare user credentials

Expand Down Expand Up @@ -625,8 +694,34 @@ if [ $_arg_debug = true ]; then
echo "Configure BTs: $_arg_configure_bt"
fi

# 3.4 Execute ConfigMyApp script
# 3.5 Prepare action supression
if [ $_arg_suppress_action = true ]; then
if [ -z "${_arg_suppress_start// }" ]; then
# set to current datetime if empty
# UTC / GMT
_arg_suppress_start=$(date -u +%FT%T+0000)
fi
if [ -z "${_arg_suppress_duration// }" ]; then
# set to one hour if empty
_arg_suppress_duration=60
fi
fi

### 4 ACTION SUPRESSION ###
if [ $_arg_suppress_action = true ]; then
./api_actions/application-action-suppression.sh "$_arg_controller_url" "$_arg_user_credentials" "$_arg_suppress_start" "$_arg_suppress_duration" "$_arg_application_name"

fi

if [ $_arg_suppress_upload_files = true ]; then
./api_actions/upload-files-action-suppression.sh "$_arg_controller_url" "$_arg_user_credentials" "$_arg_application_name"
exit 0 # only upload files
fi


### 5 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"


# <-- needed, do not delete
# ] <-- needed, do not delete

0 comments on commit f0c2b95

Please sign in to comment.