Class: OstrichPoll::ConfigParser
- Inherits:
-
Object
- Object
- OstrichPoll::ConfigParser
- Defined in:
- lib/ostrichpoll/config_parser.rb
Overview
traverses a nested hashmap (the parsed config YAML) returning a set of hosts and validators
Class Method Summary collapse
Class Method Details
.parse(map) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ostrichpoll/config_parser.rb', line 7 def self.parse(map) hosts = [] map.each do |host_config| host = Host.new host_config.each do |key,value| case key when 'url' host.url = value when 'rate_file' host.rate_file = value when 'validations' validations = parse_validations(value) validations.each do |v| v.host_instance = host end host.validations = validations else Log.warn "Unknown key: #{key}. Ignoring." end end hosts << host end hosts end |
.parse_validation(name, map) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ostrichpoll/config_parser.rb', line 47 def self.parse_validation(name, map) validator = Validator.new validator.metric = name map.each do |key,value| case key when 'rate' validator.rate = value when 'regex' validator.regex = value when 'normal_range' # FIXME validate normal range (min <= max, etc.) validator.normal_range = value when 'missing' validator.missing = value.to_sym when 'exit_code' validator.exit_code = value when 'exit_message' validator. = value else Log.warn "Unknown key for validation: #{key}. Ignoring." end end validator.verify! validator end |
.parse_validations(validations) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/ostrichpoll/config_parser.rb', line 39 def self.parse_validations(validations) return [] unless validations validations.map do |name, v| self.parse_validation name, v end end |