Last active
December 11, 2015 22:08
-
-
Save agent462/4667299 to your computer and use it in GitHub Desktop.
a very quick splunk starter example for sensu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' if RUBY_VERSION < '1.9.0' | |
require "net/https" | |
require 'json' | |
require 'sensu-plugin/check/cli' | |
class checkSplunk < Sensu::Plugin::Check::CLI | |
def api_request(opts={}) | |
o = { | |
:host => '', | |
:port => '443', | |
:path => '', | |
:auth => false, | |
:headers => false | |
}.merge(opts) | |
http = Net::HTTP.new(o[:host], o[:port]) | |
if o[:ssl] | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
end | |
req = Net::HTTP::Get.new(o[:path]) | |
if o[:auth] then req.basic_auth(o[:auth][:user], o[:auth][:pass]) end | |
if o[:headers] | |
o[:headers].each do |k,v| | |
req[k] = v | |
end | |
end | |
http.request(req) | |
end | |
def check_splunk | |
opts = { | |
:ssl => true, | |
:host => "", | |
:port => 8089, | |
:path => "/services/alerts/fired_alerts?output_mode=json", | |
:auth => { :user => "", :pass => "" } | |
} | |
res = JSON.parse(api_request(opts).body) | |
end | |
def run | |
splunk = check_splunk | |
if splunk["entry"][0]["content"]["triggered_alert_count"] > 0 | |
{do something here} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment