Fixing unescaped ' characters breaking strings in message actioner command generation

This commit is contained in:
thomashaw
2022-10-15 13:54:50 +01:00
parent 51c678925d
commit 2c224e4f44
2 changed files with 14 additions and 7 deletions

View File

@@ -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

View File

@@ -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