Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
VERSION=0.0.13
GITCOMMIT?=$(shell git describe --dirty --always 2>/dev/null || echo "unknown")
LDFLAGS=-ldflags "-w -s -X main.version=${VERSION} -X main.commit=${GITCOMMIT}"
LDFLAGS=-ldflags "-w -s -X main.version=${VERSION}"

all: check_ftp2

Expand Down
14 changes: 5 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func (o *Opt) dialOptions() []ftp.DialOption {
dialer := &net.Dialer{
Timeout: o.Timeout,
KeepAlive: 30 * time.Second,
DualStack: true,
}
tcpMode := "tcp"
if o.TCP4 {
Expand Down Expand Up @@ -143,15 +142,15 @@ func (o *Opt) doConnect() (string, error) {
res.out = replaceReplacer(res.out)

if res.err != nil {
return "", fmt.Errorf("connection failed: %v on %s port %d [%s]", res.err, o.Hostname, o.Port, res.out)
return "", fmt.Errorf("connection failed: %w on %s port %d [%s]", res.err, o.Hostname, o.Port, res.out)
}

okMsg := fmt.Sprintf(`FTP OK - %.3f second response time on %s port %d [%s]|time=%fs;;;0.000000;%f`, duration.Seconds(), o.Hostname, o.Port, res.out, duration.Seconds(), o.Timeout.Seconds())

return okMsg, nil
}

func (o *Opt) verifyOptions() error {
func (o *Opt) verifyOptions(_ []string) error {
if o.VerifySSL && o.SNI == "" {
return fmt.Errorf("verify-ssl is specified but sni is not specified")
}
Expand All @@ -161,11 +160,7 @@ func (o *Opt) verifyOptions() error {
return nil
}

func (opt *Opt) Run(_ []string) (error, int) {
if err := opt.verifyOptions(); err != nil {
return fmt.Errorf("FTP UNKNOWN: %v", err), flagrun.UNKNOWN
}

func (opt *Opt) Run(_ []string) (any, int) {
msg, err := opt.doConnect()
if err != nil {
fmt.Printf("FTP CRITICAL: %v\n", err)
Expand All @@ -177,5 +172,6 @@ func (opt *Opt) Run(_ []string) (error, int) {
}

func main() {
os.Exit(flagrun.Go(&Opt{}, flagrun.Version(version)))
o := &Opt{}
os.Exit(flagrun.Go(o, flagrun.Version(version), flagrun.Validator(o.verifyOptions)))
}
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func Test_opt_verifyOptions(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.opt.verifyOptions()
err := tt.opt.verifyOptions([]string{})
if (err != nil) != tt.wantErr {
t.Errorf("verifyOptions() error = %v, wantErr %v", err, tt.wantErr)
}
Expand Down
Loading