switch_call_cause_t cause = switch_channel_get_cause(channel);
int sip_cause = hangup_cause_to_sip(cause);
const char *ps_cause = NULL, *use_my_cause;
+ const char *gateway_name = NULL;
+ sofia_gateway_t *gateway_ptr = NULL;
+ if ((gateway_name = switch_channel_get_variable(channel, "sip_gateway_name"))) {
+ gateway_ptr = sofia_reg_find_gateway(gateway_name);
+ }
+
switch_mutex_lock(tech_pvt->sofia_mutex);
sofia_clear_flag(tech_pvt, TFLAG_RECOVERING);
} else {
tech_pvt->profile->ib_failed_calls++;
}
+
+ if (gateway_ptr) {
+ if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
+ gateway_ptr->ob_failed_calls++;
+ } else {
+ gateway_ptr->ib_failed_calls++;
+ }
+ }
+ }
+
+ if (gateway_ptr) {
+ sofia_reg_release_gateway(gateway_ptr);
}
if (!((use_my_cause = switch_channel_get_variable(channel, "sip_ignore_remote_cause")) && switch_true(use_my_cause))) {
if (argc > 0) {
if (argc == 1) {
- stream->write_function(stream, "Invalid Syntax!\n");
+ /* show summary of all gateways*/
+
+ uint32_t ib_failed = 0;
+ uint32_t ib = 0;
+ uint32_t ob_failed = 0;
+ uint32_t ob = 0;
+
+ stream->write_function(stream, "%25s\t%32s\t%s\t%s\t%s\n", "Profile::Gateway-Name", " Data ", "State", "IB Calls(F/T)", "OB Calls(F/T)");
+ stream->write_function(stream, "%s\n", line);
+ switch_mutex_lock(mod_sofia_globals.hash_mutex);
+ for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
+ switch_hash_this(hi, &vvar, NULL, &val);
+ profile = (sofia_profile_t *) val;
+ if (sofia_test_pflag(profile, PFLAG_RUNNING)) {
+
+ if (!strcmp(vvar, profile->name)) { /* not an alias */
+ for (gp = profile->gateways; gp; gp = gp->next) {
+ char *pkey = switch_mprintf("%s::%s", profile->name, gp->name);
+
+ switch_assert(gp->state < REG_STATE_LAST);
+
+ c++;
+ ib_failed += gp->ib_failed_calls;
+ ib += gp->ib_calls;
+ ob_failed += gp->ob_failed_calls;
+ ob += gp->ob_calls;
+
+ stream->write_function(stream, "%25s\t%32s\t%s\t%ld/%ld\t%ld/%ld",
+ pkey, gp->register_to, sofia_state_names[gp->state],
+ gp->ib_failed_calls, gp->ib_calls, gp->ob_failed_calls, gp->ob_calls);
+
+ if (gp->state == REG_STATE_FAILED || gp->state == REG_STATE_TRYING) {
+ time_t now = switch_epoch_time_now(NULL);
+ if (gp->retry > now) {
+ stream->write_function(stream, " (retry: %ds)", gp->retry - now);
+ } else {
+ stream->write_function(stream, " (retry: NEVER)");
+ }
+ }
+ stream->write_function(stream, "\n");
+ }
+ }
+ }
+ }
+ switch_mutex_unlock(mod_sofia_globals.hash_mutex);
+ stream->write_function(stream, "%s\n", line);
+ stream->write_function(stream, "%d gateway%s: Inound(Failed/Total): %ld/%ld,"
+ "Outbound(Failed/Total):%ld/%ld\n", c, c == 1 ? "" : "s",
+ ib_failed, ib, ob_failed, ob);
+
return SWITCH_STATUS_SUCCESS;
}
stream->write_function(stream, "Status \t%s%s\n", status_names[gp->status], gp->pinging ? " (ping)" : "");
stream->write_function(stream, "CallsIN \t%d\n", gp->ib_calls);
stream->write_function(stream, "CallsOUT\t%d\n", gp->ob_calls);
+ stream->write_function(stream, "FailedCallsIN\t%d\n", gp->ib_failed_calls);
+ stream->write_function(stream, "FailedCallsOUT\t%d\n", gp->ob_failed_calls);
stream->write_function(stream, "%s\n", line);
sofia_reg_release_gateway(gp);
} else {
if (argc > 0) {
if (argc == 1) {
- stream->write_function(stream, "Invalid Syntax!\n");
+ /* show summary of all gateways */
+
+ stream->write_function(stream, "%s\n", header);
+ stream->write_function(stream, "<gateways>\n", header);
+
+ switch_mutex_lock(mod_sofia_globals.hash_mutex);
+ for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
+ switch_hash_this(hi, &vvar, NULL, &val);
+ profile = (sofia_profile_t *) val;
+ if (sofia_test_pflag(profile, PFLAG_RUNNING)) {
+
+ if (!strcmp(vvar, profile->name)) { /* not an alias */
+ for (gp = profile->gateways; gp; gp = gp->next) {
+ switch_assert(gp->state < REG_STATE_LAST);
+
+ stream->write_function(stream, "\t<gateway>\n");
+ stream->write_function(stream, "\t\t<profile>%s</profile>\n", profile->name);
+ stream->write_function(stream, "\t\t<to>%s</to>\n", gp->register_to);
+ stream->write_function(stream, "\t\t<state>%s</state>\n", sofia_state_names[gp->state]);
+ stream->write_function(stream, "\t\t<calls-in>%ld</calls-in>\n", gp->ib_calls);
+ stream->write_function(stream, "\t\t<calls-out>%ld</calls-out>\n", gp->ob_calls);
+ stream->write_function(stream, "\t\t<failed-calls-in>%ld</failed-calls-in>\n", gp->ib_failed_calls);
+ stream->write_function(stream, "\t\t<failed-calls-out>%ld</failed-calls-out>\n", gp->ob_failed_calls);
+
+ if (gp->state == REG_STATE_FAILED || gp->state == REG_STATE_TRYING) {
+ time_t now = switch_epoch_time_now(NULL);
+ if (gp->retry > now) {
+ stream->write_function(stream, "\t\t<retry>%ds</retry>\n", gp->retry - now);
+ } else {
+ stream->write_function(stream, "\t\t<retry>NEVER</retry>\n");
+ }
+ }
+ stream->write_function(stream, "\t</gateway>\n");
+ }
+ }
+ }
+ }
+ switch_mutex_unlock(mod_sofia_globals.hash_mutex);
+ stream->write_function(stream, "</gateways>\n");
+
return SWITCH_STATUS_SUCCESS;
}
if (!strcasecmp(argv[0], "gateway")) {
stream->write_function(stream, " <status>%s%s</status>\n", status_names[gp->status], gp->pinging ? " (ping)" : "");
stream->write_function(stream, " <calls-in>%d</calls-in>\n", gp->ib_calls);
stream->write_function(stream, " <calls-out>%d</calls-out>\n", gp->ob_calls);
-
+ stream->write_function(stream, " <failed-calls-in>%d</calls-in>\n", gp->ib_failed_calls);
+ stream->write_function(stream, " <failed-calls-out>%d</calls-out>\n", gp->ob_failed_calls);
stream->write_function(stream, " </gateway>\n");
sofia_reg_release_gateway(gp);
} else {
if (gateway_ptr->status != SOFIA_GATEWAY_UP) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Gateway is down!\n");
cause = SWITCH_CAUSE_NETWORK_OUT_OF_ORDER;
+ gateway_ptr->ob_failed_calls++;
sofia_reg_release_gateway(gateway_ptr);
gateway_ptr = NULL;
goto error;
tech_pvt->transport = sofia_glue_str2transport(tp_param);
if (tech_pvt->transport == SOFIA_TRANSPORT_UNKNOWN) {
cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+ gateway_ptr->ob_failed_calls++;
goto error;
}
}