Skip to content

Commit

Permalink
feat(output.zabbix): use system hostname if no host tag is found
Browse files Browse the repository at this point in the history
If the host tag is not present in one metric, instead of failing, try to
use the system hostname.
  • Loading branch information
adrianlzt committed Dec 13, 2023
1 parent 1cbc301 commit e011b39
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions plugins/outputs/zabbix/lld.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package zabbix
import (
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"hash/fnv"
"os"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -198,8 +199,13 @@ func (zl *zabbixLLD) Add(in telegraf.Metric) error {
key = in.Name() + "." + strings.Join(keys, ".")
}

// If hostname is not defined, use the hostname of the system
if hostname == "" {
return errors.New("no hostname found")
var err error
hostname, err = os.Hostname()
if err != nil {
return fmt.Errorf("no hostname found and unable to get hostname from system: %w", err)
}
}

// Try to lookup the Zabbix series in the already received metrics and
Expand Down

0 comments on commit e011b39

Please sign in to comment.