Skip to content

Commit

Permalink
#41 #16 get Nils update from PR
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromeleonard committed May 16, 2017
1 parent 82dc2e6 commit e7867fd
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions analyzers/VMRay/vmrayclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class SampleFileNotFoundError(VMRayClientError):
pass


class UnknownSubmissionIdError(VMRayClientError):
"""Thrown on invalid submission id or if id request fails."""
pass


class VMRayClient:
"""
Client that connects to the VMRay api and allows searching for samples via hash and uploading a new sample to VMRay.
Expand Down Expand Up @@ -117,3 +122,23 @@ def submit_sample(self, filepath, filename, tags=['JAMIE_Import', 'TheHive_Impor
' Responsecode: {}; Text: {}'.format(res.status_code, res.text))
else:
raise SampleFileNotFoundError('Given sample file was not found.')

def query_job_status(self, submissionid):
"""
Queries vmray to check id a job was
:param submissionid: ID of the job/submission
:type submissionid: int
:returns: True if job finished, false if not
:rtype: bool
"""

apiurl = '/rest/submission/'
result = self.session.get('{}{}{}'.format(self.url, apiurl, submissionid))
if result.status_code == 200:
submission_info = json.loads(result.text)
if submission_info.get('data', {}).get('submission_finished', False): # Or something like that
return True
else:
raise UnknownSubmissionIdError('Submission id seems invalid, response was not HTTP 200.')
return False

0 comments on commit e7867fd

Please sign in to comment.