forked from pylon-one-ltd/CiscoWLCTelemetry
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
666 lines (567 loc) · 33.3 KB
/
Copy pathmain.py
File metadata and controls
666 lines (567 loc) · 33.3 KB
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
#!/usr/bin/python3
# ---------------------------------------------------------------
# Python Script for monitoring client data on 9800 WLC for
# zabbix-sender via gRPC Telemetry
# james@pylonone.com
# v1.0 25/Sep/2025
# ---------------------------------------------------------------
from influxdb_client import Point, InfluxDBClient, WriteOptions
from google.protobuf import json_format
from concurrent import futures
import traceback
import pprint
import proto # proto directory containing our protobuf scaffolds
import time
import json
import grpc
import sys
import os
# ------- Configuration -------
# Output debugging data, will break piping output to zabbix-sender
# Note, all other messages sent as stderr so stdout is clean for piping into sender
debug_output = False
# ------- End Configuration -------
# Stderr Print Method
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
# Zabbix Print Methods
def zabbix_sender_output(controller, typename, keyname, value, current_time):
if keyname is None:
print("{} {} {} {}".format(controller, typename, current_time, value))
else:
keyname = keyname.replace(' ', '-')
print("{} {}[{}] {} {}".format(controller, typename, keyname, current_time, value))
def zabbix_sender_discovery(controller, typename, discovery_array, current_time):
json_array = json.dumps(discovery_array, default=vars).replace("keyname", "{#KEYNAME}").replace("policytag", "{#POLICYTAGS}")
print("{} wlan.{} {} {{\"data\":{}}}".format(controller, typename, current_time, json_array))
# Main Classes
class DiscoveryObject:
def __init__(self, value):
self.keyname = value.replace(' ', '-')
class DiscoveryObjectWithTag:
def __init__(self, value, policytag = None):
self.keyname = value.replace(' ', '-')
self.policytag = policytag
class MdtDialout(proto.mdt_grpc_dialout_pb2_grpc.gRPCMdtDialoutServicer):
influx_client_connection = None
client_collection_round = 1
controller_config_data = {}
join_last_message = {}
def __init__(self, database_is_influx):
if database_is_influx == True:
influx_token = str(os.getenv("INFLUX_TOKEN"))
if influx_token is None or len(influx_token) == 0:
eprint("Influx config is invalid. Token is not set. Please set INFLUX_TOKEN")
return
influx_url = str(os.getenv("INFLUX_URL"))
if influx_url is None or len(influx_url) == 0:
eprint("Influx config is invalid. Token is not set. Please set INFLUX_URL")
return
influx_org = str(os.getenv("INFLUX_ORG"))
if influx_org is None or len(influx_org) == 0:
eprint("Influx config is invalid. Token is not set. Please set INFLUX_ORG")
return
self.influx_client_connection = InfluxDBClient(
token=influx_token,
url=influx_url,
org=influx_org
)
def MdtDialout(self, request_iterator, context):
for request in request_iterator:
try:
telemetry_pb = proto.telemetry_pb2.Telemetry()
telemetry_pb.ParseFromString(request.data)
# Check we have a handler for the incoming data
json_data = json_format.MessageToDict(telemetry_pb, preserving_proto_field_name=True)
if not 'data_gpbkv' in json_data:
continue
# Determine the peer address
socket_source_address = context.peer()
if socket_source_address is None:
eprint("[{}] Unable to handle message - Unknown message type {}".format(request.ReqId, json_data['encoding_path']))
eprint("[{}] MdtDialout connection received from {} for {}".format(request.ReqId, socket_source_address, json_data['encoding_path']))
# Create dict for controller in config data if it doesn't exist
controller_ip_address = socket_source_address.split(':')[1]
if not controller_ip_address in self.controller_config_data:
self.controller_config_data[controller_ip_address] = {}
self.controller_config_data[controller_ip_address]["current_aps"] = {}
self.controller_config_data[controller_ip_address]["current_ssids"] = {}
# Pass message onto appropriate handler
match json_data['encoding_path']:
case "Cisco-IOS-XE-wireless-client-oper:client-oper-data/dot11-oper-data":
self.HandleClientOperData(json_data["data_gpbkv"], int(json_data["collection_id"]), controller_ip_address)
case "Cisco-IOS-XE-wireless-access-point-oper:access-point-oper-data/capwap-data":
self.HandleAccessPointData(json_data["data_gpbkv"], int(json_data["collection_id"]), controller_ip_address)
case "Cisco-IOS-XE-wireless-wlan-cfg:wlan-cfg-data/policy-list-entries/policy-list-entry":
self.HandleWlanConfigData(json_data["data_gpbkv"], int(json_data["collection_id"]), controller_ip_address)
case _:
eprint("[{}] Unable to handle message - Unknown message type {}".format(request.ReqId, json_data['encoding_path']))
except Exception as e:
eprint("[{}] Unable to handle message - Exception thrown - {} - {} {}".format(request.ReqId, controller_ip_address, type(e), e))
eprint("[{}] Message handler: {}".format(request.ReqId, json_data['encoding_path']))
eprint(traceback.format_exc())
finally:
# Acknowledge message from controller
yield proto.mdt_grpc_dialout_pb2.MdtDialoutArgs(ReqId=request.ReqId)
def HandleClientOperData(self, oper_data, collection_round, controller_ip):
if len(oper_data) == 0:
return
new_client_array = {}
try:
for each_client in oper_data:
client_mac_address = "00:00:00:00:00:00"
this_client_data = {}
for client_data in each_client["fields"]:
if client_data["name"] == "keys":
client_mac_address = client_data["fields"][0]["string_value"]
if client_data["name"] == "content":
for fields in client_data["fields"]:
if fields["name"] == "ewlc-ms-phy-type":
this_client_data["ewlc-ms-phy-type"] = fields["string_value"]
if fields["name"] == "ap-mac-address":
this_client_data["ap-mac-address"] = fields["string_value"]
if fields["name"] == "vap-ssid":
this_client_data["vap-ssid"] = fields["string_value"]
if fields["name"] == "wlan-profile":
this_client_data["wlan-profile"] = fields["string_value"]
if fields["name"] == "dot11-6ghz-cap":
this_client_data["dot11-6ghz-cap"] = fields["bool_value"]
if fields["name"] == "ms-ap-slot-id":
this_client_data["ms-ap-slot-id"] = "slot_{}".format(fields["uint32_value"])
if fields["name"] == "current-channel":
this_client_data["current-channel"] = fields["uint32_value"]
if fields["name"] == "radio-type":
this_client_data["radio-type"] = fields["string_value"]
if fields["name"] == "ms-wifi":
for fields2 in fields["fields"]:
if fields2["name"] == "wpa-version":
this_client_data["wpa-version"] = fields2["string_value"]
if fields2["name"] == "auth-key-mgmt":
this_client_data["auth-key-mgmt"] = fields2["string_value"]
# Update client data
if this_client_data["vap-ssid"] == "" or ("radio-type" in this_client_data and this_client_data["radio-type"] == "dot11-radio-type-none"):
continue
new_client_array[client_mac_address] = this_client_data
except Exception as e:
eprint("Failed to process HandleClientOperData for controller {} - {} {}".format(controller_ip,type(e),e))
eprint(traceback.format_exc())
#pprint.pprint(oper_data)
return
# Generate Zabbix Output
if self.client_collection_round != collection_round:
# New collection round, print output of last round
response_data = self.GetControllerMonitoring(self.join_last_message, controller_ip)
if self.influx_client_connection is not None:
self.InfluxFormatStage(response_data, controller_ip)
else:
self.ZabbixFormatStage(response_data, controller_ip)
# Reset collection of data
self.join_last_message = new_client_array
self.client_collection_round = collection_round
else:
# Join data with last collection round
self.join_last_message = { **self.join_last_message, **new_client_array }
def HandleAccessPointData(self, oper_data, collection_round, controller_ip):
if len(oper_data) == 0:
return
try:
for each_ap in oper_data:
ap_mac_address = "00:00:00:00:00:00"
this_ap_data = {}
for ap_data in each_ap["fields"]:
if ap_data["name"] == "content":
for fields in ap_data["fields"]:
if fields["name"] == "device-detail":
for fields2 in fields["fields"]:
if fields2["name"] == "static-info":
for fields3 in fields2["fields"]:
if fields3["name"] == "board-data":
for fields4 in fields3["fields"]:
if fields4["name"] == "wtp-enet-mac":
ap_mac_address = fields4["string_value"]
if fields["name"] == "name":
this_ap_data["ap_name"] = fields["string_value"]
if fields["name"] == "tag-info":
for fields2 in fields["fields"]:
if fields2["name"] == "policy-tag-info":
this_ap_data["ap_policy_tag"] = fields2["fields"][0]["string_value"]
if fields2["name"] == "site-tag":
for fields3 in fields2["fields"]:
if fields3["name"] == "site-tag-name":
this_ap_data["ap_site_tag"] = fields3["string_value"]
# Update mapping of AP to PT
self.controller_config_data[controller_ip]["current_aps"][ap_mac_address] = this_ap_data
except Exception as e:
eprint("Failed to process HandleAccessPointData for controller {} - {} {}".format(controller_ip,type(e),e))
eprint(traceback.format_exc())
pprint.pprint(oper_data)
return
def HandleWlanConfigData(self, oper_data, collection_round, controller_ip):
if len(oper_data) == 0:
return
try:
for each_tag in oper_data:
policy_tag_name = "unknown"
for policy_tag in each_tag["fields"]:
if policy_tag["name"] == "keys":
policy_tag_name = policy_tag["fields"][0]["string_value"]
if policy_tag["name"] == "content":
if not 'fields' in policy_tag:
continue
for fields in policy_tag["fields"]:
if fields["name"] == "wlan-policies":
for fields2 in fields["fields"]:
for fields3 in fields2["fields"]:
if fields3["name"] == "wlan-profile-name":
ssid_name = fields3["string_value"] # This is wlan-profile-name not SSID name
if not ssid_name in self.controller_config_data[controller_ip]["current_ssids"]:
self.controller_config_data[controller_ip]["current_ssids"][ssid_name] = []
if not policy_tag_name in self.controller_config_data[controller_ip]["current_ssids"][ssid_name]:
self.controller_config_data[controller_ip]["current_ssids"][ssid_name].append(policy_tag_name)
except Exception as e:
eprint("Failed to process HandleWlanConfigData for controller {} - {} {}".format(controller_ip,type(e),e))
eprint(traceback.format_exc())
pprint.pprint(oper_data)
return
def GetControllerMonitoring(self, clients, controller_ip):
response_data = {
'current_clients': 0,
'clients_6ghz_capable': 0,
'clients_per_key_mgmt_type': {},
'clients_per_wpa_version': {},
'clients_per_phy_type': {},
'clients_per_ssid': {},# wlan-profile
'clients_per_vap_ssid': {}, # vap-ssid separat
'clients_per_policy': {},
'clients_per_site': {},
'clients_per_ap': {},
'ap_channel_per_slot': {},
'ssids': {},
'aps': {}
}
# Get data for this controller
if not controller_ip in self.controller_config_data:
return
this_controller = self.controller_config_data[controller_ip]
try:
# Get Policy Data
for ssid, policytags in this_controller["current_ssids"].items():
response_data['clients_per_ssid'][ssid] = 0
response_data['ssids'][ssid] = policytags
# Get AP Data
for ap_mac, this_ap in this_controller["current_aps"].items():
response_data['aps'][this_ap['ap_name']] = this_ap['ap_policy_tag']
response_data['clients_per_ap'][this_ap['ap_name']] = {}
response_data['clients_per_ap'][this_ap['ap_name']]["slot_0"] = 0
response_data['clients_per_ap'][this_ap['ap_name']]["slot_1"] = 0
response_data['clients_per_ap'][this_ap['ap_name']]["slot_2"] = 0
response_data['clients_per_ap'][this_ap['ap_name']]["slot_3"] = 0
# Get client data
response_data['current_clients'] = len(clients)
for client_mac, this_client in clients.items():
# Clients by PHY Type
try:
response_data['clients_per_phy_type'][this_client['ewlc-ms-phy-type']] = response_data['clients_per_phy_type'][this_client['ewlc-ms-phy-type']] + 1
except KeyError:
response_data['clients_per_phy_type'][this_client['ewlc-ms-phy-type']] = 1
# Clients by Key Management Type
try:
response_data['clients_per_key_mgmt_type'][this_client['auth-key-mgmt']] = response_data['clients_per_key_mgmt_type'][this_client['auth-key-mgmt']] + 1
except KeyError:
response_data['clients_per_key_mgmt_type'][this_client['auth-key-mgmt']] = 1
# Clients by WPA Version
try:
response_data['clients_per_wpa_version'][this_client['wpa-version']] = response_data['clients_per_wpa_version'][this_client['wpa-version']] + 1
except KeyError:
response_data['clients_per_wpa_version'][this_client['wpa-version']] = 1
# Clients 6GHz Capable
if this_client['dot11-6ghz-cap']:
response_data['clients_6ghz_capable'] = response_data['clients_6ghz_capable'] + 1
# Resolve AP name
access_point_name = this_client['ap-mac-address']
if this_client['ap-mac-address'] in this_controller["current_aps"]:
access_point_name = this_controller["current_aps"][this_client['ap-mac-address']]['ap_name']
if not access_point_name in response_data['clients_per_ap']:
response_data['clients_per_ap'][access_point_name] = {}
response_data['clients_per_ap'][access_point_name]["slot_0"] = 0
response_data['clients_per_ap'][access_point_name]["slot_1"] = 0
response_data['clients_per_ap'][access_point_name]["slot_2"] = 0
response_data['clients_per_ap'][access_point_name]["slot_3"] = 0
if not access_point_name in response_data['ap_channel_per_slot']:
response_data['ap_channel_per_slot'][access_point_name] = {}
response_data['ap_channel_per_slot'][access_point_name]["slot_0"] = 0
response_data['ap_channel_per_slot'][access_point_name]["slot_1"] = 0
response_data['ap_channel_per_slot'][access_point_name]["slot_2"] = 0
response_data['ap_channel_per_slot'][access_point_name]["slot_3"] = 0
response_data['ap_channel_per_slot'][access_point_name][this_client['ms-ap-slot-id']] = this_client['current-channel']
# Clients by Access Point (Name or Mac Address)
try:
response_data['clients_per_ap'][access_point_name][this_client['ms-ap-slot-id']] = response_data['clients_per_ap'][access_point_name][this_client['ms-ap-slot-id']] + 1
except KeyError:
response_data['clients_per_ap'][access_point_name][this_client['ms-ap-slot-id']] = 1
# Clients by WLAN-Profile
try:
response_data['clients_per_ssid'][this_client['wlan-profile']] = response_data['clients_per_ssid'][this_client['wlan-profile']] + 1
except KeyError:
response_data['clients_per_ssid'][this_client['wlan-profile']] = 1
# Clients by VAP SSID (separates Dict)
try:
response_data.setdefault('clients_per_vap_ssid', {})
response_data['clients_per_vap_ssid'][this_client['vap-ssid']] = \
response_data['clients_per_vap_ssid'].get(this_client['vap-ssid'], 0) + 1
except KeyError:
response_data['clients_per_vap_ssid'][this_client['vap-ssid']] = 1
# Clients by Site
if this_client['ap-mac-address'] in this_controller["current_aps"]:
if this_controller["current_aps"][this_client['ap-mac-address']]['ap_site_tag']:
this_site_tag = this_controller["current_aps"][this_client['ap-mac-address']]['ap_site_tag']
try:
response_data['clients_per_site'][this_site_tag] = response_data['clients_per_site'][this_site_tag] + 1
except KeyError:
response_data['clients_per_site'][this_site_tag] = 1
# Clients by Policy
if this_controller["current_aps"][this_client['ap-mac-address']]['ap_policy_tag']:
this_policy_tag = this_controller["current_aps"][this_client['ap-mac-address']]['ap_policy_tag']
try:
response_data['clients_per_policy'][this_policy_tag] = response_data['clients_per_policy'][this_policy_tag] + 1
except KeyError:
response_data['clients_per_policy'][this_policy_tag] = 1
except Exception as e:
eprint("Failed to process GetControllerMonitoring for controller {} - {} {}".format(controller_ip,type(e),e))
eprint(traceback.format_exc())
return
return response_data
def ZabbixFormatStage(self, response_data, controller_ip):
current_time = int(time.time())
pp = pprint.PrettyPrinter(indent=4)
try:
# Output data to console
if debug_output:
print("--------- DEBUG OUTPUT - Retrieved Data from {} at {} ---------".format(controller_ip, current_time))
print("Total Clients 6GHz Capable: {}".format(response_data['clients_6ghz_capable']));
print("Total Clients: {}".format(response_data['current_clients']));
print("\nClients by PHY Type:")
pp.pprint(response_data['clients_per_phy_type'])
print("\nClients by AP:")
pp.pprint(response_data['clients_per_ap'])
print("\nClients by SSID:")
pp.pprint(response_data['clients_per_ssid'])
print("\nClients by Site-Tag:")
pp.pprint(response_data['clients_per_site'])
print("\nClients by Policy-Tag:")
pp.pprint(response_data['clients_per_policy'])
print("\nClients by WPA Version:")
pp.pprint(response_data['clients_per_wpa_version'])
print("\nClients by Key Management Type:")
pp.pprint(response_data['clients_per_key_mgmt_type'])
print("\nConfigured SSIDs:")
pp.pprint(response_data['ssids'])
print("\nAP Policy Tags:")
pp.pprint(response_data['aps'])
print("--------- END DEBUG OUTPUT - Retrieved Data from {} at {} ---------".format(controller_ip, current_time))
# Discovery Phase
if debug_output:
print("-- Starting Discovery Phase --")
phy_discovery = []
for phy_type in response_data['clients_per_phy_type'].keys():
phy_discovery.append(DiscoveryObject(phy_type.replace('client-','').replace('-prot','')))
zabbix_sender_discovery(controller_ip, "phy_type", phy_discovery, current_time)
ap_discovery = []
for ap_name in response_data['clients_per_ap'].keys():
if ap_name in response_data['aps']:
ap_discovery.append(DiscoveryObjectWithTag(ap_name, response_data['aps'][ap_name]))
zabbix_sender_discovery(controller_ip, "access_point", ap_discovery, current_time)
ssid_discovery = []
for ssid_name in response_data['clients_per_ssid'].keys():
if ssid_name in response_data['ssids']:
#ssid_discovery.append(DiscoveryObjectWithTag(ssid_name, ','.join(response_data['ssids'][ssid_name])))
ssid_discovery.append(DiscoveryObject(ssid_name))
zabbix_sender_discovery(controller_ip, "ssid", ssid_discovery, current_time)
sitetag_discovery = []
for site_tag in response_data['clients_per_site'].keys():
sitetag_discovery.append(DiscoveryObject(site_tag))
zabbix_sender_discovery(controller_ip, "site_tag", sitetag_discovery, current_time)
policytag_discovery = []
for policy_tag in response_data['clients_per_policy'].keys():
policytag_discovery.append(DiscoveryObject(policy_tag))
zabbix_sender_discovery(controller_ip, "policy_tag", policytag_discovery, current_time)
wpa_version_discovery = []
for wpa_version in response_data['clients_per_wpa_version'].keys():
wpa_version_discovery.append(DiscoveryObject(wpa_version))
zabbix_sender_discovery(controller_ip, "wpa_version", wpa_version_discovery, current_time)
key_management_type_discovery = []
for key_mgmt_type in response_data['clients_per_key_mgmt_type'].keys():
key_management_type_discovery.append(DiscoveryObject(key_mgmt_type))
zabbix_sender_discovery(controller_ip, "key_mgmt_type", key_management_type_discovery, current_time)
# Data Phase
if debug_output:
print("-- Starting Data Phase --")
zabbix_sender_output(controller_ip, "wlan.total_clients", None, response_data['current_clients'], current_time)
zabbix_sender_output(controller_ip, "wlan.total_6ghz_capable_clients", None, response_data['clients_6ghz_capable'], current_time)
for phy_type, total in response_data['clients_per_phy_type'].items():
zabbix_sender_output(controller_ip, "wlan.phy_type.clients", phy_type.replace('client-','').replace('-prot',''), total, current_time)
for ap_name, ap_client_data in response_data['clients_per_ap'].items():
total = 0
for slotname, slot in ap_client_data.items():
total = total + slot
zabbix_sender_output(controller_ip, "wlan.access_point.clients", ap_name, total, current_time)
for ap_name, ap_client_data in response_data['clients_per_ap'].items():
for slotname, slot in ap_client_data.items():
zabbix_sender_output(controller_ip, "wlan.access_point.{}.clients".format(slotname), ap_name, slot, current_time)
for ap_name, ap_channel_data in response_data['ap_channel_per_slot'].items():
for slotname, slot in ap_channel_data.items():
if not slot == 0:
zabbix_sender_output(controller_ip, "wlan.access_point.{}.channel".format(slotname), ap_name, slot, current_time)
for ssid_name, total in response_data['clients_per_ssid'].items():
zabbix_sender_output(controller_ip, "wlan.ssid.clients", ssid_name, total, current_time)
for site_tag, total in response_data['clients_per_site'].items():
zabbix_sender_output(controller_ip, "wlan.site_tag.clients", site_tag, total, current_time)
for policy_tag, total in response_data['clients_per_policy'].items():
zabbix_sender_output(controller_ip, "wlan.policy_tag.clients", policy_tag, total, current_time)
for wpa_version, total in response_data['clients_per_wpa_version'].items():
zabbix_sender_output(controller_ip, "wlan.wpa_version.clients", wpa_version, total, current_time)
for key_mgmt_type, total in response_data['clients_per_key_mgmt_type'].items():
zabbix_sender_output(controller_ip, "wlan.key_mgmt_type.clients", key_mgmt_type, total, current_time)
except Exception as e:
eprint("Failed to process ZabbixFormatStage for controller {} - {} {}".format(controller_ip,type(e),e))
eprint(traceback.format_exc())
return
#Influx Format Stage
def InfluxFormatStage(self, response_data, controller_ip):
write_points = []
try:
# Totals
write_points.append(
Point("totals")
.tag("controller", controller_ip)
.field("total_clients", response_data['current_clients'])
)
write_points.append(
Point("totals")
.tag("controller", controller_ip)
.field("total_6ghz_capable_clients", response_data['clients_6ghz_capable'])
)
# Clients by PHY type
for phy_type, total in response_data['clients_per_phy_type'].items():
write_points.append(
Point("client_count_phy_type")
.tag("controller", controller_ip)
.tag("phy_type", phy_type.replace('client-','').replace('-prot',''))
.field("count", total)
)
# Clients by AP (gesamt)
for ap_name, ap_client_data in response_data['clients_per_ap'].items():
total = sum(ap_client_data.values())
write_points.append(
Point("client_count_per_ap")
.tag("controller", controller_ip)
.tag("ap", ap_name)
.tag("policy_tag", response_data['aps'].get(ap_name, "unknown"))
.field("count", total)
)
# Clients by AP + Slot
for ap_name, ap_client_data in response_data['clients_per_ap'].items():
for slotname, slot in ap_client_data.items():
write_points.append(
Point("client_count_per_ap_slot")
.tag("controller", controller_ip)
.tag("ap", ap_name)
.tag("slot", slotname)
.field("count", slot)
)
# Clients by SSID (wlan-profile + vap-ssid zusammen)
# Clients by WLAN Profile
for profile_name, total in response_data['clients_per_ssid'].items():
write_points.append(
Point("client_count_wlan_profile")
.tag("controller", controller_ip)
.tag("wlan_profile", profile_name)
.field("count", total)
)
# Clients by VAP SSID
if "clients_per_vap_ssid" in response_data:
for vap_ssid, total in response_data['clients_per_vap_ssid'].items():
write_points.append(
Point("client_count_vap_ssid")
.tag("controller", controller_ip)
.tag("vap_ssid", vap_ssid)
.field("count", total)
)
# Clients by Site
for site_tag, total in response_data['clients_per_site'].items():
write_points.append(
Point("client_count_site_tag")
.tag("controller", controller_ip)
.tag("site_tag", site_tag)
.field("count", total)
)
# Clients by Policy
for policy_tag, total in response_data['clients_per_policy'].items():
write_points.append(
Point("client_count_policy_tag")
.tag("controller", controller_ip)
.tag("policy_tag", policy_tag)
.field("count", total)
)
# Clients by WPA Version
for wpa_version, total in response_data['clients_per_wpa_version'].items():
write_points.append(
Point("client_count_wpa_version")
.tag("controller", controller_ip)
.tag("wpa_version", wpa_version)
.field("count", total)
)
# Clients by Key Management
for key_mgmt_type, total in response_data['clients_per_key_mgmt_type'].items():
write_points.append(
Point("client_count_key_mgmt_type")
.tag("controller", controller_ip)
.tag("key_mgmt_type", key_mgmt_type)
.field("count", total)
)
# NEU: AP Channel per Slot
if "ap_channel_per_slot" in response_data:
for ap_name, ap_channel_data in response_data['ap_channel_per_slot'].items():
for slotname, channel in ap_channel_data.items():
if channel != 0:
write_points.append(
Point("ap_channel")
.tag("controller", controller_ip)
.tag("ap", ap_name)
.tag("slot", slotname)
.field("channel", int(channel))
)
except Exception as e:
eprint("Failed to process InfluxFormatStage for controller {} - {} {}".format(controller_ip, type(e), e))
eprint(traceback.format_exc())
return
# Write points to influx
bucket_name = str(os.getenv("INFLUX_BUCKET"))
if not bucket_name:
eprint("Influx config is invalid. Bucket name is not set. Please set INFLUX_BUCKET")
return
self.WriteToInflux(write_points, bucket_name)
def WriteToInflux(self, data_points, bucket_name):
with self.influx_client_connection.write_api(write_options=WriteOptions(batch_size=50_000, flush_interval=10_000)) as write_api:
for point in data_points:
write_api.write(bucket=bucket_name, record=point)
# Main Method
def main():
is_influx_mode = False
if str(os.getenv("TELEM_DATABASE_TYPE")).lower() == "influx2":
eprint("Operating in Influx2 Mode")
is_influx_mode = True
grpc_server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
proto.mdt_grpc_dialout_pb2_grpc.add_gRPCMdtDialoutServicer_to_server(
MdtDialout(is_influx_mode), grpc_server
)
grpc_server.add_insecure_port('[::]:57001')
eprint("Starting gRPC listener on port 57001")
try:
grpc_server.start()
grpc_server.wait_for_termination()
except Exception:
pass
# Launch main method
if __name__ == '__main__':
main()