-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
59 lines (46 loc) · 1.65 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
package main
import (
"flag"
"fmt"
"github.com/tactycal/agent/packageLookup"
)
func main() {
configFile := flag.String("f", DefaultConfigurationFile, "use a configuration file")
showVersion := flag.Bool("v", false, "print version and exit")
debugMode := flag.Bool("d", false, "show debug messages")
statePath := flag.String("s", DefaultStatePath, "path to where tactycal can write its state")
clientTimeout := flag.Duration("t", DefaultClientTimeout, "client timeout for request in seconds")
localOutput := flag.Bool("l", false, "print host information and installed packages to standard output as json string and exit")
flag.Parse()
if *showVersion {
fmt.Printf("tactycal %s-%s\n", Version, GitCommit)
return
}
if *localOutput {
if s, err := local(); err != nil {
fmt.Printf("Failed to retrieved host information and installed packages; %s", err.Error())
} else {
fmt.Println(s)
}
return
}
initLogging(*debugMode)
log.Infof("Starting tactycal %s-%s", Version, GitCommit)
config, err := NewConfig(*configFile, *statePath, *clientTimeout)
if err != nil {
log.Fatalf("Failed to read configuration; err = %v", err)
}
host, err := GetHostInfo()
if err != nil {
log.Fatalf("Failed to get host info; err = %v", err)
}
packages, err := packageLookup.Get(host.Distribution)
if err != nil {
log.Fatalf("Failed to fetch a list of installed packages; err = %v", err)
}
log.Debugf("Found %d installed packages", len(packages))
client := NewClient(config, host, NewState(*statePath), *clientTimeout)
if err := client.SendPackageList(packages); err != nil {
log.Fatalf("Failed to submit list of installed packages; err = %v", err)
}
}