Class: Loggly

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_loggly.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Loggly

Returns a new instance of Loggly.



5
6
7
8
9
10
11
# File 'lib/ruby_loggly.rb', line 5

def initialize(options)
  @subdomain = options[:subdomain]
  @user = options[:user]
  @pass = options[:pass]
  @key = options[:key]
  @ec2 = options[:ec2] ||= false
end

Instance Method Details

#add_device(options) ⇒ Object



49
50
51
52
# File 'lib/ruby_loggly.rb', line 49

def add_device(options)
   response = RestClient.post("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/devices/",:ip=>options[:ip],:input_id=>options[:input_id])
	response.code==201 ? true : false
end

#add_input(options) ⇒ Object



35
36
37
38
# File 'lib/ruby_loggly.rb', line 35

def add_input(options)
   response = RestClient.post("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/inputs/", :name=>options[:name],:description=> options[:description],:service=>options[:service])
	response.code==201 ? true : false
end

#get_device(options) {|device_hash| ... } ⇒ Object

Yields:

  • (device_hash)


57
58
59
60
61
62
63
# File 'lib/ruby_loggly.rb', line 57

def get_device(options)
   response = RestClient.get("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/devices/#{options[:id]}")
	device=nil
	device_hash=JSON.parse(response.to_str)
   yield device_hash if block_given?
	device_hash 
end

#get_input(options) {|input_hash| ... } ⇒ Object

Yields:

  • (input_hash)


29
30
31
32
33
34
# File 'lib/ruby_loggly.rb', line 29

def get_input(options)
   response = RestClient.get("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/inputs/#{options[:id]}")
	input_hash=JSON.parse(response.to_str)
   yield input_hash if block_given?
	input_hash
end

#list_devices {|response_array| ... } ⇒ Object

Yields:

  • (response_array)


43
44
45
46
47
48
# File 'lib/ruby_loggly.rb', line 43

def list_devices
   response = RestClient.get("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/devices/")
	response_array=JSON.parse(response.to_str)
   yield response_array if block_given?
	response_array
end

#list_inputs {|response_array| ... } ⇒ Object

Yields:

  • (response_array)


23
24
25
26
27
28
# File 'lib/ruby_loggly.rb', line 23

def list_inputs
  response = RestClient.get("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/inputs/")
response_array=JSON.parse(response.to_str)
  yield response_array if block_given?
response_array
end

#log(log_data) ⇒ Object



13
14
15
16
# File 'lib/ruby_loggly.rb', line 13

def log(log_data)
  ec2flag = @ec2 ? 'ec2.' : ''
  RestClient.post("https://#{ec2flag}logs.loggly.com/inputs/#{@key}", log_data)
end

#remove_device(options) ⇒ Object



53
54
55
56
# File 'lib/ruby_loggly.rb', line 53

def remove_device(options)
   response = RestClient.delete("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/devices/#{options[:id]}")
	response.code==204 ? true : false
end

#remove_input(options) ⇒ Object



39
40
41
42
# File 'lib/ruby_loggly.rb', line 39

def remove_input(options)
   response = RestClient.delete("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/inputs/#{options[:id]}")
	response.code==204 ? true : false
end

#search(query) {|response.to_str| ... } ⇒ Object

Yields:

  • (response.to_str)


18
19
20
21
# File 'lib/ruby_loggly.rb', line 18

def search(query)
  response = RestClient.get("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/search", {:params => {:q => query}})
  yield response.to_str if block_given?
end