Giter Club home page Giter Club logo

stackstorm-elasticsearch's Introduction

Elasticsearch integration pack

Pack provides many operations helping to manage your Elasticsearch indices and snapshots.

Configuration

Copy the example configuration in elasticsearch.yaml.example to /opt/stackstorm/configs/elasticsearch.yaml and edit as required.

It must contain:

  • host - Host where Elasticsearch is running
  • port - Elasticsearch port - default 9200
  • query_window - Rolling window size in seconds. Default 30s
  • query_string - Query string
  • cooldown_multiplier - Multiple of query window to cooldown after successful hit. Default 2
  • count_threshold - Minimum number of hits before emitting trigger. Default 5
  • index - Index to query - e.g. 'logstash*'

You can also use dynamic values from the datastore. See the docs for more info.

Curator based actions

These actions operate similar to curator for Elasticsearch.

Action Description
indices.alias Add indices to or remove them from aliases.
indices.allocation Set routing allocation based on tags.
indices.bloom Disable the bloom filter cache for indices.
indices.close Close indices.
indices.delete Delete indices.
indices.open Open indices.
indices.optimize Optimize indices.
indices.replicas Set replica count per shard.
indices.show Show indices.
indices.snapshot Capture snapshot of indices.
snapshots.delete Delete snapshots.
snapshots.show Show snapshots.

Actions invocation parameters will be described further. But for more detailed description what each action actually does please also refer to the curator docs, it is more in-depth.

Common parameters

These parameters include general options such as elasticsearch host, port etc.

Parameter Description Default
host Specifies Elasticsearch host to connect to (required). none
url_prefix Specifies Elasticsearch http url prefix. /
port Specifies port remote Elasticsearch instance is running on. 9200
use_ssl Set to true to connect to Elasticsearch through SSL. false
http_auth Colon separated string specifying HTTP Basic Authentication. none
master_only Set to true to allow operation only on elected master. If a host you connect to is not a master node then the operation will fail. false
timeout Specifies Elasticsearch operation timeout in seconds. 600
log_level Specifies log level [critical|error|warning|info|debug]. warn
dry_run Set to true to enable dry run mode not performing any changes. false

Indices/snapshots selection parameters

These parameters filter indices or snapshots when a command is being applied.

Parameter Description Details
newer_than Filter indices or snapshots which are newer than n time_units. integer value >= 0
older_than Filter indices or snapshots which are older than n time_units. integer value >= 0
prefix Prefix that indices or snapshots must match.
suffix Suffix that indices or snapshots must match.
time_unit Specifies the time interval between indices or snapshots [hours|days|weeks|months]. (default: days)
timestring Timestring is the pattern used for matching the dates in indices and snapshots. ex. %Y.%m.%d, see. python strftime formatting
regex Include only indices or snapshots matching the provided pattern.
exclude A comma separated list of patterns specifying indices or snapshots to exclude.

Indices selection only

Parameter Description Details
index Comma separated string of index names to be included into the operation. Indices added with this option will not be filtered by any of the other index selection parameters.
all_indices Set to true to operate on all indices in a cluster. This option overrides other filtering parameters except exclude.

Snapshot selection only

Parameter Description Details
snapshot Comma separated string of snapshot names to be included into the operation. Snapshots added with this option will not be filtered by any of the other snapshot selection parameters.
all_snapshots Set to true to operate on all snapshots in a cluster. This option overrides other filtering parameters except exclude.
repository Provides the repository name for snapshot operations (required).

Search actions

Search actions perform a specified query in Elasticsearch. There are two search actions available: search.q and search.body. The first one takes a query string (given in lucene syntax), while the former allows to perform more sophisticated searches using Elasticsearch query DSL.

Both search actions use the same common parameters as curator based actions.

search.q specific parameters

This action is enhanced with index selection parameters to simplify indices matching.

Parameter Description
q Query in the Lucene query string syntax (required).
df The default field to use when no field prefix is defined within the query.
default_operator The default operator to be used, can be AND or OR. Defaults to OR.
from The starting from index of the hits to return. Defaults to 0.
size The number of hits to return. Defaults to 10.
pretty Set to true to pretty print JSON response.

search.body specific parameters

Parameter Description
body The search definition using the Query DSL (required).
indices A comma-separated list of index names to search. Defaults to "_all".
from The starting from index of the hits to return. Defaults to 0.
size The number of hits to return. Defaults to 10.
pretty Set to true to pretty print JSON response.

Usage and examples

Performing curator operations on indices or snapshots at least one filtering parameter must be specified. This's a generic rule applied to all of curator actions except. However show actions can be invoked without any filtering parameters, in this case show actions will display full list of indices or snapshots.

Now let's have a look at a few invocation examples.

Showing and deleting indices

  • Show indices older than 2 days:
st2 run elasticsearch.indices.show host=elk older_than=2 timestring=%Y.%m.%d

Shows this on my node:

{
    "result": null,
    "exit_code": 0,
    "stderr": "",
    "stdout": "logstash-2015.05.02
logstash-2015.05.04
"
}
  • Delete all indices matching ^logstash.*:
st2 run elastic.indices.delete host=elk prefix=logstash

Snapshot operations

  • Create a snapshot of indices based on time range criteria:
st2 run elasticsearch.indices.snapshot host=elk repository=my_backup newer_than=20 older_than=10 timestring=%Y.%m.%d

This command will create a snapshot of indices newer than 20 days and older than 10 days. Notice that filtering parameters of snapshot command apply to indices not to snapshots. That's why it's important not to mess it up. For example, the timestring parameter when created by curator with default options has a different time scheme.

  • Delete specific snapshots:
st2 run elasticsearch.snapshots.delete host=elk repository=my_backup snapshot=curator-20150506155615,curator-20150506155619
  • Delete all snapshots:
st2 run elasticsearch.snapshots.delete host=elk repository=my_backup all_indices=true

Querying Elasticsearch

On successful search (total hits > 0) query actions exit with return code == 0, if no documents have been found return code == 1. In all other case such as execution exceptions return code is 99.

Let's look at a few examples:

  • Run query using DSL syntax:
st2 run elasticsearch.search.body host=elk body='{"query":{"match_all":{}}}' pretty=true
  • Run query using URI syntax where q is a Lucene string:
st2 run elasticsearch.search.q host=elk q='message:my_log_event' prefix=logstash

Changelog

2016-01-08 pixelrebel [email protected]

  • The pack seems to work with elasticsearch v2.1.1 (and curator v3.4.0). So the pack now allows elasticsearch > v1.0.0 and < v2.2.0. Please update python module elasticsearch-curator==3.4.0 before upgrading this pack.
  • Updated pack version to 0.2.0.

License and Authors

stackstorm-elasticsearch's People

Contributors

dennybaa avatar kami avatar pixelrebel avatar bigmstone avatar emedvedev avatar rdvencioneck avatar lindsayhill avatar jaf-jaf avatar

Watchers

James Cloos avatar Nick Maludy avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.