Class: Inspec::Resources::Elasticsearch

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/resources/elasticsearch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Elasticsearch

Returns a new instance of Elasticsearch.



55
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
81
82
83
84
85
86
# File 'lib/inspec/resources/elasticsearch.rb', line 55

def initialize(opts = {})
  return skip_resource "Package `curl` not avaiable on the host" unless inspec.command("curl").exist?

  @url = opts.fetch(:url, "http://localhost:9200")

  username   = opts.fetch(:username, nil)
  password   = opts.fetch(:password, nil)
  ssl_verify = opts.fetch(:ssl_verify, true)

  cmd = inspec.command(curl_command_string(username, password, ssl_verify))

  # after implementation of PR #2235, this begin..rescue won't be necessary.
  # The checks in verify_curl_success! can raise their own skip message exception.
  begin
    verify_curl_success!(cmd)
  rescue => e
    return skip_resource e.message
  end

  begin
    content = JSON.parse(cmd.stdout)
    # after implementation of PR #2235, this can be broken out of the begin..rescue
    # clause. The checks in verify_json_payload! can raise their own skip message exception.
    verify_json_payload!(content)
  rescue JSON::ParserError => e
    return skip_resource "Couldn't parse the Elasticsearch response: #{e.message}"
  rescue => e
    return skip_resource e.message
  end

  @nodes = parse_cluster(content)
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



53
54
55
# File 'lib/inspec/resources/elasticsearch.rb', line 53

def nodes
  @nodes
end

#urlObject (readonly)

Returns the value of attribute url.



53
54
55
# File 'lib/inspec/resources/elasticsearch.rb', line 53

def url
  @url
end

Instance Method Details

#to_sObject



88
89
90
# File 'lib/inspec/resources/elasticsearch.rb', line 88

def to_s
  "Elasticsearch Cluster #{url}"
end