diff --git a/datadog/cassettes/TestAccDatadogMonitorDatasource.yaml b/datadog/cassettes/TestAccDatadogMonitorDatasource.yaml new file mode 100644 index 000000000..5117af3ee --- /dev/null +++ b/datadog/cassettes/TestAccDatadogMonitorDatasource.yaml @@ -0,0 +1,1438 @@ +--- +version: 1 +interactions: +- request: + body: | + {"message":"some message Notify: @hipchat-channel","name":"monitor for datasource test","options":{"escalation_message":"the situation has escalated @pagerduty","evaluation_delay":700,"include_tags":true,"new_host_delay":600,"notify_no_data":false,"renotify_interval":60,"require_full_window":true,"thresholds":{"critical":2,"critical_recovery":1.5,"warning":1,"warning_recovery":0.5},"timeout_h":60},"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} by {host} \u003e 2","tags":["baz","test_datasource_monitor:foo"],"type":"query alert"} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + Dd-Operation-Id: + - CreateMonitor + User-Agent: + - datadog-api-client-go/1.0.0-beta.6 (go go1.14.1; os darwin; arch amd64) + url: https://api.datadoghq.com/api/v1/monitor + method: POST + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:49 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:49 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - e8t0cvW5uVKXk1zUsTcAcDpqv28dgy+lCs/R2sCfbKW6stomFiq2a4ijzxRdPBn5 + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "500" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "499" + X-Ratelimit-Reset: + - "1" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Dd-Operation-Id: + - GetMonitor + User-Agent: + - datadog-api-client-go/1.0.0-beta.6 (go go1.14.1; os darwin; arch amd64) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:49 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:49 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - xNK8D8E4U1PyLMVOdDgzcc4izX6UzMbP9Ygv1jJl/dgpKsJQ0NHsqPPadJ+IsqEV + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2999" + X-Ratelimit-Reset: + - "1" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Dd-Operation-Id: + - ListMonitors + User-Agent: + - datadog-api-client-go/1.0.0-beta.6 (go go1.14.1; os darwin; arch amd64) + url: https://api.datadoghq.com/api/v1/monitor?name=monitor+for+datasource+test + method: GET + response: + body: '[{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","matching_downtimes":[{"end":null,"monitor_id":null,"start":1594155777,"groups":[],"active":true,"scope":["*"],"id":884380028},{"end":null,"monitor_id":null,"start":1594155778,"groups":[],"active":true,"scope":["*"],"id":884380035},{"end":null,"monitor_id":null,"start":1594155778,"groups":[],"active":true,"scope":["*"],"id":884380042},{"end":null,"monitor_id":null,"start":1594156034,"groups":[],"active":true,"scope":["*"],"id":884383075}],"id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}]' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json + Date: + - Thu, 09 Jul 2020 15:22:50 GMT + Dd-Pool: + - dogweb + Etag: + - W/"2ebfaf1f802947083441663893b742f7" + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:49 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - cYNsy3QDuOaYo2clO/PharSNtCykS9KtUfiNevH3xDbHJlRyddWkNpuDhMgHWZ43 + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "1000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "999" + X-Ratelimit-Reset: + - "1" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - Datadog/dev/terraform (go1.14.1) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:50 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:50 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - gH++OYwf8a2QZXnzDsHHnXqPhHbI48oqNvFjE/0p0ObpMBY4290QCI5SB0tU0MAF + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2999" + X-Ratelimit-Reset: + - "10" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - Datadog/dev/terraform (go1.14.1) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:50 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:50 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - YKF8+1vTI0wiWlB3VWhiMVnZ1RLtV3h2yAW6/TGe9qIMWdYXxsNpy3J4QxfrJoDD + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2998" + X-Ratelimit-Reset: + - "10" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Dd-Operation-Id: + - GetMonitor + User-Agent: + - datadog-api-client-go/1.0.0-beta.6 (go go1.14.1; os darwin; arch amd64) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:50 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:50 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - sAPKocoLMDEnM5qY2PL6SCQ+dkENYAR/6IistAQ5iiTU/UnJHAba158nxOvVRvKJ + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2997" + X-Ratelimit-Reset: + - "10" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Dd-Operation-Id: + - GetMonitor + User-Agent: + - datadog-api-client-go/1.0.0-beta.6 (go go1.14.1; os darwin; arch amd64) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:50 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:50 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - AVsav2jjRGvwjNvJeRUS7kJsgTlhh9y9smyL3UJVQTMAUoPyejdL0bVSnanIQLK4 + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2996" + X-Ratelimit-Reset: + - "10" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Dd-Operation-Id: + - GetMonitor + User-Agent: + - datadog-api-client-go/1.0.0-beta.6 (go go1.14.1; os darwin; arch amd64) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:50 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:50 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - HIunaScoW4AWw8tnSbk8zc5V6c9XLV6++/KbgzaC4HIb212+evjUYL1yRLeLtS2T + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2995" + X-Ratelimit-Reset: + - "10" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Dd-Operation-Id: + - GetMonitor + User-Agent: + - datadog-api-client-go/1.0.0-beta.6 (go go1.14.1; os darwin; arch amd64) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:51 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:50 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - +0e88dcOoH2a7qrZ5zz4PnubdrAKvSl+k8YKr4bhBQyArPBFiYg3oXWqeVKLPB1I + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2994" + X-Ratelimit-Reset: + - "10" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Dd-Operation-Id: + - ListMonitors + User-Agent: + - datadog-api-client-go/1.0.0-beta.6 (go go1.14.1; os darwin; arch amd64) + url: https://api.datadoghq.com/api/v1/monitor?tags=test_datasource_monitor_scope%3Afoo + method: GET + response: + body: '[{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","matching_downtimes":[{"end":null,"monitor_id":null,"start":1594155777,"groups":[],"active":true,"scope":["*"],"id":884380028},{"end":null,"monitor_id":null,"start":1594155778,"groups":[],"active":true,"scope":["*"],"id":884380035},{"end":null,"monitor_id":null,"start":1594155778,"groups":[],"active":true,"scope":["*"],"id":884380042},{"end":null,"monitor_id":null,"start":1594156034,"groups":[],"active":true,"scope":["*"],"id":884383075}],"id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}]' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json + Date: + - Thu, 09 Jul 2020 15:22:51 GMT + Dd-Pool: + - dogweb + Etag: + - W/"2ebfaf1f802947083441663893b742f7" + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:51 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - o1rjyOSbDnvYaQgtO33vwWSNsIwHafzLqam2amG/PbTP69SVY965ZpWutdoYJB30 + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "1000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "999" + X-Ratelimit-Reset: + - "9" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - Datadog/dev/terraform (go1.14.1) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:51 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:51 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - UmZMvwWLI5lgbGFBnw6J7jqO5hwyrvVF8Un8TwZ8TRQQ6jetE/6GVTSaoSUmQWRg + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2993" + X-Ratelimit-Reset: + - "9" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - Datadog/dev/terraform (go1.14.1) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:51 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:51 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - tp1qdVxoUmtlsVp6hgBWraWfL5vEbA116VZkaWKWIZtgPr5Ima8zysCBv+o2WoZ/ + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2992" + X-Ratelimit-Reset: + - "9" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Dd-Operation-Id: + - GetMonitor + User-Agent: + - datadog-api-client-go/1.0.0-beta.6 (go go1.14.1; os darwin; arch amd64) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:51 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:51 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - UlUHD7I7ISIp2OTIKJ1HGCksOU1snpAx2HtkPJw2SYzWMPmqzICEuimWl9Uiyokg + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2991" + X-Ratelimit-Reset: + - "9" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Dd-Operation-Id: + - GetMonitor + User-Agent: + - datadog-api-client-go/1.0.0-beta.6 (go go1.14.1; os darwin; arch amd64) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:52 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:52 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - 4HTfT92VNwJOKM3+9Fghpi7RnKwXOMM9XiE8bZkwhVPDb5jbW4knJKZPCpE1XUb8 + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2990" + X-Ratelimit-Reset: + - "8" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Dd-Operation-Id: + - GetMonitor + User-Agent: + - datadog-api-client-go/1.0.0-beta.6 (go go1.14.1; os darwin; arch amd64) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:52 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:52 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - IRAJ1mQ+c3epm0CLGtZoe/y8O4TCss3jYw+fwQOm7+eSKRCE+p3OtawVnIQ5ts76 + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2989" + X-Ratelimit-Reset: + - "8" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Dd-Operation-Id: + - GetMonitor + User-Agent: + - datadog-api-client-go/1.0.0-beta.6 (go go1.14.1; os darwin; arch amd64) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:52 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:52 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - i90G6k4M6qI4UypyvMoczcO5m+jatiEQSMeHpdjycp0h4nWxRpKUHr6efynkbQs+ + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2988" + X-Ratelimit-Reset: + - "8" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Dd-Operation-Id: + - ListMonitors + User-Agent: + - datadog-api-client-go/1.0.0-beta.6 (go go1.14.1; os darwin; arch amd64) + url: https://api.datadoghq.com/api/v1/monitor?monitor_tags=test_datasource_monitor%3Afoo + method: GET + response: + body: '[{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","matching_downtimes":[{"end":null,"monitor_id":null,"start":1594155777,"groups":[],"active":true,"scope":["*"],"id":884380028},{"end":null,"monitor_id":null,"start":1594155778,"groups":[],"active":true,"scope":["*"],"id":884380035},{"end":null,"monitor_id":null,"start":1594155778,"groups":[],"active":true,"scope":["*"],"id":884380042},{"end":null,"monitor_id":null,"start":1594156034,"groups":[],"active":true,"scope":["*"],"id":884383075}],"id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}]' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json + Date: + - Thu, 09 Jul 2020 15:22:52 GMT + Dd-Pool: + - dogweb + Etag: + - W/"2ebfaf1f802947083441663893b742f7" + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:52 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - 7vC9CD2UnUYbC7cu05B95RgDyGt2vcRq8GQJgBahx4BAPKzA8OvLqEF8NdaLccla + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "1000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "998" + X-Ratelimit-Reset: + - "8" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - Datadog/dev/terraform (go1.14.1) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:52 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:52 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - IRAJ1mQ+c3epm0CLGtZoe/y8O4TCss3jYw+fwQOm7+eSKRCE+p3OtawVnIQ5ts76 + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2987" + X-Ratelimit-Reset: + - "8" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - Datadog/dev/terraform (go1.14.1) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:52 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:52 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - RL7BSOiWXeq2P2iJbmiDo/2BPpcpoCDzQceVuBkp6yO348trcqTrfm/pm8rvZRoT + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2986" + X-Ratelimit-Reset: + - "8" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Dd-Operation-Id: + - GetMonitor + User-Agent: + - datadog-api-client-go/1.0.0-beta.6 (go go1.14.1; os darwin; arch amd64) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:53 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:53 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - GAK1J4mJd/EBZfEK4rqUw9OeB9GOeKgSyrXGtzNUi5zrv5sHYU56xJgA4bcbtgUA + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2985" + X-Ratelimit-Reset: + - "7" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Dd-Operation-Id: + - GetMonitor + User-Agent: + - datadog-api-client-go/1.0.0-beta.6 (go go1.14.1; os darwin; arch amd64) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:53 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:53 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - btzHvL7Rg/f/n1wMP2CFVXsuErrwOO9p2hvsBofLQbxzRkmZbfvXcB18pURNtIOI + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2984" + X-Ratelimit-Reset: + - "7" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Dd-Operation-Id: + - GetMonitor + User-Agent: + - datadog-api-client-go/1.0.0-beta.6 (go go1.14.1; os darwin; arch amd64) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:53 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:53 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - DNJM9d0LaQZJbuEjasKEmgCwDoiLnJW9mPQJm+yWIlQRbFhX4Vzx4uuDCt38dWhb + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2983" + X-Ratelimit-Reset: + - "7" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Dd-Operation-Id: + - GetMonitor + User-Agent: + - datadog-api-client-go/1.0.0-beta.6 (go go1.14.1; os darwin; arch amd64) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"restricted_roles":null,"tags":["baz","test_datasource_monitor:foo"],"deleted":null,"query":"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} + by {host} > 2","message":"some message Notify: @hipchat-channel","id":20050771,"multi":true,"name":"monitor + for datasource test","created":"2020-07-09T15:22:49.680147+00:00","created_at":1594308169000,"creator":{"id":1445416,"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"org_id":321813,"modified":"2020-07-09T15:22:49.680147+00:00","overall_state_modified":null,"overall_state":"No + Data","type":"query alert","options":{"notify_audit":false,"locked":false,"timeout_h":60,"silenced":{},"include_tags":true,"thresholds":{"critical":2.0,"warning":1.0,"warning_recovery":0.5,"critical_recovery":1.5},"new_host_delay":600,"require_full_window":true,"notify_no_data":false,"renotify_interval":60,"evaluation_delay":700,"escalation_message":"the + situation has escalated @pagerduty"}}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:53 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:53 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - 2VXDwI2pcuhRZeQ6xt/fJh1koMYSfGcgQg5wAzgLqeh10Zf5/W946U7T5w6SEIhy + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2982" + X-Ratelimit-Reset: + - "7" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Dd-Operation-Id: + - DeleteMonitor + User-Agent: + - datadog-api-client-go/1.0.0-beta.6 (go go1.14.1; os darwin; arch amd64) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: DELETE + response: + body: '{"deleted_monitor_id":20050771}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 09 Jul 2020 15:22:53 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Set-Cookie: + - DD-PSHARD=233; Max-Age=604800; Path=/; expires=Thu, 16-Jul-2020 15:22:53 GMT; + secure; HttpOnly + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Debug: + - Xj/PwLDKe3Ll1QwGP2SdQuyUcOtG0YD60hQDJ9tPEhK9OEMHkSCPXdZRvPX0YYGO + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - Datadog/dev/terraform (go1.14.1) + url: https://api.datadoghq.com/api/v1/monitor/20050771 + method: GET + response: + body: '{"errors":["Monitor not found"]}' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report + Content-Type: + - application/json + Date: + - Thu, 09 Jul 2020 15:22:54 GMT + Dd-Pool: + - dogweb + Pragma: + - no-cache + Strict-Transport-Security: + - max-age=15724800; + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Dd-Version: + - "35.2720045" + X-Frame-Options: + - SAMEORIGIN + X-Ratelimit-Limit: + - "3000" + X-Ratelimit-Period: + - "10" + X-Ratelimit-Remaining: + - "2981" + X-Ratelimit-Reset: + - "7" + status: 404 Not Found + code: 404 + duration: "" diff --git a/datadog/data_source_datadog_monitor.go b/datadog/data_source_datadog_monitor.go new file mode 100644 index 000000000..89e95c42d --- /dev/null +++ b/datadog/data_source_datadog_monitor.go @@ -0,0 +1,268 @@ +package datadog + +import ( + "fmt" + "sort" + "strconv" + "strings" + + datadogV1 "github.com/DataDog/datadog-api-client-go/api/v1/datadog" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func dataSourceDatadogMonitor() *schema.Resource { + return &schema.Resource{ + Read: dataSourceDatadogMonitorsRead, + + Schema: map[string]*schema.Schema{ + "name_filter": { + Type: schema.TypeString, + Optional: true, + }, + "tags_filter": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "monitor_tags_filter": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + + // Computed values + "name": { + Type: schema.TypeString, + Computed: true, + }, + "message": { + Type: schema.TypeString, + Computed: true, + }, + "escalation_message": { + Type: schema.TypeString, + Computed: true, + }, + "query": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + + // Options + "thresholds": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ok": { + Type: schema.TypeFloat, + Computed: true, + }, + "warning": { + Type: schema.TypeFloat, + Computed: true, + }, + "critical": { + Type: schema.TypeFloat, + Computed: true, + }, + "unknown": { + Type: schema.TypeFloat, + Computed: true, + }, + "warning_recovery": { + Type: schema.TypeFloat, + Computed: true, + }, + "critical_recovery": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + "threshold_windows": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "recovery_window": { + Type: schema.TypeString, + Computed: true, + }, + "trigger_window": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "notify_no_data": { + Type: schema.TypeBool, + Computed: true, + }, + "new_host_delay": { + Type: schema.TypeInt, + Computed: true, + }, + "evaluation_delay": { + Type: schema.TypeInt, + Computed: true, + }, + "no_data_timeframe": { + Type: schema.TypeInt, + Computed: true, + }, + "renotify_interval": { + Type: schema.TypeInt, + Computed: true, + }, + "notify_audit": { + Type: schema.TypeBool, + Computed: true, + }, + "timeout_h": { + Type: schema.TypeInt, + Computed: true, + }, + "require_full_window": { + Type: schema.TypeBool, + Computed: true, + }, + "locked": { + Type: schema.TypeBool, + Computed: true, + }, + "include_tags": { + Type: schema.TypeBool, + Computed: true, + }, + "tags": { + // we use TypeSet to represent tags, paradoxically to be able to maintain them ordered; + // we order them explicitly in the read/create/update methods of this resource and using + // TypeSet makes Terraform ignore differences in order when creating a plan + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "enable_logs_sample": { + Type: schema.TypeBool, + Computed: true, + }, + "force_delete": { + Type: schema.TypeBool, + Computed: true, + }, + }, + } +} + +func dataSourceDatadogMonitorsRead(d *schema.ResourceData, meta interface{}) error { + providerConf := meta.(*ProviderConfiguration) + datadogClientV1 := providerConf.DatadogClientV1 + authV1 := providerConf.AuthV1 + + req := datadogClientV1.MonitorsApi.ListMonitors(authV1) + if v, ok := d.GetOk("name_filter"); ok { + req = req.Name(v.(string)) + } + if v, ok := d.GetOk("tags_filter"); ok { + req = req.Tags(strings.Join(expandStringList(v.([]interface{})), ",")) + } + if v, ok := d.GetOk("monitor_tags_filter"); ok { + req = req.MonitorTags(strings.Join(expandStringList(v.([]interface{})), ",")) + } + + monitors, _, err := req.Execute() + if err != nil { + return translateClientError(err, "error querying monitors") + } + if len(monitors) > 1 { + return fmt.Errorf("your query returned more than one result, please try a more specific search criteria") + } + if len(monitors) == 0 { + return fmt.Errorf("your query returned no result, please try a less specific search criteria") + } + + m := monitors[0] + + thresholds := make(map[string]string) + + if v, ok := m.Options.Thresholds.GetOkOk(); ok { + thresholds["ok"] = fmt.Sprintf("%v", *v) + } + if v, ok := m.Options.Thresholds.GetWarningOk(); ok { + thresholds["warning"] = fmt.Sprintf("%v", *v) + } + if v, ok := m.Options.Thresholds.GetCriticalOk(); ok { + thresholds["critical"] = fmt.Sprintf("%v", *v) + } + if v, ok := m.Options.Thresholds.GetUnknownOk(); ok { + thresholds["unknown"] = fmt.Sprintf("%v", *v) + } + if v, ok := m.Options.Thresholds.GetWarningRecoveryOk(); ok { + thresholds["warning_recovery"] = fmt.Sprintf("%v", *v) + } + if v, ok := m.Options.Thresholds.GetCriticalRecoveryOk(); ok { + thresholds["critical_recovery"] = fmt.Sprintf("%v", *v) + } + + thresholdWindows := make(map[string]string) + for k, v := range map[string]string{ + "recovery_window": m.Options.ThresholdWindows.GetRecoveryWindow(), + "trigger_window": m.Options.ThresholdWindows.GetTriggerWindow(), + } { + if v != "" { + thresholdWindows[k] = v + } + } + + var tags []string + for _, s := range m.GetTags() { + tags = append(tags, s) + } + sort.Strings(tags) + + d.SetId(strconv.FormatInt(m.GetId(), 10)) + d.Set("name", m.GetName()) + d.Set("message", m.GetMessage()) + d.Set("query", m.GetQuery()) + d.Set("type", m.GetType()) + + d.Set("thresholds", thresholds) + d.Set("threshold_windows", thresholdWindows) + + d.Set("new_host_delay", m.Options.GetNewHostDelay()) + d.Set("evaluation_delay", m.Options.GetEvaluationDelay()) + d.Set("notify_no_data", m.Options.GetNotifyNoData()) + d.Set("no_data_timeframe", m.Options.NoDataTimeframe) + d.Set("renotify_interval", m.Options.GetRenotifyInterval()) + d.Set("notify_audit", m.Options.GetNotifyAudit()) + d.Set("timeout_h", m.Options.GetTimeoutH()) + d.Set("escalation_message", m.Options.GetEscalationMessage()) + d.Set("include_tags", m.Options.GetIncludeTags()) + d.Set("tags", tags) + d.Set("require_full_window", m.Options.GetRequireFullWindow()) // TODO Is this one of those options that we neeed to check? + d.Set("locked", m.Options.GetLocked()) + + if m.GetType() == datadogV1.MONITORTYPE_LOG_ALERT { + d.Set("enable_logs_sample", m.Options.GetEnableLogsSample()) + } + + return nil +} + +func expandStringList(configured []interface{}) []string { + vs := make([]string, 0, len(configured)) + for _, v := range configured { + val, ok := v.(string) + if ok && val != "" { + vs = append(vs, v.(string)) + } + } + return vs +} diff --git a/datadog/data_source_datadog_monitor_test.go b/datadog/data_source_datadog_monitor_test.go new file mode 100644 index 000000000..50db6878a --- /dev/null +++ b/datadog/data_source_datadog_monitor_test.go @@ -0,0 +1,149 @@ +package datadog + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func TestAccDatadogMonitorDatasource(t *testing.T) { + accProviders, cleanup := testAccProviders(t, initRecorder(t)) + defer cleanup(t) + accProvider := testAccProvider(t, accProviders) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: accProviders, + CheckDestroy: testAccCheckDatadogMonitorDestroy(accProvider), + Steps: []resource.TestStep{ + { + Config: testAccDatasourceMonitorNameFilterConfig, + // Because of the `depends_on` in the datasource, the plan cannot be empty. + // See https://www.terraform.io/docs/configuration/data-sources.html#data-resource-dependencies + ExpectNonEmptyPlan: true, + Check: checkDatasourceAttrs(accProvider), + }, + { + Config: testAccDatasourceMonitorTagsFilterConfig, + // Because of the `depends_on` in the datasource, the plan cannot be empty. + // See https://www.terraform.io/docs/configuration/data-sources.html#data-resource-dependencies + ExpectNonEmptyPlan: true, + Check: checkDatasourceAttrs(accProvider), + }, + { + Config: testAccDatasourceMonitorMonitorTagsFilterConfig, + // Because of the `depends_on` in the datasource, the plan cannot be empty. + // See https://www.terraform.io/docs/configuration/data-sources.html#data-resource-dependencies + ExpectNonEmptyPlan: true, + Check: checkDatasourceAttrs(accProvider), + }, + }, + }) +} + +func checkDatasourceAttrs(accProvider *schema.Provider) resource.TestCheckFunc { + return resource.ComposeTestCheckFunc( + testAccCheckDatadogMonitorExists(accProvider, "datadog_monitor.foo"), + resource.TestCheckResourceAttr( + "data.datadog_monitor.foo", "name", "monitor for datasource test"), + resource.TestCheckResourceAttr( + "data.datadog_monitor.foo", "message", "some message Notify: @hipchat-channel"), + resource.TestCheckResourceAttr( + "data.datadog_monitor.foo", "type", "query alert"), + resource.TestCheckResourceAttr( + "data.datadog_monitor.foo", "query", "avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} by {host} > 2"), + resource.TestCheckResourceAttr( + "data.datadog_monitor.foo", "notify_no_data", "false"), + resource.TestCheckResourceAttr( + "data.datadog_monitor.foo", "new_host_delay", "600"), + resource.TestCheckResourceAttr( + "data.datadog_monitor.foo", "evaluation_delay", "700"), + resource.TestCheckResourceAttr( + "data.datadog_monitor.foo", "renotify_interval", "60"), + resource.TestCheckResourceAttr( + "data.datadog_monitor.foo", "thresholds.warning", "1"), + resource.TestCheckResourceAttr( + "data.datadog_monitor.foo", "thresholds.warning_recovery", "0.5"), + resource.TestCheckResourceAttr( + "data.datadog_monitor.foo", "thresholds.critical", "2"), + resource.TestCheckResourceAttr( + "data.datadog_monitor.foo", "thresholds.critical_recovery", "1.5"), + resource.TestCheckResourceAttr( + "data.datadog_monitor.foo", "require_full_window", "true"), + resource.TestCheckResourceAttr( + "data.datadog_monitor.foo", "locked", "false"), + // Tags are a TypeSet => use a weird way to access members by their hash + // TF TypeSet is internally represented as a map that maps computed hashes + // to actual values. Since the hashes are always the same for one value, + // this is the way to get them. + resource.TestCheckResourceAttr( + "data.datadog_monitor.foo", "tags.#", "2"), + resource.TestCheckResourceAttr( + "data.datadog_monitor.foo", "tags.2644851163", "baz"), + ) +} + +var testAccMonitorConfig = ` +resource "datadog_monitor" "foo" { + name = "monitor for datasource test" + type = "query alert" + message = "some message Notify: @hipchat-channel" + escalation_message = "the situation has escalated @pagerduty" + + query = "avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo,test_datasource_monitor_scope:foo} by {host} > 2" + + thresholds = { + warning = "1.0" + critical = "2.0" + warning_recovery = "0.5" + critical_recovery = "1.5" + } + + renotify_interval = 60 + + notify_audit = false + timeout_h = 60 + new_host_delay = 600 + evaluation_delay = 700 + include_tags = true + require_full_window = true + locked = false + tags = ["test_datasource_monitor:foo", "baz"] +} +` + +var testAccDatasourceMonitorNameFilterConfig = fmt.Sprintf(` +%s +data "datadog_monitor" "foo" { + depends_on = [ + datadog_monitor.foo, + ] + name_filter = "monitor for datasource test" +} +`, testAccMonitorConfig) + +var testAccDatasourceMonitorTagsFilterConfig = fmt.Sprintf(` +%s +data "datadog_monitor" "foo" { + depends_on = [ + datadog_monitor.foo, + ] + tags_filter = [ + "test_datasource_monitor_scope:foo", + ] +} +`, testAccMonitorConfig) + +var testAccDatasourceMonitorMonitorTagsFilterConfig = fmt.Sprintf(` +%s +data "datadog_monitor" "foo" { + depends_on = [ + datadog_monitor.foo, + ] + monitor_tags_filter = [ + "test_datasource_monitor:foo", + ] +} +`, testAccMonitorConfig) diff --git a/datadog/provider.go b/datadog/provider.go index bc309c112..737f5907b 100644 --- a/datadog/provider.go +++ b/datadog/provider.go @@ -74,6 +74,7 @@ func Provider() terraform.ResourceProvider { DataSourcesMap: map[string]*schema.Resource{ "datadog_ip_ranges": dataSourceDatadogIpRanges(), + "datadog_monitor": dataSourceDatadogMonitor(), }, ConfigureFunc: providerConfigure,