sensu-plugins / sensu-plugins-mongodb

This plugin provides native MongoDB instrumentation for monitoring and metrics collection, including: service health, database connectivity, replication lag/status, `oplog` monitoring, collection-specific metrics, and more.
http://sensu-plugins.io
MIT License
9 stars 41 forks source link

Error checking serverStatus:undefined method `[]' for nil:NilClass #34

Open nnsaln opened 8 years ago

nnsaln commented 8 years ago

Error checking serverStatus:undefined method []' for nil:NilClass ["/etc/sensu/plugins/apps/metrics-mongodb.rb:173:ingather_replication_metrics'", "/etc/sensu/plugins/apps/metrics-mongodb.rb:140:in run'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugin-1.3.0/lib/sensu-plugin/cli.rb:57:inblock in class:CLI'"]

andrewawagner commented 8 years ago

I ran into the same thing with the latest metrics change.

eheydrick commented 8 years ago

Can you try the latest version (1.1.0) and see if it fixes this issue.

nnsaln commented 8 years ago

I still got this error Check failed to run: undefined method[]' for nil:NilClass, ["/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-mongodb-1.1.0/lib/sensu-plugins-mongodb/metics.rb:120:in server_metrics'", "/etc/sensu/plugins/apps/check-mongodb-metric.rb:126:inrun'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugin-1.3.0/lib/sensu-plugin/cli.rb:57:in block in <class:CLI>'"]

naemono commented 7 years ago

For me this error occurred because I did not supply the proper credentials to authenticate to the mongodb database. (--user, --password options)

eheydrick commented 7 years ago

@nnsaln is this still an issue for you?

ankitjain2 commented 7 years ago

@eheydrick I am still seeing the issue with check-mongodb-metrics.rb

I am trying to run the simple /etc/sensu/plugins/check-mongodb-metric.rb --host <myhostname.com> --ssl

Check failed to run: undefined method []' for nil:NilClass,["/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-mongodb-1.2.0/lib/sensu-plugins-mongodb/metics.rb:120:in server_metrics'", "/etc/sensu/plugins/check-mongodb-metric.rb:126:inrun'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugin-1.4.2/lib/sensu-plugin/cli.rb:58:in block in <class:CLI>'"]

majormoses commented 7 years ago

@ankitjain2 I notice you are not using embedded ruby from the path, does this bug affect you if you use sensu embedded ruby?

majormoses commented 7 years ago

Can someone confirm that specifying credentials as per: https://github.com/sensu-plugins/sensu-plugins-mongodb/issues/34#issuecomment-277743689 solves the issue?

We should ensure that credentials are not required as last I checked mongodb does not authentication despite this being a good security posture.

majormoses commented 7 years ago

Also I am noticing that the same issue effects multiple checks based on the comments here, we should keep track of which ones are affected and their resolution:

majormoses commented 7 years ago

@ankitjain2 @nnsaln @andrewawagner can you please confirm that https://github.com/sensu-plugins/sensu-plugins-mongodb/issues/34#issuecomment-277743689 fixes this for you? I would like to know if its a matter of improving error handling or a bug.

DoctorOgg commented 5 years ago

I had the same issue, however, i added the role "clusterMonitor" to a user I created on the admin database and it workes ....

majormoses commented 5 years ago

interesting, let's minimally document that it needs that permission for the user and can look at better error handling.