@@ -32,6 +32,8 @@ const (
3232 remoteChassisID
3333)
3434
35+ const noObjMsg = "A required object (or instance) doesn't exist."
36+
3537func getLLDPInfo (host string , port uint16 , community string ) (* lldpInfo , error ) {
3638 snmpClient := & snmp.GoSNMP {
3739 Version : snmp .Version2c ,
@@ -64,13 +66,19 @@ func getLLDPInfo(host string, port uint16, community string) (*lldpInfo, error)
6466 return info , err
6567 }
6668
69+ e := result .Variables [0 ]
70+ if e .Type == snmp .NoSuchObject || e .Type == snmp .NoSuchInstance {
71+ err = fmt .Errorf ("%v OID: %v" , noObjMsg , oid )
72+ return info , err
73+ }
74+
6775 switch object {
6876 case localName :
69- info .name = string (result . Variables [ 0 ] .Value .([]byte ))
77+ info .name = string (e .Value .([]byte ))
7078 case localDesc :
71- info .desc = string (result . Variables [ 0 ] .Value .([]byte ))
79+ info .desc = string (e .Value .([]byte ))
7280 case localChassisID :
73- hexrep := fmt .Sprintf ("% x" , result . Variables [ 0 ] .Value )
81+ hexrep := fmt .Sprintf ("% x" , e .Value )
7482 info .chassisID = strings .ReplaceAll (hexrep , " " , ":" )
7583 }
7684
@@ -100,6 +108,11 @@ func getRemoteTable(client *snmp.GoSNMP) (map[string]*lldpRemote, error) {
100108
101109 // Retrieve the rows (instances) of the column (object)
102110 for _ , e := range results {
111+ if e .Type == snmp .NoSuchObject || e .Type == snmp .NoSuchInstance {
112+ err = fmt .Errorf ("%v OID: %v" , noObjMsg , oid )
113+ return table , err
114+ }
115+
103116 row := strings .ReplaceAll (e .Name , oid , "" )
104117 if table [row ] == nil {
105118 table [row ] = & lldpRemote {}
0 commit comments