Adds an observable to the ``observable`` property of the :class:`Indicator`. If the `observable` parameter is ``None``, no item will be added to the ``observable`` property. Note: The STIX Language dictates that an :class:`Indicator` can have only
(self, observable)
| 297 | self.observables = value |
| 298 | |
| 299 | def add_observable(self, observable): |
| 300 | """Adds an observable to the ``observable`` property of the |
| 301 | :class:`Indicator`. |
| 302 | |
| 303 | If the `observable` parameter is ``None``, no item will be added |
| 304 | to the ``observable`` property. |
| 305 | |
| 306 | Note: |
| 307 | The STIX Language dictates that an :class:`Indicator` can have only |
| 308 | one ``Observable`` under it. Because of this, when a user adds |
| 309 | another ``Observable`` a new, empty ``Observable`` will be crated |
| 310 | and append the existing and new ``observable`` using the |
| 311 | ``ObservableComposition`` property. To access the top level |
| 312 | ``Observable`` can be achieved by the ``observable`` property .By |
| 313 | default, the ``operator`` of the composition layer will be set to |
| 314 | ``"OR"``. The ``operator`` value can be changed via the |
| 315 | ``observable_composition_operator`` property. |
| 316 | |
| 317 | Setting ``observable`` or ``observables`` with re-initialize the |
| 318 | property and lose all ``Observable`` in the composition layer. |
| 319 | |
| 320 | Args: |
| 321 | observable: An instance of ``cybox.core.Observable`` or an object |
| 322 | type that can be converted into one. |
| 323 | |
| 324 | |
| 325 | Raises: |
| 326 | ValueError: If the `observable` param cannot be converted into an |
| 327 | instance of ``cybox.core.Observable``. |
| 328 | |
| 329 | """ |
| 330 | if not observable: |
| 331 | return |
| 332 | |
| 333 | # Sets the first observable. |
| 334 | elif not self.observable: |
| 335 | self.observable = observable |
| 336 | |
| 337 | # When another is inserted. A "root" Observable is created and the |
| 338 | # user's Observables are appended to the composition. |
| 339 | elif not self.observable.observable_composition: |
| 340 | observable_comp = ObservableComposition() |
| 341 | observable_comp.operator = self.observable_composition_operator |
| 342 | |
| 343 | observable_comp.add(self.observable) |
| 344 | observable_comp.add(observable) |
| 345 | |
| 346 | self.observable = Observable() |
| 347 | self.observable.observable_composition = observable_comp |
| 348 | |
| 349 | # Keep appending to "root" Observable. |
| 350 | else: |
| 351 | self.observable.observable_composition.add(observable) |
| 352 | |
| 353 | def add_alternative_id(self, value): |
| 354 | """Adds an alternative id to the ``alternative_id`` list property. |