Skip to content

Commit

Permalink
Allow alternate binaries for iptables input plugin. (influxdata#4682)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeist authored and Jean-Louis Dupond committed Apr 22, 2019
1 parent 7d3f697 commit 35e30a9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions etc/telegraf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions plugins/inputs/iptables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 10 additions & 1 deletion plugins/inputs/iptables/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
type Iptables struct {
UseSudo bool
UseLock bool
Binary string
Table string
Chains []string
lister chainLister
Expand All @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 35e30a9

Please sign in to comment.