コード例 #1
0
def main():
    argspec = sensu_argument_spec()
    argspec.update(
        dict(
            name=dict(),
            entity=dict(),
        )
    )

    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=argspec,
        required_by={'name': ['entity']},
    )

    client = AnsibleSensuClient(module)

    if module.params['name']:
        result = [client.get('/events/{0}/{1}'.format(module.params['entity'], module.params['name']))]
    elif module.params['entity']:
        result = client.get('/events/{0}'.format(module.params['entity']))
    else:
        result = client.get('/events')

    module.exit_json(changed=False, events=result)
コード例 #2
0
def main():
    argspec = sensu_argument_spec()
    argspec.update(dict(enabled=dict(
        type='bool',
        default=False,
    ), ))

    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=argspec,
    )

    client = AnsibleSensuClient(module)
    client.namespace = None

    result = client.get('/tessen')

    changed = False
    if result['opt_out'] == module.params['enabled']:
        changed = True
        if not module.check_mode:
            payload = {
                'opt_out': not module.params['enabled'],
            }
            client.put('/tessen', payload)

    module.exit_json(changed=changed)
コード例 #3
0
def main():
    argspec = sensu_argument_spec()
    argspec.update(
        dict(
            name=dict(),
            cluster=dict(type='bool', default=False),
        ))

    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=argspec,
    )

    endpoint = '/rolebindings'
    client = AnsibleSensuClient(module)
    if module.params['cluster']:
        client.namespace = None
        endpoint = '/clusterrolebindings'

    if module.params['name']:
        result = [
            client.get('{0}/{1}'.format(endpoint, module.params['name']))
        ]
    else:
        result = client.get(endpoint)

    module.exit_json(changed=False, rolebindings=result)
コード例 #4
0
def main():
    argspec = sensu_argument_spec()
    argspec.update(dict(
        name=dict(),
        subscription=dict(),
        check=dict(),
    ))

    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=argspec,
        mutually_exclusive=[['name', 'subscription', 'check']],
    )

    client = AnsibleSensuClient(module)

    if module.params['subscription']:
        result = client.get('/silenced/subscriptions/{0}'.format(
            module.params['subscription']))
    elif module.params['check']:
        result = client.get('/silenced/checks/{0}'.format(
            module.params['check']))
    elif module.params['name']:
        result = [client.get('/silenced/{0}'.format(module.params['name']))]
    else:
        result = client.get('/silenced')

    module.exit_json(changed=False, silenced=result)
コード例 #5
0
def main():
    argspec = sensu_argument_spec()
    argspec.update(dict(
        name=dict(required=True),
        state=dict(
            default='present',
            choices=['present', 'absent'],
        ),
        cluster=dict(
            type='bool',
            default=False,
        ),
        rules=dict(
            type='list',
            elements='dict',
            default=[],
        ),
    ))

    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=argspec,
        required_if=[('state', 'present', ['rules'])],
    )

    role = SensuRole(module)
    result = role.reconcile()
    module.exit_json(changed=result['changed'], role=result['object'])
コード例 #6
0
def main():
    argspec = sensu_argument_spec()

    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=argspec,
    )

    client = AnsibleSensuClient(module)
    client.namespace = None

    result = client.get('/cluster/members')

    module.exit_json(changed=False, cluster=result)
コード例 #7
0
def main():
    argspec = sensu_argument_spec()

    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=argspec,
    )

    client = AnsibleSensuClient(module)
    client.namespace = None

    result = client.get('/namespaces')
    result = [x['name'] for x in result]

    module.exit_json(changed=False, namespaces=result)
コード例 #8
0
def main():
    argspec = sensu_argument_spec()
    argspec.update(dict(name=dict(), ))

    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=argspec,
    )

    client = AnsibleSensuClient(module)

    if module.params['name']:
        result = [client.get('/hooks/{0}'.format(module.params['name']))]
    else:
        result = client.get('/hooks')

    module.exit_json(changed=False, hooks=result)
コード例 #9
0
def main():
    argspec = sensu_argument_spec()

    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=argspec,
    )

    url = module.params['url'].rstrip('/')

    backend = {}
    for endpoint in 'health', 'version':
        try:
            result = open_url('{0}/{1}'.format(url, endpoint))
        except (HTTPError, URLError) as e:
            module.fail_json(
                msg='get failed: {0} {1}'.format(e.reason, e.read()))

        backend[endpoint] = camel_dict_to_snake_dict(json.loads(result.read()))

    module.exit_json(changed=False, backend=backend)
コード例 #10
0
def main():
    argspec = sensu_argument_spec()
    argspec.update(
        dict(
            state=dict(
                choices=['present', 'absent'],
                default='present',
            ),
            namespace=dict(
                aliases=['name'],
                required=True,
            ),
        ))

    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=argspec,
    )

    client = AnsibleSensuClient(module)
    client.namespace = None

    result = client.get('/namespaces')

    for ns in result:
        if ns['name'] == module.params['name']:
            if module.params['state'] == 'present':
                module.exit_json(changed=False)
            if not module.check_mode:
                client.delete('/namespaces/{0}'.format(module.params['name']))
            module.exit_json(changed=True)

    if module.params['state'] == 'absent':
        module.exit_json(changed=False)

    if not module.check_mode:
        payload = {'name': module.params['name']}
        client.put('/namespaces/{0}'.format(module.params['name']), payload)

    module.exit_json(changed=True)