summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2012-11-06 20:43:30 +0000
committerRobin H. Johnson <robbat2@gentoo.org>2012-11-06 20:43:30 +0000
commitdc8301d75229afb185c812bf53f5f5dc183f1591 (patch)
treef4adef36d47f53c93d75a8d7bb1cca80d4d412b8
parentActually define to_date (diff)
downloadinfra-status-dc8301d75229afb185c812bf53f5f5dc183f1591.tar.gz
infra-status-dc8301d75229afb185c812bf53f5f5dc183f1591.tar.bz2
infra-status-dc8301d75229afb185c812bf53f5f5dc183f1591.zip
Always look before you leap into hashes.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-rw-r--r--lib/service-dsl.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/service-dsl.rb b/lib/service-dsl.rb
index ec80f24..f6eaace 100644
--- a/lib/service-dsl.rb
+++ b/lib/service-dsl.rb
@@ -5,26 +5,34 @@ module HelperMethods
# Checks if all hosts are up
def all_hosts_up?(hosts)
hosts.each do |host|
- return false unless status_data['hosts'][host]['current_state'] == 0
+ return false unless
+ status_data['hosts'].has_key?(host) and
+ status_data['hosts'][host]['current_state'] == 0
end
true
end
def host_up?(host)
+ status_data['hosts'].has_key?(host) and
status_data['hosts'][host]['current_state'] == 0
end
def host_flapping?(host)
+ status_data['hosts'].has_key?(host) and
status_data['hosts'][host]['is_flapping'] != 0
end
# Checks if the service is up
def service_up?(host, service)
+ status_data['services'].has_key?(host) and
+ status_data['services'][host].has_key?(service) and
status_data['services'][host][service]['current_state'] == 0
end
def service_flapping?(host, service)
+ status_data['services'].has_key?(host) and
+ status_data['services'][host].has_key?(service) and
status_data['services'][host][service]['is_flapping'] != 0
end