Class: Wavefront::MaintenanceWindow

Inherits:
CoreApi
  • Object
show all
Defined in:
lib/wavefront-sdk/maintenancewindow.rb

Overview

Manage and query Wavefront maintenance windows

Instance Attribute Summary

Attributes inherited from CoreApi

#api, #creds, #logger, #opts

Instance Method Summary collapse

Methods inherited from CoreApi

#api_base, #api_path, #hash_for_update, #initialize, #setup_api, #time_to_ms

Methods included from Mixins

#log, #parse_relative_time, #parse_time, #relative_time, #time_multiplier, #valid_relative_time?

Methods included from Validators

#uuid?, #wf_account_id?, #wf_alert_id?, #wf_alert_severity?, #wf_apitoken_id?, #wf_aws_external_id?, #wf_cloudintegration_id?, #wf_dashboard_id?, #wf_derivedmetric_id?, #wf_distribution?, #wf_distribution_count?, #wf_distribution_interval?, #wf_distribution_values?, #wf_epoch?, #wf_event_id?, #wf_granularity?, #wf_ingestionpolicy_id?, #wf_integration_id?, #wf_link_id?, #wf_link_template?, #wf_maintenance_window_id?, #wf_message_id?, #wf_metric_name?, #wf_metricspolicy_id?, #wf_monitoredcluster_id?, #wf_ms_ts?, #wf_name?, #wf_notificant_id?, #wf_permission?, #wf_point?, #wf_point_tag?, #wf_point_tags?, #wf_proxy_id?, #wf_role_id?, #wf_sampling_value?, #wf_savedsearch_entity?, #wf_savedsearch_id?, #wf_serviceaccount_id?, #wf_source_id?, #wf_string?, #wf_tag?, #wf_trace?, #wf_ts?, #wf_user_id?, #wf_usergroup_id?, #wf_value?, #wf_version?, #wf_webhook_id?

Constructor Details

This class inherits a constructor from Wavefront::CoreApi

Instance Method Details

#create(body) ⇒ Wavefront::Response

POST /api/v2/maintenancewindow Create a maintenance window.

We used to validate input here but do not any more.

Parameters:

  • body (Hash)

    a hash of parameters describing the window. Please refer to the Wavefront Swagger docs for key:value information

Returns:

Raises:

  • (ArgumentError)


35
36
37
38
39
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 35

def create(body)
  raise ArgumentError unless body.is_a?(Hash)

  api.post('', body, 'application/json')
end

#delete(id) ⇒ Wavefront::Response

DELETE /api/v2/maintenancewindow/id Delete a specific maintenance window.

Parameters:

  • id (String, Integer)

    ID of the maintenance window

Returns:



47
48
49
50
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 47

def delete(id)
  wf_maintenance_window_id?(id)
  api.delete(id)
end

#describe(id) ⇒ Wavefront::Response

GET /api/v2/maintenancewindow/id Get a specific maintenance window.

Parameters:

  • id (String, Integer)

    ID of the maintenance window

Returns:



58
59
60
61
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 58

def describe(id)
  wf_maintenance_window_id?(id)
  api.get(id)
end

#list(offset = 0, limit = 100) ⇒ Object

GET /api/v2/maintenancewindow Get all maintenance windows for a customer.

Parameters:

  • offset (Integer) (defaults to: 0)

    window at which the list begins

  • limit (Integer) (defaults to: 100)

    the number of window to return



21
22
23
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 21

def list(offset = 0, limit = 100)
  api.get('', offset: offset, limit: limit)
end

#ongoingWavefront::Response

Windows currently open.

Returns:



87
88
89
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 87

def ongoing
  windows_in_state(:ongoing)
end

#pending(hours = 24) ⇒ Wavefront::Response

Get the windows which will be open in the next so-many hours

Parameters:

  • hours (Numeric) (defaults to: 24)

    how many hours to look ahead

Returns:



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 95

def pending(hours = 24)
  cutoff = Time.now.to_i + (hours * 3600)

  ret = windows_in_state(:pending)

  return if opts[:noop]

  ret.tap do |r|
    r.response.items.delete_if { |w| w.startTimeInSeconds > cutoff }
  end
end

#summaryWavefront::Response

This method mimics the similarly named method from the v1 SDK, which called the ‘GET /api/alert/maintenancewindow/summary’ path.

Returns:



112
113
114
115
116
117
118
119
120
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 112

def summary
  ret = pending

  items = { UPCOMING: ret.response.items,
            CURRENT: ongoing.response.items }

  ret.response.items = items
  ret
end

#update(id, body, modify = true) ⇒ Wavefront::Response

PUT /api/v2/maintenancewindow/id Update a specific maintenance window.

Parameters:

  • id (String)

    a Wavefront maintenance window ID

  • body (Hash)

    key-value hash of the parameters you wish to change

  • modify (true, false) (defaults to: true)

    if true, use #describe() to get a hash describing the existing object, and modify that with the new body. If false, pass the new body straight through.

Returns:

Raises:

  • (ArgumentError)


74
75
76
77
78
79
80
81
82
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 74

def update(id, body, modify = true)
  wf_maintenance_window_id?(id)
  raise ArgumentError unless body.is_a?(Hash)

  return api.put(id, body, 'application/json') unless modify

  api.put(id, hash_for_update(describe(id).response, body),
          'application/json')
end

#update_keysObject



10
11
12
13
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 10

def update_keys
  %i[id reason title startTimeInSeconds endTimeInSeconds
     relevantCustomerTags relevantHostTags relevantHostNames]
end

#windows_in_state(state) ⇒ Wavefront::Response

Return all maintenance windows in the given state. At the time of writing valid states are ONGOING, PENDING, and ENDED.

Parameters:

  • state (Symbol)

Returns:



127
128
129
130
131
132
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 127

def windows_in_state(state)
  require_relative 'search'
  wfs = Wavefront::Search.new(creds, opts)
  query = { key: 'runningState', value: state, matchingMethod: 'EXACT' }
  wfs.search(:maintenancewindow, query, limit: :all, offset: PAGE_SIZE)
end