Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/health rules only #38

Merged
merged 35 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
92c2794
refactor app health rules (#27)
iogbole Aug 6, 2020
e962d68
Feature/containerHealthRules (#28)
iogbole Aug 6, 2020
b1330d8
Feature/disable node hr (#29)
iogbole Aug 6, 2020
b2e95d5
microservice health rules
iogbole Aug 6, 2020
5dbd28b
Merge action-suppression and port-bugfix to develop from feature b;
AlexJov Aug 6, 2020
e128179
Add action suppression upload from file; Typos;
AlexJov Aug 7, 2020
f5be5fc
Add suppress action config;
AlexJov Aug 7, 2020
1bfc989
Add actions folder and example file;
AlexJov Aug 7, 2020
ecc6ac0
Dash layout
iogbole Aug 11, 2020
336ff65
Adding detele action suppression;
AlexJov Aug 11, 2020
def5434
Controller port as parameter takes precedence;
AlexJov Aug 11, 2020
cffd16c
Port controller;
AlexJov Aug 11, 2020
90f13e3
Merge branch 'develop' of https://github.com/Appdynamics/ConfigMyApp …
AlexJov Aug 11, 2020
308c94b
Update create and delete action suppression; Update config;
AlexJov Aug 11, 2020
33fcad5
Merge branch 'develop' into features/suppress-action-files
AlexJov Aug 11, 2020
c8d6e75
Merge branch 'develop' of https://github.com/Appdynamics/ConfigMyApp …
AlexJov Aug 19, 2020
e421441
Action suppression bugfix missing functions and folders; Save uploade…
AlexJov Aug 19, 2020
d3136b0
Action suppression adding proxy; Fix empty proxy; Backup only uploade…
AlexJov Aug 20, 2020
29c1ba7
Update action suppression help;
AlexJov Aug 20, 2020
c6f4781
Merge branch 'develop' of https://github.com/Appdynamics/ConfigMyApp …
AlexJov Oct 21, 2020
c920f16
Rename dir healthrules to health_rules;
AlexJov Oct 21, 2020
853d630
Add modules dir; Add health rule update / delete sh;
AlexJov Oct 21, 2020
ddff3ac
Add health rule only and delete options;
AlexJov Oct 21, 2020
7f6cc03
Update refs to HRs; Add debug echo;
AlexJov Oct 26, 2020
a876e58
Add delete health rule func; Remove debug from HR modules;
AlexJov Oct 26, 2020
35ed039
Add health rule vars to docker env and k8s configMap;
AlexJov Oct 26, 2020
dd5496e
Remove health rule function from configMyApp; Update readme with argb…
AlexJov Oct 26, 2020
212a931
Delete HR from comma separated list;
AlexJov Oct 30, 2020
1e3ff7a
HR override, support previous version of env. var;
AlexJov Oct 30, 2020
f677851
Add git actions for health rules;
AlexJov Oct 30, 2020
279f3ed
Update delete HR test case - delete multiple;
AlexJov Oct 30, 2020
3064daa
Update folder name in test case;
AlexJov Oct 30, 2020
3f18b6a
Add SIM HR to test case;
AlexJov Oct 30, 2020
159e1ae
Test case update include sim flag;
AlexJov Oct 30, 2020
e049352
Remove feature branch from actions;
AlexJov Oct 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still, here it shows like the Health Rule does not exist although I imported it in the previous step (line 101) :/


- 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": ""
AlexJov marked this conversation as resolved.
Show resolved Hide resolved
}
],
"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
AlexJov marked this conversation as resolved.
Show resolved Hide resolved
#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