Exemplo n.º 1
0
    def get(self):
        self.reqparse.add_argument('count', type=int, default=100)
        self.reqparse.add_argument('page', type=int, default=0)
        self.reqparse.add_argument('levelno', type=int, default=0)
        args = self.reqparse.parse_args()

        if args['levelno'] > 0:
            total_events = db.query(
                func.count(LogEvent.log_event_id)
            ).filter(LogEvent.levelno >= args['levelno']).first()[0]

            qry = (
                db.LogEvent
                .filter(LogEvent.levelno >= args['levelno'])
                .order_by(desc(LogEvent.timestamp))
                .limit(args['count'])
            )
        else:
            total_events = db.query(func.count(LogEvent.log_event_id)).first()[0]
            qry = (
                db.LogEvent
                .order_by(desc(LogEvent.timestamp))
                .limit(args['count'])
            )

        if (args['page'] - 1) > 0:
            offset = (args['page'] - 1) * args['count']
            qry = qry.offset(offset)

        events = qry.all()
        return self.make_response({
            'logEventCount': total_events,
            'logEvents': events
        })
Exemplo n.º 2
0
    def get(self):
        self.reqparse.add_argument('page', type=int, default=1)
        self.reqparse.add_argument('count', type=int, default=100)
        self.reqparse.add_argument('events',
                                   type=str,
                                   action='append',
                                   default=None)
        self.reqparse.add_argument('actors',
                                   type=str,
                                   action='append',
                                   default=None)
        args = self.reqparse.parse_args()

        qry = db.AuditLog.order_by(AuditLog.audit_log_event_id.desc())
        if args['events']:
            qry = qry.filter(AuditLog.event.in_(args['events']))

        if args['actors']:
            qry = qry.filter(AuditLog.actor.in_(args['actors']))

        totalEvents = qry.count()
        qry = qry.limit(args['count'])

        if (args['page'] - 1) > 0:
            offset = (args['page'] - 1) * args['count']
            qry = qry.offset(offset)

        return self.make_response({
            'auditLogEvents':
            qry.all(),
            'auditLogEventCount':
            totalEvents,
            'eventTypes':
            [x[0] for x in db.query(distinct(AuditLog.event)).all()]
        })
Exemplo n.º 3
0
    def _get_instances_by_account(self):
        instances = (db.query(func.count(
            Resource.resource_id), Account.account_name).join(
                Account, Resource.account_id == Account.account_id).filter(
                    Resource.resource_type_id == ec2_type_id,
                    Account.account_type_id == aws_account_type_id,
                    Account.enabled == 1).group_by(Account.account_name).all())

        return defaultdict(int, map(reversed, instances))
Exemplo n.º 4
0
 def _get_instance_counts(self):
     return (
         db.query(func.count(Resource.resource_id))
         .join(Account, Resource.account_id == Account.account_id)
         .filter(
             Account.account_id.in_(session['accounts']),
             Account.enabled == 1,
             Resource.resource_type_id == ec2_type_id
         ).first()[0]
     )
Exemplo n.º 5
0
 def _get_instances_by_state(self):
     return (db.query(
         ResourceProperty.value, func.count(ResourceProperty.value)).join(
             Resource,
             ResourceProperty.resource_id == Resource.resource_id).join(
                 Account, Resource.account_id == Account.account_id).filter(
                     Account.account_id.in_(session['accounts']),
                     Account.enabled == 1,
                     Resource.resource_type_id == ec2_type_id,
                     ResourceProperty.name == 'state').group_by(
                         ResourceProperty.value).all())
Exemplo n.º 6
0
 def _get_public_ip_instances(self):
     return (db.query(func.count(ResourceProperty.resource_id)).join(
         Resource,
         ResourceProperty.resource_id == Resource.resource_id).join(
             Account, Resource.account_id == Account.account_id).filter(
                 Account.account_id.in_(session['accounts']),
                 Account.enabled == 1,
                 and_(
                     ResourceProperty.name == 'public_ip',
                     not_(func.JSON_CONTAINS(ResourceProperty.value,
                                             'null')))).first()[0])
Exemplo n.º 7
0
    def get(self):
        self.reqparse.add_argument('page', type=int, default=1)
        self.reqparse.add_argument('count', type=int, default=100)
        self.reqparse.add_argument('subsystems',
                                   type=str,
                                   default=None,
                                   action='append')

        args = self.reqparse.parse_args()
        total_qry = db.query(func.count(Email.email_id))
        qry = db.Email.order_by(desc(Email.timestamp))

        if args['subsystems']:
            authsystems = [
                x for x in map(lambda x: x.lower(), args['subsystems'])
            ]
            qry = qry.filter(func.lower(Email.subsystem).in_(authsystems))
            total_qry = total_qry.filter(
                func.lower(Email.subsystem).in_(authsystems))

        if (args['page'] - 1) > 0:
            offset = (args['page'] - 1) * args['count']
            qry = qry.offset(offset)

        qry = qry.limit(args['count'])
        emails = qry.all()
        total_emails = total_qry.first()[0]

        return self.make_response({
            'message':
            None,
            'emailCount':
            total_emails,
            'emails':
            emails,
            'subsystems':
            [x[0] for x in db.query(distinct(Email.subsystem)).all()]
        })
Exemplo n.º 8
0
    def _get_issues_by_account(self):
        acct_alias = aliased(IssueProperty)

        issues = (db.query(func.count(
            Issue.issue_id), Account.account_name).join(
                acct_alias, Issue.issue_id == acct_alias.issue_id).join(
                    Account, acct_alias.value == Account.account_id).filter(
                        Account.account_type_id == aws_account_type_id,
                        Account.enabled == 1,
                        Issue.issue_type_id == reqtag_type_id,
                        acct_alias.name == 'account_id').group_by(
                            Account.account_name).all())

        return defaultdict(int, map(reversed, issues))