From 9d003d12b4440eabe6c6d71a451331c5f0e0d85d Mon Sep 17 00:00:00 2001 From: Quim Date: Wed, 8 Apr 2020 12:01:47 +0200 Subject: [PATCH] improved error logging and excepcions --- vulnwhisp/reporting/jira_api.py | 29 +++++++++++++++++------------ vulnwhisp/vulnwhisp.py | 24 ++++++++++++++++-------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/vulnwhisp/reporting/jira_api.py b/vulnwhisp/reporting/jira_api.py index d48b34a..ba902f0 100644 --- a/vulnwhisp/reporting/jira_api.py +++ b/vulnwhisp/reporting/jira_api.py @@ -67,18 +67,23 @@ class JiraAPI(object): if not exists: self.logger.error("Error creating Ticket: component {} not found".format(component)) return 0 - - new_issue = self.jira.create_issue(project=project, - summary=title, - description=desc, - issuetype={'name': 'Bug'}, - labels=labels, - components=components_ticket) - self.logger.info("Ticket {} created successfully".format(new_issue)) + try: + new_issue = self.jira.create_issue(project=project, + summary=title, + description=desc, + issuetype={'name': 'Bug'}, + labels=labels, + components=components_ticket) + + self.logger.info("Ticket {} created successfully".format(new_issue)) + + if attachment_contents: + self.add_content_as_attachment(new_issue, attachment_contents) - if attachment_contents: - self.add_content_as_attachment(new_issue, attachment_contents) + except Exception as e: + self.logger.error("Failed to create ticket on Jira Project '{}'. Error: {}".format(project, e)) + new_issue = False return new_issue @@ -485,7 +490,7 @@ class JiraAPI(object): if transition.get('name') == self.JIRA_REOPEN_ISSUE: self.logger.debug("Ticket is reopenable") return True - self.logger.warn("Ticket can't be opened. Check Jira transitions.") + self.logger.error("Ticket {} can't be opened. Check Jira transitions.".format(ticket_obj)) return False def is_ticket_closeable(self, ticket_obj): @@ -493,7 +498,7 @@ class JiraAPI(object): for transition in transitions: if transition.get('name') == self.JIRA_CLOSE_ISSUE: return True - self.logger.warn("Ticket can't closed. Check Jira transitions.") + self.logger.error("Ticket {} can't closed. Check Jira transitions.".format(ticket_obj)) return False def is_ticket_resolved(self, ticket_obj): diff --git a/vulnwhisp/vulnwhisp.py b/vulnwhisp/vulnwhisp.py index a2c9676..bfc6878 100755 --- a/vulnwhisp/vulnwhisp.py +++ b/vulnwhisp/vulnwhisp.py @@ -1247,16 +1247,21 @@ class vulnWhispererJIRA(vulnWhispererBase): vulnerabilities = self.parse_qualys_vuln_vulnerabilities(fullpath, source, scan_name, min_critical, dns_resolv) #***JIRA sync*** - if vulnerabilities: - self.logger.info('{source} data has been successfuly parsed'.format(source=source.upper())) - self.logger.info('Starting JIRA sync') + try: + if vulnerabilities: + self.logger.info('{source} data has been successfuly parsed'.format(source=source.upper())) + self.logger.info('Starting JIRA sync') - self.jira.sync(vulnerabilities, project, components) - else: - self.logger.info("[{source}.{scan_name}] No vulnerabilities or vulnerabilities not parsed.".format(source=source, scan_name=scan_name)) - self.set_latest_scan_reported(fullpath.split("/")[-1]) + self.jira.sync(vulnerabilities, project, components) + else: + self.logger.info("[{source}.{scan_name}] No vulnerabilities or vulnerabilities not parsed.".format(source=source, scan_name=scan_name)) + self.set_latest_scan_reported(fullpath.split("/")[-1]) + return False + except Exception as e: + self.logger.error("Error: {}".format(e)) return False + #writing to file those assets without DNS resolution #if its not empty if self.host_no_resolv: @@ -1276,7 +1281,10 @@ class vulnWhispererJIRA(vulnWhispererBase): try: self.jira_sync(self.config.get(scan, 'source'), self.config.get(scan, 'scan_name')) except Exception as e: - self.logger.error("VulnWhisperer wasn't able to report the vulnerabilities from the '{}'s source".format(self.config.get(scan, 'source'))) + self.logger.error( + "VulnWhisperer wasn't able to report the vulnerabilities from the '{}'s source, section {}.\ + \nError: {}".format( + self.config.get(scan, 'source'), self.config.get(scan, 'scan_name'), e)) return True return False