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_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_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 gelf(self): "Return the Graylog logger client." if not hasattr(self, '_gelf'): self._gelf = UdpClient(self.gelf_server, port=self.gelf_port, mtu=self.mtu, source=self.source) return self._gelf
def __init__(self): try: self.gelf = UdpClient('162.219.4.234', port=12201, mtu=8000, source=socket.gethostname()) except socket.error, (value, message): print "Could not open socket: " + message
def __init__(self): self.zone = rs.get("zone") self.bike = rs.get("bike") self.myip="myip" print(self.zone,self.bike) try: self.target = liblo.Address("192.168.100.100",1234) except liblo.AddressError as err: print(err) sys.exit() try: self.gelf = UdpClient('162.219.4.234', port=12201, mtu=8000, source=socket.gethostname()) except socket.error, (value,message): print "Could not open socket: " + message
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_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_source(self): gelf = GelfUdp(HOST, PORT, source='source') jsn = gelf.log(sys._getframe().f_code.co_name) self.assertEqual(jsn['host'], 'source')
"start": time_frame, "stop": current_time, "format": "json" })) print(measurement_url) try: d = requests.get(measurement_url) except Exception as e: print e exit(1) data = d.json() gelf = UdpClient(gelf_server, port=gelf_port) for probe in data: print(probe['prb_id']) log = {} connection = do_db_check() cursor = connection.cursor() probeid = do_db_check_probe(cursor, probe['prb_id']) if probeid is None: content_probes_raw = requests.get( 'https://atlas.ripe.net/api/v2/probes/' + str(probe['prb_id']) + '/') details = content_probes_raw.json() longitude = details['geometry']['coordinates'][0] latitude = details['geometry']['coordinates'][1] country_code = details['country_code'] else:
import random import string from gelfclient import UdpClient import argparse parser = argparse.ArgumentParser(description='transactions generator') parser.add_argument('TransactionsNumber', type=int, help="Number of email transactions to generate") 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)
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')
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)
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_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_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_default_log_level(self): gelf = GelfUdp(HOST, PORT) jsn = gelf.log(sys._getframe().f_code.co_name) self.assertEquals(jsn['level'], 1)
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_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_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!')
**上报内容可以丢,但不能抛出异常** **上报内容可以丢,但不能抛出异常** **上报内容可以丢,但不能抛出异常** """ import json import sys import traceback from gelfclient import UdpClient from urllib.parse import unquote, urlencode # from utils.myBoomFilter import myBF from utils import common log_gelf_udp = UdpClient('127.0.0.1', port=52201) def send_to_graylog_tornado(gelf_data, req=None, path=None, req_data=None): """ 发送日志到graylog """ if 'source' in gelf_data or '_source' in gelf_data: return if 'short_message' not in gelf_data: return message = gelf_data['short_message'].replace(' ', '') import utils.myCache log_rule = utils.myCache.Cacheing.GetLogRule()
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')
"stop": current_time, "format": "json" }) ) print(measurement_url) try: d = requests.get(measurement_url) except Exception as e: print e exit(1) data = d.json() gelf = UdpClient(gelf_server, port=gelf_port) for probe in data: print(probe['prb_id']) log = {} connection = do_db_check() cursor = connection.cursor() probeid = do_db_check_probe(cursor, probe['prb_id']) if probeid is None: content_probes_raw = requests.get('https://atlas.ripe.net/api/v2/probes/' + str(probe['prb_id']) + '/') 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]