Need to report an error back to the producer of VES events 88/7288/3
authorArif Hussain <arif.hussain@xoriant.com>
Thu, 9 Dec 2021 16:01:31 +0000 (21:31 +0530)
committerMahesh Jethanandani <mjethanandani@gmail.com>
Sat, 11 Dec 2021 02:55:48 +0000 (02:55 +0000)
Signed-off-by: Arif Hussain <arif.hussain@xoriant.com>
Change-Id: Id57f9c72671f4c640ba91542338a010ec7854da7
Signed-off-by: Arif Hussain <arif.hussain@xoriant.com>
collector/evel-test-collector/code/collector/monitor.py

index 60a04f0..de54891 100755 (executable)
@@ -224,7 +224,8 @@ def listener(environ, start_response, schema):
 
         except jsonschema.SchemaError as e:
             logger.error('Schema is not valid! {0}'.format(e))
-
+            # Stop container forcefully.
+            os._exit(0)
         except jsonschema.ValidationError as e:
             logger.warn('Event is not valid against schema! {0}'.format(e))
             logger.warn('Bad JSON body decoded:\n'
@@ -232,9 +233,14 @@ def listener(environ, start_response, schema):
                                      sort_keys=True,
                                      indent=4,
                                      separators=(',', ': '))))
-
+            start_response('400 Bad Request',
+                                   [('Content-type', 'application/json')])
+            yield ''.encode()
         except Exception as e:
             logger.error('Event invalid for unexpected reason! {0}'.format(e))
+            start_response('500 Internal Server Error',
+                                   [('Content-type', 'application/json')])
+            yield ''.encode()
     else:
         logger.debug('No schema so just decode JSON: {0}'.format(body))
         try: