-
Notifications
You must be signed in to change notification settings - Fork 0
/
isisint.go
94 lines (86 loc) · 2.05 KB
/
isisint.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package nettable
import (
"fmt"
"io"
"net"
"github.com/olekukonko/tablewriter"
"github.com/pkg/errors"
)
// Iints contains a list of IS-IS interfaces
type Iints struct {
list []*iint
}
type iint struct {
hostname string
name string
config string
status string
fwAddress net.IP
prefixes []prefix
}
type neighbor struct {
remoteID string
metric uint32
mtid string
}
type prefix struct {
ip string
mask uint8
metric uint32
}
func (d *Iints) Read(r io.Reader) error {
data := new(ISISInt)
err := decodeTelemetry(data, r)
if err != nil {
return errors.Wrap(err, "error decoding JSON file")
}
for _, b := range data.Rows {
i := new(iint)
// Hostname
i.hostname = data.Telemetry.NodeIDStr
// Interface Name
i.name = b.Keys.InterfaceName
// Config Status
i.config = b.Content.InterfaceStatusAndData.Enabled.AdjacencyFormStatus.Status
af := b.Content.InterfaceStatusAndData.Enabled.PerAddressFamilyData
if len(af) > 0 {
// Protocol Status
afd := af[0].AfStatus.AfData
i.status = afd.ProtocolStatus.Status
address := afd.ForwardingAddressStatus.ForwardingAddressData.ForwardingAddress
if len(address) > 0 {
// Forwarding Address
i.fwAddress = address[0].Ipv6.Value
}
pfxs := afd.PrefixStatus.PrefixData.Prefix
if len(pfxs) > 0 {
// Prefix
for _, pfx := range pfxs {
i.prefixes = append(i.prefixes, prefix{
ip: pfx.Ipv6.Prefix.String(),
mask: pfx.Ipv6.PrefixLength,
})
}
}
}
d.list = append(d.list, i)
}
return nil
}
// DisplayTable pretty prints the info populated.
func (d *Iints) DisplayTable(w io.Writer) {
var data [][]string
for _, s := range d.list {
for _, p := range s.prefixes {
pf := p.ip + "/" + fmt.Sprint(p.mask)
data = append(data, []string{s.hostname, s.name, s.config,
s.status, s.fwAddress.String(), pf})
}
}
table := tablewriter.NewWriter(w)
table.SetHeader([]string{"hostname", "interface", "config", "status", "FW address", "Prefix"})
for _, v := range data {
table.Append(v)
}
table.Render() // Send output
}