def test_nuoca_function(self): self.assertTrue(os.path.isdir(self._topdir)) self.assertTrue(os.path.isdir(self._plugin_dir)) self.assertTrue(os.path.isdir(self._config_dir)) nuoca.nuoca_run(config_file=os.path.join(self._config_dir, "counter_quick.yml"), collection_interval=1, log_level="ERROR", plugin_dir=self._plugin_dir, self_test=True, starttime=nuoca_util.nuoca_gettimestamp() + 3, verbose=False, output_values=None)
def collect(self, collection_interval): """ NuoCA Input Plugins must implement their own collect() method. The NuoCA Input Plugins must call this collect() method at the top of their collect() method. This method returns a python dictionary of values that each NuoCA Input Plugin should add to their own time-series information. Note: The plugin's collect() method must return a Python list of one or more Python dictionaries that contain time-series values. NuoCA will call the collect() method at the end of each Collection Interval. :param collection_interval: Collection Interval :type collection_interval: ``int`` :return: time-series values :type: ``dict`` """ rval = { 'nuoca_plugin': self._collection_name, 'collect_timestamp': nuoca_gettimestamp() * 1000 } return rval
def _NuoAdminMonitorPluginTest(self): nuoca_util.initialize_logger("/tmp/nuoca.test.log") print("Testing NuoAdminMon with missing config file") nuoAdminMonitor_plugin = NuoAdminMonitorPlugin(None) self.assertIsNotNone(nuoAdminMonitor_plugin) empty_config = {} startup_rval = nuoAdminMonitor_plugin.startup(empty_config) self.assertFalse(startup_rval) expected_err_msg = "NuoAdminMon plugin: missing config file." self.assertEquals(expected_err_msg, nuoca_util.nuoca_get_last_log_error_message()) nuoAdminMonitor_plugin.shutdown() print("Testing NuoAdminMon with invalid admin_host config") nuoAdminMonitor_plugin = NuoAdminMonitorPlugin(None) self.assertIsNotNone(nuoAdminMonitor_plugin) start_ts = nuoca_util.nuoca_gettimestamp() config = { 'admin_host': 'no-such-localhost', 'domain_username': '******', 'domain_password': '******', 'nuoca_start_ts': start_ts } startup_rval = nuoAdminMonitor_plugin.startup(config) self.assertTrue(startup_rval) time.sleep(13) resp_values = nuoAdminMonitor_plugin.collect(3) expected_msg = "Max retries exceeded with url" for resp_item in resp_values: self.assertTrue('nuoca_collection_error' in resp_item) if 'nuoca_collection_error' in resp_item: self.assertTrue( expected_msg in resp_item['nuoca_collection_error']) nuoAdminMonitor_plugin.shutdown() print("Testing NuoAdminMon with invalid admin_rest_api_port config") nuoAdminMonitor_plugin = NuoAdminMonitorPlugin(None) self.assertIsNotNone(nuoAdminMonitor_plugin) start_ts = nuoca_util.nuoca_gettimestamp() config = { 'admin_host': 'localhost', 'admin_rest_api_port': 8901, 'domain_username': '******', 'domain_password': '******', 'nuoca_start_ts': start_ts } startup_rval = nuoAdminMonitor_plugin.startup(config) self.assertTrue(startup_rval) time.sleep(13) resp_values = nuoAdminMonitor_plugin.collect(3) print(resp_values) expected_msg = "Max retries exceeded with url" for resp_item in resp_values: self.assertTrue('nuoca_collection_error' in resp_item) if 'nuoca_collection_error' in resp_item: self.assertTrue( expected_msg in resp_item['nuoca_collection_error']) nuoAdminMonitor_plugin.shutdown() print("Testing NuoAdminMon with invalid domain_password config") nuoAdminMonitor_plugin = NuoAdminMonitorPlugin(None) self.assertIsNotNone(nuoAdminMonitor_plugin) start_ts = nuoca_util.nuoca_gettimestamp() config = { 'admin_host': 'localhost', 'domain_username': '******', 'domain_password': '******', 'nuoca_start_ts': start_ts } startup_rval = nuoAdminMonitor_plugin.startup(config) self.assertTrue(startup_rval) time.sleep(13) resp_values = nuoAdminMonitor_plugin.collect(3) print(resp_values) expected_msg = "NuoAdminMon: Error code '401' when calling Admin Rest API" for resp_item in resp_values: self.assertTrue('nuoca_collection_error' in resp_item) if 'nuoca_collection_error' in resp_item: self.assertTrue( expected_msg in resp_item['nuoca_collection_error']) nuoAdminMonitor_plugin.shutdown() print("Testing NuoAdminMon with a valid NuoDB config/instance") nuoAdminMonitor_plugin = NuoAdminMonitorPlugin(None) self.assertIsNotNone(nuoAdminMonitor_plugin) start_ts = nuoca_util.nuoca_gettimestamp() config = { 'admin_host': 'localhost', 'admin_rest_api_port': 8888, 'domain_username': '******', 'domain_password': '******', 'host_uuid_shortname': True, 'admin_collect_interval': 10, 'admin_collect_timeout': 2, 'nuoca_start_ts': start_ts } startup_rval = nuoAdminMonitor_plugin.startup(config) self.assertTrue(startup_rval) time.sleep(13) resp_values = nuoAdminMonitor_plugin.collect(3) self.assertIsNotNone(resp_values) self.assertTrue(isinstance(resp_values, list)) self._validate_collection_response(resp_values) nuoAdminMonitor_plugin.shutdown()
def _collector_thread(self, collect_timestamp): region_result_desired_fields = [u'region'] host_result_desired_fields = \ [u'stableId', u'hostname', u'port', u'version', u'address', u'isBroker',u'ipaddress', u'id'] host_tags_desired_fields = \ [u'default_archive_base', u'journal_base', u'archive_base', u'default_region', u'region', u'os_num_cpu', u'cores', u'os_num_cores', u'default_journal_base', u'ostype', u'cputype', u'os_ram_mb', u'osversion', u'os_num_fs'] processes_desired_fields = \ [u'status', u'uid', u'hostname', u'pid', u'nodeId', u'port', u'version', u'address', u'agentid', u'type', u'dbname'] databases_desired_fields = \ [u'status', u'name', u'tagConstraints', u'variables', u'groupOptions', u'archivesByGroup', u'archives', u'template', u'active', u'unmet_messages', u'options', u'ismet'] collect_timestamp = nuoca_gettimestamp() * 1000 #print "\n\nCollection Timestamp: %s" % collect_timestamp enforcer_result = self.get_enforcer() #print "Result from Rest API %s: %s" % (self._domain_enforcer_url, enforcer_result) if 'nuoca_collection_error' in enforcer_result: results = {"TimeStamp": collect_timestamp} results['nuoca_collection_error'] = \ enforcer_result['nuoca_collection_error'] self._monitor_collect_queue.append(results) regions_result = self.get_regions() #print "Result from Rest API %s: %s" % (self._regions_url, regions_result) if 'nuoca_collection_error' in regions_result: results = {"TimeStamp": collect_timestamp} results['nuoca_collection_error'] = \ regions_result['nuoca_collection_error'] self._monitor_collect_queue.append(results) else: region_count = 0 for region in regions_result: results = {"TimeStamp": collect_timestamp} results[u'domainEnforcerEnabled'] = \ enforcer_result[u'domainEnforcerEnabled'] for region_field in region_result_desired_fields: results[region_field] = regions_result[region_count][ region_field] for host in region['hosts']: for host_field in host_result_desired_fields: results["admin.%s" % host_field] = host[host_field] for host_tag_field in host_tags_desired_fields: results["tag.%s" % host_tag_field] = host['tags'][host_tag_field] for process in host['processes']: process_results = {} for process_field in processes_desired_fields: process_results["process.%s" % process_field] \ = process[process_field] process_results.update(results) self._monitor_collect_queue.append(process_results) for database in region['databases']: database_results = {} for database_field in databases_desired_fields: database_results["database.%s" % database_field] = \ str(database[database_field]) database_results.update(results) self._monitor_collect_queue.append(database_results) region_count += 1
def _MultiprocessPluginManagerTest(self): child_pipe_timeout = 600 self.manager.setCategoriesFilter({ "Input": NuocaMPInputPlugin, "Ouput": NuocaMPOutputPlugin, "Transform": NuocaMPTransformPlugin }) print("Testing NuoAdminMon with a NuoCA multi-process manager") self.manager.collectPlugins() all_plugins = self.manager.getAllPlugins() self.assertTrue(all_plugins) self.assertTrue(len(all_plugins) > 0) nuoAdminMonitor_plugin = None for a_plugin in all_plugins: self.manager.activatePluginByName(a_plugin.name, 'Input') self.assertTrue(a_plugin.is_activated) if a_plugin.name == 'NuoAdminMon': nuoAdminMonitor_plugin = a_plugin self.assertIsNotNone(nuoAdminMonitor_plugin) start_ts = nuoca_util.nuoca_gettimestamp() config = { 'admin_host': 'localhost', 'domain_username': '******', 'domain_password': '******', 'host_uuid_shortname': True } plugin_msg = {'action': 'startup', 'config': config} plugin_resp_msg = None nuoAdminMonitor_plugin.plugin_object.child_pipe.send(plugin_msg) if nuoAdminMonitor_plugin.plugin_object.child_pipe.\ poll(child_pipe_timeout): plugin_resp_msg = nuoAdminMonitor_plugin.plugin_object.child_pipe.recv( ) self.assertIsNotNone(plugin_resp_msg) self.assertEqual(0, plugin_resp_msg['status_code']) time.sleep(13) plugin_msg = {'action': 'collect', 'collection_interval': 3} plugin_resp_msg = None nuoAdminMonitor_plugin.plugin_object.child_pipe.send(plugin_msg) if nuoAdminMonitor_plugin.plugin_object.child_pipe.\ poll(child_pipe_timeout): plugin_resp_msg = nuoAdminMonitor_plugin.plugin_object.child_pipe.recv( ) self.assertIsNotNone(plugin_resp_msg) resp_values = plugin_resp_msg['resp_values'] self.assertIsNotNone(resp_values) self.assertEqual(0, plugin_resp_msg['status_code']) self.assertIsNotNone(resp_values['collected_values']) self.assertTrue(resp_values['collected_values'], list) self._validate_collection_response(resp_values['collected_values']) plugin_msg = {'action': 'shutdown'} nuoAdminMonitor_plugin.plugin_object.child_pipe.send(plugin_msg) plugin_msg = {'action': 'exit'} nuoAdminMonitor_plugin.plugin_object.child_pipe.send(plugin_msg) for a_plugin in all_plugins: self.manager.deactivatePluginByName(a_plugin.name, 'Input') self.assertFalse(a_plugin.is_activated)