Beispiel #1
0
    def delete(self, app, action, **params):
        ''' delete the provided headline '''

        user = cherrypy.session['user']['name']
        host_app = cherrypy.request.path_info.split('/')[3]
        id = params.get('name')

        if not id:
            logger.error('on delete, no identifier was provided')
            return self.render_json({
                'success': 'false',
                'error': 'internal server error'
            })
        try:
            headline = Headlines.get(Headlines.build_id(id, app, user))
        except:
            logger.error('Failed to load headline %s' % id)
            return self.render_json({
                'success': 'false',
                'error': 'failed to load headline'
            })

        if not headline.delete():
            logger.error('failed to delete headline %s' % headline.label)
            return self.render_json({
                'success': 'false',
                'error': 'failed to delete headline'
            })

        logger.info('successfully deleted headline %s' % headline.label)

        return self.render_json({
            'success': 'true',
            'error': 'headline %s deleted' % headline.label
        })
Beispiel #2
0
    def id(self, app, action, id, **kwargs):
        ''' return details for a specific headline'''

        headline = None
        output = None
        user = cherrypy.session['user']['name'] 
        host_app = cherrypy.request.path_info.split('/')[3]

        try:
            headline = Headlines.get(Headlines.build_id(id, app, 'nobody')) 
            #if headline is not None:
            #    output = self.get_headlines_detail(list(headline), host_app, user, 1, None)
        except Exception, ex:
            logger.exception(ex)
            logger.warn('problem retreiving headline %s' % id) 
            raise cherrypy.HTTPRedirect(self._redirect(host_app, app, 'headline_not_found'), 303)
Beispiel #3
0
    def id(self, app, action, id, **kwargs):
        ''' return details for a specific headline'''

        headline = None
        output = None
        user = cherrypy.session['user']['name']
        host_app = cherrypy.request.path_info.split('/')[3]

        try:
            headline = Headlines.get(Headlines.build_id(id, app, 'nobody'))
            #if headline is not None:
            #    output = self.get_headlines_detail(list(headline), host_app, user, 1, None)
        except Exception, ex:
            logger.exception(ex)
            logger.warn('problem retreiving headline %s' % id)
            raise cherrypy.HTTPRedirect(
                self._redirect(host_app, app, 'headline_not_found'), 303)
Beispiel #4
0
    def manage(self, app, action, **kwargs):
        ''' return the headlines management template'''
 
        user = cherrypy.session['user']['name'] 
        host_app = cherrypy.request.path_info.split('/')[3]

        headlines = Headlines.all()
        headlines = headlines.filter_by_app(app)
   
        return self.render_template('/%s:/templates/unixHeadlines/headlines_manage.html' % host_app,
                                    dict(host_app=host_app, headlines=headlines, app=app))
Beispiel #5
0
    def manage(self, app, action, **kwargs):
        ''' return the headlines management template'''

        user = cherrypy.session['user']['name']
        host_app = cherrypy.request.path_info.split('/')[3]

        headlines = Headlines.all()
        headlines = headlines.filter_by_app(app)

        return self.render_template(
            '/%s:/templates/unixHeadlines/headlines_manage.html' % host_app,
            dict(host_app=host_app, headlines=headlines, app=app))
Beispiel #6
0
    def new(self, app, action, **kwargs):
        ''' render the _new template '''

        user = cherrypy.session['user']['name']
        host_app = cherrypy.request.path_info.split('/')[3]

        headline = Headlines(app, user, '_new')
        alerts = SavedSearch.all()
        alerts = alerts.filter_by_app(app)
        alerts = alerts.search('is_scheduled=True')

        return self.render_template('/%s:/templates/unixHeadlines/headlines_new.html' \
                                    % host_app,
                                    dict(host_app=host_app, app=app, headline=headline, alerts=alerts))
Beispiel #7
0
    def delete(self, app, action, **params):
        ''' delete the provided headline '''

        user = cherrypy.session['user']['name'] 
        host_app = cherrypy.request.path_info.split('/')[3]
        id = params.get('name')

        if not id:
            logger.error('on delete, no identifier was provided')
            return self.render_json({'success':'false', 'error':'internal server error'})
        try:
            headline = Headlines.get(Headlines.build_id(id, app, user))
        except:
            logger.error('Failed to load headline %s' % id)
            return self.render_json({'success':'false', 'error':'failed to load headline'})

        if not headline.delete():
            logger.error('failed to delete headline %s' % headline.label)
            return self.render_json({'success':'false', 'error':'failed to delete headline'})
        
        logger.info('successfully deleted headline %s' % headline.label)

        return self.render_json({'success':'true', 'error':'headline %s deleted' % headline.label})
Beispiel #8
0
    def list(self, app, action, **kwargs):
        ''' return headlines'''

        output = {'headlines': []} 
        user = cherrypy.session['user']['name'] 
        host_app = cherrypy.request.path_info.split('/')[3]

        count = int(kwargs.get('count', '10'))
        earliest = kwargs.get('earliest', None)
        severity = kwargs.get('severity', ['1','2','3','4','5'])

        headlines = Headlines.all()
        headlines = headlines.filter_by_app(app)
        headlines = headlines.filter_by_user(user)
      
        output['headlines'] = self.get_headlines_detail(headlines, app, user, 
                                                        count, earliest, severity=severity, srtd=True)

        return self.render_json(output)
Beispiel #9
0
    def list(self, app, action, **kwargs):
        ''' return headlines'''

        output = {'headlines': []}
        user = cherrypy.session['user']['name']
        host_app = cherrypy.request.path_info.split('/')[3]

        count = int(kwargs.get('count', '10'))
        earliest = kwargs.get('earliest', None)
        severity = kwargs.get('severity', ['1', '2', '3', '4', '5'])

        headlines = Headlines.all()
        headlines = headlines.filter_by_app(app)
        headlines = headlines.filter_by_user(user)

        output['headlines'] = self.get_headlines_detail(headlines,
                                                        app,
                                                        user,
                                                        count,
                                                        earliest,
                                                        severity=severity,
                                                        srtd=True)

        return self.render_json(output)
Beispiel #10
0
    def save(self, app, action, **params):
        ''' save the posted headline '''

        user = cherrypy.session['user']['name']
        host_app = cherrypy.request.path_info.split('/')[3]

        key = params.get('name')

        try:
            if key == '_new':
                headline = Headlines(app, user, uuid4())
            else:
                headline = Headlines.get(Headlines.build_id(key, app, user))
        except:
            headline = Headlines(app, user, uuid4())

        headline.label = params.get('label')
        if not headline.label:
            headline.errors = ['label cannot be blank']
        else:
            headline.message = params.get('message')
            headline.description = params.get('description')
            headline.alert_name = params.get('alert_name')
            headline.metadata.sharing = 'app'

        if headline.errors or not headline.passive_save():
            logger.error('Error saving headline %s: %s' %
                         (headline.name, headline.errors[0]))
            alerts = SavedSearch.all()
            alerts = alerts.filter_by_app(app)
            alerts = alerts.search('is_scheduled=True')
            if key != '_new':
                return self.render_template(
                    '/%s:/templates/unixHeadlines/headlines_detail.html' %
                    host_app,
                    dict(host_app=host_app,
                         app=app,
                         headline=headline,
                         alerts=alerts))
            else:
                headline.name = key
                return self.render_template(
                    '/%s:/templates/unixHeadlines/headlines_new.html' %
                    host_app,
                    dict(host_app=host_app,
                         app=app,
                         headline=headline,
                         alerts=alerts))
        else:
            raise cherrypy.HTTPRedirect(
                self._redirect(host_app, app, 'success'), 303)
Beispiel #11
0
    def save(self, app, action, **params):
        ''' save the posted headline '''

        user = cherrypy.session['user']['name'] 
        host_app = cherrypy.request.path_info.split('/')[3]

        key = params.get('name')

        try:
            if key == '_new':
                headline = Headlines(app, user, uuid4())
            else:
                headline = Headlines.get(Headlines.build_id(key, app, user))
        except:
            headline = Headlines(app, user, uuid4())

        headline.label = params.get('label')
        if not headline.label:
            headline.errors = ['label cannot be blank']
        else:
            headline.message = params.get('message')
            headline.description = params.get('description')
            headline.alert_name = params.get('alert_name')
            headline.metadata.sharing = 'app'

        if headline.errors or not headline.passive_save():
            logger.error('Error saving headline %s: %s' % (headline.name, headline.errors[0]))
            alerts = SavedSearch.all()
            alerts = alerts.filter_by_app(app)
            alerts = alerts.search('is_scheduled=True')
            if key != '_new':
                return self.render_template('/%s:/templates/unixHeadlines/headlines_detail.html' % host_app,
                                             dict(host_app=host_app, app=app, headline=headline, alerts=alerts))
            else:
                headline.name = key
                return self.render_template('/%s:/templates/unixHeadlines/headlines_new.html' % host_app,
                                             dict(host_app=host_app, app=app, headline=headline, alerts=alerts))
        else:
            raise cherrypy.HTTPRedirect(self._redirect(host_app, app, 'success'), 303)