diff --git a/config/endpoint/status.go b/config/endpoint/status.go index f1a725ba7..bd3cd955e 100644 --- a/config/endpoint/status.go +++ b/config/endpoint/status.go @@ -1,5 +1,7 @@ package endpoint +import "github.com/TwiN/gatus/v5/config/endpoint/ui" + // Status contains the evaluation Results of an Endpoint type Status struct { // Name of the endpoint @@ -23,16 +25,19 @@ type Status struct { // // To retrieve the uptime between two time, use store.GetUptimeByKey. Uptime *Uptime `json:"-"` + + UiConfig *ui.Config `json:"uiConfig,omitempty"` } // NewStatus creates a new Status -func NewStatus(group, name string) *Status { +func NewStatus(group, name string, uiConfig ui.Config) *Status { return &Status{ - Name: name, - Group: group, - Key: ConvertGroupAndEndpointNameToKey(group, name), - Results: make([]*Result, 0), - Events: make([]*Event, 0), - Uptime: NewUptime(), + Name: name, + Group: group, + Key: ConvertGroupAndEndpointNameToKey(group, name), + Results: make([]*Result, 0), + Events: make([]*Event, 0), + Uptime: NewUptime(), + UiConfig: &uiConfig, } } diff --git a/config/endpoint/status_test.go b/config/endpoint/status_test.go index 510f9b514..88d6ef698 100644 --- a/config/endpoint/status_test.go +++ b/config/endpoint/status_test.go @@ -6,7 +6,7 @@ import ( func TestNewEndpointStatus(t *testing.T) { ep := &Endpoint{Name: "name", Group: "group"} - status := NewStatus(ep.Group, ep.Name) + status := NewStatus(ep.Group, ep.Name, *ep.UIConfig) if status.Name != ep.Name { t.Errorf("expected %s, got %s", ep.Name, status.Name) } diff --git a/config/endpoint/ui/ui.go b/config/endpoint/ui/ui.go index 5a13ccdcf..13045fe68 100644 --- a/config/endpoint/ui/ui.go +++ b/config/endpoint/ui/ui.go @@ -18,6 +18,14 @@ type Config struct { // Badge is the configuration for the badges generated Badge *Badge `yaml:"badge"` + + Menu []MenuItem `yaml:"menu"` +} + +type MenuItem struct { + Name string `yaml:"name"` + Type string `yaml:"type"` + Value string `yaml:"value"` } type Badge struct { @@ -61,5 +69,6 @@ func GetDefaultConfig() *Config { Thresholds: []int{50, 200, 300, 500, 750}, }, }, + Menu: []MenuItem{}, } } diff --git a/storage/store/memory/memory.go b/storage/store/memory/memory.go index 6451381df..49b8d5719 100644 --- a/storage/store/memory/memory.go +++ b/storage/store/memory/memory.go @@ -145,7 +145,7 @@ func (s *Store) Insert(ep *endpoint.Endpoint, result *endpoint.Result) error { s.Lock() status, exists := s.cache.Get(key) if !exists { - status = endpoint.NewStatus(ep.Group, ep.Name) + status = endpoint.NewStatus(ep.Group, ep.Name, *ep.UIConfig) status.(*endpoint.Status).Events = append(status.(*endpoint.Status).Events, &endpoint.Event{ Type: endpoint.EventStart, Timestamp: time.Now(), diff --git a/storage/store/memory/uptime_test.go b/storage/store/memory/uptime_test.go index 3d9f36c1b..767c24af3 100644 --- a/storage/store/memory/uptime_test.go +++ b/storage/store/memory/uptime_test.go @@ -9,7 +9,7 @@ import ( func TestProcessUptimeAfterResult(t *testing.T) { ep := &endpoint.Endpoint{Name: "name", Group: "group"} - status := endpoint.NewStatus(ep.Group, ep.Name) + status := endpoint.NewStatus(ep.Group, ep.Name, *ep.UIConfig) uptime := status.Uptime now := time.Now() @@ -44,7 +44,7 @@ func TestProcessUptimeAfterResult(t *testing.T) { func TestAddResultUptimeIsCleaningUpAfterItself(t *testing.T) { ep := &endpoint.Endpoint{Name: "name", Group: "group"} - status := endpoint.NewStatus(ep.Group, ep.Name) + status := endpoint.NewStatus(ep.Group, ep.Name, *ep.UIConfig) now := time.Now() now = time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), 0, 0, 0, now.Location()) // Start 12 days ago diff --git a/storage/store/memory/util.go b/storage/store/memory/util.go index 961f740ab..bc5a0b2b0 100644 --- a/storage/store/memory/util.go +++ b/storage/store/memory/util.go @@ -10,10 +10,11 @@ import ( // within the range defined by the page and pageSize parameters func ShallowCopyEndpointStatus(ss *endpoint.Status, params *paging.EndpointStatusParams) *endpoint.Status { shallowCopy := &endpoint.Status{ - Name: ss.Name, - Group: ss.Group, - Key: ss.Key, - Uptime: endpoint.NewUptime(), + Name: ss.Name, + Group: ss.Group, + Key: ss.Key, + Uptime: endpoint.NewUptime(), + UiConfig: ss.UiConfig, } numberOfResults := len(ss.Results) resultsStart, resultsEnd := getStartAndEndIndex(numberOfResults, params.ResultsPage, params.ResultsPageSize) diff --git a/storage/store/memory/util_bench_test.go b/storage/store/memory/util_bench_test.go index 36252829b..9f8a28171 100644 --- a/storage/store/memory/util_bench_test.go +++ b/storage/store/memory/util_bench_test.go @@ -10,7 +10,7 @@ import ( func BenchmarkShallowCopyEndpointStatus(b *testing.B) { ep := &testEndpoint - status := endpoint.NewStatus(ep.Group, ep.Name) + status := endpoint.NewStatus(ep.Group, ep.Name, *ep.UIConfig) for i := 0; i < common.MaximumNumberOfResults; i++ { AddResult(status, &testSuccessfulResult) } diff --git a/storage/store/memory/util_test.go b/storage/store/memory/util_test.go index 1de445e75..43d250fcc 100644 --- a/storage/store/memory/util_test.go +++ b/storage/store/memory/util_test.go @@ -11,7 +11,7 @@ import ( func TestAddResult(t *testing.T) { ep := &endpoint.Endpoint{Name: "name", Group: "group"} - endpointStatus := endpoint.NewStatus(ep.Group, ep.Name) + endpointStatus := endpoint.NewStatus(ep.Group, ep.Name, *ep.UIConfig) for i := 0; i < (common.MaximumNumberOfResults+common.MaximumNumberOfEvents)*2; i++ { AddResult(endpointStatus, &endpoint.Result{Success: i%2 == 0, Timestamp: time.Now()}) } @@ -27,7 +27,7 @@ func TestAddResult(t *testing.T) { func TestShallowCopyEndpointStatus(t *testing.T) { ep := &endpoint.Endpoint{Name: "name", Group: "group"} - endpointStatus := endpoint.NewStatus(ep.Group, ep.Name) + endpointStatus := endpoint.NewStatus(ep.Group, ep.Name, *ep.UIConfig) ts := time.Now().Add(-25 * time.Hour) for i := 0; i < 25; i++ { AddResult(endpointStatus, &endpoint.Result{Success: i%2 == 0, Timestamp: ts}) diff --git a/storage/store/sql/sql.go b/storage/store/sql/sql.go index 30b7906fd..971bb48d5 100644 --- a/storage/store/sql/sql.go +++ b/storage/store/sql/sql.go @@ -10,6 +10,7 @@ import ( "github.com/TwiN/gatus/v5/alerting/alert" "github.com/TwiN/gatus/v5/config/endpoint" + "github.com/TwiN/gatus/v5/config/endpoint/ui" "github.com/TwiN/gatus/v5/storage/store/common" "github.com/TwiN/gatus/v5/storage/store/common/paging" "github.com/TwiN/gocache/v2" @@ -652,7 +653,7 @@ func (s *Store) getEndpointStatusByKey(tx *sql.Tx, key string, parameters *pagin if err != nil { return nil, err } - endpointStatus := endpoint.NewStatus(group, endpointName) + endpointStatus := endpoint.NewStatus(group, endpointName, *ui.GetDefaultConfig()) if parameters.EventsPageSize > 0 { if endpointStatus.Events, err = s.getEndpointEventsByEndpointID(tx, endpointID, parameters.EventsPage, parameters.EventsPageSize); err != nil { logr.Errorf("[sql.getEndpointStatusByKey] Failed to retrieve events for key=%s: %s", key, err.Error()) diff --git a/web/app/src/components/Endpoint.vue b/web/app/src/components/Endpoint.vue index f1f41e054..8552170f2 100644 --- a/web/app/src/components/Endpoint.vue +++ b/web/app/src/components/Endpoint.vue @@ -6,6 +6,23 @@ {{ data.name }} | {{ data.results[data.results.length - 1].hostname }} +