Skip to content

Commit 83129c6

Browse files
committed
feat(contrib/snmp2cpe): replace space with underscore
1 parent 9437a24 commit 83129c6

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

contrib/snmp2cpe/pkg/cpe/cpe.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func Convert(result snmp.Result) []string {
8080
if strings.HasPrefix(v, "Arista Networks EOS version ") {
8181
cpes = append(cpes, fmt.Sprintf("cpe:2.3:o:arista:eos:%s:*:*:*:*:*:*:*", strings.ToLower(strings.TrimPrefix(v, "Arista Networks EOS version "))))
8282
}
83-
cpes = append(cpes, fmt.Sprintf("cpe:/h:arista:%s:-:*:*:*:*:*:*:*", strings.ToLower(strings.TrimPrefix(h, "Arista Networks "))))
83+
cpes = append(cpes, fmt.Sprintf("cpe:2.3:h:arista:%s:-:*:*:*:*:*:*:*", strings.ToLower(strings.TrimPrefix(h, "Arista Networks "))))
8484
}
8585
if t, ok := result.EntPhysicalTables[1]; ok {
8686
if t.EntPhysicalSoftwareRev != "" {
@@ -429,6 +429,7 @@ func Convert(result snmp.Result) []string {
429429

430430
m := make(map[string]struct{}, len(cpes))
431431
for _, c := range cpes {
432+
c = strings.NewReplacer(" ", "_").Replace(c)
432433
if _, err := naming.UnbindFS(c); err != nil {
433434
log.Printf("WARN: skip %q. err: %s", c, err)
434435
continue

contrib/snmp2cpe/pkg/cpe/cpe_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func TestConvert(t *testing.T) {
8383
want: []string{"cpe:2.3:o:cisco:ios:12.2(17d)sxb11:*:*:*:*:*:*:*"},
8484
},
8585
{
86-
name: "Cisco IOX-XE Version 16.12.4",
86+
name: "Cisco IOS-XE Version 16.12.4",
8787
args: snmp.Result{
8888
SysDescr0: `Cisco IOS Software [Gibraltar], Catalyst L3 Switch Software (CAT9K_LITE_IOSXE), Version 16.12.4, RELEASE SOFTWARE (fc5)
8989
Technical Support: http://www.cisco.com/techsupport
@@ -93,7 +93,7 @@ func TestConvert(t *testing.T) {
9393
want: []string{"cpe:2.3:o:cisco:ios_xe:16.12.4:*:*:*:*:*:*:*"},
9494
},
9595
{
96-
name: "Cisco IOX-XE Version 03.06.07.E",
96+
name: "Cisco IOS-XE Version 03.06.07.E",
9797
args: snmp.Result{
9898
SysDescr0: `Cisco IOS Software, IOS-XE Software, Catalyst 4500 L3 Switch Software (cat4500es8-UNIVERSALK9-M), Version 03.06.07.E RELEASE SOFTWARE (fc3)
9999
Technical Support: http://www.cisco.com/techsupport
@@ -102,6 +102,16 @@ func TestConvert(t *testing.T) {
102102
},
103103
want: []string{"cpe:2.3:o:cisco:ios_xe:03.06.07.e:*:*:*:*:*:*:*"},
104104
},
105+
{
106+
name: "Cisco IOS-XE Version 03.06.06E on c38xx Stack",
107+
args: snmp.Result{
108+
SysDescr0: "Cisco IOS Software, IOS-XE Software, Catalyst L3 Switch Software (CAT3K_CAA-UNIVERSALK9-M), Version 03.06.06E RELEASE SOFTWARE (fc1)\r\nTechnical Support: http://www.cisco.com/techsupport\r\nCopyright (c) 1986-2016 by Cisco Systems, Inc.\r\nCompiled Sat 17-Dec-",
109+
EntPhysicalTables: map[int]snmp.EntPhysicalTable{1: {
110+
EntPhysicalName: "c38xx Stack",
111+
}},
112+
},
113+
want: []string{"cpe:2.3:h:cisco:c38xx_stack:-:*:*:*:*:*:*:*", "cpe:2.3:o:cisco:ios_xe:03.06.06e:*:*:*:*:*:*:*"},
114+
},
105115
{
106116
name: "Juniper SSG-5-SH-BT",
107117
args: snmp.Result{
@@ -164,7 +174,7 @@ func TestConvert(t *testing.T) {
164174
EntPhysicalSoftwareRev: "4.28.4M",
165175
}},
166176
},
167-
want: []string{"cpe:/h:arista:dcs-7050tx-64:-:*:*:*:*:*:*:*", "cpe:2.3:o:arista:eos:4.28.4m:*:*:*:*:*:*:*"},
177+
want: []string{"cpe:2.3:h:arista:dcs-7050tx-64:-:*:*:*:*:*:*:*", "cpe:2.3:o:arista:eos:4.28.4m:*:*:*:*:*:*:*"},
168178
},
169179
{
170180
name: "FortiGate-50E",

0 commit comments

Comments
 (0)