From 10ef6d2ac16953bd85644322b0193c70212344c6 Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Fri, 15 Mar 2024 12:12:18 +0100 Subject: [PATCH 1/2] Add flag to be able to set the port - Just a small backward compatible change that also helps when debugging --- main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.go b/main.go index 946b48c..d26dd52 100644 --- a/main.go +++ b/main.go @@ -49,6 +49,7 @@ func main() { host = fs.StringP("hostname", "H", "localhost", "SNMP host") community = fs.StringP("community", "c", "public", "SNMP community") protocol = fs.StringP("protocol", "P", "2c", "SNMP protocol") + port = fs.Uint16P("port", "p", 161, "SNMP port") file = fs.String("snmpwalk-file", "", "Read output from snmpwalk") ignoreIlo = fs.BoolP("ignore-ilo-version", "I", false, "Don't check the ILO version") ipv4 = fs.BoolP("ipv4", "4", false, "Use IPv4") @@ -76,6 +77,7 @@ func main() { } else { client = gosnmp.NewHandler() client.SetTarget(*host) + client.SetPort(*port) client.SetCommunity(*community) client.SetTimeout(time.Duration(config.Timeout) - 1*time.Second) client.SetRetries(1) From a70e4456e936b6b379e4163d87f7786a272c5db8 Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Fri, 15 Mar 2024 12:13:37 +0100 Subject: [PATCH 2/2] Fix error in timeout calculation - This error caused the default timeout for the SNMP connection to always be `-999.99ms` --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index d26dd52..fc0d5e3 100644 --- a/main.go +++ b/main.go @@ -79,7 +79,7 @@ func main() { client.SetTarget(*host) client.SetPort(*port) client.SetCommunity(*community) - client.SetTimeout(time.Duration(config.Timeout) - 1*time.Second) + client.SetTimeout(time.Duration(config.Timeout) * time.Second) client.SetRetries(1) version, err := snmp.VersionFromString(*protocol)