From ed0af6e6ac4da4a3cb468eab0b959e3778bf52e9 Mon Sep 17 00:00:00 2001 From: Gregory Soutade Date: Fri, 21 Nov 2014 16:57:37 +0100 Subject: [PATCH] Add top visitors and reverse dns plugins --- plugins/display/top_visitors.py | 27 +++++++++++++++++++++++++++ plugins/post_analysis/reverse_dns.py | 27 +++++++++++++++++++++++++++ plugins/post_analysis/top_visitors.py | 23 +++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 plugins/display/top_visitors.py create mode 100644 plugins/post_analysis/reverse_dns.py create mode 100644 plugins/post_analysis/top_visitors.py diff --git a/plugins/display/top_visitors.py b/plugins/display/top_visitors.py new file mode 100644 index 0000000..f058a79 --- /dev/null +++ b/plugins/display/top_visitors.py @@ -0,0 +1,27 @@ +import time +from display import * + +PLUGIN_CLASS = 'HTTP' +API_VERSION = 1 + +def get_plugins_infos(): + infos = { + 'class' : PLUGIN_CLASS, + 'min_version' : API_VERSION, + 'max_version' : -1 + } + return infos + +def load(): + return True + +def hook(iwla): + stats = iwla.getMonthStats() + 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']) + table.appendRow(row) + index.appendBlock(table) diff --git a/plugins/post_analysis/reverse_dns.py b/plugins/post_analysis/reverse_dns.py new file mode 100644 index 0000000..9bc5bb1 --- /dev/null +++ b/plugins/post_analysis/reverse_dns.py @@ -0,0 +1,27 @@ +import socket +from iwla import IWLA + +PLUGIN_CLASS = 'HTTP' +API_VERSION = 1 + +def get_plugins_infos(): + infos = { + 'class' : PLUGIN_CLASS, + 'min_version' : API_VERSION, + 'max_version' : -1 + } + return infos + +def load(): + socket.setdefaulttimeout(0.5) + return True + +def hook(iwla): + hits = iwla.getValidVisitors() + for (k, hit) in hits.items(): + try: + name, _, _ = socket.gethostbyaddr(k) + hit['remote_addr'] = name + except: + pass + diff --git a/plugins/post_analysis/top_visitors.py b/plugins/post_analysis/top_visitors.py new file mode 100644 index 0000000..345b947 --- /dev/null +++ b/plugins/post_analysis/top_visitors.py @@ -0,0 +1,23 @@ +from iwla import IWLA + +PLUGIN_CLASS = 'HTTP' +API_VERSION = 1 + +def get_plugins_infos(): + infos = { + 'class' : PLUGIN_CLASS, + 'min_version' : API_VERSION, + 'max_version' : -1 + } + return infos + +def load(): + return True + +def hook(iwla): + hits = iwla.getValidVisitors() + stats = iwla.getMonthStats() + top_bandwidth = [(k,hits[k]['bandwidth']) for (k,v) in hits.items()] + top_bandwidth = sorted(top_bandwidth, key=lambda t: t[1], reverse=True) + stats['top_visitors'] = [hits[h[0]] for h in top_bandwidth[:10]] +