From b76ab5e5c9dc51f88a5ee5c101410124b8283cfe Mon Sep 17 00:00:00 2001 From: George Joseph Date: Mon, 3 Feb 2020 09:24:58 -0700 Subject: [PATCH] message.c: Add option to suppress the Message channel AMI and ARI events In order to reduce the amount of AMI and ARI events generated, the global "Message/ast_msg_queue" channel can be set to suppress it's normal channel housekeeping events such as "Newexten", "VarSet", etc. This can greatly reduce load on the manager and ARI applications when the Digium Phone Module for Asterisk is in use. To enable, set "hide_messaging_ami_events" in asterisk.conf to "yes" In Asterisk versions <18, the default is "no" preserving existing behavior. Beginning with Asterisk 18, the option will default to "yes". NOTE: This change does not affect UserEvents or the ARI TextMessageReceived events. * Added the "hide_messaging_ami_events" option to asterisk.conf. * Changed message.c to set the AST_CHAN_TP_INTERNAL property on the "Message/ast_msg_queue" channel if the option is set in asterisk.conf. This suppresses the reporting of the events. Change-Id: Ia2e3516d43f4e0df994fc6598565d6bba2d7018b --- configs/samples/asterisk.conf.sample | 5 +++++ doc/CHANGES-staging/hide_messaging_ami_events | 11 +++++++++++ include/asterisk/options.h | 3 +++ main/asterisk.c | 1 + main/message.c | 6 +++++- main/options.c | 2 ++ 6 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 doc/CHANGES-staging/hide_messaging_ami_events diff --git a/configs/samples/asterisk.conf.sample b/configs/samples/asterisk.conf.sample index 5f33abbfe2..bf0bdba092 100644 --- a/configs/samples/asterisk.conf.sample +++ b/configs/samples/asterisk.conf.sample @@ -118,6 +118,11 @@ documentation_language = en_US ; Set the language you want documentation ; calls are not accepted by a remote ; implementation, please report this and go ; back to value 96. +;hide_messaging_ami_events = no; This option, if enabled, will + ; suppress all of the Message/ast_msg_queue channel's + ; housekeeping AMI and ARI channel events. This can + ; reduce the load on the manager and ARI applications + ; when the Digium Phone Module for Asterisk is in use. ; Changing the following lines may compromise your security. ;[files] diff --git a/doc/CHANGES-staging/hide_messaging_ami_events b/doc/CHANGES-staging/hide_messaging_ami_events new file mode 100644 index 0000000000..0afbeecdf7 --- /dev/null +++ b/doc/CHANGES-staging/hide_messaging_ami_events @@ -0,0 +1,11 @@ +Subject: Messaging + +In order to reduce the amount of AMI and ARI events generated, +the global "Message/ast_msg_queue" channel can be set to suppress +it's normal channel housekeeping events such as "Newexten", +"VarSet", etc. This can greatly reduce load on the manager +and ARI applications when the Digium Phone Module for Asterisk +is in use. To enable, set "hide_messaging_ami_events" in +asterisk.conf to "yes" In Asterisk versions <18, the default +is "no" preserving existing behavior. Beginning with +Asterisk 18, the option will default to "yes". diff --git a/include/asterisk/options.h b/include/asterisk/options.h index 6c4e552958..f8c813f19a 100644 --- a/include/asterisk/options.h +++ b/include/asterisk/options.h @@ -84,6 +84,8 @@ enum ast_option_flags { AST_OPT_FLAG_DEBUG_MODULE = (1 << 23), /*! Terminal colors should be adjusted for a light-colored background */ AST_OPT_FLAG_LIGHT_BACKGROUND = (1 << 25), + /*! Make the global Message channel an internal channel to suppress AMI events */ + AST_OPT_FLAG_HIDE_MESSAGING_AMI_EVENTS = (1 << 26), /*! Force black background */ AST_OPT_FLAG_FORCE_BLACK_BACKGROUND = (1 << 27), /*! Hide remote console connect messages on console */ @@ -129,6 +131,7 @@ enum ast_option_flags { #define ast_opt_generic_plc ast_test_flag(&ast_options, AST_OPT_FLAG_GENERIC_PLC) #define ast_opt_ref_debug ast_test_flag(&ast_options, AST_OPT_FLAG_REF_DEBUG) #define ast_opt_generic_plc_on_equal_codecs ast_test_flag(&ast_options, AST_OPT_FLAG_GENERIC_PLC_ON_EQUAL_CODECS) +#define ast_opt_hide_messaging_ami_events ast_test_flag(&ast_options, AST_OPT_FLAG_HIDE_MESSAGING_AMI_EVENTS) /*! Maximum log level defined by PJPROJECT. */ #define MAX_PJ_LOG_MAX_LEVEL 6 diff --git a/main/asterisk.c b/main/asterisk.c index dd2ae6f261..6ae921941d 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -509,6 +509,7 @@ static char *handle_show_settings(struct ast_cli_entry *e, int cmd, struct ast_c ast_cli(a->fd, " Transmit silence during rec: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSMIT_SILENCE) ? "Enabled" : "Disabled"); ast_cli(a->fd, " Generic PLC: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_GENERIC_PLC) ? "Enabled" : "Disabled"); ast_cli(a->fd, " Generic PLC on equal codecs: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_GENERIC_PLC_ON_EQUAL_CODECS) ? "Enabled" : "Disabled"); + ast_cli(a->fd, " Hide Msg Chan AMI events: %s\n", ast_opt_hide_messaging_ami_events ? "Enabled" : "Disabled"); ast_cli(a->fd, " Min DTMF duration:: %u\n", option_dtmfminduration); #if !defined(LOW_MEMORY) ast_cli(a->fd, " Cache media frames: %s\n", ast_opt_cache_media_frames ? "Enabled" : "Disabled"); diff --git a/main/message.c b/main/message.c index 4874162777..39b8d873e0 100644 --- a/main/message.c +++ b/main/message.c @@ -283,7 +283,7 @@ static int chan_msg_send_digit_end(struct ast_channel *chan, char digit, * This will not be registered as we never want anything to try * to create Message channels other than internally in this file. */ -static const struct ast_channel_tech msg_chan_tech_hack = { +static struct ast_channel_tech msg_chan_tech_hack = { .type = "Message", .description = "Internal Text Message Processing", .read = chan_msg_read, @@ -685,6 +685,10 @@ static struct ast_channel *create_msg_q_chan(void) return NULL; } + if (ast_opt_hide_messaging_ami_events) { + msg_chan_tech_hack.properties |= AST_CHAN_TP_INTERNAL; + } + ast_channel_tech_set(chan, &msg_chan_tech_hack); ast_channel_unlock(chan); ast_channel_unlink(chan); diff --git a/main/options.c b/main/options.c index ea97a6a0ac..38a646e178 100644 --- a/main/options.c +++ b/main/options.c @@ -457,6 +457,8 @@ void load_asterisk_conf(void) } } else if (!strcasecmp(v->name, "live_dangerously")) { live_dangerously = ast_true(v->value); + } else if (!strcasecmp(v->name, "hide_messaging_ami_events")) { + ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_HIDE_MESSAGING_AMI_EVENTS); } } if (!ast_opt_remote) {