I do a server on golnag and I need to do a SNMP command to many devices, some of this devices could not have connections( or lost it temporary) And I want message " no connection" or "Error" and next continue the runing of programm
Ubuntu 18.04 // go 1.8 // go SNMP from https://github.com/soniah/gosnmp
package main
import (
"fmt"
"log"
"time"
g "github.com/soniah/gosnmp"
)
func main() {
g.Default.Target = string("192.168.10.1")
err := g.Default.Connect()
if err != nil {
log.Fatalf("Connect() err: %v", err)
fmt.Println("Fail connection") // want this message in this case !!!!!
}
defer g.Default.Conn.Close()
oids := []string{"1.3.6.1.2.1.1.4.0", "1.3.6.1.2.1.1.7.0"}
result, err2 := g.Default.Get(oids)
if err2 != nil {
log.Fatalf("Get() err: %v", err2)
fmt.Println("Error read OID") // want this message in this case !!!!!
}
for i, variable := range result.Variables {
fmt.Printf("%d: oid: %s ", i, variable.Name)
switch variable.Type {
case g.OctetString:
fmt.Printf("string: %s
", string(variable.Value.([]byte)))
default:
fmt.Printf("number: %d
", g.ToBigInt(variable.Value))
}
}
}
I receive this result if no connection, and break the runing of pogramm
2019/05/19 15:11:33 Get() err: Request timeout (after 3 retries)
exit status 1
I want something like this
"Fail connection" or "Error read OID"
And next, I want to continue the runing of programm