-
Notifications
You must be signed in to change notification settings - Fork 0
/
agentlist.sh
113 lines (104 loc) · 4.24 KB
/
agentlist.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
# set verbose level to info
__LOGLEVEL=6
#Logging stuff
declare -A LOG_LEVELS
# https://en.wikipedia.org/wiki/Syslog#Severity_level
LOG_LEVELS=([0]="Emerg" [1]="Alert" [2]="Critical" [3]="Error" [4]="Warning" [5]="Notice" [6]="Info" [7]="Debug")
function loglevel () {
local LEVEL=${1}
shift
if [ ${__LOGLEVEL} -ge ${LEVEL} ]; then
echo "[${LOG_LEVELS[$LEVEL]}]" "$@"
fi
}
#Get user creds
#user=`test -z $USER && echo jagannsr || echo $USER`
#echo "LAN password for $user"
#read -s password
#url="http://apm.prd.emaas.cba:8090/controller/rest" #production controller
outfile="agentdata.csv"
sumfile="agentdatasummary.csv"
#user=appd_api
#password="Appd123$"
#Read config file
cnf_file=.agentlist.cnf
if [ ! -r $cnf_file ]; then
loglevel 2 "Can't find $cnf_file"
exit 1
fi
while read -r line; do
declare $line
done <$cnf_file
if [ -z $user ]; then
loglevel 2 "Unable to determine username check $cnf_file"
exit 1
fi
if [ -z $password ]; then
loglevel 2 "Unable to determine password check $cnf_file"
exit 1
fi
if [ -z $url ]; then
loglevel 2 "Unable to determine Controller URL check $cnf_file"
exit 1
fi
#Download list of applications first
echo "INFO: Getting list of applications from $url ..."
apps=`curl --user ${user}@customer1:${password} ${url}/applications/ 2>/dev/null | grep "<name>"`
if [ -z "${apps}" ]; then
loglevel 3 "Error getting list of applications or no applications created yet"
exit 1
fi
loglevel 7 $apps
#For each applicataion get all nodes under it
loglevel 6 "Getting nodes for applications..."
echo "Application Name,Machine Name,Status,Machine Agent Version,App Agent Version" > $outfile
echo "Application Name,Count" > $sumfile
#This is required because application names might have spaces
OLDIFS=$IFS
IFS=$'\n'
STATUS=([0]="Inactive" [1]="Active")
#Loop thru each app
for app in `echo "$apps"`
do
app_name=`echo $app | cut -d">" -f2 | cut -d"<" -f1`
loglevel 6 "Fetching nodes for $app_name"
#get the nodes
nodes=`curl --user ${user}@customer1:${password} ${url}/applications/${app_name}/nodes 2>/dev/null | grep "<id>"`
app_count=0
#For each node get tier, status, using the metric browser URL
for node in `echo "$nodes"`
do
node_id=`echo $node | cut -d">" -f2 | cut -d"<" -f1`
node_details=`curl --user ${user}@customer1:${password} ${url}/applications/${app_name}/nodes/${node_id} 2>/dev/null`
machine_name=`echo "$node_details" | grep "<machineName>" | cut -d">" -f2 | cut -d"<" -f1`
tier_name=`echo "$node_details" | grep "<tierName>" | cut -d">" -f2 | cut -d"<" -f1`
node_name=`echo "$node_details" | grep "<name>" | cut -d">" -f2 | cut -d"<" -f1`
machine_version=`echo "$node_details" | grep "<machineAgentVersion>" | cut -d">" -f2 | cut -d"<" -f1`
appagent_version=`echo "$node_details" | grep "<appAgentVersion>" | cut -d">" -f2 | cut -d"<" -f1`
if [ -z "$machine_version" ]; then
machine_version="NA"
fi
if [ -z "$appagent_version" ]; then
appagent_version="NA"
fi
loglevel 7 "Getting details for $app_name --> $node_name"
loglevel 7 "Getting details for $app_name --> $node_name"
#Form the REST url in the format expected by metric browser - urlencode spaces and special characters
metric_path=`echo "metric-path=Application%20Infrastructure%20Performance|${tier_name}%7CIndividual%20Nodes%7C${node_name}%7CAgent%7CApp%7CAvailability&time-range-type=BEFORE_NOW&duration-in-mins=15" | sed 's/ /%20/g'`
metric_url="${url}/applications/${app_name}/metric-data?$metric_path"
loglevel 7 $metric_url
agent_details=`curl -G --user ${user}@customer1:${password} ${metric_url} 2>/dev/null`
loglevel 7 "agent xml $agent_details"
agent_status=`echo "$agent_details" | grep "<value>" | cut -d">" -f2 | cut -d"<" -f1`
start_time=`echo "$agent_details" | grep "<startTimeInMillis>" | cut -d">" -f2 | cut -d"<" -f1 | awk '{print strftime("%c", ( $1 / 1000 ))}'`
loglevel 7 "$app_name,$node_name,$agent_status,$start_time,$machine_version,$appagent_version,$metric_url"
echo $app_name,$node_name,${STATUS[$agent_status]},$machine_version,$appagent_version >> $outfile
done
#Count the unique active agents per app
app_count=`grep "$app_name\," $outfile | grep -v Inactive | sort -u | wc -l`
echo $app_name,$app_count >> $sumfile
done
#Finish up
IFS=$OLDIFS
echo "INFO: Output stored in $outfile. Summary is in $sumfile"