sensu-plugins-eventstore 0.0.4 → 0.0.5

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/check-gossip.rb +54 -43
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38994ee87db4e297cdec9d70ef832775a29e1b33
4
- data.tar.gz: 59436bc00a7b1e9bc17ad38bad1e398344a5bc75
3
+ metadata.gz: bdb16fcadb0f5c1ce1f91bc09a8f43f82d9650b0
4
+ data.tar.gz: 3924369e8a2e84752246717a2f74e4427b1a8494
5
5
  SHA512:
6
- metadata.gz: c5112ccfa0d8a846abc8c7d3181b136794d74f463726075c12c6db4c1665891f4aff7b17c6eb22ed894b8451ac2512dd695aba85df3a8d2d33130ee73cc1ce02
7
- data.tar.gz: bfa6f88dcdf913849037905f1a4b38a8294877d8e86a3186bbb22e829412cdeb88ff80e8e1bfa7a870487b258566f32a7e899c9b083b8cce9ccfba20b17dd400
6
+ metadata.gz: fa8d641213093e20eef660428ff88985f3dc40192af60033871cbd177eed1baed8da29323cfd12eaa5ffe465024c537420123f7897db479d30c79612648e3443
7
+ data.tar.gz: 1f0c76a904c019f0145f80696ad50e4e160fd143c38fe2bedc5fd5544578a73fe39e0eea7d5a0d4e7cc5bf24739f85122e88132c6ee23412863d0d874fed96ef
data/bin/check-gossip.rb CHANGED
@@ -73,7 +73,7 @@ class CheckGossip < Sensu::Plugin::Check::CLI
73
73
 
74
74
  current_machine_ips = get_current_machine_ipv4s
75
75
  event_store_ips = get_event_store_ips_from_dns cluster_dns
76
- critical_failure_from_no_event_store_ips cluster_dns unless event_store_ips.any?
76
+ critical_no_event_store_ips cluster_dns unless event_store_ips.any?
77
77
  gossip_address = get_matching_ips current_machine_ips, event_store_ips
78
78
  expected_nodes = event_store_ips.count
79
79
  end
@@ -85,13 +85,12 @@ class CheckGossip < Sensu::Plugin::Check::CLI
85
85
  matched_ips = machine_ips.select do |ip_to_look_for|
86
86
  event_store_ips.find { |ip_to_match| ip_to_look_for == ip_to_match }
87
87
  end
88
- critical_failure_from_no_matching_ips machine_ips, event_store_ips unless matched_ips.one?
88
+ critical_no_matching_ips machine_ips, event_store_ips unless matched_ips.one?
89
89
  matched_ips[0]
90
90
  end
91
91
 
92
- def get_masters(document)
93
- states = document.xpath '//State'
94
- states.count { |state| state.content == 'Master' }
92
+ def get_master_count(document)
93
+ get_states(document).count { |state| state.content == 'Master' }
95
94
  end
96
95
 
97
96
  def get_members(document)
@@ -102,8 +101,17 @@ class CheckGossip < Sensu::Plugin::Check::CLI
102
101
  document.xpath '//IsAlive'
103
102
  end
104
103
 
104
+ def get_states(document)
105
+ document.xpath '//State'
106
+ end
107
+
105
108
  def only_one_master?(document)
106
- get_masters(document) == 1
109
+ get_master_count(document) == 1
110
+ end
111
+
112
+ def all_nodes_master_or_slave?(document)
113
+ states = get_states document
114
+ states.all? {|node| node.content == "Master" || node.content == "Slave"}
107
115
  end
108
116
 
109
117
  def node_count_is_correct?(document, expected_count)
@@ -115,56 +123,31 @@ class CheckGossip < Sensu::Plugin::Check::CLI
115
123
  nodes.all? { |node| node_is_alive? node }
116
124
  end
117
125
 
118
- def check_node(gossip_address, gossip_port, expected_nodes)
119
- puts "\nchecking gossip at #{gossip_address}:#{gossip_port}"
120
-
121
- begin
122
- connection_url = "http://#{gossip_address}:#{gossip_port}/gossip?format=xml";
123
- gossip = open(connection_url)
124
-
125
- rescue StandardError
126
- critical "Could not connect to #{connection_url} to check gossip, has event store fallen over on this node? "
127
- end
128
-
129
- xml_doc = Nokogiri::XML(gossip.readline)
130
-
131
- puts "Checking for #{expected_nodes} nodes"
132
- critical_failure_from_missing_nodes xml_doc, expected_nodes unless node_count_is_correct? xml_doc, expected_nodes
133
-
134
- puts "Checking nodes for IsAlive state"
135
- critical_failure_from_dead_nodes xml_doc, expected_nodes unless nodes_all_alive? xml_doc
136
-
137
- puts "Checking for exactly 1 master"
138
- critical_failure_from_incorrect_master_count xml_doc unless only_one_master? xml_doc
139
-
140
- ok "#{gossip_address} is gossiping with #{expected_nodes} nodes. All nodes are marked as alive and one master node was found."
141
- end
142
-
143
- def critical_failure_from_no_matching_ips(machine_ips, event_store_ips)
126
+ def critical_no_matching_ips(machine_ips, event_store_ips)
144
127
  critical "this machine has ips of #{machine_ips}, event store (according to dns lookup) has ips of #{event_store_ips}. There should be exactly one match, but wasn't. "
145
128
  end
146
- def critical_failure_from_no_event_store_ips(dns_name)
129
+ def critical_no_event_store_ips(dns_name)
147
130
  critical "could not find any ips at dns name #{dns_name} so cannot check gossips"
148
131
  end
149
- def critical_failure_from_missing_nodes(xml_doc, expected_nodes)
150
- critical "Wrong number of nodes, was #{get_members(xml_doc).count} should be exactly #{expected_nodes}"
132
+ def critical_missing_nodes(xml_doc, expected_nodes)
133
+ critical "Wrong number of nodes, was #{get_members(xml_doc).count} should be #{expected_nodes}"
151
134
  end
152
- def critical_failure_from_dead_nodes(xml_doc, expected_nodes)
135
+ def critical_dead_nodes(xml_doc, expected_nodes)
153
136
  critical "Only #{get_is_alive_nodes(xml_doc).count { |node| node_is_alive? node}} alive nodes, should be #{expected_nodes} alive"
154
137
  end
155
- def critical_failure_from_incorrect_master_count(xml_doc)
156
- critical "Wrong number of node masters, there should be exactly 1 but there were #{get_masters(xml_doc)} masters"
138
+ def critical_master_count(xml_doc)
139
+ critical "Wrong number of node masters, there should be 1 but there were #{get_master_count(xml_doc)} masters"
140
+ end
141
+ def warn_nodes_not_ready(xml_doc)
142
+ states = get_states xml_doc
143
+ states = states.find { |node| node.content != "Master" and node.content != "Slave"}
144
+ warn "nodes found with states: #{states} when expected Master or Slave."
157
145
  end
158
146
 
159
147
  def node_is_alive?(node)
160
148
  node.content == 'true'
161
149
  end
162
150
 
163
- def print_all(collection, type)
164
- puts "\nprinting #{type} collection"
165
- collection.each { |item| p item }
166
- end
167
-
168
151
  def get_event_store_ips_from_dns(dns_name)
169
152
  Resolv::DNS.open { |dns|
170
153
  resources = dns.getresources dns_name, Resolv::DNS::Resource::IN::A
@@ -181,4 +164,32 @@ class CheckGossip < Sensu::Plugin::Check::CLI
181
164
 
182
165
  potential_ips.select { |info| ipv4_regex.match(info)}
183
166
  end
167
+
168
+ def check_node(gossip_address, gossip_port, expected_nodes)
169
+ puts "\nchecking gossip at #{gossip_address}:#{gossip_port}"
170
+
171
+ begin
172
+ connection_url = "http://#{gossip_address}:#{gossip_port}/gossip?format=xml"
173
+ gossip = open(connection_url)
174
+
175
+ rescue StandardError
176
+ critical "Could not connect to #{connection_url} to check gossip, has event store fallen over on this node? "
177
+ end
178
+
179
+ xml_doc = Nokogiri::XML(gossip.readline)
180
+
181
+ puts "Checking for #{expected_nodes} nodes"
182
+ critical_missing_nodes xml_doc, expected_nodes unless node_count_is_correct? xml_doc, expected_nodes
183
+
184
+ puts "Checking nodes for IsAlive state"
185
+ critical_dead_nodes xml_doc, expected_nodes unless nodes_all_alive? xml_doc
186
+
187
+ puts "Checking for exactly 1 master"
188
+ critical_master_count xml_doc unless only_one_master? xml_doc
189
+
190
+ puts "Checking node state"
191
+ warn_nodes_not_ready xml_doc unless all_nodes_master_or_slave? xml_doc
192
+
193
+ ok "#{gossip_address} is gossiping with #{expected_nodes} nodes, all nodes are alive, exactly one master node was found and all other nodes are in the 'Slave' state."
194
+ end
184
195
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-eventstore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Wroe