Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
36 lines (32 loc) · 900 Bytes

File metadata and controls

36 lines (32 loc) · 900 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
"""
USAGE:
logparsing_apache.py apache_log_file
This script takes apache log file as an argument and then generates a report, with hostname,
bytes transferred and status
"""
import sys
def apache_output(line):
split_line = line.split()
return {'remote_host': split_line[0],
'apache_status': split_line[8],
'data_transfer': split_line[9],
}
def final_report(logfile):
for line in logfile:
line_dict = apache_output(line)
print(line_dict)
if __name__ == "__main__":
if not len(sys.argv) > 1:
print (__doc__)
sys.exit(1)
infile_name = sys.argv[1]
try:
infile = open(infile_name, 'r')
except IOError:
print ("You must specify a valid file to parse")
print (__doc__)
sys.exit(1)
log_report = final_report(infile)
print (log_report)
infile.close()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.