<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/17701">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Kevin Harwell: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Michael Bradeen: Looks good to me, but someone else must approve
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">cdr: allow disabling CDR by default on new channels<br><br>Adds a new option, defaultenabled, to the CDR core to<br>control whether or not CDR is enabled on a newly created<br>channel. This allows CDR to be disabled by default on<br>new channels and require the user to explicitly enable<br>CDR if desired. Existing behavior remains unchanged.<br><br>ASTERISK-29808 #close<br><br>Change-Id: Ibb78c11974bda229bbb7004b64761980e0b2c6d1<br>---<br>M configs/samples/cdr.conf.sample<br>A doc/CHANGES-staging/cdr_disable.txt<br>M include/asterisk/cdr.h<br>M main/cdr.c<br>M tests/test_cdr.c<br>5 files changed, 48 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/configs/samples/cdr.conf.sample b/configs/samples/cdr.conf.sample</span><br><span>index 5cd1dc1..4fce18b 100644</span><br><span>--- a/configs/samples/cdr.conf.sample</span><br><span>+++ b/configs/samples/cdr.conf.sample</span><br><span>@@ -13,6 +13,11 @@</span><br><span> ; any loading of backend CDR modules. Default is "yes".</span><br><span> ;enable=yes</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+; Define whether or not to use CDR logging on new channels by default.</span><br><span style="color: hsl(120, 100%, 40%);">+; Setting this to "no" will disable CDR on channels unless it is explicitly</span><br><span style="color: hsl(120, 100%, 40%);">+; enabled. Default is "yes".</span><br><span style="color: hsl(120, 100%, 40%);">+;channeldefaultenabled=yes</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ; Define whether or not to log unanswered calls that don't involve an outgoing</span><br><span> ; party. Setting this to "yes" will make calls to extensions that don't answer</span><br><span> ; and don't set a B side channel (such as by using the Dial application)</span><br><span>diff --git a/doc/CHANGES-staging/cdr_disable.txt b/doc/CHANGES-staging/cdr_disable.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..cae7a7c</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/cdr_disable.txt</span><br><span>@@ -0,0 +1,8 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: cdr</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+A new CDR option, channeldefaultenabled, allows controlling</span><br><span style="color: hsl(120, 100%, 40%);">+whether CDR is enabled or disabled by default on</span><br><span style="color: hsl(120, 100%, 40%);">+newly created channels. The default behavior remains</span><br><span style="color: hsl(120, 100%, 40%);">+unchanged from previous versions of Asterisk (new</span><br><span style="color: hsl(120, 100%, 40%);">+channels will have CDR enabled, as long as CDR is</span><br><span style="color: hsl(120, 100%, 40%);">+enabled globally).</span><br><span>diff --git a/include/asterisk/cdr.h b/include/asterisk/cdr.h</span><br><span>index e2a5a90..2bbfbdb 100644</span><br><span>--- a/include/asterisk/cdr.h</span><br><span>+++ b/include/asterisk/cdr.h</span><br><span>@@ -224,6 +224,7 @@</span><br><span> CDR_END_BEFORE_H_EXTEN = 1 << 4, /*!< End the CDR before the 'h' extension runs */</span><br><span> CDR_INITIATED_SECONDS = 1 << 5, /*!< Include microseconds into the billing time */</span><br><span> CDR_DEBUG = 1 << 6, /*!< Enables extra debug statements */</span><br><span style="color: hsl(120, 100%, 40%);">+ CDR_CHANNEL_DEFAULT_ENABLED = 1 << 7, /*!< Whether CDR is enabled for each channel by default */</span><br><span> };</span><br><span> </span><br><span> /*! \brief CDR Batch Mode settings */</span><br><span>diff --git a/main/cdr.c b/main/cdr.c</span><br><span>index 5558092..8a3ad66 100644</span><br><span>--- a/main/cdr.c</span><br><span>+++ b/main/cdr.c</span><br><span>@@ -96,6 +96,21 @@</span><br><span> any loading of backend CDR modules. Default is "yes".</para></span><br><span> </description></span><br><span> </configOption></span><br><span style="color: hsl(120, 100%, 40%);">+ <configOption name="channeldefaultenabled"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>Whether CDR is enabled on a channel by default</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ <description><para>Define whether or not CDR should be enabled on a channel by default.</span><br><span style="color: hsl(120, 100%, 40%);">+ Setting this to "yes" will enable CDR on every channel unless it is explicitly disabled.</span><br><span style="color: hsl(120, 100%, 40%);">+ Setting this to "no" will disable CDR on every channel unless it is explicitly enabled.</span><br><span style="color: hsl(120, 100%, 40%);">+ Default is "yes".</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>Note that CDR must still be globally enabled (<literal>enable = yes</literal>) for this</span><br><span style="color: hsl(120, 100%, 40%);">+ option to have any effect. This only applies to whether CDR is enabled or disabled on</span><br><span style="color: hsl(120, 100%, 40%);">+ newly created channels, which can be changed in the dialplan during a call.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>If this is set to "yes", you should use <literal>Set(CDR_PROP(disable)=1)</literal></span><br><span style="color: hsl(120, 100%, 40%);">+ to disable CDR for a call.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>If this is set to "no", you should use <literal>Set(CDR_PROP(disable)=0)</literal></span><br><span style="color: hsl(120, 100%, 40%);">+ to undisable (enable) CDR for a call.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </description></span><br><span style="color: hsl(120, 100%, 40%);">+ </configOption></span><br><span> <configOption name="unanswered"></span><br><span> <synopsis>Log calls that are never answered and don't set an outgoing party.</synopsis></span><br><span> <description><para></span><br><span>@@ -192,6 +207,7 @@</span><br><span> #define DEFAULT_CONGESTION "0"</span><br><span> #define DEFAULT_END_BEFORE_H_EXTEN "1"</span><br><span> #define DEFAULT_INITIATED_SECONDS "0"</span><br><span style="color: hsl(120, 100%, 40%);">+#define DEFAULT_CHANNEL_ENABLED "1"</span><br><span> </span><br><span> #define DEFAULT_BATCH_SIZE "100"</span><br><span> #define MAX_BATCH_SIZE 1000</span><br><span>@@ -2281,12 +2297,25 @@</span><br><span> }</span><br><span> </span><br><span> if (update->new_snapshot && !update->old_snapshot) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct module_config *mod_cfg = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> cdr = cdr_object_alloc(update->new_snapshot, stasis_message_timestamp(message));</span><br><span> if (!cdr) {</span><br><span> return;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ mod_cfg = ao2_global_obj_ref(module_configs);</span><br><span> cdr->is_root = 1;</span><br><span> ao2_link(active_cdrs_master, cdr);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* If CDR should be disabled unless enabled on a per-channel basis, then disable</span><br><span style="color: hsl(120, 100%, 40%);">+ CDR, right from the get go */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (mod_cfg) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_test_flag(&mod_cfg->general->settings, CDR_CHANNEL_DEFAULT_ENABLED)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(3, "Disable CDR by default\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_set_flag(&cdr->flags, AST_CDR_FLAG_DISABLE_ALL);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(mod_cfg);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> } else {</span><br><span> cdr = ao2_find(active_cdrs_master, update->new_snapshot->base->uniqueid, OBJ_SEARCH_KEY);</span><br><span> }</span><br><span>@@ -4168,6 +4197,7 @@</span><br><span> ast_cli(a->fd, " Logging: %s\n", ast_test_flag(&mod_cfg->general->settings, CDR_ENABLED) ? "Enabled" : "Disabled");</span><br><span> ast_cli(a->fd, " Mode: %s\n", ast_test_flag(&mod_cfg->general->settings, CDR_BATCHMODE) ? "Batch" : "Simple");</span><br><span> if (ast_test_flag(&mod_cfg->general->settings, CDR_ENABLED)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, " Log calls by default: %s\n", ast_test_flag(&mod_cfg->general->settings, CDR_CHANNEL_DEFAULT_ENABLED) ? "Yes" : "No");</span><br><span> ast_cli(a->fd, " Log unanswered calls: %s\n", ast_test_flag(&mod_cfg->general->settings, CDR_UNANSWERED) ? "Yes" : "No");</span><br><span> ast_cli(a->fd, " Log congestion: %s\n\n", ast_test_flag(&mod_cfg->general->settings, CDR_CONGESTION) ? "Yes" : "No");</span><br><span> if (ast_test_flag(&mod_cfg->general->settings, CDR_BATCHMODE)) {</span><br><span>@@ -4348,6 +4378,7 @@</span><br><span> aco_option_register(&cfg_info, "safeshutdown", ACO_EXACT, general_options, DEFAULT_BATCH_SAFE_SHUTDOWN, OPT_BOOLFLAG_T, 1, FLDSET(struct ast_cdr_config, batch_settings.settings), BATCH_MODE_SAFE_SHUTDOWN);</span><br><span> aco_option_register(&cfg_info, "size", ACO_EXACT, general_options, DEFAULT_BATCH_SIZE, OPT_UINT_T, PARSE_IN_RANGE, FLDSET(struct ast_cdr_config, batch_settings.size), 0, MAX_BATCH_SIZE);</span><br><span> aco_option_register(&cfg_info, "time", ACO_EXACT, general_options, DEFAULT_BATCH_TIME, OPT_UINT_T, PARSE_IN_RANGE, FLDSET(struct ast_cdr_config, batch_settings.time), 1, MAX_BATCH_TIME);</span><br><span style="color: hsl(120, 100%, 40%);">+ aco_option_register(&cfg_info, "channeldefaultenabled", ACO_EXACT, general_options, DEFAULT_CHANNEL_ENABLED, OPT_BOOLFLAG_T, 1, FLDSET(struct ast_cdr_config, settings), CDR_CHANNEL_DEFAULT_ENABLED);</span><br><span> }</span><br><span> </span><br><span> if (aco_process_config(&cfg_info, reload) == ACO_PROCESS_ERROR) {</span><br><span>diff --git a/tests/test_cdr.c b/tests/test_cdr.c</span><br><span>index bdbffcc..cef519d 100644</span><br><span>--- a/tests/test_cdr.c</span><br><span>+++ b/tests/test_cdr.c</span><br><span>@@ -59,17 +59,17 @@</span><br><span> </span><br><span> /*! \brief A configuration suitable for 'normal' CDRs */</span><br><span> static struct ast_cdr_config debug_cdr_config = {</span><br><span style="color: hsl(0, 100%, 40%);">- .settings.flags = CDR_ENABLED | CDR_DEBUG,</span><br><span style="color: hsl(120, 100%, 40%);">+ .settings.flags = CDR_ENABLED | CDR_CHANNEL_DEFAULT_ENABLED | CDR_DEBUG,</span><br><span> };</span><br><span> </span><br><span> /*! \brief A configuration suitable for CDRs with unanswered records */</span><br><span> static struct ast_cdr_config unanswered_cdr_config = {</span><br><span style="color: hsl(0, 100%, 40%);">- .settings.flags = CDR_ENABLED | CDR_UNANSWERED | CDR_DEBUG,</span><br><span style="color: hsl(120, 100%, 40%);">+ .settings.flags = CDR_ENABLED | CDR_CHANNEL_DEFAULT_ENABLED | CDR_UNANSWERED | CDR_DEBUG,</span><br><span> };</span><br><span> </span><br><span> /*! \brief A configuration suitable for CDRs with congestion enabled */</span><br><span> static struct ast_cdr_config congestion_cdr_config = {</span><br><span style="color: hsl(0, 100%, 40%);">- .settings.flags = CDR_ENABLED | CDR_UNANSWERED | CDR_DEBUG | CDR_CONGESTION,</span><br><span style="color: hsl(120, 100%, 40%);">+ .settings.flags = CDR_ENABLED | CDR_CHANNEL_DEFAULT_ENABLED | CDR_UNANSWERED | CDR_DEBUG | CDR_CONGESTION,</span><br><span> };</span><br><span> </span><br><span> /*! \brief Macro to swap a configuration out from the CDR engine. This should be</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/17701">change 17701</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/17701"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ibb78c11974bda229bbb7004b64761980e0b2c6d1 </div>
<div style="display:none"> Gerrit-Change-Number: 17701 </div>
<div style="display:none"> Gerrit-PatchSet: 9 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Michael Bradeen <mbradeen@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>