zephir.monitor.agents.passerelle

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

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

     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 surveillant le fonctionnement du routeur
    11  """
    12
    13  from twisted.internet.utils import getProcessOutput
    14
    15  from creole import parsedico
    16
    17  from zephir.monitor.agentmanager.util import log
    18  from zephir.monitor.agentmanager.agent import Agent
    19  from zephir.monitor.agentmanager.data import TableData
    20  from zephir.monitor.agentmanager.util import status_to_img, boolean_to_onoff
    21  from zephir.monitor.agentmanager import status
    22
    23 -class Passerelle(Agent):
    24
    25 -    def __init__(self, name, **params):
    26
    27          Agent.__init__(self, name, **params)
    28          try:
    29              d = parsedico.parse_dico()
    30              self.adresse_gw = d['adresse_ip_gw']
    31          except:
    32              self.adresse_gw = ""
    33
    34          self.table = TableData([
    35              ('status', "état", {'align':'center'}, status_to_img),
    36              ('description', "Description", {'align':'left'}, None),
    37              ('adresse', "Adresse", {'align':'left'}, None) ])
    38          self.data = [self.table]
    39
    40 -    def measure(self):
    41          res = getProcessOutput("/usr/bin/fping",
    42                                 args = [self.adresse_gw],
    43                                 env = {'LC_ALL': 'C'})
    44          return res.addCallbacks(self.measure_fping, self.error_process)
    45
    46 -    def measure_fping(self,data):
    47          # fping est sorti sans erreur
    48          mesures=[{ 'description': 'Contact avec la passerelle',
    49                     'adresse': self.adresse_gw,
    50                     'status': 'On' }]
    51          return mesures
    52
    53 -    def error_process(self, *args):
    54          # fping a renvoyé un code d'erreur
    55          self.measure_data['gw'] = True
    56          mesures=[{ 'description': 'Contact avec la passerelle',
    57                     'adresse': self.adresse_gw,
    58                     'status': 'Off'}]
    59          return mesures
    60
    61 -    def write_data(self):
    62          self.measure_data['gw'] = False
    63          Agent.write_data(self)
    64          if self.last_measure is not None:
    65              self.table.table_data = self.last_measure.value
    66
    67 -    def check_status(self):
    68          """remonte une erreur si un des services est tombé"""
    69          if self.last_measure is not None:
    70              if self.last_measure.value is not None:
    71                  for service in self.last_measure.value:
    72                      if service['status'] != 'On':
    73                          return status.Error()
    74          else:
    75              # pas de mesure connue
    76              return status.Unknown()
    77          return status.OK()
    78