From e011b390569a45c2bd9a737f69cf9aac81de373b Mon Sep 17 00:00:00 2001 From: Adrian Lopez Date: Wed, 13 Dec 2023 18:23:50 +0100 Subject: [PATCH] feat(output.zabbix): use system hostname if no host tag is found If the host tag is not present in one metric, instead of failing, try to use the system hostname. --- plugins/outputs/zabbix/lld.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/outputs/zabbix/lld.go b/plugins/outputs/zabbix/lld.go index 391e70752d4eb..b25a24d10d500 100644 --- a/plugins/outputs/zabbix/lld.go +++ b/plugins/outputs/zabbix/lld.go @@ -3,8 +3,9 @@ package zabbix import ( "encoding/binary" "encoding/json" - "errors" + "fmt" "hash/fnv" + "os" "sort" "strings" "time" @@ -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