Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error reporting #1490

Merged
merged 5 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_ping_exception(self, mock_ping):
mock_ping.side_effect = ConnectionError("Failed to establish a new connection")
transmission = StixTransmission(MODULE, CONNECTION, CONFIG)
ping_response = transmission.ping()
self.assertEqual(ping_response, {'code': 'unknown', 'connector': 'infoblox', 'error': "infoblox connector error => Failed to establish a new connection", 'success': False})
self.assertEqual(ping_response, {'code': 'service_unavailable', 'connector': 'infoblox', 'error': "infoblox connector error => Failed to establish a new connection", 'success': False})

###############################
## QUERY
Expand Down Expand Up @@ -316,7 +316,7 @@ def test_results_exception(self, mock_ping):
mock_ping.side_effect = ConnectionError("Failed to establish a new connection")
transmission = StixTransmission(MODULE, CONNECTION, CONFIG)
results_response = transmission.results(self._get_query(), 4, 3)
self.assertEqual(results_response, {"success": False,'connector': 'infoblox',"error": "infoblox connector error => Failed to establish a new connection","code": "unknown"})
self.assertEqual(results_response, {"success": False,'connector': 'infoblox',"error": "infoblox connector error => Failed to establish a new connection","code": "service_unavailable"})

class TestDossierTransmission(unittest.TestCase):
def get_dialect(self):
Expand Down Expand Up @@ -487,7 +487,7 @@ def test_results_exception(self, mock_ping):
mock_ping.side_effect = ConnectionError("Failed to establish a new connection")
transmission = StixTransmission(MODULE, CONNECTION, CONFIG)
results_response = transmission.results(self._get_query(threat_type="host"), 4, 3)
self.assertEqual(results_response, {"success": False,'connector': 'infoblox',"error": "infoblox connector error => Failed to establish a new connection","code": "unknown"})
self.assertEqual(results_response, {"success": False,'connector': 'infoblox',"error": "infoblox connector error => Failed to establish a new connection","code": "service_unavailable"})

class TestTideDbTransmission(unittest.TestCase):
def get_dialect(self):
Expand Down Expand Up @@ -672,4 +672,4 @@ def test_results_exception(self, mock_ping):
mock_ping.side_effect = ConnectionError("Failed to establish a new connection")
transmission = StixTransmission(MODULE, CONNECTION, CONFIG)
results_response = transmission.results(self._get_query(threat_type="host"), 4, 3)
self.assertEqual(results_response, {"success": False,'connector': 'infoblox',"error": "infoblox connector error => Failed to establish a new connection","code": "unknown"})
self.assertEqual(results_response, {"success": False,'connector': 'infoblox',"error": "infoblox connector error => Failed to establish a new connection","code": "service_unavailable"})
10 changes: 7 additions & 3 deletions stix_shifter_utils/utils/error_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ErrorCode(Enum):
TRANSMISSION_CONNECT = 'service_unavailable'
TRANSMISSION_AUTH_SSL = 'authentication_fail'
TRANSMISSION_AUTH_CREDENTIALS = 'authentication_fail'
TRANSMISSION_CERT_ERROR = 'certificate_fail'
TRANSMISSION_MODULE_DEFAULT_ERROR = 'unknown'
TRANSMISSION_QUERY_PARSING_ERROR = 'invalid_query'
TRANSMISSION_QUERY_LOGICAL_ERROR = 'invalid_query'
Expand Down Expand Up @@ -105,18 +106,21 @@ def fill_error(return_object, message_struct=None, message_path=None, message=No

if message is not None and len(message) > 0:
if error_code.value == ErrorCode.TRANSMISSION_UNKNOWN.value:
if 'uthenticat' in message or 'uthoriz' in message or 'access denied' in message:
if 'certificate' in message:
error_code = ErrorCode.TRANSMISSION_CERT_ERROR
elif 'uthenticat' in message or 'uthoriz' in message or 'access denied' in message:
error_code = ErrorCode.TRANSMISSION_AUTH_CREDENTIALS
elif 'query_syntax_error' in message:
error_code = ErrorCode.TRANSMISSION_QUERY_PARSING_ERROR
elif 'Forbidden' in message or 'forbidden' in message:
error_code = ErrorCode.TRANSMISSION_FORBIDDEN
elif 'too_many_requests' in message or 'Too Many Requests' in message:
error_code = ErrorCode.TRANSMISSION_TOO_MANY_REQUESTS
elif 'client_connector_error' in message:
elif any(m in message for m in ['client_connector_error', 'server timeout_error', 'ailed to establish']):
error_code = ErrorCode.TRANSMISSION_CONNECT
message = '{} connector error => {}'.format(connector, str(message))
return_object['error'] = str(message)
message = message.replace('[Errno 61] ','')
return_object['error'] = message
ErrorMapperBase.set_error_code(return_object, error_code.value, connector=connector)
if error_code == ErrorCode.TRANSMISSION_UNKNOWN:
ErrorResponder.call_module_error_mapper(message_struct, return_object, connector)
Expand Down