Skip to content

Commit

Permalink
Merge pull request #1161 from splunk/fix-select-alts
Browse files Browse the repository at this point in the history
fix(dests): Correct Filter alt support for multiple alt
  • Loading branch information
Ryan Faircloth authored May 19, 2021
2 parents 370a6bb + 09b4338 commit 2c2ccc4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ log{
# Output
# ("${.dest_key}" eq "SPECTRACOM_XXX" and filter(f_is_rfc3dfsfs) )

("${.dest_key}" eq "{{ filters[0][0] }}" and filter({{ filters[0][1] }}) )
{%- for i in range(1, fcount ) %}
or ("${.dest_key}" eq "{{ filters[i][0] }}" and filter({{ filters[i][1] }}) )
{%- endfor %}
"${.dest_key}" eq "{{ dest_key }}"

};
destination({{ destination }});
{%- for f in filters %}
log {
filter({{ f }})
{%- for destination in filters[f] %}
destination({{ destination }});
{%- endfor %}
};
{%- endfor %}
flags(catchall,flow-control, final);
};
41 changes: 22 additions & 19 deletions package/etc/conf.d/sc4slib/lp_dest_filtered_alts_select/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,30 @@
templateEnv = jinja2.Environment(loader=templateLoader)
tm = templateEnv.get_template("plugin.jinja")

routes = {}
filters = {}

for var in os.environ:
routes = {}
filters = {}
if var.startswith("SC4S_DEST_") and var.endswith("_FILTERED_ALTERNATES"):
dest_key = var.replace("SC4S_DEST_", "").replace("_FILTERED_ALTERNATES", "")
dest_key_dests = os.environ[var].split(",")

dest_filters = os.getenv(
f"SC4S_DEST_{ dest_key }_ALT_FILTER", "f_is_nevermatch"
).split(",")
# create a list of all the dests
for dd in dest_key_dests:
if not dd in routes.keys():
routes[dd] = {}

if not dest_key in routes[dd].keys():
routes[dd][dest_key] = os.getenv(
f"SC4S_DEST_{ dest_key }_ALT_FILTER", "f_is_nevermatch"
)

for d in routes.keys():
filter_list = []
for df in routes[d]:
filter_list.append([df, routes[d][df]])

msg = tm.render(destination=d, filters=filter_list, fcount=len(filter_list))
print(msg)
pairs = []
filters = {}
for i in range(0, len(dest_key_dests)):
d = dest_key_dests[i]
# dest_key_dests[i]
if len(dest_filters) == 1:
f = dest_filters[0]
else:
f = dest_filters[i]

if f in filters.keys():
filters[f].append(d)
else:
filters[f] = [d]
msg = tm.render(dest_key=dest_key, filters=filters)
print(msg)

0 comments on commit 2c2ccc4

Please sign in to comment.