Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import os, json, functools | |
from urllib2 import urlopen, Request | |
# GitHub Traffic API | |
# https://developer.github.com/v3/repos/traffic/ | |
def openTrafficAPI (owner, repo, token, path): | |
url = "https://api.github.com/repos/%s/%s/traffic/%s" % (owner, repo, path) | |
headers = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for item in itertools.ifilter(lambda it:it["start log"] == None, terminate_session_logs): | |
print >> sys.stderr, "This record," | |
print >> sys.stderr, item["line"] , | |
print >> sys.stderr, " has no relationship!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for item in itertools.ifilter(lambda it:it["terminate log"] == None, start_session_logs): | |
print >> unterminated_file, item["line"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipR, pipW = os.pipe () | |
os.close (pipR) | |
os.dup2 (3, pipW) | |
unterminated_file = os.fdopen (pipW, "w") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
term = next(itertools.ifilter(lambda it:it["DateTime"] >= start["DateTime"] and it["IP"] == start["IP"], terminate_session_logs), None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for start in start_session_logs: | |
term = next(itertools.ifilter(lambda it:it["DateTime"] >= start["DateTime"] and it["IP"] == start["IP"], terminate_session_logs), None) | |
if term: | |
start["terminate log"] = term | |
term["start log"] = start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start_session_logs = [] | |
terminate_session_logs = [] | |
for line in sys.stdin: | |
if re.search (r'%ASA-[^:]+?-113039:', line): | |
start_session_logs.append ( | |
extract_start_session_from_log (line)) | |
# | |
if re.search (r'%ASA-[^:]+?-113019:', line): | |
terminate_session_logs.append ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_start_session_from_log(line): | |
sep = line.rstrip().split (': ') | |
result = {} | |
result["terminate log"] = None | |
result["line"] = line | |
# | |
result["Message"] = sep[2] | |
result["Class"] = sep[1] | |
result["DateTime"] = toDateTime (sep[0]) | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def toDateTime (log_datetime): | |
date = (log_datetime.split(' '))[3:] | |
return datetime.datetime.strptime (' '.join (date), "%b %d %H:%M:%S %Z") |