diff options
| author | Jamie Nguyen <jamie.nguyen@bytemark.co.uk> | 2017-03-16 11:08:45 +0000 | 
|---|---|---|
| committer | Jamie Nguyen <jamie.nguyen@bytemark.co.uk> | 2017-03-16 11:08:45 +0000 | 
| commit | 567d8b3c419a52ccc52f35f37338514c1d8fa623 (patch) | |
| tree | 65f15a764229450aa453ec13416d0d23d5967aa1 /lib/custodian/util | |
| parent | 65216bda8dc4dbda19699ad6ed31bac711161f1a (diff) | |
| parent | 3ed213af376bcb88756a22f2ca1e5c417cd0cefb (diff) | |
Merge branch '7-allow-custom-prefixes' into 'master'
Resolve "Allow subject-lines to be prefixed with a custom string."
See merge request !4
Diffstat (limited to 'lib/custodian/util')
| -rw-r--r-- | lib/custodian/util/prefix.rb | 42 | 
1 files changed, 42 insertions, 0 deletions
| 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 | 
