Class: Nexpose::Schedule
Overview
Configuration structure for schedules.
Defined Under Namespace
Modules: Type
Instance Attribute Summary collapse
-
#console_start ⇒ Object
Starting time of the scheduled scan (in ISO 8601 format).
-
#console_timezone ⇒ Object
The timezone of the console.
-
#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.
-
#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
Scan template to use when starting a scan job.
-
#start ⇒ Object
Starting time of the scheduled scan (in ISO 8601 format).
-
#start_month ⇒ Object
Returns the value of attribute start_month.
-
#timezone ⇒ Object
Timezone in which start time run.
-
#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.
171 172 173 174 175 176 177 |
# File 'lib/nexpose/common.rb', line 171 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
#console_start ⇒ Object
Starting time of the scheduled scan (in ISO 8601 format). Relative to the console timezone
166 167 168 |
# File 'lib/nexpose/common.rb', line 166 def console_start @console_start end |
#console_timezone ⇒ Object
The timezone of the console.
168 169 170 |
# File 'lib/nexpose/common.rb', line 168 def console_timezone @console_timezone end |
#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.
138 139 140 |
# File 'lib/nexpose/common.rb', line 138 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 |
#interval ⇒ Object
The repeat interval based upon type.
142 143 144 |
# File 'lib/nexpose/common.rb', line 142 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.
146 147 148 |
# File 'lib/nexpose/common.rb', line 146 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.
160 161 162 |
# File 'lib/nexpose/common.rb', line 160 def next_run_time @next_run_time end |
#not_valid_after ⇒ Object
The date after which the schedule is disabled, in ISO 8601 format.
148 149 150 |
# File 'lib/nexpose/common.rb', line 148 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
162 163 164 |
# File 'lib/nexpose/common.rb', line 162 def repeater_type @repeater_type end |
#scan_template_id ⇒ Object
Scan template to use when starting a scan job.
164 165 166 |
# File 'lib/nexpose/common.rb', line 164 def scan_template_id @scan_template_id end |
#start ⇒ Object
Starting time of the scheduled scan (in ISO 8601 format).
144 145 146 |
# File 'lib/nexpose/common.rb', line 144 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
Timezone in which start time run. If not set will default to console timezone. If console timezone is not supported it defaults to utc.
159 160 161 |
# File 'lib/nexpose/common.rb', line 159 def timezone @timezone end |
#type ⇒ Object
Valid schedule types: daily, hourly, monthly-date, monthly-day, weekly.
140 141 142 |
# File 'lib/nexpose/common.rb', line 140 def type @type end |
Class Method Details
.from_hash(hash) ⇒ Object
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 207 208 209 210 211 212 213 |
# File 'lib/nexpose/common.rb', line 179 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] schedule.console_start = Nexpose::ISO8601.to_time(hash[:console_start_date]) if hash[:console_start_date] schedule.console_timezone = hash[:console_time_zone] if hash[:console_time_zone] 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
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/nexpose/common.rb', line 272 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.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
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/nexpose/common.rb', line 247 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['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
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 241 242 243 244 245 |
# File 'lib/nexpose/common.rb', line 215 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.to_i.zero?) && !@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
268 269 270 |
# File 'lib/nexpose/common.rb', line 268 def to_xml as_xml.to_s end |