Skip to content

Commit

Permalink
Features/health rules only (#38)
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;

* 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
AlexJov and iogbole committed Nov 24, 2020
1 parent 07d14b8 commit b0eaf35
Show file tree
Hide file tree
Showing 21 changed files with 325 additions and 69 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/QAConfigMyApp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ ConfigMyApp is wrapper on supported AppDynamics RESTful APIs.
# Official Documentation

Please refer to the <a href="https://appdynamics.github.io/ConfigMyApp" target="_blank"> official documentation </a> for further details

# Generate input parameters

https://argbash.io/generate
8 changes: 7 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"overwrite_health_rules": false,
"are_passwords_encoded": false,

"branding": [
Expand Down Expand Up @@ -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,
Expand Down
46 changes: 3 additions & 43 deletions configMyApp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -255,28 +228,15 @@ 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
echo "done"

echo ""
echo "Processing Dashboard Template."
sleep 1
echo ""

# Dashboard
Expand Down
12 changes: 11 additions & 1 deletion docker/env.list
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion kubernetes/cma-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file added modules/actions/.gitkeep
Empty file.
65 changes: 65 additions & 0 deletions modules/health_rules/delete_health_rules.sh
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}"
89 changes: 89 additions & 0 deletions modules/health_rules/upload_health_rules.sh
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}"




Loading

0 comments on commit b0eaf35

Please sign in to comment.