Skip to content

Commit d62930e

Browse files
committed
init
1 parent 6d4129c commit d62930e

File tree

6 files changed

+186
-0
lines changed

6 files changed

+186
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
**/*.tfvars
2+
**/*.tfstate*
3+
.idea
4+
*.retry
5+
.terraform
6+
*.iml
7+
dist/*
8+
/csm
9+
coverage.out

.golangci.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
run:
2+
deadline: 5m
3+
4+
linters:
5+
# please, do not use `enable-all`: it's deprecated and will be removed soon.
6+
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
7+
disable-all: true
8+
enable:
9+
- bodyclose
10+
- deadcode
11+
- depguard
12+
- dogsled
13+
- dupl
14+
- errcheck
15+
# - funlen
16+
- gochecknoinits
17+
- goconst
18+
- gocritic
19+
- gocyclo
20+
- gofmt
21+
- goimports
22+
- golint
23+
- gosec
24+
- gosimple
25+
- govet
26+
- ineffassign
27+
- interfacer
28+
- lll
29+
- misspell
30+
- nakedret
31+
- scopelint
32+
- staticcheck
33+
- structcheck
34+
- stylecheck
35+
- typecheck
36+
- unconvert
37+
- unparam
38+
- unused
39+
- varcheck
40+
- whitespace
41+
42+
43+
linters-settings:
44+
dupl:
45+
threshold: 400
46+
lll:
47+
line-length: 170
48+
gocyclo:
49+
min-complexity: 30
50+
golint:
51+
min-confidence: 0.85

.goreleaser.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
before:
2+
hooks:
3+
- go mod download
4+
builds:
5+
- env:
6+
- CGO_ENABLED=0
7+
goos:
8+
- linux
9+
- windows
10+
- darwin
11+
archives:
12+
- replacements:
13+
darwin: Darwin
14+
linux: Linux
15+
windows: Windows
16+
386: i386
17+
amd64: x86_64
18+
checksum:
19+
name_template: 'checksums.txt'
20+
snapshot:
21+
name_template: "{{ .Tag }}-next"
22+
changelog:
23+
sort: asc
24+
filters:
25+
exclude:
26+
- '^docs:'
27+
- '^test:'

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module git.signintra.com/schenker/csm
2+
3+
go 1.15
4+
5+
require github.com/fatih/color v1.9.0

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
2+
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
3+
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
4+
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
5+
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
6+
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
7+
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
8+
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
9+
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
10+
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

main.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"fmt"
7+
"net"
8+
9+
"github.com/fatih/color"
10+
)
11+
12+
func main() {
13+
s, err := net.ResolveUDPAddr("udp4", ":31000")
14+
if err != nil {
15+
panic(err)
16+
}
17+
18+
connection, err := net.ListenUDP("udp4", s)
19+
if err != nil {
20+
panic(err)
21+
}
22+
defer connection.Close()
23+
24+
for {
25+
res, err := Read(connection)
26+
if err != nil {
27+
_ = fmt.Errorf("%v: %w", "unknown response", err)
28+
continue
29+
}
30+
if res.Type == "ApiCallAttempt" { // omit Verdicts
31+
msg := fmt.Sprintf("%v %-50.50v %v\n", res.HTTPStatusCode, fmt.Sprintf("%s:%s", res.Service, res.API), res.Fqdn)
32+
if res.HTTPStatusCode >= 400 {
33+
color.Red(msg)
34+
} else {
35+
color.Green(msg)
36+
}
37+
}
38+
}
39+
}
40+
41+
type Response struct {
42+
// Attempt
43+
Version int `json:"Version"`
44+
ClientID string `json:"ClientId"`
45+
Type string `json:"Type"`
46+
Service string `json:"Service"`
47+
API string `json:"Api"`
48+
Timestamp int64 `json:"Timestamp"`
49+
AttemptLatency int `json:"AttemptLatency"`
50+
Fqdn string `json:"Fqdn"`
51+
UserAgent string `json:"UserAgent"`
52+
AccessKey string `json:"AccessKey"`
53+
Region string `json:"Region"`
54+
SessionToken string `json:"SessionToken"`
55+
HTTPStatusCode int `json:"HttpStatusCode"`
56+
XAmznRequestID string `json:"XAmznRequestId"`
57+
58+
// Verdict
59+
AttemptCount int `json:"AttemptCount"`
60+
FinalHTTPStatusCode int `json:"FinalHttpStatusCode"`
61+
Latency int `json:"Latency"`
62+
MaxRetriesExceeded int `json:"MaxRetriesExceeded"`
63+
}
64+
65+
func Read(conn *net.UDPConn) (*Response, error) {
66+
b := make([]byte, 1024)
67+
oob := make([]byte, 40)
68+
69+
//nolint:dogsled
70+
_, _, _, _, err := conn.ReadMsgUDP(b, oob)
71+
if err != nil {
72+
return nil, err
73+
}
74+
75+
// Remove NULL characters
76+
b = bytes.Trim(b, "\x00")
77+
ret := &Response{}
78+
79+
if err := json.Unmarshal(b, ret); err != nil {
80+
return nil, err
81+
}
82+
83+
return ret, err
84+
}

0 commit comments

Comments
 (0)