MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / save_scan_job

Method save_scan_job

db_manager.py:1928–1980  ·  view source on GitHub ↗

Save or update a scan job to the database. Args: scan_id: Unique scan identifier scan_type: Type of scan (nuclei, nikto, zap_full, etc.) target: Target URL or IP status: pending, running, completed, failed, cancelled progr

(self, scan_id: str, scan_type: str, target: str, status: str = 'pending',
                      progress_percent: int = 0, findings_count: int = 0, current_check: str = '',
                      started_at: datetime = None, completed_at: datetime = None,
                      error_message: str = '', options: dict = None)

Source from the content-addressed store, hash-verified

1926
1927 except Exception as e:
1928 logger.error(f"Error cleaning up WiFi data: {e}")
1929
1930 # ========================================================================
1931 # Advanced Vulnerability Scanner Persistence Methods
1932 # ========================================================================
1933
1934 def save_scan_job(self, scan_id: str, scan_type: str, target: str, status: str = 'pending',
1935 progress_percent: int = 0, findings_count: int = 0, current_check: str = '',
1936 started_at: datetime = None, completed_at: datetime = None,
1937 error_message: str = '', options: dict = None) -> bool:
1938 """
1939 Save or update a scan job to the database.
1940
1941 Args:
1942 scan_id: Unique scan identifier
1943 scan_type: Type of scan (nuclei, nikto, zap_full, etc.)
1944 target: Target URL or IP
1945 status: pending, running, completed, failed, cancelled
1946 progress_percent: 0-100
1947 findings_count: Number of findings discovered
1948 current_check: Current operation being performed
1949 started_at: When scan started
1950 completed_at: When scan completed
1951 error_message: Error message if failed
1952 options: Scan options dict (will be JSON serialized)
1953
1954 Returns:
1955 bool: True if successful
1956 """
1957 try:
1958 with self.get_connection() as conn:
1959 cursor = conn.cursor()
1960 options_json = json.dumps(options) if options else None
1961
1962 cursor.execute("""
1963 INSERT INTO scan_jobs (
1964 scan_id, scan_type, target, status, progress_percent,
1965 findings_count, current_check, started_at, completed_at,
1966 error_message, options, updated_at
1967 ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
1968 ON CONFLICT(scan_id) DO UPDATE SET
1969 status = excluded.status,
1970 progress_percent = excluded.progress_percent,
1971 findings_count = excluded.findings_count,
1972 current_check = excluded.current_check,
1973 started_at = COALESCE(excluded.started_at, scan_jobs.started_at),
1974 completed_at = excluded.completed_at,
1975 error_message = excluded.error_message,
1976 options = COALESCE(excluded.options, scan_jobs.options),
1977 updated_at = CURRENT_TIMESTAMP
1978 """, (scan_id, scan_type, target, status, progress_percent,
1979 findings_count, current_check, started_at, completed_at,
1980 error_message, options_json))
1981
1982 conn.commit()
1983 return True

Callers 1

_save_scan_to_dbMethod · 0.80

Calls 5

get_connectionMethod · 0.95
cursorMethod · 0.80
commitMethod · 0.80
errorMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected