From e4e3e677a32a69a18583e0a5a1645a750db9f86a Mon Sep 17 00:00:00 2001 From: Eugene Dementiev Date: Tue, 13 Oct 2015 21:15:12 +0300 Subject: [PATCH] Fix crash if login/password is incorrect in rabbitmq plugin. Closes #260 --- plugins/rabbitmq/rabbitmq.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/rabbitmq/rabbitmq.go b/plugins/rabbitmq/rabbitmq.go index 506e932adf867..45f1cac5ff8c4 100644 --- a/plugins/rabbitmq/rabbitmq.go +++ b/plugins/rabbitmq/rabbitmq.go @@ -119,6 +119,10 @@ func (r *RabbitMQ) gatherServer(serv *Server, acc plugins.Accumulator) error { return err } + if overview.QueueTotals == nil || overview.ObjectTotals == nil || overview.MessageStats == nil { + return fmt.Errorf("Wrong answer from rabbitmq. Probably auth issue") + } + tags := map[string]string{"url": serv.URL} if serv.Name != "" { tags["name"] = serv.Name @@ -134,11 +138,9 @@ func (r *RabbitMQ) gatherServer(serv *Server, acc plugins.Accumulator) error { acc.Add("exchanges", overview.ObjectTotals.Exchanges, tags) acc.Add("queues", overview.ObjectTotals.Queues, tags) - if overview.MessageStats != nil { - acc.Add("messages_acked", overview.MessageStats.Ack, tags) - acc.Add("messages_delivered", overview.MessageStats.Deliver, tags) - acc.Add("messages_published", overview.MessageStats.Publish, tags) - } + acc.Add("messages_acked", overview.MessageStats.Ack, tags) + acc.Add("messages_delivered", overview.MessageStats.Deliver, tags) + acc.Add("messages_published", overview.MessageStats.Publish, tags) nodes := make([]Node, 0)