Skip to content

Commit f3022a0

Browse files
committed
Update docs
1 parent dd33061 commit f3022a0

File tree

6 files changed

+104
-7
lines changed

6 files changed

+104
-7
lines changed

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
./openvpn
2-
dist
1+
/openvpn
2+
/dist

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 InfluxData Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

Makefile

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ GOARM ?= $(shell go env GOARM)
55
.PHONY: all
66
all: openvpn
77

8+
.PHONY: openvpn
89
openvpn:
910
go build ./cmd/openvpn
1011

@@ -17,16 +18,19 @@ dist-all: openvpn-windows-amd64.zip
1718

1819
openvpn-linux-amd64.tar.gz: GOOS := linux
1920
openvpn-linux-amd64.tar.gz: GOARCH := amd64
20-
openvpn-windows-amd64.tar.gz: GOOS := windows
21-
openvpn-windows-amd64.tar.gz: GOARCH := amd64
21+
openvpn-windows-amd64.zip: GOOS := windows
22+
openvpn-windows-amd64.zip: GOARCH := amd64
23+
openvpn-windows-amd64.zip: EXT := .exe
2224
openvpn-%.tar.gz:
2325
mkdir -p "dist/openvpn-$*"
24-
cd "dist/openvpn-$*" && env GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags "-w -s" ../../cmd/openvpn
26+
env GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o "dist/openvpn-$*/openvpn$(EXT)" -ldflags "-w -s" ./cmd/openvpn
27+
cp openvpn.conf "dist/openvpn-$*"
2528
cd dist && tar czf "$@" "openvpn-$*"
2629

2730
openvpn-%.zip:
2831
mkdir -p "dist/openvpn-$*"
29-
cd "dist/openvpn-$*" && env GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags "-w -s" ../../cmd/openvpn
32+
env GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o "dist/openvpn-$*/openvpn$(EXT)" -ldflags "-w -s" ./cmd/openvpn
33+
cp openvpn.conf "dist/openvpn-$*"
3034
cd dist && zip -r "$@" "openvpn-$*"
3135

3236
.PHONY: clean

README.md

+42
Original file line numberDiff line numberDiff line change
@@ -1 +1,43 @@
1+
OpenVPN Plugin for Telegraf execd input
2+
---
13
![](https://github.com/danielnelson/telegraf-execd-plugins/workflows/Build/badge.svg)
4+
5+
6+
## Usage
7+
8+
- Download the [latest release package][release] for your platform.
9+
10+
- Unpack the build to your system:
11+
```sh
12+
mkdir /var/lib/telegraf
13+
chown telegraf:telegraf /var/lib/telegraf
14+
tar xf openvpn-linux-amd64.tar.gz -C /var/lib/telegraf
15+
```
16+
17+
- Edit execd plugin configuration as needed:
18+
```sh
19+
vi /var/lib/telegraf/openvpn-linux-amd64/openvpn.conf
20+
```
21+
22+
- Add to `/etc/telegraf/telegraf.conf` or into file in `/etc/telegraf/telegraf.d`
23+
```toml
24+
[[inputs.execd]]
25+
command = ["/var/lib/telegraf/openvpn-linux-amd64/openvpn --config /var/lib/telegraf/openvpn-linux-amd64/openvpn.conf"]
26+
signal = "STDIN"
27+
```
28+
29+
- Restart or reload Telegraf.
30+
31+
## Development
32+
33+
When updating the plugin the replace directive in `go.mod` will need updated.
34+
35+
Generally it is expected that no tag will exist and the plugin will reside in a branch.
36+
```sh
37+
go mod edit -replace github.com/influxdata/telegraf=github.com/danielnelson/telegraf@openvpn-input
38+
go mod download
39+
go mod tidy
40+
```
41+
42+
43+
[releases]: https://github.com/danielnelson/telegraf-execd-openvpn/releases/latest

cmd/openvpn/main.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,35 @@ import (
55
"fmt"
66
"os"
77

8+
"github.com/influxdata/telegraf"
89
"github.com/influxdata/telegraf/plugins/inputs/execd/shim"
9-
_ "github.com/influxdata/telegraf/plugins/inputs/openvpn"
10+
"github.com/influxdata/telegraf/plugins/inputs/openvpn"
1011
)
1112

1213
var configFile = flag.String("config", "", "path to the config file for this plugin")
14+
var usage = flag.Bool("usage", false, "print sample configuration")
15+
16+
func printConfig(name string, p telegraf.PluginDescriber) {
17+
fmt.Printf("# %s\n", p.Description())
18+
fmt.Printf("[[inputs.%s]]", name)
19+
20+
config := p.SampleConfig()
21+
if config != "" {
22+
fmt.Printf(config)
23+
} else {
24+
fmt.Printf("\n # no configuration\n")
25+
}
26+
}
1327

1428
func main() {
1529
flag.Parse()
1630

31+
if *usage {
32+
printConfig("openvpn", &openvpn.OpenVPN{})
33+
34+
os.Exit(0)
35+
}
36+
1737
shim := shim.New()
1838

1939
err := shim.LoadConfig(configFile)

openvpn.conf

+9
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1+
# Gather status from the OpenVPN management interface
12
[[inputs.openvpn]]
3+
## Address of the management interface
4+
## ex: address = "tcp://example.org:1234"
25
address = "unix:///var/run/openvpn.sock"
6+
7+
## Password to the management interface
8+
# password = ""
9+
10+
## Timeout for connecting and getting status.
11+
# timeout = "5s"

0 commit comments

Comments
 (0)