mirror of
https://github.com/kyverno/policy-reporter.git
synced 2024-12-14 11:57:32 +00:00
fix result.timestamp parsing (#26)
Signed-off-by: Frank Jogeleit <fj@move-elevator.de>
This commit is contained in:
parent
6e33bde8ef
commit
9e1a1e35c2
5 changed files with 54 additions and 27 deletions
|
@ -1,5 +1,13 @@
|
|||
# Changelog
|
||||
|
||||
## 1.2.2
|
||||
|
||||
* Fix PolicyReportResult.timestamp parsing
|
||||
|
||||
## 1.2.1
|
||||
|
||||
* Support PolicyReportResult.status as well as PolicyReportResult.result for newer CRD versions
|
||||
|
||||
## 1.2.0
|
||||
|
||||
* Support for (Cluster)PolicyReport CRD Properties in Target Output
|
||||
|
|
|
@ -5,8 +5,8 @@ description: |
|
|||
It creates Prometheus Metrics and can send rule validation events to different targets like Loki, Elasticsearch, Slack or Discord
|
||||
|
||||
type: application
|
||||
version: 1.2.1
|
||||
appVersion: 1.2.1
|
||||
version: 1.2.2
|
||||
appVersion: 1.2.2
|
||||
|
||||
dependencies:
|
||||
- name: monitoring
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
image:
|
||||
repository: fjogeleit/policy-reporter
|
||||
pullPolicy: IfNotPresent
|
||||
tag: 1.2.1
|
||||
tag: 1.2.2
|
||||
|
||||
imagePullSecrets: []
|
||||
|
||||
|
|
|
@ -172,12 +172,7 @@ func (m *mapper) mapResult(result map[string]interface{}) report.Result {
|
|||
r.Category = category.(string)
|
||||
}
|
||||
|
||||
if created, ok := result["timestamp"]; ok {
|
||||
time, err := time.Parse("2006-01-02T15:04:05Z", created.(string))
|
||||
if err == nil {
|
||||
r.Timestamp = time
|
||||
}
|
||||
}
|
||||
r.Timestamp = convertTimestamp(result)
|
||||
|
||||
if props, ok := result["properties"]; ok {
|
||||
if properties, ok := props.(map[string]interface{}); ok {
|
||||
|
@ -190,6 +185,24 @@ func (m *mapper) mapResult(result map[string]interface{}) report.Result {
|
|||
return r
|
||||
}
|
||||
|
||||
func convertTimestamp(result map[string]interface{}) time.Time {
|
||||
timestamp, ok := result["timestamp"]
|
||||
if !ok {
|
||||
return time.Now().UTC()
|
||||
}
|
||||
|
||||
seconds, ok := timestamp.(map[string]interface{})["seconds"]
|
||||
|
||||
switch s := seconds.(type) {
|
||||
case int64:
|
||||
return time.Unix(s, 0).UTC()
|
||||
case int:
|
||||
return time.Unix(int64(s), 0).UTC()
|
||||
default:
|
||||
return time.Now().UTC()
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mapper) resolvePriority(policy string, severity report.Severity) report.Priority {
|
||||
if priority, ok := m.priorityMap[policy]; ok {
|
||||
return report.NewPriority(priority)
|
||||
|
|
|
@ -33,7 +33,9 @@ var policyMap = map[string]interface{}{
|
|||
"scored": true,
|
||||
"policy": "required-label",
|
||||
"rule": "app-label-required",
|
||||
"timestamp": "2021-02-23T15:10:00Z",
|
||||
"timestamp": map[string]interface{}{
|
||||
"seconds": 1614093000,
|
||||
},
|
||||
"category": "test",
|
||||
"severity": "high",
|
||||
"resources": []interface{}{
|
||||
|
@ -53,6 +55,9 @@ var policyMap = map[string]interface{}{
|
|||
"message": "message 2",
|
||||
"status": "fail",
|
||||
"scored": true,
|
||||
"timestamp": map[string]interface{}{
|
||||
"seconds": int64(1614093000),
|
||||
},
|
||||
"policy": "priority-test",
|
||||
"resources": []interface{}{},
|
||||
},
|
||||
|
@ -88,6 +93,7 @@ var clusterPolicyMap = map[string]interface{}{
|
|||
"rule": "app-label-required",
|
||||
"category": "test",
|
||||
"severity": "high",
|
||||
"timestamp": map[string]interface{}{"seconds": ""},
|
||||
"resources": []interface{}{
|
||||
map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
|
|
Loading…
Reference in a new issue