Merge pull request #91 from lazedo/event-channel-debug

[core] allow event-channel debugging & single delivery
This commit is contained in:
Andrey Volk 2019-11-15 23:37:36 +04:00 committed by GitHub
commit 66aa064588
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 6 deletions

View File

@ -387,7 +387,9 @@ typedef enum {
SCF_DIALPLAN_TIMESTAMPS = (1 << 24),
SCF_CPF_SOFT_PREFIX = (1 << 25),
SCF_CPF_SOFT_LOOKUP = (1 << 26),
SCF_EVENT_CHANNEL_ENABLE_HIERARCHY_DELIVERY = (1 << 27)
SCF_EVENT_CHANNEL_ENABLE_HIERARCHY_DELIVERY = (1 << 27),
SCF_EVENT_CHANNEL_HIERARCHY_DELIVERY_ONCE = (1 << 28),
SCF_EVENT_CHANNEL_LOG_UNDELIVERABLE_JSON = (1 << 29)
} switch_core_flag_enum_t;
typedef uint32_t switch_core_flag_t;

View File

@ -2369,6 +2369,20 @@ static void switch_load_core_config(const char *file)
} else {
switch_clear_flag((&runtime), SCF_EVENT_CHANNEL_ENABLE_HIERARCHY_DELIVERY);
}
} else if (!strcasecmp(var, "event-channel-hierarchy-deliver-once") && !zstr(val)) {
int v = switch_true(val);
if (v) {
switch_set_flag((&runtime), SCF_EVENT_CHANNEL_HIERARCHY_DELIVERY_ONCE);
} else {
switch_clear_flag((&runtime), SCF_EVENT_CHANNEL_HIERARCHY_DELIVERY_ONCE);
}
} else if (!strcasecmp(var, "event-channel-log-undeliverable-json") && !zstr(val)) {
int v = switch_true(val);
if (v) {
switch_set_flag((&runtime), SCF_EVENT_CHANNEL_LOG_UNDELIVERABLE_JSON);
} else {
switch_clear_flag((&runtime), SCF_EVENT_CHANNEL_LOG_UNDELIVERABLE_JSON);
}
}
}
}

View File

@ -2934,17 +2934,21 @@ static void ecd_deliver(event_channel_data_t **ecdP)
const char *sep = switch_core_get_event_channel_key_separator();
char *x_argv[SWITCH_CHANNEL_DISPATCH_MAX_KEY_PARTS] = { 0 };
int x_argc = switch_separate_string_string(key, (char*) sep, x_argv, SWITCH_CHANNEL_DISPATCH_MAX_KEY_PARTS);
char buf[512];
int i;
char buf[1024];
int i, r;
for(i=x_argc - 1; i > 0; i--) {
int z;
memset(buf, 0, 512);
memset(buf, 0, 1024);
sprintf(buf, "%s", x_argv[0]);
for(z=1; z < i; z++) {
strcat(buf, sep);
strcat(buf, x_argv[z]);
}
t += _switch_event_channel_broadcast(buf, ecd->event_channel, ecd->json, ecd->key, ecd->id);
r = _switch_event_channel_broadcast(buf, ecd->event_channel, ecd->json, ecd->key, ecd->id);
t += r;
if (r && switch_core_test_flag(SCF_EVENT_CHANNEL_HIERARCHY_DELIVERY_ONCE)) {
break;
}
}
} else {
char *p = NULL;
@ -2958,7 +2962,13 @@ static void ecd_deliver(event_channel_data_t **ecdP)
t += _switch_event_channel_broadcast(SWITCH_EVENT_CHANNEL_GLOBAL, ecd->event_channel, ecd->json, ecd->key, ecd->id);
if(t == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "no subscribers for %s , %s\n", ecd->event_channel, ecd->key);
if (switch_core_test_flag(SCF_EVENT_CHANNEL_LOG_UNDELIVERABLE_JSON)) {
char *json = cJSON_Print(ecd->json);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "no subscribers for %s , %s => %s\n", ecd->event_channel, ecd->key, json);
switch_safe_free(json);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "no subscribers for %s , %s\n", ecd->event_channel, ecd->key);
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "delivered to %u subscribers for %s\n", t, ecd->event_channel);
}