zephir.monitor.agents.frontend

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

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

     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 service horus_frontend
    11  """
    12
    13  import os
    14  from creole import parsedico
    15  from pyeole.service import service_out
    16  from twisted.internet import defer
    17  from twisted.internet.utils import getProcessOutput, getProcessValue
    18
    19  from zephir.monitor.agentmanager.agent import Agent
    20  from zephir.monitor.agentmanager.data import TableData
    21  from zephir.monitor.agentmanager.util import status_to_img, boolean_to_onoff
    22  from zephir.monitor.agentmanager import status
    23
    24 -def compare_hostports(hp1, hp2):
    25      h1, p1 = hp1.split(':')
    26      h2, p2 = hp2.split(':')
    27      result = cmp(h1, h2) # alpha comparison on hosts
    28      if result != 0:
    29          return result
    30      else: # numeric comparison on ports
    31          return cmp(int(p1), int(p2))
    32
    33 -class Frontend(Agent):
    34
    35 -    def __init__(self, name, **params):
    36
    37          Agent.__init__(self, name, **params)
    38          try:
    39              d = parsedico.parse_dico()
    40              self.adresse_eth0 = d['adresse_ip_eth0']
    41          except:
    42              self.adresse_eth0 = "127.0.0.1"
    43
    44          self.table = TableData([
    45              ('status', "état", {'align':'center'}, status_to_img),
    46              ('description', "Description", {'align':'left'}, None),
    47              ('host', "Hôte", {'align':'left'}, None),
    48              ('port', "Port", {'align':'left'}, None) ])
    49          self.data = [self.table]
    50
    51 -    def measure(self):
    52          res = service_out('horus_frontend', 'status')
    53          if res[0] == 0:
    54              result = True
    55          else:
    56              result = False
    57
    58          status = boolean_to_onoff(result)
    59          mesures=[{ 'description': 'serveur du frontend LDAP',
    60                     'host': self.adresse_eth0,
    61                     'port': '7080',
    62                     'status': status }]
    63          return {'services': mesures}
    64
    65 -    def write_data(self):
    66          Agent.write_data(self)
    67          if self.last_measure is not None:
    68              self.table.table_data = self.last_measure.value['services']
    69
    70 -    def check_status(self):
    71          """remonte une erreur si un des services est tombé"""
    72          if self.last_measure is not None:
    73              for service in self.last_measure.value['services']:
    74                  if service['status'] != 'On':
    75                      return status.Error()
    76          else:
    77              # pas de mesure connue
    78              return status.Unknown()
    79          return status.OK()
    80