-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
111 lines (91 loc) · 3.64 KB
/
config.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"fmt"
"github.com/fatih/color"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
"path/filepath"
) // import
type azHealthcheckConfig struct {
BrowserAgent string `yaml:"browserAgent"`
CheckInterval string `yaml:"checkInterval"`
Port string `yaml:"port"`
Hosts map[string]azHealthcheckConfigHost `yaml:"hosts"`
} // type azHealthcheckConfig
type azHealthcheckConfigHost struct {
Name string `yaml:"name"`
Url string `yaml:"url"`
Headers map[string]string `yaml:"headers,omitempty"`
ClientCertFilename string `yaml:"clientcertfilename"`
ClientKeyFilename string `yaml:"clientkeyfilename"`
} // type azHealthcheckConfig_httpCheck
var config azHealthcheckConfig
//
// Config File Load
// Reads in YAML config file
//
func azHealthcheckConfigLoad() {
fmt.Println(color.GreenString("Looking for YAML config file"))
configFilename := ""
absConfigFilename,_ := filepath.Abs("./azhealthcheck.yaml");
if _,err := os.Stat("/etc/azhealthcheck.yaml"); err == nil {
configFilename = "/etc/azhealthcheck.yaml"
printConfigVal("Found config file at", configFilename)
} else if _,err = os.Stat(absConfigFilename); err == nil {
configFilename = absConfigFilename
printConfigVal("Found config file at", configFilename)
} else {
fmt.Println(color.YellowString(" !! ") +
color.RedString("Unable to locate ") +
color.YellowString("azhealthcheck.yaml") +
color.RedString(" config file") +
color.YellowString(" !!"))
os.Exit(1)
} // if fileExists
printConfigVal("Reading YAML config file", configFilename)
yamlData, err := ioutil.ReadFile(configFilename)
errorCheck(err)
fmt.Println(color.GreenString("Parsing YAML"))
if err := yaml.Unmarshal([]byte(yamlData), &config); err != nil {
fmt.Println(err.Error())
} // if
fmt.Println(color.GreenString("Options"))
printConfigVal("browserAgent", config.BrowserAgent)
printConfigVal("checkInterval", config.CheckInterval)
printConfigVal("port", config.Port)
fmt.Println("")
fmt.Println(color.GreenString("Host Checks"))
for k, v := range config.Hosts {
fmt.Println( color.WhiteString(" * ") + color.YellowString(k) )
fmt.Println( color.WhiteString(" ** ") +
color.YellowString("Name") +
color.WhiteString(": [") +
color.CyanString(v.Name) +
color.WhiteString("]") )
fmt.Println( color.WhiteString(" ** ") +
color.YellowString("URL") +
color.WhiteString(": [") +
color.CyanString(v.Url) +
color.WhiteString("]") )
fmt.Println( color.WhiteString(" ** ") +
color.YellowString("Headers") )
for hk,hv := range v.Headers {
fmt.Println(color.WhiteString(" *** ") +
color.MagentaString(hk) +
color.WhiteString(": ") +
color.RedString(hv) )
} // for
fmt.Println( color.WhiteString(" ** ") +
color.YellowString("ClientCertFilename") +
color.WhiteString("..: [") +
color.CyanString(v.ClientCertFilename) +
color.WhiteString("]") )
fmt.Println( color.WhiteString(" ** ") +
color.YellowString("ClientKeyFilename") +
color.WhiteString("...: [") +
color.CyanString(v.ClientKeyFilename) +
color.WhiteString("]") )
} // for
fmt.Println("")
} // func azHealthcheckConfigLoad