1
2
3
4
5
6
7
8 """
9 Agent zephir pour l'étude des logs de scannedonly
10 """
11 import time
12 import random
13 import locale
14 from os.path import isfile
15 from calendar import month_abbr
16 from zephir.monitor.agentmanager.agent import Agent
17 from zephir.monitor.agentmanager.data import HTMLData, TableData
18 from zephir.monitor.agentmanager import status
19
20
21 locale.setlocale(locale.LC_ALL, ('en_US', 'UTF8'))
22 MONTH_ABBR = list(month_abbr)
23
25
27 Agent.__init__(self, name, **params)
28 self.lastcolor = None
29 self.status = status.OK()
30
31
32 self.table = TableData([
33 ('vir', 'Virus', {'align':'center'}, None),
34
35 ('nb', 'Occurences', {'align':'center'}, None)])
36 title1 = HTMLData("<h3>Derniers virus détectés<h3>")
37 self.table2 = TableData([
38
39 ('nb', 'Nombre de virus pour aujourd\'hui',
40 {'align':'center'}, None)])
41 self.data = [title1, self.table, HTMLData('<br>'), self.table2]
42
44 """
45 astuce pour réaliser un affichage sympa
46 """
47 color = self.lastcolor
48 while color == self.lastcolor :
49 color = random.choice(('red', 'green', 'blue', 'deeppink' ))
50 self.lastcolor = color
51 return "<font color=\"%s\">%s</font>" % (color, vir)
52
54 self.status = status.OK()
55 fichier = '/var/log/rsyslog/local/scannedonlyd_clamav/scannedonlyd_clamav.warn.log'
56 date = time.localtime()
57 today = date.tm_mday
58 mymonth = date.tm_mon
59 if not isfile(fichier):
60 lignes = []
61 else:
62 fp = open(fichier, 'r')
63
64 lignes = fp.readlines(10000000)
65 fp.close()
66 dico = {}
67 totalday = 0
68
69 for ligne in lignes:
70 if ligne.find("contains virus") != -1:
71 data = ligne.split()
72 day = data[1]
73 month = data[0]
74 virus = data[-1][0:-1]
75
76 client = 'unknown'
77
78 if dico.has_key((virus, client)) :
79 dico[(virus, client)] += 1
80 else:
81 dico[(virus, client)] = 1
82 if int(day) == today and month == MONTH_ABBR[mymonth]:
83 totalday += 1
84
85 warninglevel = 1
86 errorlevel = 10
87 if totalday >= errorlevel :
88 self.status = status.Error()
89 elif totalday >= warninglevel :
90 self.status = status.Warn()
91 self.measure_data['nb'] = str(totalday)
92
93 res2 = { 'nb' : str(totalday) }
94
95 if dico != {} :
96 result = []
97 cles = dico.keys()
98 for cle in cles :
99 result.append({ 'vir' : self._color(cle[0]),
100
101 'nb' : dico[cle]
102 })
103 return { 'statistics' : result,
104 'statistics2' : [ res2 ] }
105 return { 'statistics' : [ {'vir' : 'Aucun',
106
107 'nb' : '----' } ],
108 'statistics2' : [ res2 ] }
109
110
112 Agent.write_data(self)
113 if self.last_measure is not None:
114 self.table.table_data = self.last_measure.value['statistics']
115 self.table2.table_data = self.last_measure.value['statistics2']
116
119