Skip to content

Commit 32ff982

Browse files
committed
cosmetic change
1 parent c465501 commit 32ff982

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

main.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ func main() {
3030
var ip = flag.String("ip", "127.0.0.1", "IP address of target device")
3131
var community = flag.String("c", "public", "SNMP community")
3232
var format = flag.String("o", "csv", "Output format (csv, json)")
33-
var localPortType = flag.String("lt", "desc", "port-id-subtype selection for local (desc|id)")
34-
var remotePortType = flag.String("rt", "desc", "port-id-subtype selection for remote (desc|id)")
35-
var prune = flag.Bool("p", false, "whether print LLDP entry has no remote port name or not")
33+
var localPortType = flag.String("lt", "desc", "port-id-subtype selection for local (desc, id)")
34+
var remotePortType = flag.String("rt", "desc", "port-id-subtype selection for remote (desc, id)")
35+
var prune = flag.Bool("p", false, "do not output LLDP entry which has no remote info")
3636

3737
flag.Parse()
3838

@@ -90,6 +90,14 @@ func main() {
9090
lldpEntries[strings.Split(pdu.Name[26:], ".")[1]].RemotePortName = remotePort
9191
}
9292

93+
if *prune {
94+
for key, lldp := range lldpEntries {
95+
if lldp.RemotePortName == "" || lldp.RemoteSysName == "" {
96+
delete(lldpEntries, key)
97+
}
98+
}
99+
}
100+
93101
if *format == "json" {
94102
jsonString, err := json.Marshal(lldpEntries)
95103
if err != nil {
@@ -100,11 +108,6 @@ func main() {
100108
} else if *format == "csv" {
101109
fmt.Println("Local,RemotePort,RemoteSysName")
102110
for _, lldp := range lldpEntries {
103-
if *prune {
104-
if lldp.RemotePortName == "" && lldp.RemoteSysName == "" {
105-
continue
106-
}
107-
}
108111
fmt.Println(
109112
lldp.LocalPortName, ",",
110113
lldp.RemotePortName, ",",

0 commit comments

Comments
 (0)