Project: Chef InSpec (Provisioning / Security & Compliance)
File: elasticsearch.md

+++ title = "elasticsearch resource" draft = false gh_repo = "inspec" platform = "linux" [menu] [menu.inspec] title = "elasticsearch" identifier = "inspec/resources/os/elasticsearch.md elasticsearch resource" parent = "inspec/resources/os" +++ Use the `elasticsearch` resource to test the status of a node against a running Elasticsearch cluster. Chef InSpec retrieves the node list from the cluster node URL provided (defaults to `http://localhost:9200`) and provides the ability to query a variety of settings and statuses. {{< readfile file="content/inspec/reusable/md/inspec_installation.md" >}} This resource first became available in v1.43.5 of InSpec. describe elasticsearch do its('property') { should cmp 'value' } end The `elasticsearch` resource accepts several optional resource parameters: `url` : the top-level URL of an Elasticsearch node in the cluster. If your Elasticsearch installation is not served out of the top-level directory at the host, be sure to specify the full URL; for example: `http://my-load-balancer/elasticsearch`. Default: `http://localhost:9200` `username` : a username to use to log in with HTTP-Basic authentication. If `username` is provided, a `password` must also be provided. `password` : a password to use to log in with HTTP-Basic authentication. If `password` is provided, a `username` must also be provided. `ssl_verify` : if `false`, SSL certificate validation will be disabled. Default: `true` In addition, the `elasticsearch` resource allows for filtering the nodes returned by property before executing the tests: describe elasticsearch.where { node_name == 'one-off-node' } do its('version') { should eq '1.2.3' } end describe elasticsearch.where { process.mlockall == false } do its('count') { should cmp 0 } end To simply check if nodes exist that match the criteria, use the `exist` matcher: describe elasticsearch.where { clustername == 'mycluster' } do it { should exist } end The following are the different properties of the resource: Since the `elasticsearch` resource is meant for use on a cluster, each property will return an array of the values for each node that matches any provided search criteria. Using InSpec's `cmp` matcher helps avoid issues when comparing values when there is only a single match (i.e. when the cluster only contains a single node or the `where` filter criteria provided only returns a single node). The `build hash` property returns the build hash for each of the nodes. its('build_hash') { should cmp 'b2f0c09' } The `cluster_name` property returns the cluster names of each of the nodes. its('clustername') { should cmp 'mycluster' } The `host` property returns the hostname of each of the nodes. This may return an IP address if the node is improperly performing DNS resolution or has no hostname set. its('host') { should cmp 'my.hostname.mycompany.biz' } The `http` property returns a hash of HTTP-related settings for each of the

In this example, the `first` method is used to grab only the first node's HTTP-related info and is a way of removing the item from the Array if only one node is being queried. its('http.first.maxcontentlengthinbytes') { should cmp 123456 } The `ingest` property returns ingest-related settings and capabilities, such as available processors. its('ingest.first.processors.count') { should be >= 1 } The `ip` property returns the IP address of each of the nodes. its('ip') { should cmp '192.168.1.100' } The `jvm` property returns Java Virtual Machine related parameters for each of the nodes. its('jvm.first.version') { should cmp '1.8.0_141' } The `module_list` property returns a list of enabled modules for each node in the cluster. its('modulelist.first') { should include 'mymodule' } The `modules` property returns detailed information about each enabled module for each node in the cluster. its('modules.first') { should include 'lang-groovy' } The `node_name` property returns the node name for each node in the cluster. its('node_name') { should cmp 'node1' } The `node_id` property returns the node IDs of each of the nodes in the cluster. its('nodeid') { should include 'mynode_id' } The `os` property returns OS-related information about each node in the cluster. its('os.first.arch') { should cmp 'amd64' } The `plugin_list` property returns a list of enabled plugins for each node in the cluster. For more additional information about each plugin, use the `plugins` property. its('pluginlist.first') { should include 'myplugin' } The `plugins` property returns detailed information about each enabled plugin for each node in the cluster. its('plugins.first') { should include 'my_plugin' } The `process` property returns process information for each node in the cluster, such as the process ID. its('process.first.mlockall') { should cmp true } The `roles` property returns the role for each of the nodes in the cluster. its('roles') { should include 'master' } The `settings` property returns all the configuration settings for each node in the cluster. These settings usually include those set in the elasticsearch.yml as well as those set via `-Des.` or `-E` flags at startup. Use the `inspec shell` to explore the various setting keys that are available. its('settings.first.path.home') { should cmp '/usr/share/elasticsearch' } The `totalindexingbuffer` property returns the total indexing buffer for each node in the cluster. its('totalindexingbuffer') { should cmp 123456 } The `transport` property returns transport-related settings for each node in the cluster, such as the bound and published addresses. its('transport.first.bound_address') { should cmp '1.2.3.4:9200' } The `transport_address` property returns the bound transport address for each node in the cluster. its('transport_address') { should cmp '1.2.3.4:9200' } The `version` property returns the version of Elasticsearch running on each node of the cluster. its('version') { should cmp '5.5.2' } modules = elasticsearch.modules.first langgroovymodule = modules.find { |mod| mod.name == 'lang-groovy' } describe 'lang-groovy module version' do subject { langgroovymodule } its('version') { should cmp '5.5.2' } end plugins = elasticsearch.plugins.first myplugin = plugins.find { |plugin| plugin.name == 'myplugin' } describe 'my_plugin plugin version' do subject { my_plugin } its('version') { should cmp '1.2.3' } end {{< readfile file="content/inspec/reusable/md/inspecmatcherslink.md" >}}