fix reported tracking for jira
This commit is contained in:
@ -39,6 +39,8 @@ def main():
|
|||||||
# First setup logging
|
# First setup logging
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
stream=sys.stdout,
|
stream=sys.stdout,
|
||||||
|
#format only applies when not using -F flag for colouring
|
||||||
|
format='%(levelname)s:%(name)s:%(funcName)s:%(message)s',
|
||||||
level=logging.DEBUG if args.debug else logging.INFO
|
level=logging.DEBUG if args.debug else logging.INFO
|
||||||
)
|
)
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
@ -161,12 +161,13 @@ class vulnWhispererBase(object):
|
|||||||
self.logger.error("Failed to insert record in database. Error: {}".format(e))
|
self.logger.error("Failed to insert record in database. Error: {}".format(e))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def set_latest_scan_processed(self, filename):
|
def set_latest_scan_reported(self, filename):
|
||||||
#the reason to use the filename instead of the source/scan_name is because the filename already belongs to
|
#the reason to use the filename instead of the source/scan_name is because the filename already belongs to
|
||||||
#that latest scan, and we maintain integrity making sure that it is the exact scan we checked
|
#that latest scan, and we maintain integrity making sure that it is the exact scan we checked
|
||||||
try:
|
try:
|
||||||
self.cur.execute('UPDATE scan_history SET processed = 1 WHERE filename="{}";'.format(filename))
|
self.cur.execute('UPDATE scan_history SET reported = 1 WHERE filename="{}";'.format(filename))
|
||||||
self.logger.debug('Scan {} marked as successfully processed.'.format(filename))
|
self.conn.commit()
|
||||||
|
self.logger.info('Scan {} marked as successfully processed.'.format(filename))
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('Failed while setting scan with file {} as processed'.format(filename))
|
self.logger.error('Failed while setting scan with file {} as processed'.format(filename))
|
||||||
@ -210,13 +211,14 @@ class vulnWhispererBase(object):
|
|||||||
#TODO delete backward compatibility check after some versions
|
#TODO delete backward compatibility check after some versions
|
||||||
last_column_table = self.cur.execute('PRAGMA table_info(scan_history)').fetchall()[-1][1]
|
last_column_table = self.cur.execute('PRAGMA table_info(scan_history)').fetchall()[-1][1]
|
||||||
if results and last_column_table == self.table_columns[-1]:
|
if results and last_column_table == self.table_columns[-1]:
|
||||||
processed = self.cur.execute('SELECT processed FROM scan_history WHERE filename="{}"'.format(results)).fetchall()[0][0]
|
reported = self.cur.execute('SELECT reported FROM scan_history WHERE filename="{}"'.format(results)).fetchall()
|
||||||
if processed:
|
reported = reported[0][0]
|
||||||
self.logger.debug("Last downloaded scan from source {source} scan_name {scan_name} has already been processed".format(source=source, scan_name=scan_name))
|
if reported:
|
||||||
|
self.logger.debug("Last downloaded scan from source {source} scan_name {scan_name} has already been reported".format(source=source, scan_name=scan_name))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error("Error when getting latest results from {}.{} : {}".format(source, scan_name, e))
|
self.logger.error("Error when getting latest results from {}.{} : {}".format(source, scan_name, e))
|
||||||
return results, processed
|
return results, reported
|
||||||
|
|
||||||
def get_scan_profiles(self):
|
def get_scan_profiles(self):
|
||||||
# Returns a list of source.scan_name elements from the database
|
# Returns a list of source.scan_name elements from the database
|
||||||
@ -1013,7 +1015,7 @@ class vulnWhispererJIRA(vulnWhispererBase):
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
#datafile path
|
#datafile path
|
||||||
filename, processed = self.get_latest_results(source, scan_name)
|
filename, reported = self.get_latest_results(source, scan_name)
|
||||||
fullpath = ""
|
fullpath = ""
|
||||||
|
|
||||||
# search data files under user specified directory
|
# search data files under user specified directory
|
||||||
@ -1021,8 +1023,8 @@ class vulnWhispererJIRA(vulnWhispererBase):
|
|||||||
if filename in filenames:
|
if filename in filenames:
|
||||||
fullpath = "{}/{}".format(root,filename)
|
fullpath = "{}/{}".format(root,filename)
|
||||||
|
|
||||||
if processed:
|
if reported:
|
||||||
self.logger.warn('Last Scan of "{scan_name}" for source "{source}" has already been processed; will be skipped.'.format(scan_name=scan_name, source=source))
|
self.logger.warn('Last Scan of "{scan_name}" for source "{source}" has already been reported; will be skipped.'.format(scan_name=scan_name, source=source))
|
||||||
return [False] * 5
|
return [False] * 5
|
||||||
|
|
||||||
if not fullpath:
|
if not fullpath:
|
||||||
@ -1185,7 +1187,7 @@ class vulnWhispererJIRA(vulnWhispererBase):
|
|||||||
project, components, fullpath, min_critical, dns_resolv = self.get_env_variables(source, scan_name)
|
project, components, fullpath, min_critical, dns_resolv = self.get_env_variables(source, scan_name)
|
||||||
|
|
||||||
if not project:
|
if not project:
|
||||||
self.logger.debug("Skipping scan for source '{source}' and scan '{scan_name}'".format(source=source, scan_name=scan_name))
|
self.logger.debug("Skipping scan for source '{source}' and scan '{scan_name}': vulnerabilities have already been reported.".format(source=source, scan_name=scan_name))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
vulnerabilities = []
|
vulnerabilities = []
|
||||||
@ -1206,10 +1208,10 @@ class vulnWhispererJIRA(vulnWhispererBase):
|
|||||||
self.jira.sync(vulnerabilities, project, components)
|
self.jira.sync(vulnerabilities, project, components)
|
||||||
else:
|
else:
|
||||||
self.logger.info("[{source}.{scan_name}] No vulnerabilities or vulnerabilities not parsed.".format(source=source, scan_name=scan_name))
|
self.logger.info("[{source}.{scan_name}] No vulnerabilities or vulnerabilities not parsed.".format(source=source, scan_name=scan_name))
|
||||||
self.set_latest_scan_processed(fullpath.split("/")[-1])
|
self.set_latest_scan_reported(fullpath.split("/")[-1])
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.set_latest_scan_processed(fullpath.split("/")[-1])
|
self.set_latest_scan_reported(fullpath.split("/")[-1])
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def sync_all(self):
|
def sync_all(self):
|
||||||
|
Reference in New Issue
Block a user