aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2019-10-09 09:09:58 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2019-10-09 09:18:27 +0300
commit79b0eb417b0431e316964e003a9efe6b6725b94a (patch)
treea6596cdbf5fb393dda168723d1278ac3db6abdaf
parent10e75a2790e7b36095c2f0a4a2ae529b0af59d82 (diff)
downloadcertmon-79b0eb417b0431e316964e003a9efe6b6725b94a.tar.gz
certmon-79b0eb417b0431e316964e003a9efe6b6725b94a.tar.bz2
Rename to certmon. Eliminate alternate names to avoid spurious polling.
-rw-r--r--.gitignore1
-rw-r--r--certmon.go (renamed from certwatch.go)54
2 files changed, 47 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0185e2f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
certmon
diff --git a/certwatch.go b/certmon.go
index 188de0c..155ff0f 100644
--- a/certwatch.go
+++ b/certmon.go
@@ -48,11 +48,47 @@ func CertMatch(cert *x509.Certificate, cn string) bool {
48 return false 48 return false
49} 49}
50 50
51// Argument list
52type ArgList struct {
53 args []string
54}
55
56func NewArgList(a []string) *ArgList {
57 var args ArgList
58 if len(a) > 0 {
59 args.args = a
60 } else {
61 args.args = []string{``}
62 }
63 return &args
64}
65
66func (a *ArgList) Next() (string) {
67 s := a.args[0]
68 a.args = a.args[1:]
69 return s
70}
71
72func (a *ArgList) DropMatches(cert *x509.Certificate) {
73 for i := 0; i < len(a.args); {
74 if CertMatch(cert, a.args[i]) {
75 a.args = append(a.args[:i], a.args[i+1:]...)
76 } else {
77 i++
78 }
79 }
80}
81
82func (a *ArgList) More() bool {
83 return len(a.args) > 0
84}
85
51// Command line options 86// Command line options
52var warnLimit time.Duration 87var warnLimit time.Duration
53var critLimit time.Duration 88var critLimit time.Duration
54var verboseOption bool 89var verboseOption bool
55var helpOption bool 90var helpOption bool
91var quietOption bool
56var host string 92var host string
57 93
58// Intitialize command line parser 94// Intitialize command line parser
@@ -62,6 +98,7 @@ func init() {
62 flag.BoolVar(&verboseOption, `v`, false, `verbose mode`) 98 flag.BoolVar(&verboseOption, `v`, false, `verbose mode`)
63 flag.BoolVar(&helpOption, `h`, false, `show help summary`) 99 flag.BoolVar(&helpOption, `h`, false, `show help summary`)
64 flag.StringVar(&host, `H`, ``, `host name`) 100 flag.StringVar(&host, `H`, ``, `host name`)
101 flag.BoolVar(&quietOption, `q`, false, `quiet mode: print nothing, exit with a meaningful status`)
65 flag.Usage = func() { 102 flag.Usage = func() {
66 if helpOption { 103 if helpOption {
67 flag.CommandLine.SetOutput(os.Stdout) 104 flag.CommandLine.SetOutput(os.Stdout)
@@ -88,14 +125,13 @@ func main() {
88 } 125 }
89 126
90 res := CertResultList{Address: host, Status: StatusOK} 127 res := CertResultList{Address: host, Status: StatusOK}
91 if len(flag.Args()) > 0 { 128
92 for _, cn := range flag.Args() { 129 for args := NewArgList(flag.Args()); args.More(); {
93 res.Check(cn) 130 res.Check(args)
94 } 131 }
95 } else { 132 if !quietOption {
96 res.Check(``) 133 res.Format()
97 } 134 }
98 res.Format()
99 os.Exit(res.Status) 135 os.Exit(res.Status)
100} 136}
101 137
@@ -143,7 +179,8 @@ func (rl *CertResultList) Append(res CertResult) {
143 } 179 }
144} 180}
145 181
146func (rl *CertResultList) Check(cn string) { 182func (rl *CertResultList) Check(args *ArgList) {
183 cn := args.Next()
147 addr := rl.Address; 184 addr := rl.Address;
148 a := strings.Split(addr, `:`) 185 a := strings.Split(addr, `:`)
149 switch (len(a)) { 186 switch (len(a)) {
@@ -183,6 +220,7 @@ func (rl *CertResultList) Check(cn string) {
183 if !CertMatch(cert, cn) { 220 if !CertMatch(cert, cn) {
184 continue 221 continue
185 } 222 }
223 args.DropMatches(cert)
186 res := CertResult{Subject: cn, Status: StatusOK} 224 res := CertResult{Subject: cn, Status: StatusOK}
187 res.Ttl = time.Until(cert.NotAfter) 225 res.Ttl = time.Until(cert.NotAfter)
188 if res.Ttl < critLimit { 226 if res.Ttl < critLimit {

Return to:

Send suggestions and report system problems to the System administrator.