def collect(self): """ Overrides the Collector.collect method """ #check to see if the dns name returns an IP address for dnsAddress in self.config['dnsAddressList']: try: addr = socket.gethostbyname(dnsAddress) check = netuitive.Check(dnsAddress, self.hostname, self.ttl) self.api.post_check(check) except socket.gaierror: self.log.error('cannot resolve hostname')
def test_failure_general_http(self, mock_logging, mock_post): mock_post.return_value = MockResponse(code=500) # test infrastructure endpoint url creation a = netuitive.Client(api_key='apikey') mock_post.side_effect = urllib2.HTTPError(a.url, 500, '', {}, None) e = netuitive.Check('check', 'test', 60) resp = a.post_check(e) self.assertNotEqual(resp, True) self.assertEquals(mock_post.call_count, a.max_check_retry_count + 1) self.assertEqual(mock_logging.exception.call_args_list[0][0][0], 'HTTPError posting payload to api ingest endpoint (%s): %s')
def test_not_kill_switch_504(self, mock_logging, mock_post): mock_post.return_value = MockResponse(code=504) # test infrastructure endpoint url creation a = netuitive.Client(api_key='apikey') mock_post.side_effect = urllib2.HTTPError(a.url, 504, '', {}, None) c = netuitive.Check('check', 'test', 60) resp = a.post_check(c) resp2 = a.post_check(c) self.assertNotEqual(resp, True) self.assertFalse(resp2) self.assertFalse(a.disabled) self.assertEqual(mock_logging.exception.call_args_list[0][0][0], 'HTTPError posting payload to api ingest endpoint (%s): %s')
def test_kill_switch_410(self, mock_logging, mock_post): mock_post.return_value = MockResponse(code=410) # test infrastructure endpoint url creation a = netuitive.Client(api_key='apikey') mock_post.side_effect = urllib2.HTTPError(a.url, 410, '', {}, None) c = netuitive.Check('check', 'test', 60) resp = a.post_check(c) resp2 = a.post_check(c) self.assertNotEqual(resp, True) self.assertFalse(resp2) self.assertTrue(a.disabled) self.assertEqual(mock_logging.exception.call_args_list[0][0][0], 'Posting has been disabled.See previous errors for details.')
def test_success(self, mock_logging, mock_post): mock_post.return_value = MockResponse(code=202) # test infrastructure endpoint url creation a = netuitive.Client(api_key='apikey') c = netuitive.Check('check', 'test', 60) resp = a.post_check(c) self.assertTrue(resp) args, kwargs = mock_post.call_args self.assertEqual(kwargs['timeout'], 5) self.assertEqual(mock_logging.exception.call_args_list, [])
def collect(self): """ Check each process defined under the `process` subsection of the config file """ if not psutil: self.log.error('Unable to import psutil, no process check performed') return None for process in psutil.process_iter(): self.collect_process_info(process) # check results for program_name, counters in self.processes_info.iteritems(): if counters and counters['up'] > 0: # send check ttl for the process check = netuitive.Check(program_name, self.hostname, self.ttl) self.api.post_check(check) # reinitialize process info self.processes_info[program_name] = {}
def collect(self): """ Overrides the Collector.collect method """ if psutil is None: self.log.error('Unable to import module psutil') return {} for port_name, port_cfg in self.ports.iteritems(): port = int(port_cfg['number']) if port_cfg['protocol'] == []: protocol = 'tcp' else: protocol = str(port_cfg['protocol']) stats = get_port_stats(port, protocol) for stat_name, stat_value in stats.iteritems(): if stat_name == 'listen' and stat_value >= 1: check_name = '%s.%d' % (port_name, port) check = netuitive.Check(check_name, self.hostname, self.ttl) self.api.post_check(check)
def setUp(self): self.check = netuitive.Check('checkName', 'elementId', 60)
MyElement = netuitive.Element() MyElement.add_attribute('Language', 'Python') MyElement.add_attribute('app_version', '7.0') MyElement.add_relation('my_child_element') MyElement.add_tag('Production', 'True') MyElement.add_tag('app_tier', 'True') timestamp = int(time.mktime(time.localtime())) MyElement.add_sample('app.error', timestamp, 1, host='appserver01') MyElement.add_sample('app.request', timestamp, 10, host='appserver01') ApiClient.post(MyElement) MyElement.clear_samples() MyEvent = netuitive.Event('appserver01', 'INFO', 'test event', 'this is a test message', 'INFO') ApiClient.post_event(MyEvent) MyCheck = netuitive.Check('heartbeat', 'element', 60) ApiClient.post_check(MyCheck) if ApiClient.time_insync(): print('we have time sync with the server')
def collect(self): check = netuitive.Check('heartbeat', self.hostname, self.ttl) self.api.post_check(check)