Exemplo n.º 1
0
            email1 = raw_input('Enter your email: ').strip()
            email2 = raw_input('Enter your email again: ').strip()
            if email1 != email2:
                raise ValueError('Emails must match')

            user_to_add = User(username, password1, email1, role='admin')
            DB.session.add(user_to_add)
            try:
                DB.session.commit()
            except Exception, err:
                DB.session.rollback()
                msg = str(err)
                print(msg)
        elif sys.argv[1] == 'drop':
            print('Dropping database objects')
            DB.drop_all()
        elif sys.argv[1] == 'run':
            print('Running health check tests')
            from healthcheck import run_test_resource
            for res in Resource.query.all():  # run all tests
                print('Testing %s %s' % (res.resource_type, res.url))
                run_to_add = run_test_resource(res.resource_type, res.url)
                run1 = Run(res, run_to_add[1], run_to_add[2], run_to_add[3],
                           run_to_add[4])
                print('Adding run')
                DB.session.add(run1)
            try:
                DB.session.commit()
            except Exception, err:
                DB.session.rollback()
                msg = str(err)
Exemplo n.º 2
0
            print('Creating superuser account')
            username = raw_input('Enter your username: '******'Enter your password: '******'Enter your password again: ').strip()
            if password1 != password2:
                raise ValueError('Passwords must match')
            email1 = raw_input('Enter your email: ').strip()
            email2 = raw_input('Enter your email again: ').strip()
            if email1 != email2:
                raise ValueError('Emails must match')

            user_to_add = User(username, password1, email1, role='admin')
            DB.session.add(user_to_add)
        elif sys.argv[1] == 'drop':
            print('Dropping database objects')
            DB.drop_all()
        elif sys.argv[1] == 'run':
            print('Running health check tests')
            from healthcheck import run_test_resource
            for res in Resource.query.all():  # run all tests
                print('Testing %s %s' % (res.resource_type, res.url))
                last_run_success = res.last_run.success
                run_to_add = run_test_resource(res.resource_type, res.url)

                run1 = Run(res, run_to_add[1], run_to_add[2],
                           run_to_add[3], run_to_add[4])

                print('Adding run')
                DB.session.add(run1)

                if APP.config['GHC_NOTIFICATIONS']:
Exemplo n.º 3
0
def load_data(file_path):
    # Beware!
    DB.drop_all()
    db_commit()

    # In particular for Postgres to drop connections
    DB.session.close()

    DB.create_all()

    with open(file_path) as ff:
        objects = json.load(ff)

    # add users, keeping track of DB objects
    users = {}
    for user_name in objects['users']:
        user = objects['users'][user_name]
        user = User(user['username'], user['password'], user['email'],
                    user['role'])
        users[user_name] = user
        DB.session.add(user)

    # add tags, keeping track of DB objects
    tags = {}
    for tag_str in objects['tags']:
        tag = objects['tags'][tag_str]

        tag = Tag(tag)
        tags[tag_str] = tag
        DB.session.add(tag)

    # add Resources, keeping track of DB objects
    resources = {}
    for resource_name in objects['resources']:
        resource = objects['resources'][resource_name]

        resource_tags = []
        for tag_str in resource['tags']:
            resource_tags.append(tags[tag_str])

        resource = Resource(users[resource['owner']],
                            resource['resource_type'], resource['title'],
                            resource['url'], resource_tags)

        resources[resource_name] = resource
        DB.session.add(resource)

    # add Probes, keeping track of DB objects
    probes = {}
    for probe_name in objects['probe_vars']:
        probe = objects['probe_vars'][probe_name]

        probe = ProbeVars(
            resources[probe['resource']],
            probe['probe_class'],
            probe['parameters'],
        )

        probes[probe_name] = probe
        DB.session.add(probe)

    # add Checks, keeping track of DB objects
    checks = {}
    for check_name in objects['check_vars']:
        check = objects['check_vars'][check_name]

        check = CheckVars(
            probes[check['probe_vars']],
            check['check_class'],
            check['parameters'],
        )

        checks[check_name] = check
        DB.session.add(check)

    db_commit()
    DB.session.close()