mirror of
https://github.com/netbirdio/netbird.git
synced 2025-01-23 14:28:51 +01:00
Add posture checks metrics report (#1603)
This commit is contained in:
parent
8d9e1fed5f
commit
d65602f904
@ -157,31 +157,33 @@ func (w *Worker) generatePayload(apiKey string) pushPayload {
|
|||||||
|
|
||||||
func (w *Worker) generateProperties() properties {
|
func (w *Worker) generateProperties() properties {
|
||||||
var (
|
var (
|
||||||
uptime float64
|
uptime float64
|
||||||
accounts int
|
accounts int
|
||||||
expirationEnabled int
|
expirationEnabled int
|
||||||
users int
|
users int
|
||||||
serviceUsers int
|
serviceUsers int
|
||||||
pats int
|
pats int
|
||||||
peers int
|
peers int
|
||||||
peersSSHEnabled int
|
peersSSHEnabled int
|
||||||
setupKeysUsage int
|
setupKeysUsage int
|
||||||
ephemeralPeersSKs int
|
ephemeralPeersSKs int
|
||||||
ephemeralPeersSKUsage int
|
ephemeralPeersSKUsage int
|
||||||
activePeersLastDay int
|
activePeersLastDay int
|
||||||
osPeers map[string]int
|
osPeers map[string]int
|
||||||
userPeers int
|
userPeers int
|
||||||
rules int
|
rules int
|
||||||
rulesProtocol map[string]int
|
rulesProtocol map[string]int
|
||||||
rulesDirection map[string]int
|
rulesDirection map[string]int
|
||||||
groups int
|
rulesWithSrcPostureChecks int
|
||||||
routes int
|
postureChecks int
|
||||||
routesWithRGGroups int
|
groups int
|
||||||
nameservers int
|
routes int
|
||||||
uiClient int
|
routesWithRGGroups int
|
||||||
version string
|
nameservers int
|
||||||
peerActiveVersions []string
|
uiClient int
|
||||||
osUIClients map[string]int
|
version string
|
||||||
|
peerActiveVersions []string
|
||||||
|
osUIClients map[string]int
|
||||||
)
|
)
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
metricsProperties := make(properties)
|
metricsProperties := make(properties)
|
||||||
@ -219,8 +221,13 @@ func (w *Worker) generateProperties() properties {
|
|||||||
rulesDirection["oneway"]++
|
rulesDirection["oneway"]++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(policy.SourcePostureChecks) > 0 {
|
||||||
|
rulesWithSrcPostureChecks++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
postureChecks += len(account.PostureChecks)
|
||||||
|
|
||||||
for _, user := range account.Users {
|
for _, user := range account.Users {
|
||||||
if user.IsServiceUser {
|
if user.IsServiceUser {
|
||||||
serviceUsers++
|
serviceUsers++
|
||||||
@ -286,6 +293,8 @@ func (w *Worker) generateProperties() properties {
|
|||||||
metricsProperties["active_peers_last_day"] = activePeersLastDay
|
metricsProperties["active_peers_last_day"] = activePeersLastDay
|
||||||
metricsProperties["user_peers"] = userPeers
|
metricsProperties["user_peers"] = userPeers
|
||||||
metricsProperties["rules"] = rules
|
metricsProperties["rules"] = rules
|
||||||
|
metricsProperties["rules_with_src_posture_checks"] = rulesWithSrcPostureChecks
|
||||||
|
metricsProperties["posture_checks"] = postureChecks
|
||||||
metricsProperties["groups"] = groups
|
metricsProperties["groups"] = groups
|
||||||
metricsProperties["routes"] = routes
|
metricsProperties["routes"] = routes
|
||||||
metricsProperties["routes_with_routing_groups"] = routesWithRGGroups
|
metricsProperties["routes_with_routing_groups"] = routesWithRGGroups
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
nbdns "github.com/netbirdio/netbird/dns"
|
nbdns "github.com/netbirdio/netbird/dns"
|
||||||
"github.com/netbirdio/netbird/management/server"
|
"github.com/netbirdio/netbird/management/server"
|
||||||
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
||||||
|
"github.com/netbirdio/netbird/management/server/posture"
|
||||||
"github.com/netbirdio/netbird/route"
|
"github.com/netbirdio/netbird/route"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -62,6 +63,7 @@ func (mockDatasource) GetAllAccounts() []*server.Account {
|
|||||||
Protocol: server.PolicyRuleProtocolTCP,
|
Protocol: server.PolicyRuleProtocolTCP,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
SourcePostureChecks: []string{"1"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Routes: map[string]*route.Route{
|
Routes: map[string]*route.Route{
|
||||||
@ -70,6 +72,26 @@ func (mockDatasource) GetAllAccounts() []*server.Account {
|
|||||||
PeerGroups: make([]string, 1),
|
PeerGroups: make([]string, 1),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
PostureChecks: []*posture.Checks{
|
||||||
|
{
|
||||||
|
ID: "1",
|
||||||
|
Name: "test",
|
||||||
|
Checks: posture.ChecksDefinition{
|
||||||
|
NBVersionCheck: &posture.NBVersionCheck{
|
||||||
|
MinVersion: "0.0.1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: "2",
|
||||||
|
Name: "tes2",
|
||||||
|
Checks: posture.ChecksDefinition{
|
||||||
|
NBVersionCheck: &posture.NBVersionCheck{
|
||||||
|
MinVersion: "0.0.2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
Users: map[string]*server.User{
|
Users: map[string]*server.User{
|
||||||
"1": {
|
"1": {
|
||||||
IsServiceUser: true,
|
IsServiceUser: true,
|
||||||
@ -246,4 +268,13 @@ func TestGenerateProperties(t *testing.T) {
|
|||||||
if properties["store_engine"] != server.FileStoreEngine {
|
if properties["store_engine"] != server.FileStoreEngine {
|
||||||
t.Errorf("expected JsonFile, got %s", properties["store_engine"])
|
t.Errorf("expected JsonFile, got %s", properties["store_engine"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if properties["rules_with_src_posture_checks"] != 1 {
|
||||||
|
t.Errorf("expected 1 rules_with_src_posture_checks, got %d", properties["rules_with_src_posture_checks"])
|
||||||
|
}
|
||||||
|
|
||||||
|
if properties["posture_checks"] != 2 {
|
||||||
|
t.Errorf("expected 1 posture_checks, got %d", properties["posture_checks"])
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user