def get_connection_status(cls, me, hostnames, data): host_stats = [('hostname', 'state', 'start time', 'duration (sec)')] for h in hostnames: connection_color = '91' # red h_safe = safe_name(h) prefix = f'awx_{h_safe}' connection_state = data.get(f'{prefix}_connection', 'N/A') connection_started = 'N/A' connection_duration = 'N/A' if connection_state is None: connection_state = 'unknown' if connection_state == 'connected': connection_color = '92' # green connection_started = data.get(f'{prefix}_connection_start', 'Error') if connection_started != 'Error': connection_started = datetime.datetime.fromtimestamp( connection_started) connection_duration = int( (dt.now() - connection_started).total_seconds()) connection_state = f'\033[{connection_color}m{connection_state}\033[0m' host_stats.append((h, connection_state, str(connection_started), str(connection_duration))) return host_stats
def get_connection_stats(cls, me, hostnames, data): host_stats = [('hostname', 'total', 'per minute')] for h in hostnames: h = safe_name(h) prefix = f'awx_{h}' messages_total = data.get(f'{prefix}_messages_received', 'N/A') messages_per_minute = data.get(f'{prefix}_messages_received_per_minute', 'N/A') host_stats.append((h, str(int(messages_total)), str(int(messages_per_minute)))) return host_stats