-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzactrack-parser.py
93 lines (63 loc) · 2.74 KB
/
zactrack-parser.py
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
# Configuration files
import logging
from logging.handlers import TimedRotatingFileHandler
import pyzabbix
from pyzabbix import ZabbixMetric, ZabbixSender
import configparser
import sys
from time import sleep
import json
import os
import socketio
from Actor import Actor
logger = logging.getLogger('zactrack-parse')
configPath = filename=os.path.join(sys.path[0], "config.ini")
zabbix_ip="192.168.0.116"
zabbix_packet = []
log_file_handler = TimedRotatingFileHandler(filename=os.path.join(sys.path[0], "runtime.log"), when='D', interval=1, backupCount=10,
encoding='utf-8',
delay=False)
log_console_handler = logging.StreamHandler(sys.stdout)
log_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
log_file_handler.setFormatter(log_formatter)
log_console_handler.setFormatter(log_formatter)
logger.setLevel(logging.DEBUG)
logger.addHandler(log_file_handler)
logger.addHandler(log_console_handler)
logger.info("Entering program")
# Logging initialised
zabbixServer = ZabbixSender(zabbix_server=zabbix_ip, timeout=1)
sio = socketio.Client()
@sio.on("actor-live-infos")
def on_actor_message(data):
zabbix_packet = []
for actor in data:
if actor['state'] == 2 and actor['battery'] > -1:
item = "Battery.Percentage." + str(actor['id'])
zabbix_packet.append(ZabbixMetric("Zactrack", item, actor['battery']))
logger.info(str(actor['id']) + ": " + str(actor['state']) + " " + str(actor['battery']))
if len(zabbix_packet) > 0:
try:
zabbixServer.send(zabbix_packet)
except:
logger.warning("Failed to send to zabbix server")
sio.disconnect()
while True:
if sio.connected:
sleep(5)
continue
logger.info("Starting new run")
try:
sio.connect("ws://192.168.3.24:8082/socket.io/")
sio.emit("zactrack-room-control-join", ("room-system-states", False))
sio.emit("zactrack-room-control-join", ("room-version-license-information", None))
sio.emit("zactrack-room-control-join", ("room-client-live-info", None))
sio.emit("zactrack-room-control-join", ("room-active-show-history-entry", None))
sio.emit("zactrack-room-control-join", ("room-anchor-live-infos", None))
sio.emit("zactrack-room-control-join", ("room-all-anchor-tracking-infos", None))
sio.emit("zactrack-room-control-join", ("room-actor-live-infos", None))
sio.emit("zactrack-room-control-join", ("room-all-sensor-tracking-information", False))
sio.emit("zactrack-room-control-join", ("room-fixture-live-runtime-values", None))
sleep(30)
except:
logger.warn("Unable to connect to zactrack")