Example #1
0
    def post(self, version):
        
        if (self.valid_version(version)):
            name = self.request.get('name', default_value=None)
            description = self.request.get('description', default_value=None)
            image = self.request.get('image', default_value=None)
            level = self.request.get('level', default_value=None)
            severity = Level.get_severity(level)

            if name and description and severity and image:
                slug = slugify.slugify(name)
                status = Status.get_by_slug(slug)

                # Update existing resource
                if status:
                    status.description = description
                    status.severity = severity
                    status.image = image
                    status.name = name
                    status.put()
                    self.json(status.rest(self.base_url(version)))
                # Create new service
                else:
                    status = Status(name=name, slug=slug, description=description, 
                        severity=severity, image=image)
                    status.put()
                    self.json(status.rest(self.base_url(version)))
            else:
                self.error(400, "Bad Data")
        else:
            self.error(404, "API Version %s not supported" % version)
Example #2
0
    def get(self):
        user = users.get_current_user()
        logging.debug("BasicRootHandler #get")

        q = Service.all()
        q.order("name")
        services = q.fetch(100)
        
        p = Status.all()
        p.order("severity")
        
        past = get_past_days(5)

        services = q.fetch(100)
    
        for s in services:
            logging.info(s.last_six_days())

        
        td = {}
        td["services"] = services
        td["statuses"] = p.fetch(100)
        td["past"] = past
        td["default"] = Status.default()

        self.render(td, 'site/index.html')
Example #3
0
def main():
    # Check if defaults have been installed
    # Keep this for now, will be removed shortly
    installed_defaults = memcache.get("installed_defaults")
    if installed_defaults is None:
        installed_defaults = Setting.all().filter("name = ", "installed_defaults").get()
        if installed_defaults is None:
            logging.info("Installing default statuses")
            Status.install_defaults()
        if not memcache.add("installed_defaults", True):
            logging.error("Memcache set failed.")

    wsgiref.handlers.CGIHandler().run(application())
Example #4
0
    def post(self, version, status_slug):

        
        if (self.valid_version(version)):
            status = Status.get_by_slug(status_slug)
            if status:
                name = self.request.get('name', default_value=None)
                image = self.request.get('image', default_value=None)
                description = self.request.get('description', default_value=None)
                level = self.request.get('level', default_value=None)
                severity = Level.get_severity(level)
                
                if description:
                    status.description = description
                    
                if image:
                    status.image = image
                    
                if name:
                    status.name = name
                    
                if severity:
                    status.severity = severity
                
                if description or name or image or severity:
                    status.put()
                    
                self.json(status.rest(self.base_url(version)))
            else:
                self.error(404, "Status %s not found" % status_slug)
        else:
            self.error(404, "API Version %s not supported" % version)
Example #5
0
    def get(self, version, status_slug):
        logging.debug("CurrentStatusHandler#get")
        
        if (self.valid_version(version)):
            status = Status.get_by_slug(status_slug)

            if (status):
                self.json(status.rest(self.base_url(version))) 
            else:
                self.error(404, "No status %s for Service %s" % status_slug)
        else:
            self.error(404, "API Version %s not supported" % version)
Example #6
0
    def post(self, version, service_slug):
        logging.debug("EventsListHandler#post")
        
        if (self.valid_version(version)):
            status_slug = self.request.get("status", default_value=None)
            message = self.request.get("message", default_value=None)
            informational = self.request.get("informational", default_value=None)
            
            if message:
                service = Service.get_by_slug(service_slug)
                if service:
                    
                    if not status_slug:
                        event = service.current_event()
                        if event:
                            status = event.status
                        else:
                            status = Status.default()
                    else:
                        status = Status.get_by_slug(status_slug)

                    if status:
                        e = Event(status=status, service=service,
                                message=message)

                        e.informational = informational and informational == "true"

                        e.put()
                        self.json(e.rest(self.base_url(version)))
                    else:
                        self.error(404, "Status %s not found" % status_slug)
                else:
                    self.error(404, "Service %s not found" % service_slug)
            else:
                self.error(400, "Event message is required")
        else:
            self.error(404, "API Version %s not supported" % version)
Example #7
0
    def get(self, version):
        logging.debug("StatusesListHandler#get")
        
        if (self.valid_version(version)):
            query = Status.all().order('severity')

            if (query):
                data = []

                for s in query:
                    data.append(s.rest(self.base_url(version)))

                self.json({"statuses": data}) 
            else:
                self.error(404, "No statuses")
        else:
            self.error(404, "API Version %s not supported" % version)
Example #8
0
    def delete(self, version, status_slug):
        logging.debug("StatusInstanceHandler#delete slug=%s" % status_slug)
        
        if (self.valid_version(version)):

            status = Status.get_by_slug(status_slug)            

            if status:
                # We may want to think more about this
                events = Event.all().filter('status =', status).fetch(1000)
                for event in events:
                    event.delete()
                status.delete()
                self.json(status.rest(self.base_url(version)))
            else:
                self.error(404, "Status %s not found" % service_slug)
        else:
            self.error(404, "API Version %s not supported" % version)