Remove iwla parameter in hook functions

This commit is contained in:
Grégory Soutadé 2014-11-26 20:31:13 +01:00
parent 9571bf09b6
commit fec5e375e4
9 changed files with 21 additions and 21 deletions

View File

@ -25,7 +25,7 @@ class IPlugin(object):
def load(self): def load(self):
return True return True
def hook(self, iwla): def hook(self):
pass pass
def preloadPlugins(plugins, iwla): def preloadPlugins(plugins, iwla):

View File

@ -253,7 +253,7 @@ class IWLA(object):
def _generateDisplay(self): def _generateDisplay(self):
self._generateDisplayDaysStat() self._generateDisplayDaysStat()
self._callPlugins(conf.DISPLAY_HOOK_DIRECTORY, self) self._callPlugins(conf.DISPLAY_HOOK_DIRECTORY)
self.display.build(conf.DISPLAY_ROOT) self.display.build(conf.DISPLAY_ROOT)
def _generateStats(self, visits): def _generateStats(self, visits):
@ -300,7 +300,7 @@ class IWLA(object):
self.current_analysis['month_stats'] = stats self.current_analysis['month_stats'] = stats
self.valid_visitors = {k: v for (k,v) in visits.items() if not visits[k]['robot']} self.valid_visitors = {k: v for (k,v) in visits.items() if not visits[k]['robot']}
self._callPlugins(conf.POST_HOOK_DIRECTORY, self) self._callPlugins(conf.POST_HOOK_DIRECTORY)
path = self.getDBFilename(cur_time) path = self.getDBFilename(cur_time)
if os.path.exists(path): if os.path.exists(path):
@ -315,7 +315,7 @@ class IWLA(object):
def _generateDayStats(self): def _generateDayStats(self):
visits = self.current_analysis['visits'] visits = self.current_analysis['visits']
self._callPlugins(conf.PRE_HOOK_DIRECTORY, self) self._callPlugins(conf.PRE_HOOK_DIRECTORY)
stats = self._generateStats(visits) stats = self._generateStats(visits)

View File

@ -9,8 +9,8 @@ class IWLADisplayAllVisits(IPlugin):
super(IWLADisplayAllVisits, self).__init__(iwla) super(IWLADisplayAllVisits, self).__init__(iwla)
self.API_VERSION = 1 self.API_VERSION = 1
def hook(self, iwla): def hook(self):
hits = iwla.getValidVisitors() hits = self.iwla.getValidVisitors()
last_access = sorted(hits.values(), key=lambda t: t['last_access'], reverse=True) last_access = sorted(hits.values(), key=lambda t: t['last_access'], reverse=True)
cur_time = self.iwla.getCurTime() cur_time = self.iwla.getCurTime()
@ -40,7 +40,7 @@ class IWLADisplayAllVisits(IPlugin):
display = self.iwla.getDisplay() display = self.iwla.getDisplay()
display.addPage(page) display.addPage(page)
index = iwla.getDisplayIndex() index = self.iwla.getDisplayIndex()
block = DisplayHTMLRawBlock() block = DisplayHTMLRawBlock()
block.setRawHTML('<a href=\'%s\'>All visits</a>' % (filename)) block.setRawHTML('<a href=\'%s\'>All visits</a>' % (filename))
index.appendBlock(block) index.appendBlock(block)

View File

@ -70,8 +70,8 @@ class IWLADisplayReferers(IPlugin):
key_phrases[key_phrase] += 1 key_phrases[key_phrase] += 1
break break
def hook(self, iwla): def hook(self):
stats = iwla.getCurrentVisists() stats = self.iwla.getCurrentVisists()
referers = {} referers = {}
robots_referers = {} robots_referers = {}
search_engine_referers = {} search_engine_referers = {}

View File

@ -10,10 +10,10 @@ class IWLADisplayTopVisitors(IPlugin):
self.API_VERSION = 1 self.API_VERSION = 1
self.requires = ['IWLAPostAnalysisTopVisitors'] self.requires = ['IWLAPostAnalysisTopVisitors']
def hook(self, iwla): def hook(self):
stats = iwla.getMonthStats() stats = self.iwla.getMonthStats()
index = iwla.getDisplayIndex() index = self.iwla.getDisplayIndex()
table = DisplayHTMLBlockTable('Top visitors', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen']) table = DisplayHTMLBlockTable('Top visitors', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen'])
for super_hit in stats['top_visitors']: for super_hit in stats['top_visitors']:
address = super_hit['remote_addr'] address = super_hit['remote_addr']

View File

@ -13,8 +13,8 @@ class IWLAPostAnalysisReverseDNS(IPlugin):
socket.setdefaulttimeout(timeout) socket.setdefaulttimeout(timeout)
return True return True
def hook(self, iwla): def hook(self):
hits = iwla.getValidVisitors() hits = self.iwla.getValidVisitors()
for (k, hit) in hits.items(): for (k, hit) in hits.items():
if hit.get('dns_analysed', False): continue if hit.get('dns_analysed', False): continue
try: try:

View File

@ -6,9 +6,9 @@ class IWLAPostAnalysisTopVisitors(IPlugin):
super(IWLAPostAnalysisTopVisitors, self).__init__(iwla) super(IWLAPostAnalysisTopVisitors, self).__init__(iwla)
self.API_VERSION = 1 self.API_VERSION = 1
def hook(self, iwla): def hook(self):
hits = iwla.getValidVisitors() hits = self.iwla.getValidVisitors()
stats = iwla.getMonthStats() stats = self.iwla.getMonthStats()
top_bandwidth = [(k,hits[k]['bandwidth']) for k in hits.keys()] top_bandwidth = [(k,hits[k]['bandwidth']) for k in hits.keys()]
top_bandwidth = sorted(top_bandwidth, key=lambda t: t[1], reverse=True) top_bandwidth = sorted(top_bandwidth, key=lambda t: t[1], reverse=True)
stats['top_visitors'] = [hits[h[0]] for h in top_bandwidth[:10]] stats['top_visitors'] = [hits[h[0]] for h in top_bandwidth[:10]]

View File

@ -20,11 +20,11 @@ class IWLAPreAnalysisPageToHit(IPlugin):
return True return True
def hook(self, iwla): def hook(self):
start_time = self.iwla.getStartAnalysisTime() start_time = self.iwla.getStartAnalysisTime()
start_time = time.mktime(start_time) start_time = time.mktime(start_time)
hits = iwla.getCurrentVisists() hits = self.iwla.getCurrentVisists()
viewed_http_codes = self.iwla.getConfValue('viewed_http_codes', [200, 304]) viewed_http_codes = self.iwla.getConfValue('viewed_http_codes', [200, 304])
for (k, super_hit) in hits.items(): for (k, super_hit) in hits.items():
if super_hit['robot']: continue if super_hit['robot']: continue

View File

@ -16,8 +16,8 @@ class IWLAPreAnalysisRobots(IPlugin):
return True return True
# Basic rule to detect robots # Basic rule to detect robots
def hook(self, iwla): def hook(self):
hits = iwla.getCurrentVisists() hits = self.iwla.getCurrentVisists()
for k in hits.keys(): for k in hits.keys():
super_hit = hits[k] super_hit = hits[k]