class Splunk::ReadOnlyEntity

ReadOnlyEntity represents entities that can be read, but not created or updated, via the REST API. The canonical example is a modular input kind.

Attributes

name[R]

The name of this Entity.

Returns: a String.

namespace[R]

The namespace of this Entity.

Returns: a Namespace.

resource[R]

The path of the collection this entity lives in.

For example, on an app this will be [“apps”, “local”].

Returns: an Array of Strings.

service[R]

The service this entity refers to.

Returns: a Service object.

Public Instance Methods

[]() click to toggle source

Fetch a field on this entity.

Returns: a String.

# File lib/splunk-sdk-ruby/entity.rb, line 94
synonym "[]", "fetch"
fetch(key, default=nil) click to toggle source

Fetches the field key on this entity.

You may provide a default value. All values are returned as strings.

Returns: a String.

# File lib/splunk-sdk-ruby/entity.rb, line 85
def fetch(key, default=nil)
  @state["content"].fetch(key, default)
end
read(*field_list) click to toggle source

DEPRECATED. Use fetch and [] instead (since entities now cache their state).

Returns all or a specified subset of key/value pairs on this Entity

In the absence of arguments, returns a Hash of all the fields on this Entity. If you specify one or more Strings or Arrays of Strings, all the keys specified in the arguments will be returned in the Hash.

Returns: a Hash with Strings as keys, and Strings or Hashes or Arrays as values.

# File lib/splunk-sdk-ruby/entity.rb, line 121
def read(*field_list)
  warn "[DEPRECATION] Entity#read is deprecated. Use [] and fetch instead."
  if field_list.empty?
    return @state["content"].clone()
  else
    field_list = field_list.flatten()
    result = {}
    field_list.each() do |key|
      result[key] = fetch(key).clone()
    end
    return result
  end
end
readmeta() click to toggle source

Returns the metadata for this Entity.

This method is identical to

entity.read('eai:acl', 'eai:attributes')

Returns: a Hash with the keys “+eai:acl+” and “+eai:attributes+”.

# File lib/splunk-sdk-ruby/entity.rb, line 144
def readmeta
  read('eai:acl', 'eai:attributes')
end
refresh() click to toggle source

Refreshes the cached state of this Entity.

Returns: the Entity.

# File lib/splunk-sdk-ruby/entity.rb, line 153
def refresh()
  response = @service.request(:resource => @resource + [name],
                              :namespace => @namespace)
  if response.code == 204 or response.body.nil?
    # This code is here primarily to handle the case of a job not yet being
    # ready, in which case you get back empty bodies.
    raise EntityNotReady.new((@resource + [name]).join("/"))
  end
  # We are guaranteed a unique entity, since entities must have
  # exact namespaces.
  feed = AtomFeed.new(response.body)
  @state = feed.entries[0]
  self
end