From 8a3ec73c09e46ceabede414c2b5aa39b8b6a1bae Mon Sep 17 00:00:00 2001 From: Ben Edery Date: Tue, 11 Aug 2020 11:12:14 +0300 Subject: [PATCH] Added - user.name data to manictime beat --- metricbeat/build.sh | 4 ++-- metricbeat/module/system/manictime/manictime.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/metricbeat/build.sh b/metricbeat/build.sh index a896d5efcb54..e398680fb963 100644 --- a/metricbeat/build.sh +++ b/metricbeat/build.sh @@ -2,5 +2,5 @@ make collect make -go build -o metricbeat_0.0.10 main.go -GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build -o metricbeat_0.0.10.exe main.go +go build -o metricbeat_0.0.11 main.go +GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build -o metricbeat_0.0.11.exe main.go diff --git a/metricbeat/module/system/manictime/manictime.go b/metricbeat/module/system/manictime/manictime.go index 5d71e3ee20da..03198e3e80d1 100644 --- a/metricbeat/module/system/manictime/manictime.go +++ b/metricbeat/module/system/manictime/manictime.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "os" + "os/user" "path/filepath" "strings" "time" @@ -31,6 +32,7 @@ func init() { type MetricSet struct { mb.BaseMetricSet database *sql.DB + userName string } type ManicTimeConfig struct { @@ -88,12 +90,18 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { fmt.Println("could not open db file of manicTime") } + user, err := user.Current() + if err != nil { + fmt.Println("could not get user details", err) + } + // // get last updated time // lastSync = getLastSyncTime(database) return &MetricSet{ BaseMetricSet: base, database: database, + userName: user.Username, }, nil } @@ -122,11 +130,15 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error { "durationMin": activity.durationMin, "durationSec": activity.durationSec, "applicationName": activity.applicationName, + "id": activity.id, } report.Event(mb.Event{ MetricSetFields: common.MapStr{ "data": rootFields, }, + RootFields: common.MapStr{ + "user.name": m.userName, + }, }) }