-
Notifications
You must be signed in to change notification settings - Fork 33
/
main.go
85 lines (71 loc) · 2.24 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
package main
import (
"crypto/tls"
"flag"
"fmt"
"log"
"pktvisor/internal/ui"
"github.com/jroimartin/gocui"
"net/http"
"pktvisor/pkg/client"
)
func main() {
usage := `pktvisor-cli command line UI
Usage:
pktvisor-cli [-p PORT] [-H HOST]
pktvisor-cli -h
pktvisor-cli --version
Options:
-p PORT Query pktvisord metrics webserver on the given port [default: 10853]
-H HOST Query pktvisord metrics webserver on the given host [default: localhost]
-P POLICY pktvisor policy to query [default: default]
--tls Use TLS to communicate with pktvisord metrics webserver
--tls-noverify Do not verify TLS certificate
-h Show this screen
--version Show client version`
wantTLS := flag.Bool("tls", false, "Use TLS to communicate with pktvisord metrics webserver")
wantTLSNoVerify := flag.Bool("tls-noverify", false, "Use TLS to communicate with pktvisord metrics webserver, do not verify TLS certificate")
wantVersion := flag.Bool("version", false, "Show client version")
wantHelp := flag.Bool("h", false, "Show help")
fPort := flag.Int("p", 10853, "Query pktvisord metrics webserver on the given port")
fHost := flag.String("H", "localhost", "Query pktvisord metrics webserver on the given host")
pPolicy := flag.String("P", "default", "pktvisor policy to query")
flag.Parse()
if *wantVersion {
fmt.Println(client.VisorVersionNum)
return
}
if *wantHelp {
fmt.Println(usage)
return
}
config := client.ClientConfig{
Host: *fHost,
Port: *fPort,
DefaultPolicy: *pPolicy,
}
config.Protocol = "http"
if *wantTLS || *wantTLSNoVerify {
config.Protocol = "https"
if *wantTLSNoVerify {
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
}
c, err := client.New(config)
if err != nil {
log.Panicln(err)
}
g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
log.Panicln(err)
}
defer g.Close()
u, err := ui.New(g, c, 1)
if err != nil {
log.Panicln(err)
}
u.Start()
}