Permalink
Browse files

Fixed an issue with datasources alert

In the event that replication for a cluster is switched off,
the datasources ls output won't include the "progress" attribute
that I was grepping on.  Now slurping in the entire ls output, and
in ruby (for ease of writing the more-complicated regex) am grepping
for the relevant lines by looking for datasource name and role.
  • Loading branch information...
1 parent 29f40e2 commit 67d3e6b71597b019e70d5d9e98f86a4483639f3a @bensomers bensomers committed Jun 15, 2011
Showing with 34 additions and 11 deletions.
  1. +31 −9 tungsten/test.rb
  2. +3 −2 tungsten/tungsten.rb
View
@@ -23,18 +23,40 @@ def stub_online_status(plugin)
end
def stub_datasources(plugin)
- plugin.stubs(:`).with('echo "ls" | /opt/tungsten/tungsten-manager/bin/cctrl | grep progress').
+ plugin.stubs(:`).with('echo "ls" | /opt/tungsten/tungsten-manager/bin/cctrl').
returns(<<-EOS
-|db01(master:ONLINE, progress=446708700, VIP=(eth0:0:10.5.6.7 |
-|db02(slave:ONLINE, progress=446708701, latency=0.775) |
+|Connected to manager db01: |
+| web-ubuntu.dc1.datacenter.com#284555555:ONLINE |
+| db02.dc1.bookrenter.com#515555555:ONLINE |
+|Connected to manager db02: |
+|db01(master:ONLINE, progress=472712251, VIP=(eth0:0:10.5.6.7 |
+|netmask 255.255.255.0)) |
+| MANAGER(state=ONLINE) |
+| REPLICATOR(role=master, state=ONLINE) |
+| DATASERVER(state=ONLINE) |
+|db02(slave:ONLINE, progress=472712255, latency=0.368) |
+| MANAGER(state=ONLINE) |
+| REPLICATOR(role=slave, master=db01, state=ONLINE) |
+| DATASERVER(state=ONLINE) |
EOS
)
end
def test_parse_datasources
command_result = <<-EOS
-|db01(master:ONLINE, progress=446708700, VIP=(eth0:0:10.5.6.7 |
-|db02(slave:ONLINE, progress=446708701, latency=0.775) |
+|Connected to manager db01: |
+| web-ubuntu.dc1.datacenter.com#284555555:ONLINE |
+| db02.dc1.bookrenter.com#284555555:ONLINE |
+|Connected to manager db02: |
+|db01(master:ONLINE, progress=472712251, VIP=(eth0:0:10.5.6.7 |
+|netmask 255.255.255.0)) |
+| MANAGER(state=ONLINE) |
+| REPLICATOR(role=master, state=ONLINE) |
+| DATASERVER(state=ONLINE) |
+|db02(slave:ONLINE, progress=472712255, latency=0.368) |
+| MANAGER(state=ONLINE) |
+| REPLICATOR(role=slave, master=db01, state=ONLINE) |
+| DATASERVER(state=ONLINE) |
EOS
expected = { "db01" => "ONLINE", "db02" => "ONLINE" }
@@ -121,7 +143,7 @@ def test_build_report_datasources_online
stub_latency(@plugin)
stub_online_status(@plugin)
stub_replication_roles(@plugin)
- @plugin.stubs(:`).with('echo "ls" | /opt/tungsten/tungsten-manager/bin/cctrl | grep progress').
+ @plugin.stubs(:`).with('echo "ls" | /opt/tungsten/tungsten-manager/bin/cctrl').
returns(<<-EOS
|db01(master:ONLINE, progress=446708700, VIP=(eth0:0:10.5.6.7 |
|db02(slave:ONLINE, progress=446708701, latency=0.775) |
@@ -136,7 +158,7 @@ def test_build_report_datasources_offline
stub_latency(@plugin)
stub_online_status(@plugin)
stub_replication_roles(@plugin)
- @plugin.stubs(:`).with('echo "ls" | /opt/tungsten/tungsten-manager/bin/cctrl | grep progress').
+ @plugin.stubs(:`).with('echo "ls" | /opt/tungsten/tungsten-manager/bin/cctrl').
returns(<<-EOS
|db01(master:ONLINE, progress=446708700, VIP=(eth0:0:10.5.6.7 |
|db02(slave:OFFLINE, progress=446708701, latency=0.775) |
@@ -152,7 +174,7 @@ def test_build_report_dr_only_datasources_offline
stub_latency(@plugin)
stub_online_status(@plugin)
stub_replication_roles(@plugin)
- @plugin.stubs(:`).with('echo "ls" | /opt/tungsten/tungsten-manager/bin/cctrl | grep progress').
+ @plugin.stubs(:`).with('echo "ls" | /opt/tungsten/tungsten-manager/bin/cctrl').
returns(<<-EOS
|db01(master:OFFLINE, progress=446708700, VIP=(eth0:0:10.5.6.7 |
|db02(slave:OFFLINE, progress=446708701, latency=0.775) |
@@ -168,7 +190,7 @@ def test_build_report_dr_only_datasources_online
stub_latency(@plugin)
stub_online_status(@plugin)
stub_replication_roles(@plugin)
- @plugin.stubs(:`).with('echo "ls" | /opt/tungsten/tungsten-manager/bin/cctrl | grep progress').
+ @plugin.stubs(:`).with('echo "ls" | /opt/tungsten/tungsten-manager/bin/cctrl').
returns(<<-EOS
|db01(master:ONLINE, progress=446708700, VIP=(eth0:0:10.5.6.7 |
|db02(slave:OFFLINE, progress=446708701, latency=0.775) |
View
@@ -19,7 +19,8 @@ class TungstenPlugin < Scout::Plugin
EOS
def parse_datasources(datasources_string)
- datasources_string.split(/\|\n\|/).inject({}) do |datasources, string|
+ lines = datasources_string.select { |line| line.match(/\|[\w]+\((master|slave)/) }
+ lines.each.inject({}) do |datasources, string|
if match = string.match(/^\|?([\w]+)\(([\w]+):([\w]+), /)
datasources[match[1]] = match[3]
end
@@ -51,7 +52,7 @@ def build_report
status_string = %x(/opt/tungsten/cluster-home/bin/check_tungsten_online)
replication_string = %x(/opt/tungsten/cluster-home/bin/get_replicator_roles)
replication_roles = parse_replication_roles(replication_string)
- datasources_string = %x(echo "ls" | /opt/tungsten/tungsten-manager/bin/cctrl | grep progress)
+ datasources_string = %x(echo "ls" | /opt/tungsten/tungsten-manager/bin/cctrl)
datasources = parse_datasources(datasources_string)
latencies_string = %x(/opt/tungsten/cluster-home/bin/check_tungsten_latency -c 0)
latencies = parse_latency(latencies_string)

0 comments on commit 67d3e6b

Please sign in to comment.