Class: Splunk::Inputs

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

Overview

A collection of specific inputs.

Instance Attribute Summary

Attributes inherited from ReadOnlyCollection

#entity_class, #resource, #service

Instance Method Summary collapse

Methods inherited from Collection

#delete, #delete_if

Methods inherited from ReadOnlyCollection

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

Constructor Details

#initialize(service, resource) ⇒ Inputs



87
88
89
90
# File 'lib/splunk-sdk-ruby/collection/input_kinds.rb', line 87

def initialize(service, resource)
  super(service, resource)
  @always_fetch = true
end

Instance Method Details

#create(name, args = {}) ⇒ Object

Raises:

  • (StandardError)


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/splunk-sdk-ruby/collection/input_kinds.rb', line 92

def create(name, args={})
  body_args = args.clone()
  body_args["name"] = name

  request_args = {
      :method => :POST,
      :resource => @resource,
      :body => body_args
  }
  if args.has_key?(:namespace)
    request_args[:namespace] = body_args.delete(:namespace)
  end

  @service.request(request_args)

  # If we have created a oneshot input, no actual entity
  # is created. We return nil here in that case.
  if @resource == ["data", "inputs", "oneshot"]
    return nil
  end

  # TCP and UDP inputs have a key restrictToHost. If it is set
  # then they are created with hostname:port as their resource
  # instead of just port, and we must adjust our behavior
  # accordingly.
  if args.has_key?(:restrictToHost)
    name = args[:restrictToHost] + ":" + name
  end

  fetch_args = {:method => :GET,
                :resource => @resource + [name]}
  if args.has_key?(:namespace)
    fetch_args[:namespace] = args[:namespace]
  end
  response = @service.request(fetch_args)

  feed = AtomFeed.new(response.body)
  raise StandardError.new("No entities returned") if feed.entries.empty?
  entity = atom_entry_to_entity(feed.entries[0])
  raise StandardError.new("Found nil entity.") if entity.nil?
  return entity
end