diff options
author | OpenGnSys Support Team <soporte-og@soleta.eu> | 2019-06-21 13:30:40 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2019-07-03 02:56:07 +0200 |
commit | a0f41fca6e0f505e2bc21d8868629fecc363d0fa (patch) | |
tree | f1537960a892f97f698de168d6b928f6e09cfd03 | |
parent | 1316c877b4c1798f00f1e98606350041b5394614 (diff) |
#915 add POST software command to REST API in ogAdmServer
This patch implements the command "software" that fetches the software
configuration from the clients.
Request:
POST /software
{"clients" : [ "192.168.2.1", "192.168.2.2" ]}
Reply:
200 OK
This allows to refresh the software inventory from clients.
-rw-r--r-- | admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp | 30 | ||||
-rwxr-xr-x | admin/Sources/Services/ogAdmServer/tests/run-tests.sh | 1 |
2 files changed, 31 insertions, 0 deletions
diff --git a/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp b/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp index 2fc9b3fa..c9b10484 100644 --- a/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp +++ b/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp @@ -3895,6 +3895,27 @@ static int og_cmd_hardware(json_t *element, struct og_msg_params *params) CLIENTE_OCUPADO); } +static int og_cmd_software(json_t *element, struct og_msg_params *params) +{ + const char *key; + json_t *value; + int err = 0; + + if (json_typeof(element) != JSON_OBJECT) + return -1; + + json_object_foreach(element, key, value) { + if (!strcmp(key, "clients")) + err = og_json_parse_clients(value, params); + + if (err < 0) + break; + } + + return og_cmd_legacy_send(params, "InventarioSoftware", + CLIENTE_OCUPADO); +} + static int og_client_not_found(struct og_client *cli) { char buf[] = "HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\n\r\n"; @@ -4064,6 +4085,15 @@ static int og_client_state_process_payload_rest(struct og_client *cli) return og_client_not_found(cli); } err = og_cmd_hardware(root, ¶ms); + } else if (!strncmp(cmd, "software", strlen("software"))) { + if (method != OG_METHOD_POST) + return -1; + + if (!root) { + syslog(LOG_ERR, "command software with no payload\n"); + return og_client_not_found(cli); + } + err = og_cmd_software(root, ¶ms); } else { syslog(LOG_ERR, "unknown command %s\n", cmd); err = og_client_not_found(cli); diff --git a/admin/Sources/Services/ogAdmServer/tests/run-tests.sh b/admin/Sources/Services/ogAdmServer/tests/run-tests.sh index dfa48433..f22df02a 100755 --- a/admin/Sources/Services/ogAdmServer/tests/run-tests.sh +++ b/admin/Sources/Services/ogAdmServer/tests/run-tests.sh @@ -11,3 +11,4 @@ curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/reboot -d @reboo curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/stop -d @stop.json curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/refresh -d @refresh.json curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/hardware -d @post_clients.json +curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/software -d @post_clients.json |