Created
June 27, 2012 16:53
-
-
Save ploubser/3005365 to your computer and use it in GitHub Desktop.
Updated Summary plugin
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
Summary of All Collectives: | |
mcollective : 10 | |
subdev2 : 7 | |
subdev1 : 3 |
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
module MCollective | |
class Aggregate | |
class Summary<Base | |
# Before function is run processing | |
def startup_hook | |
@result[:value] = {} | |
@result[:type] = :collection | |
# set default aggregate_format if it is undefined | |
@aggregate_format = "%s : %s" unless @aggregate_format | |
end | |
# Increments the value field if value has been seen before | |
# Else create a new value field | |
def process_result(value, reply) | |
unless value.nil? | |
if value.is_a? Array | |
value.map{|val| add_value(val)} | |
else | |
add_value(value) | |
end | |
end | |
end | |
def add_value(value) | |
if @result[:value].keys.include?(value) | |
@result[:value][value] += 1 | |
else | |
@result[:value][value] = 1 | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment