Class: Splunk::InputKinds

Inherits:
ReadOnlyCollection show all
Defined in:
lib/splunk-sdk-ruby/collection/input_kinds.rb

Overview

A collection of input types.

Inputs in the Splunk REST API are arranged in what looks like a directory structure, as in

monitor/
tcp/
  cooked/
  raw/
udp/

You get the top level directory by calling inputs on your Service. Then you can use it as if it were a Hash. If you fetch an entry that has subtypes, such as tcp, you get another InputKinds containing the types in that entry. If you fetch an entry that doesn’t have subtypes, such as “udp”, then you get an Inputs object (a subclass of Collection) containing specific inputs.

Example:

# Returns an InputKinds collection
tcp_inputs = service.inputs["tcp"]
tcp_inputs.has_key?("raw")    # ==> true
tcp_inputs.has_key?("cooked") # ==> true

# A read only collection of all the inputs in Splunk.
service.inputs["all"]

# An Inputs object containing all the UDP inputs in Splunk.
service.inputs["udp"]

Instance Attribute Summary

Attributes inherited from ReadOnlyCollection

#entity_class, #resource, #service

Instance Method Summary collapse

Methods inherited from ReadOnlyCollection

#assoc, #atom_entry_to_entity, #each, #each_key, #each_pair, #each_value, #empty?, #has_key?, #initialize, #keys, #length, #values

Constructor Details

This class inherits a constructor from Splunk::ReadOnlyCollection

Instance Method Details

#fetch(name, namespace = nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/splunk-sdk-ruby/collection/input_kinds.rb', line 56

def fetch(name, namespace=nil)
  request_args = {:resource => @resource + [name]}
  if not namespace.nil?
    request_args[:namespace] = namespace
  end

  begin
    response = @service.request(request_args)
  rescue SplunkHTTPError => err
    if err.code == 404
      return nil
    else
      raise err
    end
  end

  feed = AtomFeed.new(response.body)
  if feed.["links"].has_key?("create")
    Inputs.new(@service, resource + [name])
  elsif name == "all"
    ReadOnlyCollection.new(@service, resource + [name])
  else
    InputKinds.new(@service, resource + [name])
  end
end