#1852 Add connection created time to mod_admin_shell

Reporter Aidan
Owner Nobody
Created
Updated
Stars ★ (1)
Tags
  • Status-Fixed
  • Type-Enhancement
  • Priority-Medium
  • Patch
  • Milestone-0.13
  1. Aidan on

    Here's a small patch that adds a connection created field to the s2s and c2s :show commands. Not sure about the formatting keys, I mostly copied from the port formatting. --- plugins/mod_admin_shell.lua 2024-03-26 16:05:52.270558634 -0700 +++ /usr/lib/prosody/modules/mod_admin_shell.lua 2024-03-26 16:29:48.764878038 -0700 @@ -867,6 +867,18 @@ end end; }; + created = { + title = "Connection Created"; + description = "Time when connection was created"; + width = #"YYYY MM DD HH:MM:SS"; + align = "right"; + key = "conn"; + mapper = function(conn) + if conn then + return os.date("%Y %m %d %H:%M:%S", math.floor(conn.created)); + end + end; + }; dir = { title = "Dir"; description = "Direction of server-to-server connection";

  2. Aidan on

    Same patch, but formatted better if it helps: # HG changeset patch # User aidan@jmad.org # Date 1712206563 25200 # Wed Apr 03 21:56:03 2024 -0700 # Node ID 0b8c745cb128ebb867945ae7b82f35f657a0a1c5 # Parent c670b935a7c4d2db171b2a42958fe4c4133745b9 Add connection created time to mod_admin_shell diff -r c670b935a7c4 -r 0b8c745cb128 plugins/mod_admin_shell.lua --- a/plugins/mod_admin_shell.lua Wed Apr 03 21:52:13 2024 -0700 +++ b/plugins/mod_admin_shell.lua Wed Apr 03 21:56:03 2024 -0700 @@ -879,6 +879,18 @@ end end; }; + created = { + title = "Connection Created"; + description = "Time when connection was created"; + width = #"YYYY MM DD HH:MM:SS"; + align = "right"; + key = "conn"; + mapper = function(conn) + if conn then + return os.date("%Y %m %d %H:%M:%S", math.floor(conn.created)); + end + end; + }; dir = { title = "Dir"; description = "Direction of server-to-server connection";

  3. Aidan on

    Added proper commit message: # HG changeset patch # User aidan@jmad.org # Date 1712206563 25200 # Wed Apr 03 21:56:03 2024 -0700 # Node ID 0b8c745cb128ebb867945ae7b82f35f657a0a1c5 # Parent c670b935a7c4d2db171b2a42958fe4c4133745b9 mod_admin_shell: Add connection created time This adds an output format option to show the time that the connection was created. diff -r c670b935a7c4 -r 0b8c745cb128 plugins/mod_admin_shell.lua --- a/plugins/mod_admin_shell.lua Wed Apr 03 21:52:13 2024 -0700 +++ b/plugins/mod_admin_shell.lua Wed Apr 03 21:56:03 2024 -0700 @@ -879,6 +879,18 @@ end end; }; + created = { + title = "Connection Created"; + description = "Time when connection was created"; + width = #"YYYY MM DD HH:MM:SS"; + align = "right"; + key = "conn"; + mapper = function(conn) + if conn then + return os.date("%Y %m %d %H:%M:%S", math.floor(conn.created)); + end + end; + }; dir = { title = "Dir"; description = "Direction of server-to-server connection";

  4. Zash on

    Good idea and thank for the patch. As mentioned in the chat, please see commit message format in https://prosody.im/doc/contributing Also I thought we had a common function for formatting timestamps, but it turns out that was a different module.

    Changes
    • tags Patch
  5. Aidan on

    Just found `"prosody.util.datetime".datetime`. Looks like it works with that so I can use that if preferred: # HG changeset patch # User aidan@jmad.org # Date 1712254386 25200 # Thu Apr 04 11:13:06 2024 -0700 # Node ID 49ef3590c7aacab14244d1f7f1c249a2206abbc7 # Parent d5a9847b0e554305d90db273dad037d1f678ad9e mod_admin_shell: Add connection created time This adds an output format option to show the time that the connection was created. diff -r d5a9847b0e55 -r 49ef3590c7aa plugins/mod_admin_shell.lua --- a/plugins/mod_admin_shell.lua Thu Apr 04 19:44:17 2024 +0200 +++ b/plugins/mod_admin_shell.lua Thu Apr 04 11:13:06 2024 -0700 @@ -19,6 +19,7 @@ local server = require "prosody.net.server"; local schema = require "prosody.util.jsonschema"; local st = require "prosody.util.stanza"; +local datetime = require "prosody.util.datetime".datetime; local _G = _G; @@ -867,6 +868,18 @@ end end; }; + created = { + title = "Connection Created"; + description = "Time when connection was created"; + width = #"YYYY-MM-DDTHH:MM:SS.SSSSSSZ"; + align = "right"; + key = "conn"; + mapper = function(conn) + if conn then + return datetime(conn.created); + end + end; + }; dir = { title = "Dir"; description = "Direction of server-to-server connection";

  6. Zash on

    Pushed as https://hg.prosody.im/trunk/rev/9eb081616842 with some tweak to the timestamp format. Thanks again! I observe that there are many different timestamp formats in use for various things throughout mod_admin_shell. Kinda wanted to take this one: https://hg.prosody.im/prosody-modules/file/e199f33f7a2e/mod_client_management/mod_client_management.lua#l444 since it shows date or time depending on whether the time is in the last 24h, making it pretty compact.

    Changes
    • tags Milestone-0.13 Status-Fixed
  7. Aidan on

    Thanks! I agree that format would be a little nicer, you do need a wide terminal to list a lot of fields in s2s:show() as of now

New comment

Not published. Used for spam prevention and optional update notifications.