Class: Nexpose::Schedule

Inherits:
Object
  • Object
show all
Defined in:
lib/nexpose/common.rb

Overview

Configuration structure for schedules.

Defined Under Namespace

Modules: Type

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Schedule.



117
118
119
120
121
122
# File 'lib/nexpose/common.rb', line 117

def initialize(type, interval, start, enabled = true)
  @type = type
  @interval = interval
  @start = start
  @enabled = enabled
end

Instance Attribute Details

#enabledObject

Whether or not this schedule is enabled.



101
102
103
# File 'lib/nexpose/common.rb', line 101

def enabled
  @enabled
end

#incrementalObject

Returns the value of attribute incremental.



114
115
116
# File 'lib/nexpose/common.rb', line 114

def incremental
  @incremental
end

#intervalObject

The repeat interval based upon type.



105
106
107
# File 'lib/nexpose/common.rb', line 105

def interval
  @interval
end

#max_durationObject

The amount of time, in minutes, to allow execution before stopping.



110
111
112
# File 'lib/nexpose/common.rb', line 110

def max_duration
  @max_duration
end

#not_valid_afterObject

The date after which the schedule is disabled, in ISO 8601 format.



112
113
114
# File 'lib/nexpose/common.rb', line 112

def not_valid_after
  @not_valid_after
end

#repeater_typeObject

Returns the value of attribute repeater_type.



115
116
117
# File 'lib/nexpose/common.rb', line 115

def repeater_type
  @repeater_type
end

#startObject

The earliest date to generate the report on (in ISO 8601 format).



107
108
109
# File 'lib/nexpose/common.rb', line 107

def start
  @start
end

#typeObject

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



103
104
105
# File 'lib/nexpose/common.rb', line 103

def type
  @type
end

Class Method Details

.parse(xml) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/nexpose/common.rb', line 141

def self.parse(xml)
  schedule = Schedule.new(xml.attributes['type'],
                          xml.attributes['interval'].to_i,
                          xml.attributes['start'],
                          xml.attributes['enabled'] != '0')

  # Optional parameters.
  schedule.max_duration = xml.attributes['maxDuration'].to_i if xml.attributes['maxDuration']
  schedule.not_valid_after = xml.attributes['notValidAfter'] if xml.attributes['notValidAfter']
  schedule.incremental = (xml.attributes['incremental'] && xml.attributes['incremental'] == '1')
  schedule.repeater_type = xml.attributes['repeaterType'] if xml.attributes['repeaterType']
  schedule
end

Instance Method Details

#as_xmlObject



124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/nexpose/common.rb', line 124

def as_xml
  xml = REXML::Element.new('Schedule')
  xml.attributes['enabled'] = @enabled ? 1 : 0
  xml.attributes['type'] = @type
  xml.attributes['interval'] = @interval
  xml.attributes['start'] = @start
  xml.attributes['maxDuration'] = @max_duration if @max_duration
  xml.attributes['notValidAfter'] = @not_valid_after if @not_valid_after
  xml.attributes['incremental'] = @incremental ? 1 : 0 if @incremental
  xml.attributes['repeaterType'] = @repeater_type if @repeater_type
  xml
end

#to_xmlObject



137
138
139
# File 'lib/nexpose/common.rb', line 137

def to_xml
  as_xml.to_s
end