comparison plugins/mod_admin_shell.lua @ 13976:a2d4c71f5066

mod_admin_shell: Add debug:ping() which prints debug logs until pong Essentially a verbose version of xmpp:ping(), but more useful for debugging s2s issues without having to watch (and have enabled) debug logs at the same time and try to pick out where the start and end are.
author Kim Alvefur <zash@zash.se>
date Sun, 05 Oct 2025 11:08:27 +0200
parents b1e7d3f571b1
children d520cee2bbdb
comparison
equal deleted inserted replaced
13975:eae7d0350a52 13976:a2d4c71f5066
2463 print(""); 2463 print("");
2464 2464
2465 return true, ("Showing %d certificates in %s"):format(c, path); 2465 return true, ("Showing %d certificates in %s"):format(c, path);
2466 end 2466 end
2467 2467
2468 describe_command [[debug:ping(localhost, remotehost) - Sends a ping to a remote XMPP server while printing debug logs]]
2469 function def_env.debug:ping(localhost, remotehost, timeout)
2470 localhost = select(2, jid_split(localhost));
2471 remotehost = select(2, jid_split(remotehost));
2472 if not localhost then
2473 return nil, "Invalid sender hostname";
2474 elseif not prosody.hosts[localhost] then
2475 return nil, "No such local host";
2476 end
2477 if not remotehost then
2478 return nil, "Invalid destination hostname";
2479 elseif prosody.hosts[remotehost] then
2480 return nil, "Both hosts are local";
2481 end
2482
2483 local iq = st.iq{ from=localhost, to=remotehost, type="get", id=new_id()}
2484 :tag("ping", {xmlns="urn:xmpp:ping"});
2485 local time_start = time.now();
2486 local print = self.session.print;
2487
2488 local writing = false;
2489 local sink = logger.add_simple_sink(function (source, level, message)
2490 if writing then return; end
2491 writing = true;
2492 print(source, level, message);
2493 writing = false;
2494 end);
2495
2496 return module:context(localhost):send_iq(iq, nil, timeout):finally(function()
2497 if not logger.remove_sink(sink) then
2498 module:log("warn", "Unable to remove watch:log() sink");
2499 end
2500 end):next(function(pong)
2501 return ("pong from %s on %s in %gs"):format(pong.stanza.attr.from, pong.origin.id, time.now() - time_start);
2502 end);
2503 end
2504
2505
2468 def_env.role = new_section("Role and access management"); 2506 def_env.role = new_section("Role and access management");
2469 2507
2470 describe_command [[role:list(host) - List known roles]] 2508 describe_command [[role:list(host) - List known roles]]
2471 function def_env.role:list(host) 2509 function def_env.role:list(host)
2472 if not host then 2510 if not host then