-
Notifications
You must be signed in to change notification settings - Fork 109
Feature/sandbox information #333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Philldomd
wants to merge
19
commits into
prometheus-community:main
Choose a base branch
from
Philldomd:feature/sandbox-information
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b3ccf0f
Started implementing sandbox probes
Philldomd 6e70fec
New probe: sandbox stats
Philldomd 84114a2
Correct testdata and fixes
Philldomd dae1423
Merge branch 'main' into feature/sandbox-information
SuperQ 691b446
Merge branch 'feature/sandbox-information' of github.com:Philldomd/fo…
Philldomd aef7cd0
Renamed metrics
Philldomd 5fadbc6
Renamed metrics in readme
Philldomd 4ba1b59
Merge branch 'main' into feature/sandbox-information
Philldomd 103454c
Merge branch 'main' into feature/sandbox-information
Philldomd 6eb3cc6
Update pkg/probe/system_sandbox_connection.go
Philldomd 63dc342
Update pkg/probe/system_sandbox_status.go
Philldomd b97b9ca
Merge branch 'main' into feature/sandbox-information
Philldomd fd4d0fa
Lint
Philldomd 7682cb4
Merge branch 'feature/sandbox-information' of github.com:Philldomd/fo…
Philldomd c0810a2
Lint 2.0
Philldomd f85b1f9
Merge branch 'main' into feature/sandbox-information
SuperQ f7373de
Merge branch 'main' into feature/sandbox-information
Philldomd bb71c99
Merge branch 'main' into feature/sandbox-information
Philldomd a303cbf
Latest version
Philldomd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,58 @@ | ||
| // Copyright 2025 The Prometheus Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package probe | ||
|
|
||
| import ( | ||
| "log" | ||
|
|
||
| "github.com/prometheus-community/fortigate_exporter/pkg/http" | ||
| "github.com/prometheus/client_golang/prometheus" | ||
| ) | ||
|
|
||
| func probeSystemSandboxConnection(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) { | ||
| var ( | ||
| connectionStatus = prometheus.NewDesc( | ||
| "fortigate_sandbox_connection_status", | ||
| "Sandbox connection status, (unreachable=0, reachable=1, disabled=-1)", | ||
| []string{"type"}, nil, | ||
| ) | ||
| ) | ||
|
|
||
| type SystemSandboxConnection struct { | ||
| Status string `json:"status"` | ||
| Type string `json:"type"` | ||
| } | ||
|
|
||
| type SystemSandboxConnectionResult struct { | ||
| Results []SystemSandboxConnection `json:"results"` | ||
| } | ||
| var res SystemSandboxConnectionResult | ||
| if err := c.Get("api/v2/monitor/system/sandbox/connection","", &res); err != nil { | ||
| log.Printf("Warning: %v", err) | ||
| return nil, false | ||
| } | ||
|
|
||
| m := []prometheus.Metric{} | ||
| for _, r := range res.Results { | ||
| switch r.Status { | ||
| case "unreachable": | ||
| m = append(m, prometheus.MustNewConstMetric(connectionStatus, prometheus.GaugeValue, 0, r.Type)) | ||
| case "reachable": | ||
| m = append(m, prometheus.MustNewConstMetric(connectionStatus, prometheus.GaugeValue, 1, r.Type)) | ||
| case "disabled": | ||
| m = append(m, prometheus.MustNewConstMetric(connectionStatus, prometheus.GaugeValue, -1, r.Type)) | ||
| } | ||
| } | ||
| return m, true | ||
| } | ||
This file contains hidden or 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,41 @@ | ||
| // Copyright 2025 The Prometheus Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package probe | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus" | ||
| "github.com/prometheus/client_golang/prometheus/testutil" | ||
| ) | ||
|
|
||
| func TestSystemSandboxConnection(t *testing.T) { | ||
| c := newFakeClient() | ||
| c.prepare("api/v2/monitor/system/sandbox/connection", "testdata/system-sandbox-connection.jsonnet") | ||
| r := prometheus.NewPedanticRegistry() | ||
| if !testProbe(probeSystemSandboxConnection, c, r) { | ||
| t.Errorf("probeSystemSandboxConnection() returned non-success") | ||
| } | ||
|
|
||
| em := ` | ||
| # HELP fortigate_sandbox_connection_status Sandbox connection status, (unreachable=0, reachable=1, disabled=-1) | ||
| # TYPE fortigate_sandbox_connection_status gauge | ||
| fortigate_sandbox_connection_status{type="appliance"} 1 | ||
| ` | ||
|
|
||
| if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil { | ||
| t.Fatalf("metric compare: err %v", err) | ||
| } | ||
| } |
This file contains hidden or 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,86 @@ | ||
| // Copyright 2025 The Prometheus Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package probe | ||
|
|
||
| import ( | ||
| "log" | ||
|
|
||
| "github.com/prometheus-community/fortigate_exporter/pkg/http" | ||
| "github.com/prometheus/client_golang/prometheus" | ||
| ) | ||
|
|
||
| func probeSystemSandboxStats (c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) { | ||
| var ( | ||
| numberDetected = prometheus.NewDesc( | ||
| "fortigate_sandbox_stats_detected", | ||
Philldomd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "Number of detected files", | ||
| []string{}, nil, | ||
| ) | ||
| numberClean = prometheus.NewDesc( | ||
| "fortigate_sandbox_stats_clean", | ||
| "Number of clean files", | ||
| []string{}, nil, | ||
| ) | ||
| numberRiskLow = prometheus.NewDesc( | ||
| "fortigate_sandbox_stats_risk_low", | ||
| "Number of low risk files detected", | ||
| []string{}, nil, | ||
| ) | ||
| numberRiskMedium = prometheus.NewDesc( | ||
| "fortigate_sandbox_stats_risk_medium", | ||
| "Number of medium risk files detected", | ||
| []string{}, nil, | ||
| ) | ||
| numberRiskHigh = prometheus.NewDesc( | ||
| "fortigate_sandbox_stats_risk_high", | ||
| "Number of high risk files detected", | ||
| []string{}, nil, | ||
| ) | ||
| numberSubmitted = prometheus.NewDesc( | ||
| "fortigate_sandbox_stats_submitted", | ||
| "Number of submitted files", | ||
| []string{}, nil, | ||
| ) | ||
| ) | ||
|
|
||
| type SystemSandboxStats struct { | ||
| Detected float64 | ||
| Clean float64 | ||
| Low float64 `json:"risk_low"` | ||
| Medium float64 `json:"risk_med"` | ||
| High float64 `json:"risk_high"` | ||
| Submitted float64 | ||
| } | ||
|
|
||
| type SystemSandboxStatsResult struct { | ||
| Results []SystemSandboxStats `json:"results"` | ||
| } | ||
|
|
||
| var res SystemSandboxStatsResult | ||
| if err := c.Get("api/v2/monitor/system/sandbox/stats","", &res); err != nil { | ||
| log.Printf("Warning: %v", err) | ||
| return nil, false | ||
| } | ||
| var m = []prometheus.Metric{} | ||
|
|
||
| for _, r := range res.Results { | ||
| m = append(m, prometheus.MustNewConstMetric(numberDetected, prometheus.CounterValue, r.Detected)) | ||
| m = append(m, prometheus.MustNewConstMetric(numberClean, prometheus.CounterValue, r.Clean)) | ||
| m = append(m, prometheus.MustNewConstMetric(numberRiskLow, prometheus.CounterValue, r.Low)) | ||
| m = append(m, prometheus.MustNewConstMetric(numberRiskMedium, prometheus.CounterValue, r.Medium)) | ||
| m = append(m, prometheus.MustNewConstMetric(numberRiskHigh, prometheus.CounterValue, r.High)) | ||
| m = append(m, prometheus.MustNewConstMetric(numberSubmitted, prometheus.CounterValue, r.Submitted)) | ||
| } | ||
| return m, true | ||
| } | ||
This file contains hidden or 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,56 @@ | ||
| // Copyright 2025 The Prometheus Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package probe | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus" | ||
| "github.com/prometheus/client_golang/prometheus/testutil" | ||
| ) | ||
|
|
||
| func TestSystemSandboxStats(t *testing.T) { | ||
| c := newFakeClient() | ||
| c.prepare("api/v2/monitor/system/sandbox/stats", "testdata/system-sandbox-stats.jsonnet") | ||
| r := prometheus.NewPedanticRegistry() | ||
| if !testProbe(probeSystemSandboxStats, c, r) { | ||
| t.Errorf("probeSystemSandboxStats() returned non-success") | ||
| } | ||
|
|
||
| em := ` | ||
| # HELP fortigate_sandbox_stats_clean Number of clean files | ||
| # TYPE fortigate_sandbox_stats_clean counter | ||
| fortigate_sandbox_stats_clean 45120 | ||
| # HELP fortigate_sandbox_stats_detected Number of detected files | ||
| # TYPE fortigate_sandbox_stats_detected counter | ||
| fortigate_sandbox_stats_detected 10 | ||
| # HELP fortigate_sandbox_stats_risk_high Number of high risk files detected | ||
| # TYPE fortigate_sandbox_stats_risk_high counter | ||
| fortigate_sandbox_stats_risk_high 5 | ||
| # HELP fortigate_sandbox_stats_risk_low Number of low risk files detected | ||
| # TYPE fortigate_sandbox_stats_risk_low counter | ||
| fortigate_sandbox_stats_risk_low 3 | ||
| # HELP fortigate_sandbox_stats_risk_medium Number of medium risk files detected | ||
| # TYPE fortigate_sandbox_stats_risk_medium counter | ||
| fortigate_sandbox_stats_risk_medium 2 | ||
| # HELP fortigate_sandbox_stats_submitted Number of submitted files | ||
| # TYPE fortigate_sandbox_stats_submitted counter | ||
| fortigate_sandbox_stats_submitted 45130 | ||
| ` | ||
|
|
||
| if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil { | ||
| t.Fatalf("metric compare: err %v", err) | ||
| } | ||
| } |
This file contains hidden or 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,56 @@ | ||
| // Copyright 2025 The Prometheus Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package probe | ||
|
|
||
| import ( | ||
| "log" | ||
|
|
||
| "github.com/prometheus-community/fortigate_exporter/pkg/http" | ||
| "github.com/prometheus/client_golang/prometheus" | ||
| ) | ||
|
|
||
| func probeSystemSandboxStatus(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) { | ||
| var ( | ||
| signatureCount = prometheus.NewDesc( | ||
| "fortigate_sandbox_status_signature_count", | ||
| "Sandbox signature counts", | ||
| []string{"server", "region", "version", "type"}, nil, | ||
| ) | ||
| ) | ||
|
|
||
| type SystemSandboxStatus struct { | ||
| Server string `json:"server"` | ||
| Type string `json:"type"` | ||
| Region string `json:"cloud_region"` | ||
| Version string `json:"malware_package_version"` | ||
| Count float64 `json:"signatures_count"` | ||
| } | ||
|
|
||
| type SystemSandboxStatusResult struct { | ||
| Results []SystemSandboxStatus `json:"results"` | ||
| } | ||
|
|
||
| var res SystemSandboxStatusResult | ||
| if err := c.Get("api/v2/monitor/system/sandbox/status","", &res); err != nil { | ||
| log.Printf("Warning: %v", err) | ||
| return nil, false | ||
| } | ||
|
|
||
| m := []prometheus.Metric{} | ||
| for _, r := range res.Results { | ||
| m = append(m, prometheus.MustNewConstMetric(signatureCount, prometheus.GaugeValue, r.Count, r.Server, r.Region, r.Version, r.Type)) | ||
| } | ||
|
|
||
| return m, true | ||
| } |
This file contains hidden or 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,41 @@ | ||
| // Copyright 2025 The Prometheus Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package probe | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus" | ||
| "github.com/prometheus/client_golang/prometheus/testutil" | ||
| ) | ||
|
|
||
| func TestSystemSandboxStatus(t *testing.T) { | ||
| c := newFakeClient() | ||
| c.prepare("api/v2/monitor/system/sandbox/status", "testdata/system-sandbox-status.jsonnet") | ||
| r := prometheus.NewPedanticRegistry() | ||
| if !testProbe(probeSystemSandboxStatus, c, r) { | ||
| t.Errorf("probeSystemSandboxStatus() returned non-success") | ||
| } | ||
|
|
||
| em := ` | ||
| # HELP fortigate_sandbox_status_signature_count Sandbox signature counts | ||
| # TYPE fortigate_sandbox_status_signature_count gauge | ||
| fortigate_sandbox_status_signature_count{region="Sweden",server="127.0.0.1",type="cloud",version="v17.0.3"} 252891 | ||
| ` | ||
|
|
||
| if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil { | ||
| t.Fatalf("metric compare: err %v", err) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.