Esempio n. 1
0
def archive():
    traptype = db.Snmptt

    where_clause = db.sql_where_query(traptype,
                                      request.args,
                                      force_combiner='OR')

    try:
        result = db.DB.find(traptype, where_clause)
        count = result.count()
        for r in result:
            x = db.SnmpttArchive()
            x.eventname = r.eventname
            x.eventid = r.eventid
            x.trapoid = r.trapoid
            x.enterprise = r.enterprise
            x.community = r.community
            x.hostname = r.hostname
            x.agentid = r.agentip
            x.category = r.category
            x.severity = r.severity
            x.uptime = r.uptime
            x.traptime = r.traptime
            x.formatline = r.formatline
            x.trapread = r.trapread
            x.timewritten = r.timewritten
            db.DB.add(x)
        json_str = {'success': 'Successfully archived %d traps.' % count}
        result.remove()
    except Exception, e:
        json_str = {
            'error': 'Error occurred while archiving trap: %s' % str(e)
        }
Esempio n. 2
0
def archive():
    traptype = db.Snmptt

    where_clause = db.sql_where_query(traptype, request.args, force_combiner='OR')

    try:
        result = db.DB.find(traptype, where_clause)
        count = result.count()
        for r in result:
            x = db.SnmpttArchive()
            x.eventname = r.eventname
            x.eventid = r.eventid
            x.trapoid = r.trapoid
            x.enterprise = r.enterprise
            x.community = r.community
            x.hostname = r.hostname
            x.agentid = r.agentip
            x.category = r.category
            x.severity = r.severity
            x.uptime = r.uptime
            x.traptime = r.traptime
            x.formatline = r.formatline
            x.trapread = r.trapread
            x.timewritten = r.timewritten
            db.DB.add(x)
        json_str = {'success': 'Successfully archived %d traps.' % count}
        result.remove()
    except Exception, e:
        json_str = {'error': 'Error occurred while archiving trap: %s' % str(e)}
Esempio n. 3
0
def delete(tablename):
    traptype = getattr(db, tablename)

    where_clause = db.sql_where_query(traptype, request.args, force_combiner='OR')

    try:
        result = db.DB.find(traptype, where_clause)
        count = result.count()
        result.remove()
        json_str = {'success': 'Deleted %d traps.' % count}
    except Exception, e:
        json_str = {'error': 'Could not delete traps: %s' % str(e)}
Esempio n. 4
0
def inspector_read(trapid):
    trap = getattr(db, trapid)
    
    where_clause = db.sql_where_query(trap, request.args)
    
    if where_clause:
        results = db.DB.find(trap, where_clause)
    else:
        results = db.DB.find(trap)
    
    result_dict = db.encode_storm_result_set(results)
    
    json_str = json.dumps(result_dict, default=db.encode_storm_result_set)
    return Response(response=json_str, status=200, mimetype='application/json')
Esempio n. 5
0
def delete(tablename):
    traptype = getattr(db, tablename)

    where_clause = db.sql_where_query(traptype,
                                      request.args,
                                      force_combiner='OR')

    try:
        result = db.DB.find(traptype, where_clause)
        count = result.count()
        result.remove()
        json_str = {'success': 'Deleted %d traps.' % count}
    except Exception, e:
        json_str = {'error': 'Could not delete traps: %s' % str(e)}
Esempio n. 6
0
def inspector_chart(traptype):
    trapt = getattr(db, traptype)

    where_clause = db.sql_where_query(trapt, request.args)

    if where_clause:
        results = db.DB.find(trapt, where_clause)
    else:
        results = db.DB.find(trapt)

    result_dict = db.encode_storm_result_set(results)

    json_str = json.dumps(result_dict, default=db.encode_storm_result_set)
    return Response(response=json_str, status=200, mimetype='application/json')
Esempio n. 7
0
def delete(tablename):
    traptype = getattr(db, tablename)
    
    query = None
    id_list = [int(x) for x in request.args.getlist('id')]
    
    where_clause = db.sql_where_query(traptype, {'id__in': id_list})
    
    try:
        result = db.DB.find(traptype, where_clause)
        count = result.count()
        result.remove()
        json_str = {'success': 'Deleted %d traps.' % count}
    except Exception, e:
        json_str = {'error': 'Could not delete traps: %s' % str(e)}
Esempio n. 8
0
def read(tablename):
    traptype = getattr(db, tablename)

    trap_filters = filters.get_requested_filters()

    where_clause = db.sql_where_query(traptype, request.args, trap_filters)

    if where_clause:
        results = db.DB.find(traptype, where_clause)
    else:
        results = db.DB.find(traptype)

    result_dict = db.encode_storm_result_set(results)

    json_str = json.dumps(result_dict, default=db.encode_storm_result_set, indent=4)
    return Response(response=json_str, status=200, mimetype='application/json')
Esempio n. 9
0
def read(tablename):
    traptype = getattr(db, tablename)

    trap_filters = filters.get_requested_filters()

    where_clause = db.sql_where_query(traptype, request.args, trap_filters)

    if where_clause:
        results = db.DB.find(traptype, where_clause)
    else:
        results = db.DB.find(traptype)

    result_dict = db.encode_storm_result_set(results)

    json_str = json.dumps(result_dict,
                          default=db.encode_storm_result_set,
                          indent=4)
    return Response(response=json_str, status=200, mimetype='application/json')
Esempio n. 10
0
def read_filter_raw():
    filt = {}
    where_clause = db.sql_where_query(db.Filter, request.args)

    if where_clause:
        db_filters = db.DB.find(db.Filter, where_clause)
    else:
        db_filters = db.DB.find(db.Filter)

    for f in db_filters:
        j = {'id': f.id}
        action = []
        for atom in db.DB.find(db.FilterAtom, db.FilterAtom.filter_id == f.id):
            action.append({'column_name': atom.column_name,
                           'comparison': atom.comparison,
                           'value': atom.val})
        j['actions'] = action
        filt[f.name] = j
    return filt
Esempio n. 11
0
def read_filter_raw():
    filt = {}
    where_clause = db.sql_where_query(db.Filter, request.args)

    if where_clause:
        db_filters = db.DB.find(db.Filter, where_clause)
    else:
        db_filters = db.DB.find(db.Filter)

    for f in db_filters:
        j = {'id': f.id}
        action = []
        for atom in db.DB.find(db.FilterAtom, db.FilterAtom.filter_id == f.id):
            action.append({
                'column_name': atom.column_name,
                'comparison': atom.comparison,
                'value': atom.val
            })
        j['actions'] = action
        filt[f.name] = j
    return filt
Esempio n. 12
0
def read_filter():
    filters = {}
    json_result = {'filters': filters}
    where_clause = db.sql_where_query(db.Filter, request.args)

    if where_clause:
        db_filters = db.DB.find(db.Filter, where_clause)
    else:
        db_filters = db.DB.find(db.Filter)

    for f in db_filters:
        j = {'id': f.id}
        action = []
        for atom in db.DB.find(db.FilterAtom, db.FilterAtom.filter_id == f.id):
            action.append({'column_name': atom.column_name,
                           'comparison': atom.comparison,
                           'value': atom.val})
        j['actions'] = action
        filters[f.name] = j

    json_str = json.dumps(json_result)
    return Response(response=json_str, status=200, mimetype='application/json')
Esempio n. 13
0
def inspector_chart_debug(traptype):
    trapt = getattr(db, traptype)

    where_clause = db.sql_where_query(trapt, request.args)
    
    if where_clause:
        results = db.DB.find(trapt, where_clause)
    else:
        results = db.DB.find(trapt)
    
    start_date = request.args.get('start_date', 0)
    end_date = request.args.get('end_date', int(time.time()))

    try:
        start_date = datetime.datetime.fromtimestamp(int(start_date))
        end_date = datetime.datetime.fromtimestamp(int(end_date))
    except TypeError:
        start_date = datetime.datetime.fromtimestamp(0)
        end_date = datetime.datetime.now()

    results = inspector_results_aggregator(trapt, results, start_date, end_date) 
    json_str = json.dumps(results)
    return Response(response=json_str, status=200, mimetype='application/json')
Esempio n. 14
0
def read_filter():
    filters = {}
    json_result = {'filters': filters}
    where_clause = db.sql_where_query(db.Filter, request.args)

    if where_clause:
        db_filters = db.DB.find(db.Filter, where_clause)
    else:
        db_filters = db.DB.find(db.Filter)

    for f in db_filters:
        j = {'id': f.id}
        action = []
        for atom in db.DB.find(db.FilterAtom, db.FilterAtom.filter_id == f.id):
            action.append({
                'column_name': atom.column_name,
                'comparison': atom.comparison,
                'value': atom.val
            })
        j['actions'] = action
        filters[f.name] = j

    json_str = json.dumps(json_result)
    return Response(response=json_str, status=200, mimetype='application/json')
Esempio n. 15
0
def inspector_chart_debug(traptype):
    trapt = getattr(db, traptype)

    where_clause = db.sql_where_query(trapt, request.args)

    if where_clause:
        results = db.DB.find(trapt, where_clause)
    else:
        results = db.DB.find(trapt)

    start_date = request.args.get('start_date', 0)
    end_date = request.args.get('end_date', int(time.time()))

    try:
        start_date = datetime.datetime.fromtimestamp(int(start_date))
        end_date = datetime.datetime.fromtimestamp(int(end_date))
    except TypeError:
        start_date = datetime.datetime.fromtimestamp(0)
        end_date = datetime.datetime.now()

    results = inspector_results_aggregator(trapt, results, start_date,
                                           end_date)
    json_str = json.dumps(results)
    return Response(response=json_str, status=200, mimetype='application/json')