Ejemplo n.º 1
0
def fake_scans():
    from models.audit import ScanLog
    from internal.server import get_server_by_hostname

    server = get_server_by_hostname('vinz-ubuntu-12-04.student.iastate.edu')

    now = datetime.datetime.now()
    for day_index in xrange(7):
        day_delta = now - datetime.timedelta(days=day_index)

        print "working on %s days ago" % day_index

        number_of_servers = 814
        if day_index > 4:
            number_of_servers = 598

        print number_of_servers
        for log_index in xrange(number_of_servers):

            log = ScanLog(
                server=server,
                server_status=0,
                timestamp=day_delta,
                status=0,
                users_expected=[],
                actual_users=[],
                unexpected_users=[],
                keys_added=[],
                keys_removed=[],
                unexpected_keys=[],
            )

            log.save()
Ejemplo n.º 2
0
def create_scan_log(server,
                    server_status,
                    users_expected=None,
                    actual_users=None,
                    unexpected_users=None,
                    keys_added=None,
                    keys_removed=None,
                    unexpected_keys=None):
    now = datetime.datetime.now()

    if not users_expected:
        users_expected = []

    if not actual_users:
        actual_users = []

    if not unexpected_users:
        unexpected_users = []

    if not keys_added:
        keys_added = []

    if not keys_removed:
        keys_removed = []

    if not unexpected_keys:
        unexpected_keys = []

    actual_users_set = set(actual_users)
    users_expected_set = set(users_expected)

    if unexpected_users:
        status = SCAN_LOG_STATUS.EXCEPTION
    elif users_expected_set.difference(actual_users_set):
        status = SCAN_LOG_STATUS.USERS_ALTERED
    else:
        status = SCAN_LOG_STATUS.NO_CHANGE

    log = ScanLog(
        server=server,
        server_status=server_status,
        timestamp=now,
        status=status,
        users_expected=list(users_expected),
        actual_users=list(actual_users),
        unexpected_users=list(unexpected_users),
        keys_added=list(keys_added),
        keys_removed=list(keys_removed),
        unexpected_keys=list(unexpected_keys),
    )
    log.save()
    return log