@@ 333-445 (lines=113) @@ | ||
330 | cmd.add_element("copy", agent_id) |
|
331 | return self._send_xml_command(cmd) |
|
332 | ||
333 | def create_alert( |
|
334 | self, |
|
335 | name: str, |
|
336 | condition: AlertCondition, |
|
337 | event: AlertEvent, |
|
338 | method: AlertMethod, |
|
339 | *, |
|
340 | method_data: Optional[dict] = None, |
|
341 | event_data: Optional[dict] = None, |
|
342 | condition_data: Optional[dict] = None, |
|
343 | filter_id: Optional[int] = None, |
|
344 | comment: Optional[str] = None |
|
345 | ) -> Any: |
|
346 | """Create a new alert |
|
347 | ||
348 | Arguments: |
|
349 | name: Name of the new Alert |
|
350 | condition: The condition that must be satisfied for the alert |
|
351 | to occur; if the event is either 'Updated SecInfo arrived' or |
|
352 | 'New SecInfo arrived', condition must be 'Always'. Otherwise, |
|
353 | condition can also be on of 'Severity at least', 'Filter count |
|
354 | changed' or 'Filter count at least'. |
|
355 | event: The event that must happen for the alert to occur, one |
|
356 | of 'Task run status changed', 'Updated SecInfo arrived' or 'New |
|
357 | SecInfo arrived' |
|
358 | method: The method by which the user is alerted, one of 'SCP', |
|
359 | 'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; if the event is |
|
360 | neither 'Updated SecInfo arrived' nor 'New SecInfo arrived', |
|
361 | method can also be one of 'Start Task', 'HTTP Get', 'Sourcefire |
|
362 | Connector' or 'verinice Connector'. |
|
363 | condition_data: Data that defines the condition |
|
364 | event_data: Data that defines the event |
|
365 | method_data: Data that defines the method |
|
366 | filter_id: Filter to apply when executing alert |
|
367 | comment: Comment for the alert |
|
368 | ||
369 | Returns: |
|
370 | The response. See :py:meth:`send_command` for details. |
|
371 | """ |
|
372 | if not name: |
|
373 | raise RequiredArgument( |
|
374 | function=self.create_alert.__name__, argument='name' |
|
375 | ) |
|
376 | ||
377 | if not condition: |
|
378 | raise RequiredArgument( |
|
379 | function=self.create_alert.__name__, argument='condition' |
|
380 | ) |
|
381 | ||
382 | if not event: |
|
383 | raise RequiredArgument( |
|
384 | function=self.create_alert.__name__, argument='event' |
|
385 | ) |
|
386 | ||
387 | if not method: |
|
388 | raise RequiredArgument( |
|
389 | function=self.create_alert.__name__, argument='method' |
|
390 | ) |
|
391 | ||
392 | if not isinstance(condition, AlertCondition): |
|
393 | raise InvalidArgumentType( |
|
394 | function=self.create_alert.__name__, |
|
395 | argument='condition', |
|
396 | arg_type=AlertCondition.__name__, |
|
397 | ) |
|
398 | ||
399 | if not isinstance(event, AlertEvent): |
|
400 | raise InvalidArgumentType( |
|
401 | function=self.create_alert.__name__, |
|
402 | argument='even', |
|
403 | arg_type=AlertEvent.__name__, |
|
404 | ) |
|
405 | ||
406 | if not isinstance(method, AlertMethod): |
|
407 | raise InvalidArgumentType( |
|
408 | function=self.create_alert.__name__, |
|
409 | argument='method', |
|
410 | arg_type=AlertMethod.__name__, |
|
411 | ) |
|
412 | ||
413 | _check_event(event, condition, method) |
|
414 | ||
415 | cmd = XmlCommand("create_alert") |
|
416 | cmd.add_element("name", name) |
|
417 | ||
418 | conditions = cmd.add_element("condition", condition.value) |
|
419 | ||
420 | if condition_data is not None: |
|
421 | for key, value in condition_data.items(): |
|
422 | _data = conditions.add_element("data", value) |
|
423 | _data.add_element("name", key) |
|
424 | ||
425 | events = cmd.add_element("event", event.value) |
|
426 | ||
427 | if event_data is not None: |
|
428 | for key, value in event_data.items(): |
|
429 | _data = events.add_element("data", value) |
|
430 | _data.add_element("name", key) |
|
431 | ||
432 | methods = cmd.add_element("method", method.value) |
|
433 | ||
434 | if method_data is not None: |
|
435 | for key, value in method_data.items(): |
|
436 | _data = methods.add_element("data", value) |
|
437 | _data.add_element("name", key) |
|
438 | ||
439 | if filter_id: |
|
440 | cmd.add_element("filter", attrs={"id": filter_id}) |
|
441 | ||
442 | if comment: |
|
443 | cmd.add_element("comment", comment) |
|
444 | ||
445 | return self._send_xml_command(cmd) |
|
446 | ||
447 | def clone_alert(self, alert_id: str) -> Any: |
|
448 | """Clone an existing alert |
@@ 144-256 (lines=113) @@ | ||
141 | # Is authenticated on gvmd |
|
142 | self._authenticated = False |
|
143 | ||
144 | def create_alert( |
|
145 | self, |
|
146 | name: str, |
|
147 | condition: AlertCondition, |
|
148 | event: AlertEvent, |
|
149 | method: AlertMethod, |
|
150 | *, |
|
151 | method_data: Optional[dict] = None, |
|
152 | event_data: Optional[dict] = None, |
|
153 | condition_data: Optional[dict] = None, |
|
154 | filter_id: Optional[int] = None, |
|
155 | comment: Optional[str] = None |
|
156 | ) -> Any: |
|
157 | """Create a new alert |
|
158 | ||
159 | Arguments: |
|
160 | name: Name of the new Alert |
|
161 | condition: The condition that must be satisfied for the alert |
|
162 | to occur; if the event is either 'Updated SecInfo arrived' or |
|
163 | 'New SecInfo arrived', condition must be 'Always'. Otherwise, |
|
164 | condition can also be on of 'Severity at least', 'Filter count |
|
165 | changed' or 'Filter count at least'. |
|
166 | event: The event that must happen for the alert to occur, one |
|
167 | of 'Task run status changed', 'Updated SecInfo arrived' or 'New |
|
168 | SecInfo arrived' |
|
169 | method: The method by which the user is alerted, one of 'SCP', |
|
170 | 'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; if the event is |
|
171 | neither 'Updated SecInfo arrived' nor 'New SecInfo arrived', |
|
172 | method can also be one of 'Start Task', 'HTTP Get', 'Sourcefire |
|
173 | Connector' or 'verinice Connector'. |
|
174 | condition_data: Data that defines the condition |
|
175 | event_data: Data that defines the event |
|
176 | method_data: Data that defines the method |
|
177 | filter_id: Filter to apply when executing alert |
|
178 | comment: Comment for the alert |
|
179 | ||
180 | Returns: |
|
181 | The response. See :py:meth:`send_command` for details. |
|
182 | """ |
|
183 | if not name: |
|
184 | raise RequiredArgument( |
|
185 | function=self.create_alert.__name__, argument='name' |
|
186 | ) |
|
187 | ||
188 | if not condition: |
|
189 | raise RequiredArgument( |
|
190 | function=self.create_alert.__name__, argument='condition' |
|
191 | ) |
|
192 | ||
193 | if not event: |
|
194 | raise RequiredArgument( |
|
195 | function=self.create_alert.__name__, argument='event' |
|
196 | ) |
|
197 | ||
198 | if not method: |
|
199 | raise RequiredArgument( |
|
200 | function=self.create_alert.__name__, argument='method' |
|
201 | ) |
|
202 | ||
203 | if not isinstance(condition, AlertCondition): |
|
204 | raise InvalidArgumentType( |
|
205 | function=self.create_alert.__name__, |
|
206 | argument='condition', |
|
207 | arg_type=AlertCondition.__name__, |
|
208 | ) |
|
209 | ||
210 | if not isinstance(event, AlertEvent): |
|
211 | raise InvalidArgumentType( |
|
212 | function=self.create_alert.__name__, |
|
213 | argument='even', |
|
214 | arg_type=AlertEvent.__name__, |
|
215 | ) |
|
216 | ||
217 | if not isinstance(method, AlertMethod): |
|
218 | raise InvalidArgumentType( |
|
219 | function=self.create_alert.__name__, |
|
220 | argument='method', |
|
221 | arg_type=AlertMethod.__name__, |
|
222 | ) |
|
223 | ||
224 | _check_event(event, condition, method) |
|
225 | ||
226 | cmd = XmlCommand("create_alert") |
|
227 | cmd.add_element("name", name) |
|
228 | ||
229 | conditions = cmd.add_element("condition", condition.value) |
|
230 | ||
231 | if condition_data is not None: |
|
232 | for key, value in condition_data.items(): |
|
233 | _data = conditions.add_element("data", value) |
|
234 | _data.add_element("name", key) |
|
235 | ||
236 | events = cmd.add_element("event", event.value) |
|
237 | ||
238 | if event_data is not None: |
|
239 | for key, value in event_data.items(): |
|
240 | _data = events.add_element("data", value) |
|
241 | _data.add_element("name", key) |
|
242 | ||
243 | methods = cmd.add_element("method", method.value) |
|
244 | ||
245 | if method_data is not None: |
|
246 | for key, value in method_data.items(): |
|
247 | _data = methods.add_element("data", value) |
|
248 | _data.add_element("name", key) |
|
249 | ||
250 | if filter_id: |
|
251 | cmd.add_element("filter", attrs={"id": filter_id}) |
|
252 | ||
253 | if comment: |
|
254 | cmd.add_element("comment", comment) |
|
255 | ||
256 | return self._send_xml_command(cmd) |
|
257 | ||
258 | def create_audit( |
|
259 | self, |