Last active
August 29, 2015 14:22
-
-
Save neilhwatson/da3176a83d397600bfca to your computer and use it in GitHub Desktop.
merging containers to get a single list
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
body common control | |
{ | |
bundlesequence => { | |
"main", | |
}; | |
} | |
bundle agent main | |
{ | |
methods: | |
"any" usebundle => test1; | |
"any" usebundle => test2; | |
"any" usebundle => test3; | |
} | |
bundle agent test1 | |
{ | |
vars: | |
"ports" | |
data => parsejson( '{ "tcp" : [ "100", "101", "102" ] }' ), | |
meta => { "firewall" }; | |
} | |
bundle agent test2 | |
{ | |
vars: | |
"ports" | |
data => parsejson( '{ "tcp" : [ "200", "201", "202" ] }' ), | |
meta => { "firewall" }; | |
} | |
bundle agent test3 | |
{ | |
vars: | |
"port_lists" | |
comment => "Get list of firewall port lists", | |
slist => variablesmatching( ".*ports", "firewall" ); | |
"port_lists_tcp" | |
slist => maplist("$(this)[tcp]", @(port_lists)); | |
methods: | |
"any" usebundle => cmerge( "all_fw_ports", @{port_lists_tcp} ); | |
reports: | |
"tcp ports => ${cmerge.all_fw_ports}"; | |
"string dump => ${cmerge.all_fw_ports_str}"; | |
} | |
bundle agent cmerge( name, varlist ) | |
{ | |
vars: | |
"$(name)" data => parsejson('[]'), policy => "free"; | |
"$(name)" data => mergedata($(name), $(varlist)), policy => "free"; # iterates! | |
"$(name)_str" string => format("%S", $(name)), policy => "free"; | |
} | |
$ cf-agent -Kf ./ggmpd.cf | |
R: tcp ports => 100 | |
R: tcp ports => 101 | |
R: tcp ports => 102 | |
R: tcp ports => 200 | |
R: tcp ports => 201 | |
R: tcp ports => 202 | |
R: string dump => ["100","101","102","200","201","202"] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment