lib/splunk_client/splunk_client.rb in splunk-client-0.7.0 vs lib/splunk_client/splunk_client.rb in splunk-client-0.8.0
- old
+ new
@@ -4,10 +4,12 @@
require 'net/https'
require 'cgi'
require 'rubygems'
require 'nokogiri'
require File.expand_path File.join(File.dirname(__FILE__), 'splunk_job')
+require File.expand_path File.join(File.dirname(__FILE__), 'splunk_alert')
+require File.expand_path File.join(File.dirname(__FILE__), 'splunk_alert_feed')
class SplunkClient
def initialize(username, password, host, port=8089)
@USER=username; @PASS=password; @HOST=host; @PORT=port
@@ -38,9 +40,19 @@
def get_search_results(sid, maxResults=0, mode=nil)
url = "/services/search/jobs/#{sid}/results?count=#{maxResults}"
url += "&output_mode=#{mode}" unless mode.nil?
splunk_get_request(url)
+ end
+
+ def get_alert_list(user="nobody")
+ xml = splunk_get_request("/servicesNS/#{user}/search/alerts/fired_alerts")
+ SplunkAlertFeed.new(Nokogiri::Slop(xml), self)
+ end
+
+ def get_alert(alarmName, user="nobody")
+ xml = splunk_get_request("/servicesNS/#{user}/search/alerts/fired_alerts/#{alarmName}")
+ SplunkAlert.new(Nokogiri::Slop(xml).css("entry")[0], self)
end
def control_job(sid, action)
xml = splunk_post_request("/services/search/jobs/#{sid}/control",
"action=#{CGI::escape(action)}",