iwla

iwla Git Source Tree

Root/plugins/post_analysis/top_downloads.py

1import re
2
3from iwla import IWLA
4from iplugin import IPlugin
5
6#
7# Post analysis hook
8#
9# Count TOP downloads
10#
11# Plugin requirements :
12# None
13#
14# Conf values needed :
15# reverse_dns_timeout*
16#
17# Output files :
18# None
19#
20# Statistics creation :
21# None
22#
23# Statistics update :
24# month_stats:
25# top_downloads =>
26# uri
27#
28# Statistics deletion :
29# None
30#
31
32class IWLAPostAnalysisTopDownloads(IPlugin):
33 def __init__(self, iwla):
34 super(IWLAPostAnalysisTopDownloads, self).__init__(iwla)
35 self.API_VERSION = 1
36 self.conf_requires = ['multimedia_files', 'viewed_http_codes']
37
38 def hook(self):
39 stats = self.iwla.getCurrentVisists()
40 month_stats = self.iwla.getMonthStats()
41
42 multimedia_files = self.iwla.getConfValue('multimedia_files')
43 viewed_http_codes = self.iwla.getConfValue('viewed_http_codes')
44
45 top_downloads = month_stats.get('top_downloads', {})
46
47 for (k, super_hit) in stats.items():
48 if super_hit['robot']: continue
49 for r in super_hit['requests']:
50 if not self.iwla.isValidForCurrentAnalysis(r) or\
51 not self.iwla.hasBeenViewed(r):
52 continue
53 if r['is_page']: continue
54
55
56 if not int(r['status']) in viewed_http_codes: continue
57
58 uri = r['extract_request']['extract_uri'].lower()
59
60 isMultimedia = False
61 for ext in multimedia_files:
62 if uri.endswith(ext):
63 isMultimedia = True
64 break
65
66 if isMultimedia: continue
67
68 uri = "%s%s" % (r.get('server_name', ''),
69 r['extract_request']['extract_uri'])
70
71 if not uri in top_downloads.keys():
72 top_downloads[uri] = 1
73 else:
74 top_downloads[uri] += 1
75
76 month_stats['top_downloads'] = top_downloads

Archive Download this file

Branches

Tags