ansible/ansible — pull request #7987 by smashwilson (2014-06-30 13:10:19+00:00)
Title: Rackspace Cloud Monitoring modules

This family of modules enables full management of a Rackspace Cloud Monitoring setup. Each module is idempotent, keying off of `label`: existing models will be updated with changed attributes if possible, or deleted and re-created otherwise.

Here's what a full playbook that configures monitoring for a site looks like:

```yaml
---
- name: Configure Cloud Monitoring
hosts: local
connection: local
gather_facts: false
vars:
monitoring_zones:
- mzdfw
- mziad
- mzord
tasks:

- name: Create a monitoring entity for the site to monitor.
rax_mon_entity:
credentials: ~/.rackspace_cloud_credentials
state: present
name: my_site
named_ip_addresses:
frontend: "{{ frontend_ip }}"
register: the_entity

- name: Fetch the frontpage.
rax_mon_check:
credentials: ~/.rackspace_cloud_credentials
state: present
entity_id: "{{ the_entity['entity']['id'] }}"
label: frontpage_check
check_type: remote.http
details:
url: http://{{ frontend_fqdn }}/
method: GET
monitoring_zones_poll: "{{ monitoring_zones }}"
target_alias: frontend
register: frontpage_check

- name: Email notification.
rax_mon_notification:
credentials: ~/.rackspace_cloud_credentials
state: present
label: who_ya_gonna_call
notification_type: email
details:
address: "{{ opsfloor_email }}"
register: email_notification

- name: Create a notification plan.
rax_mon_notification_plan:
credentials: ~/.rackspace_cloud_credentials
state: present
label: escalation_station
ok_state:
- "{{ email_notification['notification']['id'] }}"
warning_state:
- "{{ email_notification['notification']['id'] }}"
critical_state:
- "{{ email_notification['notification']['id'] }}"
register: escalation_station

- name: Trigger an alarm when the site errors out.
rax_mon_alarm:
credentials: ~/.rackspace_cloud_credentials
state: present
label: frontpage_alarm
entity_id: "{{ the_entity['entity']['id'] }}"
check_id: "{{ frontpage_check['check']['id'] }}"
notification_plan_id: "{{ escalation_station['notification_plan']['id'] }}"
criteria: >
if (metric['code'] != "200") {
return new AlarmStatus(CRITICAL, "Non-200 status code #{code} returned.");
}
if (metric['duration'] > 500) {
return new AlarmStatus(WARNING, "Page render took #{duration}ms > 500ms.");
}
return new AlarmStatus(OK);
```

/cc @sivel, @claco