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

chore(monitors): add disabled property #327

Merged
merged 4 commits into from
Jul 30, 2024
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
46 changes: 24 additions & 22 deletions axiom/monitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,38 +108,40 @@ func (c *MonitorType) UnmarshalJSON(b []byte) (err error) {
type Monitor struct {
// ID is the unique ID of the monitor.
ID string `json:"id,omitempty"`
// CreatedAt is the time when the monitor was created.
CreatedAt time.Time `json:"createdAt"`
// CreatedBy is the ID of the user who created the monitor.
CreatedBy string `json:"createdBy"`
// Name is the name of the monitor.
Name string `json:"name"`
// Type sets the type of monitor. Defaults to [Threshold]
Type MonitorType `json:"type"`
// Description of the monitor.
Description string `json:"description,omitempty"`

// APLQuery is the APL query to use for the monitor.
APLQuery string `json:"aplQuery"`
// Operator is the operator to use for the monitor.
Operator Operator `json:"operator"`
// Threshold the query result is compared against, which evaluates if the monitor acts or not.
Threshold float64 `json:"threshold"`
// AlertOnNoData indicates whether to alert on no data.
AlertOnNoData bool `json:"alertOnNoData"`
// NotifyByGroup tracks each none-time group independently
// NotifyByGroup tracks each non-time group independently.
NotifyByGroup bool `json:"notifyByGroup"`
// Resolvable determines whether the events triggered by the monitor
// are resolvable. This has no effect on threshold monitors
// Resolvable determines whether the events triggered by the monitor are resolvable. This has no effect on threshold monitors.
Resolvable bool `json:"resolvable"`
// APLQuery is the APL query to use for the monitor.
APLQuery string `json:"aplQuery"`
// Description of the monitor.
Description string `json:"description,omitempty"`
// DisabledUntil is the time that the monitor will be disabled until.
DisabledUntil time.Time `json:"disabledUntil"`
// Interval is the interval in minutes in which the monitor will run.
Interval time.Duration `json:"IntervalMinutes"`
// Name is the name of the monitor.
Name string `json:"name"`
// NotifierIDs attached to the monitor.
NotifierIDs []string `json:"NotifierIDs"`
// Operator is the operator to use for the monitor.
Operator Operator `json:"operator"`

// Interval is the interval in minutes in which the monitor will run.
Interval time.Duration `json:"IntervalMinutes"`
// Range the monitor goes back in time and looks at the data it acts on.
Range time.Duration `json:"RangeMinutes"`
// Threshold the query result is compared against, which evaluates if the
// monitor acts or not.
Threshold float64 `json:"threshold"`
// CreatedAt is the time when the monitor was created.
CreatedAt time.Time `json:"createdAt"`
// CreatedBy is the id of the user who created the monitor.
CreatedBy string `json:"createdBy"`
// Disabled sets whether the monitor is disabled or not.
Disabled bool `json:"disabled"`
// DisabledUntil is the time that the monitor will be disabled until.
DisabledUntil time.Time `json:"disabledUntil"`
}

// MarshalJSON implements [json.Marshaler]. It is in place to marshal the
Expand Down
32 changes: 32 additions & 0 deletions axiom/monitors_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (s *MonitorsTestSuite) Test() {
}

func (s *MonitorsTestSuite) TestCreateMatchMonitor() {
// Create the monitor
monitor, err := s.client.Monitors.Create(s.ctx, axiom.MonitorCreateRequest{
Monitor: axiom.Monitor{
AlertOnNoData: false,
Expand All @@ -137,4 +138,35 @@ func (s *MonitorsTestSuite) TestCreateMatchMonitor() {
s.Require().NoError(err)
s.Require().NotNil(monitor)
s.Equal(axiom.MonitorTypeMatchEvent.String(), monitor.Type.String())
s.Equal(false, monitor.Disabled)

// Disable the match monitor
monitor.Disabled = true
updatedMonitor, err := s.client.Monitors.Update(s.ctx, monitor.ID, axiom.MonitorUpdateRequest{
Monitor: *monitor,
})
s.Require().NoError(err)
s.Require().NotNil(updatedMonitor)
s.True(updatedMonitor.Disabled, "monitor should be disabled")

// Verify the monitor is disabled
monitor, err = s.client.Monitors.Get(s.ctx, monitor.ID)
s.Require().NoError(err)
s.Require().NotNil(monitor)
s.True(monitor.Disabled, "monitor should be disabled")

// Re-enable the match monitor
monitor.Disabled = false
updatedMonitor, err = s.client.Monitors.Update(s.ctx, monitor.ID, axiom.MonitorUpdateRequest{
Monitor: *monitor,
})
s.Require().NoError(err)
s.Require().NotNil(updatedMonitor)
s.False(updatedMonitor.Disabled, "monitor should be enabled")

// Verify the monitor is re-enabled
monitor, err = s.client.Monitors.Get(s.ctx, monitor.ID)
s.Require().NoError(err)
s.Require().NotNil(monitor)
s.False(monitor.Disabled, "monitor should be enabled")
Rambatino marked this conversation as resolved.
Show resolved Hide resolved
}
Loading