diff --git a/bbbmon/bbbmon.py b/bbbmon/bbbmon.py index 6b4c394d48cc156c55681f7f712b377c6d2f761b..da0451b59bd240e70fe1eeb66d371be6892b93ed 100755 --- a/bbbmon/bbbmon.py +++ b/bbbmon/bbbmon.py @@ -177,6 +177,31 @@ def json(ctx, userconfig, watch, endpoint, compact): print(format_json(config, watch, compact)) +@main.command(context_settings=CONTEXT_SETTINGS) +@click.pass_context +@click.option('--watch', '-w', help="Run repeatedly with the given interval in seconds", type=click.IntRange(2, 2147483647, clamp=True)) +@click.option('--compact/--pretty', '-c/-p', default=False, show_default=True, help="Print pretty and indented json or compact") +@click.option('--userconfig', '-u', is_flag=True, help="Use user config even if on server") +@click.option('--endpoint', '-e', multiple=True, help="Filter by one or more endpoints as named in the user configuration (e.g. [servername]). Order is respected.") +def raw(ctx, userconfig, watch, endpoint, compact): + """Print raw response""" + config = init_config(userconfig) + config.filter_endpoints(endpoint) + if not config.endpoints: + exit() + if watch is not None: + while watch is not None: + try: + for m in format_raw(config, watch, compact): + print(m) + time.sleep(watch) + except KeyboardInterrupt: + sys.exit() + else: + for m in format_raw(config, watch, compact): + print(m) + + if __name__ == "__main__": diff --git a/bbbmon/meetings.py b/bbbmon/meetings.py index 4ad91005495827a22f3daa96714cd6a60d40e700..553e6edef70150c2e0188425dbcea9bc307d141b 100644 --- a/bbbmon/meetings.py +++ b/bbbmon/meetings.py @@ -4,6 +4,7 @@ import time import copy import subprocess +import xml.dom.minidom import hashlib import json from datetime import datetime, timedelta @@ -33,6 +34,27 @@ def generate_checksum(call_name: str, query_string: str, secret: Secret) -> str: return m.hexdigest() + +def request_raw_meetings(secret: Secret, bbb_url: Url, user_config_path: str) -> str: + """ + Make a getMeetings-API Call to the bbb instance and return a XmlDictConfig + with the servers response + """ + call_name = "getMeetings" + checksum = generate_checksum(call_name, "", secret) + url = "{}/api/{}?checksum={}".format(bbb_url, call_name, checksum) + + try: + r = requests.get(url, timeout=3) + return r.text + except requests.exceptions.Timeout as e: + # Offline Server! + return "" + except: + # Offline Server! + return "" + + def request_meetings(secret: Secret, bbb_url: Url, user_config_path: str, sum_: bool) -> XmlDictConfig: """ Make a getMeetings-API Call to the bbb instance and return a XmlDictConfig @@ -366,13 +388,11 @@ def meetings_twolines(config: Config, watch: int, fancy: bool, sum_:bool): def format_json(config: Config, watch: bool, compact: bool) -> str: """ - Get the running meetings + Get the running meetings as json """ meetings = [] for e, meeting in [(e, get_meetings(e.secret, e.url, config.path, sum_=False)) for e in config.endpoints]: - # metting = [m for m in ] - if meeting == ["unreachable"]: meeting = [{"unreachable" : "true"}] else: @@ -393,3 +413,24 @@ def format_json(config: Config, watch: bool, compact: bool) -> str: return str(json.dumps(meetings)) else: return str(json.dumps(meetings, indent=4)) + + +def format_raw(config: Config, watch: bool, compact: bool) -> str: + """ + Get the running meetings as raw xml response + """ + meetings = [] + + for e, meeting in [(e, request_raw_meetings(e.secret, e.url, config.path)) for e in config.endpoints]: + if not compact: + meeting = "\n".join([l for l in xml.dom.minidom.parseString(str(meeting)).toprettyxml().split("\n") if l.strip() != ""]) + else: + meeting = str("".join(meeting.split("\n"))) + meetings.append(meeting) + + # Clear screen after request is done, and before printing new data to keep + # blinking to a minimum + if watch is not None: + click.clear() + + return meetings \ No newline at end of file