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 (limited to '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