mirror of https://github.com/statping/statping
HTML updates - notifier changes
parent
2385cf88e1
commit
361d4e1f58
|
@ -164,9 +164,11 @@ func (s *Service) checkHttp(record bool) *Service {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
contents, err := ioutil.ReadAll(response.Body)
|
||||||
|
s.LastResponse = string(contents)
|
||||||
|
s.LastStatusCode = response.StatusCode
|
||||||
|
|
||||||
if s.Expected != "" {
|
if s.Expected != "" {
|
||||||
contents, err := ioutil.ReadAll(response.Body)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Log(2, err)
|
utils.Log(2, err)
|
||||||
}
|
}
|
||||||
|
@ -175,8 +177,6 @@ func (s *Service) checkHttp(record bool) *Service {
|
||||||
utils.Log(2, err)
|
utils.Log(2, err)
|
||||||
}
|
}
|
||||||
if !match {
|
if !match {
|
||||||
s.LastResponse = string(contents)
|
|
||||||
s.LastStatusCode = response.StatusCode
|
|
||||||
if record {
|
if record {
|
||||||
recordFailure(s, fmt.Sprintf("HTTP Response Body did not match '%v'", s.Expected))
|
recordFailure(s, fmt.Sprintf("HTTP Response Body did not match '%v'", s.Expected))
|
||||||
}
|
}
|
||||||
|
@ -184,14 +184,11 @@ func (s *Service) checkHttp(record bool) *Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if s.ExpectedStatus != response.StatusCode {
|
if s.ExpectedStatus != response.StatusCode {
|
||||||
//s.LastResponse = string(contents)
|
|
||||||
s.LastStatusCode = response.StatusCode
|
|
||||||
if record {
|
if record {
|
||||||
recordFailure(s, fmt.Sprintf("HTTP Status Code %v did not match %v", response.StatusCode, s.ExpectedStatus))
|
recordFailure(s, fmt.Sprintf("HTTP Status Code %v did not match %v", response.StatusCode, s.ExpectedStatus))
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
s.LastStatusCode = response.StatusCode
|
|
||||||
s.Online = true
|
s.Online = true
|
||||||
if record {
|
if record {
|
||||||
recordSuccess(s)
|
recordSuccess(s)
|
||||||
|
|
|
@ -358,11 +358,6 @@ func (n *Notification) GetValue(dbField string) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Testable returns true if it includes the CoreEvents interface
|
|
||||||
func (n *Notification) Testable() bool {
|
|
||||||
return isType(n, new(Tester))
|
|
||||||
}
|
|
||||||
|
|
||||||
// isType will return true if a variable can implement an interface
|
// isType will return true if a variable can implement an interface
|
||||||
func isType(n interface{}, obj interface{}) bool {
|
func isType(n interface{}, obj interface{}) bool {
|
||||||
one := reflect.TypeOf(n)
|
one := reflect.TypeOf(n)
|
||||||
|
|
|
@ -52,6 +52,7 @@ var slacker = &Slack{¬ifier.Notification{
|
||||||
Placeholder: "Insert your Slack webhook URL here.",
|
Placeholder: "Insert your Slack webhook URL here.",
|
||||||
SmallText: "Incoming Webhook URL from <a href=\"https://api.slack.com/apps\" target=\"_blank\">Slack Apps</a>",
|
SmallText: "Incoming Webhook URL from <a href=\"https://api.slack.com/apps\" target=\"_blank\">Slack Apps</a>",
|
||||||
DbField: "Host",
|
DbField: "Host",
|
||||||
|
Required: true,
|
||||||
}}},
|
}}},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ func TestSlackNotifier(t *testing.T) {
|
||||||
|
|
||||||
t.Run("Slack Queue", func(t *testing.T) {
|
t.Run("Slack Queue", func(t *testing.T) {
|
||||||
go notifier.Queue(slacker)
|
go notifier.Queue(slacker)
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(4 * time.Second)
|
||||||
assert.Equal(t, SLACK_URL, slacker.Host)
|
assert.Equal(t, SLACK_URL, slacker.Host)
|
||||||
assert.Equal(t, 0, len(slacker.Queue))
|
assert.Equal(t, 0, len(slacker.Queue))
|
||||||
})
|
})
|
||||||
|
|
|
@ -45,21 +45,25 @@ var twilioNotifier = &twilio{¬ifier.Notification{
|
||||||
Title: "Account Sid",
|
Title: "Account Sid",
|
||||||
Placeholder: "Insert your Twilio Account Sid",
|
Placeholder: "Insert your Twilio Account Sid",
|
||||||
DbField: "api_key",
|
DbField: "api_key",
|
||||||
|
Required: true,
|
||||||
}, {
|
}, {
|
||||||
Type: "text",
|
Type: "text",
|
||||||
Title: "Account Token",
|
Title: "Account Token",
|
||||||
Placeholder: "Insert your Twilio Account Token",
|
Placeholder: "Insert your Twilio Account Token",
|
||||||
DbField: "api_secret",
|
DbField: "api_secret",
|
||||||
|
Required: true,
|
||||||
}, {
|
}, {
|
||||||
Type: "text",
|
Type: "text",
|
||||||
Title: "SMS to Phone Number",
|
Title: "SMS to Phone Number",
|
||||||
Placeholder: "18555555555",
|
Placeholder: "18555555555",
|
||||||
DbField: "Var1",
|
DbField: "Var1",
|
||||||
|
Required: true,
|
||||||
}, {
|
}, {
|
||||||
Type: "text",
|
Type: "text",
|
||||||
Title: "From Phone Number",
|
Title: "From Phone Number",
|
||||||
Placeholder: "18555555555",
|
Placeholder: "18555555555",
|
||||||
DbField: "Var2",
|
DbField: "Var2",
|
||||||
|
Required: true,
|
||||||
}}},
|
}}},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,9 +99,11 @@ func (u *twilio) Send(msg interface{}) error {
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
contents, _ := ioutil.ReadAll(res.Body)
|
contents, _ := ioutil.ReadAll(res.Body)
|
||||||
success, twilioRes := twilioSuccess(contents)
|
success, _ := twilioSuccess(contents)
|
||||||
if !success {
|
if !success {
|
||||||
return errors.New(fmt.Sprintf("Twilio didn't receive the expected status of 'enque' from API got: %v", twilioRes))
|
errorOut := twilioError(contents)
|
||||||
|
out := fmt.Sprintf("Error code %v - %v", errorOut.Code, errorOut.Message)
|
||||||
|
return errors.New(out)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -127,6 +133,12 @@ func (u *twilio) OnSave() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OnTest will test the Twilio SMS messaging
|
||||||
|
func (u *twilio) OnTest() error {
|
||||||
|
msg := fmt.Sprintf("Testing the Twilio SMS Notifier")
|
||||||
|
return u.Send(msg)
|
||||||
|
}
|
||||||
|
|
||||||
func twilioSuccess(res []byte) (bool, TwilioResponse) {
|
func twilioSuccess(res []byte) (bool, TwilioResponse) {
|
||||||
var obj TwilioResponse
|
var obj TwilioResponse
|
||||||
json.Unmarshal(res, &obj)
|
json.Unmarshal(res, &obj)
|
||||||
|
@ -136,6 +148,19 @@ func twilioSuccess(res []byte) (bool, TwilioResponse) {
|
||||||
return false, obj
|
return false, obj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func twilioError(res []byte) TwilioError {
|
||||||
|
var obj TwilioError
|
||||||
|
json.Unmarshal(res, &obj)
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
type TwilioError struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
MoreInfo string `json:"more_info"`
|
||||||
|
Status int `json:"status"`
|
||||||
|
}
|
||||||
|
|
||||||
type TwilioResponse struct {
|
type TwilioResponse struct {
|
||||||
Sid string `json:"sid"`
|
Sid string `json:"sid"`
|
||||||
DateCreated string `json:"date_created"`
|
DateCreated string `json:"date_created"`
|
||||||
|
|
|
@ -44,7 +44,6 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTwilioNotifier(t *testing.T) {
|
func TestTwilioNotifier(t *testing.T) {
|
||||||
t.SkipNow()
|
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
if TWILIO_SID == "" || TWILIO_SECRET == "" || TWILIO_FROM == "" {
|
if TWILIO_SID == "" || TWILIO_SECRET == "" || TWILIO_FROM == "" {
|
||||||
t.Log("twilio notifier testing skipped, missing TWILIO_SID environment variable")
|
t.Log("twilio notifier testing skipped, missing TWILIO_SID environment variable")
|
||||||
|
@ -73,7 +72,7 @@ func TestTwilioNotifier(t *testing.T) {
|
||||||
|
|
||||||
t.Run("Twilio OnFailure", func(t *testing.T) {
|
t.Run("Twilio OnFailure", func(t *testing.T) {
|
||||||
twilioNotifier.OnFailure(TestService, TestFailure)
|
twilioNotifier.OnFailure(TestService, TestFailure)
|
||||||
assert.Len(t, twilioNotifier.Queue, 2)
|
assert.Len(t, twilioNotifier.Queue, 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Twilio Check Offline", func(t *testing.T) {
|
t.Run("Twilio Check Offline", func(t *testing.T) {
|
||||||
|
@ -82,7 +81,7 @@ func TestTwilioNotifier(t *testing.T) {
|
||||||
|
|
||||||
t.Run("Twilio OnSuccess", func(t *testing.T) {
|
t.Run("Twilio OnSuccess", func(t *testing.T) {
|
||||||
twilioNotifier.OnSuccess(TestService)
|
twilioNotifier.OnSuccess(TestService)
|
||||||
assert.Len(t, twilioNotifier.Queue, 3)
|
assert.Len(t, twilioNotifier.Queue, 2)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Twilio Check Back Online", func(t *testing.T) {
|
t.Run("Twilio Check Back Online", func(t *testing.T) {
|
||||||
|
@ -91,7 +90,7 @@ func TestTwilioNotifier(t *testing.T) {
|
||||||
|
|
||||||
t.Run("Twilio OnSuccess Again", func(t *testing.T) {
|
t.Run("Twilio OnSuccess Again", func(t *testing.T) {
|
||||||
twilioNotifier.OnSuccess(TestService)
|
twilioNotifier.OnSuccess(TestService)
|
||||||
assert.Len(t, twilioNotifier.Queue, 3)
|
assert.Len(t, twilioNotifier.Queue, 2)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Twilio Send", func(t *testing.T) {
|
t.Run("Twilio Send", func(t *testing.T) {
|
||||||
|
|
|
@ -145,6 +145,11 @@ HTML, BODY {
|
||||||
height: 170px;
|
height: 170px;
|
||||||
width: 100%; }
|
width: 100%; }
|
||||||
|
|
||||||
|
.service-chart-container {
|
||||||
|
position: relative;
|
||||||
|
height: 400px;
|
||||||
|
width: 100%; }
|
||||||
|
|
||||||
.btn-primary {
|
.btn-primary {
|
||||||
background-color: #3e9bff;
|
background-color: #3e9bff;
|
||||||
border-color: #006fe6;
|
border-color: #006fe6;
|
||||||
|
@ -688,6 +693,9 @@ HTML, BODY {
|
||||||
border-bottom-left-radius: 0; }
|
border-bottom-left-radius: 0; }
|
||||||
|
|
||||||
.list-group-item P {
|
.list-group-item P {
|
||||||
font-size: 0.7rem; } }
|
font-size: 0.7rem; }
|
||||||
|
|
||||||
|
.service-chart-container {
|
||||||
|
height: 200px; } }
|
||||||
|
|
||||||
/*# sourceMappingURL=base.css.map */
|
/*# sourceMappingURL=base.css.map */
|
||||||
|
|
|
@ -148,9 +148,15 @@ HTML,BODY {
|
||||||
}
|
}
|
||||||
|
|
||||||
.chart-container {
|
.chart-container {
|
||||||
position: relative;
|
position: relative;
|
||||||
height: 170px;
|
height: 170px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.service-chart-container {
|
||||||
|
position: relative;
|
||||||
|
height: 400px;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
@mixin dynamic-color-hov($color) {
|
@mixin dynamic-color-hov($color) {
|
||||||
|
|
|
@ -96,4 +96,8 @@
|
||||||
.list-group-item P {
|
.list-group-item P {
|
||||||
font-size: 0.7rem;
|
font-size: 0.7rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.service-chart-container {
|
||||||
|
height: 200px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,9 @@
|
||||||
|
|
||||||
<div class="col-10 offset-1 col-md-8 offset-md-2 mt-md-2">
|
<div class="col-10 offset-1 col-md-8 offset-md-2 mt-md-2">
|
||||||
|
|
||||||
<div class="col-12 col-md-6 offset-md-3 mb-4"><img class="col-12 mt-5 mt-md-0" src="/statup.png"></div>
|
<div class="col-12 col-md-8 offset-md-2 mb-4">
|
||||||
|
<img class="col-12 mt-5 mt-md-0" src="/statup.png">
|
||||||
|
</div>
|
||||||
|
|
||||||
{{ if .Error }}
|
{{ if .Error }}
|
||||||
<div class="alert alert-danger" role="alert">
|
<div class="alert alert-danger" role="alert">
|
||||||
|
|
|
@ -57,11 +57,11 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="chart-container" style="height: 400px">
|
<div class="service-chart-container">
|
||||||
<canvas id="service"></canvas>
|
<canvas id="service"></canvas>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form id="service_date_form" class="row mt-2 mb-3">
|
<form id="service_date_form" class="col-12 mt-2 mb-3">
|
||||||
<span id="start_date" class="text-muted small float-left pointer">{{FromUnix .Start}}</span>
|
<span id="start_date" class="text-muted small float-left pointer">{{FromUnix .Start}}</span>
|
||||||
<span id="end_date" class="text-muted small float-right pointer" style="position: absolute;right: 0;">{{FromUnix .End}}</span>
|
<span id="end_date" class="text-muted small float-right pointer" style="position: absolute;right: 0;">{{FromUnix .End}}</span>
|
||||||
<input type="hidden" name="start" class="form-control" id="service_start" spellcheck="false">
|
<input type="hidden" name="start" class="form-control" id="service_start" spellcheck="false">
|
||||||
|
|
Loading…
Reference in New Issue