bug fixes and fieldnames protection

This commit is contained in:
Antoine Van Elstraete 2021-10-29 17:02:16 +02:00
parent 808ea56a63
commit bdc27fbca3

View File

@ -6,22 +6,23 @@ def config(name, port_max, ports_label):
print(f"graph_title Network flow for {name}") print(f"graph_title Network flow for {name}")
print("graph_order down up") print("graph_order down up")
print("graph_args --base 1000") print("graph_args --base 1000")
print("graph_vlabel bits in (-) / out (+) per ${graph_period}") print("graph_vlabel in (-) / out (+)")
for port in range(1, port_max + 1): for port in range(1, port_max + 1):
print(f"down{port}.label {ports_label[port - 1]}") print(f"down{port}.label {ports_label[port - 1]}")
print(f"down{port}.type DERIVE") print(f"down{port}.type DERIVE")
print(f"down{port}.graph no") print(f"down{port}.graph no")
print(f"down{port}.cdef down,8,*") print(f"down{port}.cdef down{port},8,*")
for port in range(1, port_max + 1): for port in range(1, port_max + 1):
print(f"up{port}.label {ports_label[port - 1]}") print(f"up{port}.label {ports_label[port - 1]}")
print(f"up{port}.type DERIVE") print(f"up{port}.type DERIVE")
print(f"up{port}.negative down") print(f"up{port}.negative down{port}")
print(f"up{port}.cdef up,8,*") print(f"up{port}.cdef up{port},8,*")
if __name__ == '__main__': if __name__ == '__main__':
from sys import argv from sys import argv
import subprocess import subprocess
import re
ports_label = [] ports_label = []
InOctets = [] InOctets = []
OutOctets = [] OutOctets = []
@ -32,8 +33,11 @@ if __name__ == '__main__':
for line in result.splitlines(): for line in result.splitlines():
if "sysName" in line: if "sysName" in line:
name = line.split()[-1] name = line.split()[-1]
name = re.sub(r"(^[^A-Za-z_]|[^A-Za-z0-9_])", "_", name)
if "ifDescr" in line: if "ifDescr" in line:
ports_label.append(line.split()[-1]) label = (line.split()[-1])
label = re.sub(r"(^[^A-Za-z_]|[^A-Za-z0-9_])", "_", label)
ports_label.append(label)
if "ifIndex" in line: if "ifIndex" in line:
port_max += 1 port_max += 1
if "ifInOctets" in line: if "ifInOctets" in line: