def health( endpoint, appkey, http_url, http, http_extra_check, rolename, rolesecret, channel, retry, ): '''Health check \b cobra health --http \b cobra health --http --http_url 'http://127.0.0.1:8765/health/' \b ''' url = makeUrl(endpoint, appkey) if http: print('url:', http_url) with urllib.request.urlopen(http_url) as response: html = response.read() print(html.decode('utf8'), end='') else: try: healthCheck(url, rolename, rolesecret, channel, retry, http_extra_check) except Exception as e: click.secho(f'System is unhealthy !!: {e}', fg='red') sys.exit(1) click.secho('System is healthy', fg='green')
def admin(endpoint, appkey, rolename, rolesecret, action, connection_id): '''Execute admin operations on the server \b cobra admin --action disconnect --connection_id 3919dc67 ''' url = makeUrl(endpoint, appkey) credentials = createCredentials(rolename, rolesecret) asyncio.get_event_loop().run_until_complete( adminCoroutine(url, credentials, action, connection_id))
def monitor( endpoint, appkey, rolename, rolesecret, raw, role_filter, channel_filter, metric_filter, hide_nodes, hide_roles, hide_channels, hide_summary, subscribers, system, once, tidy, unsafe, ): '''Monitor cobra ''' url = makeUrl(endpoint, appkey) credentials = createCredentials(rolename, rolesecret) if tidy: hide_nodes = True hide_roles = True hide_channels = True retry = not unsafe runMonitor( url, credentials, raw, role_filter, channel_filter, metric_filter, not hide_nodes, not hide_roles, not hide_channels, not hide_summary, subscribers, system, once, retry, )
def read(endpoint, appkey, rolename, rolesecret, channel, position): '''Read from the cobra key value store ''' url = makeUrl(endpoint, appkey) credentials = createCredentials(rolename, rolesecret) async def handler(url, credentials, channel, position): connection = Connection(url, credentials) await connection.connect() try: data = await connection.read(channel, position) except ActionException as e: logging.error(f'Action error: {e}') return await connection.close() print() print(f'handler received message {data}') asyncio.get_event_loop().run_until_complete( handler(url, credentials, channel, position))
def subscribe( endpoint, appkey, rolename, rolesecret, channel, position, stream_sql, resume_from_last_position, batch_size, disable_debug_memory, ): '''Subscribe to a channel ''' url = makeUrl(endpoint, appkey) credentials = createCredentials(rolename, rolesecret) resumeFromLastPositionId = '' if resume_from_last_position: resumeFromLastPositionId = f'{channel}::{stream_sql}' asyncio.get_event_loop().run_until_complete( subscribeClient( url, credentials, channel, position, stream_sql, MessageHandlerClass, { 'resume_from_last_position': resume_from_last_position, 'disable_debug_memory': disable_debug_memory, }, resumeFromLastPosition=resume_from_last_position, resumeFromLastPositionId=resumeFromLastPositionId, batchSize=batch_size, ) )
def publish( endpoint, appkey, channel, path, rolename, rolesecret, batch, batch_events_path, limit, repeat, delay, summary, ): '''Publish to a channel ''' if batch: path = batch_events_path url = makeUrl(endpoint, appkey) credentials = createCredentials(rolename, rolesecret) run(url, channel, path, credentials, repeat, delay, limit, summary)
def write(endpoint, appkey, rolename, rolesecret, channel, data, repeat): '''Write to the cobra key value store ''' url = makeUrl(endpoint, appkey) credentials = createCredentials(rolename, rolesecret) async def handler(url, credentials, channel, data, repeat): connection = Connection(url, credentials) await connection.connect() try: while True: await connection.write(channel, data) if not repeat: break except ActionException as e: logging.error(f'Action error: {e}') return await connection.close() asyncio.get_event_loop().run_until_complete( handler(url, credentials, channel, data, repeat))