<commit_before>- name: Gather information about the load balancers.
  hosts: local
  connection: local
  gather_facts: false
  vars_files:
  - vars.yml
  tasks:

  - name: Inspect production load balancer
    rax_clb:
      credentials: ~/.rackspace_cloud_credentials
      region: "{{ lookup('env', 'RAX_REGION') | upper }}"
      name: prod_developer.rackspace.com
    register: clb_prod

  - name: Inspect staging load balancer
    rax_clb:
      credentials: ~/.rackspace_cloud_credentials
      region: "{{ lookup('env', 'RAX_REGION') | upper }}"
      name: staging.developer.rackspace.com
    register: clb_staging

- name: Configure Cloud Monitoring
  hosts: local
  connection: local
  gather_facts: false
  vars:
    load_balancers:
    - name: production
      ip_address: "{{ clb_prod['balancer']['virtual_ips'][0]['address'] }}"
    - name: staging
      ip_address: "{{ clb_staging['balancer']['virtual_ips'][0]['address'] }}"
  vars_files:
  - vars.yml
  - [ 'secrets.yml', 'secrets.prod.yml' ]
  tasks:

  - name: Use the monitored region as a label prefix.
    set_fact: prefix={{ lookup('env', 'RAX_REGION') | lower }}

  - name: Nuke all existing monitoring on this account
    command: ../script/rmmon

  - name: Create a monitoring entity for each load balancer
    rax_mon_entity:
      credentials: ~/.rackspace_cloud_credentials
      state: present
      name: "{{ prefix }}_entity_{{ item.name }}"
      named_ip_addresses:
        load_balancer: "{{ item.ip_address }}"
    with_items: load_balancers
    register: entities

  - name: Production entity.
    set_fact: production_entity_id={{ entities.results[0].entity.id }}

  - name: Staging entity.
    set_fact: staging_entity_id={{ entities.results[1].entity.id }}

  # Create checks.

  - name: Verify that port 80 is redirecting to 443
    rax_mon_check:
      credentials: ~/.rackspace_cloud_credentials
      state: present
      entity_id: "{{ item.entity.id }}"
      label: http_check_redirect
      check_type: remote.http
      details:
        url: http://{{ item.item.ip_address }}/
        method: GET
        follow_redirects: false
      monitoring_zones_poll: "{{ monitoring_zones }}"
      target_alias: load_balancer
    with_items: entities.results
    register: http_checks_redirect

  - name: Production redirection check.
    set_fact: production_http_check_redirect_id={{ http_checks_redirect.results[0].check.id }}

  - name: Staging redirection check.
    set_fact: staging_http_check_redirect_id={{ http_checks_redirect.results[1].check.id }}

  - name: Create checks on index.html
    rax_mon_check:
      credentials: ~/.rackspace_cloud_credentials
      state: present
      entity_id: "{{ item.entity.id }}"
      label: http_check_index
      check_type: remote.http
      details:
        url: https://{{ item.item.ip_address }}/
        body: <span class="boxtitle">SDKs &amp; Tools</span>
        include_body: "true"
        method: GET
        follow_redirects: "true"
      monitoring_zones_poll: "{{ monitoring_zones }}"
      target_alias: load_balancer
    with_items: entities.results
    register: http_checks_index

  - name: Production index.html content check.
    set_fact: production_http_check_index_id={{ http_checks_index.results[0].check.id }}

  - name: Staging index.html content check.
    set_fact: staging_http_check_index_id={{ http_checks_index.results[1].check.id }}

  - name: Create a check on the blog index page
    rax_mon_check:
      credentials: ~/.rackspace_cloud_credentials
      state: present
      entity_id: "{{ item.entity.id }}"
      label: http_check_blog
      check_type: remote.http
      details:
        url: https://{{ item.item.ip_address }}/blog/
        body: <span class="headline">Developer Blog</span>
        include_body: "true"
        method: GET
        follow_redirects: "true"
      monitoring_zones_poll: "{{ monitoring_zones }}"
      target_alias: load_balancer
    with_items: entities.results
    register: http_checks_blog

  - name: Production blog index content check.
    set_fact: production_http_check_blog_id={{ http_checks_blog.results[0].check.id }}

  - name: Staging blog index content check.
    set_fact: staging_http_check_blog_id={{ http_checks_blog.results[1].check.id }}

  - name: Create a check on the SDK index page
    rax_mon_check:
      credentials: ~/.rackspace_cloud_credentials
      state: present
      entity_id: "{{ item.entity.id }}"
      label: http_check_sdk
      check_type: remote.http
      details:
        url: https://{{ item.item.ip_address }}/sdks/
        body: <span class="headline">SDKs &amp; Tools</span>
        include_body: false
        method: GET
        follow_redirects: true
      monitoring_zones_poll: "{{ monitoring_zones }}"
      target_alias: load_balancer
    with_items: entities.results
    register: http_checks_sdk

  - name: Production SDK index content check.
    set_fact: production_http_check_sdk_id={{ http_checks_sdk.results[0].check.id }}

  - name: Staging SDK index content check.
    set_fact: staging_http_check_sdk_id={{ http_checks_sdk.results[1].check.id }}

  # PagerDuty notifications and notification plans.
  # Active when mon_email has not been provided.

  - name: PagerDuty notifications.
    rax_mon_notification:
      credentials: ~/.rackspace_cloud_credentials
      state: present
      label: "{{ item.label }}"
      notification_type: pagerduty
      details:
        service_key: "{{ item.key }}"
    with_items:
    - label: "{{ prefix }}_pd_notification_production"
      key: "{{ production_pagerduty_servicekey }}"
    - label: "{{ prefix }}_pd_notification_staging"
      key: "{{ staging_pagerduty_servicekey }}"
    register: pd_notifications
    when: mon_pagerduty

  - name: PagerDuty notification plans.
    rax_mon_notification_plan:
      credentials: ~/.rackspace_cloud_credentials
      state: present
      label: "{{ item.label }}"
      ok_state:
      - "{{ item.notification_id }}"
      warning_state:
      - "{{ item.notification_id }}"
      critical_state:
      - "{{ item.notification_id }}"
    with_items:
    - label: "{{ prefix }}_pd_plan_production"
      notification_id: "{{ pd_notifications.results[0].notification.id }}"
    - label: "{{ prefix }}_pd_plan_staging"
      notification_id: "{{ pd_notifications.results[1].notification.id }}"
    register: pd_plans
    when: mon_pagerduty

  - name: Set PagerDuty as the active notification plan for production.
    set_fact: production_plan_id={{ pd_plans.results[0].notification_plan.id }}
    when: mon_pagerduty

  - name: Set PagerDuty as the active notification plan for staging.
    set_fact: staging_plan_id={{ pd_plans.results[1].notification_plan.id }}
    when: mon_pagerduty

  # Email notifications and notification plans.
  # Active when mon_email has been provided.

  - name: Email notification.
    rax_mon_notification:
      credentials: ~/.rackspace_cloud_credentials
      state: present
      label: "{{ prefix }}_email_notification"
      notification_type: email
      details:
        address: "{{ mon_email }}"
    register: email_notification
    when: mon_email is defined

  - name: Create email notification plans.<commit_msg>mon_pagerduty is undefined, not false.<commit_after>- name: Gather information about the load balancers.
  hosts: local
  connection: local
  gather_facts: false
  vars_files:
  - vars.yml
  tasks:

  - name: Inspect production load balancer
    rax_clb:
      credentials: ~/.rackspace_cloud_credentials
      region: "{{ lookup('env', 'RAX_REGION') | upper }}"
      name: prod_developer.rackspace.com
    register: clb_prod

  - name: Inspect staging load balancer
    rax_clb:
      credentials: ~/.rackspace_cloud_credentials
      region: "{{ lookup('env', 'RAX_REGION') | upper }}"
      name: staging.developer.rackspace.com
    register: clb_staging

- name: Configure Cloud Monitoring
  hosts: local
  connection: local
  gather_facts: false
  vars:
    load_balancers:
    - name: production
      ip_address: "{{ clb_prod['balancer']['virtual_ips'][0]['address'] }}"
    - name: staging
      ip_address: "{{ clb_staging['balancer']['virtual_ips'][0]['address'] }}"
  vars_files:
  - vars.yml
  - [ 'secrets.yml', 'secrets.prod.yml' ]
  tasks:

  - name: Use the monitored region as a label prefix.
    set_fact: prefix={{ lookup('env', 'RAX_REGION') | lower }}

  - name: Nuke all existing monitoring on this account
    command: ../script/rmmon

  - name: Create a monitoring entity for each load balancer
    rax_mon_entity:
      credentials: ~/.rackspace_cloud_credentials
      state: present
      name: "{{ prefix }}_entity_{{ item.name }}"
      named_ip_addresses:
        load_balancer: "{{ item.ip_address }}"
    with_items: load_balancers
    register: entities

  - name: Production entity.
    set_fact: production_entity_id={{ entities.results[0].entity.id }}

  - name: Staging entity.
    set_fact: staging_entity_id={{ entities.results[1].entity.id }}

  # Create checks.

  - name: Verify that port 80 is redirecting to 443
    rax_mon_check:
      credentials: ~/.rackspace_cloud_credentials
      state: present
      entity_id: "{{ item.entity.id }}"
      label: http_check_redirect
      check_type: remote.http
      details:
        url: http://{{ item.item.ip_address }}/
        method: GET
        follow_redirects: false
      monitoring_zones_poll: "{{ monitoring_zones }}"
      target_alias: load_balancer
    with_items: entities.results
    register: http_checks_redirect

  - name: Production redirection check.
    set_fact: production_http_check_redirect_id={{ http_checks_redirect.results[0].check.id }}

  - name: Staging redirection check.
    set_fact: staging_http_check_redirect_id={{ http_checks_redirect.results[1].check.id }}

  - name: Create checks on index.html
    rax_mon_check:
      credentials: ~/.rackspace_cloud_credentials
      state: present
      entity_id: "{{ item.entity.id }}"
      label: http_check_index
      check_type: remote.http
      details:
        url: https://{{ item.item.ip_address }}/
        body: <span class="boxtitle">SDKs &amp; Tools</span>
        include_body: "true"
        method: GET
        follow_redirects: "true"
      monitoring_zones_poll: "{{ monitoring_zones }}"
      target_alias: load_balancer
    with_items: entities.results
    register: http_checks_index

  - name: Production index.html content check.
    set_fact: production_http_check_index_id={{ http_checks_index.results[0].check.id }}

  - name: Staging index.html content check.
    set_fact: staging_http_check_index_id={{ http_checks_index.results[1].check.id }}

  - name: Create a check on the blog index page
    rax_mon_check:
      credentials: ~/.rackspace_cloud_credentials
      state: present
      entity_id: "{{ item.entity.id }}"
      label: http_check_blog
      check_type: remote.http
      details:
        url: https://{{ item.item.ip_address }}/blog/
        body: <span class="headline">Developer Blog</span>
        include_body: "true"
        method: GET
        follow_redirects: "true"
      monitoring_zones_poll: "{{ monitoring_zones }}"
      target_alias: load_balancer
    with_items: entities.results
    register: http_checks_blog

  - name: Production blog index content check.
    set_fact: production_http_check_blog_id={{ http_checks_blog.results[0].check.id }}

  - name: Staging blog index content check.
    set_fact: staging_http_check_blog_id={{ http_checks_blog.results[1].check.id }}

  - name: Create a check on the SDK index page
    rax_mon_check:
      credentials: ~/.rackspace_cloud_credentials
      state: present
      entity_id: "{{ item.entity.id }}"
      label: http_check_sdk
      check_type: remote.http
      details:
        url: https://{{ item.item.ip_address }}/sdks/
        body: <span class="headline">SDKs &amp; Tools</span>
        include_body: false
        method: GET
        follow_redirects: true
      monitoring_zones_poll: "{{ monitoring_zones }}"
      target_alias: load_balancer
    with_items: entities.results
    register: http_checks_sdk

  - name: Production SDK index content check.
    set_fact: production_http_check_sdk_id={{ http_checks_sdk.results[0].check.id }}

  - name: Staging SDK index content check.
    set_fact: staging_http_check_sdk_id={{ http_checks_sdk.results[1].check.id }}

  # PagerDuty notifications and notification plans.
  # Active when mon_email has not been provided.

  - name: PagerDuty notifications.
    rax_mon_notification:
      credentials: ~/.rackspace_cloud_credentials
      state: present
      label: "{{ item.label }}"
      notification_type: pagerduty
      details:
        service_key: "{{ item.key }}"
    with_items:
    - label: "{{ prefix }}_pd_notification_production"
      key: "{{ production_pagerduty_servicekey }}"
    - label: "{{ prefix }}_pd_notification_staging"
      key: "{{ staging_pagerduty_servicekey }}"
    register: pd_notifications
    when: mon_pagerduty is defined

  - name: PagerDuty notification plans.
    rax_mon_notification_plan:
      credentials: ~/.rackspace_cloud_credentials
      state: present
      label: "{{ item.label }}"
      ok_state:
      - "{{ item.notification_id }}"
      warning_state:
      - "{{ item.notification_id }}"
      critical_state:
      - "{{ item.notification_id }}"
    with_items:
    - label: "{{ prefix }}_pd_plan_production"
      notification_id: "{{ pd_notifications.results[0].notification.id }}"
    - label: "{{ prefix }}_pd_plan_staging"
      notification_id: "{{ pd_notifications.results[1].notification.id }}"
    register: pd_plans
    when: mon_pagerduty is defined

  - name: Set PagerDuty as the active notification plan for production.
    set_fact: production_plan_id={{ pd_plans.results[0].notification_plan.id }}
    when: mon_pagerduty is defined

  - name: Set PagerDuty as the active notification plan for staging.
    set_fact: staging_plan_id={{ pd_plans.results[1].notification_plan.id }}
    when: mon_pagerduty is defined

  # Email notifications and notification plans.
  # Active when mon_email has been provided.

  - name: Email notification.
    rax_mon_notification:
      credentials: ~/.rackspace_cloud_credentials
      state: present
      label: "{{ prefix }}_email_notification"
      notification_type: email
      details:
        address: "{{ mon_email }}"
    register: email_notification
    when: mon_email is defined

  - name: Create email notification plans.
{'fraction_non_alphanumeric': 0.10664829486737858, 'fraction_numerical': 0.0028935583878746123, 'mean_word_length': 3.219767441860465, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6113413', 'n_tokens_mistral': 4620, 'n_tokens_neox': 4466, 'n_words': 1025}