mirror of https://git.48k.eu/ogserver
rest: add cmd to shell/output
Add "cmd" field to json that provides the original command string, so it is provided with the output and the return code.master
parent
12d5caf6a6
commit
6cbe69e89e
10
src/client.c
10
src/client.c
|
@ -171,7 +171,7 @@ static int og_resp_probe(struct og_client *cli, json_t *data)
|
||||||
|
|
||||||
static int og_resp_shell_run(struct og_client *cli, json_t *data)
|
static int og_resp_shell_run(struct og_client *cli, json_t *data)
|
||||||
{
|
{
|
||||||
const char *output = NULL;
|
const char *cmd = NULL, *output = NULL;
|
||||||
uint32_t retcode;
|
uint32_t retcode;
|
||||||
const char *key;
|
const char *key;
|
||||||
json_t *value;
|
json_t *value;
|
||||||
|
@ -181,7 +181,11 @@ static int og_resp_shell_run(struct og_client *cli, json_t *data)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
json_object_foreach(data, key, value) {
|
json_object_foreach(data, key, value) {
|
||||||
if (!strcmp(key, "out")) {
|
if (!strcmp(key, "cmd")) {
|
||||||
|
err = og_json_parse_string(value, &cmd);
|
||||||
|
if (err < 0)
|
||||||
|
return err;
|
||||||
|
} else if (!strcmp(key, "out")) {
|
||||||
err = og_json_parse_string(value, &output);
|
err = og_json_parse_string(value, &output);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
@ -199,7 +203,9 @@ static int og_resp_shell_run(struct og_client *cli, json_t *data)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free((void *)cli->shell.cmd);
|
||||||
free((void *)cli->shell.output);
|
free((void *)cli->shell.output);
|
||||||
|
cli->shell.cmd = strdup(cmd);
|
||||||
cli->shell.output = strdup(output);
|
cli->shell.output = strdup(output);
|
||||||
cli->shell.retcode = retcode;
|
cli->shell.retcode = retcode;
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ static void og_client_release(struct ev_loop *loop, struct og_client *cli)
|
||||||
ev_timer_stop(loop, &cli->timer);
|
ev_timer_stop(loop, &cli->timer);
|
||||||
ev_io_stop(loop, &cli->io);
|
ev_io_stop(loop, &cli->io);
|
||||||
close(cli->io.fd);
|
close(cli->io.fd);
|
||||||
|
free((void *)cli->shell.cmd);
|
||||||
free((void *)cli->shell.output);
|
free((void *)cli->shell.output);
|
||||||
free(cli);
|
free(cli);
|
||||||
}
|
}
|
||||||
|
|
10
src/rest.c
10
src/rest.c
|
@ -777,7 +777,7 @@ static int og_cmd_run_get(json_t *element, struct og_msg_params *params,
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (i = 0; i < params->ips_array_len; i++) {
|
for (i = 0; i < params->ips_array_len; i++) {
|
||||||
json_t *object, *output, *addr;
|
json_t *object, *output, *addr, *cmd;
|
||||||
struct og_client *cli;
|
struct og_client *cli;
|
||||||
|
|
||||||
cli = og_client_find(params->ips_array[i]);
|
cli = og_client_find(params->ips_array[i]);
|
||||||
|
@ -797,6 +797,14 @@ static int og_cmd_run_get(json_t *element, struct og_msg_params *params,
|
||||||
}
|
}
|
||||||
json_object_set_new(object, "addr", addr);
|
json_object_set_new(object, "addr", addr);
|
||||||
|
|
||||||
|
cmd = json_string(cli->shell.cmd);
|
||||||
|
if (!cmd) {
|
||||||
|
json_decref(object);
|
||||||
|
json_decref(array);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
json_object_set_new(object, "cmd", cmd);
|
||||||
|
|
||||||
output = json_string(cli->shell.output);
|
output = json_string(cli->shell.output);
|
||||||
if (!output) {
|
if (!output) {
|
||||||
json_decref(object);
|
json_decref(object);
|
||||||
|
|
|
@ -72,6 +72,7 @@ struct og_client {
|
||||||
uint32_t speed;
|
uint32_t speed;
|
||||||
uint32_t seq;
|
uint32_t seq;
|
||||||
struct {
|
struct {
|
||||||
|
const char *cmd;
|
||||||
const char *output;
|
const char *output;
|
||||||
uint32_t retcode;
|
uint32_t retcode;
|
||||||
} shell;
|
} shell;
|
||||||
|
|
Loading…
Reference in New Issue