Skip to content

Commit 315ca59

Browse files
committed
Fixed truncate issue while creating nodes
1 parent f6f20b4 commit 315ca59

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# Netmap
22

3-
Netmap stands for Network Mapper, a visualizer for your inventory of network devices. Netmap starts collecting LLDP information with a single device credential and recursively collects neighbor of neighbors information. Built with love by Roopesh and friends in Go.
3+
Netmap stands for Network Mapper, a visualizer for your inventory of network devices. Netmap starts collecting LLDP information with a single device credential and recursively lookup to create a graph. At the moment the tool supports only Arista devices.
4+
5+
Built with love by Roopesh and friends in Go.
46

57
## Usage
68

9+
The graph can be created using the command `netmap create`,
10+
711
```
812
roopesh:~/ $ netmap create --help
913
Create topology diagram
@@ -21,5 +25,5 @@ roopesh:~/ $ netmap create -n ok270 -u admin -p password
2125

2226
<figure>
2327
<img src="./graph.png" alt="Graph created by netmap">
24-
<figcaption>Graph created by Netmap</figcaption>
28+
<figcaption>The above graph was created by Netmap. The labels of nodes and edges are truncated for privacy concerns.</figcaption>
2529
</figure>

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ module opennetworktools/netmap
33
go 1.23.1
44

55
require (
6+
aqwari.net/xml v0.0.0-20210331023308-d9421b293817
67
github.com/aristanetworks/goeapi v1.0.0
78
github.com/goccy/go-graphviz v0.2.9
89
github.com/spf13/cobra v1.9.1
910
)
1011

1112
require (
12-
aqwari.net/xml v0.0.0-20210331023308-d9421b293817 // indirect
1313
github.com/disintegration/imaging v1.6.2 // indirect
1414
github.com/flopp/go-findfont v0.1.0 // indirect
1515
github.com/fogleman/gg v1.3.0 // indirect

graph.png

-66.7 KB
Loading

internal/visualizer/graphviz.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"opennetworktools/netmap/internal/utils"
99
"os"
1010
"path/filepath"
11+
"strings"
1112

1213
"aqwari.net/xml/xmltree"
1314
"github.com/goccy/go-graphviz"
@@ -42,11 +43,12 @@ func SaveTopologyWithGraphviz(ctx context.Context, networkMap *NetworkMap, times
4243

4344
// Create nodes
4445
for device := range networkMap.Devices {
45-
node, err := graph.CreateNodeByName(utils.TruncateString(device, 8))
46+
node, err := graph.CreateNodeByName(device)
4647
if err != nil {
4748
fmt.Println("Error creating node:", err)
4849
continue
4950
}
51+
node.SetLabel(utils.TruncateString(device, 3))
5052
node.SetShape(cgraph.EllipseShape)
5153
node.SetStyle(cgraph.FilledNodeStyle)
5254
nodes[device] = node
@@ -57,11 +59,12 @@ func SaveTopologyWithGraphviz(ctx context.Context, networkMap *NetworkMap, times
5759
for _, edge := range edges {
5860
neighbor := edge.Neighbor
5961
if nodes[neighbor] == nil {
60-
node, err := graph.CreateNodeByName(utils.TruncateString(neighbor, 8))
62+
node, err := graph.CreateNodeByName(neighbor)
6163
if err != nil {
6264
fmt.Println("Error creating node:", err)
6365
continue
6466
}
67+
node.SetLabel(utils.TruncateString(neighbor, 3))
6568
node.SetShape(cgraph.EllipseShape)
6669
node.SetStyle(cgraph.FilledNodeStyle)
6770
nodes[neighbor] = node
@@ -72,7 +75,7 @@ func SaveTopologyWithGraphviz(ctx context.Context, networkMap *NetworkMap, times
7275
fmt.Println("Error creating edge:", err)
7376
continue
7477
}
75-
e.SetLabel(fmt.Sprintf("%s %s", edge.LocalPort, edge.NeighborPort))
78+
e.SetLabel(fmt.Sprintf("%s - %s", formatEdgeName(edge.LocalPort), formatEdgeName(edge.NeighborPort)))
7679
}
7780
}
7881

@@ -167,3 +170,11 @@ func renderOutputToFilename(filePath string, outData []byte) error {
167170

168171
return nil
169172
}
173+
174+
func formatEdgeName(name string) string {
175+
if strings.Contains(name, ".") {
176+
parts := strings.Split(name, ".")
177+
return parts[0]
178+
}
179+
return name
180+
}

0 commit comments

Comments
 (0)