Skip to content
This repository was archived by the owner on Sep 25, 2019. It is now read-only.

Commit 75b431a

Browse files
ldep30mlinde201
authored andcommitted
Add lock option to the IPtables input plugin (influxdata#2201)
* Update README.md * Add lock support to the IPtables input plugin * Update iptables.go Doc cleaning
1 parent cc32d4d commit 75b431a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

plugins/inputs/iptables/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@ You may edit your sudo configuration with the following:
3030
telegraf ALL=(root) NOPASSWD: /usr/bin/iptables -nvL *
3131
```
3232

33+
### Using IPtables lock feature
34+
35+
Defining multiple instances of this plugin in telegraf.conf can lead to concurrent IPtables access resulting in "ERROR in input [inputs.iptables]: exit status 4" messages in telegraf.log and missing metrics. Setting 'use_lock = true' in the plugin configuration will run IPtables with the '-w' switch, allowing a lock usage to prevent this error.
36+
3337
### Configuration:
3438

3539
```toml
3640
# use sudo to run iptables
3741
use_sudo = false
42+
# run iptables with the lock option
43+
use_lock = false
3844
# defines the table to monitor:
3945
table = "filter"
4046
# defines the chains to monitor:

plugins/inputs/iptables/iptables.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
// Iptables is a telegraf plugin to gather packets and bytes throughput from Linux's iptables packet filter.
1717
type Iptables struct {
1818
UseSudo bool
19+
UseLock bool
1920
Table string
2021
Chains []string
2122
lister chainLister
@@ -32,8 +33,11 @@ func (ipt *Iptables) SampleConfig() string {
3233
## iptables require root access on most systems.
3334
## Setting 'use_sudo' to true will make use of sudo to run iptables.
3435
## Users must configure sudo to allow telegraf user to run iptables with no password.
35-
## iptables can be restricted to only list command "iptables -nvL"
36+
## iptables can be restricted to only list command "iptables -nvL"
3637
use_sudo = false
38+
## Setting 'use_lock' to true runs iptables with the "-w" option.
39+
## Adjust your sudo settings appropriately if using this option ("iptables -wnvl")
40+
use_lock = false
3741
## defines the table to monitor:
3842
table = "filter"
3943
## defines the chains to monitor:
@@ -75,7 +79,11 @@ func (ipt *Iptables) chainList(table, chain string) (string, error) {
7579
name = "sudo"
7680
args = append(args, iptablePath)
7781
}
78-
args = append(args, "-nvL", chain, "-t", table, "-x")
82+
iptablesBaseArgs := "-nvL"
83+
if ipt.UseLock {
84+
iptablesBaseArgs = "-wnvL"
85+
}
86+
args = append(args, iptablesBaseArgs, chain, "-t", table, "-x")
7987
c := exec.Command(name, args...)
8088
out, err := c.Output()
8189
return string(out), err

0 commit comments

Comments
 (0)