From 2c224e4f44d3097e35d5c3bb5bcb76f486f0699b Mon Sep 17 00:00:00 2001 From: thomashaw Date: Sat, 15 Oct 2022 13:54:50 +0100 Subject: [PATCH] Fixing unescaped ' characters breaking strings in message actioner command generation --- .../alert_actioner/actioners/message_actioner.rb | 6 +++--- .../files/alert_actioner/alert_router.rb | 15 +++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/modules/services/unix/logging/analysis_alert_action_server/files/alert_actioner/actioners/message_actioner.rb b/modules/services/unix/logging/analysis_alert_action_server/files/alert_actioner/actioners/message_actioner.rb index 2fc203533..5fab83a7d 100644 --- a/modules/services/unix/logging/analysis_alert_action_server/files/alert_actioner/actioners/message_actioner.rb +++ b/modules/services/unix/logging/analysis_alert_action_server/files/alert_actioner/actioners/message_actioner.rb @@ -15,9 +15,9 @@ class MessageActioner < CommandActioner # Return [Array] of command strings def command_strings - ["DISPLAY=:0 /usr/bin/notify-send '#{self.message_header}' '#{self.message_subtext}' --icon=dialog-information", - "/usr/bin/wall #{self.username == 'root' ? '-n ' : ''}'#{self.message_header}' '#{self.message_subtext}'", # wall -n requires root - "/bin/echo '#{self.message_subtext}' | /usr/bin/mail -s '#{self.message_header}' #{self.recipient}"] + ["DISPLAY=:0 /usr/bin/notify-send \"#{self.message_header}\" \"#{self.message_subtext}\" --icon=dialog-information", + "/usr/bin/wall #{self.username == 'root' ? '-n ' : ''}\"#{self.message_header}\" \"#{self.message_subtext}\"", # wall -n requires root + "/bin/echo \"#{self.message_subtext}\" | /usr/bin/mail -s \"#{self.message_header}\" #{self.recipient}"] end diff --git a/modules/services/unix/logging/analysis_alert_action_server/files/alert_actioner/alert_router.rb b/modules/services/unix/logging/analysis_alert_action_server/files/alert_actioner/alert_router.rb index 46b1258f4..0ca0ff58e 100644 --- a/modules/services/unix/logging/analysis_alert_action_server/files/alert_actioner/alert_router.rb +++ b/modules/services/unix/logging/analysis_alert_action_server/files/alert_actioner/alert_router.rb @@ -202,11 +202,17 @@ end def test_actions(opts) db_conn = PG::Connection.open(:dbname => 'alert_events') - alert_name = opts[:alert_to_test] - Print.info("Testing actions associated with: #{alert_name}") - load_configs - run_alert_actions(db_conn, alert_name) + + if opts[:alert_to_test] + alert_name = opts[:alert_to_test] + Print.info("Testing actions associated with: #{alert_name}") + run_alert_actions(db_conn, alert_name) + else + @alert_actioners.each do |actioner| + run_alert_actions(db_conn, actioner.alert_name) + end + end end def delete_db @@ -291,4 +297,5 @@ else end rescue Exception => e Print.err e.to_s, logger + Print.err e.backtrace, logger end \ No newline at end of file