zephir.monitor.agents.crl

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

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

     1  # -*- coding: UTF-8 -*-
     2  ###########################################################################
     3  # Eole NG - 2007
     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 zephir pour la surveillance de la crl agriates
    11  """
    12
    13  from zephir.monitor.agentmanager.agent import Agent
    14  from zephir.monitor.agentmanager.data import HTMLData, TableData
    15  from zephir.monitor.agentmanager import status, util
    16  from twisted.internet.utils import getProcessOutput
    17  import datetime
    18
    19 -class Crl(Agent):
    20 -    def __init__(self, name, **params):
    21          Agent.__init__(self, name, **params)
    22          self.status = status.OK()
    23          self.table = TableData([
    24              ('expire', "Date d'expiration", {'align':'left'}, None),
    25              ])
    26          title = HTMLData("<h3>Surveillance de la CRL</h3>")
    27          self.data = [title, self.table]
    28
    29 -    def measure(self):
    30          self.status = status.OK()
    31          cmd = "/usr/sbin/ipsec"
    32          args = ["listcrls"]
    33          update = getProcessOutput(cmd, args)
    34          return update.addCallbacks(self.callback_expire, self.errback_expire)
    35
    36 -    def callback_expire(self, response):
    37          # récupération de la date
    38          expire = ""
    39          for line in response.split('\n'):
    40              line = line[13:].strip()
    41              if line.startswith('next'):
    42                  expire = line.split()[1:5]
    43                  expire = " ".join(expire).split(',')[0]
    44          # transformation en datetime
    45          if expire == "":
    46              self.status = status.Warn("date d'invalidation non trouvée")
    47              return [{'expire':"ipsec listcrls ne renvoie pas de date d'invalidation de la crl" }]
    48          expdate = util.parse_date(expire)
    49          # calcul de la date avant laquelle on est en warning (expiration - 20 minutes)
    50          warn_delta = datetime.timedelta(seconds=60*20)
    51          warndate = expdate - warn_delta
    52          date = datetime.datetime.utcnow()
    53          if date > expdate:
    54              msg = "expiration de la CRL"
    55              self.status = status.Error(msg)
    56          else:
    57              delta = expdate - date
    58              minutes = (delta.days*3600*24 + delta.seconds) / 60
    59              if date > warndate:
    60                  self.status=status.Warn("Expiration dans %s minutes" % minutes)
    61          return [{'expire': expdate.strftime('%d %b %Y %H:%M:%S')}]
    62
    63 -    def errback_expire(self, err):
    64          msg = u"erreur de lecture de la date d'expiration"
    65          self.status = status.Warn(msg)
    66          return None
    67
    68 -    def write_data(self):
    69          Agent.write_data(self)
    70          if self.last_measure is not None:
    71              self.table.table_data = self.last_measure.value
    72
    73 -    def check_status(self):
    74          return self.status
    75