-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #229 from ahuret/main
key passphrase + feature security-ike
- Loading branch information
Showing
8 changed files
with
145 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
package securityike | ||
|
||
import ( | ||
"encoding/xml" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/czerwonk/junos_exporter/pkg/collector" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
const prefix string = "junos_security_ike_" | ||
|
||
var ( | ||
connectedActiveUsers *prometheus.Desc | ||
) | ||
|
||
func init() { | ||
l := []string{"target", "re_name"} | ||
|
||
connectedActiveUsers = prometheus.NewDesc(prefix+"connected_active_users", "Number of connected active users", append(l, "remote_address", "remote_port", "ike_id", "x_auth_username", "x_auth_user_assigned_ip"), nil) | ||
} | ||
|
||
type securityIKECollector struct { | ||
} | ||
|
||
// NewCollector creates a new collector | ||
func NewCollector() collector.RPCCollector { | ||
return &securityIKECollector{} | ||
} | ||
|
||
// Name returns the name of the collector | ||
func (*securityIKECollector) Name() string { | ||
return "Security IKE" | ||
} | ||
|
||
// Describe describes the metrics | ||
func (*securityIKECollector) Describe(ch chan<- *prometheus.Desc) { | ||
ch <- connectedActiveUsers | ||
} | ||
|
||
// Collect collects metrics from JunOS | ||
func (c *securityIKECollector) Collect(client collector.Client, ch chan<- prometheus.Metric, labelValues []string) error { | ||
var x = multiEngineResult{} | ||
err := client.RunCommandAndParseWithParser("show security ike active-peer", func(b []byte) error { | ||
return parseXML(b, &x) | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, re := range x.Results.RoutingEngines { | ||
ls := append(labelValues, re.Name) | ||
activePeersCounters := make(map[string]int) | ||
for _, ap := range re.IKEActivePeersInformation.IKEActivePeers { | ||
saRemotePort := strconv.Itoa(ap.IKESARemotePort) | ||
key := ap.IKESARemoteAddress + saRemotePort + ap.IKEIKEID + ap.IKEXAuthUsername + ap.IKEXAuthUserAssignedIP | ||
if _, exists := activePeersCounters[key]; !exists { | ||
activePeersCounters[key] = 0 | ||
} | ||
activePeersCounters[key] += 1 | ||
ch <- prometheus.MustNewConstMetric(connectedActiveUsers, prometheus.GaugeValue, float64(activePeersCounters[key]), append(ls, ap.IKESARemoteAddress, saRemotePort, ap.IKEIKEID, ap.IKEXAuthUsername, ap.IKEXAuthUserAssignedIP)...) | ||
} | ||
} | ||
|
||
return err | ||
} | ||
|
||
func parseXML(b []byte, res *multiEngineResult) error { | ||
if strings.Contains(string(b), "multi-routing-engine-results") { | ||
return xml.Unmarshal(b, res) | ||
} | ||
|
||
fi := singleEngineResult{} | ||
|
||
err := xml.Unmarshal(b, &fi) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
res.Results.RoutingEngines = []routingEngine{ | ||
{ | ||
Name: "N/A", | ||
IKEActivePeersInformation: fi.IKEActivePeersInformation, | ||
}, | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
package securityike | ||
|
||
import "encoding/xml" | ||
|
||
type multiEngineResult struct { | ||
XMLName xml.Name `xml:"rpc-reply"` | ||
Results routingEngines `xml:"multi-routing-engine-results"` | ||
} | ||
|
||
type routingEngines struct { | ||
RoutingEngines []routingEngine `xml:"multi-routing-engine-item"` | ||
} | ||
|
||
type routingEngine struct { | ||
Name string `xml:"re-name"` | ||
IKEActivePeersInformation ikeActivePeersInformation `xml:"ike-active-peers-information"` | ||
} | ||
|
||
type ikeActivePeersInformation struct { | ||
IKEActivePeers []ikeActivePeer `xml:"ike-active-peers"` | ||
} | ||
|
||
type ikeActivePeer struct { | ||
IKESARemoteAddress string `xml:"ike-sa-remote-address"` | ||
IKESARemotePort int `xml:"ike-sa-remote-port"` | ||
IKEIKEID string `xml:"ike-ike-id"` | ||
IKEXAuthUsername string `xml:"ike-xauth-username"` | ||
IKEXAuthUserAssignedIP string `xml:"ike-xauth-user-assigned-ip"` | ||
} | ||
|
||
type singleEngineResult struct { | ||
XMLName xml.Name `xml:"rpc-reply"` | ||
IKEActivePeersInformation ikeActivePeersInformation `xml:"ike-active-peers-information"` | ||
} |