-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add VulnerabilityStats() to for kernel vulnerabilities
See prometheus/node_exporter#1046 Signed-off-by: Ivan Babrou <[email protected]>
- Loading branch information
1 parent
8f55e60
commit 7c1ba21
Showing
2 changed files
with
86 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package cpu | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
const ( | ||
notAffectedSysFsValue = "Not Affected" | ||
vulnerableSysFsValue = "Vulnerable" | ||
mitigationSysFsValue = "Mitigation" | ||
) | ||
|
||
const ( | ||
NotAffected VulnerabilityState = "not affected" | ||
Vulnerable VulnerabilityState = "vulnerable" | ||
Mitigation VulnerabilityState = "mitigation" | ||
) | ||
|
||
type VulnerabilityState string | ||
|
||
func (s VulnerabilityState) String() string { | ||
return string(s) | ||
} | ||
|
||
type Vulnerability struct { | ||
CodeName string | ||
State VulnerabilityState | ||
Mitigation string | ||
} | ||
|
||
func ParseVulnerability(name, value string) (Vulnerability, error) { | ||
v := Vulnerability{CodeName: name} | ||
|
||
if value == notAffectedSysFsValue { | ||
v.State = NotAffected | ||
return v, nil | ||
} | ||
|
||
if strings.HasPrefix(value, vulnerableSysFsValue) { | ||
v.State = Vulnerable | ||
v.Mitigation = strings.TrimPrefix(strings.TrimPrefix(value, vulnerableSysFsValue), ": ") | ||
return v, nil | ||
} | ||
|
||
if strings.HasPrefix(value, mitigationSysFsValue) { | ||
v.State = Mitigation | ||
v.Mitigation = strings.TrimPrefix(strings.TrimPrefix(value, mitigationSysFsValue), ": ") | ||
return v, nil | ||
} | ||
|
||
return v, fmt.Errorf("unknown vulnerability state for %s: %s", name, value) | ||
} |
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