zephir.monitor.agents.baculaservices

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

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

     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 zephir pour les démons bacula
    11  """
    12
    13  from zephir.monitor.agentmanager.agent import Agent
    14  from zephir.monitor.agentmanager.data import TableData
    15  from zephir.monitor.agentmanager.util import status_to_img
    16  from zephir.monitor.agentmanager import status
    17
    18
    19 -class BaculaServices(Agent):
    20
    21 -    def __init__(self, name,
    22                   bacula_services, # dict {"host:port": "comment"}
    23                   **params):
    24          Agent.__init__(self, name, **params)
    25          self.bacula_services = bacula_services
    26          self.table = TableData([
    27              ('description', "Description", {'align':'left'}, None),
    28              ('status', "état", {'align':'center'}, status_to_img),
    29              ('stats', "Historique", {'align':'left'}, None),
    30              ('host', "Hôte", {'align':'left'}, None),
    31              ('port', "Port", {'align':'left'}, None),
    32              ])
    33          self.data = [self.table]
    34
    35
    36 -    def measure(self):
    37          mesures = []
    38          try:
    39              # recherche de l'identifiant zephir
    40              # (nécessaire pour l'url du graphe de status des 'sous agents')
    41              from zephir.zephir_conf.zephir_conf import id_serveur
    42          except:
    43              # si on est pas enregistré : 0
    44              id_serveur = 0
    45
    46          for service in self.bacula_services:
    47              if self.manager.agents.has_key(service):
    48                 serv_agent = self.manager.agents[service]
    49                 if serv_agent.last_measure is not None:
    50                     status = serv_agent.last_measure.value['services'][0]['status']
    51                     description = serv_agent.last_measure.value['services'][0]['description']
    52                     mesures.append({ 'description': description,
    53                                      'host': serv_agent.last_measure.value['services'][0]['host'],
    54                                      'port': serv_agent.last_measure.value['services'][0]['port'],
    55                                      'status': status,
    56                                      'stats': '<img src=/agents/%s/%s/status.png alt="Historique (%s)"/>' % (id_serveur,service,service)})
    57                     self.measure_data[service]=[status,description]
    58                 else:
    59                     mesures.append({ 'description': service,
    60                                      'host': '',
    61                                      'port': '',
    62                                      'status': '',
    63                                      'stats': ''})
    64          return {'services': mesures}
    65
    66
    67 -    def write_data(self):
    68          Agent.write_data(self)
    69          if self.last_measure is not None:
    70              self.table.table_data = self.last_measure.value['services']
    71
    72
    73 -    def check_status(self):
    74          """remonte une erreur si un des services est tombé"""
    75          if self.last_measure is not None:
    76              for service in self.last_measure.value['services']:
    77                  if service['status'] == 'Off':
    78                      return status.Error()
    79          else:
    80              # pas de mesure connue
    81              return status.Unknown()
    82          return status.OK()
    83