[Asterisk-code-review] manager: Fix AMI "Queues" action to output text in correct f... (asterisk[master])

Benjamin Keith Ford asteriskteam at digium.com
Thu Jun 29 13:51:49 CDT 2017


Benjamin Keith Ford has uploaded this change for review. ( https://gerrit.asterisk.org/5929


Change subject: manager: Fix AMI "Queues" action to output text in correct format.
......................................................................

manager: Fix AMI "Queues" action to output text in correct format.

When sending the "Queues" action to Asterisk via the manager interface,
it outputs the same text that the Asterisk CLI outputs when running a
"queue show" command, which does not conform with the AMI spec. This
fix corrects the output format so that it is uniform with other AMI
outputs.

ASTERISK-27073
Reported by: Brian

Change-Id: Id11743859758255b69cc3a557750d7a56c6d16f8
---
M apps/app_queue.c
1 file changed, 72 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/29/5929/1

diff --git a/apps/app_queue.c b/apps/app_queue.c
index f158a4c..15a9a04 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -9733,10 +9733,79 @@
  */
 static int manager_queues_show(struct mansession *s, const struct message *m)
 {
-	static const char * const a[] = { "queue", "show" };
+	time_t now;
+	int q_items = 0;
+	const char *id = astman_get_header(m,"ActionID");
+	char idText[256];
+	struct call_queue *q;
+	float sl = 0;
+	struct member *mem;
+	struct ao2_iterator queue_iter;
+	struct ao2_iterator mem_iter;
 
-	__queues_show(s, -1, 2, a);
-	astman_append(s, "\r\n\r\n");	/* Properly terminate Manager output */
+	astman_send_listack(s, m, "Queue list will follow", "start");
+	time(&now);
+	idText[0] = '\0';
+	if (!ast_strlen_zero(id)) {
+		snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
+	}
+
+	queue_iter = ao2_iterator_init(queues, 0);
+	while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) {
+		ao2_lock(q);
+
+		sl = ((q->callscompleted > 0) ? 100 * ((float)q->callscompletedinsl / (float)q->callscompleted) : 0);
+		astman_append(s, "Event: QueueParams\r\n"
+			"Queue: %s\r\n"
+			"Max: %d\r\n"
+			"Strategy: %s\r\n"
+			"Calls: %d\r\n"
+			"Holdtime: %d\r\n"
+			"Talktime: %d\r\n"
+			"Completed: %d\r\n"
+			"Abandoned: %d\r\n"
+			"ServiceLevel: %d\r\n"
+			"ServicelevelPerf: %2.1f\r\n"
+			"Weight: %d\r\n"
+			"%s"
+			"\r\n",
+			q->name, q->maxlen, int2strat(q->strategy), q->count, q->holdtime, q->talktime, q->callscompleted,
+			q->callsabandoned, q->servicelevel, sl, q->weight, idText);
+		++q_items;
+
+		/* List Queue Members */
+		mem_iter = ao2_iterator_init(q->members, 0);
+		while ((mem = ao2_iterator_next(&mem_iter))) {
+			astman_append(s, "Event: QueueMember\r\n"
+				"Queue: %s\r\n"
+				"Name: %s\r\n"
+				"Location: %s\r\n"
+				"StateInterface: %s\r\n"
+				"Membership: %s\r\n"
+				"Penalty: %d\r\n"
+				"CallsTaken: %d\r\n"
+				"LastCall: %d\r\n"
+				"LastPause: %d\r\n"
+				"InCall: %d\r\n"
+				"Status: %d\r\n"
+				"Paused: %d\r\n"
+				"PausedReason: %s\r\n"
+				"%s"
+				"\r\n",
+				q->name, mem->membername, mem->interface, mem->state_interface, mem->dynamic ? "dynamic" : "static",
+				mem->penalty, mem->calls, (int)mem->lastcall, (int)mem->lastpause,  mem->starttime ? 1 : 0, mem->status,
+				mem->paused, mem->reason_paused, idText);
+			++q_items;
+			ao2_ref(mem, -1);
+		}
+		ao2_iterator_destroy(&mem_iter);
+		ao2_unlock(q);
+		queue_t_unref(q, "Done with iterator");
+	}
+	ao2_iterator_destroy(&queue_iter);
+
+	astman_send_list_complete_start(s, m, "QueuesComplete", q_items);
+	astman_send_list_complete_end(s);
 
 	return RESULT_SUCCESS;
 }

-- 
To view, visit https://gerrit.asterisk.org/5929
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id11743859758255b69cc3a557750d7a56c6d16f8
Gerrit-Change-Number: 5929
Gerrit-PatchSet: 1
Gerrit-Owner: Benjamin Keith Ford <bford at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20170629/5e4f7d18/attachment-0001.html>


More information about the asterisk-code-review mailing list