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)
|
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"
|
freebox_app_id = "fr.freebox.seximonitor"
|
||||||
|
|
||||||
# Fetch challenge
|
# Fetch challenge
|
||||||
|
@ -204,6 +204,7 @@ def get_and_print_metrics(creds):
|
||||||
|
|
||||||
##
|
##
|
||||||
# General infos
|
# General infos
|
||||||
|
if s_sys:
|
||||||
sysJsonRaw = get_system_config(headers)
|
sysJsonRaw = get_system_config(headers)
|
||||||
myData['sys_fan_rpm'] = sysJsonRaw['result']['fan_rpm'] # rpm
|
myData['sys_fan_rpm'] = sysJsonRaw['result']['fan_rpm'] # rpm
|
||||||
myData['sys_temp_sw'] = sysJsonRaw['result']['temp_sw'] # Temp Switch, degree Celcius
|
myData['sys_temp_sw'] = sysJsonRaw['result']['temp_sw'] # Temp Switch, degree Celcius
|
||||||
|
@ -214,6 +215,7 @@ def get_and_print_metrics(creds):
|
||||||
|
|
||||||
##
|
##
|
||||||
# Switch status
|
# Switch status
|
||||||
|
if s_switch:
|
||||||
switchJsonRaw = get_switch_status(headers)
|
switchJsonRaw = get_switch_status(headers)
|
||||||
for i in switchJsonRaw['result']:
|
for i in switchJsonRaw['result']:
|
||||||
# 0 down, 1 up
|
# 0 down, 1 up
|
||||||
|
@ -230,6 +232,9 @@ def get_and_print_metrics(creds):
|
||||||
else:
|
else:
|
||||||
myData['switch_%s_mode' % i['id']] = 0 # auto
|
myData['switch_%s_mode' % i['id']] = 0 # auto
|
||||||
|
|
||||||
|
##
|
||||||
|
# Switch ports status
|
||||||
|
if s_ports:
|
||||||
for i in [1,2,3,4]:
|
for i in [1,2,3,4]:
|
||||||
switchPortStats = get_switch_port_stats(headers, i)
|
switchPortStats = get_switch_port_stats(headers, i)
|
||||||
myData['switch_%s_rx_bytes_rate' % i] = switchPortStats['result']['rx_bytes_rate'] # bytes/s (?)
|
myData['switch_%s_rx_bytes_rate' % i] = switchPortStats['result']['rx_bytes_rate'] # bytes/s (?)
|
||||||
|
@ -315,6 +320,10 @@ if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('-r', '--register', action='store_true', help="Register app with Freebox API")
|
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', '--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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
auth = get_auth()
|
auth = get_auth()
|
||||||
|
@ -324,4 +333,4 @@ if __name__ == '__main__':
|
||||||
elif args.status:
|
elif args.status:
|
||||||
register_status(auth)
|
register_status(auth)
|
||||||
else:
|
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