From 40231b39564a0c508e2df5adcbd662ed035bffe5 Mon Sep 17 00:00:00 2001 From: Dan Geist Date: Wed, 5 Sep 2018 12:58:54 -0400 Subject: [PATCH 1/2] Updates to allow the use of alternate binary names --- etc/telegraf.conf | 2 ++ plugins/inputs/iptables/README.md | 2 ++ plugins/inputs/iptables/iptables.go | 11 ++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/etc/telegraf.conf b/etc/telegraf.conf index 9315aa457dba7..11842e7e1f72f 100644 --- a/etc/telegraf.conf +++ b/etc/telegraf.conf @@ -2004,6 +2004,8 @@ # ## Setting 'use_lock' to true runs iptables with the "-w" option. # ## Adjust your sudo settings appropriately if using this option ("iptables -wnvl") # use_lock = false +# ## Define an alternate executable, such as "ip6tables". Default is "iptables". +# # binary = "ip6tables" # ## defines the table to monitor: # table = "filter" # ## defines the chains to monitor. diff --git a/plugins/inputs/iptables/README.md b/plugins/inputs/iptables/README.md index 527723f09c228..03bf784e67571 100644 --- a/plugins/inputs/iptables/README.md +++ b/plugins/inputs/iptables/README.md @@ -45,6 +45,8 @@ Defining multiple instances of this plugin in telegraf.conf can lead to concurre use_sudo = false # run iptables with the lock option use_lock = false + # Define an alternate executable, such as "ip6tables". Default is "iptables". + # binary = "ip6tables" # defines the table to monitor: table = "filter" # defines the chains to monitor: diff --git a/plugins/inputs/iptables/iptables.go b/plugins/inputs/iptables/iptables.go index 01041fcc17ae3..9b33049f288d2 100644 --- a/plugins/inputs/iptables/iptables.go +++ b/plugins/inputs/iptables/iptables.go @@ -17,6 +17,7 @@ import ( type Iptables struct { UseSudo bool UseLock bool + Binary string Table string Chains []string lister chainLister @@ -38,6 +39,8 @@ func (ipt *Iptables) SampleConfig() string { ## Setting 'use_lock' to true runs iptables with the "-w" option. ## Adjust your sudo settings appropriately if using this option ("iptables -wnvl") use_lock = false + ## Define an alternate executable, such as "ip6tables". Default is "iptables". + # binary = "ip6tables" ## defines the table to monitor: table = "filter" ## defines the chains to monitor. @@ -70,7 +73,13 @@ func (ipt *Iptables) Gather(acc telegraf.Accumulator) error { } func (ipt *Iptables) chainList(table, chain string) (string, error) { - iptablePath, err := exec.LookPath("iptables") + var binary string + if ipt.Binary != "" { + binary = ipt.Binary + } else { + binary = "iptables" + } + iptablePath, err := exec.LookPath(binary) if err != nil { return "", err } From 6d1f8ac5e0190c216ae8739b6d6a66f55f2ce07a Mon Sep 17 00:00:00 2001 From: Dan Geist Date: Wed, 12 Sep 2018 09:19:15 -0400 Subject: [PATCH 2/2] Added capability for alternate binaries (i.e. ip6tables) --- plugins/inputs/iptables/iptables.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inputs/iptables/iptables.go b/plugins/inputs/iptables/iptables.go index 9b33049f288d2..21f6642a939ac 100644 --- a/plugins/inputs/iptables/iptables.go +++ b/plugins/inputs/iptables/iptables.go @@ -17,7 +17,7 @@ import ( type Iptables struct { UseSudo bool UseLock bool - Binary string + Binary string Table string Chains []string lister chainLister