Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show hostname for SSH recordings in tsh recordings ls #49118

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions tool/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/api/types/events"
"github.com/gravitational/teleport/lib/asciitable"
libevents "github.com/gravitational/teleport/lib/events"
"github.com/gravitational/teleport/lib/utils"
)

Expand All @@ -55,35 +56,40 @@ type SessionsCollection struct {

// WriteText writes the session collection as text to the provided io.Writer.
func (e *SessionsCollection) WriteText(w io.Writer) error {
t := asciitable.MakeTable([]string{"ID", "Type", "Participants", "Hostname", "Timestamp"})
t := asciitable.MakeTable([]string{"ID", "Type", "Participants", "Target", "Timestamp"})
for _, event := range e.SessionEvents {
var id, typ, participants, hostname, timestamp string
var id, typ, participants, target, timestamp string

switch session := event.(type) {
case *events.SessionEnd:
id = session.GetSessionID()
typ = session.Protocol
participants = strings.Join(session.Participants, ", ")
hostname = session.ServerAddr
timestamp = session.GetTime().Format(constants.HumanDateFormatSeconds)

target = session.ServerHostname
if typ == libevents.EventProtocolKube {
target = session.KubernetesCluster
}

case *events.WindowsDesktopSessionEnd:
id = session.GetSessionID()
typ = "windows"
participants = strings.Join(session.Participants, ", ")
hostname = session.DesktopName
target = session.DesktopName
timestamp = session.GetTime().Format(constants.HumanDateFormatSeconds)
case *events.DatabaseSessionEnd:
id = session.GetSessionID()
typ = session.DatabaseProtocol
participants = session.GetUser()
hostname = session.DatabaseService
target = session.DatabaseName
timestamp = session.GetTime().Format(constants.HumanDateFormatSeconds)
default:
log.Warn(trace.BadParameter("unsupported event type: expected SessionEnd, WindowsDesktopSessionEnd or DatabaseSessionEnd: got: %T", event))
continue
}

t.AddRow([]string{id, typ, participants, hostname, timestamp})
t.AddRow([]string{id, typ, participants, target, timestamp})
}
_, err := t.AsBuffer().WriteTo(w)
return trace.Wrap(err)
Expand Down
Loading