-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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 <iogbole@yahoo.com>
- Loading branch information
Showing
21 changed files
with
325 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}" | ||
|
||
|
||
|
||
|
Oops, something went wrong.