Skip to content

Instantly share code, notes, and snippets.

@zzamboni
Created August 24, 2010 06:58
Show Gist options
  • Save zzamboni/547095 to your computer and use it in GitHub Desktop.
Save zzamboni/547095 to your computer and use it in GitHub Desktop.
# Find all network interfaces that match a certain IP address.
# Time-stamp: <[netif_find.cf] modified by Diego Zamboni on Tuesday, 2010.08.24 at 01:53:03>
body common control
{
bundlesequence => { "test" };
}
bundle agent test
{
vars:
"nics" slist => getindices("sys.ipv4");
# Regex we want to match on the IP address
"ipregex" string => "192\.168\..*";
# This is heavily based on cfengine3 list expansion. The expression is
# evaluated for every value of ${nics}, and if there are any matches,
# the corresponding class is defined, which then triggers the printing
# of the "Matched NIC" message (of course, in a real example, the class
# could be used to trigger some other action).
classes:
"ismatch_${nics}" expression => regcmp("${ipregex}", "${sys.ipv4[${nics}]}");
reports:
linux|windows::
"NICs found: ${nics}";
"Matched NIC: ${nics} (${sys.ipv4[${nics}]})"
ifvarclass => "ismatch_${nics}";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment