zephir.monitor.agents.bacula

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

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

     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 la surveillance ds démons bacula via check_bacula
    11  """
    12
    13  from twisted.internet import defer
    14  from twisted.internet.utils import getProcessOutput, getProcessValue
    15  from os import system
    16  import traceback
    17
    18  from zephir.monitor.agentmanager.agent import Agent
    19  from zephir.monitor.agentmanager.data import HTMLData, TableData
    20  from zephir.monitor.agentmanager.util import status_to_img, boolean_to_onoff, log
    21  from zephir.monitor.agentmanager import status
    22
    23 -class BaculaService(Agent):
    24
    25 -    def __init__(self, name, password, **params):
    26          Agent.__init__(self, name, **params)
    27          self.name = name
    28          self.short_name = self.name.split('-')[1]
    29          self.password = password
    30          self.table = TableData([
    31              ('status', "Etat", {'align':'center'}, status_to_img),
    32              ('description', "Description", {'align':'left'}, None),
    33              ('host', "Hôte", {'align':'left'}, None),
    34              ('port', "Port", {'align':'left'}, None) ])
    35          self.data = [self.table]
    36
    37 -    def measure(self):
    38          CHECK_BACULA = '/usr/lib/nagios/plugins/check_bacula'
    39          result = getProcessOutput(CHECK_BACULA,
    40                                  args=('-H', 'localhost',
    41                                      '-D', self.short_name,
    42                                      '-M', '127.0.0.1-mon',
    43                                      '-K', self.password),
    44                                  env={'LC_ALL': 'C'})
    45          result.addCallbacks(self.measure_activity, self.measure_error)
    46          return result
    47
    48 -    def measure_activity(self, data):
    49          if 'BACULA OK' in str(data):
    50              status = boolean_to_onoff(1)
    51          else:
    52              status = boolean_to_onoff(0)
    53          mesures=[{ 'description': self.name,
    54                     'host': 'localhost',
    55                     'port': '',
    56                     'status': status }]
    57          return {'services': mesures}
    58
    59 -    def measure_error(self, failure):
    60          log.msg(dir(failure))
    61          traceback.print_exc()
    62
    63
    64 -    def write_data(self):
    65          Agent.write_data(self)
    66          if self.last_measure is not None:
    67              self.table.table_data = self.last_measure.value['services']
    68
    69 -    def check_status(self):
    70          """remonte une erreur si un des services est tombé"""
    71          if self.last_measure is not None:
    72              for service in self.last_measure.value['services']:
    73                  if service['status'] != 'On':
    74                      return status.Error()
    75          else:
    76              # pas de mesure connue
    77              return status.Unknown()
    78          return status.OK()
    79