Skip to content

Commit 5c2e009

Browse files
author
wafuwafu13
committed
enable to specify -a muti times instead of use conmma
1 parent b40a366 commit 5c2e009

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

check-dns/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ check-dns -H example.com -s 8.8.8.8
1919
Check IP-ADDRESS DNS server returns
2020
If DNS server returns 1.1.1.1 and 2.2.2.2
2121
```
22-
-a 1.1.1.1, 2.2.2.2 -> OK
23-
-a 1.1.1.1, 2.2.2.2, 3.3.3.3 -> WARNING
24-
-a 1.1.1.1 -> WARNING
25-
-a 1.1.1.1, 3.3.3.3 -> WARNING
26-
-a 3.3.3.3 -> CRITICAL
27-
-a 3.3.3.3, 4.4.4.4, 5.5.5.5 -> CRITICAL
22+
-a 1.1.1.1 -a 2.2.2.2 -> OK
23+
-a 1.1.1.1 -a 2.2.2.2 -a 3.3.3.3 -> WARNING
24+
-a 1.1.1.1 -> WARNING
25+
-a 1.1.1.1 -a 3.3.3.3 -> WARNING
26+
-a 3.3.3.3 -> CRITICAL
27+
-a 3.3.3.3 -a 4.4.4.4 -a 5.5.5.5 -> CRITICAL
2828
```
2929
```
3030
check-dns -H example.com -s 8.8.8.8 -a 93.184.216.34
@@ -69,7 +69,7 @@ command = ["check-dns", "-H", "example.com", "-s", "8.8.8.8"]
6969
-q, --querytype= DNS record query type where TYPE =(A, AAAA, SRV, TXT, MX, ANY) (default: A)
7070
-c, --queryclass= DNS record class type where TYPE =(IN, CS, CH, HS, NONE, ANY) (default: IN)
7171
--norec Set not recursive mode
72-
-a, --expected-address= IP-ADDRESS you expect the DNS server to return. If multiple addresses are returned at once, you have to match the whole string of addresses separated with commas
72+
-a, --expected-address= IP-ADDRESS you expect the DNS server to return. If multiple addresses are returned at once, you have to specify whole string of addresses
7373
```
7474

7575
## For more information

check-dns/lib/check_dns.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import (
1313
)
1414

1515
type dnsOpts struct {
16-
Host string `short:"H" long:"host" required:"true" description:"The name or address you want to query"`
17-
Server string `short:"s" long:"server" description:"DNS server you want to use for the lookup"`
18-
Port int `short:"p" long:"port" default:"53" description:"Port number you want to use"`
19-
QueryType string `short:"q" long:"querytype" default:"A" description:"DNS record query type where TYPE =(A, AAAA, SRV, TXT, MX, ANY)"`
20-
QueryClass string `short:"c" long:"queryclass" default:"IN" description:"DNS record class type where TYPE =(IN, CS, CH, HS, NONE, ANY)"`
21-
Norec bool `long:"norec" description:"Set not recursive mode"`
22-
ExpectedAddress string `short:"a" long:"expected-address" description:"IP-ADDRESS you expect the DNS server to return. If multiple addresses are returned at once, you have to match the whole string of addresses separated with commas"`
16+
Host string `short:"H" long:"host" required:"true" description:"The name or address you want to query"`
17+
Server string `short:"s" long:"server" description:"DNS server you want to use for the lookup"`
18+
Port int `short:"p" long:"port" default:"53" description:"Port number you want to use"`
19+
QueryType string `short:"q" long:"querytype" default:"A" description:"DNS record query type where TYPE =(A, AAAA, SRV, TXT, MX, ANY)"`
20+
QueryClass string `short:"c" long:"queryclass" default:"IN" description:"DNS record class type where TYPE =(IN, CS, CH, HS, NONE, ANY)"`
21+
Norec bool `long:"norec" description:"Set not recursive mode"`
22+
ExpectedAddress []string `short:"a" long:"expected-address" description:"IP-ADDRESS you expect the DNS server to return. If multiple addresses are returned at once, you have to specify whole string of addresses"`
2323
}
2424

2525
// Do the plugin
@@ -86,18 +86,17 @@ func (opts *dnsOpts) run() *checkers.Checker {
8686
5: --expected-address 3.3.3.3 -> CRITICAL
8787
6: --expected-address 3.3.3.3, 4.4.4.4, 5.5.5.5 -> CRITICAL
8888
**/
89-
if opts.ExpectedAddress != "" {
90-
expectedAddress := strings.Split(opts.ExpectedAddress, ",")
89+
if len(opts.ExpectedAddress) != 0 {
9190
match := 0
92-
for _, v := range expectedAddress {
91+
for _, v := range opts.ExpectedAddress {
9392
for _, answer := range r.Answer {
9493
if strings.Contains(answer.String(), strings.TrimSpace(v)) {
9594
match += 1
9695
}
9796
}
9897
}
9998
if match == len(r.Answer) {
100-
if len(expectedAddress) == len(r.Answer) { // case 1
99+
if len(opts.ExpectedAddress) == len(r.Answer) { // case 1
101100
checkSt = checkers.OK
102101
} else { // case 2
103102
checkSt = checkers.WARNING

check-dns/lib/check_dns_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ func TestCheckDns(t *testing.T) {
9999
[]string{"status: NXDOMAIN"},
100100
},
101101
{
102-
[]string{"-H", "a.root-servers.net", "-s", "8.8.8.8", "-a", "198.41.0.3,198.41.0.4"},
102+
[]string{"-H", "a.root-servers.net", "-s", "8.8.8.8", "-a", "198.41.0.3", "-a", "198.41.0.4"},
103103
checkers.WARNING,
104104
[]string{"status: NOERROR", "198.41.0.4"},
105105
},
106106
{
107-
[]string{"-H", "a.root-servers.net", "-s", "8.8.8.8", "-a", "198.41.0.3, 198.41.0.4"},
107+
[]string{"-H", "a.root-servers.net", "-s", "8.8.8.8", "-a", "198.41.0.3", "-a", " 198.41.0.4 "},
108108
checkers.WARNING,
109109
[]string{"status: NOERROR", "198.41.0.4"},
110110
},

0 commit comments

Comments
 (0)