mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
parent
aaef18b1a3
commit
e96f19c867
@ -19,7 +19,6 @@ package target
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -83,8 +82,14 @@ func (target *ElasticsearchTarget) Save(eventData event.Event) error {
|
||||
if target.store != nil {
|
||||
return target.store.Put(eventData)
|
||||
}
|
||||
if _, err := net.Dial("tcp", target.args.URL.Host); err != nil {
|
||||
return errNotConnected
|
||||
if dErr := target.args.URL.DialHTTP(); dErr != nil {
|
||||
if urlErr, ok := dErr.(*url.Error); ok {
|
||||
// To treat "connection refused" errors as errNotConnected.
|
||||
if IsConnRefusedErr(urlErr.Err) {
|
||||
return errNotConnected
|
||||
}
|
||||
}
|
||||
return dErr
|
||||
}
|
||||
return target.send(eventData)
|
||||
}
|
||||
@ -151,8 +156,14 @@ func (target *ElasticsearchTarget) Send(eventKey string) error {
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := net.Dial("tcp", target.args.URL.Host); err != nil {
|
||||
return errNotConnected
|
||||
if dErr := target.args.URL.DialHTTP(); dErr != nil {
|
||||
if urlErr, ok := dErr.(*url.Error); ok {
|
||||
// To treat "connection refused" errors as errNotConnected.
|
||||
if IsConnRefusedErr(urlErr.Err) {
|
||||
return errNotConnected
|
||||
}
|
||||
}
|
||||
return dErr
|
||||
}
|
||||
|
||||
eventData, eErr := target.store.Get(eventKey)
|
||||
@ -227,10 +238,10 @@ func NewElasticsearchTarget(id string, args ElasticsearchArgs, doneCh <-chan str
|
||||
}
|
||||
}
|
||||
|
||||
_, derr := net.Dial("tcp", args.URL.Host)
|
||||
if derr != nil {
|
||||
dErr := args.URL.DialHTTP()
|
||||
if dErr != nil {
|
||||
if store == nil {
|
||||
return nil, derr
|
||||
return nil, dErr
|
||||
}
|
||||
} else {
|
||||
client, err = newClient(args)
|
||||
|
@ -82,15 +82,16 @@ func (target *WebhookTarget) Save(eventData event.Event) error {
|
||||
if target.store != nil {
|
||||
return target.store.Put(eventData)
|
||||
}
|
||||
urlStr, pErr := xnet.ParseURL(target.args.Endpoint.String())
|
||||
u, pErr := xnet.ParseURL(target.args.Endpoint.String())
|
||||
if pErr != nil {
|
||||
return pErr
|
||||
}
|
||||
_, dErr := net.Dial("tcp", urlStr.Host)
|
||||
if dErr != nil {
|
||||
// To treat "connection refused" errors as errNotConnected.
|
||||
if IsConnRefusedErr(dErr) {
|
||||
return errNotConnected
|
||||
if dErr := u.DialHTTP(); dErr != nil {
|
||||
if urlErr, ok := dErr.(*url.Error); ok {
|
||||
// To treat "connection refused" errors as errNotConnected.
|
||||
if IsConnRefusedErr(urlErr.Err) {
|
||||
return errNotConnected
|
||||
}
|
||||
}
|
||||
return dErr
|
||||
}
|
||||
@ -136,15 +137,16 @@ func (target *WebhookTarget) send(eventData event.Event) error {
|
||||
// Send - reads an event from store and sends it to webhook.
|
||||
func (target *WebhookTarget) Send(eventKey string) error {
|
||||
|
||||
urlStr, pErr := xnet.ParseURL(target.args.Endpoint.String())
|
||||
u, pErr := xnet.ParseURL(target.args.Endpoint.String())
|
||||
if pErr != nil {
|
||||
return pErr
|
||||
}
|
||||
_, dErr := net.Dial("tcp", urlStr.Host)
|
||||
if dErr != nil {
|
||||
// To treat "connection refused" errors as errNotConnected.
|
||||
if IsConnRefusedErr(dErr) {
|
||||
return errNotConnected
|
||||
if dErr := u.DialHTTP(); dErr != nil {
|
||||
if urlErr, ok := dErr.(*url.Error); ok {
|
||||
// To treat "connection refused" errors as errNotConnected.
|
||||
if IsConnRefusedErr(urlErr.Err) {
|
||||
return errNotConnected
|
||||
}
|
||||
}
|
||||
return dErr
|
||||
}
|
||||
|
@ -19,9 +19,12 @@ package net
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// URL - improved JSON friendly url.URL.
|
||||
@ -79,6 +82,27 @@ func (u *URL) UnmarshalJSON(data []byte) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DialHTTP - dials the url to check the connection.
|
||||
func (u URL) DialHTTP() error {
|
||||
var client = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
DialContext: (&net.Dialer{
|
||||
Timeout: 2 * time.Second,
|
||||
}).DialContext,
|
||||
},
|
||||
}
|
||||
req, err := http.NewRequest("POST", u.String(), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp.Body.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
// ParseURL - parses string into URL.
|
||||
func ParseURL(s string) (u *URL, err error) {
|
||||
var uu *url.URL
|
||||
|
Loading…
Reference in New Issue
Block a user