Add arguments to select switch, ports and sys infos to be get and shown
This commit is contained in:
parent
d8d20c3c8b
commit
1bf9218a80
|
@ -115,7 +115,7 @@ def get_switch_port_stats(headers, port):
|
|||
print('Failed request: %s\n' % r.text)
|
||||
|
||||
|
||||
def get_and_print_metrics(creds):
|
||||
def get_and_print_metrics(creds, s_switch, s_ports, s_sys):
|
||||
freebox_app_id = "fr.freebox.seximonitor"
|
||||
|
||||
# Fetch challenge
|
||||
|
@ -204,36 +204,41 @@ def get_and_print_metrics(creds):
|
|||
|
||||
##
|
||||
# General infos
|
||||
sysJsonRaw = get_system_config(headers)
|
||||
myData['sys_fan_rpm'] = sysJsonRaw['result']['fan_rpm'] # rpm
|
||||
myData['sys_temp_sw'] = sysJsonRaw['result']['temp_sw'] # Temp Switch, degree Celcius
|
||||
myData['sys_uptime'] = sysJsonRaw['result']['uptime_val'] # Uptime, in seconds
|
||||
myData['sys_temp_cpub'] = sysJsonRaw['result']['temp_cpub'] # Temp CPU Broadcom, degree Celcius
|
||||
myData['sys_temp_cpum'] = sysJsonRaw['result']['temp_cpum'] # Temp CPU Marvell, degree Celcius
|
||||
if s_sys:
|
||||
sysJsonRaw = get_system_config(headers)
|
||||
myData['sys_fan_rpm'] = sysJsonRaw['result']['fan_rpm'] # rpm
|
||||
myData['sys_temp_sw'] = sysJsonRaw['result']['temp_sw'] # Temp Switch, degree Celcius
|
||||
myData['sys_uptime'] = sysJsonRaw['result']['uptime_val'] # Uptime, in seconds
|
||||
myData['sys_temp_cpub'] = sysJsonRaw['result']['temp_cpub'] # Temp CPU Broadcom, degree Celcius
|
||||
myData['sys_temp_cpum'] = sysJsonRaw['result']['temp_cpum'] # Temp CPU Marvell, degree Celcius
|
||||
|
||||
|
||||
##
|
||||
# Switch status
|
||||
switchJsonRaw = get_switch_status(headers)
|
||||
for i in switchJsonRaw['result']:
|
||||
# 0 down, 1 up
|
||||
myData['switch_%s_link' % i['id']] = 0 if i['link'] == "down" else 1
|
||||
# 0 auto, 1 10Base-T, 2 100Base-T, 3 1000Base-T
|
||||
# In fact the duplex is appended like 10BaseT-HD, 1000BaseT-FD, 1000BaseT-FD
|
||||
# So juse is an "in" because duplex isn't really usefull
|
||||
if "10BaseT" in i['mode']:
|
||||
myData['switch_%s_mode' % i['id']] = 1
|
||||
elif "100BaseT" in i['mode']:
|
||||
myData['switch_%s_mode' % i['id']] = 2
|
||||
elif "1000BaseT" in i['mode']:
|
||||
myData['switch_%s_mode' % i['id']] = 3
|
||||
else:
|
||||
myData['switch_%s_mode' % i['id']] = 0 # auto
|
||||
if s_switch:
|
||||
switchJsonRaw = get_switch_status(headers)
|
||||
for i in switchJsonRaw['result']:
|
||||
# 0 down, 1 up
|
||||
myData['switch_%s_link' % i['id']] = 0 if i['link'] == "down" else 1
|
||||
# 0 auto, 1 10Base-T, 2 100Base-T, 3 1000Base-T
|
||||
# In fact the duplex is appended like 10BaseT-HD, 1000BaseT-FD, 1000BaseT-FD
|
||||
# So juse is an "in" because duplex isn't really usefull
|
||||
if "10BaseT" in i['mode']:
|
||||
myData['switch_%s_mode' % i['id']] = 1
|
||||
elif "100BaseT" in i['mode']:
|
||||
myData['switch_%s_mode' % i['id']] = 2
|
||||
elif "1000BaseT" in i['mode']:
|
||||
myData['switch_%s_mode' % i['id']] = 3
|
||||
else:
|
||||
myData['switch_%s_mode' % i['id']] = 0 # auto
|
||||
|
||||
for i in [1,2,3,4]:
|
||||
switchPortStats = get_switch_port_stats(headers, i)
|
||||
myData['switch_%s_rx_bytes_rate' % i] = switchPortStats['result']['rx_bytes_rate'] # bytes/s (?)
|
||||
myData['switch_%s_tx_bytes_rate' % i] = switchPortStats['result']['tx_bytes_rate']
|
||||
##
|
||||
# Switch ports status
|
||||
if s_ports:
|
||||
for i in [1,2,3,4]:
|
||||
switchPortStats = get_switch_port_stats(headers, i)
|
||||
myData['switch_%s_rx_bytes_rate' % i] = switchPortStats['result']['rx_bytes_rate'] # bytes/s (?)
|
||||
myData['switch_%s_tx_bytes_rate' % i] = switchPortStats['result']['tx_bytes_rate']
|
||||
|
||||
# Prepping Graphite Data format
|
||||
timestamp = int(time.time())
|
||||
|
@ -315,6 +320,10 @@ if __name__ == '__main__':
|
|||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-r', '--register', action='store_true', help="Register app with Freebox API")
|
||||
parser.add_argument('-s', '--register-status', dest='status', action='store_true', help="Get register status")
|
||||
|
||||
parser.add_argument('-S', '--status-switch', dest='status_switch', action='store_true', help="Get and show switch status")
|
||||
parser.add_argument('-P', '--status-ports', dest='status_ports', action='store_true', help="Get and show switch ports stats")
|
||||
parser.add_argument('-H', '--status-sys', dest='status_sys', action='store_true', help="Get and show system status")
|
||||
args = parser.parse_args()
|
||||
|
||||
auth = get_auth()
|
||||
|
@ -324,4 +333,4 @@ if __name__ == '__main__':
|
|||
elif args.status:
|
||||
register_status(auth)
|
||||
else:
|
||||
get_and_print_metrics(auth)
|
||||
get_and_print_metrics(auth, args.status_switch, args.status_ports, args.status_sys)
|
Loading…
Reference in New Issue