-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathobjCounter.ts
162 lines (111 loc) · 4.38 KB
/
objCounter.ts
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import { BigipConfObj, GslbStats, ObjStats } from './models'
/**
* counts up totals of the different LTM objects (vs, nodes, pools, ...)
* @param obj ltm branch of config tree
*/
export async function countObjects (obj: BigipConfObj): Promise<ObjStats> {
const stats: ObjStats = {};
if(obj?.ltm?.virtual) {
stats.virtuals = Object.keys(obj.ltm.virtual).length
}
if(obj?.ltm?.profile) {
// todo: dig deeper to get a better count of actaul profile numbers
// currently only returns number of parent objects which represents (tcp, ssl, http, ...), not all the keys within those objects
stats.profiles = Object.keys(obj.ltm.profile).length
}
if(obj?.ltm?.policy) {
stats.policies = Object.keys(obj.ltm.policy).length
}
if(obj?.ltm?.pool) {
stats.pools = Object.keys(obj.ltm.pool).length
}
if(obj?.ltm?.rule) {
stats.irules = Object.keys(obj.ltm.rule).length
}
if(obj?.ltm?.monitor) {
// todo: same as profiles above, dig deeper into each parent object for all the keys of the children
stats.monitors = Object.keys(obj.ltm.monitor).length
}
if(obj?.ltm?.node) {
stats.nodes = Object.keys(obj.ltm.node).length
}
if(obj?.ltm?.snatpool) {
stats.snatPools = Object.keys(obj.ltm.snatpool).length
}
// GTM stats
if(obj?.gtm) {
// here we return/assign the value
stats.gtm = await countGSLB(obj);
}
if(obj?.apm) {
// here we pass in the main stats object and add stats in the function
await countAPM(obj, stats)
}
// asm policies are refenced by local traffic policies on each vs
if(obj?.asm?.policy) {
stats.asmPolicies = Object.keys(obj.asm.policy).length;
}
if(obj?.security?.['bot-defense']) {
stats.botProfiles = Object.keys(obj.security['bot-defense']).length;
}
if(obj?.security?.dos) {
stats.dosProfiles = Object.keys(obj.security.dos).length;
}
return stats;
}
export async function countAPM(obj: BigipConfObj, stats: ObjStats): Promise<void> {
// count access policies
// apm policy access-policy <name> <details>
if(obj?.apm?.policy?.['access-policy']) {
stats.apmPolicies = Object.keys(obj.apm.policy['access-policy']).length;
}
// count access profiles
// apm profile access <name> <details
if(obj?.apm?.profile?.access) {
stats.apmProfiles = Object.keys(obj.apm.profile.access).length;
}
// we already added the stats to the main object, so just finish the function with a return
return;
}
/**
* list of gtm record types, not for Typescript typing (see models export)
* [ 'a', 'aaaa', 'ns', 'srv', 'cname', 'mx', 'naptr']
*/
export const gtmRecordTypes = [ 'a', 'aaaa', 'ns', 'srv', 'cname', 'mx', 'naptr'];
export async function countGSLB(obj: BigipConfObj): Promise<GslbStats> {
const gtmStats: GslbStats = {};
const parents = ['datacenter', 'region', 'server'];
// loop through the list of parents
parents.forEach( p => {
// if parent found in obj.gtm object
if(obj?.gtm?.[p]) {
// count the keys
gtmStats[`${p}s`] = Object.keys(obj.gtm[p]).length;
}
})
// pools and wideips have named children object for the different record types
// so we need to dig a bit deeper into each one
if(obj?.gtm?.pool) {
// we have some gslb pools so, create the param and set the initial value
gtmStats.pools = 0
// loop through each of the record types and add up counts
gtmRecordTypes.forEach( r => {
// make sure we have this type of records
if(obj.gtm.pool[r]) {
// grab the number of keys and add the count
const count = Object.keys(obj.gtm.pool[r]).length;
gtmStats.pools = gtmStats.pools + count;
}
})
}
if(obj?.gtm?.wideip) {
gtmStats.wideips = 0;
gtmRecordTypes.forEach( r => {
if(obj.gtm.wideip[r]) {
const count = Object.keys(obj.gtm.wideip[r]).length;
gtmStats.wideips = gtmStats.wideips + count;
}
})
}
return gtmStats;
}