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.



125
126
127
128
129
130
# File 'lib/nexpose/common.rb', line 125

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

Instance Attribute Details

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#dayObject

Returns the value of attribute day.



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

def day
  @day
end

#enabledObject

Whether or not this schedule is enabled.



97
98
99
# File 'lib/nexpose/common.rb', line 97

def enabled
  @enabled
end

#hourObject

Returns the value of attribute hour.



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

def hour
  @hour
end

#incrementalObject

Returns the value of attribute incremental.



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

def incremental
  @incremental
end

#intervalObject

The repeat interval based upon type.



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

def interval
  @interval
end

#is_extendedObject

Extended attributes added with the new scheduler implementation



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

def is_extended
  @is_extended
end

#max_durationObject

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



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

def max_duration
  @max_duration
end

#minuteObject

Returns the value of attribute minute.



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

def minute
  @minute
end

#next_run_timeObject

Returns the value of attribute next_run_time.



122
123
124
# File 'lib/nexpose/common.rb', line 122

def next_run_time
  @next_run_time
end

#not_valid_afterObject

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



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

def not_valid_after
  @not_valid_after
end

#occurrenceObject

Returns the value of attribute occurrence.



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

def occurrence
  @occurrence
end

#repeater_typeObject

Returns the value of attribute repeater_type.



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

def repeater_type
  @repeater_type
end

#startObject

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



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

def start
  @start
end

#start_monthObject

Returns the value of attribute start_month.



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

def start_month
  @start_month
end

#templateObject

Returns the value of attribute template.



123
124
125
# File 'lib/nexpose/common.rb', line 123

def template
  @template
end

#timezoneObject

Returns the value of attribute timezone.



121
122
123
# File 'lib/nexpose/common.rb', line 121

def timezone
  @timezone
end

#typeObject

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



99
100
101
# File 'lib/nexpose/common.rb', line 99

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object



132
133
134
135
136
137
138
# File 'lib/nexpose/common.rb', line 132

def self.from_hash(hash)
  schedule = new(hash[:type], hash[:interval], hash[:start])
  hash.each do |k, v|
    schedule.instance_variable_set("@#{k}", v)
  end
  schedule
end

.parse(xml) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/nexpose/common.rb', line 166

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.is_extended = xml.attributes['is_extended'] if xml.attributes['is_extended']
  schedule.hour = xml.attributes['hour'] if xml.attributes['hour']
  schedule.minute = xml.attributes['minute'] if xml.attributes['minute']
  schedule.date = xml.attributes['date'] if xml.attributes['date']
  schedule.day = xml.attributes['day'] if xml.attributes['day']
  schedule.occurrence = xml.attributes['occurrence'] if xml.attributes['occurrence']
  schedule.start_month = xml.attributes['start_month'] if xml.attributes['start_month']
  schedule.timezone = xml.attributes['timezone'] if xml.attributes['timezone']
  schedule.next_run_time = xml.attributes['next_run_time'] if xml.attributes['next_run_time']
  schedule.template = xml.attributes['template'] if xml.attributes['template']
  schedule
end

Instance Method Details

#as_xmlObject



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/nexpose/common.rb', line 140

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 if @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.attributes['is_extended'] = @is_extended if @is_extended
  xml.attributes['hour'] = @hour if @hour
  xml.attributes['minute'] = @minute if @minute
  xml.attributes['date'] = @date if @date
  xml.attributes['day'] = @day if @day
  xml.attributes['occurrence'] = @occurrence if @occurrence
  xml.attributes['start_month'] = @start_month if @start_month
  xml.attributes['timezone'] = @timezone if @timezone
  xml.attributes['template'] = @template if @template
  xml
end

#to_xmlObject



162
163
164
# File 'lib/nexpose/common.rb', line 162

def to_xml
  as_xml.to_s
end