def get_discover(http_context, app, sessions): logger.info('Starting discovery.') try: sysinfo = SysInfo() with app.postgres.connect() as conn: pginfo = PgInfo(conn) ret = dict(hostname=sysinfo.hostname( app.config.temboard['hostname']), cpu=sysinfo.n_cpu(), memory_size=sysinfo.memory_size(), pg_port=pginfo.setting('port'), pg_version=pginfo.version()['full'], pg_version_summary=pginfo.version()['summary'], pg_data=pginfo.setting('data_directory'), plugins=[ plugin_name for plugin_name in app.config.temboard['plugins'] ]) logger.info('Discovery done.') return ret except (error, Exception, HTTPError) as e: logger.exception(e) logger.info('Discovery failed.') if isinstance(e, HTTPError): raise e else: raise HTTPError(500, "Internal error.")
def get_discover(http_context, app, sessions): logger.info('Starting discovery.') # Optionnal validation of key. For compatibility, we accept unauthenticated # /discover. But for better reliability, we validate a key sent by HTTP # header. temboard-agent-register sends key to prevent configuration # mismatch. request_key = http_context['headers'].get('X-Temboard-Agent-Key') if request_key and request_key != app.config.temboard['key']: raise HTTPError(401, "Invalid key") discover = dict( hostname=None, cpu=None, memory_size=None, pg_port=app.config.postgresql['port'], pg_version=None, pg_version_summary=None, pg_data=None, plugins=[plugin for plugin in app.config.temboard['plugins']], ) try: # Gather system informations sysinfo = SysInfo() hostname = sysinfo.hostname(app.config.temboard['hostname']) cpu = sysinfo.n_cpu() memory_size = sysinfo.memory_size() except (Exception, HTTPError) as e: logger.exception(str(e)) logger.error('System discovery failed.') # We stop here if system information has not been collected if isinstance(e, HTTPError): raise e else: raise HTTPError(500, "Internal error.") discover.update(hostname=hostname, cpu=cpu, memory_size=memory_size) try: with app.postgres.connect() as conn: pginfo = PgInfo(conn) discover.update(pg_block_size=int(pginfo.setting('block_size')), pg_version=pginfo.version()['full'], pg_version_summary=pginfo.version()['summary'], pg_data=pginfo.setting('data_directory')) except Exception as e: logger.exception(str(e)) logger.error('Postgres discovery failed.') # Do not raise HTTPError, just keeping null values for Postgres # informations. logger.info('Discovery done.') logger.debug(discover) return discover
def get_discover(http_context, app, sessions): logger.info('Starting discovery.') discover = dict( hostname=None, cpu=None, memory_size=None, pg_port=app.config.postgresql['port'], pg_version=None, pg_version_summary=None, pg_data=None, plugins=[plugin for plugin in app.config.temboard['plugins']], ) try: # Gather system informations sysinfo = SysInfo() hostname = sysinfo.hostname(app.config.temboard['hostname']) cpu = sysinfo.n_cpu() memory_size = sysinfo.memory_size() except (Exception, HTTPError) as e: logger.exception(str(e)) logger.error('System discovery failed.') # We stop here if system information has not been collected if isinstance(e, HTTPError): raise e else: raise HTTPError(500, "Internal error.") discover.update( hostname=hostname, cpu=cpu, memory_size=memory_size ) try: with app.postgres.connect() as conn: pginfo = PgInfo(conn) discover.update( pg_block_size=int(pginfo.setting('block_size')), pg_version=pginfo.version()['full'], pg_version_summary=pginfo.version()['summary'], pg_data=pginfo.setting('data_directory') ) except Exception as e: logger.exception(str(e)) logger.error('Postgres discovery failed.') # Do not raise HTTPError, just keeping null values for Postgres # informations. logger.info('Discovery done.') logger.debug(discover) return discover
def get_discover(http_context, config=None, sessions=None): conn = connector(host=config.postgresql['host'], port=config.postgresql['port'], user=config.postgresql['user'], password=config.postgresql['password'], database=config.postgresql['dbname']) logger.info('Starting discovery.') try: conn.connect() sysinfo = SysInfo() pginfo = PgInfo(conn) ret = { 'hostname': sysinfo.hostname(config.temboard['hostname']), 'cpu': sysinfo.n_cpu(), 'memory_size': sysinfo.memory_size(), 'pg_port': pginfo.setting('port'), 'pg_version': pginfo.version()['full'], 'pg_data': pginfo.setting('data_directory'), 'plugins': [plugin_name for plugin_name in config.temboard['plugins']] } conn.close() logger.info('Discovery done.') return ret except (error, Exception, HTTPError) as e: logger.exception(str(e)) logger.info('Discovery failed.') try: conn.close() except Exception: pass if isinstance(e, HTTPError): raise e else: raise HTTPError(500, "Internal error.")