-
Notifications
You must be signed in to change notification settings - Fork 0
/
isisnbr.go
70 lines (63 loc) · 1.42 KB
/
isisnbr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package nettable
import (
"io"
"net"
"github.com/olekukonko/tablewriter"
"github.com/pkg/errors"
)
// Inbrs contains a list of IS-IS neighbors
type Inbrs struct {
list []*inbr
}
type inbr struct {
remoteID string
fwAddress net.IP
local
}
type local struct {
hostname string
intName string
area string
}
func (d *Inbrs) Read(r io.Reader) error {
data := new(ISISNbr)
err := decodeTelemetry(data, r)
if err != nil {
return errors.Wrap(err, "error decoding JSON file")
}
for _, b := range data.Rows {
i := new(inbr)
// Hostname
i.hostname = data.Telemetry.NodeIDStr
// Interface Name
i.intName = b.Content.LocalInterface
// Area
aa := b.Content.NeighborActiveAreaAddresses
if len(aa) > 0 {
i.area = aa[0].Value
}
// Remote SystemID
i.remoteID = b.Content.NeighborSystemID
af := b.Content.NeighborPerAddressFamilyData
if len(af) > 0 {
// FW Address neighbor
i.fwAddress = af[0].Ipv6.NextHop
}
d.list = append(d.list, i)
}
return nil
}
// DisplayTable pretty prints the info populated.
func (d *Inbrs) DisplayTable(w io.Writer) {
var data [][]string
for _, s := range d.list {
data = append(data, []string{s.hostname, s.intName, s.area,
s.remoteID, s.fwAddress.String()})
}
table := tablewriter.NewWriter(w)
table.SetHeader([]string{"hostname", "interface", "area", "remote id", "FW address"})
for _, v := range data {
table.Append(v)
}
table.Render() // Send output
}