From 70bd9610a098edf542a63c06d781ec741c8f5aeb Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Thu, 16 Mar 2017 12:12:53 +0200 Subject: Added helper for reading a custom-prefix. This will allow classification (by human eyes) of raised-alerts. --- lib/custodian/util/prefix.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lib/custodian/util/prefix.rb diff --git a/lib/custodian/util/prefix.rb b/lib/custodian/util/prefix.rb new file mode 100644 index 0000000..743a422 --- /dev/null +++ b/lib/custodian/util/prefix.rb @@ -0,0 +1,42 @@ + + +# +# This class allows a custom-prefix to be prepended to any alert +# subjects. +# +module Custodian + + module Util + + class Prefix + + + # + # Return the custom-prefix to use, if any. + # + def Prefix.text() + # Default to no prefix. + default = "" + + # Look for matches - last one wins. + Dir.glob( "/store/clients/*/custodian-prefix.cfg" ).each do |file| + begin + default = File.read( file ) + rescue Errno::EACCES + # Permission-denied. + end + end + + # Remove any newline characters + default.gsub!( /[\r\n]/, '' ) + + # Truncate, if required. + max = 32 + default = default[0...max] if ( default.length > max ) + + default + end + + end + end +end -- cgit v1.2.1 From 836f38bfe4a330b9ab1e917139de81771bcb15a8 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Thu, 16 Mar 2017 12:16:00 +0200 Subject: Use the subject-prefix if it is present. --- lib/custodian/alerts/mauve.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/custodian/alerts/mauve.rb b/lib/custodian/alerts/mauve.rb index be19eec..0aed390 100644 --- a/lib/custodian/alerts/mauve.rb +++ b/lib/custodian/alerts/mauve.rb @@ -2,6 +2,7 @@ require 'custodian/util/bytemark' require 'custodian/util/dns' +require 'custodian/util/prefix' require 'digest/sha1' @@ -223,12 +224,14 @@ module Custodian # Because there might be N-classes which implemented the test # we need to make sure these are distinct too. # - id_key = test.to_s - id_key += test.class.to_s + id_key = test.to_s + id_key += test.class.to_s + alert.id = Digest::SHA1.hexdigest(id_key) - alert.id = Digest::SHA1.hexdigest(id_key) + # Look for a subject-prefix + subject_prefix = Custodian::Util::Prefix.text() - alert.subject = subject + alert.subject = subject_prefix + subject alert.summary = "The #{test_type} test failed against #{test_host}" # -- cgit v1.2.1 From 3ed213af376bcb88756a22f2ca1e5c417cd0cefb Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Thu, 16 Mar 2017 12:17:17 +0200 Subject: Bump changelog --- debian/changelog | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/debian/changelog b/debian/changelog index 06639b0..a875787 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +custodian (0.33) stable; urgency=low + + * Allow an alert's subject to be prefixed with a custom string, read from + /store/clients/*/custodian-prefix.cfg. If multiple files are present + then the last match wins. + + -- Steve Kemp Thu, 16 Mar 2016 12:11:21 +0100 + custodian (0.32) stable; urgency=low * When a TCP-test fails, due to timeout, show the host/port which was -- cgit v1.2.1