Skip to content

Commit 386c5e4

Browse files
InterLinked1Friendly Automation
authored and
Friendly Automation
committed
cdr: allow disabling CDR by default on new channels
Adds a new option, defaultenabled, to the CDR core to control whether or not CDR is enabled on a newly created channel. This allows CDR to be disabled by default on new channels and require the user to explicitly enable CDR if desired. Existing behavior remains unchanged. ASTERISK-29808 #close Change-Id: Ibb78c11974bda229bbb7004b64761980e0b2c6d1
1 parent 70f8ea0 commit 386c5e4

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed

configs/samples/cdr.conf.sample

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
; any loading of backend CDR modules. Default is "yes".
1414
;enable=yes
1515

16+
; Define whether or not to use CDR logging on new channels by default.
17+
; Setting this to "no" will disable CDR on channels unless it is explicitly
18+
; enabled. Default is "yes".
19+
;channeldefaultenabled=yes
20+
1621
; Define whether or not to log unanswered calls that don't involve an outgoing
1722
; party. Setting this to "yes" will make calls to extensions that don't answer
1823
; and don't set a B side channel (such as by using the Dial application)

doc/CHANGES-staging/cdr_disable.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Subject: cdr
2+
3+
A new CDR option, channeldefaultenabled, allows controlling
4+
whether CDR is enabled or disabled by default on
5+
newly created channels. The default behavior remains
6+
unchanged from previous versions of Asterisk (new
7+
channels will have CDR enabled, as long as CDR is
8+
enabled globally).

include/asterisk/cdr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ enum ast_cdr_settings {
224224
CDR_END_BEFORE_H_EXTEN = 1 << 4, /*!< End the CDR before the 'h' extension runs */
225225
CDR_INITIATED_SECONDS = 1 << 5, /*!< Include microseconds into the billing time */
226226
CDR_DEBUG = 1 << 6, /*!< Enables extra debug statements */
227+
CDR_CHANNEL_DEFAULT_ENABLED = 1 << 7, /*!< Whether CDR is enabled for each channel by default */
227228
};
228229

229230
/*! \brief CDR Batch Mode settings */

main/cdr.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,21 @@
9696
any loading of backend CDR modules. Default is "yes".</para>
9797
</description>
9898
</configOption>
99+
<configOption name="channeldefaultenabled">
100+
<synopsis>Whether CDR is enabled on a channel by default</synopsis>
101+
<description><para>Define whether or not CDR should be enabled on a channel by default.
102+
Setting this to "yes" will enable CDR on every channel unless it is explicitly disabled.
103+
Setting this to "no" will disable CDR on every channel unless it is explicitly enabled.
104+
Default is "yes".</para>
105+
<para>Note that CDR must still be globally enabled (<literal>enable = yes</literal>) for this
106+
option to have any effect. This only applies to whether CDR is enabled or disabled on
107+
newly created channels, which can be changed in the dialplan during a call.</para>
108+
<para>If this is set to "yes", you should use <literal>Set(CDR_PROP(disable)=1)</literal>
109+
to disable CDR for a call.</para>
110+
<para>If this is set to "no", you should use <literal>Set(CDR_PROP(disable)=0)</literal>
111+
to undisable (enable) CDR for a call.</para>
112+
</description>
113+
</configOption>
99114
<configOption name="unanswered">
100115
<synopsis>Log calls that are never answered and don't set an outgoing party.</synopsis>
101116
<description><para>
@@ -192,6 +207,7 @@
192207
#define DEFAULT_CONGESTION "0"
193208
#define DEFAULT_END_BEFORE_H_EXTEN "1"
194209
#define DEFAULT_INITIATED_SECONDS "0"
210+
#define DEFAULT_CHANNEL_ENABLED "1"
195211

196212
#define DEFAULT_BATCH_SIZE "100"
197213
#define MAX_BATCH_SIZE 1000
@@ -2281,12 +2297,25 @@ static void handle_channel_snapshot_update_message(void *data, struct stasis_sub
22812297
}
22822298

22832299
if (update->new_snapshot && !update->old_snapshot) {
2300+
struct module_config *mod_cfg = NULL;
2301+
22842302
cdr = cdr_object_alloc(update->new_snapshot, stasis_message_timestamp(message));
22852303
if (!cdr) {
22862304
return;
22872305
}
2306+
mod_cfg = ao2_global_obj_ref(module_configs);
22882307
cdr->is_root = 1;
22892308
ao2_link(active_cdrs_master, cdr);
2309+
2310+
/* If CDR should be disabled unless enabled on a per-channel basis, then disable
2311+
CDR, right from the get go */
2312+
if (mod_cfg) {
2313+
if (!ast_test_flag(&mod_cfg->general->settings, CDR_CHANNEL_DEFAULT_ENABLED)) {
2314+
ast_debug(3, "Disable CDR by default\n");
2315+
ast_set_flag(&cdr->flags, AST_CDR_FLAG_DISABLE_ALL);
2316+
}
2317+
ao2_cleanup(mod_cfg);
2318+
}
22902319
} else {
22912320
cdr = ao2_find(active_cdrs_master, update->new_snapshot->base->uniqueid, OBJ_SEARCH_KEY);
22922321
}
@@ -4168,6 +4197,7 @@ static char *handle_cli_status(struct ast_cli_entry *e, int cmd, struct ast_cli_
41684197
ast_cli(a->fd, " Logging: %s\n", ast_test_flag(&mod_cfg->general->settings, CDR_ENABLED) ? "Enabled" : "Disabled");
41694198
ast_cli(a->fd, " Mode: %s\n", ast_test_flag(&mod_cfg->general->settings, CDR_BATCHMODE) ? "Batch" : "Simple");
41704199
if (ast_test_flag(&mod_cfg->general->settings, CDR_ENABLED)) {
4200+
ast_cli(a->fd, " Log calls by default: %s\n", ast_test_flag(&mod_cfg->general->settings, CDR_CHANNEL_DEFAULT_ENABLED) ? "Yes" : "No");
41714201
ast_cli(a->fd, " Log unanswered calls: %s\n", ast_test_flag(&mod_cfg->general->settings, CDR_UNANSWERED) ? "Yes" : "No");
41724202
ast_cli(a->fd, " Log congestion: %s\n\n", ast_test_flag(&mod_cfg->general->settings, CDR_CONGESTION) ? "Yes" : "No");
41734203
if (ast_test_flag(&mod_cfg->general->settings, CDR_BATCHMODE)) {
@@ -4348,6 +4378,7 @@ static int process_config(int reload)
43484378
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);
43494379
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);
43504380
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);
4381+
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);
43514382
}
43524383

43534384
if (aco_process_config(&cfg_info, reload) == ACO_PROCESS_ERROR) {

tests/test_cdr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ static struct ast_cdr_config *saved_config;
5959

6060
/*! \brief A configuration suitable for 'normal' CDRs */
6161
static struct ast_cdr_config debug_cdr_config = {
62-
.settings.flags = CDR_ENABLED | CDR_DEBUG,
62+
.settings.flags = CDR_ENABLED | CDR_CHANNEL_DEFAULT_ENABLED | CDR_DEBUG,
6363
};
6464

6565
/*! \brief A configuration suitable for CDRs with unanswered records */
6666
static struct ast_cdr_config unanswered_cdr_config = {
67-
.settings.flags = CDR_ENABLED | CDR_UNANSWERED | CDR_DEBUG,
67+
.settings.flags = CDR_ENABLED | CDR_CHANNEL_DEFAULT_ENABLED | CDR_UNANSWERED | CDR_DEBUG,
6868
};
6969

7070
/*! \brief A configuration suitable for CDRs with congestion enabled */
7171
static struct ast_cdr_config congestion_cdr_config = {
72-
.settings.flags = CDR_ENABLED | CDR_UNANSWERED | CDR_DEBUG | CDR_CONGESTION,
72+
.settings.flags = CDR_ENABLED | CDR_CHANNEL_DEFAULT_ENABLED | CDR_UNANSWERED | CDR_DEBUG | CDR_CONGESTION,
7373
};
7474

7575
/*! \brief Macro to swap a configuration out from the CDR engine. This should be

0 commit comments

Comments
 (0)