Commit bc4d2d31 authored by David Huss's avatar David Huss 💬
Browse files

Fix where --watch caused malformed requests

This happened due to config not cloning implicitly, then beeing
overwritten by sum_meetings and then not containing any URL at all
during the next iteration. Solved by creating a deepcopy
parent 97fb67e3
__version__ = '0.1.30' __version__ = '0.1.31'
...@@ -53,7 +53,7 @@ def main(userconfig, watch, version): ...@@ -53,7 +53,7 @@ def main(userconfig, watch, version):
Internally bbbmon relies on the offical bbb-API, which means you need to have the server's secret in order to create a valid request. Create a new configuration with: bbbmon config --new Internally bbbmon relies on the offical bbb-API, which means you need to have the server's secret in order to create a valid request. Create a new configuration with: bbbmon config --new
""" """
__version__ = "0.1.30" __version__ = "0.1.31"
if version: if version:
print(__version__) print(__version__)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import time import time
import copy
import subprocess import subprocess
import hashlib import hashlib
import json import json
...@@ -78,9 +79,11 @@ def get_meetings(secret: Secret, bbb_url: Url, user_config_path: str, sum_: bool ...@@ -78,9 +79,11 @@ def get_meetings(secret: Secret, bbb_url: Url, user_config_path: str, sum_: bool
try: try:
d = request_meetings(secret, bbb_url, user_config_path, sum_) d = request_meetings(secret, bbb_url, user_config_path, sum_)
except: except:
eprint("request_meetings didn't work out...")
return ["unreachable"] return ["unreachable"]
if d["meetings"] is None: if d["meetings"] is None:
eprint("No meetings returned...")
return [] return []
if type(d["meetings"]["meeting"]) is XmlListConfig: if type(d["meetings"]["meeting"]) is XmlListConfig:
...@@ -127,9 +130,11 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool ...@@ -127,9 +130,11 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool
# Request Meetings from API # Request Meetings from API
meetings = [get_meetings(e.secret, e.url, config.path, sum_) for e in config.endpoints] meetings = [get_meetings(e.secret, e.url, config.path, sum_) for e in config.endpoints]
config_override = copy.deepcopy(config)
# Collate all meetings from all endpoints together for --sum flag # Collate all meetings from all endpoints together for --sum flag
if sum_: if sum_:
config, meetings = sum_meetings(config, meetings) config_override, meetings = sum_meetings(config_override, meetings)
# Clear screen after request is done, and before printing new data to keep # Clear screen after request is done, and before printing new data to keep
# blinking to a minimum # blinking to a minimum
...@@ -137,7 +142,7 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool ...@@ -137,7 +142,7 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool
click.clear() click.clear()
for i, endpoint in enumerate(config.endpoints): for i, endpoint in enumerate(config_override.endpoints):
# Print divider if there is more than one endpoint # Print divider if there is more than one endpoint
if i > 0: if i > 0:
print() print()
...@@ -164,11 +169,10 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool ...@@ -164,11 +169,10 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool
print(" └─── Currently no active meetings.") print(" └─── Currently no active meetings.")
continue continue
# There are no unreachable endpoints in sum mode # print this if the endpoint (or all endpoints!) is unreachable
if not sum_: if meeting[0] == "unreachable":
if meeting[0] == "unreachable": printing.print_header(endpoint.name, "No connection..", fancy)
printing.print_header(endpoint.name, "No connection..", fancy) continue
continue
# Make sure that meeting is an actual list # Make sure that meeting is an actual list
if type(meeting) is XmlDictConfig: if type(meeting) is XmlDictConfig:
...@@ -226,7 +230,8 @@ def sum_meetings(config: Config, meetings: Optional[XmlDictConfig]) -> Optiona ...@@ -226,7 +230,8 @@ def sum_meetings(config: Config, meetings: Optional[XmlDictConfig]) -> Optiona
active_endpoints = [m for m in meetings if m != ["unreachable"]] active_endpoints = [m for m in meetings if m != ["unreachable"]]
if len(active_endpoints) == 0: if len(active_endpoints) == 0:
return config, None eprint("No active endpoint...")
return config, ["unreachable"]
summed_endpoint = [] summed_endpoint = []
...@@ -253,9 +258,11 @@ def meetings_twolines(config: Config, watch: int, fancy: bool, sum_:bool): ...@@ -253,9 +258,11 @@ def meetings_twolines(config: Config, watch: int, fancy: bool, sum_:bool):
# Request Meetings from API # Request Meetings from API
meetings = [get_meetings(e.secret, e.url, config.path, sum_) for e in config.endpoints] meetings = [get_meetings(e.secret, e.url, config.path, sum_) for e in config.endpoints]
config_override = copy.deepcopy(config)
# Collate meetings from all endpoints together in sum mode # Collate meetings from all endpoints together in sum mode
if sum_: if sum_:
config, meetings = sum_meetings(config, meetings) config_override, meetings = sum_meetings(config_override, meetings)
if sum_ and fancy: if sum_ and fancy:
config.endpoints[0].name = "bbb" config.endpoints[0].name = "bbb"
...@@ -265,7 +272,7 @@ def meetings_twolines(config: Config, watch: int, fancy: bool, sum_:bool): ...@@ -265,7 +272,7 @@ def meetings_twolines(config: Config, watch: int, fancy: bool, sum_:bool):
if watch is not None: if watch is not None:
click.clear() click.clear()
for i, endpoint in enumerate(config.endpoints): for i, endpoint in enumerate(config_override.endpoints):
# Print divider if there is more than one endpoint # Print divider if there is more than one endpoint
if i > 0: if i > 0:
print("="*click.get_terminal_size()[0]) print("="*click.get_terminal_size()[0])
...@@ -300,11 +307,10 @@ def meetings_twolines(config: Config, watch: int, fancy: bool, sum_:bool): ...@@ -300,11 +307,10 @@ def meetings_twolines(config: Config, watch: int, fancy: bool, sum_:bool):
print(lines) print(lines)
continue continue
# There should be no unreachable meetings in sum mode # print this if the endpoint (or all endpoints!) is unreachable
if not sum_: if meeting[0] == "unreachable":
if meeting[0] == "unreachable": printing.print_header(endpoint.name, "No connection..", fancy)
printing.print_header(endpoint.name, "No connection..", fancy) continue
continue
# Make sure meeting is always a list # Make sure meeting is always a list
if type(meeting) is XmlDictConfig: if type(meeting) is XmlDictConfig:
...@@ -321,7 +327,7 @@ def meetings_twolines(config: Config, watch: int, fancy: bool, sum_:bool): ...@@ -321,7 +327,7 @@ def meetings_twolines(config: Config, watch: int, fancy: bool, sum_:bool):
avg_s = avg_s/60./60. avg_s = avg_s/60./60.
if not fancy: if not fancy:
if config.on_server: if config_override.on_server:
# If on server get load # If on server get load
w = subprocess.run(["w | head -1"], shell=True, stdout=subprocess.PIPE) w = subprocess.run(["w | head -1"], shell=True, stdout=subprocess.PIPE)
w = w.stdout.decode('utf-8').strip().split("load average:") w = w.stdout.decode('utf-8').strip().split("load average:")
......
[tool.poetry] [tool.poetry]
name = "bbbmon" name = "bbbmon"
version = "0.1.30" version = "0.1.31"
description = "A small CLI utility to monitor bbb usage" description = "A small CLI utility to monitor bbb usage"
authors = ["David Huss <david.huss@hfbk-hamburg.de>"] authors = ["David Huss <david.huss@hfbk-hamburg.de>"]
maintainers = ["David Huss <david.huss@hfbk-hamburg.de>"] maintainers = ["David Huss <david.huss@hfbk-hamburg.de>"]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment