Skip to content

Commit b7e41b1

Browse files
committed
adding netconf as a feature czerwonk#2
1 parent 5b9a3dd commit b7e41b1

3 files changed

Lines changed: 43 additions & 24 deletions

File tree

accounting/collector.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,16 @@ func (c *accountingCollector) accountingFlows(client *rpc.Client) (*AccountingFl
126126

127127
func (c *accountingCollector) accountingFailures(client *rpc.Client) (*AccountingError, error) {
128128
var x = AccountingFlowErrorRpc{}
129-
// err := client.RunCommandAndParse("show services accounting errors inline-jflow fpc-slot 0", &x)
130-
err := client.RunCommandAndParse("<get-service-accounting-error-inline-jflow-information><inline-jflow-error-information>0</inline-jflow-error-information></get-service-accounting-error-inline-jflow-information>", &x)
131-
if err != nil {
132-
return nil, err
129+
if client.Netconf {
130+
err := client.RunCommandAndParse("<get-service-accounting-error-inline-jflow-information><inline-jflow-error-information>0</inline-jflow-error-information></get-service-accounting-error-inline-jflow-information>", &x)
131+
if err != nil {
132+
return nil, err
133+
}
134+
} else {
135+
err := client.RunCommandAndParse("show services accounting errors inline-jflow fpc-slot 0", &x)
136+
if err != nil {
137+
return nil, err
138+
}
133139
}
134140

135141
return &AccountingError{

bgp/collector.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,16 @@ func (c *bgpCollector) collect(client *rpc.Client, ch chan<- prometheus.Metric,
7979
var cmd strings.Builder
8080
if client.Netconf {
8181
cmd.WriteString("<get-bgp-neighbor-information/>")
82-
err := client.RunCommandAndParse(cmd.String(), &x)
83-
if err != nil {
84-
return err
85-
}
8682
} else {
8783
cmd.WriteString("show bgp neighbor")
8884
if c.LogicalSystem != "" {
8985
cmd.WriteString(" logical-system " + c.LogicalSystem)
9086
}
91-
err := client.RunCommandAndParse(cmd.String(), &x)
92-
if err != nil {
93-
return err
94-
}
87+
}
88+
89+
err := client.RunCommandAndParse(cmd.String(), &x)
90+
if err != nil {
91+
return err
9592
}
9693

9794

fpc/collector.go

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,20 @@ func (c *fpcCollector) CollectFPCDetail(client *rpc.Client, ch chan<- prometheus
129129
// Collect collects metrics from JunOS
130130
func (c *fpcCollector) CollectFPC(client *rpc.Client, ch chan<- prometheus.Metric, labelValues []string) error {
131131
r := RpcReply{}
132-
// err := client.RunCommandAndParseWithParser("show chassis fpc", func(b []byte) error {
133-
err := client.RunCommandAndParseWithParser("<get-fpc-information/>", func(b []byte) error {
134-
return parseXML(b, &r)
135-
})
136-
if err != nil {
137-
return err
132+
if client.Netconf {
133+
err := client.RunCommandAndParseWithParser("<get-fpc-information/>", func(b []byte) error {
134+
return parseXML(b, &r)
135+
})
136+
if err != nil {
137+
return err
138+
}
139+
} else {
140+
err := client.RunCommandAndParseWithParser("show chassis fpc", func(b []byte) error {
141+
return parseXML(b, &r)
142+
})
143+
if err != nil {
144+
return err
145+
}
138146
}
139147

140148
for _, r := range r.MultiRoutingEngineResults.RoutingEngine {
@@ -148,12 +156,20 @@ func (c *fpcCollector) CollectFPC(client *rpc.Client, ch chan<- prometheus.Metri
148156

149157
func (c *fpcCollector) CollectPIC(client *rpc.Client, ch chan<- prometheus.Metric, labelValues []string) error {
150158
r := RpcReply{}
151-
// err := client.RunCommandAndParseWithParser("show chassis fpc pic-status", func(b []byte) error {
152-
err := client.RunCommandAndParseWithParser("<get-pic-information/>", func(b []byte) error {
153-
return parseXML(b, &r)
154-
})
155-
if err != nil {
156-
return err
159+
if client.Netconf {
160+
err := client.RunCommandAndParseWithParser("<get-pic-information/>", func(b []byte) error {
161+
return parseXML(b, &r)
162+
})
163+
if err != nil {
164+
return err
165+
}
166+
} else {
167+
err := client.RunCommandAndParseWithParser("show chassis fpc pic-status", func(b []byte) error {
168+
return parseXML(b, &r)
169+
})
170+
if err != nil {
171+
return err
172+
}
157173
}
158174
for _, r := range r.MultiRoutingEngineResults.RoutingEngine {
159175
labels := append(labelValues, r.Name)

0 commit comments

Comments
 (0)