Class: Wavefront::MaintenanceWindow
- Defined in:
- lib/wavefront-sdk/maintenancewindow.rb
Overview
Manage and query Wavefront maintenance windows
Instance Attribute Summary
Attributes inherited from CoreApi
Instance Method Summary collapse
-
#create(body) ⇒ Wavefront::Response
POST /api/v2/maintenancewindow Create a maintenance window.
-
#delete(id) ⇒ Wavefront::Response
DELETE /api/v2/maintenancewindow/id Delete a specific maintenance window.
-
#describe(id) ⇒ Wavefront::Response
GET /api/v2/maintenancewindow/id Get a specific maintenance window.
-
#list(offset = 0, limit = 100) ⇒ Object
GET /api/v2/maintenancewindow Get all maintenance windows for a customer.
-
#ongoing ⇒ Wavefront::Response
Windows currently open.
-
#pending(hours = 24) ⇒ Wavefront::Response
Get the windows which will be open in the next so-many hours.
-
#summary ⇒ Wavefront::Response
This method mimics the similarly named method from the v1 SDK, which called the ‘GET /api/alert/maintenancewindow/summary’ path.
-
#update(id, body, modify = true) ⇒ Wavefront::Response
PUT /api/v2/maintenancewindow/id Update a specific maintenance window.
- #update_keys ⇒ Object
-
#windows_in_state(state) ⇒ Wavefront::Response
Return all maintenance windows in the given state.
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
#wf_alert_id?, #wf_alert_severity?, #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_integration_id?, #wf_link_id?, #wf_link_template?, #wf_maintenance_window_id?, #wf_message_id?, #wf_metric_name?, #wf_ms_ts?, #wf_name?, #wf_notificant_id?, #wf_point?, #wf_point_tag?, #wf_point_tags?, #wf_proxy_id?, #wf_savedsearch_entity?, #wf_savedsearch_id?, #wf_source_id?, #wf_string?, #wf_tag?, #wf_ts?, #wf_user_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.
33 34 35 36 |
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 33 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.
44 45 46 47 |
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 44 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.
55 56 57 58 |
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 55 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.
19 20 21 |
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 19 def list(offset = 0, limit = 100) api.get('', offset: offset, limit: limit) end |
#ongoing ⇒ Wavefront::Response
Windows currently open.
84 85 86 |
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 84 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
92 93 94 95 96 97 98 |
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 92 def pending(hours = 24) cutoff = Time.now.to_i + hours * 3600 windows_in_state(:pending).tap do |r| r.response.items.delete_if { |w| w.startTimeInSeconds > cutoff } end end |
#summary ⇒ Wavefront::Response
This method mimics the similarly named method from the v1 SDK, which called the ‘GET /api/alert/maintenancewindow/summary’ path.
105 106 107 108 109 110 111 112 113 |
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 105 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.
71 72 73 74 75 76 77 78 79 |
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 71 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_keys ⇒ Object
8 9 10 11 |
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 8 def update_keys i[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.
120 121 122 123 124 125 |
# File 'lib/wavefront-sdk/maintenancewindow.rb', line 120 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 |