feat: NetBox insights, host tools and configurable TUI
Test / test (pull_request) Successful in 4m15s

- info/open/whois: NetBox details (site, nested locations, rack units,
  role, platform, tenant, IPs per interface), web page, reverse IP lookup
- cache status, site, role, platform, tenant, location chain and rack;
  ask before connecting to hosts in ssh.warn_status (--force skips)
- ssh rules and command restrictions match site/role/platform/tenant/status
- tui.columns selects what the TUI shows; optional TCP reachability column;
  detail view (Ctrl+L), NetBox page (Ctrl+G), status/location filters
- resolver.fallback tries other strategies' addresses when unreachable
- copy-id, known-hosts reset and address-change notices
- export ansible (YAML/INI) and export ssh-config
- token: keyring stores NetBox tokens in the system keyring
- fix stale menu number in testenv configure test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-18 12:33:59 +01:00
1 parent e5bde9c61f
commit 1660bb3098
39 files changed
+4868 -96

No files matched your search

+87
View File
@@ -0,0 +1,87 @@
package main
import (
"context"
"fmt"
"time"
"git.zb-server.de/Sebi/ssh-netbox-wrapper/internal/config"
"git.zb-server.de/Sebi/ssh-netbox-wrapper/internal/netbox"
internalssh "git.zb-server.de/Sebi/ssh-netbox-wrapper/internal/ssh"
"git.zb-server.de/Sebi/ssh-netbox-wrapper/internal/tui"
)
// configureTUIExtras wires reachability, the detail view and opening NetBox
// pages into the TUI. known enriches a listed host from the cache.
func configureTUIExtras(m *tui.Model, cfg *config.Config, client *netbox.Client, known func(name, kind string, tags []string) resolvedHost) {
m.SetColumns(cfg.TUI.EffectiveColumns())
if cfg.TUI.ReachabilityEnabled() {
m.SetReachability(cfg.TUI.ReachabilityTimeoutDuration(), func(name, kind string, tags []string) (int, bool) {
h := known(name, kind, tags)
if usesJumpHost(hostOptions(cfg, h), internalssh.WrapperFlags{}) {
return 0, false
}
_, port := hostDefaults(cfg, h)
if port <= 0 {
port = 22
}
return port, true
})
}
lookup := func(ctx context.Context, name, kind string, id int) (netbox.HostEntry, resolvedHost, error) {
h := known(name, kind, nil)
if kind == config.StaticKind {
return netbox.HostEntry{}, h, fmt.Errorf("%s is a static host and has no NetBox record", name)
}
if client == nil {
return netbox.HostEntry{}, h, fmt.Errorf("no NetBox is configured")
}
if id <= 0 {
id = h.ID
}
entry, _, h, err := netboxEntry(ctx, client, name, kind, id, h)
return entry, h, err
}
m.SetOpener(func(name, kind string, id int) error {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
entry, _, err := lookup(ctx, name, kind, id)
if err != nil {
return err
}
url, err := client.WebURL(entry)
if err != nil {
return err
}
return openBrowser(url)
})
m.SetDetails(func(name, kind string, id int) (string, error) {
if kind == config.StaticKind {
h := known(name, kind, nil)
user, port := hostDefaults(cfg, h)
text := fmt.Sprintf("%s (static host from hosts:)\n Address %s\n", name, h.IP)
if user != "" {
text += " User " + user + "\n"
}
if port > 0 {
text += fmt.Sprintf(" Port %d\n", port)
}
return text, nil
}
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
entry, h, err := lookup(ctx, name, kind, id)
if err != nil {
return "", err
}
details, err := client.GetDetails(ctx, entry)
if err != nil && details.Name == "" {
return "", err
}
text := formatDetails(details, h)
if err != nil {
text += "\nwarning: " + err.Error() + "\n"
}
return text, nil
})
}