From 8a24619f05de1f52a65fdd36e7a8a6643a887953 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Thu, 15 Nov 2012 11:17:52 +0000 Subject: Resolve purely numeric alerts --- lib/custodian/alerter.rb | 63 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) (limited to 'lib/custodian/alerter.rb') diff --git a/lib/custodian/alerter.rb b/lib/custodian/alerter.rb index 69de28e..f5caa6a 100644 --- a/lib/custodian/alerter.rb +++ b/lib/custodian/alerter.rb @@ -11,6 +11,10 @@ require 'socket' # # This class encapsulates the raising and clearing of alerts via Mauve. # +# There is a helper method to update any alerts with details of whether the +# affected host is inside/outside the Bytemark network. +# +# class Alerter @@ -67,14 +71,49 @@ class Alerter end + # + # Resolve an IP address + # + def document_address( address ) + + raise ArgumentError, "Address must not be nil" if ( address.nil? ) + + begin + Resolv.new.getname(address) + rescue + nil + end + end + + + # # Raise the alert. # def raise( detail ) + # + # Is this alert affecting a machine inside/outside our network + # inside = expand_inside_bytemark( @details["target_host"] ) + # + # Document the hostname if the alert relates to an IP address. + # + resolved = "" + if ( ( @details["target_host"] =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ ) || + ( @details["target_host"] =~ /^([0-9a-f:]+)$/ ) ) + + resolved = document_address( @details["target_host"] ) + if ( resolved.nil? ) + resolved = "" + else + resolved = "The IP address #{@details["target_host"]} resolves to #{resolved}." + end + end + + update = Mauve::Proto::AlertUpdate.new update.alert = [] update.source = "custodian" @@ -90,7 +129,7 @@ class Alerter alert.subject = @details['target_host'] alert.summary = @details['test_alert'] - alert.detail = "#{inside}

The #{@details['test_type']} test failed against #{@details['target_host']}: #{detail}

" + alert.detail = "#{inside}

The #{@details['test_type']} test failed against #{@details['target_host']}: #{detail}

#{resolved}

" alert.raise_time = Time.now.to_i update.alert << alert @@ -103,8 +142,28 @@ class Alerter # def clear + # + # Is this alert affecting a machine inside/outside our network + # inside = expand_inside_bytemark( @details["target_host"] ) + + # + # Document the hostname if the alert relates to an IP address. + # + resolved = "" + if ( ( @details["target_host"] =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ ) || + ( @details["target_host"] =~ /^([0-9a-f:]+)$/ ) ) + + resolved = document_address( @details["target_host"] ) + if ( resolved.nil? ) + resolved = "" + else + resolved = "The IP address #{@details["target_host"]} resolves to #{resolved}." + end + end + + update = Mauve::Proto::AlertUpdate.new update.alert = [] update.source = "custodian" @@ -121,7 +180,7 @@ class Alerter alert.subject = @details['target_host'] alert.summary = @details['test_alert'] - alert.detail = "#{inside}

The #{@details['test_type']} test succeeded against #{@details['target_host']}

" + alert.detail = "#{inside}

The #{@details['test_type']} test succeeded against #{@details['target_host']}

#{resolved}

" alert.clear_time = Time.now.to_i update.alert << alert -- cgit v1.2.1