Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
Fix Issue #210
Browse files Browse the repository at this point in the history
- bug in Ack handler
  • Loading branch information
guilhemmarchand committed Jan 2, 2021
1 parent 0c5a434 commit 5e9f666
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 35 deletions.
42 changes: 7 additions & 35 deletions trackme/bin/trackme_rest_handler_ack.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ def post_ack_enable(self, request_info, **kwargs):

try:

# create a record
record = '{"object": "' + object_value + '", "object_category": "' + object_category_value + '", "ack_expiration": "' + str(ack_expiration) + '", "ack_state": "' + str(ack_state) + '", "ack_mtime": "' + str(ack_mtime) + '"}'

# Insert the record
collection_audit.data.insert(json.dumps({
"time": str(current_time),
Expand All @@ -285,7 +288,7 @@ def post_ack_enable(self, request_info, **kwargs):
"change_type": "enable ack",
"object": str(object_value),
"object_category": "data_source",
"object_attrs": json.dumps({"object": object_value, "object_category": object_category_value, "ack_expiration": str(ack_expiration), "ack_state": str(ack_state), "ack_mtime": str(ack_mtime)}, index=1),
"object_attrs": json.dumps(json.loads(record), indent=1),
"result": "N/A",
"comment": str(update_comment)
}))
Expand All @@ -296,7 +299,7 @@ def post_ack_enable(self, request_info, **kwargs):
}

return {
"payload": json.dumps(collection.data.query(query=str(query_string)), indent=1),
"payload": json.dumps(json.loads(record), indent=1),
'status': 200 # HTTP status code
}

Expand Down Expand Up @@ -415,40 +418,9 @@ def post_ack_disable(self, request_info, **kwargs):

else:

# Insert the record
collection.data.insert(json.dumps({"object": object_value,
"object_category": object_category_value,
"ack_expiration": str(ack_expiration),
"ack_state": str(ack_state),
"ack_mtime": str(ack_mtime)}))

# Record an audit change
import time
current_time = int(round(time.time() * 1000))
user = "nobody"

try:

# Insert the record
collection_audit.data.insert(json.dumps({
"time": str(current_time),
"user": str(user),
"action": "success",
"change_type": "disable ack",
"object": str(object_value),
"object_category": "data_source",
"object_attrs": json.dumps({"object": object_value, "object_category": object_category_value, "ack_expiration": str(ack_expiration), "ack_state": str(ack_state), "ack_mtime": str(ack_mtime)}, index=1),
"result": "N/A",
"comment": str(update_comment)
}))

except Exception as e:
return {
'payload': 'Warn: exception encountered: ' + str(e) # Payload of the request.
}

# There no ack currently for this object, return http 200 with message
return {
"payload": json.dumps(collection.data.query(query=str(query_string)), indent=1),
"payload": "There are no active acknowledgment for the entity object: " + str(object_value) + ", object_category: " + str(object_category_value),
'status': 200 # HTTP status code
}

Expand Down
Binary file modified trackme_1230.tgz
Binary file not shown.

0 comments on commit 5e9f666

Please sign in to comment.