Skip to content
This repository was archived by the owner on Aug 9, 2023. It is now read-only.

Commit 47b91cd

Browse files
author
Bjørn
authored
Add issue_type label (#50)
Currently it is not possible to separate vulnerability metrics from license issue metrics. License issues was added in afdb810 as a side effect of changing the Snyk API endpoint. This change adds an issue_type label to the exporters metric making it possible to inspect issues related to license or vulnerabilities explicitly.
1 parent afdb810 commit 47b91cd

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ The API results are aggregated and recorded on the `snyk_vulnerabiilities_total`
7575
- `organization` - The organization where the vulnerable project exists
7676
- `project` - The project with a vulnerability
7777
- `severity` - The severity of the vulnerability, can be `high`, `medium` and `low`
78+
- `issue_type` - The type of issue, e.g. `vuln`, `license`
7879
- `issue_title` - The issue title of the vulnerability, e.g. `Denial os Service (DoS)`. Can be the CVE if the vulnerability is not named by Snyk
7980
- `ignored` - The issue is ignored in Snyk.
8081
- `upgradeable` - The issue can be fixed by upgrading to a later version of the dependency.
@@ -83,8 +84,9 @@ The API results are aggregated and recorded on the `snyk_vulnerabiilities_total`
8384
Here is an example.
8485

8586
```
86-
snyk_vulnerabilities_total{organization="my-org",project="my-app",severity="high",issue_title="Privilege Escalation",ignored="false",upgradeable="false",patchable="false"} 1.0
87-
snyk_vulnerabilities_total{organization="my-org",project="my-app",severity="low",issue_title="Sandbox (chroot) Escape",ignored="true",upgradeable="false",patchable="false"} 2.0
87+
snyk_vulnerabilities_total{organization="my-org",project="my-app",severity="high",issue_type="vuln",issue_title="Privilege Escalation",ignored="false",upgradeable="false",patchable="false"} 1.0
88+
snyk_vulnerabilities_total{organization="my-org",project="my-app",severity="low",issue_type="vuln",issue_title="Sandbox (chroot) Escape",ignored="true",upgradeable="false",patchable="false"} 2.0
89+
snyk_vulnerabilities_total{organization="my-org",project="my-app",severity="medium",issue_type="license",issue_title="MPL-2.0 license",ignored="true",upgradeable="false",patchable="false"} 1
8890
```
8991

9092
# Build

main.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
const (
2222
projectLabel = "project"
23+
issueTypeLabel = "issue_type"
2324
issueTitleLabel = "issue_title"
2425
severityLabel = "severity"
2526
organizationLabel = "organization"
@@ -34,7 +35,7 @@ var (
3435
Name: "snyk_vulnerabilities_total",
3536
Help: "Gauge of Snyk vulnerabilities",
3637
},
37-
[]string{organizationLabel, projectLabel, issueTitleLabel, severityLabel, ignoredLabel, upgradeableLabel, patchableLabel},
38+
[]string{organizationLabel, projectLabel, issueTypeLabel, issueTitleLabel, severityLabel, ignoredLabel, upgradeableLabel, patchableLabel},
3839
)
3940
)
4041

@@ -263,7 +264,7 @@ func register(results []gaugeResult) {
263264
vulnerabilityGauge.Reset()
264265
for _, r := range results {
265266
for _, result := range r.results {
266-
vulnerabilityGauge.WithLabelValues(r.organization, r.project, result.title, result.severity, strconv.FormatBool(result.ignored), strconv.FormatBool(result.upgradeable), strconv.FormatBool(result.patchable)).Set(float64(result.count))
267+
vulnerabilityGauge.WithLabelValues(r.organization, r.project, result.issueType, result.title, result.severity, strconv.FormatBool(result.ignored), strconv.FormatBool(result.upgradeable), strconv.FormatBool(result.patchable)).Set(float64(result.count))
267268
}
268269
}
269270
}
@@ -309,6 +310,7 @@ func collect(ctx context.Context, client *client, organization org) ([]gaugeResu
309310
}
310311

311312
type aggregateResult struct {
313+
issueType string
312314
title string
313315
severity string
314316
ignored bool
@@ -318,7 +320,7 @@ type aggregateResult struct {
318320
}
319321

320322
func aggregationKey(i issue) string {
321-
return fmt.Sprintf("%s_%s_%t_%t_%t", i.IssueData.Severity, i.IssueData.Title, i.Ignored, i.FixInfo.Upgradeable, i.FixInfo.Patchable)
323+
return fmt.Sprintf("%s_%s_%s_%t_%t_%t", i.IssueData.Severity, i.IssueType, i.IssueData.Title, i.Ignored, i.FixInfo.Upgradeable, i.FixInfo.Patchable)
322324
}
323325

324326
func aggregateIssues(issues []issue) []aggregateResult {
@@ -328,6 +330,7 @@ func aggregateIssues(issues []issue) []aggregateResult {
328330
aggregate, ok := aggregateResults[aggregationKey(issue)]
329331
if !ok {
330332
aggregate = aggregateResult{
333+
issueType: issue.IssueType,
331334
title: issue.IssueData.Title,
332335
severity: issue.IssueData.Severity,
333336
count: 0,

snyk.go

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ type issuesResponse struct {
137137

138138
type issue struct {
139139
ID string `json:"id,omitempty"`
140+
IssueType string `json:"issueType"`
140141
IssueData issueData `json:"issueData,omitempty"`
141142
Ignored bool `json:"isIgnored"`
142143
FixInfo fixInfo `json:"fixInfo,omitempty"`

0 commit comments

Comments
 (0)