zephir.monitor.agents.freshclam

Package zephir :: Package monitor :: Package agents :: Module freshclam |
[frames] | no frames]

# Source Code for Module zephir.monitor.agents.freshclam

     1  # -*- coding: UTF-8 -*-
     2  ###########################################################################
     3  # Eole NG - 2011
     4  # Copyright Pole de Competence Eole  (Ministere Education - Academie Dijon)
     5  # Licence CeCill  cf /root/LicenceEole.txt
     6  # eole@ac-dijon.fr
     7  ###########################################################################
     8
     9  """
    10  Agent FreshClam
    11  """
    12
    13  from zephir.monitor.agentmanager.agent import Agent
    14  from zephir.monitor.agentmanager.data import TableData, HTMLData
    15  #from twisted.internet.utils import getProcessOutput
    16  from zephir.monitor.agentmanager import status
    17  from os.path import isfile
    18  from zephir.monitor.agentmanager.util import status_to_img
    19  import time
    20
    21  freshclam_file = '/var/log/clamav/freshclam-status.log'
    22
    23 -class Freshclam(Agent):
    24      """
    25      Utilisateurs connectes
    26      """
    27 -    def __init__(self, name, **params):
    28          Agent.__init__(self, name, **params)
    29          self.status = 1
    30          self.table = TableData([
    31              ('status', 'état', {'align':'center'}, status_to_img),
    32              ('msg', 'message', {'align':'left'}, None)
    33          ])
    34          self.data = [self.table]
    35
    36  #    def init_data(self, archive_dir):
    37  #        title1 = HTMLData("<h3>Mise à jour de ClamAV<h3>")
    38  #        self.data.extend([title1, self.table])
    39  #        Agent.init_data(self, archive_dir)
    40
    41 -    def measure(self):
    42          ret = {}
    43          try:
    44              if isfile(freshclam_file):
    45                  execfile(freshclam_file, {}, ret)
    46                  if ret['STATUS'] == '0':
    47                      self.status = 1
    48                      status = 'On'
    49                      last_update = time.strftime("%d %b %Y %H:%M:%S", time.localtime(float(ret['DATE'])))
    50                      msg = 'Base antivirale mise à jour le %s' % last_update
    51                  else:
    52                      self.status = 0
    53                      status = 'Off'
    54                      msg = ret['MSG']
    55              else:
    56                  self.status = 0
    57                  status = 'Off'
    58                  msg = "Le fichier %s n'existe pas" % freshclam_file
    59          except Exception, e:
    60              self.status = 0
    61              status = 'Off'
    62              msg = "Impossible de lire %s : %s" % (freshclam_file, e)
    63          return [{'msg': msg, 'status': status}]
    64
    65 -    def check_status(self):
    66          if self.status == 1 :
    67              return status.OK()
    68          return status.Error()
    69
    70 -    def write_data(self):
    71          Agent.write_data(self)
    72          if self.last_measure is not None:
    73              self.table.table_data = self.last_measure.value
    74