def _secho(msg, **kwargs): elapsed_seconds = time.time() - START_TIME # using timedelta here for convenient default formatting elapsed = timedelta(seconds=elapsed_seconds) secho( '[{} | {}] {}'.format( getattr(THREADDATA, 'name', 'GLOBAL').rjust(PATTERNLENGTH), elapsed, msg), **kwargs)
def check_endpoint(account, endpoint, port, show_public_only): if port in SSL_PORTS: scheme = 'https' else: scheme = 'http' url = '{}://{}:{}/'.format(scheme, endpoint.split('/')[-1], port) try: r = requests.get(url, timeout=5, verify=False) do_print = True if r.status_code == 401: style = {'fg': 'green', 'bold': True} if show_public_only: do_print = False else: style = {'fg': 'yellow', 'bold': True} if do_print: secho('{} {} {} {}'.format(account, url, r.status_code, r.text.strip().replace('\n', ' ')[:40]), **style) except Exception as e: if not show_public_only: secho('{} {} {}'.format(account, url, str(e)[:40]))
def render_status(status, output=None): secho('Alerts active: {}'.format(status.get('alerts_active'))) info('Workers:') rows = [] for worker in status.get('workers', []): rows.append(worker) rows.sort(key=lambda x: x.get('name')) print_table(['name', 'check_invocations', 'last_execution_time'], rows) info('Queues:') rows = [] for queue in status.get('queues', []): rows.append(queue) rows.sort(key=lambda x: x.get('name')) print_table(['name', 'size'], rows)
def __enter__(self): if self.output == 'text' and not self.printer: action(self.msg) if self.nl: secho('') return self
def _print_table(title, rows): info(title) rows.sort(key=lambda x: x.get('title')) print_table(['id', 'title', 'team', 'link'], rows) secho('')
def _secho(msg, **kwargs): elapsed_seconds = time.time() - START_TIME # using timedelta here for convenient default formatting elapsed = timedelta(seconds=elapsed_seconds) secho('[{} | {}] {}'.format(getattr(THREADDATA, 'name', 'GLOBAL').rjust(PATTERNLENGTH), elapsed, msg), **kwargs)