From df5161ebc351df35504bd6366526a544ff6a96da Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Tue, 10 May 2022 17:18:15 +0200 Subject: #915 Add last_cmd to GET /clients API "last_cmd" json object contains information of the last command executed by the correspondent client. For now, it only includes "result" string property, which stores "success" if the last command finished correctly or "failure" on the contrary. To populate "result" property, this commit also adds "last_cmd_result" enum attribute to og_client struct. Client response processing fills this attribute according to its success. Clients in WOL_SENT state always have last_cmd->result = "unknown". Request: GET /clients Response: 200 OK { "clients": [ { "addr": "10.141.10.102", "state": "WOL_SENT", "last_cmd": { "result": "unknown" } }, { "addr": "10.141.10.101", "state": "OPG", "speed": 1000, "last_cmd": { "result": "success" } }, { "addr": "10.141.10.100", "state": "OPG", "speed": 1000, "last_cmd": { "result": "failure" } } ] } --- src/client.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/client.c') diff --git a/src/client.c b/src/client.c index f4a47eb..a53f52c 100644 --- a/src/client.c +++ b/src/client.c @@ -768,6 +768,11 @@ int og_agent_state_process_response(struct og_client *cli) break; } + if (success) + cli->last_cmd_result = OG_SUCCESS; + else + cli->last_cmd_result = OG_FAILURE; + if (code != 200 && code != 103) { og_dbi_update_action(cli->last_cmd_id, success); cli->last_cmd_id = 0; @@ -831,6 +836,7 @@ int og_agent_state_process_response(struct og_client *cli) if (err < 0) { err = 0; success = false; + cli->last_cmd_result = OG_FAILURE; /* ... cancel pending actions related to this task for this client here */ } -- cgit v1.2.3-18-g5258