From 551e811f1cf0c999a28a03adae85eec81fc2dc88 Mon Sep 17 00:00:00 2001 From: "ci.datadog-api-spec" Date: Tue, 23 May 2023 18:58:13 +0000 Subject: [PATCH] Regenerate client from commit ae6015d7 of spec repo --- .apigentools-info | 8 +- .generator/schemas/v1/openapi.yaml | 49 ++++ api/datadogV1/api_monitors.go | 12 +- api/datadogV1/model_matching_downtime.go | 233 ++++++++++++++++++ api/datadogV1/model_monitor.go | 69 ++++-- examples/v1/monitors/GetMonitor.go | 2 +- examples/v1/monitors/GetMonitor_2200114573.go | 33 +++ ...onitors_details_returns_OK_response.freeze | 2 +- ..._monitors_details_returns_OK_response.yaml | 22 +- ...s_with_downtime_returns_OK_response.freeze | 1 + ...ils_with_downtime_returns_OK_response.yaml | 106 ++++++++ tests/scenarios/features/v1/given.json | 12 + tests/scenarios/features/v1/monitors.feature | 15 ++ 13 files changed, 529 insertions(+), 35 deletions(-) create mode 100644 api/datadogV1/model_matching_downtime.go create mode 100644 examples/v1/monitors/GetMonitor_2200114573.go create mode 100644 tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Get_a_monitors_details_with_downtime_returns_OK_response.freeze create mode 100644 tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Get_a_monitors_details_with_downtime_returns_OK_response.yaml diff --git a/.apigentools-info b/.apigentools-info index 7b3084d10b5..42dddc86e71 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.4", - "regenerated": "2023-05-23 13:54:22.420354", - "spec_repo_commit": "2ccd9d0a" + "regenerated": "2023-05-23 18:56:58.766282", + "spec_repo_commit": "ae6015d7" }, "v2": { "apigentools_version": "1.6.4", - "regenerated": "2023-05-23 13:54:22.432956", - "spec_repo_commit": "2ccd9d0a" + "regenerated": "2023-05-23 18:56:58.779039", + "spec_repo_commit": "ae6015d7" } } } \ No newline at end of file diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index 268d9602444..830743dce0c 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -5829,6 +5829,43 @@ components: type: string x-enum-varnames: - USER_AGENT_PARSER + MatchingDowntime: + description: Object describing a downtime that matches this monitor. + properties: + end: + description: POSIX timestamp to end the downtime. + example: 1412792983 + format: int64 + nullable: true + type: integer + id: + description: The downtime ID. + example: 1625 + format: int64 + readOnly: true + type: integer + scope: + description: 'The scope(s) to which the downtime applies. Must be in `key:value` + format. For example, `host:app2`. + + Provide multiple scopes as a comma-separated list like `env:dev,env:prod`. + + The resulting downtime applies to sources that matches ALL provided scopes + (`env:dev` **AND** `env:prod`).' + example: + - env:staging + items: + description: A scope. For example, `"env:staging"`. + type: string + type: array + start: + description: POSIX timestamp to start the downtime. + example: 1412792983 + format: int64 + type: integer + required: + - id + type: object MetricContentEncoding: default: deflate description: HTTP header used to compress the media-type. @@ -6109,6 +6146,11 @@ components: format: int64 readOnly: true type: integer + matching_downtimes: + description: A list of active downtimes that match this monitor. + items: + $ref: '#/components/schemas/MatchingDowntime' + type: array message: description: A message to include with notifications for this monitor. type: string @@ -25354,6 +25396,13 @@ paths: required: false schema: type: string + - description: If this argument is set to true, then the returned data includes + all current active downtimes for the monitor. + in: query + name: with_downtimes + required: false + schema: + type: boolean responses: '200': content: diff --git a/api/datadogV1/api_monitors.go b/api/datadogV1/api_monitors.go index 5bfc1c31adb..67fc8523adc 100644 --- a/api/datadogV1/api_monitors.go +++ b/api/datadogV1/api_monitors.go @@ -454,7 +454,8 @@ func (a *MonitorsApi) DeleteMonitor(ctx _context.Context, monitorId int64, o ... // GetMonitorOptionalParameters holds optional parameters for GetMonitor. type GetMonitorOptionalParameters struct { - GroupStates *string + GroupStates *string + WithDowntimes *bool } // NewGetMonitorOptionalParameters creates an empty struct for parameters. @@ -469,6 +470,12 @@ func (r *GetMonitorOptionalParameters) WithGroupStates(groupStates string) *GetM return r } +// WithWithDowntimes sets the corresponding parameter name and returns the struct. +func (r *GetMonitorOptionalParameters) WithWithDowntimes(withDowntimes bool) *GetMonitorOptionalParameters { + r.WithDowntimes = &withDowntimes + return r +} + // GetMonitor Get a monitor's details. // Get details about the specified monitor from your organization. func (a *MonitorsApi) GetMonitor(ctx _context.Context, monitorId int64, o ...GetMonitorOptionalParameters) (Monitor, *_nethttp.Response, error) { @@ -500,6 +507,9 @@ func (a *MonitorsApi) GetMonitor(ctx _context.Context, monitorId int64, o ...Get if optionalParams.GroupStates != nil { localVarQueryParams.Add("group_states", datadog.ParameterToString(*optionalParams.GroupStates, "")) } + if optionalParams.WithDowntimes != nil { + localVarQueryParams.Add("with_downtimes", datadog.ParameterToString(*optionalParams.WithDowntimes, "")) + } localVarHeaderParams["Accept"] = "application/json" datadog.SetAuthKeys( diff --git a/api/datadogV1/model_matching_downtime.go b/api/datadogV1/model_matching_downtime.go new file mode 100644 index 00000000000..3d0b2b999a2 --- /dev/null +++ b/api/datadogV1/model_matching_downtime.go @@ -0,0 +1,233 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV1 + +import ( + "encoding/json" + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// MatchingDowntime Object describing a downtime that matches this monitor. +type MatchingDowntime struct { + // POSIX timestamp to end the downtime. + End datadog.NullableInt64 `json:"end,omitempty"` + // The downtime ID. + Id int64 `json:"id"` + // The scope(s) to which the downtime applies. Must be in `key:value` format. For example, `host:app2`. + // Provide multiple scopes as a comma-separated list like `env:dev,env:prod`. + // The resulting downtime applies to sources that matches ALL provided scopes (`env:dev` **AND** `env:prod`). + Scope []string `json:"scope,omitempty"` + // POSIX timestamp to start the downtime. + Start *int64 `json:"start,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} +} + +// NewMatchingDowntime instantiates a new MatchingDowntime object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewMatchingDowntime(id int64) *MatchingDowntime { + this := MatchingDowntime{} + this.Id = id + return &this +} + +// NewMatchingDowntimeWithDefaults instantiates a new MatchingDowntime object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewMatchingDowntimeWithDefaults() *MatchingDowntime { + this := MatchingDowntime{} + return &this +} + +// GetEnd returns the End field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *MatchingDowntime) GetEnd() int64 { + if o == nil || o.End.Get() == nil { + var ret int64 + return ret + } + return *o.End.Get() +} + +// GetEndOk returns a tuple with the End field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned. +func (o *MatchingDowntime) GetEndOk() (*int64, bool) { + if o == nil { + return nil, false + } + return o.End.Get(), o.End.IsSet() +} + +// HasEnd returns a boolean if a field has been set. +func (o *MatchingDowntime) HasEnd() bool { + return o != nil && o.End.IsSet() +} + +// SetEnd gets a reference to the given datadog.NullableInt64 and assigns it to the End field. +func (o *MatchingDowntime) SetEnd(v int64) { + o.End.Set(&v) +} + +// SetEndNil sets the value for End to be an explicit nil. +func (o *MatchingDowntime) SetEndNil() { + o.End.Set(nil) +} + +// UnsetEnd ensures that no value is present for End, not even an explicit nil. +func (o *MatchingDowntime) UnsetEnd() { + o.End.Unset() +} + +// GetId returns the Id field value. +func (o *MatchingDowntime) GetId() int64 { + if o == nil { + var ret int64 + return ret + } + return o.Id +} + +// GetIdOk returns a tuple with the Id field value +// and a boolean to check if the value has been set. +func (o *MatchingDowntime) GetIdOk() (*int64, bool) { + if o == nil { + return nil, false + } + return &o.Id, true +} + +// SetId sets field value. +func (o *MatchingDowntime) SetId(v int64) { + o.Id = v +} + +// GetScope returns the Scope field value if set, zero value otherwise. +func (o *MatchingDowntime) GetScope() []string { + if o == nil || o.Scope == nil { + var ret []string + return ret + } + return o.Scope +} + +// GetScopeOk returns a tuple with the Scope field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MatchingDowntime) GetScopeOk() (*[]string, bool) { + if o == nil || o.Scope == nil { + return nil, false + } + return &o.Scope, true +} + +// HasScope returns a boolean if a field has been set. +func (o *MatchingDowntime) HasScope() bool { + return o != nil && o.Scope != nil +} + +// SetScope gets a reference to the given []string and assigns it to the Scope field. +func (o *MatchingDowntime) SetScope(v []string) { + o.Scope = v +} + +// GetStart returns the Start field value if set, zero value otherwise. +func (o *MatchingDowntime) GetStart() int64 { + if o == nil || o.Start == nil { + var ret int64 + return ret + } + return *o.Start +} + +// GetStartOk returns a tuple with the Start field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *MatchingDowntime) GetStartOk() (*int64, bool) { + if o == nil || o.Start == nil { + return nil, false + } + return o.Start, true +} + +// HasStart returns a boolean if a field has been set. +func (o *MatchingDowntime) HasStart() bool { + return o != nil && o.Start != nil +} + +// SetStart gets a reference to the given int64 and assigns it to the Start field. +func (o *MatchingDowntime) SetStart(v int64) { + o.Start = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o MatchingDowntime) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return json.Marshal(o.UnparsedObject) + } + if o.End.IsSet() { + toSerialize["end"] = o.End.Get() + } + toSerialize["id"] = o.Id + if o.Scope != nil { + toSerialize["scope"] = o.Scope + } + if o.Start != nil { + toSerialize["start"] = o.Start + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return json.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *MatchingDowntime) UnmarshalJSON(bytes []byte) (err error) { + raw := map[string]interface{}{} + required := struct { + Id *int64 `json:"id"` + }{} + all := struct { + End datadog.NullableInt64 `json:"end,omitempty"` + Id int64 `json:"id"` + Scope []string `json:"scope,omitempty"` + Start *int64 `json:"start,omitempty"` + }{} + err = json.Unmarshal(bytes, &required) + if err != nil { + return err + } + if required.Id == nil { + return fmt.Errorf("required field id missing") + } + err = json.Unmarshal(bytes, &all) + if err != nil { + err = json.Unmarshal(bytes, &raw) + if err != nil { + return err + } + o.UnparsedObject = raw + return nil + } + additionalProperties := make(map[string]interface{}) + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"end", "id", "scope", "start"}) + } else { + return err + } + o.End = all.End + o.Id = all.Id + o.Scope = all.Scope + o.Start = all.Start + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/api/datadogV1/model_monitor.go b/api/datadogV1/model_monitor.go index 073a481f772..5132d9f6e91 100644 --- a/api/datadogV1/model_monitor.go +++ b/api/datadogV1/model_monitor.go @@ -22,6 +22,8 @@ type Monitor struct { Deleted datadog.NullableTime `json:"deleted,omitempty"` // ID of this monitor. Id *int64 `json:"id,omitempty"` + // A list of active downtimes that match this monitor. + MatchingDowntimes []MatchingDowntime `json:"matching_downtimes,omitempty"` // A message to include with notifications for this monitor. Message *string `json:"message,omitempty"` // Last timestamp when the monitor was edited. @@ -193,6 +195,34 @@ func (o *Monitor) SetId(v int64) { o.Id = &v } +// GetMatchingDowntimes returns the MatchingDowntimes field value if set, zero value otherwise. +func (o *Monitor) GetMatchingDowntimes() []MatchingDowntime { + if o == nil || o.MatchingDowntimes == nil { + var ret []MatchingDowntime + return ret + } + return o.MatchingDowntimes +} + +// GetMatchingDowntimesOk returns a tuple with the MatchingDowntimes field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Monitor) GetMatchingDowntimesOk() (*[]MatchingDowntime, bool) { + if o == nil || o.MatchingDowntimes == nil { + return nil, false + } + return &o.MatchingDowntimes, true +} + +// HasMatchingDowntimes returns a boolean if a field has been set. +func (o *Monitor) HasMatchingDowntimes() bool { + return o != nil && o.MatchingDowntimes != nil +} + +// SetMatchingDowntimes gets a reference to the given []MatchingDowntime and assigns it to the MatchingDowntimes field. +func (o *Monitor) SetMatchingDowntimes(v []MatchingDowntime) { + o.MatchingDowntimes = v +} + // GetMessage returns the Message field value if set, zero value otherwise. func (o *Monitor) GetMessage() string { if o == nil || o.Message == nil { @@ -553,6 +583,9 @@ func (o Monitor) MarshalJSON() ([]byte, error) { if o.Id != nil { toSerialize["id"] = o.Id } + if o.MatchingDowntimes != nil { + toSerialize["matching_downtimes"] = o.MatchingDowntimes + } if o.Message != nil { toSerialize["message"] = o.Message } @@ -604,22 +637,23 @@ func (o *Monitor) UnmarshalJSON(bytes []byte) (err error) { Type *MonitorType `json:"type"` }{} all := struct { - Created *time.Time `json:"created,omitempty"` - Creator *Creator `json:"creator,omitempty"` - Deleted datadog.NullableTime `json:"deleted,omitempty"` - Id *int64 `json:"id,omitempty"` - Message *string `json:"message,omitempty"` - Modified *time.Time `json:"modified,omitempty"` - Multi *bool `json:"multi,omitempty"` - Name *string `json:"name,omitempty"` - Options *MonitorOptions `json:"options,omitempty"` - OverallState *MonitorOverallStates `json:"overall_state,omitempty"` - Priority datadog.NullableInt64 `json:"priority,omitempty"` - Query string `json:"query"` - RestrictedRoles []string `json:"restricted_roles,omitempty"` - State *MonitorState `json:"state,omitempty"` - Tags []string `json:"tags,omitempty"` - Type MonitorType `json:"type"` + Created *time.Time `json:"created,omitempty"` + Creator *Creator `json:"creator,omitempty"` + Deleted datadog.NullableTime `json:"deleted,omitempty"` + Id *int64 `json:"id,omitempty"` + MatchingDowntimes []MatchingDowntime `json:"matching_downtimes,omitempty"` + Message *string `json:"message,omitempty"` + Modified *time.Time `json:"modified,omitempty"` + Multi *bool `json:"multi,omitempty"` + Name *string `json:"name,omitempty"` + Options *MonitorOptions `json:"options,omitempty"` + OverallState *MonitorOverallStates `json:"overall_state,omitempty"` + Priority datadog.NullableInt64 `json:"priority,omitempty"` + Query string `json:"query"` + RestrictedRoles []string `json:"restricted_roles,omitempty"` + State *MonitorState `json:"state,omitempty"` + Tags []string `json:"tags,omitempty"` + Type MonitorType `json:"type"` }{} err = json.Unmarshal(bytes, &required) if err != nil { @@ -642,7 +676,7 @@ func (o *Monitor) UnmarshalJSON(bytes []byte) (err error) { } additionalProperties := make(map[string]interface{}) if err = json.Unmarshal(bytes, &additionalProperties); err == nil { - datadog.DeleteKeys(additionalProperties, &[]string{"created", "creator", "deleted", "id", "message", "modified", "multi", "name", "options", "overall_state", "priority", "query", "restricted_roles", "state", "tags", "type"}) + datadog.DeleteKeys(additionalProperties, &[]string{"created", "creator", "deleted", "id", "matching_downtimes", "message", "modified", "multi", "name", "options", "overall_state", "priority", "query", "restricted_roles", "state", "tags", "type"}) } else { return err } @@ -673,6 +707,7 @@ func (o *Monitor) UnmarshalJSON(bytes []byte) (err error) { o.Creator = all.Creator o.Deleted = all.Deleted o.Id = all.Id + o.MatchingDowntimes = all.MatchingDowntimes o.Message = all.Message o.Modified = all.Modified o.Multi = all.Multi diff --git a/examples/v1/monitors/GetMonitor.go b/examples/v1/monitors/GetMonitor.go index 840172579f3..84ec2c97d43 100644 --- a/examples/v1/monitors/GetMonitor.go +++ b/examples/v1/monitors/GetMonitor.go @@ -21,7 +21,7 @@ func main() { configuration := datadog.NewConfiguration() apiClient := datadog.NewAPIClient(configuration) api := datadogV1.NewMonitorsApi(apiClient) - resp, r, err := api.GetMonitor(ctx, MonitorID, *datadogV1.NewGetMonitorOptionalParameters()) + resp, r, err := api.GetMonitor(ctx, MonitorID, *datadogV1.NewGetMonitorOptionalParameters().WithWithDowntimes(true)) if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `MonitorsApi.GetMonitor`: %v\n", err) diff --git a/examples/v1/monitors/GetMonitor_2200114573.go b/examples/v1/monitors/GetMonitor_2200114573.go new file mode 100644 index 00000000000..45b4b1c9208 --- /dev/null +++ b/examples/v1/monitors/GetMonitor_2200114573.go @@ -0,0 +1,33 @@ +// Get a monitor's details with downtime returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + "strconv" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV1" +) + +func main() { + // there is a valid "monitor" in the system + MonitorID, _ := strconv.ParseInt(os.Getenv("MONITOR_ID"), 10, 64) + + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV1.NewMonitorsApi(apiClient) + resp, r, err := api.GetMonitor(ctx, MonitorID, *datadogV1.NewGetMonitorOptionalParameters().WithWithDowntimes(true)) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `MonitorsApi.GetMonitor`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `MonitorsApi.GetMonitor`:\n%s\n", responseContent) +} diff --git a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Get_a_monitors_details_returns_OK_response.freeze b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Get_a_monitors_details_returns_OK_response.freeze index 0b370dd72b8..ec45a2b566b 100644 --- a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Get_a_monitors_details_returns_OK_response.freeze +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Get_a_monitors_details_returns_OK_response.freeze @@ -1 +1 @@ -2023-01-18T18:37:19.697Z \ No newline at end of file +2023-05-22T17:02:26.784Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Get_a_monitors_details_returns_OK_response.yaml b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Get_a_monitors_details_returns_OK_response.yaml index 0cf27d446cc..878d41deff0 100644 --- a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Get_a_monitors_details_returns_OK_response.yaml +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Get_a_monitors_details_returns_OK_response.yaml @@ -1,7 +1,7 @@ interactions: - request: body: | - {"message":"some message Notify: @hipchat-channel","name":"Test-Get_a_monitor_s_details_returns_OK_response-1674067039","options":{"enable_logs_sample":true,"escalation_message":"the situation has escalated","evaluation_delay":700,"groupby_simple_monitor":true,"include_tags":true,"locked":false,"new_host_delay":600,"no_data_timeframe":null,"notification_preset_name":"hide_handles","notify_audit":false,"notify_no_data":false,"on_missing_data":"show_and_notify_no_data","renotify_interval":60,"require_full_window":true,"thresholds":{"critical":2,"warning":1},"timeout_h":24},"priority":3,"query":"logs(\"service:foo AND type:error\").index(\"main\").rollup(\"count\").by(\"source\").last(\"5m\") \u003e 2","tags":["test:testgetamonitorsdetailsreturnsokresponse1674067039","env:ci"],"type":"log alert"} + {"message":"some message Notify: @hipchat-channel","name":"Test-Get_a_monitor_s_details_returns_OK_response-1684774946","options":{"enable_logs_sample":true,"escalation_message":"the situation has escalated","evaluation_delay":700,"groupby_simple_monitor":true,"include_tags":true,"locked":false,"new_host_delay":600,"no_data_timeframe":null,"notification_preset_name":"hide_handles","notify_audit":false,"notify_no_data":false,"on_missing_data":"show_and_notify_no_data","renotify_interval":60,"require_full_window":true,"thresholds":{"critical":2,"warning":1},"timeout_h":24},"priority":3,"query":"logs(\"service:foo AND type:error\").index(\"main\").rollup(\"count\").by(\"source\").last(\"5m\") \u003e 2","tags":["test:testgetamonitorsdetailsreturnsokresponse1684774946","env:ci"],"type":"log alert"} form: {} headers: Accept: @@ -11,11 +11,11 @@ interactions: method: POST url: https://api.datadoghq.com/api/v1/monitor response: - body: '{"id":108260305,"org_id":321813,"type":"log alert","name":"Test-Get_a_monitor_s_details_returns_OK_response-1674067039","message":"some - message Notify: @hipchat-channel","tags":["test:testgetamonitorsdetailsreturnsokresponse1674067039","env:ci"],"query":"logs(\"service:foo + body: '{"id":119735290,"org_id":321813,"type":"log alert","name":"Test-Get_a_monitor_s_details_returns_OK_response-1684774946","message":"some + message Notify: @hipchat-channel","tags":["test:testgetamonitorsdetailsreturnsokresponse1684774946","env:ci"],"query":"logs(\"service:foo AND type:error\").index(\"main\").rollup(\"count\").by(\"source\").last(\"5m\") > 2","options":{"enable_logs_sample":true,"escalation_message":"the situation - has escalated","evaluation_delay":700,"groupby_simple_monitor":true,"include_tags":true,"locked":false,"new_host_delay":600,"no_data_timeframe":null,"notification_preset_name":"hide_handles","notify_audit":false,"notify_no_data":false,"on_missing_data":"show_and_notify_no_data","renotify_interval":60,"require_full_window":true,"thresholds":{"critical":2.0,"warning":1.0},"timeout_h":24,"silenced":{}},"multi":true,"created_at":1674067039000,"created":"2023-01-18T18:37:19.812019+00:00","modified":"2023-01-18T18:37:19.812019+00:00","deleted":null,"restricted_roles":null,"priority":3,"overall_state_modified":null,"overall_state":"No + has escalated","evaluation_delay":700,"groupby_simple_monitor":true,"include_tags":true,"locked":false,"new_host_delay":600,"no_data_timeframe":null,"notification_preset_name":"hide_handles","notify_audit":false,"notify_no_data":false,"on_missing_data":"show_and_notify_no_data","renotify_interval":60,"require_full_window":true,"thresholds":{"critical":2.0,"warning":1.0},"timeout_h":24,"silenced":{}},"multi":true,"created_at":1684774946000,"created":"2023-05-22T17:02:26.996650+00:00","modified":"2023-05-22T17:02:26.996650+00:00","deleted":null,"restricted_roles":null,"priority":3,"overall_state_modified":null,"overall_state":"No Data","creator":{"name":null,"handle":"frog@datadoghq.com","email":"frog@datadoghq.com","id":1445416}} ' @@ -32,14 +32,14 @@ interactions: Accept: - application/json method: GET - url: https://api.datadoghq.com/api/v1/monitor/108260305 + url: https://api.datadoghq.com/api/v1/monitor/119735290?with_downtimes=true response: - body: '{"id":108260305,"org_id":321813,"type":"log alert","name":"Test-Get_a_monitor_s_details_returns_OK_response-1674067039","message":"some - message Notify: @hipchat-channel","tags":["test:testgetamonitorsdetailsreturnsokresponse1674067039","env:ci"],"query":"logs(\"service:foo + body: '{"id":119735290,"org_id":321813,"type":"log alert","name":"Test-Get_a_monitor_s_details_returns_OK_response-1684774946","message":"some + message Notify: @hipchat-channel","tags":["test:testgetamonitorsdetailsreturnsokresponse1684774946","env:ci"],"query":"logs(\"service:foo AND type:error\").index(\"main\").rollup(\"count\").by(\"source\").last(\"5m\") > 2","options":{"enable_logs_sample":true,"escalation_message":"the situation - has escalated","evaluation_delay":700,"groupby_simple_monitor":true,"include_tags":true,"locked":false,"new_host_delay":600,"no_data_timeframe":null,"notification_preset_name":"hide_handles","notify_audit":false,"notify_no_data":false,"on_missing_data":"show_and_notify_no_data","renotify_interval":60,"require_full_window":true,"thresholds":{"critical":2.0,"warning":1.0},"timeout_h":24,"silenced":{}},"multi":true,"created_at":1674067039000,"created":"2023-01-18T18:37:19.812019+00:00","modified":"2023-01-18T18:37:19.812019+00:00","deleted":null,"restricted_roles":null,"priority":3,"overall_state_modified":null,"overall_state":"No - Data","creator":{"name":null,"handle":"frog@datadoghq.com","email":"frog@datadoghq.com","id":1445416}} + has escalated","evaluation_delay":700,"groupby_simple_monitor":true,"include_tags":true,"locked":false,"new_host_delay":600,"no_data_timeframe":null,"notification_preset_name":"hide_handles","notify_audit":false,"notify_no_data":false,"on_missing_data":"show_and_notify_no_data","renotify_interval":60,"require_full_window":true,"thresholds":{"critical":2.0,"warning":1.0},"timeout_h":24,"silenced":{}},"multi":true,"created_at":1684774946000,"created":"2023-05-22T17:02:26.996650+00:00","modified":"2023-05-22T17:02:26.996650+00:00","deleted":null,"restricted_roles":null,"priority":3,"overall_state_modified":null,"overall_state":"No + Data","creator":{"name":null,"handle":"frog@datadoghq.com","email":"frog@datadoghq.com","id":1445416},"matching_downtimes":[]} ' code: 200 @@ -55,9 +55,9 @@ interactions: Accept: - application/json method: DELETE - url: https://api.datadoghq.com/api/v1/monitor/108260305 + url: https://api.datadoghq.com/api/v1/monitor/119735290 response: - body: '{"deleted_monitor_id":108260305} + body: '{"deleted_monitor_id":119735290} ' code: 200 diff --git a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Get_a_monitors_details_with_downtime_returns_OK_response.freeze b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Get_a_monitors_details_with_downtime_returns_OK_response.freeze new file mode 100644 index 00000000000..901591b10ad --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Get_a_monitors_details_with_downtime_returns_OK_response.freeze @@ -0,0 +1 @@ +2023-05-22T21:15:19.763Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Get_a_monitors_details_with_downtime_returns_OK_response.yaml b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Get_a_monitors_details_with_downtime_returns_OK_response.yaml new file mode 100644 index 00000000000..56f6769e5b0 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Monitors/Scenario_Get_a_monitors_details_with_downtime_returns_OK_response.yaml @@ -0,0 +1,106 @@ +interactions: +- request: + body: | + {"message":"some message Notify: @hipchat-channel","name":"Test-Get_a_monitor_s_details_with_downtime_returns_OK_response-1684790119","options":{"enable_logs_sample":true,"escalation_message":"the situation has escalated","evaluation_delay":700,"groupby_simple_monitor":true,"include_tags":true,"locked":false,"new_host_delay":600,"no_data_timeframe":null,"notification_preset_name":"hide_handles","notify_audit":false,"notify_no_data":false,"on_missing_data":"show_and_notify_no_data","renotify_interval":60,"require_full_window":true,"thresholds":{"critical":2,"warning":1},"timeout_h":24},"priority":3,"query":"logs(\"service:foo AND type:error\").index(\"main\").rollup(\"count\").by(\"source\").last(\"5m\") \u003e 2","tags":["test:testgetamonitorsdetailswithdowntimereturnsokresponse1684790119","env:ci"],"type":"log alert"} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + method: POST + url: https://api.datadoghq.com/api/v1/monitor + response: + body: '{"id":119766008,"org_id":717122,"type":"log alert","name":"Test-Get_a_monitor_s_details_with_downtime_returns_OK_response-1684790119","message":"some + message Notify: @hipchat-channel","tags":["test:testgetamonitorsdetailswithdowntimereturnsokresponse1684790119","env:ci"],"query":"logs(\"service:foo + AND type:error\").index(\"main\").rollup(\"count\").by(\"source\").last(\"5m\") + > 2","options":{"enable_logs_sample":true,"escalation_message":"the situation + has escalated","evaluation_delay":700,"groupby_simple_monitor":true,"include_tags":true,"locked":false,"new_host_delay":600,"no_data_timeframe":null,"notification_preset_name":"hide_handles","notify_audit":false,"notify_no_data":false,"on_missing_data":"show_and_notify_no_data","renotify_interval":60,"require_full_window":true,"thresholds":{"critical":2.0,"warning":1.0},"timeout_h":24,"silenced":{}},"multi":true,"created_at":1684790119000,"created":"2023-05-22T21:15:19.942502+00:00","modified":"2023-05-22T21:15:19.942502+00:00","deleted":null,"restricted_roles":null,"priority":3,"overall_state_modified":null,"overall_state":"No + Data","creator":{"name":"Kevin Zou","handle":"kevin.zou@datadoghq.com","email":"kevin.zou@datadoghq.com","id":4351227}} + + ' + code: 200 + duration: '' + headers: + Content-Type: + - application/json + status: 200 OK +- request: + body: | + {"end":1685394919,"message":"Test-Get_a_monitor_s_details_with_downtime_returns_OK_response-1684790119","monitor_id":119766008,"mute_first_recovery_notification":true,"notify_end_states":["alert"],"notify_end_types":["canceled"],"scope":["*"],"start":1684790119,"timezone":"Etc/UTC"} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + method: POST + url: https://api.datadoghq.com/api/v1/downtime + response: + body: '{"id":2942947856,"monitor_id":119766008,"org_id":717122,"start":1684790119,"end":1685394919,"canceled":null,"created":1684790120,"modified":1684790120,"message":"Test-Get_a_monitor_s_details_with_downtime_returns_OK_response-1684790119","active":true,"disabled":false,"recurrence":null,"timezone":"Etc/UTC","parent_id":null,"child_id":null,"creator_id":4351227,"updater_id":null,"downtime_type":0,"status":"active","monitor_tags":["*"],"mute_first_recovery_notification":true,"notify_end_types":["canceled"],"notify_end_states":["alert"],"uuid":"c1ddf27c-f8e5-11ed-8c5a-da7ad0900002","scope":["*"]} + + ' + code: 200 + duration: '' + headers: + Content-Type: + - application/json + status: 200 OK +- request: + body: '' + form: {} + headers: + Accept: + - application/json + method: GET + url: https://api.datadoghq.com/api/v1/monitor/119766008?with_downtimes=true + response: + body: '{"id":119766008,"org_id":717122,"type":"log alert","name":"Test-Get_a_monitor_s_details_with_downtime_returns_OK_response-1684790119","message":"some + message Notify: @hipchat-channel","tags":["test:testgetamonitorsdetailswithdowntimereturnsokresponse1684790119","env:ci"],"query":"logs(\"service:foo + AND type:error\").index(\"main\").rollup(\"count\").by(\"source\").last(\"5m\") + > 2","options":{"enable_logs_sample":true,"escalation_message":"the situation + has escalated","evaluation_delay":700,"groupby_simple_monitor":true,"include_tags":true,"locked":false,"new_host_delay":600,"no_data_timeframe":null,"notification_preset_name":"hide_handles","notify_audit":false,"notify_no_data":false,"on_missing_data":"show_and_notify_no_data","renotify_interval":60,"require_full_window":true,"thresholds":{"critical":2.0,"warning":1.0},"timeout_h":24,"silenced":{"*":1685394919}},"multi":true,"created_at":1684790119000,"created":"2023-05-22T21:15:19.942502+00:00","modified":"2023-05-22T21:15:19.942502+00:00","deleted":null,"restricted_roles":null,"priority":3,"overall_state_modified":"2023-05-22T21:15:22+00:00","overall_state":"No + Data","creator":{"name":"Kevin Zou","handle":"kevin.zou@datadoghq.com","email":"kevin.zou@datadoghq.com","id":4351227},"matching_downtimes":[{"id":2942947856,"active":true,"monitor_id":119766008,"start":1684790119,"end":1685394919,"scope":["*"],"groups":["total"]}]} + + ' + code: 200 + duration: '' + headers: + Content-Type: + - application/json + status: 200 OK +- request: + body: '' + form: {} + headers: + Accept: + - '*/*' + method: DELETE + url: https://api.datadoghq.com/api/v1/downtime/2942947856 + response: + body: '' + code: 204 + duration: '' + headers: + Content-Type: + - text/html; charset=utf-8 + status: 204 No Content +- request: + body: '' + form: {} + headers: + Accept: + - application/json + method: DELETE + url: https://api.datadoghq.com/api/v1/monitor/119766008 + response: + body: '{"deleted_monitor_id":119766008} + + ' + code: 200 + duration: '' + headers: + Content-Type: + - application/json + status: 200 OK +version: 1 diff --git a/tests/scenarios/features/v1/given.json b/tests/scenarios/features/v1/given.json index b80cd82fe38..1c5be660728 100644 --- a/tests/scenarios/features/v1/given.json +++ b/tests/scenarios/features/v1/given.json @@ -87,6 +87,18 @@ "tag": "Downtimes", "operationId": "CreateDowntime" }, + { + "parameters": [ + { + "name": "body", + "value": "{\n \"message\": \"{{ unique }}\",\n \"monitor_id\": {{ monitor.id }},\n \"start\": {{ timestamp(\"now\") }},\n \"end\": {{ timestamp(\"now + 7d\") }},\n \"timezone\": \"Etc/UTC\",\n \"scope\": [\"*\"],\n \"mute_first_recovery_notification\": true,\n \"notify_end_states\": [\"alert\"],\n \"notify_end_types\": [\"canceled\"]\n}" + } + ], + "step": "there is a valid \"downtime\" for a \"monitor\" in the system", + "key": "downtime_monitor", + "tag": "Downtimes", + "operationId": "CreateDowntime" + }, { "parameters": [ { diff --git a/tests/scenarios/features/v1/monitors.feature b/tests/scenarios/features/v1/monitors.feature index 129aae472e0..8a640140dad 100644 --- a/tests/scenarios/features/v1/monitors.feature +++ b/tests/scenarios/features/v1/monitors.feature @@ -187,9 +187,24 @@ Feature: Monitors Given there is a valid "monitor" in the system And new "GetMonitor" request And request contains "monitor_id" parameter from "monitor.id" + And request contains "with_downtimes" parameter with value true When the request is sent Then the response status is 200 OK And the response "id" has the same value as "monitor.id" + And the response "matching_downtimes" has length 0 + + @replay-only @team:DataDog/monitor-app + Scenario: Get a monitor's details with downtime returns "OK" response + Given there is a valid "monitor" in the system + And there is a valid "downtime" for a "monitor" in the system + And new "GetMonitor" request + And request contains "monitor_id" parameter from "monitor.id" + And request contains "with_downtimes" parameter with value true + When the request is sent + Then the response status is 200 OK + And the response "id" has the same value as "monitor.id" + And the response "matching_downtimes" has length 1 + And the response "matching_downtimes[0].id" has the same value as "downtime_monitor.id" @team:DataDog/monitor-app Scenario: Get a synthetics monitor's details