-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (54 loc) · 1.46 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"context"
"flag"
"fmt"
"os"
"github.com/kaginawa/kaginawa-sdk-go"
)
func main() {
endpoint := flag.String("e", "", "endpoint (https://...)")
key := flag.String("k", "", "api key")
cid := flag.String("c", "", "custom id")
flag.Parse()
// Prepare the API client
client, err := kaginawa.NewClient(*endpoint, *key)
if err != nil {
println(err)
os.Exit(2)
}
if len(*cid) == 0 {
println("most specify a custom id")
os.Exit(2)
}
// Gathering reports
nodes, err := client.ListNodesByCustomID(context.Background(), *cid)
if err != nil {
println(err)
os.Exit(1)
}
fmt.Printf("found %d node(s)\n", len(nodes))
sshServerSet := map[string]struct{}{}
for _, node := range nodes {
if node.SSHRemotePort > 0 {
fmt.Printf("🔵 %s %s (%v) %s:%d\n",
node.ID, node.CustomID, node.Timestamp(), node.SSHServerHost, node.SSHRemotePort)
sshServerSet[node.SSHServerHost] = struct{}{}
} else {
fmt.Printf("⚪ %s %s (%v) (ssh forwarding disabled or not connected)\n",
node.ID, node.CustomID, node.Timestamp())
}
}
// Gathering ssh server information
if len(sshServerSet) > 0 {
fmt.Printf("found %d ssh server(s)\n", len(sshServerSet))
for sshServer := range sshServerSet {
sv, err := client.FindSSHServerByHostname(context.Background(), sshServer)
if err != nil {
println(err)
os.Exit(1)
}
fmt.Printf("⚫ %s@%s:%d key=%v pw=%v\n", sv.User, sv.Host, sv.Port, len(sv.Key) > 0, len(sv.Password) > 0)
}
}
}