Permalink
Browse files

Merge branch 'elastic_status_code'

  • Loading branch information...
2 parents 96e2a2d + f31030d commit 6dee2ec3920a03359aa4daf1487dd6d7ab28db89 @itsderek23 itsderek23 committed Mar 13, 2013
Showing with 14 additions and 1 deletion.
  1. +14 −1 elasticsearch_cluster_status/elasticsearch_cluster_status.rb
View
15 elasticsearch_cluster_status/elasticsearch_cluster_status.rb
@@ -25,7 +25,7 @@ def build_report
base_url = "#{option(:elasticsearch_host)}:#{option(:elasticsearch_port)}/_cluster/health"
response = JSON.parse(Net::HTTP.get(URI.parse(base_url)))
- report(:status => response['status'])
+ report(:status => status(response['status']))
report(:number_of_nodes => response['number_of_nodes'])
report(:number_of_data_nodes => response['number_of_data_nodes'])
report(:active_primary_shards => response['active_primary_shards'])
@@ -47,6 +47,19 @@ def build_report
rescue Errno::ECONNREFUSED
error("Unable to connect", "Please ensure the host and port are correct. Current URL: \n\n#{base_url}")
end
+
+ # Generates a status string like "2 (green)" so triggers can be run off the status.
+ def status(color)
+ code = case color
+ when 'green'
+ 2
+ when 'yellow'
+ 1
+ when 'red'
+ 0
+ end
+ "#{code} (#{color})"
+ end
end

0 comments on commit 6dee2ec

Please sign in to comment.