def test_log_minimum(self): gelf = GelfUdp(HOST, PORT) jsn = gelf.log(sys._getframe().f_code.co_name) msg = jsn['short_message'] self.assertEqual(msg, sys._getframe().f_code.co_name) self.assertEqual(jsn['host'], socket.gethostname()) self.assertIsInstance(jsn['version'], string_types)
def test_log_minimum(self): gelf = GelfUdp(HOST, PORT) jsn = gelf.log(sys._getframe().f_code.co_name) msg = jsn['short_message'] self.assertEquals(msg, sys._getframe().f_code.co_name) self.assertEquals(jsn['host'], socket.gethostname()) self.assertIsInstance(jsn['version'], basestring)
def test_log_extra_value(self): gelf = GelfUdp(HOST, PORT) jsn = gelf.log(sys._getframe().f_code.co_name, server='server', test='test') self.assertEqual(jsn['server'], 'server') self.assertEqual(jsn['test'], 'test')
def test_log_source_override(self): gelf = GelfUdp(HOST, PORT, source='source') jsn = gelf.log(sys._getframe().f_code.co_name, source='notsource') self.assertEqual(jsn['host'], 'notsource') jsn = gelf.log(sys._getframe().f_code.co_name, host='notsource') self.assertEqual(jsn['host'], 'notsource')
def test_log_source(self): gelf = GelfUdp(HOST, PORT, source='source') jsn = gelf.log(sys._getframe().f_code.co_name) self.assertEquals(jsn['host'], 'source')
def test_log_source(self): gelf = GelfUdp(HOST, PORT, source='source') jsn = gelf.log(sys._getframe().f_code.co_name) self.assertEqual(jsn['host'], 'source')
def test_wrong_type_for_level(self): gelf = GelfUdp(HOST, PORT) with self.assertRaises(ValueError): jsn = gelf.log(sys._getframe().f_code.co_name, level='not a number!')
def test_different_log_level(self): gelf = GelfUdp(HOST, PORT) for level in [0, 4, '0', '3', '7']: jsn = gelf.log(sys._getframe().f_code.co_name, level=level) self.assertEqual(jsn['level'], int(level))
def test_log_chunked_small_mtu(self): gelf = GelfUdp(HOST, PORT, mtu=50) data = random_string(gelf.mtu * 5) jsn = gelf.log(sys._getframe().f_code.co_name, data=data)
def test_log_timestamp(self): gelf = GelfUdp(HOST, PORT) ts = time.time() - 120 # override timestamp 2 mintes in past jsn = gelf.log(sys._getframe().f_code.co_name, timestamp = ts) self.assertEquals(jsn['timestamp'], ts)
def test_log_extra_value(self): gelf = GelfUdp(HOST, PORT) jsn = gelf.log(sys._getframe().f_code.co_name, server='server', test='test') self.assertEquals(jsn['server'], 'server') self.assertEquals(jsn['test'], 'test')
def test_log_source_override(self): gelf = GelfUdp(HOST, PORT, source='source') jsn = gelf.log(sys._getframe().f_code.co_name, source='notsource') self.assertEquals(jsn['host'], 'notsource') jsn = gelf.log(sys._getframe().f_code.co_name, host='notsource') self.assertEquals(jsn['host'], 'notsource')
longitude = details['geometry']['coordinates'][0] latitude = details['geometry']['coordinates'][1] country_code = details['country_code'] else: geodata = do_db_select_geodata(cursor, probe['prb_id']) longitude = geodata[0] latitude = geodata[1] country_code = geodata[2] connection.close() location = get_place(probe['prb_id'], country_code, latitude, longitude, current_time) log['short_message'] = 'RIPE Atlas Data of Probe ' + str(probe['prb_id']) log['host'] = 'ripe-atlas' log['level'] = syslog.LOG_INFO log['timestamp'] = probe['timestamp'] log['_ripe_atlas_prbid'] = probe['prb_id'] log['_ripe_atlas_dst_addr'] = probe['dst_addr'] log['_ripe_atlas_src_addr'] = probe['from'] log['_ripe_atlas_type'] = probe['type'] log['_ripe_atlas_proto'] = probe['proto'] log['_ripe_atlas_sent_pkts'] = probe['sent'] log['_ripe_atlas_country'] = country_code log['_ripe_atlas_location'] = location[0] + ',' + location[1] log['_ripe_atlas_location_extended'] = location[0] + ',' + location[ 1] + ',' + location[2] log['_ripe_atlas_rcvd_pkts'] = probe['rcvd'] log['_ripe_atlas_avg_rtt'] = probe['avg'] log['_ripe_atlas_max_rtt'] = probe['max'] log['_ripe_atlas_min_rtt'] = probe['min'] gelf.log(log)
def test_default_log_level(self): gelf = GelfUdp(HOST, PORT) jsn = gelf.log(sys._getframe().f_code.co_name) self.assertEquals(jsn['level'], 1)
def test_log_timestamp(self): gelf = GelfUdp(HOST, PORT) ts = time.time() - 120 # override timestamp 2 mintes in past jsn = gelf.log(sys._getframe().f_code.co_name, timestamp=ts) self.assertEqual(jsn['timestamp'], ts)
def test_different_log_level(self): gelf = GelfUdp(HOST, PORT) for level in [0, 4, '0', '3', '7']: jsn = gelf.log(sys._getframe().f_code.co_name, level=level) self.assertEquals(jsn['level'], int(level))
def test_default_log_level(self): gelf = GelfUdp(HOST, PORT) jsn = gelf.log(sys._getframe().f_code.co_name) self.assertEqual(jsn['level'], 1)
def test_out_of_range_level(self): gelf = GelfUdp(HOST, PORT) for level in [-1, 8]: with self.assertRaises(AssertionError): jsn = gelf.log(sys._getframe().f_code.co_name, level=level)
parser.add_argument('ElasticVersion', help="ElasticSearch version: e.g. '5.6' or '6.8'") args = parser.parse_args() gelf_server = 'localhost' gelf = UdpClient(gelf_server, port=11001, source='log_generator') ev = args.ElasticVersion transactionsnum = args.TransactionsNumber domains = [] domainnum = 100 # Pregenerate domains for i in range(0, domainnum): domain = ''.join(random.choices( string.ascii_lowercase, k=10)) + '.' + ''.join( random.choices(string.ascii_lowercase, k=3)) domains.append(domain) # Log transactions for i in range(0, transactionsnum): sender = ''.join(random.choices(string.ascii_lowercase, k=10)) + '@' + random.choice(domains) rcpt = ''.join(random.choices(string.ascii_lowercase, k=10)) + '@' + random.choice(domains) qid = ''.join(random.choices(string.digits + string.ascii_uppercase, k=14)) gelf.log('mta transaction', _qid=qid, _from=sender, _to=rcpt, _fromdomain=sender.split('@')[1], _todomain=rcpt.split('@')[1], _elasticversion=ev)
details = content_probes_raw.json() longitude = details['geometry']['coordinates'][0] latitude = details['geometry']['coordinates'][1] country_code = details['country_code'] else: geodata = do_db_select_geodata(cursor, probe['prb_id']) longitude = geodata[0] latitude = geodata[1] country_code = geodata[2] connection.close() location = get_place(probe['prb_id'], country_code, latitude, longitude, current_time) log['short_message'] = 'RIPE Atlas Data of Probe ' + str(probe['prb_id']) log['host'] = 'ripe-atlas' log['level'] = syslog.LOG_INFO log['timestamp'] = probe['timestamp'] log['_ripe_atlas_prbid'] = probe['prb_id'] log['_ripe_atlas_dst_addr'] = probe['dst_addr'] log['_ripe_atlas_src_addr'] = probe['from'] log['_ripe_atlas_type'] = probe['type'] log['_ripe_atlas_proto'] = probe['proto'] log['_ripe_atlas_sent_pkts'] = probe['sent'] log['_ripe_atlas_country'] = country_code log['_ripe_atlas_location'] = location[0] + ',' + location[1] log['_ripe_atlas_location_extended'] = location[0] + ',' + location[1] + ',' + location[2] log['_ripe_atlas_rcvd_pkts'] = probe['rcvd'] log['_ripe_atlas_avg_rtt'] = probe['avg'] log['_ripe_atlas_max_rtt'] = probe['max'] log['_ripe_atlas_min_rtt'] = probe['min'] gelf.log(log)