-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NR-164383 feat: roles for HNR alerts
- Loading branch information
1 parent
d01b069
commit cd47169
Showing
8 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
caos.ansible_roles/roles/infrastructure_hnr_alert/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Create or Delete Infrastructure HNR alerts | ||
|
||
```yaml | ||
- name: Create HNR alerts | ||
include_role: | ||
name: caos.ansible_roles.infrastructure_hnr_alert | ||
vars: | ||
action: create | ||
entity_name: "{{ iid }}:{{ inventory_hostname }}" | ||
policy_name: "CAOS packaging tests HNR {{ inventory_hostname }}" | ||
``` | ||
```yaml | ||
- name: Delete HNR alerts | ||
include_role: | ||
name: caos.ansible_roles.infrastructure_hnr_alert | ||
vars: | ||
action: delete | ||
entity_name: "{{ iid }}:{{ inventory_hostname }}" | ||
policy_name: "CAOS packaging tests HNR {{ inventory_hostname }}" | ||
``` |
6 changes: 6 additions & 0 deletions
6
caos.ansible_roles/roles/infrastructure_hnr_alert/defaults/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
nr_api_key: "" | ||
action: "" # create | delete | ||
infra_alerts_host: "https://staging-infra-api.newrelic.com" | ||
alerts_host: "https://staging-api.newrelic.com" | ||
entity_name: "" # i.e. "{{ iid }}:{{ inventory_hostname }}" | ||
policy_name: "" # i.e. "CAOS packaging tests HNR {{ inventory_hostname }}" |
31 changes: 31 additions & 0 deletions
31
caos.ansible_roles/roles/infrastructure_hnr_alert/tasks/alert_create.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
|
||
- name: create host not reporting policy | ||
delegate_to: 127.0.0.1 | ||
uri: | ||
url: "{{ alerts_host }}/v2/alerts_policies.json" | ||
method: POST | ||
body: | ||
policy: | ||
incident_preference: "PER_POLICY" | ||
name: "{{ policy_name }}" | ||
status_code: 201 | ||
body_format: json | ||
headers: | ||
Api-Key: "{{ nr_api_key }}" | ||
register: response_policy | ||
no_log: true | ||
|
||
- name: create host not reporting condition | ||
delegate_to: 127.0.0.1 | ||
uri: | ||
url: "{{ infra_alerts_host }}/v2/alerts/conditions" | ||
method: POST | ||
body: "{\"data\":{\"type\":\"infra_host_not_reporting\",\"name\":\"CAOS packaging tests HNR {{ entity_name }}\",\"filter\":{\"and\":[{\"is\":{\"entityName\":\"{{ entity_name }}\"}}]},\"enabled\":true,\"violation_close_timer\": 24,\"policy_id\":{{ response_policy.json.policy.id }},\"critical_threshold\":{\"duration_minutes\":5,\"no_trigger_on\":[\"shutdown\"]}}}" | ||
status_code: 201 | ||
body_format: json | ||
headers: | ||
Api-Key: "{{ nr_api_key }}" | ||
no_log: true | ||
|
||
... |
34 changes: 34 additions & 0 deletions
34
caos.ansible_roles/roles/infrastructure_hnr_alert/tasks/alert_delete.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
|
||
- name: get host not reporting policyId | ||
delegate_to: 127.0.0.1 | ||
uri: | ||
url: "{{ alerts_host }}/v2/alerts_policies.json?{{ 'filter[name]=' | urlencode }}{{ policy_name | urlencode }}" | ||
method: GET | ||
return_content: yes | ||
status_code: 200 | ||
headers: | ||
Api-Key: "{{ nr_api_key }}" | ||
register: existing_response_policy | ||
no_log: true | ||
|
||
- name: fail if more than one policy found | ||
fail: | ||
msg: "more than one policy found" | ||
when: existing_response_policy.json.policies | length > 1 | ||
|
||
- name: delete host not reporting policy | ||
delegate_to: 127.0.0.1 | ||
uri: | ||
url: "{{ alerts_host }}/v2/alerts_policies/{{ existing_response_policy.json.policies[0].id }}" | ||
method: DELETE | ||
status_code: 200 | ||
headers: | ||
Api-Key: "{{ nr_api_key }}" | ||
Content-Type: application/json | ||
Accept: application/json | ||
register: existing_response_policy | ||
when: existing_response_policy.json.policies | length == 1 | ||
no_log: true | ||
|
||
... |
5 changes: 5 additions & 0 deletions
5
caos.ansible_roles/roles/infrastructure_hnr_alert/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
|
||
- ansible.builtin.include_tasks: alert_{{ action }}.yml | ||
|
||
... |
21 changes: 21 additions & 0 deletions
21
caos.ansible_roles/roles/infrastructure_hnr_alert_violation_assert/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Infrastructure HNR alert violation assert | ||
|
||
```yaml | ||
- name: assert violation is opened | ||
include_role: | ||
name: caos.ansible_roles.infrastructure_hnr_alert_violation_assert | ||
vars: | ||
violation_open: true | ||
entity_name: "{{ iid }}:{{ inventory_hostname }}" | ||
policy_name: "CAOS packaging tests HNR {{ inventory_hostname }}" | ||
|
||
|
||
- name: assert violation is closed | ||
include_role: | ||
name: caos.ansible_roles.infrastructure_hnr_alert_violation_assert | ||
vars: | ||
violation_open: false | ||
entity_name: "{{ iid }}:{{ inventory_hostname }}" | ||
policy_name: "CAOS packaging tests HNR {{ inventory_hostname }}" | ||
``` | ||
5 changes: 5 additions & 0 deletions
5
caos.ansible_roles/roles/infrastructure_hnr_alert_violation_assert/defaults/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
nr_api_key: "" | ||
infra_alerts_host: "https://staging-infra-api.newrelic.com" | ||
alerts_host: "https://staging-api.newrelic.com" | ||
entity_name: "" # i.e. "{{ iid }}:{{ inventory_hostname }}" | ||
policy_name: "" # i.e. "CAOS packaging tests HNR {{ inventory_hostname }}" |
29 changes: 29 additions & 0 deletions
29
caos.ansible_roles/roles/infrastructure_hnr_alert_violation_assert/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
|
||
- name: list violations | ||
delegate_to: 127.0.0.1 | ||
uri: | ||
url: "{{ alerts_host }}/v2/alerts_violations.json?only_open=true" | ||
method: GET | ||
status_code: 200 | ||
headers: | ||
Api-Key: "{{ nr_api_key }}" | ||
register: existing_violations | ||
no_log: true | ||
|
||
- name: assert violation exists | ||
vars: | ||
violating_entities_query: "[?policy_name=='{{ policy_name }}'].entity.name" | ||
assert: | ||
that: "'{{entity_name}}' in existing_violations.json.violations | json_query(violating_entities_query) | flatten" | ||
when: violation_open | ||
|
||
- name: assert violation does not exists | ||
vars: | ||
violating_entities_query: "[?policy_name=='{{ policy_name }}'].entity.name" | ||
assert: | ||
that: "'{{entity_name}}' not in existing_violations.json.violations | json_query(violating_entities_query) | flatten" | ||
when: not violation_open | ||
|
||
... | ||
|