mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Make CI happy
This commit is contained in:
parent
7f05fbcda5
commit
6908e744e1
@ -1,9 +1,9 @@
|
|||||||
package uptimerobot
|
package uptimerobot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"errors"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -92,11 +92,9 @@ func (widget *Widget) contentFrom(monitors []Monitor) string {
|
|||||||
switch monitor.State {
|
switch monitor.State {
|
||||||
case 2:
|
case 2:
|
||||||
prefix += "[green] + "
|
prefix += "[green] + "
|
||||||
break
|
|
||||||
case 8:
|
case 8:
|
||||||
case 9:
|
case 9:
|
||||||
prefix += "[red] - "
|
prefix += "[red] - "
|
||||||
break
|
|
||||||
default:
|
default:
|
||||||
prefix += "[yellow] ~ "
|
prefix += "[yellow] ~ "
|
||||||
}
|
}
|
||||||
@ -113,9 +111,9 @@ func (widget *Widget) contentFrom(monitors []Monitor) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Monitor struct {
|
type Monitor struct {
|
||||||
Name string `json:"friendly_name"`
|
Name string `json:"friendly_name"`
|
||||||
// Monitor state, see: https://uptimerobot.com/api/#parameters
|
// Monitor state, see: https://uptimerobot.com/api/#parameters
|
||||||
State int8 `json:"status"`
|
State int8 `json:"status"`
|
||||||
// Uptime ratio, preformatted, e.g.: 100.000-97.233-96.975
|
// Uptime ratio, preformatted, e.g.: 100.000-97.233-96.975
|
||||||
Uptime string `json:"custom_uptime_ratio"`
|
Uptime string `json:"custom_uptime_ratio"`
|
||||||
}
|
}
|
||||||
@ -124,8 +122,8 @@ func (widget *Widget) getMonitors() ([]Monitor, error) {
|
|||||||
// See: https://uptimerobot.com/api/#getMonitorsWrap
|
// See: https://uptimerobot.com/api/#getMonitorsWrap
|
||||||
resp, err_h := http.PostForm("https://api.uptimerobot.com/v2/getMonitors",
|
resp, err_h := http.PostForm("https://api.uptimerobot.com/v2/getMonitors",
|
||||||
url.Values{
|
url.Values{
|
||||||
"api_key": {widget.settings.apiKey},
|
"api_key": {widget.settings.apiKey},
|
||||||
"format": {"json"},
|
"format": {"json"},
|
||||||
"custom_uptime_ratios": {widget.settings.uptimePeriods},
|
"custom_uptime_ratios": {widget.settings.uptimePeriods},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -138,19 +136,22 @@ func (widget *Widget) getMonitors() ([]Monitor, error) {
|
|||||||
|
|
||||||
// First pass to read the status
|
// First pass to read the status
|
||||||
c := make(map[string]json.RawMessage)
|
c := make(map[string]json.RawMessage)
|
||||||
json.Unmarshal([]byte(body), &c)
|
err_j1 := json.Unmarshal([]byte(body), &c)
|
||||||
|
|
||||||
stat := string(c["stat"])
|
if err_j1 != nil {
|
||||||
if stat != `"ok"` {
|
return nil, err_j1
|
||||||
|
}
|
||||||
|
|
||||||
|
if string(c["stat"]) != `"ok"` {
|
||||||
return nil, errors.New(string(body))
|
return nil, errors.New(string(body))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second pass to get the actual info
|
// Second pass to get the actual info
|
||||||
var monitors []Monitor
|
var monitors []Monitor
|
||||||
err_j := json.Unmarshal(c["monitors"], &monitors)
|
err_j2 := json.Unmarshal(c["monitors"], &monitors)
|
||||||
|
|
||||||
if err_j != nil {
|
if err_j2 != nil {
|
||||||
return nil, err_j
|
return nil, err_j2
|
||||||
}
|
}
|
||||||
|
|
||||||
return monitors, nil
|
return monitors, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user