From ef3cc04eeaf6f6847db5cb43a3e626de7ae68c98 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Wed, 17 Oct 2018 11:44:48 -0700 Subject: [PATCH] Lower authorization errors to debug level in mongodb input (#4869) (cherry picked from commit cd865cfd2274eea32bf37ff944b8a693bc47490a) --- plugins/inputs/mongodb/mongodb_server.go | 25 ++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/plugins/inputs/mongodb/mongodb_server.go b/plugins/inputs/mongodb/mongodb_server.go index 1d9db9181fe68..6ab236b5829e1 100644 --- a/plugins/inputs/mongodb/mongodb_server.go +++ b/plugins/inputs/mongodb/mongodb_server.go @@ -3,6 +3,7 @@ package mongodb import ( "log" "net/url" + "strings" "time" "github.com/influxdata/telegraf" @@ -26,6 +27,10 @@ type oplogEntry struct { Timestamp bson.MongoTimestamp `bson:"ts"` } +func IsAuthorization(err error) bool { + return strings.Contains(err.Error(), "not authorized") +} + func (s *Server) gatherOplogStats() *OplogStats { stats := &OplogStats{} localdb := s.Session.DB("local") @@ -39,14 +44,22 @@ func (s *Server) gatherOplogStats() *OplogStats { if err == mgo.ErrNotFound { continue } - log.Println("E! Error getting first oplog entry (" + err.Error() + ")") + if IsAuthorization(err) { + log.Println("D! Error getting first oplog entry (" + err.Error() + ")") + } else { + log.Println("E! Error getting first oplog entry (" + err.Error() + ")") + } return stats } if err := localdb.C(collection_name).Find(query).Sort("-$natural").Limit(1).One(&op_last); err != nil { - if err == mgo.ErrNotFound { + if err == mgo.ErrNotFound || IsAuthorization(err) { continue } - log.Println("E! Error getting last oplog entry (" + err.Error() + ")") + if IsAuthorization(err) { + log.Println("D! Error getting first oplog entry (" + err.Error() + ")") + } else { + log.Println("E! Error getting first oplog entry (" + err.Error() + ")") + } return stats } } @@ -98,7 +111,11 @@ func (s *Server) gatherData(acc telegraf.Accumulator, gatherDbStats bool) error }, }, &resultShards) if err != nil { - log.Println("E! Error getting database shard stats (" + err.Error() + ")") + if IsAuthorization(err) { + log.Println("D! Error getting database shard stats (" + err.Error() + ")") + } else { + log.Println("E! Error getting database shard stats (" + err.Error() + ")") + } } oplogStats := s.gatherOplogStats()