diff --git a/display.py b/display.py
index 6ddf1f8..8356e49 100644
--- a/display.py
+++ b/display.py
@@ -15,7 +15,7 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
self.rows = []
def appendRow(self, row):
- self.rows.append(row)
+ self.rows.append(listToStr(row))
def build(self, f):
f.write('
')
@@ -68,3 +68,21 @@ class DisplayHTMLBuild(object):
def build(self, root):
for page in self.pages:
page.build(root)
+
+def bytesToStr(bytes):
+ suffixes = ['', ' kB', ' MB', ' GB', ' TB']
+
+ for i in range(0, len(suffixes)):
+ if bytes < 1024: break
+ bytes /= 1024.0
+
+ if i:
+ return '%.02f%s' % (bytes, suffixes[i])
+ else:
+ return '%d%s' % (bytes, suffixes[i])
+
+def _toStr(v):
+ if type(v) != str: return str(v)
+ else: return v
+
+def listToStr(l): return map(lambda(v) : _toStr(v), l)
diff --git a/iwla.py b/iwla.py
index af8d705..b7c4072 100755
--- a/iwla.py
+++ b/iwla.py
@@ -237,8 +237,8 @@ class IWLA(object):
nb_visits = 0
for k in keys:
stats = self.current_analysis['days_stats'][k]
- row = [k, stats['nb_visitors'], stats['viewed_pages'], stats['viewed_hits'], stats['viewed_bandwidth'], stats['not_viewed_bandwidth']]
- row = map(lambda(v): str(v), row)
+ row = [k, stats['nb_visitors'], stats['viewed_pages'], stats['viewed_hits'],
+ bytesToStr(stats['viewed_bandwidth']), bytesToStr(stats['not_viewed_bandwidth'])]
days.appendRow(row)
nb_visits += stats['nb_visitors']
@@ -247,15 +247,18 @@ class IWLA(object):
nb_days = len(keys)
row = [0, nb_visits, stats['viewed_pages'], stats['viewed_hits'], stats['viewed_bandwidth'], stats['not_viewed_bandwidth']]
if nb_days:
- row = map(lambda(v): str(int(v/nb_days)), row)
+ average_row = map(lambda(v): str(int(v/nb_days)), row)
else:
- row = map(lambda(v): '0', row)
+ average_row = map(lambda(v): '0', row)
- row[0] = 'Average'
- days.appendRow(row)
+ average_row[0] = 'Average'
+ average_row[4] = bytesToStr(row[4])
+ average_row[5] = bytesToStr(row[5])
+ days.appendRow(average_row)
- row = ['Total', nb_visits, stats['viewed_pages'], stats['viewed_hits'], stats['viewed_bandwidth'], stats['not_viewed_bandwidth']]
- row = map(lambda(v): str(v), row)
+ row[0] = 'Total'
+ row[4] = bytesToStr(row[4])
+ row[5] = bytesToStr(row[5])
days.appendRow(row)
page.appendBlock(days)
self.display.addPage(page)
diff --git a/plugins/__init__.py b/plugins/__init__.py
new file mode 100644
index 0000000..bd0daba
--- /dev/null
+++ b/plugins/__init__.py
@@ -0,0 +1,2 @@
+
+__all__ = ['pre_analysis', 'post_analysis', 'display']
diff --git a/plugins/display/__init__.py b/plugins/display/__init__.py
new file mode 100644
index 0000000..792d600
--- /dev/null
+++ b/plugins/display/__init__.py
@@ -0,0 +1 @@
+#
diff --git a/plugins/display/top_visitors.py b/plugins/display/top_visitors.py
index c4db4f8..796af31 100644
--- a/plugins/display/top_visitors.py
+++ b/plugins/display/top_visitors.py
@@ -18,15 +18,20 @@ def load():
def hook(iwla):
stats = iwla.getMonthStats()
- if not 'top_visitors' in stats.keys():
+ top_visitors = stats.get('top_visitors', None)
+ if not top_visitors:
print 'Top visitors post analysis plugin not installed'
return
index = iwla.getDisplayIndex()
table = DisplayHTMLBlockTable('Top visitors', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen'])
- for super_hit in stats['top_visitors']:
- row = [super_hit['remote_addr'], super_hit['viewed_pages'], super_hit['viewed_hits'], super_hit['bandwidth'], 0]
- row = map(lambda(v): str(v), row)
- row[4] = time.asctime(super_hit['last_access'])
+ for super_hit in top_visitors:
+ row = [
+ super_hit['remote_addr'],
+ super_hit['viewed_pages'],
+ super_hit['viewed_hits'],
+ bytesToStr(super_hit['bandwidth']),
+ time.asctime(super_hit['last_access'])
+ ]
table.appendRow(row)
index.appendBlock(table)
diff --git a/plugins/post_analysis/__init__.py b/plugins/post_analysis/__init__.py
new file mode 100644
index 0000000..792d600
--- /dev/null
+++ b/plugins/post_analysis/__init__.py
@@ -0,0 +1 @@
+#
diff --git a/plugins/post_analysis/reverse_dns.py b/plugins/post_analysis/reverse_dns.py
index 9bc5bb1..b935efa 100644
--- a/plugins/post_analysis/reverse_dns.py
+++ b/plugins/post_analysis/reverse_dns.py
@@ -19,9 +19,12 @@ def load():
def hook(iwla):
hits = iwla.getValidVisitors()
for (k, hit) in hits.items():
+ if hit.get('dns_analysed', False): continue
try:
name, _, _ = socket.gethostbyaddr(k)
hit['remote_addr'] = name
except:
pass
+ finally:
+ hit['dns_analysed'] = True
diff --git a/plugins/pre_analysis/__init__.py b/plugins/pre_analysis/__init__.py
new file mode 100644
index 0000000..792d600
--- /dev/null
+++ b/plugins/pre_analysis/__init__.py
@@ -0,0 +1 @@
+#