def index(self, **kwargs): """Point d'entrée principal""" if not DBSession.query(Host).count(): LOGGER.error("No configuration yet") raise HTTPServiceUnavailable("No configuration yet") if "host" not in kwargs: return redirect('/servers') host = kwargs["host"] if "graphtemplate" not in kwargs: return redirect('/graphs', host_=host) if "start" in kwargs: start = int(kwargs["start"]) else: start = int(time.time()) - 86400 # Par défaut: 24 heures avant details = "1" if "details" in kwargs and kwargs["details"] == "0": details = "" duration = int(kwargs.get('duration', 86400)) if "direct" in kwargs and kwargs["direct"]: format = "png" else: format = "html" redirect('/graph.%s' % format, { 'host_': kwargs['host'], 'graphtemplate': kwargs['graphtemplate'], 'start': start, 'duration': duration, 'details': details, })
def by_host_and_name(cls, host, name): if isinstance(host, int): idhost = host else: idhost = host.idhost return DBSession.query(cls).filter( cls.idhost == idhost ).filter( cls.name == unicode(name) ).first()
def by_graph_and_name(cls, graph, name): """Retourne le CDEF correspondant au graphe et au nom donné""" if isinstance(graph, int): idgraph = graph else: idgraph = graph.idgraph return DBSession.query(cls).filter( cls.idgraph == idgraph ).filter( cls.name == unicode(name) ).first()
def getLastValue(self, ds): """ Lecture derniere valeur RRD @return: Dernière valeur. @rtype: C{str} ou C{None} """ # dernier timestamp et step lasttime = self.getLast() step = self.getStep() if not lasttime or not step: return None # bornes selon timestamp et step start = lasttime - step end = lasttime # informations cf = self.getPeriodCF(start) _info, _ds_rrd, data = rrdtool.fetch(self.filename, cf, "--start", str(start), "--end", str(end)) if len(data) == 0 or len(data[0]) == 0: return None lastValue = data[0][0] if lastValue is None: return None factor = DBSession.query( PerfDataSource.factor ).join( (GRAPH_PERFDATASOURCE_TABLE, GRAPH_PERFDATASOURCE_TABLE.c.idperfdatasource == PerfDataSource.idperfdatasource), (Graph, Graph.idgraph == GRAPH_PERFDATASOURCE_TABLE.c.idgraph), ).filter(PerfDataSource.name == unicode(ds) ).filter(Graph.idhost == self.host.idhost ).scalar() if factor is None: factor = 1 return lastValue * factor
def servers(self): servers = [ h.name for h in DBSession.query(Host.name).all() ] return {"servers": servers}
def by_name(cls, name): return DBSession.query(cls).filter(cls.name == unicode(name)).first()