diff --git a/.golangci.yml b/.golangci.yml
index f1e58d8..28aed0f 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -69,9 +69,7 @@ linters:
- wrapcheck
- wsl
# deprecated
- - execinquery
- exportloopref
- - gomnd
issues:
max-same-issues: 0
max-issues-per-linter: 0
diff --git a/pkg/nagflux/collector/SimplePrintable.go b/pkg/nagflux/collector/SimplePrintable.go
index 662cf38..6f31cc1 100644
--- a/pkg/nagflux/collector/SimplePrintable.go
+++ b/pkg/nagflux/collector/SimplePrintable.go
@@ -10,7 +10,7 @@ type SimplePrintable struct {
}
// PrintForInfluxDB generates an String for InfluxDB
-func (p SimplePrintable) PrintForInfluxDB(_ string) string {
+func (p *SimplePrintable) PrintForInfluxDB(_ string) string {
if p.Datatype == data.InfluxDB {
return p.Text
}
@@ -18,7 +18,7 @@ func (p SimplePrintable) PrintForInfluxDB(_ string) string {
}
// PrintForElasticsearch generates an String for Elasticsearch
-func (p SimplePrintable) PrintForElasticsearch(_, _ string) string {
+func (p *SimplePrintable) PrintForElasticsearch(_, _ string) string {
if p.Datatype == data.Elasticsearch {
return p.Text
}
diff --git a/pkg/nagflux/collector/livestatus/Collector.go b/pkg/nagflux/collector/livestatus/Collector.go
index dca0c0f..8460121 100644
--- a/pkg/nagflux/collector/livestatus/Collector.go
+++ b/pkg/nagflux/collector/livestatus/Collector.go
@@ -115,7 +115,7 @@ func (live *Collector) Stop() {
}
// Loop which checks livestats for data or waits to quit.
-func (live Collector) run() {
+func (live *Collector) run() {
live.queryData()
for {
select {
@@ -129,7 +129,7 @@ func (live Collector) run() {
}
// Queries livestatus and returns the data to the gobal queue
-func (live Collector) queryData() {
+func (live *Collector) queryData() {
printables := make(chan collector.Printable)
finished := make(chan bool)
go live.requestPrintablesFromLivestatus(live.logQuery, true, printables, finished)
@@ -150,7 +150,7 @@ func (live Collector) queryData() {
}
}
-func (live Collector) requestPrintablesFromLivestatus(query string, addTimestampToQuery bool, printables chan collector.Printable, outerFinish chan bool) {
+func (live *Collector) requestPrintablesFromLivestatus(query string, addTimestampToQuery bool, printables chan collector.Printable, outerFinish chan bool) {
queryWithTimestamp := query
if addTimestampToQuery {
queryWithTimestamp = addTimestampToLivestatusQuery(query)
@@ -174,19 +174,19 @@ func (live Collector) requestPrintablesFromLivestatus(query string, addTimestamp
}
case QueryForComments:
if len(line) == 6 {
- printables <- CommentData{collector.AllFilterable, Data{line[0], line[1], line[2], line[3], line[4]}, line[5]}
+ printables <- &CommentData{collector.AllFilterable, Data{line[0], line[1], line[2], line[3], line[4]}, line[5]}
} else {
live.log.Warn("QueryForComments out of range", line)
}
case QueryForDowntimes:
if len(line) == 6 {
- printables <- DowntimeData{collector.AllFilterable, Data{line[0], line[1], line[2], line[3], line[4]}, line[5]}
+ printables <- &DowntimeData{collector.AllFilterable, Data{line[0], line[1], line[2], line[3], line[4]}, line[5]}
} else {
live.log.Warn("QueryForDowntimes out of range", line)
}
case QueryLivestatusVersion:
if len(line) == 1 {
- printables <- collector.SimplePrintable{Filterable: collector.AllFilterable, Text: line[0], Datatype: data.InfluxDB}
+ printables <- &collector.SimplePrintable{Filterable: collector.AllFilterable, Text: line[0], Datatype: data.InfluxDB}
} else {
live.log.Warn("QueryLivestatusVersion out of range", line)
}
@@ -206,7 +206,7 @@ func addTimestampToLivestatusQuery(query string) string {
return fmt.Sprintf(query, time.Now().Add(intervalToCheckLivestatus/100*-150).Unix())
}
-func (live Collector) handleQueryForNotifications(line []string) *NotificationData {
+func (live *Collector) handleQueryForNotifications(line []string) *NotificationData {
switch line[0] {
case "HOST NOTIFICATION":
if len(line) == 10 {
diff --git a/pkg/nagflux/collector/livestatus/CommentData.go b/pkg/nagflux/collector/livestatus/CommentData.go
index 1420b27..66c015f 100644
--- a/pkg/nagflux/collector/livestatus/CommentData.go
+++ b/pkg/nagflux/collector/livestatus/CommentData.go
@@ -19,9 +19,9 @@ func (comment *CommentData) sanitizeValues() {
}
// PrintForInfluxDB prints the data in influxdb lineformat
-func (comment CommentData) PrintForInfluxDB(version string) string {
- comment.sanitizeValues()
+func (comment *CommentData) PrintForInfluxDB(version string) string {
if helper.VersionOrdinal(version) >= helper.VersionOrdinal("0.9") {
+ comment.sanitizeValues()
var tags string
if text := commentIDToText(comment.entryType); text != "" {
tags = ",type=" + text
@@ -33,7 +33,7 @@ func (comment CommentData) PrintForInfluxDB(version string) string {
}
// PrintForElasticsearch prints in the elasticsearch json format
-func (comment CommentData) PrintForElasticsearch(version, index string) string {
+func (comment *CommentData) PrintForElasticsearch(version, index string) string {
if helper.VersionOrdinal(version) >= helper.VersionOrdinal("2.0") {
typ := commentIDToText(comment.entryType)
return comment.genElasticLineWithValue(index, typ, comment.comment, comment.entryTime)
diff --git a/pkg/nagflux/collector/livestatus/Connector.go b/pkg/nagflux/collector/livestatus/Connector.go
index 2ad74ce..870b055 100644
--- a/pkg/nagflux/collector/livestatus/Connector.go
+++ b/pkg/nagflux/collector/livestatus/Connector.go
@@ -19,7 +19,7 @@ type Connector struct {
}
// Queries livestatus and returns an list of list outer list are lines inner elements within the line.
-func (connector Connector) connectToLivestatus(query string, result chan []string, outerFinish chan bool) {
+func (connector *Connector) connectToLivestatus(query string, result chan []string, outerFinish chan bool) {
var conn net.Conn
switch connector.ConnectionType {
case "tcp":
diff --git a/pkg/nagflux/collector/livestatus/Data.go b/pkg/nagflux/collector/livestatus/Data.go
index 211bc40..244c651 100644
--- a/pkg/nagflux/collector/livestatus/Data.go
+++ b/pkg/nagflux/collector/livestatus/Data.go
@@ -26,7 +26,7 @@ func (live *Data) sanitizeValues() {
}
// Generates the Influxdb tablename.
-func (live Data) getTablename() string {
+func (live *Data) getTablename() string {
if live.serviceDisplayName == "" {
live.serviceDisplayName = config.GetConfig().InfluxDBGlobal.HostcheckAlias
}
@@ -34,17 +34,17 @@ func (live Data) getTablename() string {
}
// Generates the linedata which can be parsed from influxdb
-func (live Data) genInfluxLine(tags string) string {
+func (live *Data) genInfluxLine(tags string) string {
return live.genInfluxLineWithValue(tags, live.comment)
}
// Generates the linedata which can be parsed from influxdb
-func (live Data) genInfluxLineWithValue(tags, text string) string {
+func (live *Data) genInfluxLineWithValue(tags, text string) string {
tags += ",author=" + live.author
return fmt.Sprintf("%s%s message=\"%s\" %s", live.getTablename(), tags, text, helper.CastStringTimeFromSToMs(live.entryTime))
}
-func (live Data) genElasticLineWithValue(index, typ, value, timestamp string) string {
+func (live *Data) genElasticLineWithValue(index, typ, value, timestamp string) string {
value = strings.Replace(value, `"`, `\"`, -1)
if live.serviceDisplayName == "" {
live.serviceDisplayName = config.GetConfig().ElasticsearchGlobal.HostcheckAlias
diff --git a/pkg/nagflux/collector/livestatus/DowntimeData.go b/pkg/nagflux/collector/livestatus/DowntimeData.go
index a42d913..319a6a1 100644
--- a/pkg/nagflux/collector/livestatus/DowntimeData.go
+++ b/pkg/nagflux/collector/livestatus/DowntimeData.go
@@ -22,20 +22,20 @@ func (downtime *DowntimeData) sanitizeValues() {
}
// PrintForInfluxDB prints the data in influxdb lineformat
-func (downtime DowntimeData) PrintForInfluxDB(version string) string {
- downtime.sanitizeValues()
+func (downtime *DowntimeData) PrintForInfluxDB(version string) string {
if helper.VersionOrdinal(version) >= helper.VersionOrdinal("0.9") {
+ downtime.sanitizeValues()
tags := ",type=downtime,author=" + downtime.author
start := fmt.Sprintf("%s%s message=\"%s\" %s", downtime.getTablename(), tags, strings.TrimSpace("Downtime start:
"+downtime.comment), helper.CastStringTimeFromSToMs(downtime.entryTime))
end := fmt.Sprintf("%s%s message=\"%s\" %s", downtime.getTablename(), tags, strings.TrimSpace("Downtime end:
"+downtime.comment), helper.CastStringTimeFromSToMs(downtime.endTime))
return start + "\n" + end
}
logging.GetLogger().Criticalf("This influxversion [%s] given in the config is not supported", version)
- panic("")
+ panic("influxdb version not supported")
}
// PrintForElasticsearch prints in the elasticsearch json format
-func (downtime DowntimeData) PrintForElasticsearch(version, index string) string {
+func (downtime *DowntimeData) PrintForElasticsearch(version, index string) string {
if helper.VersionOrdinal(version) >= helper.VersionOrdinal("2.0") {
typ := `downtime`
start := downtime.genElasticLineWithValue(index, typ, strings.TrimSpace("Downtime start:
"+downtime.comment), downtime.entryTime)
@@ -43,5 +43,5 @@ func (downtime DowntimeData) PrintForElasticsearch(version, index string) string
return start + "\n" + end
}
logging.GetLogger().Criticalf("This elasticsearchversion [%s] given in the config is not supported", version)
- panic("")
+ panic("elasticsearch version not supported")
}
diff --git a/pkg/nagflux/collector/livestatus/DowntimeData_test.go b/pkg/nagflux/collector/livestatus/DowntimeData_test.go
index 7732909..8596d59 100644
--- a/pkg/nagflux/collector/livestatus/DowntimeData_test.go
+++ b/pkg/nagflux/collector/livestatus/DowntimeData_test.go
@@ -5,20 +5,20 @@ import (
"pkg/nagflux/config"
"pkg/nagflux/logging"
+
+ "github.com/stretchr/testify/assert"
)
func TestSanitizeValuesDowntime(t *testing.T) {
t.Parallel()
- down := DowntimeData{Data: Data{hostName: "host 1", serviceDisplayName: "service 1", author: "philip"}, endTime: "123"}
+ down := &DowntimeData{Data: Data{hostName: "host 1", serviceDisplayName: "service 1", author: "philip"}, endTime: "123"}
down.sanitizeValues()
- if down.Data.hostName != `host\ 1` {
- t.Errorf("The notificationType should be escaped. Expected: %s Got: %s", `host\ 1`, down.Data.hostName)
- }
+ assert.Equalf(t, `host\ 1`, down.Data.hostName, "The notificationType should be escaped.")
}
func TestPrintInfluxdbDowntime(t *testing.T) {
logging.InitTestLogger()
- down := DowntimeData{Data: Data{hostName: "host 1", serviceDisplayName: "service 1", author: "philip"}, endTime: "123"}
+ down := &DowntimeData{Data: Data{hostName: "host 1", serviceDisplayName: "service 1", author: "philip"}, endTime: "123"}
if !didThisPanic(down.PrintForInfluxDB, "0.8") {
t.Errorf("This should panic, due to unsuported influxdb version")
}
@@ -26,15 +26,13 @@ func TestPrintInfluxdbDowntime(t *testing.T) {
result := down.PrintForInfluxDB("0.9")
expected := `messages,host=host\ 1,service=service\ 1,type=downtime,author=philip message="Downtime start:
" 000
messages,host=host\ 1,service=service\ 1,type=downtime,author=philip message="Downtime end:
" 123000`
- if result != expected {
- t.Errorf("The result did not match the expected. Result:\n%s \nExpected:\n%s", result, expected)
- }
+ assert.Equalf(t, expected, result, "The result did not match the expected")
}
func TestPrintElasticsearchDowntime(t *testing.T) {
logging.InitTestLogger()
config.InitConfigFromString(Config)
- down := DowntimeData{Data: Data{hostName: "host 1", serviceDisplayName: "service 1", author: "philip", entryTime: "1458988932000"}, endTime: "123"}
+ down := &DowntimeData{Data: Data{hostName: "host 1", serviceDisplayName: "service 1", author: "philip", entryTime: "1458988932000"}, endTime: "123"}
if !didThatPanic(down.PrintForElasticsearch, "1.0", "index") {
t.Errorf("This should panic, due to unsuported elasticsearch version")
}
@@ -46,7 +44,5 @@ func TestPrintElasticsearchDowntime(t *testing.T) {
{"index":{"_index":"index-1970.01","_type":"messages"}}
{"timestamp":123000,"message":"Downtime end:
","author":"philip","host":"host 1","service":"service 1","type":"downtime"}
`
- if result != expected {
- t.Errorf("The result did not match the expected. Result: %sExpected: %s", result, expected)
- }
+ assert.Equalf(t, expected, result, "The result did not match the expected")
}
diff --git a/pkg/nagflux/collector/livestatus/NotificationData.go b/pkg/nagflux/collector/livestatus/NotificationData.go
index b9a4204..7d8f85f 100644
--- a/pkg/nagflux/collector/livestatus/NotificationData.go
+++ b/pkg/nagflux/collector/livestatus/NotificationData.go
@@ -24,9 +24,9 @@ func (notification *NotificationData) sanitizeValues() {
}
// PrintForInfluxDB prints the data in influxdb lineformat
-func (notification NotificationData) PrintForInfluxDB(version string) string {
- notification.sanitizeValues()
+func (notification *NotificationData) PrintForInfluxDB(version string) string {
if helper.VersionOrdinal(version) >= helper.VersionOrdinal("0.9") {
+ notification.sanitizeValues()
var tags string
if text := notificationToText(notification.notificationType); text != "" {
tags = ",type=" + text
@@ -39,7 +39,7 @@ func (notification NotificationData) PrintForInfluxDB(version string) string {
}
// PrintForElasticsearch prints in the elasticsearch json format
-func (notification NotificationData) PrintForElasticsearch(version, index string) string {
+func (notification *NotificationData) PrintForElasticsearch(version, index string) string {
if helper.VersionOrdinal(version) >= helper.VersionOrdinal("2.0") {
text := notificationToText(notification.notificationType)
value := fmt.Sprintf("%s:
%s", strings.TrimSpace(notification.notificationLevel), notification.comment)
diff --git a/pkg/nagflux/collector/nagflux/NagfluxPrintable.go b/pkg/nagflux/collector/nagflux/NagfluxPrintable.go
index 8d93a0d..b49f608 100644
--- a/pkg/nagflux/collector/nagflux/NagfluxPrintable.go
+++ b/pkg/nagflux/collector/nagflux/NagfluxPrintable.go
@@ -17,7 +17,7 @@ type Printable struct {
}
// PrintForInfluxDB prints the data in influxdb lineformat
-func (p Printable) PrintForInfluxDB(version string) string {
+func (p *Printable) PrintForInfluxDB(version string) string {
if helper.VersionOrdinal(version) >= helper.VersionOrdinal("0.9") {
line := p.Table
if len(p.tags) > 0 {
@@ -33,7 +33,7 @@ func (p Printable) PrintForInfluxDB(version string) string {
}
// PrintForElasticsearch prints in the elasticsearch json format
-func (p Printable) PrintForElasticsearch(version, index string) string {
+func (p *Printable) PrintForElasticsearch(version, index string) string {
if helper.VersionOrdinal(version) >= helper.VersionOrdinal("2.0") {
head := fmt.Sprintf(`{"index":{"_index":"%s","_type":"%s"}}`, helper.GenIndex(index, p.Timestamp), p.Table) + "\n"
data := `{"timestamp":` + p.Timestamp
diff --git a/pkg/nagflux/collector/nagflux/dumpfileCollector.go b/pkg/nagflux/collector/nagflux/dumpfileCollector.go
index d6a778a..f0960aa 100644
--- a/pkg/nagflux/collector/nagflux/dumpfileCollector.go
+++ b/pkg/nagflux/collector/nagflux/dumpfileCollector.go
@@ -73,7 +73,7 @@ func (dump *DumpfileCollector) run() {
case <-dump.quit:
dump.quit <- true
return
- case dump.jobs <- collector.SimplePrintable{
+ case dump.jobs <- &collector.SimplePrintable{
Filterable: collector.AllFilterable,
Text: string(line),
Datatype: dump.target.Datatype,
@@ -106,7 +106,7 @@ func (dump *DumpfileCollector) run() {
case <-dump.quit:
dump.quit <- true
return
- case dump.jobs <- collector.SimplePrintable{
+ case dump.jobs <- &collector.SimplePrintable{
Filterable: collector.AllFilterable,
Text: buffer.String(),
Datatype: dump.target.Datatype,
diff --git a/pkg/nagflux/collector/nagflux/nagfluxFileCollector.go b/pkg/nagflux/collector/nagflux/nagfluxFileCollector.go
index 01bc88a..1f2da28 100644
--- a/pkg/nagflux/collector/nagflux/nagfluxFileCollector.go
+++ b/pkg/nagflux/collector/nagflux/nagfluxFileCollector.go
@@ -54,7 +54,7 @@ func (nfc *FileCollector) Stop() {
}
// Checks if the files are old enough, if so they will be added in the queue
-func (nfc FileCollector) run() {
+func (nfc *FileCollector) run() {
for {
select {
case <-nfc.quit:
@@ -74,7 +74,7 @@ func (nfc FileCollector) run() {
case <-nfc.quit:
nfc.quit <- true
return
- case r <- p:
+ case r <- &p:
case <-time.After(time.Duration(1) * time.Minute):
nfc.log.Warn("NagfluxFileCollector: Could not write to buffer")
}
@@ -89,7 +89,7 @@ func (nfc FileCollector) run() {
}
}
-func (nfc FileCollector) parseFile(filename string) []Printable {
+func (nfc *FileCollector) parseFile(filename string) []Printable {
result := []Printable{}
csvfile, err := os.Open(filename)
if err != nil {
diff --git a/pkg/nagflux/collector/spoolfile/nagiosSpoolfileWorker.go b/pkg/nagflux/collector/spoolfile/nagiosSpoolfileWorker.go
index 57d9b3b..df758f1 100644
--- a/pkg/nagflux/collector/spoolfile/nagiosSpoolfileWorker.go
+++ b/pkg/nagflux/collector/spoolfile/nagiosSpoolfileWorker.go
@@ -153,8 +153,8 @@ func (w *NagiosSpoolfileWorker) run() {
}
// PerformanceDataIterator returns an iterator to loop over generated perf data.
-func (w *NagiosSpoolfileWorker) PerformanceDataIterator(input map[string]string) <-chan PerformanceData {
- ch := make(chan PerformanceData)
+func (w *NagiosSpoolfileWorker) PerformanceDataIterator(input map[string]string) <-chan *PerformanceData {
+ ch := make(chan *PerformanceData)
typ := findType(input)
if typ == "" {
if len(input) > 1 {
@@ -199,7 +199,7 @@ func (w *NagiosSpoolfileWorker) PerformanceDataIterator(input map[string]string)
target = collector.AllFilterable
}
- perf := PerformanceData{
+ perf := &PerformanceData{
Hostname: input[hostname],
Service: currentService,
Command: currentCommand,
diff --git a/pkg/nagflux/collector/spoolfile/nagiosSpoolfileWorker_test.go b/pkg/nagflux/collector/spoolfile/nagiosSpoolfileWorker_test.go
index 167a4b4..d8445d6 100644
--- a/pkg/nagflux/collector/spoolfile/nagiosSpoolfileWorker_test.go
+++ b/pkg/nagflux/collector/spoolfile/nagiosSpoolfileWorker_test.go
@@ -428,7 +428,7 @@ func testPerformanceDataParser(t *testing.T, input string, expect []PerformanceD
splittedPerformanceData := helper.StringToMap(input, "\t", "::")
collectedPerfData := []PerformanceData{}
for singlePerfdata := range w.PerformanceDataIterator(splittedPerformanceData) {
- collectedPerfData = append(collectedPerfData, singlePerfdata)
+ collectedPerfData = append(collectedPerfData, *singlePerfdata)
}
assert.Equalf(t, expect, collectedPerfData, "performance data matches")
}
diff --git a/pkg/nagflux/collector/spoolfile/performanceData.go b/pkg/nagflux/collector/spoolfile/performanceData.go
index 8f5fb02..df49eb9 100644
--- a/pkg/nagflux/collector/spoolfile/performanceData.go
+++ b/pkg/nagflux/collector/spoolfile/performanceData.go
@@ -22,7 +22,7 @@ type PerformanceData struct {
}
// PrintForInfluxDB prints the data in influxdb lineformat
-func (p PerformanceData) PrintForInfluxDB(version string) string {
+func (p *PerformanceData) PrintForInfluxDB(version string) string {
if helper.VersionOrdinal(version) >= helper.VersionOrdinal("0.9") {
tableName := `metrics,host=` + helper.SanitizeInfluxInput(p.Hostname)
if p.Service == "" {
@@ -47,7 +47,7 @@ func (p PerformanceData) PrintForInfluxDB(version string) string {
}
// PrintForElasticsearch prints in the elasticsearch json format
-func (p PerformanceData) PrintForElasticsearch(version, index string) string {
+func (p *PerformanceData) PrintForElasticsearch(version, index string) string {
if helper.VersionOrdinal(version) >= helper.VersionOrdinal("2.0") {
if p.Service == "" {
p.Service = config.GetConfig().InfluxDBGlobal.HostcheckAlias
diff --git a/pkg/nagflux/target/elasticsearch/Connector.go b/pkg/nagflux/target/elasticsearch/Connector.go
index a2a8965..a67a4a0 100644
--- a/pkg/nagflux/target/elasticsearch/Connector.go
+++ b/pkg/nagflux/target/elasticsearch/Connector.go
@@ -93,17 +93,17 @@ func (connector *Connector) RemoveWorker() {
}
// AmountWorkers current amount of workers.
-func (connector Connector) AmountWorkers() int {
+func (connector *Connector) AmountWorkers() int {
return len(connector.workers)
}
// IsAlive is the database system alive.
-func (connector Connector) IsAlive() bool {
+func (connector *Connector) IsAlive() bool {
return connector.isAlive
}
// DatabaseExists does the database exist.
-func (connector Connector) DatabaseExists() bool {
+func (connector *Connector) DatabaseExists() bool {
return connector.templateExists
}
diff --git a/pkg/nagflux/target/elasticsearch/Worker.go b/pkg/nagflux/target/elasticsearch/Worker.go
index b714c38..44efa9e 100644
--- a/pkg/nagflux/target/elasticsearch/Worker.go
+++ b/pkg/nagflux/target/elasticsearch/Worker.go
@@ -73,7 +73,7 @@ func (worker *Worker) Stop() {
}
// Tries to send data all the time.
-func (worker Worker) run() {
+func (worker *Worker) run() {
var queries []collector.Printable
var query collector.Printable
for {
@@ -116,7 +116,7 @@ func (worker Worker) run() {
}
// Checks if a external quit signal arrives.
-func (worker Worker) waitForExternalQuit() bool {
+func (worker *Worker) waitForExternalQuit() bool {
select {
case <-worker.quit:
worker.quit <- true
@@ -127,7 +127,7 @@ func (worker Worker) waitForExternalQuit() bool {
}
// Sends the given queries to the influxdb.
-func (worker Worker) sendBuffer(queries []collector.Printable) {
+func (worker *Worker) sendBuffer(queries []collector.Printable) {
if len(queries) == 0 {
return
}
@@ -183,7 +183,7 @@ func (worker Worker) sendBuffer(queries []collector.Printable) {
}
// Writes the bad queries to a dumpfile.
-func (worker Worker) dumpErrorQueries(messageForLog string, errorQueries []string) {
+func (worker *Worker) dumpErrorQueries(messageForLog string, errorQueries []string) {
errorFile := worker.dumpFile + "-errors"
worker.log.Warnf("Dumping queries with errors to: %s", errorFile)
errorQueries = append([]string{messageForLog}, errorQueries...)
@@ -193,7 +193,7 @@ func (worker Worker) dumpErrorQueries(messageForLog string, errorQueries []strin
var mutex = &sync.Mutex{}
// Dumps the remaining queries if a quit signal arises.
-func (worker Worker) dumpRemainingQueries(remainingQueries []string) {
+func (worker *Worker) dumpRemainingQueries(remainingQueries []string) {
mutex.Lock()
worker.log.Debugf("Global queue %d own queue %d", len(worker.jobs), len(remainingQueries))
if len(worker.jobs) != 0 || len(remainingQueries) != 0 {
@@ -208,7 +208,7 @@ func (worker Worker) dumpRemainingQueries(remainingQueries []string) {
}
// Reads the queries from the global queue and returns them as string.
-func (worker Worker) readQueriesFromQueue() []string {
+func (worker *Worker) readQueriesFromQueue() []string {
var queries []string
var query collector.Printable
stop := false
@@ -227,7 +227,7 @@ func (worker Worker) readQueriesFromQueue() []string {
}
// sends the raw data to influxdb and returns an err if given.
-func (worker Worker) sendData(rawData []byte, log bool) error {
+func (worker *Worker) sendData(rawData []byte, log bool) error {
worker.log.Debug(string(rawData))
req, err := http.NewRequest(http.MethodPost, worker.connection, bytes.NewBuffer(rawData))
if err != nil {
@@ -255,7 +255,7 @@ func (worker Worker) sendData(rawData []byte, log bool) error {
return nil // maybe return error?
}
-func (worker Worker) printErrors(result JSONResult, rawData []byte) {
+func (worker *Worker) printErrors(result JSONResult, rawData []byte) {
errors := []map[int]string{{}}
for index, item := range result.Items {
if item.Create.Status != 201 {
@@ -269,7 +269,7 @@ func (worker Worker) printErrors(result JSONResult, rawData []byte) {
}
// Waits on an internal quit signal.
-func (worker Worker) waitForQuitOrGoOn() error {
+func (worker *Worker) waitForQuitOrGoOn() error {
select {
// Got stop signal
case <-worker.quitInternal:
@@ -283,7 +283,7 @@ func (worker Worker) waitForQuitOrGoOn() error {
}
// Writes queries to a dumpfile.
-func (worker Worker) dumpQueries(filename string, queries []string) {
+func (worker *Worker) dumpQueries(filename string, queries []string) {
if _, err := os.Stat(filename); os.IsNotExist(err) {
if _, err := os.Create(filename); err != nil {
worker.log.Critical(err)
@@ -302,7 +302,7 @@ func (worker Worker) dumpQueries(filename string, queries []string) {
}
// Converts an collector.Printable to a string.
-func (worker Worker) castJobToString(job collector.Printable) (string, error) {
+func (worker *Worker) castJobToString(job collector.Printable) (string, error) {
var result string
var err error
diff --git a/pkg/nagflux/target/file/json/Worker.go b/pkg/nagflux/target/file/json/Worker.go
index f983a67..3662fc4 100644
--- a/pkg/nagflux/target/file/json/Worker.go
+++ b/pkg/nagflux/target/file/json/Worker.go
@@ -65,7 +65,7 @@ func (t *FileWorker) Stop() {
}
}
-func (t FileWorker) run() {
+func (t *FileWorker) run() {
var queries []collector.Printable
var query collector.Printable
go func() {
@@ -90,7 +90,7 @@ func (t FileWorker) run() {
}
}
-func (t FileWorker) writeData(data []collector.Printable) {
+func (t *FileWorker) writeData(data []collector.Printable) {
if len(data) == 0 {
return
}
@@ -144,7 +144,7 @@ func (t FileWorker) writeData(data []collector.Printable) {
}
}
-func (t FileWorker) getFilename() string {
+func (t *FileWorker) getFilename() string {
if t.rotation {
return path.Join(t.path, fmt.Sprintf("perfdata_%d", time.Now().Unix()))
}
diff --git a/pkg/nagflux/target/influx/Connector.go b/pkg/nagflux/target/influx/Connector.go
index 5b86797..d34ef41 100644
--- a/pkg/nagflux/target/influx/Connector.go
+++ b/pkg/nagflux/target/influx/Connector.go
@@ -154,17 +154,17 @@ func (connector *Connector) RemoveWorker() {
}
// AmountWorkers current amount of workers.
-func (connector Connector) AmountWorkers() int {
+func (connector *Connector) AmountWorkers() int {
return len(connector.workers)
}
// IsAlive is the database system alive.
-func (connector Connector) IsAlive() bool {
+func (connector *Connector) IsAlive() bool {
return connector.isAlive
}
// DatabaseExists does the database exist.
-func (connector Connector) DatabaseExists() bool {
+func (connector *Connector) DatabaseExists() bool {
return connector.databaseExists
}
diff --git a/pkg/nagflux/target/influx/Worker.go b/pkg/nagflux/target/influx/Worker.go
index 3c985b6..e5466a0 100644
--- a/pkg/nagflux/target/influx/Worker.go
+++ b/pkg/nagflux/target/influx/Worker.go
@@ -87,7 +87,7 @@ func (worker *Worker) Stop() {
}
// Tries to send data all the time.
-func (worker Worker) run() {
+func (worker *Worker) run() {
var queries []collector.Printable
var query collector.Printable
for {
@@ -142,7 +142,7 @@ func (worker Worker) run() {
}
// Sends the given queries to the influxdb.
-func (worker Worker) sendBuffer(queries []collector.Printable) {
+func (worker *Worker) sendBuffer(queries []collector.Printable) {
if len(queries) == 0 {
return
}
@@ -204,7 +204,7 @@ func (worker Worker) sendBuffer(queries []collector.Printable) {
}
// Reads the queries from the global queue and returns them as string.
-func (worker Worker) readQueriesFromQueue() []string {
+func (worker *Worker) readQueriesFromQueue() []string {
var queries []string
var query collector.Printable
stop := false
@@ -225,7 +225,7 @@ func (worker Worker) readQueriesFromQueue() []string {
}
// sends the raw data to influxdb and returns an err if given.
-func (worker Worker) sendData(rawData []byte, log bool) error {
+func (worker *Worker) sendData(rawData []byte, log bool) error {
if log {
worker.log.Debug("sendData (" + worker.target.Name + ")\n" + string(rawData))
}
@@ -265,13 +265,13 @@ func (worker Worker) sendData(rawData []byte, log bool) error {
}
// Logs a http response to warn.
-func (worker Worker) logHTTPResponse(resp *http.Response) {
+func (worker *Worker) logHTTPResponse(resp *http.Response) {
body, _ := io.ReadAll(resp.Body)
worker.log.Warnf("Influx status: %s - %s", resp.Status, string(body))
}
// Waits on an internal quit signal.
-func (worker Worker) waitForQuitOrGoOn() error {
+func (worker *Worker) waitForQuitOrGoOn() error {
select {
// Got stop signal
case <-worker.quitInternal:
@@ -285,7 +285,7 @@ func (worker Worker) waitForQuitOrGoOn() error {
}
// Writes the bad queries to a dumpfile.
-func (worker Worker) dumpErrorQueries(messageForLog string, errorQueries []string) {
+func (worker *Worker) dumpErrorQueries(messageForLog string, errorQueries []string) {
errorFile := worker.dumpFile + "-errors"
worker.log.Warnf("Dumping queries with errors to: %s", errorFile)
errorQueries = append([]string{messageForLog}, errorQueries...)
@@ -293,7 +293,7 @@ func (worker Worker) dumpErrorQueries(messageForLog string, errorQueries []strin
}
// Dumps the remaining queries if a quit signal arises.
-func (worker Worker) dumpRemainingQueries(remainingQueries []string) {
+func (worker *Worker) dumpRemainingQueries(remainingQueries []string) {
worker.log.Debugf("Global queue %d own queue %d", len(worker.jobs), len(remainingQueries))
if len(worker.jobs) != 0 || len(remainingQueries) != 0 {
worker.log.Debug("Saving queries to disk")
@@ -304,7 +304,7 @@ func (worker Worker) dumpRemainingQueries(remainingQueries []string) {
}
// Writes queries to a dumpfile.
-func (worker Worker) dumpQueries(filename string, queries []string) {
+func (worker *Worker) dumpQueries(filename string, queries []string) {
mutex.Lock()
if _, err := os.Stat(filename); os.IsNotExist(err) {
if _, err := os.Create(filename); err != nil {
@@ -325,7 +325,7 @@ func (worker Worker) dumpQueries(filename string, queries []string) {
}
// Converts an collector.Printable to a string.
-func (worker Worker) castJobToString(job collector.Printable) (string, error) {
+func (worker *Worker) castJobToString(job collector.Printable) (string, error) {
var result string
var err error