| @@ 196-269 (lines=74) @@ | ||
| 193 | cmd.set_attribute("details", "1") |
|
| 194 | return self._send_xml_command(cmd) |
|
| 195 | ||
| 196 | def modify_note( |
|
| 197 | self, |
|
| 198 | note_id: str, |
|
| 199 | text: str, |
|
| 200 | *, |
|
| 201 | days_active: Optional[int] = None, |
|
| 202 | hosts: Optional[List[str]] = None, |
|
| 203 | port: Optional[int] = None, |
|
| 204 | result_id: Optional[str] = None, |
|
| 205 | severity: Optional[Severity] = None, |
|
| 206 | task_id: Optional[str] = None, |
|
| 207 | threat: Optional[SeverityLevel] = None, |
|
| 208 | ) -> Any: |
|
| 209 | """Modifies an existing note. |
|
| 210 | ||
| 211 | Arguments: |
|
| 212 | note_id: UUID of note to modify. |
|
| 213 | text: The text of the note. |
|
| 214 | days_active: Days note will be active. -1 on always, 0 off. |
|
| 215 | hosts: A list of hosts addresses |
|
| 216 | port: Port to which note applies. |
|
| 217 | result_id: Result to which note applies. |
|
| 218 | severity: Severity to which note applies. |
|
| 219 | task_id: Task to which note applies. |
|
| 220 | threat: Threat level to which note applies. Will be converted to |
|
| 221 | severity. |
|
| 222 | ||
| 223 | Returns: |
|
| 224 | The response. See :py:meth:`send_command` for details. |
|
| 225 | """ |
|
| 226 | if not note_id: |
|
| 227 | raise RequiredArgument( |
|
| 228 | function=self.modify_note.__name__, argument='note_id' |
|
| 229 | ) |
|
| 230 | ||
| 231 | if not text: |
|
| 232 | raise RequiredArgument( |
|
| 233 | function=self.modify_note.__name__, argument='text' |
|
| 234 | ) |
|
| 235 | ||
| 236 | cmd = XmlCommand("modify_note") |
|
| 237 | cmd.set_attribute("note_id", note_id) |
|
| 238 | cmd.add_element("text", text) |
|
| 239 | ||
| 240 | if days_active is not None: |
|
| 241 | cmd.add_element("active", str(days_active)) |
|
| 242 | ||
| 243 | if hosts: |
|
| 244 | cmd.add_element("hosts", to_comma_list(hosts)) |
|
| 245 | ||
| 246 | if port: |
|
| 247 | cmd.add_element("port", str(port)) |
|
| 248 | ||
| 249 | if result_id: |
|
| 250 | cmd.add_element("result", attrs={"id": result_id}) |
|
| 251 | ||
| 252 | if severity: |
|
| 253 | cmd.add_element("severity", str(severity)) |
|
| 254 | ||
| 255 | if task_id: |
|
| 256 | cmd.add_element("task", attrs={"id": task_id}) |
|
| 257 | ||
| 258 | if threat is not None: |
|
| 259 | ||
| 260 | if not isinstance(threat, SeverityLevel): |
|
| 261 | raise InvalidArgumentType( |
|
| 262 | function=self.modify_note.__name__, |
|
| 263 | argument='threat', |
|
| 264 | arg_type=SeverityLevel.__name__, |
|
| 265 | ) |
|
| 266 | ||
| 267 | cmd.add_element("threat", threat.value) |
|
| 268 | ||
| 269 | return self._send_xml_command(cmd) |
|
| 270 | ||
| @@ 31-104 (lines=74) @@ | ||
| 28 | ||
| 29 | ||
| 30 | class NotesMixin: |
|
| 31 | def create_note( |
|
| 32 | self, |
|
| 33 | text: str, |
|
| 34 | nvt_oid: str, |
|
| 35 | *, |
|
| 36 | days_active: Optional[int] = None, |
|
| 37 | hosts: Optional[List[str]] = None, |
|
| 38 | port: Optional[int] = None, |
|
| 39 | result_id: Optional[str] = None, |
|
| 40 | severity: Optional[Severity] = None, |
|
| 41 | task_id: Optional[str] = None, |
|
| 42 | threat: Optional[SeverityLevel] = None, |
|
| 43 | ) -> Any: |
|
| 44 | """Create a new note |
|
| 45 | ||
| 46 | Arguments: |
|
| 47 | text: Text of the new note |
|
| 48 | nvt_id: OID of the nvt to which note applies |
|
| 49 | days_active: Days note will be active. -1 on |
|
| 50 | always, 0 off |
|
| 51 | hosts: A list of hosts addresses |
|
| 52 | port: Port to which the note applies |
|
| 53 | result_id: UUID of a result to which note applies |
|
| 54 | severity: Severity to which note applies |
|
| 55 | task_id: UUID of task to which note applies |
|
| 56 | threat: Severity level to which note applies. Will be converted to |
|
| 57 | severity. |
|
| 58 | ||
| 59 | Returns: |
|
| 60 | The response. See :py:meth:`send_command` for details. |
|
| 61 | """ |
|
| 62 | if not text: |
|
| 63 | raise RequiredArgument( |
|
| 64 | function=self.create_note.__name__, argument='text' |
|
| 65 | ) |
|
| 66 | ||
| 67 | if not nvt_oid: |
|
| 68 | raise RequiredArgument( |
|
| 69 | function=self.create_note.__name__, argument='nvt_oid' |
|
| 70 | ) |
|
| 71 | ||
| 72 | cmd = XmlCommand("create_note") |
|
| 73 | cmd.add_element("text", text) |
|
| 74 | cmd.add_element("nvt", attrs={"oid": nvt_oid}) |
|
| 75 | ||
| 76 | if days_active is not None: |
|
| 77 | cmd.add_element("active", str(days_active)) |
|
| 78 | ||
| 79 | if hosts: |
|
| 80 | cmd.add_element("hosts", to_comma_list(hosts)) |
|
| 81 | ||
| 82 | if port: |
|
| 83 | cmd.add_element("port", str(port)) |
|
| 84 | ||
| 85 | if result_id: |
|
| 86 | cmd.add_element("result", attrs={"id": result_id}) |
|
| 87 | ||
| 88 | if severity: |
|
| 89 | cmd.add_element("severity", str(severity)) |
|
| 90 | ||
| 91 | if task_id: |
|
| 92 | cmd.add_element("task", attrs={"id": task_id}) |
|
| 93 | ||
| 94 | if threat is not None: |
|
| 95 | if not isinstance(threat, SeverityLevel): |
|
| 96 | raise InvalidArgumentType( |
|
| 97 | function="create_note", |
|
| 98 | argument="threat", |
|
| 99 | arg_type=SeverityLevel.__name__, |
|
| 100 | ) |
|
| 101 | ||
| 102 | cmd.add_element("threat", threat.value) |
|
| 103 | ||
| 104 | return self._send_xml_command(cmd) |
|
| 105 | ||
| 106 | def clone_note(self, note_id: str) -> Any: |
|
| 107 | """Clone an existing note |
|