add search on sighting

added the possibility to search sightings : 
Here some example : 
```python
print(misp.sighting_list(424242))
```
The answer will give a sighting list corresponding to the attribute 424242.
```python
print(misp.sighting_list(element_id=42, org_id=2, scope=event))
```
The return will be a sighting list of event 42 with a filter for organisation 2.
pull/195/head
ANSSI-BSO-D 2018-02-21 15:12:26 +01:00 committed by GitHub
parent 62fb26fafd
commit 9087768b1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 0 deletions

View File

@ -1345,6 +1345,40 @@ class PyMISP(object):
s.from_dict(value=value, uuid=uuid, id=id, source=source, type=type, timestamp=timestamp, **kwargs)
return self.set_sightings(s)
def sighting_list(self, element_id, scope="attribute", org_id=False):
"""Get the list of sighting.
:param element_id: could be an event id or attribute id
:type element_id: int
:param scope: could be attribute or event
:return: A json list of sighting corresponding to the search
:rtype: list
:Example:
>>> misp.sighting_list(4731) # default search on attribute
[ ... ]
>>> misp.sighting_list(42, event) # return list of sighting for event 42
[ ... ]
>>> misp.sighting_list(element_id=42, org_id=2, scope=event) # return list of sighting for event 42 filtered with org id 2
"""
if isinstance(element_id, int) is False:
raise Exception('Invalid parameter, element_id must be a number')
if scope not in ["attribute", "event"]:
raise Exception('scope parameter must be "attribute" or "event"')
if org_id is not False:
if isinstance(org_id, int) is False:
raise Exception('Invalid parameter, org_id must be a number')
else:
org_id = ""
uri = 'sightings/listSightings/{}/{}/{}'.format(
element_id,
scope,
org_id
)
url = urljoin(self.root_url, uri)
response = self.__prepare_request('POST', url)
return self._check_response(response)
# ############## Sharing Groups ##################
def get_sharing_groups(self):