-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathexample_info_test.go
61 lines (52 loc) · 1.15 KB
/
example_info_test.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
package pango_test
import (
"encoding/json"
"fmt"
"github.com/PaloAltoNetworks/pango"
)
// About is a struct to hold information about the given PAN-OS device.
type About struct {
Hostname string `json:"hostname"`
Type string `json:"type"`
Model string `json:"model"`
Version string `json:"version"`
Serial string `json:"serial"`
}
// ExamplePanosInfo outputs various info about a PAN-OS device as
// JSON.
func Example_outputApiKey() {
var out About
conInfo := pango.Client{
Hostname: "192.168.1.1",
Username: "admin",
Password: "admin",
Logging: pango.LogQuiet,
}
con, err := pango.Connect(conInfo)
if err != nil {
return
}
switch x := con.(type) {
case *pango.Firewall:
out = About{
Hostname: x.Hostname,
Type: "NGFW",
Model: x.SystemInfo["model"],
Version: x.Version.String(),
Serial: x.SystemInfo["serial"],
}
case *pango.Panorama:
out = About{
Hostname: x.Hostname,
Type: "Panorama",
Model: x.SystemInfo["model"],
Version: x.Version.String(),
Serial: x.SystemInfo["serial"],
}
}
b, err := json.Marshal(out)
if err != nil {
return
}
fmt.Printf("%s\n", b)
}