zephir.monitor.agentmanager.data

Package zephir :: Package monitor :: Package agentmanager :: Module data |
[frames] | no frames]

# Source Code for Module zephir.monitor.agentmanager.data

      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
     11  """
     12
     13  try: _ # localized string fetch function
     14  except NameError: _ = str
     15
     16  from datetime import datetime
     17  import time
     18  from twisted.web.microdom import *
     19
     20  from zephir.monitor.agentmanager import util
     21
     22  DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
     23
     24 -class Measure:
     25      """Résultat d'une mesure à un instant donné."""
     26
     27 -    def __init__(self, date, value):
     28          self.date = util.timestampfromutc(date) #time.mktime(date.utctimetuple()) #date.strftime(DATE_FORMAT)
     29          self.value = value # {champ:valeur}
     30
     31 -    def get_date(self):
     32          """@return: date de mesure, UTC"""
     33          return util.utcfromtimestamp(self.date)
     34          #self.date #datetime.fromtimestamp(time.mktime(time.strptime(self.date, DATE_FORMAT)))
     35 -    def get_strdate(self):
     36          """
     37          @return: représentation texte de la date de mesure en temps
     38            local"""
     39          return datetime.fromtimestamp(self.date).strftime(DATE_FORMAT)
     40 -    def get_value(self, f):
     41          return self.value[f]
     42
     43 -    def __str__(self):
     44          return "[%s : %s]" % (self.get_strdate(), str(self.value))
     45
     46 -    def __cmp__(self, other):
     47          # None n'a pas d'attribut get_date, on renvoie toujours vrai dans ce cas
     48          if other == None:
     49              return 1
     50          else:
     51              return cmp(self.get_date(), other.get_date())
     52
     53
     54
     55 -class AgentDataChunk:
     56      """Élément de données généré par l'agent
     57      """
     58      pass
     59
     60
     61 -class FileData(AgentDataChunk):
     62      """Fichier quelconque dans le répertoire de l'agent
     63
     64      TODO: optional copying to the agent data dir
     65      """
     66 -    def __init__(self, filename):
     67          self.filename = filename
     68
     69 -class RRDFileData(FileData):
     70      """Fichier RRD"""
     71      pass
     72
     73 -class ImgFileData(FileData):
     74      """Fichier image, à afficher directement plutôt que par un lien"""
     75      pass
     76
     77 -class HTMLData(AgentDataChunk):
     78      """Code HTML, du niveau d'une balise <div> ou <p>"""
     79 -    def __init__(self, data):
     80          self.data = data
     81
     82 -class MeasuresData(AgentDataChunk):
     83      """Table de mesures C{zephir.monitor.agentmanager.data.Measure}"""
     84 -    def __init__(self, measures, fields = ['value']):
     85          self.measures = measures
     86          self.fields = fields
     87
     88 -class TableData(AgentDataChunk):
     89      """Table de valeurs
     90      """
     91 -    def __init__(self, columns_format, table_data=None):
     92          """
     93          @param table_data: a list of C{{key:value}} dicts (one dict
     94            per row, one key per column)
     95
     96          @param columns_format: a list of (key, title, attributes,
     97            formatter) tuples, one for each column in C{table_data},
     98            where:
     99
    100             - attributes is a C{{attr:value}} dict which describes HTML
    101               attributes of the corresponding table cell
    102
    103             - formatter is a function returning a string to display the
    104               value in the cell; you will probably have to define a
    105               real function instead of using lambda.
    106          """
    107          self.table_data = table_data
    108          self.columns_format = []
    109          for (field, title, attrs, format) in columns_format:
    110              if format is None: format = identity
    111              if attrs is None: attrs = ""
    112              else:
    113                  attrs = " " + ' '.join(['%s="%s"' % (k,v) for k,v in attrs.items()])
    114              self.columns_format.append((field, title, attrs, format))
    115
    116 -def identity(x): return x
    117