-
-
Notifications
You must be signed in to change notification settings - Fork 64
feat: add uptime monitors with datadog synthetics #587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,2 @@ | ||
| datadog_api_key: deadbeefdeadbeefdeadbeefdeadbeefdeadbeef | ||
| datadog_app_key: deadbeefdeadbeefdeadbeefdeadbeefdeadbeef |
This file contains hidden or 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,76 @@ | ||
| {% set minion_id = grains['id'] %} | ||
| {% set fqdn = grains['fqdn'] %} | ||
| {% set api_key = pillar.get('datadog_api_key') %} | ||
| {% set app_key = pillar.get('datadog_app_key') %} | ||
| {% set datadog_locations = salt['http.query']('https://api.datadoghq.com/api/v1/synthetics/locations', header_list=['DD-API-KEY: ' + api_key, 'DD-APPLICATION-KEY: ' + app_key], decode=True) %} | ||
| {% set existing_monitors = salt['http.query']('https://api.datadoghq.com/api/v1/synthetics/tests', header_list=['DD-API-KEY: ' + api_key, 'DD-APPLICATION-KEY: ' + app_key], decode=True) %} | ||
| {% set monitor_name = minion_id + ' HTTP Health' %} | ||
| {% set monitor_exists = existing_monitors.get('dict', {}).get('tests', []) | selectattr('name', 'equalto', monitor_name) | list | length > 0 %} | ||
|
|
||
| #notable this fails to capture multi-host minions (bugs has bugs.python, bugs.jython, bugs.roundup and | ||
| # codespeed has speed.python and speed.pypy) | ||
JacobCoffee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {% set web_roles = ['loadbalancer', 'docs', 'downloads', 'hg', 'moin', 'planet', 'bugs', 'buildbot', 'codespeed', 'pythontest'] %} | ||
| {% set matched_roles = [] %} | ||
| {% for role in web_roles %} | ||
| {% if salt["match.compound"](pillar["roles"][role]["pattern"]) %} | ||
| {% set _ = matched_roles.append(role) %} | ||
| {% endif %} | ||
| {% endfor %} | ||
| {% set is_web_minion = matched_roles|length > 0 %} | ||
| {% set is_loadbalancer = 'loadbalancer' in matched_roles %} | ||
|
|
||
| # hit the haproxy status page for loadbalancers or the root for other web minions | ||
| # web minions also haev _haproxy_status endpoint but im not sure if that needs to be checked? | ||
| {% set health_url = "https://" + fqdn + ("/_haproxy_status" if is_loadbalancer else "/") %} | ||
|
|
||
| {% if is_web_minion and api_key and app_key and not monitor_exists %} | ||
| create-synthetics-monitor-{{ minion_id }}: | ||
| http.query: | ||
| - name: https://api.datadoghq.com/api/v1/synthetics/tests | ||
| - method: POST | ||
| - header_list: | ||
| - "DD-API-KEY: {{ api_key }}" | ||
| - "DD-APPLICATION-KEY: {{ app_key }}" | ||
| - "Content-Type: application/json" | ||
| - data: | | ||
| { | ||
| "name": "{{ minion_id }} HTTP Health", | ||
| "type": "api", | ||
| "subtype": "http", | ||
| "config": { | ||
| "request": { | ||
| "url": "{{ health_url }}", | ||
| "method": "GET", | ||
| "timeout": 30 | ||
| }, | ||
| "assertions": [ | ||
| { | ||
| "type": "statusCode", | ||
| "operator": "is", | ||
| "target": 200 | ||
| }, | ||
| { | ||
| "type": "responseTime", | ||
| "operator": "lessThan", | ||
| "target": 2000 | ||
| } | ||
| ] | ||
| }, | ||
| "locations": {{ datadog_locations.get('dict', {}).get('locations', []) | map(attribute='id') | list | tojson }}, | ||
| "options": { | ||
| "tick_every": 60, | ||
| "min_failure_duration": 180, | ||
| "min_location_failed": 5, | ||
| "retry": { | ||
| "count": 1, | ||
| "interval": 300 | ||
| } | ||
| }, | ||
| "message": "{{ minion_id }} is down in 5 or more locations! @pagerduty-Datadog", | ||
| "tags": [ | ||
| "minion_id:{{ minion_id }}", | ||
| "auto_created:salt.synthetics.sls" | ||
| ] | ||
| } | ||
| - status: 200 | ||
| {% endif %} | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ base: | |
| - tls | ||
| - rsyslog | ||
| - datadog | ||
| - datadog.synthetics | ||
| - secrets.datadog | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this the right place for this? it felt wrong but it needed them to be available |
||
| - base.motd | ||
| - base.swap | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.