From 9298e3ba8aafcf415f126240ebf0795975cb0b8f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 14 Jul 2021 02:41:15 +0200 Subject: mod_s2s: Vary log level by remote stream error Increases log level for stream conditions that could indicate a problem on our end, especially programming errors like invalid XML, or the remote server saying that our certificate is invalid, since these should be investigated. Non-issues like closing of idle streams are lowered to debug since it's mostly noise. Other issues left at info are mostly about changes to the remote server, e.g. complete or partial shutdown. --- plugins/mod_s2s.lua | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/mod_s2s.lua b/plugins/mod_s2s.lua index f673e9c5..f2a7c850 100644 --- a/plugins/mod_s2s.lua +++ b/plugins/mod_s2s.lua @@ -526,6 +526,38 @@ function stream_callbacks.streamclosed(session, attr) session.thread:run({ stream = "closed", attr = attr }); end +-- Some stream conditions indicate a problem on our end, e.g. that we sent +-- something invalid. Those should be investigated. Others are problems or +-- events in the remote host that don't affect us, or simply that the +-- connection was closed for being idle. +local stream_condition_severity = { + ["bad-format"] = "warn"; + ["bad-namespace-prefix"] = "warn"; + ["conflict"] = "warn"; + ["connection-timeout"] = "debug"; + ["host-gone"] = "info"; + ["host-unknown"] = "info"; + ["improper-addressing"] = "warn"; + ["internal-server-error"] = "warn"; + ["invalid-from"] = "warn"; + ["invalid-namespace"] = "warn"; + ["invalid-xml"] = "warn"; + ["not-authorized"] = "warn"; + ["not-well-formed"] = "warn"; + ["policy-violation"] = "warn"; + ["remote-connection-failed"] = "warn"; + ["reset"] = "info"; + ["resource-constraint"] = "info"; + ["restricted-xml"] = "warn"; + ["see-other-host"] = "info"; + ["system-shutdown"] = "info"; + ["undefined-condition"] = "warn"; + ["unsupported-encoding"] = "warn"; + ["unsupported-feature"] = "warn"; + ["unsupported-stanza-type"] = "warn"; + ["unsupported-version"] = "warn"; +} + function stream_callbacks.error(session, error, data) if error == "no-stream" then session.log("debug", "Invalid opening stream header (%s)", (data:gsub("^([^\1]+)\1", "{%1}"))); @@ -546,7 +578,7 @@ function stream_callbacks.error(session, error, data) end end text = condition .. (text and (" ("..text..")") or ""); - session.log("info", "Session closed by remote with error: %s", text); + session.log(stream_condition_severity[condition] or "info", "Session closed by remote with error: %s", text); session:close(nil, text); end end -- cgit v1.2.3