Class: OpenvasCli::VasTask
Instance Attribute Summary collapse
Attributes inherited from VasBase
#id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from VasBase
#destroy, #destroy!, get_by_id, #initialize, #new_record?, #reset_changes, #save, #save!, #to_key, #to_param, #update_attributes
Methods included from ConnAddin
included
Methods included from XmlAddin
included
Instance Attribute Details
Returns the value of attribute comment.
7
8
9
|
# File 'lib/openvas-cli/vas_task.rb', line 7
def
end
|
#config_id ⇒ Object
Returns the value of attribute config_id.
11
12
13
|
# File 'lib/openvas-cli/vas_task.rb', line 11
def config_id
@config_id
end
|
#last_report_id ⇒ Object
Returns the value of attribute last_report_id.
10
11
12
|
# File 'lib/openvas-cli/vas_task.rb', line 10
def last_report_id
@last_report_id
end
|
#name ⇒ Object
Returns the value of attribute name.
6
7
8
|
# File 'lib/openvas-cli/vas_task.rb', line 6
def name
@name
end
|
#schedule_id ⇒ Object
Returns the value of attribute schedule_id.
13
14
15
|
# File 'lib/openvas-cli/vas_task.rb', line 13
def schedule_id
@schedule_id
end
|
#status ⇒ Object
Returns the value of attribute status.
8
9
10
|
# File 'lib/openvas-cli/vas_task.rb', line 8
def status
@status
end
|
#target_id ⇒ Object
Returns the value of attribute target_id.
12
13
14
|
# File 'lib/openvas-cli/vas_task.rb', line 12
def target_id
@target_id
end
|
#times_run ⇒ Object
Returns the value of attribute times_run.
9
10
11
|
# File 'lib/openvas-cli/vas_task.rb', line 9
def times_run
@times_run
end
|
Class Method Details
.from_xml_node(node) ⇒ Object
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
# File 'lib/openvas-cli/vas_task.rb', line 203
def self.from_xml_node(node)
t = VasTask.new
t.id = ("@id", node)
t.name = ("name", node)
t. = ("comment", node)
t.status = ("status", node)
if node.at_xpath("progress")
t.progress = VasTaskProgress.from_xml_node(node.at_xpath("progress"))
end
t.times_run = ("report_count/finished", node).to_i
t.last_report_id = ("last_report/report/@id", node)
t.config_id = ("config/@id", node)
t.target_id = ("target/@id", node)
node.xpath("reports/report").each { |xr|
t.reports << VasReport.new({
:id => ("@id", xr),
:started_at => ("timestamp", xr)
})
}
t.reset_changes
t
end
|
.get_all(options = {}) ⇒ Object
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
# File 'lib/openvas-cli/vas_task.rb', line 184
def self.get_all(options = {})
params = {:apply_overrides => 0, :sort_field => "name"}
params[:task_id] = options[:id] if options[:id]
req = Nokogiri::XML::Builder.new { |xml|
xml.get_tasks(params)
}
tasks = connection.send_receive(req.doc)
ret = []
tasks.xpath('//task').each { |t|
ret << from_xml_node(t)
}
ret
end
|
Instance Method Details
#config ⇒ Object
57
58
59
|
# File 'lib/openvas-cli/vas_task.rb', line 57
def config
@config ||= pull_my_config
end
|
#config=(val) ⇒ Object
61
62
63
64
|
# File 'lib/openvas-cli/vas_task.rb', line 61
def config=(val)
@config = val
config_id = val.id if val
end
|
#create_or_update ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/openvas-cli/vas_task.rb', line 79
def create_or_update
if schedule && schedule.changed?
return unless schedule.save
schedule_id = schedule.id
end
if config && config.changed?
return unless config.save
config_id = config.id
end
req = Nokogiri::XML::Builder.new { |xml|
if @id
xml.modify_task(:id => @id) {
xml.name { xml.text(@name) } if name_changed?
xml. { xml.text() } if
xml.schedule(:id => @schedule_id) if schedule_id && !schedule_id.blank? && schedule_id_changed?
}
else
xml.create_task {
xml.name { xml.text(@name) } if @name
xml. { xml.text() } if
xml.config(:id => @config_id)
xml.target(:id => @target_id)
xml.schedule(:id => @schedule_id) if @schedule_id && !@schedule_id.blank?
}
end
}
begin
resp = VasTask.connection.send_receive(req.doc)
@id = VasTask.("/create_task_response/@id", resp) unless @id
reset_changes
true
rescue VasExceptions::CommandException => e
errors[:command_failure] << e.message
nil
end
end
|
#delete_record ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/openvas-cli/vas_task.rb', line 124
def delete_record
req = Nokogiri::XML::Builder.new { |xml|
xml.delete_task(:task_id => @id)
}
begin
VasTask.connection.send_receive(req.doc)
true
rescue VasExceptions::CommandException => e
errors[:command_failure] << e.message
nil
end
end
|
#pause ⇒ Object
168
169
170
171
172
173
174
|
# File 'lib/openvas-cli/vas_task.rb', line 168
def pause
req = Nokogiri::XML::Builder.new { |xml|
xml.pause_task(:task_id => @id)
}
VasTask.connection.send_receive(req.doc)
end
|
#progress(refresh = false) ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/openvas-cli/vas_task.rb', line 152
def progress(refresh=false)
if refresh == true || @progress == nil
params = {:apply_overrides => 0, :sort_field => "name"}
params[:task_id] = options[:task_id] if options[:task_id]
req = Nokogiri::XML::Builder.new { |xml|
xml.get_tasks
}
task = VasTask.connection.send_receive(req.doc)
@progress = VasTaskProgress.from_xml_node task.at_xpath('/get_tasks_response/task/progress')
end
@progress
end
|
#progress=(val) ⇒ Object
148
149
150
|
# File 'lib/openvas-cli/vas_task.rb', line 148
def progress=(val)
@progress = val
end
|
#reports ⇒ Object
75
76
77
|
# File 'lib/openvas-cli/vas_task.rb', line 75
def reports
@reports ||= []
end
|
#schedule ⇒ Object
48
49
50
|
# File 'lib/openvas-cli/vas_task.rb', line 48
def schedule
@schedule ||= pull_my_schedule
end
|
#schedule=(v) ⇒ Object
52
53
54
55
|
# File 'lib/openvas-cli/vas_task.rb', line 52
def schedule=(v)
@schedule = v
schedule_id = v ? v.id : nil
end
|
#start ⇒ Object
140
141
142
143
144
145
146
|
# File 'lib/openvas-cli/vas_task.rb', line 140
def start
req = Nokogiri::XML::Builder.new { |xml|
xml.resume_or_start_task(:task_id => @id)
}
VasTask.connection.send_receive(req.doc)
end
|
#stop ⇒ Object
176
177
178
179
180
181
182
|
# File 'lib/openvas-cli/vas_task.rb', line 176
def stop
req = Nokogiri::XML::Builder.new { |xml|
xml.stop_task(:task_id => @id)
}
VasTask.connection.send_receive(req.doc)
end
|
#target ⇒ Object
66
67
68
|
# File 'lib/openvas-cli/vas_task.rb', line 66
def target
@target ||= pull_my_target
end
|
#target=(val) ⇒ Object
70
71
72
73
|
# File 'lib/openvas-cli/vas_task.rb', line 70
def target=(val)
@target = val
target_id = val.id if val
end
|