Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downtime Improvements #239

Merged
merged 2 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions datadog-accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4385,6 +4385,37 @@ func (d *Downtime) SetCanceled(v int) {
d.Canceled = &v
}

// GetCreatorID returns the CreatorID field if non-nil, zero value otherwise.
func (d *Downtime) GetCreatorID() int {
if d == nil || d.CreatorID == nil {
return 0
}
return *d.CreatorID
}

// GetCreatorIDOk returns a tuple with the CreatorID field if it's non-nil, zero value otherwise
// and a boolean to check if the value has been set.
func (d *Downtime) GetCreatorIDOk() (int, bool) {
if d == nil || d.CreatorID == nil {
return 0, false
}
return *d.CreatorID, true
}

// HasCreatorID returns a boolean if a field has been set.
func (d *Downtime) HasCreatorID() bool {
if d != nil && d.CreatorID != nil {
return true
}

return false
}

// SetCreatorID allocates a new d.CreatorID and returns the pointer to it.
func (d *Downtime) SetCreatorID(v int) {
d.CreatorID = &v
}

// GetDisabled returns the Disabled field if non-nil, zero value otherwise.
func (d *Downtime) GetDisabled() bool {
if d == nil || d.Disabled == nil {
Expand Down Expand Up @@ -4664,6 +4695,68 @@ func (d *Downtime) SetTimezone(v string) {
d.Timezone = &v
}

// GetType returns the Type field if non-nil, zero value otherwise.
func (d *Downtime) GetType() int {
if d == nil || d.Type == nil {
return 0
}
return *d.Type
}

// GetTypeOk returns a tuple with the Type field if it's non-nil, zero value otherwise
// and a boolean to check if the value has been set.
func (d *Downtime) GetTypeOk() (int, bool) {
if d == nil || d.Type == nil {
return 0, false
}
return *d.Type, true
}

// HasType returns a boolean if a field has been set.
func (d *Downtime) HasType() bool {
if d != nil && d.Type != nil {
return true
}

return false
}

// SetType allocates a new d.Type and returns the pointer to it.
func (d *Downtime) SetType(v int) {
d.Type = &v
}

// GetUpdaterID returns the UpdaterID field if non-nil, zero value otherwise.
func (d *Downtime) GetUpdaterID() int {
if d == nil || d.UpdaterID == nil {
return 0
}
return *d.UpdaterID
}

// GetUpdaterIDOk returns a tuple with the UpdaterID field if it's non-nil, zero value otherwise
// and a boolean to check if the value has been set.
func (d *Downtime) GetUpdaterIDOk() (int, bool) {
if d == nil || d.UpdaterID == nil {
return 0, false
}
return *d.UpdaterID, true
}

// HasUpdaterID returns a boolean if a field has been set.
func (d *Downtime) HasUpdaterID() bool {
if d != nil && d.UpdaterID != nil {
return true
}

return false
}

// SetUpdaterID allocates a new d.UpdaterID and returns the pointer to it.
func (d *Downtime) SetUpdaterID(v int) {
d.UpdaterID = &v
}

// GetAggregation returns the Aggregation field if non-nil, zero value otherwise.
func (e *Event) GetAggregation() string {
if e == nil || e.Aggregation == nil {
Expand Down
38 changes: 38 additions & 0 deletions downtimes.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ package datadog

import (
"fmt"
"strings"
)

// DowntimeType are a classification of a given downtime scope
type DowntimeType int

// The three downtime type classifications.
const (
StarDowntimeType DowntimeType = 0
HostDowntimeType DowntimeType = 1
OtherDowntimeType DowntimeType = 2
)

type Recurrence struct {
Expand All @@ -34,6 +45,33 @@ type Downtime struct {
Recurrence *Recurrence `json:"recurrence,omitempty"`
Scope []string `json:"scope,omitempty"`
Start *int `json:"start,omitempty"`
CreatorID *int `json:"creator_id,omitempty"`
UpdaterID *int `json:"updater_id,omitempty"`
Type *int `json:"downtime_type,omitempty"`
}

// DowntimeType returns the canonical downtime type classification.
// This is calculated based on the provided server response, but the logic is copied down here to calculate locally.
func (d *Downtime) DowntimeType() DowntimeType {
if d.Type != nil {
switch *d.Type {
case 0:
return StarDowntimeType
case 1:
return HostDowntimeType
default:
return OtherDowntimeType
}
}
if len(d.Scope) == 1 {
if d.Scope[0] == "*" {
return StarDowntimeType
}
if strings.HasPrefix(d.Scope[0], "host:") {
return HostDowntimeType
}
}
return OtherDowntimeType
}

// reqDowntimes retrieves a slice of all Downtimes.
Expand Down