Skip to content

Instantly share code, notes, and snippets.

@hostmaster
Last active August 29, 2015 14:04
Show Gist options
  • Save hostmaster/c230e6c3d6ea10a5daa1 to your computer and use it in GitHub Desktop.
Save hostmaster/c230e6c3d6ea10a5daa1 to your computer and use it in GitHub Desktop.
Schedule from ansible playbook a maintenance window in http://copperegg.com monitoring service.

Schedule and maintenance outage window in CopperEgg monitoring service.

Variables

copperegg_api_key is required. Your api key is at the bottom of your Settings page.

Usage example

pre_tasks:
  - include: mute.yml
    tags: [ 'copperegg' ]
    sudo: False

[....]

post_tasks:
  - include: unmute.yml
    tags: [ 'copperegg' ]
    sudo: False
---
copperegg_alert:
name: "Maintenance window for {{ inventory_hostname }}"
start_time: "{{ current_date_time }}"
duration: 60
state: "enabled"
match:
tag:
- "{{ deploy_env }}"
- "{{ inventory_hostname_short }}"
match_exclude: {}
recurring: false
---
# get start time
- name: Get *local* current date/time
local_action: command date -u +"%Y-%m-%dT%H:%M:%SZ"
register: current_date_time
sudo: False
changed_when: false
# vars/alert_template.yml
- include_vars: alert_template.yml
# schedule maintenance window and save id
- name: Schedule maintenance window in CopperEgg
local_action: command curl -su {{ copperegg_api_key }}:U
-H 'Content-Type{{':'}} application/json'
-XPOST -d '{{ copperegg_alert | to_json }}'
https://api.copperegg.com/v2/alerts/schedules.json
register: copperegg_api_response
failed_when: "'error' in copperegg_api_response.stdout"
changed_when: false
---
- name: Delete scheduled maintenance window in CopperEgg
local_action: command curl -su {{ copperegg_api_key }}:U -XDELETE
'https://api.copperegg.com/v2/alerts/schedules/{{ (copperegg_api_response.stdout|from_json).id }}.json'
when: copperegg_api_response is defined
and "'id' in copperegg_api_response.stdout"
changed_when: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment