ARI - GET /ari/asterisk/info

This patch adds basic system information access to ARI.

The results are roughly what you get from 'core show settings', with a
few minor differences.

 * Data is structured, with 'build', 'system', 'config' and 'status'
   sub-objects.
 * Each sub-object is selectable, using the ?only= parameter. A comma
   separated list can be provided to select multiple sections.
 * A few config options are numeric, for which 0 means 'unlimited'.
   Instead of having a special interpretation of those fields, they
   are simply omitted if they're 0.
 * The information is limited to what might be useful to building
   external applications.

(closes issue ASTERISK-21575)
Review: https://reviewboard.asterisk.org/r/2702/


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396125 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
David M. Lee
2013-08-02 14:46:21 +00:00
parent 537ecebd2d
commit 5114e4fc0b
4 changed files with 776 additions and 4 deletions

View File

@@ -31,12 +31,113 @@
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "resource_asterisk.h"
#include "asterisk/ast_version.h"
#include "asterisk/buildinfo.h"
#include "asterisk/paths.h"
#include "asterisk/pbx.h"
#include "resource_asterisk.h"
void ast_ari_get_asterisk_info(struct ast_variable *headers, struct ast_get_asterisk_info_args *args, struct ast_ari_response *response)
void ast_ari_get_asterisk_info(struct ast_variable *headers,
struct ast_get_asterisk_info_args *args,
struct ast_ari_response *response)
{
ast_log(LOG_ERROR, "TODO: ari_get_asterisk_info\n");
RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
int show_all = args->only_count == 0;
int show_build = show_all;
int show_system = show_all;
int show_config = show_all;
int show_status = show_all;
size_t i;
int res = 0;
for (i = 0; i < args->only_count; ++i) {
if (strcasecmp("build", args->only[i]) == 0) {
show_build = 1;
} else if (strcasecmp("system", args->only[i]) == 0) {
show_system = 1;
} else if (strcasecmp("config", args->only[i]) == 0) {
show_config = 1;
} else if (strcasecmp("status", args->only[i]) == 0) {
show_status = 1;
} else {
ast_log(LOG_WARNING, "Unrecognized info section '%s'\n",
args->only[i]);
}
}
json = ast_json_object_create();
if (show_build) {
res |= ast_json_object_set(json, "build",
ast_json_pack(
"{ s: s, s: s, s: s,"
" s: s, s: s, s: s }",
"os", ast_build_os,
"kernel", ast_build_kernel,
"machine", ast_build_machine,
"options", AST_BUILDOPTS,
"date", ast_build_date,
"user", ast_build_user));
}
if (show_system) {
char eid_str[128];
ast_eid_to_str(eid_str, sizeof(eid_str), &ast_eid_default);
res |= ast_json_object_set(json, "system",
ast_json_pack("{ s: s, s: s }",
"version", ast_get_version(),
"entity_id", eid_str));
}
if (show_config) {
struct ast_json *config = ast_json_pack(
"{ s: s, s: s,"
" s: { s: s, s: s } }",
"name", ast_config_AST_SYSTEM_NAME,
"default_language", defaultlanguage,
"setid",
"user", ast_config_AST_RUN_USER,
"group", ast_config_AST_RUN_GROUP);
res |= ast_json_object_set(json, "config", config);
if (option_maxcalls) {
res |= ast_json_object_set(config, "max_channels",
ast_json_integer_create(option_maxcalls));
}
if (option_maxfiles) {
res |= ast_json_object_set(config, "max_open_files",
ast_json_integer_create(option_maxfiles));
}
if (option_maxload) {
res |= ast_json_object_set(config, "max_load",
ast_json_real_create(option_maxload));
}
}
if (show_status) {
res |= ast_json_object_set(json, "status",
ast_json_pack("{ s: o, s: o }",
"startup_time",
ast_json_timeval(ast_startuptime, NULL),
"last_reload_time",
ast_json_timeval(ast_lastreloadtime, NULL)));
}
if (res != 0) {
ast_ari_response_alloc_failed(response);
return;
}
ast_ari_response_ok(response, ast_json_ref(json));
}
void ast_ari_get_global_var(struct ast_variable *headers, struct ast_get_global_var_args *args, struct ast_ari_response *response)