Created
May 27, 2014 15:40
-
-
Save pablobm/30cfe041224740182005 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pp' | |
def substitute_command_tokens(check) | |
unmatched_tokens = Array.new | |
substituted = check[:command].gsub(/:::([^:]*?):::/) do | |
token, default = $1.to_s.split('|', -1) | |
matched = token.split('.').inject(@settings[:client]) do |client, attribute| | |
if client[attribute].nil? | |
default.nil? ? break : default | |
else | |
client[attribute] | |
end | |
end | |
pp matched | |
if matched.nil? | |
unmatched_tokens << token | |
end | |
matched | |
end | |
[substituted, unmatched_tokens] | |
end | |
check = { | |
command: "PATH=$PATH:/usr/local/nagios/libexec check_activemq -H :::amq.host|localhost-8161|||::: -q mailer.fast -w 5:5 -c 2:5 -C" | |
} | |
@settings = { | |
client: { | |
'amq' => { | |
'host' => 'foobar' | |
} | |
} | |
} | |
pp substitute_command_tokens(check) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment