def post(self, subdomain, method = None, alert_id = None):
     form = AlertForm(MultiDict(self))
     if not form.validate():
         args = self.template_args
         args['form'] = form
         args['method'] = method
         args['subdomain'] = subdomain
         return self.render('alert.html', **args)
     user = UserManager.get_current_user()
     if method == 'create':
         alert = Alert()
     else:
         alert = AlertManager.get_alert(alert_id)
     alert.email = user.email
     alert.subdomain = user.subdomain
     alert.name = self.get_argument('name', '')
     alert.description = self.get_argument('description', '')
     alert.saved_search = int(self.get_argument('saved_search'))
     alert.threshold_operator = self.get_argument('threshold_operator')
     alert.threshold_count = int(self.get_argument('threshold_count'))
     alert.threshold_time_secs = int(self.get_argument('threshold_time_secs'))
     alert.sound = self.get_argument('sound')
     alert.endpoint = self.get_argument('endpoint', '')
     if method == 'create':
         alert.active = True
         alert.muted = False
         alert.state = 'N'
         alert.last_run = 0
         alert.last_state_change = 0
     alert.put()
     self.redirect('/%s' % subdomain)
Пример #2
0
    def delete(self):
        user = UserManager.get_current_user()
        oauth_client = lib.oauth.Client(user.subdomain)
        token = oauth_client.generate_token(user.access_token_key, user.access_token_secret)

        return oauth_client.make_request(token, 'http://%s.%s/api/savedsearches/%s' % \
            (user.subdomain, config.LOGGLY_DOMAIN, self.id), 'DELETE')
 def build_search_url(context, search_from_secs):
     # _devices is not yet supported - use (device:...) syntax instead for now
     # e.g. https://foo.loggly.com/shell#/_search */_inputs=syslog_udp,test_http/_from=NOW-2MINUTES
     user = UserManager.get_current_user()
     params = []
     params.append("_search %s" % Loggly.build_search_query(context))
     params.append("_from=NOW-%sSECONDS" % search_from_secs)
     return "http://%s.%s/shell#/%s" % (user.subdomain, config.LOGGLY_DOMAIN, "/".join(params))
Пример #4
0
 def build_search_url(context, search_from_secs):
     # _devices is not yet supported - use (device:...) syntax instead for now
     # e.g. https://foo.loggly.com/shell#/_search */_inputs=syslog_udp,test_http/_from=NOW-2MINUTES
     user = UserManager.get_current_user()
     params = []
     params.append('_search %s' % Loggly.build_search_query(context))
     params.append('_from=NOW-%sSECONDS' % search_from_secs)
     return 'http://%s.%s/shell#/%s' % (
         user.subdomain, config.LOGGLY_DOMAIN, '/'.join(params))
Пример #5
0
 def get_inputs(user=None):
     if not user:
         user = UserManager.get_current_user()
     oauth_client = lib.oauth.Client(user.subdomain)
     token = oauth_client.generate_token(user.access_token_key,
                                         user.access_token_secret)
     try:
         return json.loads(oauth_client.make_request(token, 'http://%s.%s/api/inputs' % \
             (user.subdomain, config.LOGGLY_DOMAIN) , 'GET'))
     except ValueError:
         logging.error(json.dumps({'module': 'lib.loggly', 'message': \
             'Subdomain \'%s\' could not load the list of inputs' % user.subdomain}))
         raise
Пример #6
0
    def get_saved_search(id):
        user = UserManager.get_current_user()
        oauth_client = lib.oauth.Client(user.subdomain)
        token = oauth_client.generate_token(user.access_token_key,
                                            user.access_token_secret)

        try:
            return json.loads(oauth_client.make_request(token, 'http://%s.%s/api/savedsearches/%s' % \
                (user.subdomain, config.LOGGLY_DOMAIN, id), 'GET'))
        except ValueError:
            logging.error(json.dumps({'module': 'lib.loggly', 'message': \
                'Subdomain \'%s\' could not load the saved search with ID %d' % (user.subdomain, id)}))
            raise
Пример #7
0
    def put(self):
        user = UserManager.get_current_user()
        oauth_client = lib.oauth.Client(user.subdomain)
        token = oauth_client.generate_token(user.access_token_key, user.access_token_secret)
         
        params = {}
        if self.id:
            params['id'] = self.id
        params['name'] = self.name
        params['context'] = json.dumps(self.context)

        if not self.id:
            method = 'POST'
        else:
            method = 'PUT'

        return oauth_client.make_request(token, 'http://%s.%s/api/savedsearches' % \
            (user.subdomain, config.LOGGLY_DOMAIN), method, params = params)
    def post(self, subdomain, method = None, id = None):
        form = SavedSearchForm(MultiDict(self))
        if not form.validate():
            self.errors = form.errors
            raise tornado.web.HTTPError(400)
            return
        user = UserManager.get_current_user()

        if method == 'create':
            savedsearch = SavedSearch()
        else:
            savedsearch = SavedSearchManager.get_saved_search(id)

        savedsearch.name = self.get_argument('name') 
        savedsearch.context = {'terms': self.get_argument('terms'), 
                               'inputs': self.get_arguments('inputs'), 
                               'devices': self.get_arguments('devices')}

        result = savedsearch.put()
    def get(self, subdomain, action = None, id = None):
        if action == 'run':
            user = UserManager.get_current_user()
            oauth_client = lib.oauth.Client(user.subdomain)
            token = oauth_client.generate_token(user.access_token_key, user.access_token_secret)

            saved_search = SavedSearchManager.get_saved_search(id)

            qs = Loggly.build_search_query_string(saved_search.context, self.get_argument('threshold_time_secs'))

            self.write(oauth_client.make_request(token, 'http://%s.%s/api/search/?%s' % \
                (user.subdomain, config.LOGGLY_DOMAIN, qs) , 'GET'))
        if action == 'retrieve':
            if id:
                self.write(json.dumps(Loggly.get_saved_search(id)))
            else:
                self.write(json.dumps(Loggly.get_all_saved_searches()))
        if action == 'delete':
            return self.write(SavedSearchManager.get_saved_search(id).delete())
    def post(self, subdomain, method = None, endpoint_id = None):
        form = EndpointForm(MultiDict(self))
        if not form.validate():
            self.errors = form.errors
            raise tornado.web.HTTPError(400)
            return
        user = UserManager.get_current_user()
        if method == 'create':
            endpoint = Endpoint()
        else:
            endpoint = EndpointManager.get_endpoint(endpoint_id)

        endpoint.email = user.email
        endpoint.subdomain = user.subdomain
        endpoint.provider = self.get_argument('provider')
        endpoint.description = self.get_argument('description', '')
        endpoint.service_key = self.get_argument('service_key')
        endpoint.alert_text = self.get_argument('alert_text', '')
        endpoint.put()
        self.redirect('/%s' % subdomain)
Пример #11
0
    def post(self, subdomain, method=None, endpoint_id=None):
        form = EndpointForm(MultiDict(self))
        if not form.validate():
            self.errors = form.errors
            raise tornado.web.HTTPError(400)
            return
        user = UserManager.get_current_user()
        if method == 'create':
            endpoint = Endpoint()
        else:
            endpoint = EndpointManager.get_endpoint(endpoint_id)

        endpoint.email = user.email
        endpoint.subdomain = user.subdomain
        endpoint.provider = self.get_argument('provider')
        endpoint.description = self.get_argument('description', '')
        endpoint.service_key = self.get_argument('service_key')
        endpoint.alert_text = self.get_argument('alert_text', '')
        endpoint.put()
        self.redirect('/%s' % subdomain)
    def post(self, subdomain, method=None, id=None):
        form = SavedSearchForm(MultiDict(self))
        if not form.validate():
            self.errors = form.errors
            raise tornado.web.HTTPError(400)
            return
        user = UserManager.get_current_user()

        if method == 'create':
            savedsearch = SavedSearch()
        else:
            savedsearch = SavedSearchManager.get_saved_search(id)

        savedsearch.name = self.get_argument('name')
        savedsearch.context = {
            'terms': self.get_argument('terms'),
            'inputs': self.get_arguments('inputs'),
            'devices': self.get_arguments('devices')
        }

        result = savedsearch.put()
    def get(self, subdomain, action=None, id=None):
        if action == 'run':
            user = UserManager.get_current_user()
            oauth_client = lib.oauth.Client(user.subdomain)
            token = oauth_client.generate_token(user.access_token_key,
                                                user.access_token_secret)

            saved_search = SavedSearchManager.get_saved_search(id)

            qs = Loggly.build_search_query_string(
                saved_search.context, self.get_argument('threshold_time_secs'))

            self.write(oauth_client.make_request(token, 'http://%s.%s/api/search/?%s' % \
                (user.subdomain, config.LOGGLY_DOMAIN, qs) , 'GET'))
        if action == 'retrieve':
            if id:
                self.write(json.dumps(Loggly.get_saved_search(id)))
            else:
                self.write(json.dumps(Loggly.get_all_saved_searches()))
        if action == 'delete':
            return self.write(SavedSearchManager.get_saved_search(id).delete())
    def get_saved_search(id):
        user = UserManager.get_current_user()
        oauth_client = lib.oauth.Client(user.subdomain)
        token = oauth_client.generate_token(user.access_token_key, user.access_token_secret)

        try:
            return json.loads(
                oauth_client.make_request(
                    token, "http://%s.%s/api/savedsearches/%s" % (user.subdomain, config.LOGGLY_DOMAIN, id), "GET"
                )
            )
        except ValueError:
            logging.error(
                json.dumps(
                    {
                        "module": "lib.loggly",
                        "message": "Subdomain '%s' could not load the saved search with ID %d" % (user.subdomain, id),
                    }
                )
            )
            raise
 def get_inputs(user=None):
     if not user:
         user = UserManager.get_current_user()
     oauth_client = lib.oauth.Client(user.subdomain)
     token = oauth_client.generate_token(user.access_token_key, user.access_token_secret)
     try:
         return json.loads(
             oauth_client.make_request(
                 token, "http://%s.%s/api/inputs" % (user.subdomain, config.LOGGLY_DOMAIN), "GET"
             )
         )
     except ValueError:
         logging.error(
             json.dumps(
                 {
                     "module": "lib.loggly",
                     "message": "Subdomain '%s' could not load the list of inputs" % user.subdomain,
                 }
             )
         )
         raise
Пример #16
0
    def get(self, subdomain=None):
        '''
        We're here for one of several reasons:
        1. Initial visit, not logged in, going to '/' (show welcome page)
        2. Initial visit, no User object stored yet in App Engine datastore (returning from google.com)
        3. Return visit, everything normal
        4. Return visit, no subdomain in URL (so going to '/')
        5. User object stored, but access token not yet written (returning from loggly.com)
        6. User object stored, but access token not yet written (App Engine threw exception when returning from Loggly, etc.)
        7. User entered a subdomain, then hit the back button
        '''
        args = self.template_args
        if not google_users.get_current_user():
            # case 1
            logging.info({'module': 'main', 'path': 'case 1'})
            args['login_url'] = google_users.create_login_url(self.request.uri)
            return self.render('splash.html', **args)

        if not UserManager.current_user_exists():
            # case 2
            logging.info({'module': 'main', 'path': 'case 2'})
            args['form'] = SubdomainForm()
            return self.render('subdomain.html', **args)

        user = UserManager.get_current_user()
        if subdomain:
            args['subdomain'] = subdomain
        else:
            args['subdomain'] = user.subdomain

        if self.get_argument('oauth_verifier',
                             None) or not user.access_token_key:
            # cases 5, 6, or 7
            logging.info({'module': 'main', 'path': 'case 5, 6 or 7'})

            oauth_client = lib.oauth.Client(user.subdomain)

            if self.get_argument('oauth_verifier', None):
                # case 5 (just in case)
                user.oauth_verifier = self.get_argument('oauth_verifier')
                user.put()
            elif not user.oauth_verifier:
                # case 7
                request_token = oauth_client.generate_token(
                    user.request_token_key, user.request_token_secret)
                url = oauth_client.get_authorize_url(request_token)
                return self.redirect(url)

            request_token = oauth_client.generate_token(
                user.request_token_key, user.request_token_secret)
            request_token.verifier = user.oauth_verifier

            access_token = oauth_client.get_access_token(request_token)

            # store the access token for all future requests
            user.access_token_key = access_token.key
            user.access_token_secret = access_token.secret
            user.new_user = False
            user.put()

            search_result = json.loads(oauth_client.make_request(access_token, 'http://%s.%s/api/facets/date?q=*&from=NOW-1YEAR' % \
                (user.subdomain, config.LOGGLY_DOMAIN), 'GET'))
            logging.info(
                json.dumps({
                    'module': 'main',
                    'user': user.email,
                    'event': 'new user',
                    'loggly_events_found': search_result['numFound']
                }))
            if search_result['numFound'] == 0:
                return self.render('nodata.html', **args)

        if not subdomain:
            # case 4
            logging.info({'module': 'main', 'path': 'case 4'})
            # this must come after the others so we don't lose the OAuth parameters from the URL
            return self.redirect('/%s' % user.subdomain)

        # case 3 or 5
        logging.info({'module': 'main', 'path': 'case 3 or 5'})
        if self.request.uri[-1] == '/':
            return self.redirect(self.request.uri[:-1])

        args['alerts'] = AlertManager.get_all_alerts(user.subdomain)
        self.render('main.html', **args)
    def get(self, subdomain = None):
        '''
        We're here for one of several reasons:
        1. Initial visit, not logged in, going to '/' (show welcome page)
        2. Initial visit, no User object stored yet in App Engine datastore (returning from google.com)
        3. Return visit, everything normal
        4. Return visit, no subdomain in URL (so going to '/')
        5. User object stored, but access token not yet written (returning from loggly.com)
        6. User object stored, but access token not yet written (App Engine threw exception when returning from Loggly, etc.)
        7. User entered a subdomain, then hit the back button
        '''
        args = self.template_args
        if not google_users.get_current_user():
            # case 1
            logging.info({'module': 'main', 'path': 'case 1'})
            args['login_url'] = google_users.create_login_url(self.request.uri)
            return self.render('splash.html', **args)

        if not UserManager.current_user_exists():
            # case 2
            logging.info({'module': 'main', 'path': 'case 2'})
            args['form'] = SubdomainForm()
            return self.render('subdomain.html', **args)

        user = UserManager.get_current_user()
        if subdomain:
            args['subdomain'] = subdomain
        else:
            args['subdomain'] = user.subdomain

        if self.get_argument('oauth_verifier', None) or not user.access_token_key:
            # cases 5, 6, or 7
            logging.info({'module': 'main', 'path': 'case 5, 6 or 7'})

            oauth_client = lib.oauth.Client(user.subdomain)
 
            if self.get_argument('oauth_verifier', None):
                # case 5 (just in case)
                user.oauth_verifier = self.get_argument('oauth_verifier')
                user.put()
            elif not user.oauth_verifier:
                # case 7
                request_token = oauth_client.generate_token(user.request_token_key, user.request_token_secret)
                url = oauth_client.get_authorize_url(request_token)
                return self.redirect(url)

            request_token = oauth_client.generate_token(user.request_token_key, user.request_token_secret)
            request_token.verifier = user.oauth_verifier

            access_token = oauth_client.get_access_token(request_token)
            
            # store the access token for all future requests
            user.access_token_key = access_token.key
            user.access_token_secret = access_token.secret
            user.new_user = False
            user.put()

            search_result = json.loads(oauth_client.make_request(access_token, 'http://%s.%s/api/facets/date?q=*&from=NOW-1YEAR' % \
                (user.subdomain, config.LOGGLY_DOMAIN), 'GET'))
            logging.info(json.dumps({'module': 'main', 'user': user.email, 'event': 'new user', 'loggly_events_found': search_result['numFound']}))
            if search_result['numFound'] == 0:
                return self.render('nodata.html', **args)

        if not subdomain:
            # case 4
            logging.info({'module': 'main', 'path': 'case 4'})
            # this must come after the others so we don't lose the OAuth parameters from the URL
            return self.redirect('/%s' % user.subdomain)

        # case 3 or 5
        logging.info({'module': 'main', 'path': 'case 3 or 5'})
        if self.request.uri[-1] == '/':
            return self.redirect(self.request.uri[:-1])

        args['alerts'] = AlertManager.get_all_alerts(user.subdomain)
        self.render('main.html', **args)