fix: snmpv3 in ipv6

This commit is contained in:
2024-09-21 13:54:14 +08:00
parent 21f9d6d458
commit 3b7f992425
5 changed files with 46 additions and 17 deletions

View File

@@ -10,7 +10,6 @@ import (
"strings"
"time"
"github.com/gosnmp/gosnmp"
g "github.com/gosnmp/gosnmp"
"github.com/slayercat/GoSNMPServer"
"github.com/slayercat/GoSNMPServer/mibImps"
@@ -243,6 +242,19 @@ func (s *SNMPService) handleOIDs() []*GoSNMPServer.PDUValueControlItem {
},
},
}
// 为 GETBULK 新增处理 OIDs
bulkOIDs := &GoSNMPServer.PDUValueControlItem{
OID: ".1.3.6.1.4.1.1379.2.3.3.3.1.1", // 这里是您想要支持 GETBULK 的 OID 前缀
Type: g.OctetString,
OnGet: func() (value interface{}, err error) {
// 假设我们返回一百度值,您可以根据您的实现进行调整
values := []interface{}{s.SysName, s.SysStatus, s.SysDescr, s.SysLocation, s.SysContact, uint32(time.Now().Unix()), s.SysService} // 可以从其他结构中获取真实值
return values, nil
},
}
customOIDs = append(customOIDs, bulkOIDs)
// 获取mibImps.All()返回的OID列表
mibOIDs := mibImps.All()
@@ -405,7 +417,7 @@ func (s *SNMPService) sendLinkDownTrap(gs *g.GoSNMP, ifIndex int, ifDescr string
},
{
Name: ".1.3.6.1.4.1.1379.2.3.3.3.4", // severity OID
Type: gosnmp.Integer,
Type: g.Integer,
Value: 2, // event
},
},
@@ -446,7 +458,7 @@ func (s *SNMPService) sendLinkUpTrap(gs *g.GoSNMP, ifIndex int, ifDescr string)
},
{
Name: ".1.3.6.1.4.1.1379.2.3.3.3.4", // severity OID
Type: gosnmp.Integer,
Type: g.Integer,
Value: 5, // event
},
},
@@ -487,7 +499,7 @@ func (s *SNMPService) sendAuthFailureTrap(gs *g.GoSNMP, username, descr string)
},
{
Name: ".1.3.6.1.4.1.1379.2.3.3.3.4", // severity OID
Type: gosnmp.Integer,
Type: g.Integer,
Value: 4, // event
},
},