Exemplo n.º 1
0
 def get_one(self, idpds):
     # pylint:disable-msg=C0111,R0201
     idhost = get_parent_id("hosts")
     pds = get_pds(idpds, idhost)
     result = {
             "id": pds.idperfdatasource,
             "href": tg.url("/api/v%s/hosts/%s/perfdatasources/%s"
                    % (self.apiver, pds.host.idhost, pds.idperfdatasource)),
             "host": {
                 "id": pds.host.idhost,
                 "name": pds.host.name,
                 "href": tg.url("/api/v%s/hosts/%s" % (self.apiver, pds.host.idhost)),
                 },
             "name": pds.name,
             "type": pds.type,
             "label": pds.label,
             "factor": pds.factor,
             "max": pds.max,
             }
     graphs = []
     for graph in pds.graphs:
         graphs.append({
             "id": graph.idgraph,
             "href": tg.url("/api/v%s/graphs/%s" % (self.apiver, graph.idgraph)),
             "name": graph.name,
             })
     result["graphs"] = graphs
     return dict(pds=result)
Exemplo n.º 2
0
 def get_all(self):
     # pylint:disable-msg=C0111,R0201
     idhost = get_parent_id("hosts")
     if idhost is None:
         raise HTTPNotFound("Can't find the host")
     host = get_host(idhost)
     result = []
     for pds in host.perfdatasources:
         result.append({
             "id": pds.idperfdatasource,
             "name": pds.name,
             "href": tg.url("/api/v%s/hosts/%s/perfdatasources/%s"
                        % (self.apiver, host.idhost, pds.idperfdatasource)),
             })
     return dict(perfdatasources=result)
Exemplo n.º 3
0
 def get_all(self):
     # pylint:disable-msg=C0111,R0201
     idhost = get_parent_id("hosts")
     if idhost is not None:
         host = get_host(idhost)
         services = host.services
     else:
         services = get_all_services(self.model_class)
     result = []
     for service in services:
         result.append({
             "id": service.idservice,
             "type": self.type,
             "href": tg.url("/api/v%s/%s/%s"
                         % (self.apiver, self.type, service.idservice)),
             "name": service.servicename,
             })
     return dict(services=result)
Exemplo n.º 4
0
 def get_all(self):
     # pylint:disable-msg=C0111,R0201
     idhost = get_parent_id("hosts")
     if idhost is not None:
         hosts = [get_host(idhost)]
     else:
         hosts = get_all_hosts()
     result = []
     for host in hosts:
         for graph in host.graphs:
             result.append(
                 {
                     "id": graph.idgraph,
                     "href": tg.url("/api/v%s/graphs/%s" % (self.apiver, graph.idgraph)),
                     "name": graph.name,
                 }
             )
     return dict(graphs=result)
Exemplo n.º 5
0
 def get_all(self):
     # pylint:disable-msg=C0111,R0201
     idmap = get_parent_id("maps")
     if idmap is not None:
         m = DBSession.query(tables.Map).get(idmap)
     else:
         raise HTTPNotFound("The URL seems invalid (no map found)")
     if m is None:
         raise HTTPNotFound("The map %s does not exist" % idmap)
     check_map_access(m)
     result = []
     for node in m.nodes:
         result.append({
             "id": node.idmapnode,
             "href": tg.url("/api/v%s/maps/%s/nodes/%s"
                            % (self.apiver, idmap, node.idmapnode)),
             })
     return dict(mapnodes=result)
Exemplo n.º 6
0
 def get_all(self):
     # pylint:disable-msg=C0111,R0201
     idmap = get_parent_id("maps")
     if idmap is not None:
         m = DBSession.query(tables.Map).get(idmap)
     else:
         raise HTTPNotFound("The URL seems invalid (no map found)")
     if m is None:
         raise HTTPNotFound("The map %s does not exist" % idmap)
     check_map_access(m)
     links = DBSession.query(tables.MapLink).filter_by(idmap=idmap).all()
     result = []
     for link in links:
         result.append({
             "id": link.idmaplink,
             "href": tg.url("/api/v%s/maps/%s/links/%s"
                            % (self.apiver, idmap, link.idmaplink)),
             })
     return dict(maplinks=result)
Exemplo n.º 7
0
 def get_one(self, idservice):
     # pylint:disable-msg=C0111,R0201
     idhost = get_parent_id("hosts")
     service = get_service(idservice, self.type, idhost)
     if not service:
         raise HTTPNotFound("Can't find service %s" % idservice)
     result = {"id": service.idservice,
               "type": self.type,
               "name": service.servicename,
               "href": tg.url("/api/v%s/%s/%s"
                         % (self.apiver, self.type, service.idservice))
               }
     status = {
             "name": service.state.name.statename,
             "message": service.state.message,
             "datetime": service.state.timestamp.isoformat(),
             "order": service.state.name.order,
             }
     result["status"] = status
     result["tags"] = [t.name for t in service.tags]
     groups = []
     for group in service.groups:
         groups.append({
             "id": group.idgroup,
             "name": group.name,
             })
     result["groups"] = groups
     if isinstance(service, LowLevelService):
         result["host"] = {
                 "id": service.host.idhost,
                 "name": service.host.name,
                 "href": tg.url("/api/v%s/hosts/%s"
                             % (self.apiver, service.host.idhost)),
                 }
     else:
         result["host"] = None
     return dict(service=result)