[Asterisk-code-review] ami: Allow events to be globally disabled (asterisk[master])

N A asteriskteam at digium.com
Sun Jan 9 07:37:40 CST 2022


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/17793 )


Change subject: ami: Allow events to be globally disabled
......................................................................

ami: Allow events to be globally disabled

The disabledevents setting has been added
to the general section in manager.conf,
which allows users to specify events that
should be globally disabled and not sent
to any AMI listeners.

This allows for processing of these AMI
events to end sooner and, for frequent
AMI events such as Newexten which users
may not have any need for, can result in
a performance boost. Additionally, it also
cleans up core debug as previously when
debug was 3 or higher, the debug was
constantly spammed by "Analyzing AMI
event" messages along with a complete dump
of the event contents (often for Newexten).

ASTERISK-29853 #close

Change-Id: Id42b9a3722a1f460d745cad1ebc47c537fd4f205
---
M configs/samples/manager.conf.sample
A doc/CHANGES-staging/manager_disable.txt
M main/manager.c
3 files changed, 41 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/93/17793/1

diff --git a/configs/samples/manager.conf.sample b/configs/samples/manager.conf.sample
index 405e0d3..673b1c3 100644
--- a/configs/samples/manager.conf.sample
+++ b/configs/samples/manager.conf.sample
@@ -79,7 +79,14 @@
 ;    on a action=waitevent request (actually its httptimeout-10)
 ; c) httptimeout is also the amount of time the webserver keeps
 ;    a http session alive after completing a successful action
+;
+; disabledevents specifies AMI events which should be completely globally disabled.
+; These events will not be available to any AMI listeners. If used to disable
+; frequent events which are not desired, this can boost performance. Default
+; is no events are globally disabled. Event names are case-sensitive.
+; Events disabled in stasis.conf do not also need to be disabled here.
 
+;disabledevents = Newexten,Varset
 
 ;[mark]
 ;secret = mysecret
diff --git a/doc/CHANGES-staging/manager_disable.txt b/doc/CHANGES-staging/manager_disable.txt
new file mode 100644
index 0000000..762ceca
--- /dev/null
+++ b/doc/CHANGES-staging/manager_disable.txt
@@ -0,0 +1,4 @@
+Subject: ami
+
+AMI events can now be globally disabled using
+the disabledevents [general] setting.
diff --git a/main/manager.c b/main/manager.c
index 8307421..5755318 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -1479,6 +1479,7 @@
 static int authtimeout;
 static int authlimit;
 static char *manager_channelvars;
+static char *manager_disabledevents;
 
 #define DEFAULT_REALM		"asterisk"
 static char global_realm[MAXHOSTNAMELEN];	/*!< Default realm */
@@ -7238,6 +7239,15 @@
 	va_list ap;
 	int res;
 
+	if (!ast_strlen_zero(manager_disabledevents)) {
+		if (strstr(manager_disabledevents, event)) {
+			ast_debug(3, "AMI Event '%s' is globally disabled, skipping\n", event);
+			/* Event is globally disabled */
+			ao2_cleanup(sessions);
+			return 0;
+		}
+	}
+
 	if (!any_manager_listeners(sessions)) {
 		/* Nobody is listening */
 		ao2_cleanup(sessions);
@@ -8692,6 +8702,7 @@
 	ast_cli(a->fd, FORMAT, "Display connects:", AST_CLI_YESNO(displayconnects));
 	ast_cli(a->fd, FORMAT, "Timestamp events:", AST_CLI_YESNO(timestampevents));
 	ast_cli(a->fd, FORMAT, "Channel vars:", S_OR(manager_channelvars, ""));
+	ast_cli(a->fd, FORMAT, "Disabled events:", S_OR(manager_disabledevents, ""));
 	ast_cli(a->fd, FORMAT, "Debug:", AST_CLI_YESNO(manager_debug));
 #undef FORMAT
 #undef FORMAT2
@@ -8912,10 +8923,10 @@
  */
 static void load_channelvars(struct ast_variable *var)
 {
-        char *parse = NULL;
-        AST_DECLARE_APP_ARGS(args,
-                AST_APP_ARG(vars)[MAX_VARS];
-        );
+	char *parse = NULL;
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(vars)[MAX_VARS];
+	);
 
 	ast_free(manager_channelvars);
 	manager_channelvars = ast_strdup(var->value);
@@ -8929,6 +8940,18 @@
 
 /*!
  * \internal
+ * \brief Load the config disabledevents variable.
+ *
+ * \param var Config variable to load.
+ */
+static void load_disabledevents(struct ast_variable *var)
+{
+	ast_free(manager_disabledevents);
+	manager_disabledevents = ast_strdup(var->value);
+}
+
+/*!
+ * \internal
  * \brief Free a user record.  Should already be removed from the list
  */
 static void manager_free_user(struct ast_manager_user *user)
@@ -9041,6 +9064,7 @@
 	acl_change_stasis_unsubscribe();
 
 	ast_free(manager_channelvars);
+	ast_free(manager_disabledevents);
 }
 
 
@@ -9335,6 +9359,8 @@
 			}
 		} else if (!strcasecmp(var->name, "channelvars")) {
 			load_channelvars(var);
+		} else if (!strcasecmp(var->name, "disabledevents")) {
+			load_disabledevents(var);
 		} else {
 			ast_log(LOG_NOTICE, "Invalid keyword <%s> = <%s> in manager.conf [general]\n",
 				var->name, val);

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/17793
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Id42b9a3722a1f460d745cad1ebc47c537fd4f205
Gerrit-Change-Number: 17793
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220109/1afc4a68/attachment.html>


More information about the asterisk-code-review mailing list