From a39a7c6e0fb70d6784d4a74d3e2f39ee1bb0315e Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Wed, 8 Jun 2022 21:42:40 +0000 Subject: [PATCH 1/2] Add condition message to event message If you're using some monitoring solution that aggregates events from your Kubernetes cluster, having the underlying reason why a condition triggered could be very useful, especially if you are using custom plugin monitors. Co-authored-by: Micah Norman Signed-off-by: Ryan Eschinger --- pkg/custompluginmonitor/custom_plugin_monitor.go | 1 + pkg/systemlogmonitor/log_monitor.go | 1 + pkg/systemlogmonitor/log_monitor_test.go | 1 + pkg/util/helpers.go | 4 ++-- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/custompluginmonitor/custom_plugin_monitor.go b/pkg/custompluginmonitor/custom_plugin_monitor.go index 88ea084a..0c524872 100644 --- a/pkg/custompluginmonitor/custom_plugin_monitor.go +++ b/pkg/custompluginmonitor/custom_plugin_monitor.go @@ -232,6 +232,7 @@ func (c *customPluginMonitor) generateStatus(result cpmtypes.Result) *types.Stat condition.Type, status, newReason, + newMessage, timestamp, ) diff --git a/pkg/systemlogmonitor/log_monitor.go b/pkg/systemlogmonitor/log_monitor.go index ffe25f25..5528a22a 100644 --- a/pkg/systemlogmonitor/log_monitor.go +++ b/pkg/systemlogmonitor/log_monitor.go @@ -192,6 +192,7 @@ func (l *logMonitor) generateStatus(logs []*logtypes.Log, rule systemlogtypes.Ru condition.Type, types.True, rule.Reason, + message, timestamp, )) } diff --git a/pkg/systemlogmonitor/log_monitor_test.go b/pkg/systemlogmonitor/log_monitor_test.go index e68aaa4d..ac18e9e1 100644 --- a/pkg/systemlogmonitor/log_monitor_test.go +++ b/pkg/systemlogmonitor/log_monitor_test.go @@ -84,6 +84,7 @@ func TestGenerateStatusForConditions(t *testing.T) { testConditionA, types.True, "test reason", + "test message 1\ntest message 2", time.Unix(1000, 1000), )}, Conditions: []types.Condition{ diff --git a/pkg/util/helpers.go b/pkg/util/helpers.go index 22528d6e..cdacd952 100644 --- a/pkg/util/helpers.go +++ b/pkg/util/helpers.go @@ -23,12 +23,12 @@ import ( ) // GenerateConditionChangeEvent generates an event for condition change. -func GenerateConditionChangeEvent(t string, status types.ConditionStatus, reason string, timestamp time.Time) types.Event { +func GenerateConditionChangeEvent(t string, status types.ConditionStatus, reason, message string, timestamp time.Time) types.Event { return types.Event{ Severity: types.Info, Timestamp: timestamp, Reason: reason, - Message: fmt.Sprintf("Node condition %s is now: %s, reason: %s", t, status, reason), + Message: fmt.Sprintf("Node condition %s is now: %s, reason: %s, message: %s", t, status, reason, message), } } From b1bd8e74241f10be30549606603bb025c9508455 Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Thu, 9 Jun 2022 17:18:30 +0000 Subject: [PATCH 2/2] Use %q instead of %s --- pkg/util/helpers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/util/helpers.go b/pkg/util/helpers.go index cdacd952..d58e88cd 100644 --- a/pkg/util/helpers.go +++ b/pkg/util/helpers.go @@ -28,7 +28,7 @@ func GenerateConditionChangeEvent(t string, status types.ConditionStatus, reason Severity: types.Info, Timestamp: timestamp, Reason: reason, - Message: fmt.Sprintf("Node condition %s is now: %s, reason: %s, message: %s", t, status, reason, message), + Message: fmt.Sprintf("Node condition %s is now: %s, reason: %s, message: %q", t, status, reason, message), } }