Adding upstream version 1.34.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e393c3af3f
commit
4978089aab
4963 changed files with 677545 additions and 0 deletions
116
plugins/inputs/opensmtpd/README.md
Normal file
116
plugins/inputs/opensmtpd/README.md
Normal file
|
@ -0,0 +1,116 @@
|
|||
# OpenSMTPD Input Plugin
|
||||
|
||||
This plugin gathers stats from [OpenSMTPD - a FREE implementation of the
|
||||
server-side SMTP protocol](https://www.opensmtpd.org/)
|
||||
|
||||
## Global configuration options <!-- @/docs/includes/plugin_config.md -->
|
||||
|
||||
In addition to the plugin-specific configuration settings, plugins support
|
||||
additional global and plugin configuration settings. These settings are used to
|
||||
modify metrics, tags, and field or create aliases and configure ordering, etc.
|
||||
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||
|
||||
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins
|
||||
|
||||
## Configuration
|
||||
|
||||
```toml @sample.conf
|
||||
# A plugin to collect stats from Opensmtpd - a validating, recursive, and caching DNS resolver
|
||||
[[inputs.opensmtpd]]
|
||||
## If running as a restricted user you can prepend sudo for additional access:
|
||||
#use_sudo = false
|
||||
|
||||
## The default location of the smtpctl binary can be overridden with:
|
||||
binary = "/usr/sbin/smtpctl"
|
||||
|
||||
# The default timeout of 1s can be overridden with:
|
||||
#timeout = "1s"
|
||||
```
|
||||
|
||||
## Metrics
|
||||
|
||||
This is the full list of stats provided by smtpctl and potentially collected by
|
||||
telegram depending of your smtpctl configuration.
|
||||
|
||||
- smtpctl
|
||||
bounce_envelope
|
||||
bounce_message
|
||||
bounce_session
|
||||
control_session
|
||||
mda_envelope
|
||||
mda_pending
|
||||
mda_running
|
||||
mda_user
|
||||
mta_connector
|
||||
mta_domain
|
||||
mta_envelope
|
||||
mta_host
|
||||
mta_relay
|
||||
mta_route
|
||||
mta_session
|
||||
mta_source
|
||||
mta_task
|
||||
mta_task_running
|
||||
queue_bounce
|
||||
queue_evpcache_load_hit
|
||||
queue_evpcache_size
|
||||
queue_evpcache_update_hit
|
||||
scheduler_delivery_ok
|
||||
scheduler_delivery_permfail
|
||||
scheduler_delivery_tempfail
|
||||
scheduler_envelope
|
||||
scheduler_envelope_expired
|
||||
scheduler_envelope_incoming
|
||||
scheduler_envelope_inflight
|
||||
scheduler_ramqueue_envelope
|
||||
scheduler_ramqueue_message
|
||||
scheduler_ramqueue_update
|
||||
smtp_session
|
||||
smtp_session_inet4
|
||||
smtp_session_local
|
||||
uptime
|
||||
|
||||
## Permissions
|
||||
|
||||
It's important to note that this plugin references smtpctl, which may require
|
||||
additional permissions to execute successfully. Depending on the user/group
|
||||
permissions of the telegraf user executing this plugin, you may need to alter
|
||||
the group membership, set facls, or use sudo.
|
||||
|
||||
**Group membership (Recommended)**:
|
||||
|
||||
```bash
|
||||
$ groups telegraf
|
||||
telegraf : telegraf
|
||||
|
||||
$ usermod -a -G opensmtpd telegraf
|
||||
|
||||
$ groups telegraf
|
||||
telegraf : telegraf opensmtpd
|
||||
```
|
||||
|
||||
**Sudo privileges**:
|
||||
If you use this method, you will need the following in your telegraf config:
|
||||
|
||||
```toml
|
||||
[[inputs.opensmtpd]]
|
||||
use_sudo = true
|
||||
```
|
||||
|
||||
You will also need to update your sudoers file:
|
||||
|
||||
```bash
|
||||
$ visudo
|
||||
# Add the following line:
|
||||
Cmnd_Alias SMTPCTL = /usr/sbin/smtpctl
|
||||
telegraf ALL=(ALL) NOPASSWD: SMTPCTL
|
||||
Defaults!SMTPCTL !logfile, !syslog, !pam_session
|
||||
```
|
||||
|
||||
Please use the solution you see as most appropriate.
|
||||
|
||||
## Example Output
|
||||
|
||||
```text
|
||||
opensmtpd,host=localhost scheduler_delivery_tempfail=822,mta_host=10,mta_task_running=4,queue_bounce=13017,scheduler_delivery_permfail=51022,mta_relay=7,queue_evpcache_size=2,scheduler_envelope_expired=26,bounce_message=0,mta_domain=7,queue_evpcache_update_hit=848,smtp_session_local=12294,bounce_envelope=0,queue_evpcache_load_hit=4389703,scheduler_ramqueue_update=0,mta_route=3,scheduler_delivery_ok=2149489,smtp_session_inet4=2131997,control_session=1,scheduler_envelope_incoming=0,uptime=10346728,scheduler_ramqueue_envelope=2,smtp_session=0,bounce_session=0,mta_envelope=2,mta_session=6,mta_task=2,scheduler_ramqueue_message=2,mta_connector=7,mta_source=1,scheduler_envelope=2,scheduler_envelope_inflight=2 1510220300000000000
|
||||
```
|
121
plugins/inputs/opensmtpd/opensmtpd.go
Normal file
121
plugins/inputs/opensmtpd/opensmtpd.go
Normal file
|
@ -0,0 +1,121 @@
|
|||
//go:generate ../../../tools/readme_config_includer/generator
|
||||
package opensmtpd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/config"
|
||||
"github.com/influxdata/telegraf/filter"
|
||||
"github.com/influxdata/telegraf/internal"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
)
|
||||
|
||||
//go:embed sample.conf
|
||||
var sampleConfig string
|
||||
|
||||
var (
|
||||
defaultBinary = "/usr/sbin/smtpctl"
|
||||
defaultTimeout = config.Duration(time.Second)
|
||||
)
|
||||
|
||||
type Opensmtpd struct {
|
||||
Binary string `toml:"binary"`
|
||||
Timeout config.Duration `toml:"timeout"`
|
||||
UseSudo bool `toml:"use_sudo"`
|
||||
|
||||
run runner
|
||||
}
|
||||
|
||||
type runner func(cmdName string, timeout config.Duration, useSudo bool) (*bytes.Buffer, error)
|
||||
|
||||
func (*Opensmtpd) SampleConfig() string {
|
||||
return sampleConfig
|
||||
}
|
||||
|
||||
func (s *Opensmtpd) Gather(acc telegraf.Accumulator) error {
|
||||
// All the dots in stat name will be replaced by underscores.
|
||||
// Histogram statistics will not be collected.
|
||||
|
||||
// Always exclude uptime.human statistics
|
||||
statExcluded := []string{"uptime.human"}
|
||||
filterExcluded, err := filter.Compile(statExcluded)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
out, err := s.run(s.Binary, s.Timeout, s.UseSudo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error gathering metrics: %w", err)
|
||||
}
|
||||
|
||||
// Process values
|
||||
fields := make(map[string]interface{})
|
||||
scanner := bufio.NewScanner(out)
|
||||
for scanner.Scan() {
|
||||
cols := strings.Split(scanner.Text(), "=")
|
||||
|
||||
// Check split correctness
|
||||
if len(cols) != 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
stat := cols[0]
|
||||
value := cols[1]
|
||||
|
||||
// Filter value
|
||||
if filterExcluded.Match(stat) {
|
||||
continue
|
||||
}
|
||||
|
||||
field := strings.ReplaceAll(stat, ".", "_")
|
||||
|
||||
fields[field], err = strconv.ParseFloat(value, 64)
|
||||
if err != nil {
|
||||
acc.AddError(fmt.Errorf("expected a numerical value for %s = %v", stat, value))
|
||||
}
|
||||
}
|
||||
|
||||
acc.AddFields("opensmtpd", fields, nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Shell out to opensmtpd_stat and return the output
|
||||
func opensmtpdRunner(cmdName string, timeout config.Duration, useSudo bool) (*bytes.Buffer, error) {
|
||||
cmdArgs := []string{"show", "stats"}
|
||||
|
||||
cmd := exec.Command(cmdName, cmdArgs...)
|
||||
|
||||
if useSudo {
|
||||
cmdArgs = append([]string{cmdName}, cmdArgs...)
|
||||
cmd = exec.Command("sudo", cmdArgs...)
|
||||
}
|
||||
|
||||
var out bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
err := internal.RunTimeout(cmd, time.Duration(timeout))
|
||||
if err != nil {
|
||||
return &out, fmt.Errorf("error running smtpctl: %w", err)
|
||||
}
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
inputs.Add("opensmtpd", func() telegraf.Input {
|
||||
return &Opensmtpd{
|
||||
run: opensmtpdRunner,
|
||||
Binary: defaultBinary,
|
||||
Timeout: defaultTimeout,
|
||||
UseSudo: false,
|
||||
}
|
||||
})
|
||||
}
|
109
plugins/inputs/opensmtpd/opensmtpd_test.go
Normal file
109
plugins/inputs/opensmtpd/opensmtpd_test.go
Normal file
|
@ -0,0 +1,109 @@
|
|||
package opensmtpd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf/config"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
)
|
||||
|
||||
func smtpCTL(output string) func(string, config.Duration, bool) (*bytes.Buffer, error) {
|
||||
return func(string, config.Duration, bool) (*bytes.Buffer, error) {
|
||||
return bytes.NewBufferString(output), nil
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterSomeStats(t *testing.T) {
|
||||
acc := &testutil.Accumulator{}
|
||||
v := &Opensmtpd{
|
||||
run: smtpCTL(fullOutput),
|
||||
}
|
||||
err := v.Gather(acc)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.True(t, acc.HasMeasurement("opensmtpd"))
|
||||
require.Equal(t, uint64(1), acc.NMetrics())
|
||||
|
||||
require.Equal(t, 36, acc.NFields())
|
||||
acc.AssertContainsFields(t, "opensmtpd", parsedFullOutput)
|
||||
}
|
||||
|
||||
var parsedFullOutput = map[string]interface{}{
|
||||
"bounce_envelope": float64(0),
|
||||
"bounce_message": float64(0),
|
||||
"bounce_session": float64(0),
|
||||
"control_session": float64(1),
|
||||
"mda_envelope": float64(0),
|
||||
"mda_pending": float64(0),
|
||||
"mda_running": float64(0),
|
||||
"mda_user": float64(0),
|
||||
"mta_connector": float64(1),
|
||||
"mta_domain": float64(1),
|
||||
"mta_envelope": float64(0),
|
||||
"mta_host": float64(6),
|
||||
"mta_relay": float64(1),
|
||||
"mta_route": float64(1),
|
||||
"mta_session": float64(1),
|
||||
"mta_source": float64(1),
|
||||
"mta_task": float64(0),
|
||||
"mta_task_running": float64(5),
|
||||
"queue_bounce": float64(11495),
|
||||
"queue_evpcache_load_hit": float64(3927539),
|
||||
"queue_evpcache_size": float64(0),
|
||||
"queue_evpcache_update_hit": float64(508),
|
||||
"scheduler_delivery_ok": float64(1922951),
|
||||
"scheduler_delivery_permfail": float64(45967),
|
||||
"scheduler_delivery_tempfail": float64(493),
|
||||
"scheduler_envelope": float64(0),
|
||||
"scheduler_envelope_expired": float64(17),
|
||||
"scheduler_envelope_incoming": float64(0),
|
||||
"scheduler_envelope_inflight": float64(0),
|
||||
"scheduler_ramqueue_envelope": float64(0),
|
||||
"scheduler_ramqueue_message": float64(0),
|
||||
"scheduler_ramqueue_update": float64(0),
|
||||
"smtp_session": float64(0),
|
||||
"smtp_session_inet4": float64(1903412),
|
||||
"smtp_session_local": float64(10827),
|
||||
"uptime": float64(9253995),
|
||||
}
|
||||
|
||||
var fullOutput = `bounce.envelope=0
|
||||
bounce.message=0
|
||||
bounce.session=0
|
||||
control.session=1
|
||||
mda.envelope=0
|
||||
mda.pending=0
|
||||
mda.running=0
|
||||
mda.user=0
|
||||
mta.connector=1
|
||||
mta.domain=1
|
||||
mta.envelope=0
|
||||
mta.host=6
|
||||
mta.relay=1
|
||||
mta.route=1
|
||||
mta.session=1
|
||||
mta.source=1
|
||||
mta.task=0
|
||||
mta.task.running=5
|
||||
queue.bounce=11495
|
||||
queue.evpcache.load.hit=3927539
|
||||
queue.evpcache.size=0
|
||||
queue.evpcache.update.hit=508
|
||||
scheduler.delivery.ok=1922951
|
||||
scheduler.delivery.permfail=45967
|
||||
scheduler.delivery.tempfail=493
|
||||
scheduler.envelope=0
|
||||
scheduler.envelope.expired=17
|
||||
scheduler.envelope.incoming=0
|
||||
scheduler.envelope.inflight=0
|
||||
scheduler.ramqueue.envelope=0
|
||||
scheduler.ramqueue.message=0
|
||||
scheduler.ramqueue.update=0
|
||||
smtp.session=0
|
||||
smtp.session.inet4=1903412
|
||||
smtp.session.local=10827
|
||||
uptime=9253995
|
||||
uptime.human=107d2h33m15s`
|
10
plugins/inputs/opensmtpd/sample.conf
Normal file
10
plugins/inputs/opensmtpd/sample.conf
Normal file
|
@ -0,0 +1,10 @@
|
|||
# A plugin to collect stats from Opensmtpd - a validating, recursive, and caching DNS resolver
|
||||
[[inputs.opensmtpd]]
|
||||
## If running as a restricted user you can prepend sudo for additional access:
|
||||
#use_sudo = false
|
||||
|
||||
## The default location of the smtpctl binary can be overridden with:
|
||||
binary = "/usr/sbin/smtpctl"
|
||||
|
||||
# The default timeout of 1s can be overridden with:
|
||||
#timeout = "1s"
|
Loading…
Add table
Add a link
Reference in a new issue