Add function for sighting using attribute id, uuid or a json file

pull/17/head
Déborah Servili 2016-04-29 16:35:27 +02:00
parent 5c23d12f2c
commit 3cd9ede99f
3 changed files with 47 additions and 1 deletions

2
examples/sighting.json Normal file
View File

@ -0,0 +1,2 @@
{"values":["www.google.com", "8.8.8.8"], "timestamp":1460558710}

27
examples/sighting.py Normal file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pymisp import PyMISP
from keys import misp_url, misp_key
import argparse
# For python2 & 3 compat, a bit dirty, but it seems to be the least bad one
try:
input = raw_input
except NameError:
pass
def init(url, key):
return PyMISP(url, key, True, 'json')
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Add sighting.')
parser.add_argument("-f", "--json_file", help="The name of the json file describing the attribute you want to add sighting to.")
args = parser.parse_args()
misp = init(misp_url, misp_key)
misp.sighting_per_json(args.json_file)

View File

@ -990,9 +990,26 @@ class PyMISP(object):
url = urljoin(self.root_url, 'attributes/attributeStatistics/{}/{}'.format(context, percentage))
else:
url = urljoin(self.root_url, 'attributes/attributeStatistics/{}'.format(context))
print(url)
return session.get(url).json()
# ############## Sightings ##################
def sighting_per_id(self, attribute_id, force_out=None):
session = self.__prepare_session(force_out)
url = urljoin(self.root_url, 'sightings/add/{}'.format(attribute_id))
return session.post(url)
def sighting_per_uuid(self, attribute_uuid, force_out=None):
session = self.__prepare_session(force_out)
url = urljoin(self.root_url, 'sightings/add/{}'.format(attribute_uuid))
return session.post(url)
def sighting_per_json(self, json_file, force_out=None):
session = self.__prepare_session(force_out)
jdata = json.load(open(json_file))
url = urljoin(self.root_url, 'sightings/add/')
return session.post(url, data=json.dumps(jdata))
# ############## Deprecated (Pure XML API should not be used) ##################
@deprecated
def download_all(self):