def DELETE(self, name):
     session = cherrypy.request.db
     cherrypy.response.headers["content-type"] = "text/plain"
     element = Monitor.get_one(session, name)
     if isinstance(element, Monitor):
         element = Monitor.del_one(session, element)
         if isinstance(element, Monitor):
             client_com.send_requests_process({"backend": None}, "DELETE", "monitor", name, None, None, None)
             return "Monitor %s deleted" % name
     elif element == Monitor.ERROR_ELEMENT_NOT_EXISTS:
         raise cherrypy.HTTPError("404", "Monitor %s not found" % name)
 def GET(self, name=None, room=None):
     session = cherrypy.request.db
     cherrypy.response.headers["content-type"] = "text/xml"
     if name == None:
         elements = Monitor.get_all(session, room)
         if isinstance(elements, list):
             return Monitor.export_all(elements, "all")
     else:
         element = Monitor.get_one(session, name)
         if isinstance(element, Monitor):
             return Monitor.export_one(element, "all")
         elif elements == Monitor.ERROR_ELEMENT_NOT_EXISTS:
             raise cherrypy.HTTPError("404", "Monitor %s not found" % name)
 def POST(self, name):
     session = cherrypy.request.db
     cherrypy.response.headers["content-type"] = "text/plain"
     body = cherrypy.request.body.read().decode()
     if cherrypy.request.process_request_body == True:
         element = Monitor.get_one(session, name)
         if isinstance(element, Monitor):
             element = Monitor.import_one(session, body, element=element)
             if isinstance(element, Monitor):
                 client_com.send_requests_process({"backend": None}, "POST", "monitor", name, None, body, "text/xml")
                 return "Monitor %s updated" % name
             elif element == Monitor.ERROR_TAG_NOT_VALID:
                 raise cherrypy.HTTPError("400", "Tag not valid")
         elif element == Monitor.ERROR_ELEMENT_NOT_EXISTS:
             raise cherrypy.HTTPError("404", "Monitor %s not found" % name)
     else:
         raise cherrypy.HTTPError("400", "No body specified")
 def PUT(self, name, attrib=None):
     session = cherrypy.request.db
     cherrypy.response.headers["content-type"] = "text/plain"
     body = cherrypy.request.body.read().decode()
     if cherrypy.request.process_request_body == True:
         if attrib == None:
             element = Monitor.import_one(session, body, name=name)
             if isinstance(element, Monitor):
                 element = Monitor.add_one(session, element)
                 if isinstance(element, Monitor):
                     client_com.send_requests_process(
                         {"backend": None}, "PUT", "monitor", name, attrib, body, "text/xml"
                     )
                     return "Monitor %s added" % name
                 elif element == Monitor.ERROR_ELEMENT_ALREADY_EXISTS:
                     raise cherrypy.HTTPError("403", "Monitor %s alread exists" % name)
             elif element == Monitor.ERROR_TAG_NOT_VALID:
                 raise cherrypy.HTTPError("400", "Tag not valid")
         else:
             if not isinstance(cherrypy.request.role, str):
                 element = Monitor.get_one(session, name)
                 if isinstance(element, Monitor):
                     element = Monitor.edit_one(session, element, attrib, body)
                     if isinstance(element, Monitor):
                         client_com.send_requests_process(
                             {"backend": None}, "PUT", "monitor", name, attrib, body, "text/plain"
                         )
                         return "Monitor %s attribute %s value %s changed" % (name, attrib, body)
                     elif element == Monitor.ERROR_ATTRIB_NOT_VALID:
                         raise cherrypy.HTTPError("404", "Attribute %s not found" % attrib)
                 elif element == Monitor.ERROR_ELEMENT_NOT_EXISTS:
                     raise cherrypy.HTTPError("404", "Monitor %s not found" % name)
             else:
                 raise cherrypy.HTTPError("401", "You are not allowed to access this resource.")
     else:
         raise cherrypy.HTTPError("400", "No body specified")