telegraf/plugins/inputs/dovecot/dovecot_test.go

70 lines
4.1 KiB
Go
Raw Normal View History

2016-02-05 16:58:21 +00:00
package dovecot
import (
"bytes"
"testing"
"time"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"
)
func TestDovecot(t *testing.T) {
2016-02-09 09:57:57 +00:00
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
// Test type=global
2016-02-05 16:58:21 +00:00
var acc testutil.Accumulator
tags := map[string]string{"server": "dovecot.test", "type": "global"}
buf := bytes.NewBufferString(sampleGlobal)
2016-02-05 16:58:21 +00:00
err := gatherStats(buf, &acc, "dovecot.test", "global")
2016-02-05 16:58:21 +00:00
require.NoError(t, err)
fields := map[string]interface{}{
"reset_timestamp": time.Unix(1453969886, 0),
"last_update": time.Unix(1454603963, 39864),
"num_logins": int64(7503897),
"num_cmds": int64(52595715),
"num_connected_sessions": int64(1204),
"user_cpu": 1.00831175372e+08,
"sys_cpu": 8.3849071112e+07,
"clock_time": 4.3260019315281835e+15,
"min_faults": int64(763950011),
"maj_faults": int64(1112443),
"vol_cs": int64(4120386897),
"invol_cs": int64(3685239306),
"disk_input": int64(41679480946688),
"disk_output": int64(1819070669176832),
"read_count": int64(2368906465),
"read_bytes": int64(2957928122981169),
"write_count": int64(3545389615),
"write_bytes": int64(1666822498251286),
"mail_lookup_path": int64(24396105),
"mail_lookup_attr": int64(302845),
"mail_read_count": int64(20155768),
"mail_read_bytes": int64(669946617705),
"mail_cache_hits": int64(1557255080),
}
acc.AssertContainsTaggedFields(t, "dovecot", fields, tags)
}
const sampleGlobal = `reset_timestamp last_update num_logins num_cmds num_connected_sessions user_cpu sys_cpu clock_time min_faults maj_faults vol_cs invol_cs disk_input disk_output read_count read_bytes write_count write_bytes mail_lookup_path mail_lookup_attr mail_read_count mail_read_bytes mail_cache_hits
1453969886 1454603963.039864 7503897 52595715 1204 100831175.372000 83849071.112000 4326001931528183.495762 763950011 1112443 4120386897 3685239306 41679480946688 1819070669176832 2368906465 2957928122981169 3545389615 1666822498251286 24396105 302845 20155768 669946617705 1557255080`
const sampleDomain = `domain reset_timestamp last_update num_logins num_cmds num_connected_sessions user_cpu sys_cpu clock_time min_faults maj_faults vol_cs invol_cs disk_input disk_output read_count read_bytes write_count write_bytes mail_lookup_path mail_lookup_attr mail_read_count mail_read_bytes mail_cache_hits
2016-02-05 16:58:21 +00:00
domain.test 1453969886 1454603963.039864 7503897 52595715 1204 100831175.372000 83849071.112000 4326001931528183.495762 763950011 1112443 4120386897 3685239306 41679480946688 1819070669176832 2368906465 2957928122981169 3545389615 1666822498251286 24396105 302845 20155768 669946617705 1557255080`
const sampleUser = `user reset_timestamp last_update num_logins num_cmds user_cpu sys_cpu clock_time min_faults maj_faults vol_cs invol_cs disk_input disk_output read_count read_bytes write_count write_bytes mail_lookup_path mail_lookup_attr mail_read_count mail_read_bytes mail_cache_hits
user.1@tiscali.it 1460041745 1460041745.258851 2 0 8.868000 6.344000 2920083490.361458 706804 448916 48979 268148736 950759424 632685 1556937725 219865 907305251 0 0 0 0 0
user.2@tiscali.it 1460041657 1460041658.284800 2 0 1.192000 0.660000 2920083316.276633 13873 0 60226 5584 31674368 122347520 78251 207879097 27095 118197529 0 0 0 0 0
user.3@tiscali.it 1460041657 1460041717.175634 1 7 0.0 0.0 0.20 319 0 50 9 61440 1228867 73508 28 3174 0 0 0 0 0`
const sampleIp = `ip reset_timestamp last_update num_logins num_cmds num_connected_sessions user_cpu sys_cpu clock_time min_faults maj_faults vol_cs invol_cs disk_input disk_output read_count read_bytes write_count write_bytes mail_lookup_path mail_lookup_attr mail_read_count mail_read_bytes mail_cache_hits
192.168.0.100 1460041847 1460041847.849766 1 0 0 0.4000 0.0 0.49 449 0 70 3 4096 1228861 45414 24 1606 0 0 0 0 0
192.168.0.201 1460041772 1460041772.737830 1 0 0 0.0 0.0 0.0 0 0 0 0 0 0 00 0 0 0 0 0 0 0`