sensu-plugins-eventstore 0.0.2
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 +7 -0
- data/CHANGELOG.md +6 -0
- data/LICENSE +22 -0
- data/README.md +2 -0
- data/bin/check-gossip.rb +156 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c0617566fa20ad24d0fbaec757fadf48592e0f32
|
4
|
+
data.tar.gz: 091df80a070ac656f47acceb8965da3288c52c91
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: af5df1e909219aacefec8ce0c8e892dcdc9be1b4e9cf2716d5a19d57deb2ea37b3f00de19c445f269b334b5b05f830f517d38e54a9f6ae76c2ab76161621fe43
|
7
|
+
data.tar.gz: 564bd8b8a1e2822259831b811c72420f99d64b372db965d6cc30fa17f230f77fa1da7a77f24211f8ad1a4969afbf7c3be1ab0a949af2bdeae4d53a118ab6047c
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Sensu-Plugins
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/bin/check-gossip.rb
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-gossip
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Checks the event store gossip page, making sure everything is working as expected
|
7
|
+
# OUTPUT:
|
8
|
+
# plain text, metric data, etc
|
9
|
+
#
|
10
|
+
# PLATFORMS:
|
11
|
+
# Linux, Windows
|
12
|
+
#
|
13
|
+
# DEPENDENCIES:
|
14
|
+
# gem: sensu-plugin
|
15
|
+
# gem: nokogiri
|
16
|
+
#
|
17
|
+
# USAGE:
|
18
|
+
# #YELLOW
|
19
|
+
#
|
20
|
+
# NOTES:
|
21
|
+
#
|
22
|
+
# LICENSE:
|
23
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
24
|
+
# for details.
|
25
|
+
#
|
26
|
+
|
27
|
+
require 'nokogiri'
|
28
|
+
require 'open-uri'
|
29
|
+
require 'socket'
|
30
|
+
require 'Resolv'
|
31
|
+
require 'sensu-plugin/check/cli'
|
32
|
+
|
33
|
+
|
34
|
+
class CheckGossip < Sensu::Plugin::Check::CLI
|
35
|
+
option :discover_via_dns,
|
36
|
+
description: 'Whether to use DNS lookup to discover other cluster nodes. (Default: true)',
|
37
|
+
short: '-v',
|
38
|
+
long: '--discover_via_dns discover_via_dns',
|
39
|
+
default: 'true'
|
40
|
+
|
41
|
+
option :cluster_dns,
|
42
|
+
description: 'DNS name from which other nodes can be discovered.',
|
43
|
+
short: '-d',
|
44
|
+
long: '--cluster_dns cluster_dns',
|
45
|
+
default: 'localhost'
|
46
|
+
|
47
|
+
option :gossip_address,
|
48
|
+
description: 'If discover_via_dns is set to false then this address will be used for gossip. (Default localhost)',
|
49
|
+
short: '-g',
|
50
|
+
long: '--gossip_ip gossip_ip',
|
51
|
+
default: 'localhost'
|
52
|
+
|
53
|
+
option :gossip_port,
|
54
|
+
description: 'What port to use when connecting to gossip. (Default 2113)',
|
55
|
+
short: '-p',
|
56
|
+
long: '--gossip_port gossip_port',
|
57
|
+
default: '2113'
|
58
|
+
|
59
|
+
option :expected_nodes,
|
60
|
+
description: 'The total number of nodes we expect to be gossiping, including this one. (Default 2)',
|
61
|
+
short: '-e',
|
62
|
+
long: '--expected_nodes expected_nodes',
|
63
|
+
default: '2'
|
64
|
+
|
65
|
+
def run
|
66
|
+
discover_via_dns = config[:discover_via_dns]
|
67
|
+
gossip_address = config[:gossip_address]
|
68
|
+
gossip_port = config[:gossip_port]
|
69
|
+
expected_nodes = config[:expected_nodes].to_i
|
70
|
+
|
71
|
+
if discover_via_dns
|
72
|
+
cluster_dns = config[:cluster_dns]
|
73
|
+
|
74
|
+
current_machine_ips = get_current_machine_ipv4s
|
75
|
+
event_store_ips = get_event_store_ips_from_dns cluster_dns
|
76
|
+
gossip_address = get_matching_ips current_machine_ips, event_store_ips
|
77
|
+
expected_nodes = event_store_ips.count
|
78
|
+
end
|
79
|
+
|
80
|
+
check_node gossip_address, gossip_port, expected_nodes
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_matching_ips(machine_ips, event_store_ips)
|
84
|
+
matched_ips = machine_ips.select do |ip_to_look_for|
|
85
|
+
event_store_ips.find { |ip_to_match| ip_to_look_for == ip_to_match }
|
86
|
+
end
|
87
|
+
critical "#{matched_ips.count} ips were found for this machine in the event store dns lookup, cannot figure out where to check gossip from" unless matched_ips.one?
|
88
|
+
matched_ips[0]
|
89
|
+
end
|
90
|
+
|
91
|
+
def get_masters(document)
|
92
|
+
states = document.xpath '//State'
|
93
|
+
states.count { |state| state.content == 'Master' }
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_members(document)
|
97
|
+
document.xpath '//MemberInfoDto'
|
98
|
+
end
|
99
|
+
|
100
|
+
def get_is_alive_nodes(document)
|
101
|
+
document.xpath '//IsAlive'
|
102
|
+
end
|
103
|
+
|
104
|
+
def only_one_master?(document)
|
105
|
+
get_masters(document) == 1
|
106
|
+
end
|
107
|
+
|
108
|
+
def node_count_is_correct?(document, expected_count)
|
109
|
+
get_members(document).count == expected_count
|
110
|
+
end
|
111
|
+
|
112
|
+
def nodes_all_alive?(document)
|
113
|
+
nodes = get_is_alive_nodes document
|
114
|
+
nodes.all? { |node| node.content == 'true' }
|
115
|
+
end
|
116
|
+
|
117
|
+
def check_node(gossip_address, gossip_port, expected_nodes)
|
118
|
+
puts "\nchecking gossip at #{gossip_address}:#{gossip_port}"
|
119
|
+
gossip = open("http://#{gossip_address}:#{gossip_port}/gossip?format=xml")
|
120
|
+
|
121
|
+
xml_doc = Nokogiri::XML(gossip.readline)
|
122
|
+
|
123
|
+
puts "\tchecking for #{expected_nodes} nodes"
|
124
|
+
critical "\twrong number of nodes, was #{get_members(xml_doc).count} should be exactly #{expected_nodes}" unless node_count_is_correct? xml_doc, expected_nodes
|
125
|
+
|
126
|
+
puts "\tchecking nodes for IsAlive state"
|
127
|
+
critical "\tat least 1 node is not alive" unless nodes_all_alive? xml_doc
|
128
|
+
|
129
|
+
puts "\tchecking for exactly 1 master"
|
130
|
+
critical "\twrong number of node masters, there should be exactly 1" unless only_one_master? xml_doc
|
131
|
+
|
132
|
+
ok "Gossiping with #{expected_nodes} nodes, all of which alive and with one master node."
|
133
|
+
end
|
134
|
+
|
135
|
+
def print_all(collection, type)
|
136
|
+
puts "\nprinting #{type} collection"
|
137
|
+
collection.each { |item| p item }
|
138
|
+
end
|
139
|
+
|
140
|
+
def get_event_store_ips_from_dns(dns_name)
|
141
|
+
Resolv::DNS.open { |dns|
|
142
|
+
resources = dns.getresources dns_name, Resolv::DNS::Resource::IN::A
|
143
|
+
resources.map { |res| res.address.to_s }
|
144
|
+
}
|
145
|
+
end
|
146
|
+
|
147
|
+
def get_current_machine_ipv4s
|
148
|
+
loopback_regex = /^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/
|
149
|
+
ipv4_regex = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/
|
150
|
+
|
151
|
+
potential_ips = Socket.ip_address_list.map{|info| info.ip_address}
|
152
|
+
.select {|info| not loopback_regex.match(info)}
|
153
|
+
|
154
|
+
potential_ips.select { |info| ipv4_regex.match(info)}
|
155
|
+
end
|
156
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-plugins-eventstore
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jamie Wroe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: yard
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sensu-plugin
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.2.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.2.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.6.7.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.6.7.2
|
69
|
+
description: A collection of checks and metrics for event store, designed for sensu
|
70
|
+
email: Jamie.Wroe@live.co.uk
|
71
|
+
executables:
|
72
|
+
- check-gossip.rb
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- CHANGELOG.md
|
77
|
+
- LICENSE
|
78
|
+
- README.md
|
79
|
+
- bin/check-gossip.rb
|
80
|
+
homepage: https://github.com/JWroe/sensu-plugins-eventstore
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata:
|
84
|
+
maintainer: "@JWroe"
|
85
|
+
development_status: active
|
86
|
+
production_status: unstable - testing recommended
|
87
|
+
release_draft: 'false'
|
88
|
+
release_prerelease: 'false'
|
89
|
+
post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
|
90
|
+
in /etc/default/sensu
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 1.9.3
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.4.5.1
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: sensu-plugins for event store
|
110
|
+
test_files: []
|