-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
aggregation-services.conf
258 lines (212 loc) · 8.17 KB
/
aggregation-services.conf
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
// Icinga2 Aggregation Services.
// Max.Fischer (c) 2024 - Licensed under M.I.T.
// Updates: https://github.com/xyhtac/icingatelegram
// List_services - Generates concatenated text output of all services for the given host / host group
// wildcards: groupname = host (list only host services), identifier = all (sets * pattern for all services)
apply Service for (identifier => groupname in host.vars.list_services) {
name = "services-" + groupname + "-" + identifier
display_name = "services-" + groupname + "-" + identifier
vars.service_pattern = identifier
vars.host_groupname = groupname
max_check_attempts = 5
check_interval = 3m
retry_interval = 1m
check_command = "dummy"
vars.dummy_text = {{
// get vars from service and convert to plaintext
var this_servicename = macro("$name$")
var service_pattern = macro("$service_pattern$")
if ( service_pattern == "all") {
service_pattern = "*"
}
var applied_group = macro("$host_groupname$")
if ( applied_group == "host") {
var applied_host = macro("$host.name$")
//var applied_hosts = [ applied_host ]
f = function(node) use(applied_host) { match( applied_host, node.name ) }
var applied_hosts = get_objects(Host).filter(f)
} else {
// define lambda function to pass variable to host filter
f = function(node) use(applied_group) { applied_group in node.groups }
var applied_hosts = get_objects(Host).filter(f)
}
var status = "SERVICE DETAILS: \n\n"
var hostStatus = ""
var hostText = ""
for (host in applied_hosts) {
hostText = host.name
hostStatus = " * " + hostText + " (" + service_pattern + "):\n"
serviceCount = 0
// define lambda function to pass variables to service filter
f = function(node) use(hostText, service_pattern) { match( hostText, node.host_name ) && match( "*" + service_pattern + "*", node.name ) }
var applied_services = get_objects(Service).filter(f)
var serviceStateIcon = [ "✅ ", "⚠️ ", "⭕ " , "⏳ " ]
for (service in applied_services) {
servicenameText = service.name
// prevent listing self
if ( servicenameText != this_servicename) {
serviceOutput = get_service(hostText, service.name ).last_check_result.output
serviceState = get_service(hostText, service.name ).last_check_result.state
stateIcon = serviceStateIcon[ serviceState ]
hostStatus = hostStatus + stateIcon + servicenameText + ": " + serviceOutput + "\n"
serviceCount = serviceCount + 1
}
}
if (serviceCount > 0) {
status = status + hostStatus + "\n"
}
}
return status
}}
vars.dummy_state = 0
}
// Group_list - Generate concatenated text output of specific services for the given group
apply Service for (identifier => groupname in host.vars.group_list) {
name = groupname + "-" + identifier
display_name = groupname + "-" + identifier
vars.group_name = groupname
vars.group_service = identifier
max_check_attempts = 5
check_interval = 3m
retry_interval = 1m
check_command = "dummy"
vars.dummy_text = {{
var status = "DETAILS:\n\n"
// get vars from service and convert to plaintext
var applied_group = macro("$group_name$")
var applied_service = macro("$group_service$")
// define lambda function to pass variable to filter
f = function(node) use(applied_group) { applied_group in node.groups }
var applied_hosts = get_objects(Host).filter(f)
var serviceStateIcon = [ "✅ ", "⚠️ ", "⭕ " , "⏳ " ]
for (node in applied_hosts) {
hostnameText = node.name
serviceStatus = get_service(node.name, applied_service ).last_check_result.output
serviceState = get_service(node.name, applied_service ).last_check_result.state
stateIcon = serviceStateIcon[ serviceState ]
status = status + hostnameText + "\n" + stateIcon + serviceStatus + "\n\n"
}
return status
}}
vars.dummy_state = 0
// Uncomment if state calculation for dummy object is desired
// vars.dummy_state = {{
// var service_state = []
// var state = 0
//
// //get vars from service and convert to plaintext
// var applied_group = macro("$group_name$")
// var applied_service = macro("$group_service$")
// // define lambda function to pass variable to filter
// f = function(node) use(applied_group) { applied_group in node.groups }
// var applied_hosts = get_objects(Host).filter(f)
// //var applied_hosts = get_objects(Host).filter(h => "ti-servers" in h.groups)
// for (node in applied_hosts) {
// service_state.add(get_service(node.name, applied_service ).last_check_result.state)
// }
// for (current_state in service_state) {
// if (current_state > state) {
// state = current_state
// }
// }
// return state
// }}
}
// Group_summary - Generates status summary of specific service for the given group
// wildcards: identifier = host (list hosts instead of services)
apply Service for (identifier => servicename in host.vars.group_summary) {
name = identifier + "-" + servicename
display_name = identifier + "-" + servicename
vars.group_name = identifier
vars.group_service = servicename
max_check_attempts = 5
check_interval = 3m
retry_interval = 1m
check_command = "dummy"
vars.dummy_text = {{
var status_ok = 0
var status_warning = 0
var status_critical = 0
var acknowledgedCount = 0
var serviceAck = 0
// get vars from service and convert to plaintext
var applied_group = macro("$group_name$")
var applied_service = macro("$group_service$")
// define lambda function to pass variable to filter
f = function(node) use(applied_group) { applied_group in node.groups }
var applied_hosts = get_objects(Host).filter(f)
for (node in applied_hosts) {
if (applied_service == "host") {
serviceState = node.last_check_result.state
} else {
serviceState = get_service(node.name, applied_service).last_check_result.state
}
serviceAck = node.acknowledgement
if (serviceState == 0) {
status_ok = status_ok + 1
} else if (serviceState == 2 && serviceAck == 0) {
status_critical = status_critical + 1
} else if (serviceState == 1 && serviceAck == 0) {
status_warning = status_warning + 1
}
if (serviceAck != 0 ) {
acknowledgedCount = acknowledgedCount + 1
}
}
var status = "HOST STATE SUMMARY:\n\n ✅ OK: " + status_ok + "\n ⚠️ WARNING: " + status_warning + "\n ⭕ CRITICAL: " + status_critical + "\n ⏳ MAINTENANCE: " + acknowledgedCount;
return status
}}
vars.dummy_state = 0
// Uncomment if state calculation for dummy object is desired
// vars.dummy_state = {{
// var service_state = []
// var state = 0
// // get vars from service and convert to plaintext
// var applied_group = macro("$group_name$")
// var applied_service = macro("$group_service$")
// // define lambda function to pass variable to filter
// f = function(node) use(applied_group) { applied_group in node.groups }
// var applied_hosts = get_objects(Host).filter(f)
// // var applied_hosts = get_objects(Host).filter(h => "ti-cams" in h.groups)
//
// for (node in applied_hosts) {
// service_state.add(get_service(node.name, applied_service).last_check_result.state)
// }
// for (current_state in service_state) {
// if (current_state > state) {
// state = current_state
// }
// }
// return state
// }}
}
// Group_count - count non-null values of specific service for the given group
apply Service for (identifier => servicename in host.vars.group_count) {
name = identifier + "-" + servicename
display_name = identifier + "-" + servicename
vars.group_name = identifier
vars.group_service = servicename
max_check_attempts = 5
check_interval = 3m
retry_interval = 1m
check_command = "dummy"
vars.dummy_text = {{
var serviceOut = ""
var serviceSum = 0
// get vars from service and convert to plaintext
var applied_group = macro("$group_name$")
var applied_service = macro("$group_service$")
// define lambda function to pass variable to filter
f = function(node) use(applied_group) { applied_group in node.groups }
var applied_hosts = get_objects(Host).filter(f)
for (node in applied_hosts) {
serviceOut = get_service(node.name, applied_service).last_check_result.performance_data[0]
serviceValue = parse_performance_data(serviceOut).value
if (serviceValue > 0) {
serviceSum = serviceSum + serviceValue
}
}
return serviceSum
}}
vars.dummy_state = 0
}