Class: Nexpose::Schedule

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

Overview

Configuration structure for schedules.

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.



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

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.



92
93
94
# File 'lib/nexpose/common.rb', line 92

def enabled
  @enabled
end

#incrementalObject

– TODO These are not captured or put to XML. ++



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

def incremental
  @incremental
end

#intervalObject

The repeat interval based upon type.



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

def interval
  @interval
end

#max_durationObject

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



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

def max_duration
  @max_duration
end

#not_valid_afterObject

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



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

def not_valid_after
  @not_valid_after
end

#repeater_typeObject

Returns the value of attribute repeater_type.



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

def repeater_type
  @repeater_type
end

#startObject

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



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

def start
  @start
end

#typeObject

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



94
95
96
# File 'lib/nexpose/common.rb', line 94

def type
  @type
end

Class Method Details

.parse(xml) ⇒ Object



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

def self.parse(xml)
  xml.elements.each('//Schedule') do |sched|
    schedule = Schedule.new(sched.attributes['type'],
                            sched.attributes['interval'].to_i,
                            sched.attributes['start'],
                            sched.attributes['enabled'] || true)
    # Optional parameters.
    schedule.max_duration = sched.attributes['maxDuration'].to_i if sched.attributes['maxDuration']
    schedule.not_valid_after = sched.attributes['notValidAfter'] if sched.attributes['notValidAfter']
    return schedule
  end
end

Instance Method Details

#to_xmlObject



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

def to_xml
  xml = %Q{<Schedule enabled='#{@enabled ? 1 : 0}' type='#{@type}' interval='#{@interval}' start='#{@start}'}
  xml << %Q{ maxDuration='#@max_duration'} if @max_duration
  xml << %Q{ notValidAfter='#@not_valid_after'} if @not_valid_after
  xml << '/>'
end