-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
74 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,11 +24,11 @@ squid-auth-healthcheck --proxy-addr 127.0.0.1 --proxy-username [email protected] - | |
``` | ||
Application Options: | ||
-u, --url= url to check for availability (required) | ||
--auth-type= type of used proxy authentication mechanism. [ntlm, kerberos] (required) | ||
--auth-type= type of used proxy authentication mechanism. [ntlm, kerberos, no] (required) | ||
--proxy-addr= proxy server address (required) | ||
--proxy-port= proxy server port (default: 3128) (default: 3128) | ||
--proxy-username= proxy user login (required) | ||
--proxy-password= proxy user password (required) | ||
--proxy-username= proxy user login | ||
--proxy-password= proxy user password | ||
--timeout= healthcheck connection timeout in seconds (default: 2) (default: 2) | ||
--strict-url the check returns a positive result only if all URLs are available | ||
--strict-auth the check returns a positive result only if url are available with all auth method | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package checker | ||
|
||
import ( | ||
"sync" | ||
|
||
curl "github.com/andelf/go-curl" | ||
) | ||
|
||
type AuthNo struct { | ||
authType string | ||
ProxyAddr string | ||
ProxyPort int | ||
ConnectionTimeout int | ||
} | ||
|
||
func NewAuthNo(ProxyAddr string, ProxyPort int, ConnectionTimeout int) *AuthNo { | ||
var a AuthNo | ||
a.authType = "no" | ||
a.ProxyAddr = ProxyAddr | ||
a.ProxyPort = ProxyPort | ||
a.ConnectionTimeout = ConnectionTimeout | ||
return &a | ||
} | ||
|
||
func (a *AuthNo) Check(urls []string, ch chan HealthResponse, wg *sync.WaitGroup) { | ||
var innerWg sync.WaitGroup | ||
innerWg.Add(len(urls)) | ||
for _, url := range urls { | ||
go func(u string) { | ||
conn := curl.EasyInit() | ||
conn.Setopt(curl.OPT_VERBOSE, 0) | ||
conn.Setopt(curl.OPT_FOLLOWLOCATION, 1) | ||
conn.Setopt(curl.OPT_PROXYTYPE, curl.PROXY_HTTP) | ||
conn.Setopt(curl.OPT_PROXY, a.ProxyAddr) | ||
conn.Setopt(curl.OPT_PROXYPORT, a.ProxyPort) | ||
conn.Setopt(curl.OPT_TIMEOUT, a.ConnectionTimeout) | ||
conn.Setopt(curl.OPT_WRITEFUNCTION, nullHandler) | ||
conn.Setopt(curl.OPT_URL, u) | ||
if err := conn.Perform(); err != nil { | ||
ch <- HealthResponse{u, a.authType, 0, 0} | ||
} else { | ||
code, _ := conn.Getinfo(curl.INFO_RESPONSE_CODE) | ||
responseTime, _ := conn.Getinfo(curl.INFO_TOTAL_TIME) | ||
if code.(int) == 200 { | ||
ch <- HealthResponse{u, a.authType, 1, responseTime.(float64)} | ||
} else { | ||
ch <- HealthResponse{u, a.authType, 0, responseTime.(float64)} | ||
} | ||
} | ||
conn.Cleanup() | ||
innerWg.Done() | ||
}(url) | ||
} | ||
innerWg.Wait() | ||
wg.Done() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters