zephir.monitor.agents.samba3

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

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

     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 Samba 3
    11  """
    12
    13  from zephir.monitor.agentmanager.agent import RRDAgent
    14  from zephir.monitor.agentmanager.data import TableData, HTMLData
    15  from twisted.internet.utils import getProcessOutput
    16  from zephir.monitor.agentmanager import status
    17
    18
    19 -class SmbUsers(RRDAgent):
    20      """
    21      Utilisateurs connectes
    22      """
    23 -    def __init__(self, name, **params):
    24          RRDAgent.__init__(self, name, **params)
    25          self.status = 1
    26          self.table = TableData([
    27              ('connected', 'Connectés', {'align':'center'}, None) ])
    28
    29 -    def init_data(self, archive_dir):
    30          title1 = HTMLData("<h3>Nombre de connectés actuels<h3>")
    31          title2 = HTMLData("<h3>Graphes des connexions<h3>")
    32          self.data.extend([title1, self.table, title2])
    33          RRDAgent.init_data(self, archive_dir)
    34
    35 -    def measure(self):
    36          res = getProcessOutput("/usr/share/eole/fichier/connexions.sh",
    37                                 env = {'LC_ALL': 'C'})
    38          res.addCallback(self.measure_process)
    39          return res
    40
    41 -    def measure_process(self, result):
    42          try:
    43              self.measure_data['connected'] = int(result)
    44              return {'connected' : int(result),
    45                      't_con' : [{'connected':int(result)}]
    46                     }
    47          except:
    48              # Erreur
    49              self.status = 0
    50              return {'connected' : 0,
    51                      't_con' : [{'connected': 0}]
    52                     }
    53
    54 -    def write_data(self):
    55          RRDAgent.write_data(self)
    56          if self.last_measure is not None:
    57              self.table.table_data = self.last_measure.value['t_con']
    58
    59 -    def check_status(self):
    60          if self.status == 1 :
    61              return status.OK()
    62          return status.Error()
    63