def test_shutdown_exception(self): class ShutdownExceptionPlugin(seer_plugin.DataCollectorPlugin): def shutdown(self): raise Exception def testing_exception(deliv, data): deliv.stop() delivery = seer_plugin.PluginDelivery([ShutdownExceptionPlugin], testing_exception) delivery.start()
def test_data_exception(self): class DataExceptionPlugin(seer_plugin.DataCollectorPlugin): def collect(self): raise Exception def testing_exception(deliv, data): self.assertEquals(1, len(data)) self.assertEquals(1, data['test']) deliv.stop() delivery = seer_plugin.PluginDelivery( [DataExceptionPlugin, plugins.test_plugins.ActualTestCollector], testing_exception) delivery.start()
def test_collect(self): plugs = \ [ plugins.test_plugins.ActualTestCollector, plugins.test_plugins.ActualTestCollector2 ] def testing_data_return(deliv, data): self.assertEquals(1, data['test']) self.assertEquals(64, data['howdy!']) deliv.stop() delivery = seer_plugin.PluginDelivery(plugs, testing_data_return) delivery.start()
def test_shutdown(self): test_value = 'test' test_list = [] class TestShutdownPlugin(seer_plugin.DataCollectorPlugin): def shutdown(self): test_list.append(test_value) def testing_shutdown(deliv, data): deliv.stop() delivery = seer_plugin.PluginDelivery([TestShutdownPlugin], testing_shutdown) delivery.start() self.assertEquals([test_value], test_list)
def test_init(self): test_value = 100 class TestInitPlugin(seer_plugin.DataCollectorPlugin): def init(self): self.test = test_value def collect(self): return {'test': self.test} def testing_init(deliv, data): self.assertEquals(test_value, data['test']) deliv.stop() delivery = seer_plugin.PluginDelivery([TestInitPlugin], testing_init) delivery.start()
def test_init_exception(self): test_key = 'test' class InitExceptionPlugin(seer_plugin.DataCollectorPlugin): def init(self): raise Exception def collect(self): return {test_key: test_key} def testing_exception(deliv, data): self.assertFalse(test_key in data) deliv.stop() delivery = seer_plugin.PluginDelivery([InitExceptionPlugin], testing_exception) delivery.start()
logging.getLogger('urllib3').setLevel(logging.WARNING) http_session = requests.Session() timeout = None if seer_config.data_collection_timeout is None else seer_config.data_collection_timeout / 1000 url = '{}:{}{}'.format(seer_config.delphi_address, seer_config.delphi_port, seer_config.delphi_endpoint) # Since Python lambdas suck, I need to make # a function. Capturing variables such # as http_session and url. def http_send_json(delivery_system, data): headers = {'Content-Type': 'application/json'} try: r = http_session.post(url, headers=headers, data=json.dumps(data)) if r.status_code not in [requests.codes.ok, requests.codes.no_content, requests.codes.bad_request]: logging.error(f'Error sending delivery. Status code: {r.status_code}') delivery_system.stop() connection_tries = 0 except requests.exceptions.ConnectionError as e: logging.error(f'Unable to connect to delphi, stopping: {e}') delivery_system.stop() if len(PLUGINS) == 0: logging.error('No plugins loaded!') sys.exit(1) delivery = seer_plugin.PluginDelivery(PLUGINS, http_send_json, seer_config.data_collection_timeout, seer_config.data_collection_queue_size) delivery.start()