HTML updates - notifier changes

pull/78/head
hunterlong 2018-09-26 18:49:21 -07:00
parent 2385cf88e1
commit 361d4e1f58
11 changed files with 62 additions and 25 deletions

View File

@ -164,9 +164,11 @@ func (s *Service) checkHttp(record bool) *Service {
return s
}
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
s.LastResponse = string(contents)
s.LastStatusCode = response.StatusCode
if s.Expected != "" {
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
utils.Log(2, err)
}
@ -175,8 +177,6 @@ func (s *Service) checkHttp(record bool) *Service {
utils.Log(2, err)
}
if !match {
s.LastResponse = string(contents)
s.LastStatusCode = response.StatusCode
if record {
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 {
//s.LastResponse = string(contents)
s.LastStatusCode = response.StatusCode
if record {
recordFailure(s, fmt.Sprintf("HTTP Status Code %v did not match %v", response.StatusCode, s.ExpectedStatus))
}
return s
}
s.LastStatusCode = response.StatusCode
s.Online = true
if record {
recordSuccess(s)

View File

@ -358,11 +358,6 @@ func (n *Notification) GetValue(dbField string) string {
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
func isType(n interface{}, obj interface{}) bool {
one := reflect.TypeOf(n)

View File

@ -52,6 +52,7 @@ var slacker = &Slack{&notifier.Notification{
Placeholder: "Insert your Slack webhook URL here.",
SmallText: "Incoming Webhook URL from <a href=\"https://api.slack.com/apps\" target=\"_blank\">Slack Apps</a>",
DbField: "Host",
Required: true,
}}},
}

View File

@ -108,7 +108,7 @@ func TestSlackNotifier(t *testing.T) {
t.Run("Slack Queue", func(t *testing.T) {
go notifier.Queue(slacker)
time.Sleep(2 * time.Second)
time.Sleep(4 * time.Second)
assert.Equal(t, SLACK_URL, slacker.Host)
assert.Equal(t, 0, len(slacker.Queue))
})

View File

@ -45,21 +45,25 @@ var twilioNotifier = &twilio{&notifier.Notification{
Title: "Account Sid",
Placeholder: "Insert your Twilio Account Sid",
DbField: "api_key",
Required: true,
}, {
Type: "text",
Title: "Account Token",
Placeholder: "Insert your Twilio Account Token",
DbField: "api_secret",
Required: true,
}, {
Type: "text",
Title: "SMS to Phone Number",
Placeholder: "18555555555",
DbField: "Var1",
Required: true,
}, {
Type: "text",
Title: "From Phone Number",
Placeholder: "18555555555",
DbField: "Var2",
Required: true,
}}},
}
@ -95,9 +99,11 @@ func (u *twilio) Send(msg interface{}) error {
}
defer res.Body.Close()
contents, _ := ioutil.ReadAll(res.Body)
success, twilioRes := twilioSuccess(contents)
success, _ := twilioSuccess(contents)
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
}
@ -127,6 +133,12 @@ func (u *twilio) OnSave() error {
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) {
var obj TwilioResponse
json.Unmarshal(res, &obj)
@ -136,6 +148,19 @@ func twilioSuccess(res []byte) (bool, TwilioResponse) {
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 {
Sid string `json:"sid"`
DateCreated string `json:"date_created"`

View File

@ -44,7 +44,6 @@ func init() {
}
func TestTwilioNotifier(t *testing.T) {
t.SkipNow()
t.Parallel()
if TWILIO_SID == "" || TWILIO_SECRET == "" || TWILIO_FROM == "" {
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) {
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) {
@ -82,7 +81,7 @@ func TestTwilioNotifier(t *testing.T) {
t.Run("Twilio OnSuccess", func(t *testing.T) {
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) {
@ -91,7 +90,7 @@ func TestTwilioNotifier(t *testing.T) {
t.Run("Twilio OnSuccess Again", func(t *testing.T) {
twilioNotifier.OnSuccess(TestService)
assert.Len(t, twilioNotifier.Queue, 3)
assert.Len(t, twilioNotifier.Queue, 2)
})
t.Run("Twilio Send", func(t *testing.T) {

View File

@ -145,6 +145,11 @@ HTML, BODY {
height: 170px;
width: 100%; }
.service-chart-container {
position: relative;
height: 400px;
width: 100%; }
.btn-primary {
background-color: #3e9bff;
border-color: #006fe6;
@ -688,6 +693,9 @@ HTML, BODY {
border-bottom-left-radius: 0; }
.list-group-item P {
font-size: 0.7rem; } }
font-size: 0.7rem; }
.service-chart-container {
height: 200px; } }
/*# sourceMappingURL=base.css.map */

View File

@ -148,9 +148,15 @@ HTML,BODY {
}
.chart-container {
position: relative;
height: 170px;
width: 100%;
position: relative;
height: 170px;
width: 100%;
}
.service-chart-container {
position: relative;
height: 400px;
width: 100%;
}
@mixin dynamic-color-hov($color) {

View File

@ -96,4 +96,8 @@
.list-group-item P {
font-size: 0.7rem;
}
.service-chart-container {
height: 200px;
}
}

View File

@ -19,7 +19,9 @@
<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 }}
<div class="alert alert-danger" role="alert">

View File

@ -57,11 +57,11 @@
</div>
</div>
<div class="chart-container" style="height: 400px">
<div class="service-chart-container">
<canvas id="service"></canvas>
</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="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">