Created
March 14, 2013 19:48
-
-
Save marcelom/5164562 to your computer and use it in GitHub Desktop.
Print Server Log Analyser (for Windows)
This file contains hidden or 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
# This script takes a windows CSV export of the log file from a windows server machines | |
# and looks for print jobs. | |
# It then adds them to a disctionary of dictionaries of sets. First level is the date, | |
# second is the user, third is the set of printers. | |
# Then it exports them as a CSV. | |
import re | |
import sys | |
import csv | |
matcher = re.compile('.+was printed on (.+) via.+') | |
csvreader = csv.reader(sys.stdin) | |
csvwriter = csv.writer(sys.stdout) | |
l = {} | |
for line in csvreader: | |
# Fifth field is the event ID. 10 means Print Job. | |
if line[5]=='10': | |
# Found a print entry. Searches the desciption (field 8) for the printer name... | |
match = matcher.search(line[8]) | |
if match: | |
# Adds it to a dict of dicts of sets. First level is the date, second is the user, and the set is of printers. | |
# this will give you a list of printers per user per day. | |
l.setdefault(line[0],{}).setdefault(line[6],set()).add(match.groups()[0]) | |
for date in l: | |
for user in l[date]: | |
csvwriter.writerow((date,user,', '.join(l[date][user]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment