forked from CastawayLabs/cachet-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- abstract type - http, tcp, icmp & dns monitor types - unmarshal from json into any monitor type
- Loading branch information
1 parent
0cd6fa1
commit 36bf228
Showing
12 changed files
with
341 additions
and
257 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 |
---|---|---|
@@ -1,7 +1,56 @@ | ||
package cachet | ||
|
||
import ( | ||
"bytes" | ||
"crypto/tls" | ||
"errors" | ||
"io/ioutil" | ||
"net/http" | ||
) | ||
|
||
type CachetAPI struct { | ||
Url string `json:"api_url"` | ||
Token string `json:"api_token"` | ||
URL string `json:"url"` | ||
Token string `json:"token"` | ||
Insecure bool `json:"insecure"` | ||
} | ||
|
||
func (api CachetAPI) Ping() error { | ||
resp, _, err := api.NewRequest("GET", "/ping", nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if resp.StatusCode != 200 { | ||
return errors.New("API Responded with non-200 status code") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (api CachetAPI) NewRequest(requestType, url string, reqBody []byte) (*http.Response, []byte, error) { | ||
req, err := http.NewRequest(requestType, api.URL+url, bytes.NewBuffer(reqBody)) | ||
|
||
req.Header.Set("Content-Type", "application/json") | ||
req.Header.Set("X-Cachet-Token", api.Token) | ||
|
||
transport := &http.Transport{ | ||
Proxy: http.ProxyFromEnvironment, | ||
} | ||
if api.Insecure { | ||
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} | ||
} | ||
|
||
client := &http.Client{ | ||
Transport: transport, | ||
} | ||
|
||
res, err := client.Do(req) | ||
if err != nil { | ||
return nil, []byte{}, err | ||
} | ||
|
||
defer res.Body.Close() | ||
body, _ := ioutil.ReadAll(res.Body) | ||
|
||
return res, body, nil | ||
} |
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
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
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,3 @@ | ||
package cachet | ||
|
||
type DNSMonitor struct{} |
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.