def test_get_time_out_of_filename(): assert ParseEvents.get_time_out_of_filename( 'consolelog-18-03-16-04.txt') == ParseEvents.get_time_out_of_filename( 'consolelog-18-03-16-05.txt') assert ParseEvents.get_time_out_of_filename( 'consolelog-18-03-16-04.txt') == 1521183600 with pytest.raises(ValueError): ParseEvents.get_time_out_of_filename( 'consolelsdfsdfog-18-03-16-04.txt')
def test_parse_shutdown(): event = ParseEvents( None, None, None, None).parse_line('18-09-19 04:10:47 Signal received, shutting down') assert isinstance(event, EventShutdown) event = ParseEvents( None, None, None, None).parse_line('18-09-19 04:10:47 Shutting down server...') assert isinstance(event, EventShutdown)
def update_events(r, keys, retention, filemanager): # Get kills and events out of our logs parse = ParseEvents(retention, filemanager) # Interact with redis to store and delete kills and events manage = ManageEvents(r, keys) for event in parse.get_events(): if event: manage.apply_event(event)
def test_parse_bare_log(): event = ParseEvents( None, None, None, None).parse_line('15-02-11 20:37:48 area6_Leaf by chakapoko maker') assert isinstance(event, EventBareLog) assert event.line == 'area6_Leaf by chakapoko maker' assert isinstance(event.date, int)
def test_parse_cmd_map(): event = ParseEvents( None, None, None, None).parse_line('15-02-11 20:37:48 /map ctf_Wretch (198.136.48.50)') assert isinstance(event, EventNextMap) assert event.map == 'ctf_Wretch' assert isinstance(event.date, int)
def test_parse_score(): event = ParseEvents( None, None, None, None).parse_line('16-03-16 12:05:24 Gandalf scores for Alpha Team') assert isinstance(event, EventScore) assert event.player == 'Gandalf' assert event.team == 'Alpha' assert isinstance(event.date, int)
def test_parse_player_join(): event = ParseEvents(None, None, None, None).parse_line( '15-01-30 23:34:09 rage rage foo rage joining game (84.120.15.45:23073) HWID:4DD3F08B8AA' ) assert isinstance(event, EventPlayerJoin) assert event.player == 'rage rage foo rage' assert event.ip == '84.120.15.45' assert event.hwid == '4DD3F08B8AA' assert isinstance(event.date, int)
def test_parse_kill_5(): event = ParseEvents(None, None, None, None).parse_line( '16-05-04 09:33:44 (0) jrgp killed (0) Zamyhrushka with Bow') assert isinstance(event, Kill) assert event.killer == 'jrgp' assert event.victim == 'Zamyhrushka' assert event.weapon == 'Bow' assert event.killer_team == 'none' assert event.victim_team == 'none'
def update_events(r, keys, retention, filemanager, server, verbose): # Get raw events out of logs parse = ParseEvents(retention, filemanager, r, keys) # Manager of HWID <-> Name mappings hwid = Hwid(r, keys, verbose) # GeoIP lookups try: geoip_obj = geoip2.database.Reader( pkg_resources.resource_filename('piestats.update', 'GeoLite2-Country.mmdb')) except Exception as e: print 'Failed loading geoip file %s' % e # Connect to ftp/ssh or no-op if getting local files with filemanager.initialize(): # Apply events with this with MultiProcApplyEvents(r=r, keys=keys, hwid=hwid, geoip=geoip_obj) as apply_events: # Need to get these map_titles, flag_score_maps = parse.build_map_names() # Maintain round state with this round_manager = RoundManager(r=r, keys=keys, flag_score_maps=flag_score_maps) # Maybe the last round is empty. Delete it if so round_manager.tweak_last_round() for logfile, events in parse.get_events(): for decorated_event in decorate_events( events, map_titles=map_titles, ignore_maps=server.ignore_maps, ignore_players=server.ignore_players, round_manager=round_manager, logfile=logfile): apply_events.apply(decorated_event)
def logfile_greater(cls, logfile1, logfile2): ''' See if one logfile path (logfile1) came after another comparable logfile path (logfile2) ''' if not cls.logfile_comparable(logfile1, logfile2): raise ValueError('Logfiles %s and %s are not comparable' % (logfile1, logfile2)) filename1 = logfile1.split('/')[-1] filename2 = logfile2.split('/')[-1] time1 = ParseEvents.get_time_out_of_filename(filename1) time2 = ParseEvents.get_time_out_of_filename(filename2) # f the date in the files is the same, compare the last bit after the date in consolelog-19-03-16-04.txt if time2 == time1: trailer1 = int(filename1.split('-')[-1].split('.')[0]) trailer2 = int(filename2.split('-')[-1].split('.')[0]) return trailer1 > trailer2 else: return time1 > time2
def test_parse_kill_2(): event = ParseEvents(None, None, None, None).parse_line( '16-03-17 00:33:54 (1) \\\\F.O.S.T//Petterkowsk! killed (2) *>Spready<* with Grenade' ) assert isinstance(event, Kill) assert event.killer == '\\\\F.O.S.T//Petterkowsk!' assert event.victim == '*>Spready<*' assert event.weapon == 'Grenade' assert event.killer_team == 'alpha' assert event.victim_team == 'bravo'
def test_parse_kill_3(): event = ParseEvents(None, None, None, None).parse_line( '16-03-01 03:04:21 (1) Vicious - MEXIKANO.Mx killed (2) r|2 Der Exorzischt with FN Minimi' ) assert isinstance(event, Kill) assert event.killer == 'Vicious - MEXIKANO.Mx' assert event.victim == 'r|2 Der Exorzischt' assert event.weapon == 'FN Minimi' assert event.killer_team == 'alpha' assert event.victim_team == 'bravo'
def test_parse_kill_1(): event = ParseEvents(None, None, None, None).parse_line( '16-03-26 02:56:20 (2) r|2 Der Exorzischt killed (1) r|3 Benedetta Zavatta with Grenade' ) assert isinstance(event, Kill) assert event.killer == 'r|2 Der Exorzischt' assert event.victim == 'r|3 Benedetta Zavatta' assert event.weapon == 'Grenade' assert event.date == 1458960980 assert event.killer_team == 'bravo' assert event.victim_team == 'alpha'
def test_parse_invalid_map(): event = ParseEvents( None, None, None, None).parse_line('15-02-11 20:37:48 Map not found (ctf_Wretch)') assert isinstance(event, EventInvalidMap) assert event.map == 'ctf_Wretch'
def test_parse_restart_notif(): event = ParseEvents(None, None, None, None).parse_line('15-02-11 20:37:48 Restarting...') assert isinstance(event, EventRestart)
def test_parse_cmd_restart(): event = ParseEvents( None, None, None, None).parse_line('15-02-11 20:37:48 /restart (78.50.103.50)') assert isinstance(event, EventRestart)
def test_parse_cmd_map_nick(): event = ParseEvents(None, None, None, None).parse_line( '15-02-11 20:37:48 /map ctf_Guardian(78.50.103.50[IMP darDar])') assert isinstance(event, EventNextMap) assert event.map == 'ctf_Guardian'
def test_parse_next_map(): event = ParseEvents(None, None, None, None).parse_line('15-02-11 20:37:48 Next map: Blox') assert isinstance(event, EventNextMap) assert event.map == 'Blox' assert isinstance(event.date, int)
def test_parse_req_map(): event = ParseEvents( None, None, None, None).parse_line('16-03-11 11:34:59 [DDSSTINY] !map ctf_Rotten') assert isinstance(event, EventRequestMap) assert event.map == 'ctf_Rotten'
def too_old_filename(self, filename): seconds = ParseEvents.get_time_out_of_filename(filename) return self.oldest_allowed_unix > seconds