From d17f0f88f0f1d5734d207a72803393c0a40dd302 Mon Sep 17 00:00:00 2001 From: Shark Date: Thu, 5 Dec 2024 02:57:10 +0300 Subject: [PATCH] fix tnies values --- config.yml | 4 ++++ main.go | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/config.yml b/config.yml index b1f3545..5860189 100644 --- a/config.yml +++ b/config.yml @@ -12,3 +12,7 @@ oids: - oid: "1.3.6.1.4.1.935.10.1.1.1" # upsEIdentity - oid: "1.3.6.1.4.1.935.10.1.1.2" # upsESystemSummary - oid: "1.3.6.1.4.1.935.10.1.1.3" # upsEBatterySystem + +toNullIfEmpty: #only for int + - tne: "upsESystemInputVoltage" + - tne: "upsESystemOutputLoad" diff --git a/main.go b/main.go index 2e9ba0c..ae4fe9e 100644 --- a/main.go +++ b/main.go @@ -34,6 +34,9 @@ type Config struct { OIDs []struct { OID string `yaml:"oid"` } `yaml:"oids"` + Tnies []struct { + Tnie string `yaml:"tne"` + } `yaml:"toNullIfEmpty"` } func loadConfig(filename string) (*Config, error) { @@ -179,8 +182,12 @@ func starts(params *gosnmp.GoSNMP, config *Config) { } - if toExport["upsESystemInputVoltage"].(int64) <= 0 { - delete(toExport, "upsESystemInputVoltage") + for _, v := range config.Tnies { + if mapVal, ok := toExport[v.Tnie]; ok { + if mapVal.(int64) <= 0 { + delete(toExport, v.Tnie) + } + } } go PushData(toExport, tm)