I am calling an API in Sensu custom metric-collection-check, but when I tried to parse the response its throw the below error
Request returned undefined method `parse' for Sensu::Plugin::Metric::CLI::JSON:Class
While the same API parse working in standard-check when it extends from Sensu::Plugin::Check
Here is the check
#!/opt/sensu/embedded/bin/ruby
require 'socket'
require 'active_support/core_ext/hash'
require 'json'
require "rest-client"
require 'sensu-plugin/metric/cli'
class SomeName < Sensu::Plugin::Metric::CLI::Graphite
option :scheme,
description: 'Metric naming scheme, text to prepend to metric',
short: '-s SCHEME',
long: '--scheme SCHEME',
default: "#{Socket.gethostname}.stream"
def run
response = ""
begin
response =::JSON.parse RestClient::Request.execute(method: :get, url: "http://localhost:3001/stats" )
rescue Exception => e
critical "#{config[:scheme]}.name Metric check failed, Request returned #{e.message}"
end
output "#{config[:scheme]}.somekey", response["somekey"]
ok
end
end
Working with the following class.
class SomeName < Sensu::Plugin::Check::CLI
Seems like something wrong with sense metric plugin, any suggestion would be appreciated.
Fix the issue by calling global method using
::
Operators also it does not require to importrequire 'json'
as sensu-plugin come with JSON class.Sensu::Plugin::Metric::CLI::JSON
sensu-plugin Checks and Metrics