Class: Nexpose::Schedule
Overview
Configuration structure for schedules.
Defined Under Namespace
Modules: Type
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#day ⇒ Object
Returns the value of attribute day.
-
#enabled ⇒ Object
Whether or not this schedule is enabled.
-
#hour ⇒ Object
Returns the value of attribute hour.
-
#incremental ⇒ Object
TODO: Remove this unused attribute.
-
#interval ⇒ Object
The repeat interval based upon type.
-
#is_extended ⇒ Object
Extended attributes added with the new scheduler implementation.
-
#max_duration ⇒ Object
The amount of time, in minutes, to allow execution before stopping.
-
#minute ⇒ Object
Returns the value of attribute minute.
-
#next_run_time ⇒ Object
Returns the value of attribute next_run_time.
-
#not_valid_after ⇒ Object
The date after which the schedule is disabled, in ISO 8601 format.
-
#occurrence ⇒ Object
Returns the value of attribute occurrence.
-
#repeater_type ⇒ Object
scan-schedule attributes.
-
#scan_template_id ⇒ Object
Returns the value of attribute scan_template_id.
-
#start ⇒ Object
The earliest date to generate the report on (in ISO 8601 format).
-
#start_month ⇒ Object
Returns the value of attribute start_month.
-
#timezone ⇒ Object
Returns the value of attribute timezone.
-
#type ⇒ Object
Valid schedule types: daily, hourly, monthly-date, monthly-day, weekly.
Class Method Summary collapse
Instance Method Summary collapse
- #as_xml ⇒ Object
-
#initialize(type, interval, start, enabled = true, scan_template_id = nil) ⇒ Schedule
constructor
A new instance of Schedule.
- #to_h ⇒ Object
- #to_xml ⇒ Object
Methods inherited from APIObject
Constructor Details
#initialize(type, interval, start, enabled = true, scan_template_id = nil) ⇒ Schedule
Returns a new instance of Schedule.
165 166 167 168 169 170 171 |
# File 'lib/nexpose/common.rb', line 165 def initialize(type, interval, start, enabled = true, scan_template_id = nil) @type = type @interval = interval @start = start @enabled = enabled @scan_template_id = scan_template_id end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
153 154 155 |
# File 'lib/nexpose/common.rb', line 153 def date @date end |
#day ⇒ Object
Returns the value of attribute day.
154 155 156 |
# File 'lib/nexpose/common.rb', line 154 def day @day end |
#enabled ⇒ Object
Whether or not this schedule is enabled.
133 134 135 |
# File 'lib/nexpose/common.rb', line 133 def enabled @enabled end |
#hour ⇒ Object
Returns the value of attribute hour.
151 152 153 |
# File 'lib/nexpose/common.rb', line 151 def hour @hour end |
#incremental ⇒ Object
TODO: Remove this unused attribute
147 148 149 |
# File 'lib/nexpose/common.rb', line 147 def incremental @incremental end |
#interval ⇒ Object
The repeat interval based upon type.
137 138 139 |
# File 'lib/nexpose/common.rb', line 137 def interval @interval end |
#is_extended ⇒ Object
Extended attributes added with the new scheduler implementation
150 151 152 |
# File 'lib/nexpose/common.rb', line 150 def is_extended @is_extended end |
#max_duration ⇒ Object
The amount of time, in minutes, to allow execution before stopping.
142 143 144 |
# File 'lib/nexpose/common.rb', line 142 def max_duration @max_duration end |
#minute ⇒ Object
Returns the value of attribute minute.
152 153 154 |
# File 'lib/nexpose/common.rb', line 152 def minute @minute end |
#next_run_time ⇒ Object
Returns the value of attribute next_run_time.
158 159 160 |
# File 'lib/nexpose/common.rb', line 158 def next_run_time @next_run_time end |
#not_valid_after ⇒ Object
The date after which the schedule is disabled, in ISO 8601 format.
144 145 146 |
# File 'lib/nexpose/common.rb', line 144 def not_valid_after @not_valid_after end |
#occurrence ⇒ Object
Returns the value of attribute occurrence.
155 156 157 |
# File 'lib/nexpose/common.rb', line 155 def occurrence @occurrence end |
#repeater_type ⇒ Object
scan-schedule attributes
161 162 163 |
# File 'lib/nexpose/common.rb', line 161 def repeater_type @repeater_type end |
#scan_template_id ⇒ Object
Returns the value of attribute scan_template_id.
162 163 164 |
# File 'lib/nexpose/common.rb', line 162 def scan_template_id @scan_template_id end |
#start ⇒ Object
The earliest date to generate the report on (in ISO 8601 format).
139 140 141 |
# File 'lib/nexpose/common.rb', line 139 def start @start end |
#start_month ⇒ Object
Returns the value of attribute start_month.
156 157 158 |
# File 'lib/nexpose/common.rb', line 156 def start_month @start_month end |
#timezone ⇒ Object
Returns the value of attribute timezone.
157 158 159 |
# File 'lib/nexpose/common.rb', line 157 def timezone @timezone end |
#type ⇒ Object
Valid schedule types: daily, hourly, monthly-date, monthly-day, weekly.
135 136 137 |
# File 'lib/nexpose/common.rb', line 135 def type @type end |
Class Method Details
.from_hash(hash) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/nexpose/common.rb', line 173 def self.from_hash(hash) start = nil start = Nexpose::ISO8601.to_time(hash[:start_date]) if hash[:start_date] repeat_scan_hash = hash[:repeat_scan] if repeat_scan_hash.nil? schedule = new('daily', 0, start) else schedule = new(repeat_scan_hash[:type], repeat_scan_hash[:interval], start) end schedule.enabled = hash[:enabled].nil? ? true : hash[:enabled] schedule.scan_template_id = hash[:scan_template_id] schedule.start = Nexpose::ISO8601.to_time(hash[:start_date]) if hash[:start_date] schedule.max_duration = hash[:maximum_scan_duration] if hash[:maximum_scan_duration] schedule.not_valid_after = Nexpose::ISO8601.to_time(hash[:not_valid_after_date]) if hash[:not_valid_after_date] schedule.timezone = hash[:time_zone] if hash[:time_zone] schedule.next_run_time = hash[:next_run_time] if hash[:next_run_time] unless repeat_scan_hash.nil? schedule.type = repeat_scan_hash[:type] schedule.interval = repeat_scan_hash[:interval] schedule.repeater_type = 'restart' if repeat_scan_hash[:on_repeat] == 'restart-scan' schedule.repeater_type = 'continue' if repeat_scan_hash[:on_repeat] == 'resume-scan' schedule.is_extended = repeat_scan_hash[:is_extended] if repeat_scan_hash[:is_extended] schedule.hour = repeat_scan_hash[:hour] if repeat_scan_hash[:hour] schedule.minute = repeat_scan_hash[:minute] if repeat_scan_hash[:minute] schedule.date = repeat_scan_hash[:date] if repeat_scan_hash[:date] schedule.day = repeat_scan_hash[:day] if repeat_scan_hash[:day] schedule.occurrence = repeat_scan_hash[:occurrence] if repeat_scan_hash[:occurrence] schedule.start_month = repeat_scan_hash[:start_month] if repeat_scan_hash[:start_month] end schedule end |
.parse(xml) ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/nexpose/common.rb', line 268 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.scan_template_id = xml.attributes['template'] if xml.attributes['template'] schedule end |
Instance Method Details
#as_xml ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/nexpose/common.rb', line 242 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'] = @scan_template_id if @scan_template_id xml end |
#to_h ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/nexpose/common.rb', line 208 def to_h schedule_hash = { enabled: @enabled, scan_template_id: @scan_template_id, maximum_scan_duration: @max_duration } schedule_hash[:start_date] = Nexpose::ISO8601.to_string(@start) if @start schedule_hash[:not_valid_after_date] = Nexpose::ISO8601.to_string(@not_valid_after) if @not_valid_after schedule_hash[:time_zone] = @timezone if @timezone unless (@type.nil? || @interval == 0) && !@is_extended repeat_scan_hash = { type: @type, interval: @interval } repeat_scan_hash[:on_repeat] = 'restart-scan' if @repeater_type == 'restart' repeat_scan_hash[:on_repeat] = 'resume-scan' if @repeater_type == 'continue' if @is_extended repeat_scan_hash[:is_extended] = @is_extended repeat_scan_hash[:hour] = @hour if @hour repeat_scan_hash[:minute] = @minute if @minute repeat_scan_hash[:date] = @date if @date repeat_scan_hash[:day] = @day if @day repeat_scan_hash[:occurrence] = @occurrence if @occurrence repeat_scan_hash[:start_month] = @start_month if @start_month end schedule_hash[:repeat_scan] = repeat_scan_hash end schedule_hash end |
#to_xml ⇒ Object
264 265 266 |
# File 'lib/nexpose/common.rb', line 264 def to_xml as_xml.to_s end |