Skip to content

Commit

Permalink
Improve imposter response for task status
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianogorza committed Mar 11, 2024
1 parent 1f60ce4 commit 620f4c5
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docker/imposter/tasks/empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"data": {
"affected_items": [],
"total_affected_items": 0,
"total_failed_items": 0,
"failed_items": []
},
"message": "All specified task's status were returned",
"error": 0
}
47 changes: 47 additions & 0 deletions docker/imposter/tasks/status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var storeWazuh = stores.open('storeWazuh');
var attemptRestart = storeWazuh.load('attempt');

var taskStatus = context.request.queryParams.status;

if (!taskStatus) {
respond().withStatusCode(200).withFile('tasks/status_in_progress_2.json');
}

if (attemptRestart < 5) {
storeWazuh.save('attempt', attemptRestart + 1);

if (taskStatus === 'In progress') {
respond().withStatusCode(200).withFile('tasks/status_in_progress_2.json');
}

if (taskStatus === 'Done' || taskStatus === 'Failed') {
respond().withStatusCode(200).withFile('tasks/empty.json');
}
} else if (attemptRestart < 10) {
storeWazuh.save('attempt', attemptRestart + 1);

if (taskStatus === 'In progress') {
respond().withStatusCode(200).withFile('tasks/status_in_progress_1.json');
}

if (taskStatus === 'Done') {
respond().withStatusCode(200).withFile('tasks/status_done.json');
}

if (taskStatus === 'Failed') {
respond().withStatusCode(200).withFile('tasks/empty.json');
}
} else {
if (taskStatus === 'In progress') {
respond().withStatusCode(200).withFile('tasks/empty.json');
}

if (taskStatus === 'Done') {
respond().withStatusCode(200).withFile('tasks/status_done.json');
}

if (taskStatus === 'Failed') {
storeWazuh.save('attempt', 0);
respond().withStatusCode(200).withFile('tasks/status_failed.json');
}
}
22 changes: 22 additions & 0 deletions docker/imposter/tasks/status_done.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"data": {
"affected_items": [
{
"message": "Success",
"agent": "001",
"task_id": 1,
"node": "worker2",
"module": "upgrade_module",
"command": "upgrade",
"status": "Done",
"create_time": "2024-03-11T11:55:33.000Z",
"last_update_time": "2020-03-11T12:05:10.000Z"
}
],
"total_affected_items": 1,
"total_failed_items": 0,
"failed_items": []
},
"message": "All specified task's status were returned",
"error": 0
}
22 changes: 22 additions & 0 deletions docker/imposter/tasks/status_failed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"data": {
"affected_items": [
{
"message": "Success",
"agent": "002",
"task_id": 2,
"node": "worker2",
"module": "upgrade_module",
"command": "upgrade",
"status": "Failed",
"create_time": "2024-03-11T11:57:44.000Z",
"last_update_time": "2020-03-11T12:11:32.000Z"
}
],
"total_affected_items": 1,
"total_failed_items": 0,
"failed_items": []
},
"message": "All specified task's status were returned",
"error": 0
}
22 changes: 22 additions & 0 deletions docker/imposter/tasks/status_in_progress_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"data": {
"affected_items": [
{
"message": "Success",
"agent": "002",
"task_id": 2,
"node": "worker2",
"module": "upgrade_module",
"command": "upgrade",
"status": "In progress",
"create_time": "2024-03-11T11:57:44.000Z",
"last_update_time": "2020-03-11T11:57:46.000Z"
}
],
"total_affected_items": 1,
"total_failed_items": 0,
"failed_items": []
},
"message": "All specified task's status were returned",
"error": 0
}
33 changes: 33 additions & 0 deletions docker/imposter/tasks/status_in_progress_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"data": {
"affected_items": [
{
"message": "Success",
"agent": "001",
"task_id": 1,
"node": "worker2",
"module": "upgrade_module",
"command": "upgrade",
"status": "In progress",
"create_time": "2024-03-11T11:55:33.000Z",
"last_update_time": "2020-03-11T11:55:36.000Z"
},
{
"message": "Success",
"agent": "002",
"task_id": 2,
"node": "worker2",
"module": "upgrade_module",
"command": "upgrade",
"status": "In progress",
"create_time": "2024-03-11T11:57:44.000Z",
"last_update_time": "2020-03-11T11:57:46.000Z"
}
],
"total_affected_items": 2,
"total_failed_items": 0,
"failed_items": []
},
"message": "All specified task's status were returned",
"error": 0
}

0 comments on commit 620f4c5

Please sign in to comment.