Skip to content

Commit

Permalink
Lower authorization errors to debug level in mongodb input (influxdat…
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored and Jean-Louis Dupond committed Apr 22, 2019
1 parent 12ffcf5 commit 56f4c6c
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions plugins/inputs/mongodb/mongodb_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mongodb
import (
"log"
"net/url"
"strings"
"time"

"github.com/influxdata/telegraf"
Expand All @@ -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")
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 56f4c6c

Please sign in to comment.