Class: Nexpose::Blackout

Inherits:
APIObject show all
Defined in:
lib/nexpose/blackout.rb

Overview

Constants useful across the Nexpose module. Configuration structure for blackouts.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from APIObject

#object_from_hash

Constructor Details

#initialize(start, enabled = true, duration, type, interval) ⇒ Blackout

Returns a new instance of Blackout.



17
18
19
20
21
22
23
# File 'lib/nexpose/blackout.rb', line 17

def initialize(start, enabled = true, duration, type, interval)
  @blackout_start    = start
  @enabled           = enabled
  @blackout_duration = duration.to_i
  @blackout_type     = type
  @blackout_interval = interval.to_i
end

Instance Attribute Details

#blackout_durationObject

The amount of time, in minutes, a blackout period should last.



15
16
17
# File 'lib/nexpose/blackout.rb', line 15

def blackout_duration
  @blackout_duration
end

#blackout_intervalObject

The repeat interval based upon type.



10
11
12
# File 'lib/nexpose/blackout.rb', line 10

def blackout_interval
  @blackout_interval
end

#blackout_startObject

Starting time of the blackout (in unix epoch with milliseconds. Example: 1464956590000) The timezone is the timezone of the console. If the console timezone is not supported it defaults to utc.



13
14
15
# File 'lib/nexpose/blackout.rb', line 13

def blackout_start
  @blackout_start
end

#blackout_typeObject

Valid schedule types: daily, hourly, monthly-date, monthly-day, weekly.



8
9
10
# File 'lib/nexpose/blackout.rb', line 8

def blackout_type
  @blackout_type
end

#enabledObject

Whether or not this blackout is enabled.



6
7
8
# File 'lib/nexpose/blackout.rb', line 6

def enabled
  @enabled
end

Class Method Details

.from_hash(hash) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/nexpose/blackout.rb', line 25

def self.from_hash(hash)
  repeat_blackout_hash = hash[:repeat_blackout]
  if repeat_blackout_hash.nil?
    type     = 'daily'
    interval = 0
  else
    type     = repeat_blackout_hash[:type]
    interval = repeat_blackout_hash[:interval]
  end
  new(hash[:start_date], hash[:enabled], hash[:blackout_duration], type, interval)
end

Instance Method Details

#to_hObject



37
38
39
40
41
42
# File 'lib/nexpose/blackout.rb', line 37

def to_h
  blackout_hash = { start_date: @blackout_start, enabled: @enabled, blackout_duration: @blackout_duration }
  repeat_hash   = { type: @blackout_type, interval: @blackout_interval }
  blackout_hash[:repeat_blackout] = repeat_hash
  blackout_hash
end