#915 add POST hardware command to REST API in ogAdmServer

This patch implements the command "hardware" that fetches the hardware
configuration from the clients.

Request:
	POST /hardware
        {"clients" : [ "192.168.2.1", "192.168.2.2" ]}
Reply:
        200 OK

This allows to refresh the hardware inventory from clients.
master
OpenGnSys Support Team 2019-06-21 13:22:12 +02:00
parent eae2385f67
commit 6b30dbc65c
2 changed files with 31 additions and 0 deletions

View File

@ -3874,6 +3874,27 @@ static int og_cmd_stop(json_t *element, struct og_msg_params *params)
return og_cmd_legacy_send(params, "Purgar", CLIENTE_APAGADO);
}
static int og_cmd_hardware(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, "InventarioHardware",
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";
@ -4034,6 +4055,15 @@ static int og_client_state_process_payload_rest(struct og_client *cli)
return og_client_not_found(cli);
}
err = og_cmd_refresh(root, &params);
} else if (!strncmp(cmd, "hardware", strlen("hardware"))) {
if (method != OG_METHOD_POST)
return -1;
if (!root) {
syslog(LOG_ERR, "command hardware with no payload\n");
return og_client_not_found(cli);
}
err = og_cmd_hardware(root, &params);
} else {
syslog(LOG_ERR, "unknown command %s\n", cmd);
err = og_client_not_found(cli);

View File

@ -10,3 +10,4 @@ curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/poweroff -d @pow
curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/reboot -d @reboot.json
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