sumo-check-es 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 565a1f2419bf63b4e1300e3797e7b41663a2ada8
4
+ data.tar.gz: 5f666397568acb8859b5a958c19e2c9466bd9db1
5
+ SHA512:
6
+ metadata.gz: 40e802aae3cbaafe04bc449c362aaac6254e1291c29331fe11a6f845ebf67cc836e16d91706907a7e5e5fe130d09f6e8936e0f172f25e2b75b98175e240ba264
7
+ data.tar.gz: ad753d19bc315d42f545f1645fc979db13ad5217d041ff277f2d3d23d8631fe33168362047251849d772a4b2beb58e1f78bafd4c1a7edf29c1244b01e4bb653d
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+ require 'elasticsearch'
3
+ require 'faraday_middleware'
4
+ require 'faraday_middleware/aws_signers_v4'
5
+ require 'sensu-plugin/check/cli'
6
+ require 'uri'
7
+
8
+ class SensuCheckEsSubscriberRate < Sensu::Plugin::Check::CLI
9
+ option :server,
10
+ short: '-s http://localhost:9200',
11
+ long: '--server',
12
+ description: 'Hostname of Elastic Search Cluster',
13
+ default: 'http://localhost:9200'
14
+
15
+ option :min_per_min,
16
+ short: '-r 15',
17
+ description: 'Mininum subscribers per min',
18
+ default: 15
19
+
20
+ option :aws_access_key_id,
21
+ short: '-i sdfsdfsfs',
22
+ description: 'aws access key id',
23
+ default: nil
24
+
25
+ option :aws_secret_access_key,
26
+ short: '-v sdfsfsdfdsfs',
27
+ description: 'aws secret access key',
28
+ default: nil
29
+
30
+ def run
31
+ uri = URI(config[:server].strip)
32
+ if config[:aws_access_key_id] != nil && config[:aws_secret_access_key] != nil
33
+ signing_options = {
34
+ credentials: Aws::Credentials.new(config[:aws_access_key_id], config[:aws_secret_access_key]),
35
+ service_name: 'es',
36
+ region: 'us-west-2'
37
+ }
38
+ client = Elasticsearch::Client.new log:false, url: uri do |f|
39
+ f.use FaradayMiddleware::Gzip
40
+ f.request :aws_signers_v4, signing_options
41
+ end
42
+ else
43
+ client = Elasticsearch::Client.new log:false, url: uri
44
+ end
45
+
46
+ past = (Time.at(Rational(Time.now - ( 15*60 )))).to_i * 1000
47
+
48
+ query = {
49
+ :query => {
50
+ :range => {
51
+ :created_at => {
52
+ :gt => past
53
+ }
54
+ }
55
+ }
56
+ }
57
+
58
+ result = client.count index: 'subscribers', type: 'subscriber' , body: query.to_json
59
+ if result["_shards"]["failed"] == 0
60
+ subscribers_per_min = (result["count"] / 15).to_i
61
+ if subscribers_per_min > config[:min_per_min].to_i
62
+ ok("subscribers/min: #{subscribers_per_min}")
63
+ else
64
+ critical("subscribers rate is to low...: #{subscribers_per_min}")
65
+ end
66
+ else
67
+ critical("oops, there was an issue with the query: #{result.to_s}")
68
+ end
69
+
70
+ end
71
+
72
+ end
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+ require 'elasticsearch'
3
+ require 'faraday_middleware'
4
+ require 'faraday_middleware/aws_signers_v4'
5
+ require 'sensu-plugin/check/cli'
6
+ require 'uri'
7
+
8
+ class SensuCheckEsSubscriberStatus < Sensu::Plugin::Check::CLI
9
+ option :server,
10
+ short: '-s http://localhost:9200',
11
+ long: '--server',
12
+ description: 'Hostname of Elastic Search Cluster',
13
+ default: 'http://localhost:9200'
14
+
15
+ option :time_variance,
16
+ short: '-t 600',
17
+ description: 'Time Variance Allowed',
18
+ default: 600
19
+
20
+ option :aws_access_key_id,
21
+ short: '-i sdfsdfsfs',
22
+ description: 'aws access key id',
23
+ default: nil
24
+
25
+ option :aws_secret_access_key,
26
+ short: '-v sdfsfsdfdsfs',
27
+ description: 'aws secret access key',
28
+ default: nil
29
+
30
+ def run
31
+ uri = URI(config[:server].strip)
32
+ if config[:aws_access_key_id] != nil && config[:aws_secret_access_key] != nil
33
+ signing_options = {
34
+ credentials: Aws::Credentials.new(config[:aws_access_key_id], config[:aws_secret_access_key]),
35
+ service_name: 'es',
36
+ region: 'us-west-2'
37
+ }
38
+ client = Elasticsearch::Client.new log:false, url: uri do |f|
39
+ f.use FaradayMiddleware::Gzip
40
+ f.request :aws_signers_v4, signing_options
41
+ end
42
+ else
43
+ client = Elasticsearch::Client.new log:false, url: uri
44
+ end
45
+
46
+ result = client.search index: 'subscribers', type: 'subscriber' , body: { sort: { created_at: "desc"}, size: 1 }
47
+ reported_time = Time.at(Rational(result["hits"]["hits"][0]["_source"]["created_at"], 1000))
48
+ thePast, theFuture = Time.now - config[:time_variance].to_i, Time.now + config[:time_variance].to_i
49
+
50
+ if reported_time < thePast || reported_time > theFuture
51
+ critical("ES subscriber data looks like it might be stale or moldy or unborn, as i dont know which timeframe im living in")
52
+ else
53
+ ok("ES subscriber data looks good")
54
+ end
55
+
56
+ end
57
+
58
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sumo-check-es
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dr. Ogg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: elasticsearch
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.12'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday_middleware-aws-signers-v4
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sensu-plugin
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.3'
69
+ description:
70
+ email:
71
+ executables:
72
+ - sumo-check-es_subscriber_rate.rb
73
+ - sumo-check-es_subscriber_status.rb
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - bin/sumo-check-es_subscriber_rate.rb
78
+ - bin/sumo-check-es_subscriber_status.rb
79
+ homepage:
80
+ licenses: []
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.6.13
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Sumo Sensu gem for elasticsearch checks
102
+ test_files: []