sensu-plugins-elasticsearch 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +4 -0
- data/README.md +2 -0
- data/bin/check-es-cluster-status.rb +11 -1
- data/bin/check-es-query-count.rb +199 -0
- data/bin/check-es-query-exists.rb +173 -0
- data/bin/metrics-es-node-graphite.rb +1 -1
- data/lib/sensu-plugins-elasticsearch.rb +2 -0
- data/lib/sensu-plugins-elasticsearch/elasticsearch-common.rb +42 -0
- data/lib/sensu-plugins-elasticsearch/elasticsearch-query.rb +123 -0
- data/lib/sensu-plugins-elasticsearch/version.rb +2 -2
- metadata +26 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 688a6c3a44c0b90345fcfb6d3a4e557300ecc2ed
|
4
|
+
data.tar.gz: fcc7ae8b297550825127dd780ac5311785ba5aa9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a904263acfbd9efa5749f33375b18de707800711bff06644b0913fc5ae9e1ea3f61bad2a7f6e90f3f37d7a3ee3305eb572f759856fb3c60972f940dd4f105dd
|
7
|
+
data.tar.gz: 521346128d10b9fe848100f96584174c86976b3f907cffcf0d77e083f6f518769dbf0da9be6ab2e93fd168ef4076967df9500fddc5ac39032f2ffdc9439deabb
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,10 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
|
|
5
5
|
|
6
6
|
## [Unreleased][unreleased]
|
7
7
|
|
8
|
+
## [0.2.0] - 2015-10-15
|
9
|
+
### Changed
|
10
|
+
- cluster-status check: added a new `status_timeout` option that will use elasticsearch's [`wait_for_status` parameter](https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html#request-params) and wait up to the given number of seconds for the cluster to be green. This pervents false alerting during normal elasticsearch operations.
|
11
|
+
|
8
12
|
## [0.1.2] - 2015-08-11
|
9
13
|
### Added
|
10
14
|
- add parameters for elasticsearch auth
|
data/README.md
CHANGED
@@ -14,6 +14,8 @@
|
|
14
14
|
* /bin/check-es-file-descriptors.rb
|
15
15
|
* /bin/check-es-heap.rb
|
16
16
|
* /bin/check-es-node-status.rb
|
17
|
+
* /bin/check-es-query-count.rb
|
18
|
+
* /bin/check-es-query-exists.rb
|
17
19
|
* /bin/metrics-es-cluster.rb
|
18
20
|
* /bin/metrics-es-node.rb
|
19
21
|
* /bin/metrics-es-node-graphite.rb
|
@@ -62,6 +62,12 @@ class ESClusterStatus < Sensu::Plugin::Check::CLI
|
|
62
62
|
proc: proc(&:to_i),
|
63
63
|
default: 30
|
64
64
|
|
65
|
+
option :status_timeout,
|
66
|
+
description: 'Sets the time to wait for the cluster status to be green',
|
67
|
+
short: '-T SECS',
|
68
|
+
long: '--status_timeout SECS',
|
69
|
+
proc: proc(&:to_i)
|
70
|
+
|
65
71
|
option :user,
|
66
72
|
description: 'Elasticsearch User',
|
67
73
|
short: '-u USER',
|
@@ -105,7 +111,11 @@ class ESClusterStatus < Sensu::Plugin::Check::CLI
|
|
105
111
|
end
|
106
112
|
|
107
113
|
def acquire_status
|
108
|
-
|
114
|
+
if config[:status_timeout]
|
115
|
+
health = get_es_resource("/_cluster/health?wait_for_status=green&timeout=#{config[:status_timeout]}s")
|
116
|
+
else
|
117
|
+
health = get_es_resource('/_cluster/health')
|
118
|
+
end
|
109
119
|
health['status'].downcase
|
110
120
|
end
|
111
121
|
|
@@ -0,0 +1,199 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-es-query
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin checks an ElasticSearch query.
|
7
|
+
#
|
8
|
+
# OUTPUT:
|
9
|
+
# plain text
|
10
|
+
#
|
11
|
+
# PLATFORMS:
|
12
|
+
# Linux
|
13
|
+
#
|
14
|
+
# DEPENDENCIES:
|
15
|
+
# gem: sensu-plugin
|
16
|
+
# gem: elasticsearch
|
17
|
+
#
|
18
|
+
# USAGE:
|
19
|
+
# This example checks that the count of special_type logs matching a query of
|
20
|
+
# anything (*) at the host elasticsearch.service.consul for the past 90 minutes
|
21
|
+
# will warn if there are under 100 and go critical if the result count is below 1
|
22
|
+
# (The invert flag warns if counts are _below_ the critical and warning values)
|
23
|
+
# check-es-query-count.rb -h elasticsearch.service.consul -q "*" --invert
|
24
|
+
# --types special_type -d 'logging-%Y.%m.%d' --minutes-previous 90 -p 9200 -c 1 -w 100
|
25
|
+
#
|
26
|
+
# NOTES:
|
27
|
+
#
|
28
|
+
# LICENSE:
|
29
|
+
# Brendan Gibat <brendan.gibat@gmail.com>
|
30
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
31
|
+
# for details.
|
32
|
+
#
|
33
|
+
|
34
|
+
require 'sensu-plugin/check/cli'
|
35
|
+
require 'elasticsearch'
|
36
|
+
require 'time'
|
37
|
+
|
38
|
+
require_relative 'sensu-plugins-elasticsearch'
|
39
|
+
|
40
|
+
#
|
41
|
+
# ES Heap
|
42
|
+
#
|
43
|
+
class ESQueryCount < Sensu::Plugin::Check::CLI
|
44
|
+
include ElasticsearchCommon
|
45
|
+
|
46
|
+
option :index,
|
47
|
+
description: 'Elasticsearch indices to query.
|
48
|
+
Comma-separated list of index names to search.
|
49
|
+
Use `_all` or empty string to perform the operation on all indices.
|
50
|
+
Accepts wildcards',
|
51
|
+
short: '-i INDEX',
|
52
|
+
long: '--indices INDEX'
|
53
|
+
|
54
|
+
option :types,
|
55
|
+
description: 'Elasticsearch types to limit searches to, comma separated list.',
|
56
|
+
long: '--types TYPES'
|
57
|
+
|
58
|
+
option :minutes_previous,
|
59
|
+
description: 'Minutes before now to check @timestamp against query.',
|
60
|
+
long: '--minutes-previous MINUTES_PREVIOUS',
|
61
|
+
proc: proc(&:to_i),
|
62
|
+
default: 0
|
63
|
+
|
64
|
+
option :hours_previous,
|
65
|
+
description: 'Hours before now to check @timestamp against query.',
|
66
|
+
long: '--hours-previous HOURS_PREVIOUS',
|
67
|
+
proc: proc(&:to_i),
|
68
|
+
default: 0
|
69
|
+
|
70
|
+
option :days_previous,
|
71
|
+
description: 'Days before now to check @timestamp against query.',
|
72
|
+
long: '--days-previous DAYS_PREVIOUS',
|
73
|
+
proc: proc(&:to_i),
|
74
|
+
default: 0
|
75
|
+
|
76
|
+
option :weeks_previous,
|
77
|
+
description: 'Weeks before now to check @timestamp against query.',
|
78
|
+
long: '--weeks-previous WEEKS_PREVIOUS',
|
79
|
+
proc: proc(&:to_i),
|
80
|
+
default: 0
|
81
|
+
|
82
|
+
option :months_previous,
|
83
|
+
description: 'Months before now to check @timestamp against query.',
|
84
|
+
long: '--months-previous MONTHS_PREVIOUS',
|
85
|
+
proc: proc(&:to_i),
|
86
|
+
default: 0
|
87
|
+
|
88
|
+
option :date_index,
|
89
|
+
description: 'Elasticsearch time based index.
|
90
|
+
Accepts format from http://ruby-doc.org/core-2.2.0/Time.html#method-i-strftime',
|
91
|
+
short: '-d DATE_INDEX',
|
92
|
+
long: '--date-index DATE_INDEX'
|
93
|
+
|
94
|
+
option :date_repeat_daily,
|
95
|
+
description: 'Elasticsearch date based index repeats daily.',
|
96
|
+
long: '--repeat-daily',
|
97
|
+
boolean: true,
|
98
|
+
default: true
|
99
|
+
|
100
|
+
option :date_repeat_hourly,
|
101
|
+
description: 'Elasticsearch date based index repeats hourly.',
|
102
|
+
long: '--repeat-hourly',
|
103
|
+
boolean: true,
|
104
|
+
default: false
|
105
|
+
|
106
|
+
option :query,
|
107
|
+
description: 'Elasticsearch query',
|
108
|
+
short: '-q QUERY',
|
109
|
+
long: '--query QUERY',
|
110
|
+
required: true
|
111
|
+
|
112
|
+
option :host,
|
113
|
+
description: 'Elasticsearch host',
|
114
|
+
short: '-h HOST',
|
115
|
+
long: '--host HOST',
|
116
|
+
default: 'localhost'
|
117
|
+
|
118
|
+
option :port,
|
119
|
+
description: 'Elasticsearch port',
|
120
|
+
short: '-p PORT',
|
121
|
+
long: '--port PORT',
|
122
|
+
proc: proc(&:to_i),
|
123
|
+
default: 9200
|
124
|
+
|
125
|
+
option :scheme,
|
126
|
+
description: 'Elasticsearch connection scheme, defaults to https for authenticated connections',
|
127
|
+
short: '-s SCHEME',
|
128
|
+
long: '--scheme SCHEME',
|
129
|
+
default: 'https'
|
130
|
+
|
131
|
+
option :password,
|
132
|
+
description: 'Elasticsearch connection password',
|
133
|
+
short: '-P PASSWORD',
|
134
|
+
long: '--password PASSWORD'
|
135
|
+
|
136
|
+
option :user,
|
137
|
+
description: 'Elasticsearch connection user',
|
138
|
+
short: '-u USER',
|
139
|
+
long: '--user USER'
|
140
|
+
|
141
|
+
option :timeout,
|
142
|
+
description: 'Elasticsearch query timeout in seconds',
|
143
|
+
short: '-t TIMEOUT',
|
144
|
+
long: '--timeout TIMEOUT',
|
145
|
+
proc: proc(&:to_i),
|
146
|
+
default: 30
|
147
|
+
|
148
|
+
option :warn,
|
149
|
+
short: '-w N',
|
150
|
+
long: '--warn N',
|
151
|
+
description: 'Result count WARNING threshold',
|
152
|
+
proc: proc(&:to_i),
|
153
|
+
default: 0
|
154
|
+
|
155
|
+
option :crit,
|
156
|
+
short: '-c N',
|
157
|
+
long: '--crit N',
|
158
|
+
description: 'Result count CRITICAL threshold',
|
159
|
+
proc: proc(&:to_i),
|
160
|
+
default: 0
|
161
|
+
|
162
|
+
option :invert,
|
163
|
+
long: '--invert',
|
164
|
+
description: 'Invert thresholds',
|
165
|
+
boolean: true
|
166
|
+
|
167
|
+
def run
|
168
|
+
response = client.count(build_request_options)
|
169
|
+
if config[:invert]
|
170
|
+
if response['count'] < config[:crit]
|
171
|
+
critical 'Query count was below critical threshold'
|
172
|
+
elsif response['count'] < config[:warn]
|
173
|
+
warning 'Query count was below warning threshold'
|
174
|
+
else
|
175
|
+
ok
|
176
|
+
end
|
177
|
+
else
|
178
|
+
if response['count'] > config[:crit]
|
179
|
+
critical 'Query count was above critical threshold'
|
180
|
+
elsif response['count'] > config[:warn]
|
181
|
+
warning 'Query count was above warning threshold'
|
182
|
+
else
|
183
|
+
ok
|
184
|
+
end
|
185
|
+
end
|
186
|
+
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
187
|
+
if config[:invert]
|
188
|
+
if response['count'] < config[:crit]
|
189
|
+
critical 'Query count was below critical threshold'
|
190
|
+
elsif response['count'] < config[:warn]
|
191
|
+
warning 'Query count was below warning threshold'
|
192
|
+
else
|
193
|
+
ok
|
194
|
+
end
|
195
|
+
else
|
196
|
+
ok 'No results found, count was below thresholds'
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-es-query-exists
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin checks an ElasticSearch query that documents exist.
|
7
|
+
#
|
8
|
+
# OUTPUT:
|
9
|
+
# plain text
|
10
|
+
#
|
11
|
+
# PLATFORMS:
|
12
|
+
# Linux
|
13
|
+
#
|
14
|
+
# DEPENDENCIES:
|
15
|
+
# gem: sensu-plugin
|
16
|
+
# gem: elasticsearch
|
17
|
+
#
|
18
|
+
# USAGE:
|
19
|
+
# This example checks that the count of special_type logs matching a query of
|
20
|
+
# "docker.args:special AND *specialstring* AND _exists_:key.name"
|
21
|
+
# at the host elasticsearch.service.consul and port 9200 for the past 3 minutes
|
22
|
+
# will go critical if there are NO results for that period.
|
23
|
+
# This check is to ensure that events are happening at all.
|
24
|
+
# check-es-query-exists.rb -h elasticsearch.service.consul
|
25
|
+
# -q "docker.args:special AND *specialstring* AND _exists_:key.name" --invert
|
26
|
+
# --types special_type -d 'logging-%Y.%m.%d' --minutes-previous 3 -p 9200
|
27
|
+
#
|
28
|
+
# NOTES:
|
29
|
+
#
|
30
|
+
# LICENSE:
|
31
|
+
# Brendan Gibat <brendan.gibat@gmail.com>
|
32
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
33
|
+
# for details.
|
34
|
+
#
|
35
|
+
|
36
|
+
require 'sensu-plugin/check/cli'
|
37
|
+
require 'elasticsearch'
|
38
|
+
require 'sensu-plugins-elasticsearch'
|
39
|
+
|
40
|
+
#
|
41
|
+
# ES Heap
|
42
|
+
#
|
43
|
+
class ESQueryExists < Sensu::Plugin::Check::CLI
|
44
|
+
include ElasticsearchCommon
|
45
|
+
|
46
|
+
option :index,
|
47
|
+
description: 'Elasticsearch indices to query.
|
48
|
+
Comma-separated list of index names to search.
|
49
|
+
Use `_all` or empty string to perform the operation on all indices.
|
50
|
+
Accepts wildcards',
|
51
|
+
short: '-i INDEX',
|
52
|
+
long: '--indices INDEX'
|
53
|
+
|
54
|
+
option :types,
|
55
|
+
description: 'Elasticsearch types to limit searches to, comma separated list.',
|
56
|
+
long: '--types TYPES'
|
57
|
+
|
58
|
+
option :minutes_previous,
|
59
|
+
description: 'Minutes before now to check @timestamp against query.',
|
60
|
+
long: '--minutes-previous MINUTES_PREVIOUS',
|
61
|
+
proc: proc(&:to_i),
|
62
|
+
default: 0
|
63
|
+
|
64
|
+
option :hours_previous,
|
65
|
+
description: 'Hours before now to check @timestamp against query.',
|
66
|
+
long: '--hours-previous DAYS_PREVIOUS',
|
67
|
+
proc: proc(&:to_i),
|
68
|
+
default: 0
|
69
|
+
|
70
|
+
option :days_previous,
|
71
|
+
description: 'Days before now to check @timestamp against query.',
|
72
|
+
long: '--days-previous DAYS_PREVIOUS',
|
73
|
+
proc: proc(&:to_i),
|
74
|
+
default: 0
|
75
|
+
|
76
|
+
option :weeks_previous,
|
77
|
+
description: 'Weeks before now to check @timestamp against query.',
|
78
|
+
long: '--weeks-previous WEEKS_PREVIOUS',
|
79
|
+
proc: proc(&:to_i),
|
80
|
+
default: 0
|
81
|
+
|
82
|
+
option :months_previous,
|
83
|
+
description: 'Months before now to check @timestamp against query.',
|
84
|
+
long: '--months-previous MONTHS_PREVIOUS',
|
85
|
+
proc: proc(&:to_i),
|
86
|
+
default: 0
|
87
|
+
|
88
|
+
option :date_index,
|
89
|
+
description: 'Elasticsearch time based index.
|
90
|
+
Accepts format from http://ruby-doc.org/core-2.2.0/Time.html#method-i-strftime',
|
91
|
+
short: '-d DATE_INDEX',
|
92
|
+
long: '--date-index DATE_INDEX'
|
93
|
+
|
94
|
+
option :date_repeat_daily,
|
95
|
+
description: 'Elasticsearch date based index repeats daily.',
|
96
|
+
long: '--repeat-daily',
|
97
|
+
boolean: true,
|
98
|
+
default: true
|
99
|
+
|
100
|
+
option :date_repeat_hourly,
|
101
|
+
description: 'Elasticsearch date based index repeats hourly.',
|
102
|
+
long: '--repeat-hourly',
|
103
|
+
boolean: true,
|
104
|
+
default: false
|
105
|
+
|
106
|
+
option :query,
|
107
|
+
description: 'Elasticsearch query',
|
108
|
+
short: '-q QUERY',
|
109
|
+
long: '--query QUERY',
|
110
|
+
required: true
|
111
|
+
|
112
|
+
option :host,
|
113
|
+
description: 'Elasticsearch host',
|
114
|
+
short: '-h HOST',
|
115
|
+
long: '--host HOST',
|
116
|
+
default: 'localhost'
|
117
|
+
|
118
|
+
option :port,
|
119
|
+
description: 'Elasticsearch port',
|
120
|
+
short: '-p PORT',
|
121
|
+
long: '--port PORT',
|
122
|
+
proc: proc(&:to_i),
|
123
|
+
default: 9200
|
124
|
+
|
125
|
+
option :scheme,
|
126
|
+
description: 'Elasticsearch connection scheme, defaults to https for authenticated connections',
|
127
|
+
short: '-s SCHEME',
|
128
|
+
long: '--scheme SCHEME',
|
129
|
+
default: 'https'
|
130
|
+
|
131
|
+
option :password,
|
132
|
+
description: 'Elasticsearch connection password',
|
133
|
+
short: '-P PASSWORD',
|
134
|
+
long: '--password PASSWORD'
|
135
|
+
|
136
|
+
option :user,
|
137
|
+
description: 'Elasticsearch connection user',
|
138
|
+
short: '-u USER',
|
139
|
+
long: '--user USER'
|
140
|
+
|
141
|
+
option :timeout,
|
142
|
+
description: 'Elasticsearch query timeout in seconds',
|
143
|
+
short: '-t TIMEOUT',
|
144
|
+
long: '--timeout TIMEOUT',
|
145
|
+
proc: proc(&:to_i),
|
146
|
+
default: 30
|
147
|
+
|
148
|
+
option :warn,
|
149
|
+
short: '-w N',
|
150
|
+
long: '--warn N',
|
151
|
+
description: 'Result count WARNING threshold',
|
152
|
+
proc: proc(&:to_i),
|
153
|
+
default: 0
|
154
|
+
|
155
|
+
option :crit,
|
156
|
+
short: '-c N',
|
157
|
+
long: '--crit N',
|
158
|
+
description: 'Result count CRITICAL threshold',
|
159
|
+
proc: proc(&:to_i),
|
160
|
+
default: 0
|
161
|
+
|
162
|
+
option :invert,
|
163
|
+
long: '--invert',
|
164
|
+
description: 'Invert thresholds',
|
165
|
+
boolean: true
|
166
|
+
|
167
|
+
def run # rubocop:disable all
|
168
|
+
client.exists(build_request_options)
|
169
|
+
ok
|
170
|
+
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
171
|
+
critical
|
172
|
+
end
|
173
|
+
end
|
@@ -123,7 +123,7 @@ class ESNodeGraphiteMetrics < Sensu::Plugin::Metric::CLI::Graphite
|
|
123
123
|
info['version']['number']
|
124
124
|
end
|
125
125
|
|
126
|
-
def run
|
126
|
+
def run
|
127
127
|
# invert various stats depending on if some flags are set
|
128
128
|
os_stat = !config[:disable_os_stats]
|
129
129
|
process_stats = !config[:disable_process_stats]
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#
|
2
|
+
# DESCRIPTION:
|
3
|
+
# Common helper methods
|
4
|
+
#
|
5
|
+
# DEPENDENCIES:
|
6
|
+
# gem: elasticsearch
|
7
|
+
# gem: sensu-plugin
|
8
|
+
#
|
9
|
+
# USAGE:
|
10
|
+
#
|
11
|
+
# NOTES:
|
12
|
+
#
|
13
|
+
# LICENSE:
|
14
|
+
# Brendan Gibat <brendan.gibat@gmail.com>
|
15
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
16
|
+
# for details.
|
17
|
+
#
|
18
|
+
require_relative 'elasticsearch-query.rb'
|
19
|
+
|
20
|
+
module ElasticsearchCommon
|
21
|
+
include ElasticsearchQuery
|
22
|
+
def initialize
|
23
|
+
super()
|
24
|
+
end
|
25
|
+
|
26
|
+
def client
|
27
|
+
@client ||= begin
|
28
|
+
if !config[:user].nil? && !config[:pass].nil? && !config[:scheme].nil?
|
29
|
+
Elasticsearch::Client.new hosts: [{
|
30
|
+
host: config[:host],
|
31
|
+
port: config[:port],
|
32
|
+
user: config[:user],
|
33
|
+
password: config[:password],
|
34
|
+
scheme: config[:scheme],
|
35
|
+
request_timeout: config[:timeout]
|
36
|
+
}]
|
37
|
+
else
|
38
|
+
Elasticsearch::Client.new host: "#{config[:host]}:#{config[:port]}", request_timeout: config[:timeout]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
#
|
2
|
+
# DESCRIPTION:
|
3
|
+
# Common search helper methods
|
4
|
+
#
|
5
|
+
# DEPENDENCIES:
|
6
|
+
# gem: elasticsearch
|
7
|
+
# gem: sensu-plugin
|
8
|
+
#
|
9
|
+
# USAGE:
|
10
|
+
#
|
11
|
+
# NOTES:
|
12
|
+
#
|
13
|
+
# LICENSE:
|
14
|
+
# Brendan Gibat <brendan.gibat@gmail.com>
|
15
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
16
|
+
# for details.
|
17
|
+
#
|
18
|
+
|
19
|
+
module ElasticsearchQuery
|
20
|
+
def initialize
|
21
|
+
super()
|
22
|
+
end
|
23
|
+
|
24
|
+
def indices
|
25
|
+
if !config[:index].nil?
|
26
|
+
return config[:index]
|
27
|
+
elsif !config[:date_index].nil?
|
28
|
+
indices = []
|
29
|
+
curr = Time.now.utc.to_i
|
30
|
+
start = curr
|
31
|
+
|
32
|
+
if config[:minutes_previous] != 0
|
33
|
+
start -= (config[:minutes_previous] * 60)
|
34
|
+
end
|
35
|
+
if config[:hours_previous] != 0
|
36
|
+
start -= (config[:hours_previous] * 60 * 60)
|
37
|
+
end
|
38
|
+
if config[:days_previous] != 0
|
39
|
+
start -= (config[:days_previous] * 60 * 60 * 24)
|
40
|
+
end
|
41
|
+
if config[:weeks_previous] != 0
|
42
|
+
start -= (config[:weeks_previous] * 60 * 60 * 24 * 7)
|
43
|
+
end
|
44
|
+
if config[:months_previous] != 0
|
45
|
+
start -= (config[:months_previous] * 60 * 60 * 24 * 7 * 31)
|
46
|
+
end
|
47
|
+
total = 60 * 60 * 24
|
48
|
+
if config[:date_repeat_hourly]
|
49
|
+
total = 60 * 60
|
50
|
+
end
|
51
|
+
(start.to_i..curr.to_i).step(total) do |step|
|
52
|
+
indices.push(Time.at(step).utc.strftime config[:date_index])
|
53
|
+
end
|
54
|
+
unless indices.include?(Time.at(curr).utc.strftime config[:date_index])
|
55
|
+
indices.push(Time.at(curr).utc.strftime config[:date_index])
|
56
|
+
end
|
57
|
+
return indices.join(',')
|
58
|
+
end
|
59
|
+
['_all']
|
60
|
+
end
|
61
|
+
|
62
|
+
def build_request_options
|
63
|
+
options = {
|
64
|
+
index: indices,
|
65
|
+
ignore_unavailable: true
|
66
|
+
}
|
67
|
+
if !config[:body].nil?
|
68
|
+
options[:body] = config[:body]
|
69
|
+
else
|
70
|
+
es_date_filter = es_date_math_string
|
71
|
+
unless es_date_filter.nil?
|
72
|
+
options[:body] = {
|
73
|
+
'query' => {
|
74
|
+
'filtered' => {
|
75
|
+
'query' => {
|
76
|
+
'query_string' => {
|
77
|
+
'default_field' => 'message',
|
78
|
+
'query' => config[:query]
|
79
|
+
}
|
80
|
+
},
|
81
|
+
'filter' => {
|
82
|
+
'range' => {
|
83
|
+
'@timestamp' => { 'gt' => es_date_filter }
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
end
|
90
|
+
end
|
91
|
+
unless config[:types].nil?
|
92
|
+
options[:type] = config[:types]
|
93
|
+
end
|
94
|
+
options
|
95
|
+
end
|
96
|
+
|
97
|
+
def es_date_math_string
|
98
|
+
if config[:minutes_previous] == 0 && \
|
99
|
+
config[:hours_previous] == 0 && \
|
100
|
+
config[:weeks_previous] == 0 && \
|
101
|
+
config[:months_previous] == 0
|
102
|
+
return nil
|
103
|
+
else
|
104
|
+
es_math = "#{Time.now.utc.strftime '%Y-%m-%dT%H:%M:%S'}||"
|
105
|
+
if config[:minutes_previous] != 0
|
106
|
+
es_math += "-#{config[:minutes_previous]}m"
|
107
|
+
end
|
108
|
+
if config[:hours_previous] != 0
|
109
|
+
es_math += "-#{config[:hours_previous]}h"
|
110
|
+
end
|
111
|
+
if config[:days_previous] != 0
|
112
|
+
es_math += "-#{config[:days_previous]}d"
|
113
|
+
end
|
114
|
+
if config[:weeks_previous] != 0
|
115
|
+
es_math += "-#{config[:weeks_previous]}w"
|
116
|
+
end
|
117
|
+
if config[:months_previous] != 0
|
118
|
+
es_math += "-#{config[:months_previous]}M"
|
119
|
+
end
|
120
|
+
return es_math
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-elasticsearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu Plugins and contributors
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
|
31
31
|
HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2015-
|
33
|
+
date: 2015-10-16 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: rest-client
|
@@ -46,6 +46,20 @@ dependencies:
|
|
46
46
|
- - '='
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: 1.8.0
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: elasticsearch
|
51
|
+
requirement: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.0.12
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.0.12
|
49
63
|
- !ruby/object:Gem::Dependency
|
50
64
|
name: sensu-plugin
|
51
65
|
requirement: !ruby/object:Gem::Requirement
|
@@ -186,12 +200,17 @@ dependencies:
|
|
186
200
|
- - "~>"
|
187
201
|
- !ruby/object:Gem::Version
|
188
202
|
version: '0.8'
|
189
|
-
description:
|
203
|
+
description: |-
|
204
|
+
This plugin provides native ElasticSearch instrumentation
|
205
|
+
for monitoring and metrics collection, including:
|
206
|
+
service health and metrics for cluster, node, and more
|
190
207
|
email: "<sensu-users@googlegroups.com>"
|
191
208
|
executables:
|
192
209
|
- metrics-es-node.rb
|
193
210
|
- metrics-es-node-graphite.rb
|
194
211
|
- metrics-es-cluster.rb
|
212
|
+
- check-es-query-exists.rb
|
213
|
+
- check-es-query-count.rb
|
195
214
|
- check-es-node-status.rb
|
196
215
|
- check-es-heap.rb
|
197
216
|
- check-es-file-descriptors.rb
|
@@ -206,10 +225,14 @@ files:
|
|
206
225
|
- bin/check-es-file-descriptors.rb
|
207
226
|
- bin/check-es-heap.rb
|
208
227
|
- bin/check-es-node-status.rb
|
228
|
+
- bin/check-es-query-count.rb
|
229
|
+
- bin/check-es-query-exists.rb
|
209
230
|
- bin/metrics-es-cluster.rb
|
210
231
|
- bin/metrics-es-node-graphite.rb
|
211
232
|
- bin/metrics-es-node.rb
|
212
233
|
- lib/sensu-plugins-elasticsearch.rb
|
234
|
+
- lib/sensu-plugins-elasticsearch/elasticsearch-common.rb
|
235
|
+
- lib/sensu-plugins-elasticsearch/elasticsearch-query.rb
|
213
236
|
- lib/sensu-plugins-elasticsearch/version.rb
|
214
237
|
homepage: https://github.com/sensu-plugins/sensu-plugins-elasticsearch
|
215
238
|
licenses:
|
metadata.gz.sig
CHANGED
Binary file
|