mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-16 09:46:22 +00:00
Added ARI resource /ari/asterisk/ping
Added ARI resource. GET /ari/asterisk/ping : It returns "pong" message with timestamp and asterisk id. It would be useful for simple heath check. Change-Id: I8d24e1dcc96f60f73437c68d9463ed746f688b29
This commit is contained in:
@@ -395,6 +395,56 @@ fin: __attribute__((unused))
|
||||
ast_free(args.only);
|
||||
return;
|
||||
}
|
||||
/*!
|
||||
* \brief Parameter parsing callback for /asterisk/ping.
|
||||
* \param get_params GET parameters in the HTTP request.
|
||||
* \param path_vars Path variables extracted from the request.
|
||||
* \param headers HTTP headers.
|
||||
* \param[out] response Response to the HTTP request.
|
||||
*/
|
||||
static void ast_ari_asterisk_ping_cb(
|
||||
struct ast_tcptls_session_instance *ser,
|
||||
struct ast_variable *get_params, struct ast_variable *path_vars,
|
||||
struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
|
||||
{
|
||||
struct ast_ari_asterisk_ping_args args = {};
|
||||
#if defined(AST_DEVMODE)
|
||||
int is_valid;
|
||||
int code;
|
||||
#endif /* AST_DEVMODE */
|
||||
|
||||
ast_ari_asterisk_ping(headers, &args, response);
|
||||
#if defined(AST_DEVMODE)
|
||||
code = response->response_code;
|
||||
|
||||
switch (code) {
|
||||
case 0: /* Implementation is still a stub, or the code wasn't set */
|
||||
is_valid = response->message == NULL;
|
||||
break;
|
||||
case 500: /* Internal Server Error */
|
||||
case 501: /* Not Implemented */
|
||||
is_valid = 1;
|
||||
break;
|
||||
default:
|
||||
if (200 <= code && code <= 299) {
|
||||
is_valid = ast_ari_validate_asterisk_ping(
|
||||
response->message);
|
||||
} else {
|
||||
ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/ping\n", code);
|
||||
is_valid = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_valid) {
|
||||
ast_log(LOG_ERROR, "Response validation failed for /asterisk/ping\n");
|
||||
ast_ari_response_error(response, 500,
|
||||
"Internal Server Error", "Response validation failed");
|
||||
}
|
||||
#endif /* AST_DEVMODE */
|
||||
|
||||
fin: __attribute__((unused))
|
||||
return;
|
||||
}
|
||||
/*!
|
||||
* \brief Parameter parsing callback for /asterisk/modules.
|
||||
* \param get_params GET parameters in the HTTP request.
|
||||
@@ -1142,6 +1192,15 @@ static struct stasis_rest_handlers asterisk_info = {
|
||||
.children = { }
|
||||
};
|
||||
/*! \brief REST handler for /api-docs/asterisk.json */
|
||||
static struct stasis_rest_handlers asterisk_ping = {
|
||||
.path_segment = "ping",
|
||||
.callbacks = {
|
||||
[AST_HTTP_GET] = ast_ari_asterisk_ping_cb,
|
||||
},
|
||||
.num_children = 0,
|
||||
.children = { }
|
||||
};
|
||||
/*! \brief REST handler for /api-docs/asterisk.json */
|
||||
static struct stasis_rest_handlers asterisk_modules_moduleName = {
|
||||
.path_segment = "moduleName",
|
||||
.is_wildcard = 1,
|
||||
@@ -1207,8 +1266,8 @@ static struct stasis_rest_handlers asterisk = {
|
||||
.path_segment = "asterisk",
|
||||
.callbacks = {
|
||||
},
|
||||
.num_children = 5,
|
||||
.children = { &asterisk_config,&asterisk_info,&asterisk_modules,&asterisk_logging,&asterisk_variable, }
|
||||
.num_children = 6,
|
||||
.children = { &asterisk_config,&asterisk_info,&asterisk_ping,&asterisk_modules,&asterisk_logging,&asterisk_variable, }
|
||||
};
|
||||
|
||||
static int unload_module(void)
|
||||
|
Reference in New Issue
Block a user