mirror of https://github.com/statping/statping
tests - Shell Command Notifier - Annoucements in sample/seed
parent
28880e2c5e
commit
e111e91181
|
@ -52,6 +52,13 @@ func SelectMessage(id int64) (*Message, error) {
|
|||
return &message, db.Error
|
||||
}
|
||||
|
||||
func (m *Message) Service() *Service {
|
||||
if m.ServiceId == 0 {
|
||||
return nil
|
||||
}
|
||||
return SelectService(m.ServiceId)
|
||||
}
|
||||
|
||||
// Create will create a Message and insert it into the database
|
||||
func (m *Message) Create() (int64, error) {
|
||||
m.CreatedAt = time.Now().UTC()
|
||||
|
|
|
@ -400,6 +400,18 @@ func (s *Service) Messages() []*Message {
|
|||
return messages
|
||||
}
|
||||
|
||||
// ActiveMessages returns all Messages for a Service
|
||||
func (s *Service) ActiveMessages() []*Message {
|
||||
var messages []*Message
|
||||
msgs := SelectServiceMessages(s.Id)
|
||||
for _, m := range msgs {
|
||||
if m.StartOn.UTC().After(time.Now().UTC()) {
|
||||
messages = append(messages, m)
|
||||
}
|
||||
}
|
||||
return messages
|
||||
}
|
||||
|
||||
// ServicesCount returns the amount of services inside the []*core.Services slice
|
||||
func (c *Core) ServicesCount() int {
|
||||
return len(c.Services)
|
||||
|
|
|
@ -74,6 +74,18 @@
|
|||
<a href="/service/{{ .Id }}" class="btn {{if .Online}}btn-success{{else}}btn-danger{{end}} btn-sm float-right dyn-dark btn-block">View Service</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{if .ActiveMessages}}
|
||||
<div class="col-12 mb-4">
|
||||
{{range .ActiveMessages}}
|
||||
<div class="alert alert-warning" role="alert">
|
||||
<h3>{{.Title}}</h3>
|
||||
<span>{{safe .Description}}</span>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Title</th>
|
||||
<th scope="col">Service</th>
|
||||
<th scope="col">Begins</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -15,6 +17,8 @@
|
|||
{{range .}}
|
||||
<tr>
|
||||
<td>{{.Title}}</td>
|
||||
<td>{{if .Service}}<a href="/service/{{.Service.Id}}">{{.Service.Name}}</a>{{end}}</td>
|
||||
<td>{{Duration 0}}</td>
|
||||
<td class="text-right" id="message_{{.Id}}">
|
||||
<div class="btn-group">
|
||||
<a href="/message/{{.Id}}" class="btn btn-outline-secondary"><i class="fas fa-exclamation-triangle"></i> Edit</a>
|
||||
|
|
|
@ -41,6 +41,17 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{{if $s.ActiveMessages}}
|
||||
<div class="col-12 mb-4">
|
||||
{{range $s.ActiveMessages}}
|
||||
<div class="alert alert-warning" role="alert">
|
||||
<h3>{{.Title}}</h3>
|
||||
<span>{{safe .Description}}</span>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
<div class="service-chart-container">
|
||||
<canvas id="service"></canvas>
|
||||
</div>
|
||||
|
@ -59,15 +70,6 @@
|
|||
<div class="col-12 small text-center mt-3 text-muted">{{$s.DowntimeText}}</div>
|
||||
{{end}}
|
||||
|
||||
{{if $s.Messages}}
|
||||
{{range $s.Messages}}
|
||||
<div class="alert alert-warning" role="alert">
|
||||
<h3>{{.Title}}</h3>
|
||||
<span>{{safe .Description}}</span>
|
||||
</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
{{ if $s.LimitedFailures }}
|
||||
<div class="list-group mt-3 mb-4">
|
||||
{{ range $s.LimitedFailures }}
|
||||
|
|
|
@ -21,15 +21,15 @@ import (
|
|||
|
||||
// Message is for creating Announcements, Alerts and other messages for the end users
|
||||
type Message struct {
|
||||
Id int64 `gorm:"primary_key;column:id"`
|
||||
Title string `gorm:"column:title"`
|
||||
Description string `gorm:"column:description"`
|
||||
StartOn time.Time `gorm:"column:start_on"`
|
||||
EndOn time.Time `gorm:"column:end_on"`
|
||||
ServiceId int64 `gorm:"index;column:service"`
|
||||
NotifyUsers NullBool `gorm:"column:notify_users"`
|
||||
NotifyMethod string `gorm:"column:notify_method"`
|
||||
NotifyBefore time.Duration `gorm:"column:notify_before"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
|
||||
Id int64 `gorm:"primary_key;column:id" json:"id"`
|
||||
Title string `gorm:"column:title" json:"title"`
|
||||
Description string `gorm:"column:description" json:"description"`
|
||||
StartOn time.Time `gorm:"column:start_on" json:"start_on"`
|
||||
EndOn time.Time `gorm:"column:end_on" json:"end_on"`
|
||||
ServiceId int64 `gorm:"index;column:service" json:"service"`
|
||||
NotifyUsers NullBool `gorm:"column:notify_users" json:"notify_users"`
|
||||
NotifyMethod string `gorm:"column:notify_method" json:"notify_method"`
|
||||
NotifyBefore time.Duration `gorm:"column:notify_before" json:"notify_before"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at" json:"updated_at"`
|
||||
}
|
||||
|
|
|
@ -43,12 +43,6 @@ func init() {
|
|||
}
|
||||
}
|
||||
|
||||
func StringPoint(s string) *string {
|
||||
val := new(string)
|
||||
*val = s
|
||||
return val
|
||||
}
|
||||
|
||||
// StringInt converts a string to an int64
|
||||
func StringInt(s string) int64 {
|
||||
num, _ := strconv.Atoi(s)
|
||||
|
|
Loading…
Reference in New Issue