Skip to content

Commit

Permalink
Merging action suppression from Develop (#34)
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

* 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;

* Update QAConfigMyApp.yml

* Update QAConfigMyApp.yml

Co-authored-by: Israel Ogbole <iogbole@yahoo.com>
  • Loading branch information
AlexJov and iogbole committed Aug 24, 2020
1 parent 5e97ef8 commit f37a791
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 63 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/QAConfigMyApp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ jobs:
- name: TestCase4- Action suppression. Date and duration
run: |
echo Running Action Suppression,
./start.sh -a Jenkins_API -c configmyappdemo-2044no-uzyczrm0.appd-cx.com -p appd -u appd --suppress-action --suppress-start=$(date -u +%FT%T) --suppress-duration=120
./start.sh -a Jenkins_API -c configmyappdemo-2044no-uzyczrm0.appd-cx.com -p appd -u appd --suppress-action --suppress-start=$(date -d " + 5 minutes" -u +%FT%T) --suppress-duration=120
- name: TestCase4- SIM and DB
- name: TestCase5- SIM and DB
run: |
echo Running SIM and DB,
./start.sh -a IoT_API -c configmyappdemo-2044no-uzyczrm0.appd-cx.com -p appd -u appd --include-database --database-name 'ConfigMyApp' --include-sim
./start.sh -a IoT_API -c configmyappdemo-2044no-uzyczrm0.appd-cx.com -p appd -u appd --include-database --database-name 'ConfigMyApp' --include-sim
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ Setup/Applications/*
.vscode/*
zz_demoflow*
business_transactions/uploaded/*
api_actions/uploaded/*.json
api_actions/uploaded/*.json*
api_actions/actions/*.json*
Empty file added api_actions/actions/.gitkeep
Empty file.
17 changes: 0 additions & 17 deletions api_actions/actions/tiers_action.json

This file was deleted.

40 changes: 29 additions & 11 deletions api_actions/application-action-suppression.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,46 @@
_controller_url=${1} # hostname + /controller
_user_credentials=${2} # ${username}:${password}

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

_application_name=${5}
_action_suppression_start=${4}
_action_suppression_duration=${5}

_action_suppression_name=${6}
_application_name=${6}

_action_suppression_name=${7}

# 2. FUNCTIONS
function func_check_http_response(){
local http_message_body="$1"
local string_success_response_contains="$2"
local filePath="$3"
local fileName="$4"
if [[ "$http_message_body" =~ "$string_success_response_contains" ]]; then # contains
echo "Success..."
cp -rf "$filePath" "./api_actions/uploaded/${fileName}.${dt}"
echo "Success..."
else
echo "${dt} ERROR "{$http_message_body}"" >> error.log
echo "ERROR $http_message_body"
exit 1
fi
}

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 "ERROR $http_code: $message_on_failure"
exit 1
fi
}

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

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

_header="Content-Type: application/json; charset=utf8"
Expand All @@ -49,7 +65,7 @@ fi
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)
allApplications=$(curl -s --user ${_user_credentials} ${_controller_url}/rest/applications?output=JSON ${_proxy_details})

applicationObject=$(jq --arg appName "$_application_name" '.[] | select(.name == $appName)' <<<$allApplications)

Expand All @@ -60,13 +76,15 @@ 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}" )
echo "Uploading '"${_action_suppression_name}"' application supression action..."
response=$(curl -s -X POST --user $_user_credentials $_controller_url/$_resource_url -H "${_header}" --data "@${_payload_path}" ${_proxy_details} )

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

#fileName="$(basename -- $_payload_path)"
#cp -rf "$_payload_path" "./api_actions/uploaded/${fileName}.${dt}"

#echo "response is: $response"
45 changes: 31 additions & 14 deletions api_actions/delete-action-suppression.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,29 @@
_controller_url=${1} # hostname + /controller
_user_credentials=${2} # ${username}:${password}

_action_suppression_name=${3}
_proxy_details=${3}

_application_name=${4}
_action_suppression_name=${4}

# 2. PREPARE REQUEST
_application_name=${5}

# application id
allApplications=$(curl -s --user ${_user_credentials} ${_controller_url}/rest/applications?output=JSON)
# 2. FUNCTIONS
dt=$(date '+%Y-%m-%d_%H-%M-%S')

function func_check_http_status() {
local http_code=$1
local message_on_failure=$2
if [[ $http_code -lt 200 ]] || [[ $http_code -gt 299 ]]; then
echo "${dt} ERROR "{$http_code: $message_on_failure}"" >> error.log
echo "ERROR $http_code: $message_on_failure"
exit 1
fi
}

# 3. PREPARE REQUEST

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

applicationObject=$(jq --arg appName "$_application_name" '.[] | select(.name == $appName)' <<<$allApplications)

Expand All @@ -21,21 +36,23 @@ fi

application_id=$(jq '.id' <<< $applicationObject)

# suppression id
actionSupressions=$(curl -s --user ${_user_credentials} ${_controller_url}/alerting/rest/v1/applications/${application_id}/action-suppressions)
# 3.2 Get suppression id
actionSupressions=$(curl -s --user ${_user_credentials} ${_controller_url}/alerting/rest/v1/applications/${application_id}/action-suppressions ${_proxy_details})

actionSupressionObject=$(jq --arg suppressionName "$_action_suppression_name" '.[] | select(.name == $suppressionName)' <<< $actionSupressions)

if [ "$actionSupressions" = "" ]; then
if [ "$actionSupressionObject" = "" ]; then
func_check_http_status 404 "Action supression '"$_action_suppression_name"' not found. Aborting..."
fi

actionSupressionObject=$(jq --arg suppressionName "$_action_suppression_name" '.[] | select(.name == $suppressionName)' <<< $actionSupressions)

action_supression_id=$(jq '.id' <<< $actionSupressionObject)

# request url
# 3.3 Set request url
_resource_url="alerting/rest/v1/applications/${application_id}/action-suppressions/${action_supression_id}"

# 3. SEND A DELETE REQUEST
echo "Deleting application supression action"
# 4. SEND A DELETE REQUEST
echo "Deleting '"$_action_suppression_name"' application supression action..."
# response is always empty
response=$(curl -s -X DELETE --user $_user_credentials $_controller_url/$_resource_url)
response=$(curl -s -X DELETE --user $_user_credentials $_controller_url/$_resource_url ${_proxy_details})

echo "Done."
36 changes: 28 additions & 8 deletions api_actions/upload-files-action-suppression.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,33 @@
_controller_url=${1} # hostname + /controller
_user_credentials=${2} # ${username}:${password}

_application_name=${3}
_proxy_details=${3}

_application_name=${4}

# 2. FUNCTIONS
function func_check_http_response(){
local http_message_body="$1"
local string_success_response_contains="$2"
local filePath="$3"
local fileName="$4"
if [[ "$http_message_body" =~ "$string_success_response_contains" ]]; then # contains
echo "Success..."
cp -rf "$filePath" "./api_actions/uploaded/${fileName}.${dt}"
echo "Success..."
else
echo "${dt} ERROR "{$http_message_body}"" >> error.log
echo "ERROR $http_message_body"
#exit 1
# do not break on failure
fi
}

function func_check_http_status() {
local http_code=$1
local message_on_failure=$2
if [[ $http_code -lt 200 ]] || [[ $http_code -gt 299 ]]; then
echo "${dt} ERROR "{$http_code: $message_on_failure}"" >> error.log
echo "ERROR $http_code: $message_on_failure"
exit 1
fi
}

Expand All @@ -25,7 +40,7 @@ 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)
allApplications=$(curl -s --user ${_user_credentials} ${_controller_url}/rest/applications?output=JSON ${_proxy_details})

applicationObject=$(jq --arg appName "$_application_name" '.[] | select(.name == $appName)' <<<$allApplications)

Expand All @@ -36,20 +51,25 @@ fi
_application_id=$(jq '.id' <<< $applicationObject)
_resource_url="alerting/rest/v1/applications/${_application_id}/action-suppressions"

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


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

# Check if folder contains files
[ -f "$f" ] || func_check_http_status 404 "No files found that match pattern: '"$_action_suppression_files"'. Aborting..."

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}" )
response=$(curl -s -X POST --user $_user_credentials $_controller_url/$_resource_url -H "${_header}" --data "@${_payload_path}" ${_proxy_details})

# 5. CHECK RESULT
expected_response='"id":' # returns id on success
func_check_http_response "\{$response}" $expected_response
fileName="$(basename -- $f)"
func_check_http_response "\{$response}" "${expected_response}" ${_payload_path} "${fileName}"

# echo "response is: $response"

Expand Down
Empty file added api_actions/uploaded/.gitkeep
Empty file.
4 changes: 2 additions & 2 deletions configMyApp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ function func_check_http_status() {
local message_on_failure=$2
#echo "HTTP status code: $http_code"
if [[ $http_code -lt 200 ]] || [[ $http_code -gt 299 ]]; then
echo "$http_code : $message_on_failure"
echo "${dt} ERROR "{$http_code: $message_on_failure}"" >> error.log
echo "$http_code: $message_on_failure"
func_cleanup
exit 1
fi
Expand Down
15 changes: 8 additions & 7 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ print_help()

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-name: custom name of the supression action, if none specified name is auto-generated (no default)"
printf '\t%s\n' "--suppress-start: application suppression start date in \"yyyy-MM-ddThh:mm:ss+0000\" format (GMT) (current datetime by default)"
printf '\t%s\n' "--suppress-duration: application suppression duration in minutes (one hour by default)"
printf '\t%s\n' "--suppress-name: custom name of the supression action, if none specified name is auto-generated"

printf '\t%s\n' "--suppress-upload-files, --no-suppress-upload-files: upload action suppression files from a folder (${_arg_suppress_upload_files} by default)"

Expand Down Expand Up @@ -717,7 +717,7 @@ _arg_controller_url="$protocol://$_arg_controller_host:$_arg_controller_port/con
# 3.4 Prepare proxy details

if [ $_arg_use_proxy = true ]; then
_arg_proxy_details="-x $proxy_url:$proxy_port"
_arg_proxy_details="-x $_arg_proxy_url:$_arg_proxy_port"
else
_arg_proxy_details=""
fi
Expand Down Expand Up @@ -751,16 +751,17 @@ 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" "$_arg_suppress_name"
./api_actions/application-action-suppression.sh "$_arg_controller_url" "$_arg_user_credentials" "$_arg_proxy_details" "$_arg_suppress_start" "$_arg_suppress_duration" "$_arg_application_name" "$_arg_suppress_name"
exit 0 # only do action suppression
fi

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

if [[ ! -z "${_arg_suppress_delete// }" ]]; then
./api_actions/delete-action-suppression.sh "$_arg_controller_url" "$_arg_user_credentials" "$_arg_suppress_delete" "$_arg_application_name"
./api_actions/delete-action-suppression.sh "$_arg_controller_url" "$_arg_user_credentials" "$_arg_proxy_details" "$_arg_suppress_delete" "$_arg_application_name"
exit 0 # only delete action suppression
fi

Expand Down

0 comments on commit f37a791

Please sign in to comment.