Skip to content

Commit

Permalink
feat: initial hooks boilerplate and updated screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
mentos1386 committed May 29, 2024
1 parent c51bed6 commit 1ef49c4
Show file tree
Hide file tree
Showing 22 changed files with 1,101 additions and 77 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ Golang selfhosted Status/Healthcheck monitoring app.
- Kinda working atm. ~But look if all the data could be stored/fetched from temporal.~
- [x] Edit/Delete operations for healthchecks and workers.
- [ ] CronJob Healthchecks (via webhooks).
- Allow CronJob monitoring by checking that there was an event at expected time.
- Allow Heartbeat monitoring to alert when events stop coming.
- Allow integration with other services by alerting/transforming when events come.
- [ ] Notifications (webhooks, slack, etc).
- [ ] Incidents (based on script that is triggered by monitors/crobjobs).
- [ ] Prepare i18n.
- [ ] Alpha Version (1H 2024)
- [ ] Alpha Version (3Q 2024)
- [ ] ??
- [ ] Beta Version (2H 2024)
- [ ] Beta Version (4Q 2024)
- [ ] ??
- [ ] Stable Release (2025)
- [ ] Stable Release (1H 2025)

![Screenshot](docs/screenshot.png)
Demo is available at https://zdravko.mnts.dev.
Demo is available at https://zdravko.mnts.dev. More screenshots in the [docs folder](docs/).

# Development

Expand Down
27 changes: 27 additions & 0 deletions database/models/checks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package models

type CheckState string

const (
CheckStateActive CheckState = "ACTIVE"
CheckStatePaused CheckState = "PAUSED"
CheckStateUnknown CheckState = "UNKNOWN"
)

type Check struct {
CreatedAt *Time `db:"created_at"`
UpdatedAt *Time `db:"updated_at"`

Id string `db:"id"`
Name string `db:"name"`

Schedule string `db:"schedule"`
Script string `db:"script"`
Filter string `db:"filter"`
}

type CheckWithWorkerGroups struct {
Check
// List of worker group names
WorkerGroups []string
}
20 changes: 20 additions & 0 deletions database/models/hooks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package models

type HookState string

const (
HookStateActive HookState = "ACTIVE"
HookStatePaused HookState = "PAUSED"
HookStateUnknown HookState = "UNKNOWN"
)

type Hook struct {
CreatedAt *Time `db:"created_at"`
UpdatedAt *Time `db:"updated_at"`

Id string `db:"id"`
Name string `db:"name"`

Schedule string `db:"schedule"`
Script string `db:"script"`
}
73 changes: 0 additions & 73 deletions database/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,6 @@ type OAuth2State struct {
ExpiresAt *Time `db:"expires_at"`
}

type CheckState string

const (
CheckStateActive CheckState = "ACTIVE"
CheckStatePaused CheckState = "PAUSED"
CheckStateUnknown CheckState = "UNKNOWN"
)

type Check struct {
CreatedAt *Time `db:"created_at"`
UpdatedAt *Time `db:"updated_at"`

Id string `db:"id"`
Name string `db:"name"`

Schedule string `db:"schedule"`
Script string `db:"script"`
Filter string `db:"filter"`
}

type CheckWithWorkerGroups struct {
Check
// List of worker group names
WorkerGroups []string
}

type WorkerGroup struct {
CreatedAt *Time `db:"created_at"`
UpdatedAt *Time `db:"updated_at"`
Expand Down Expand Up @@ -102,50 +76,3 @@ type Trigger struct {
Name string `db:"name"`
Script string `db:"script"`
}

type TargetVisibility string

const (
TargetVisibilityPublic TargetVisibility = "PUBLIC"
TargetVisibilityPrivate TargetVisibility = "PRIVATE"
TargetVisibilityUnknown TargetVisibility = "UNKNOWN"
)

type TargetState string

const (
TargetStateActive TargetState = "ACTIVE"
TargetStatePaused TargetState = "PAUSED"
TargetStateUnknown TargetState = "UNKNOWN"
)

type Target struct {
CreatedAt *Time `db:"created_at"`
UpdatedAt *Time `db:"updated_at"`

Id string `db:"id"`
Name string `db:"name"`
Group string `db:"group"`
Visibility TargetVisibility `db:"visibility"`
State TargetState `db:"state"`
Metadata string `db:"metadata"`
}

type TargetStatus string

const (
TargetStatusSuccess TargetStatus = "SUCCESS"
TargetStatusFailure TargetStatus = "FAILURE"
TargetStatusUnknown TargetStatus = "UNKNOWN"
)

type TargetHistory struct {
CreatedAt *Time `db:"created_at"`

TargetId string `db:"target_id"`
WorkerGroupId string `db:"worker_group_id"`
CheckId string `db:"check_id"`

Status TargetStatus `db:"status"`
Note string `db:"note"`
}
48 changes: 48 additions & 0 deletions database/models/target.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package models

type TargetVisibility string

const (
TargetVisibilityPublic TargetVisibility = "PUBLIC"
TargetVisibilityPrivate TargetVisibility = "PRIVATE"
TargetVisibilityUnknown TargetVisibility = "UNKNOWN"
)

type TargetState string

const (
TargetStateActive TargetState = "ACTIVE"
TargetStatePaused TargetState = "PAUSED"
TargetStateUnknown TargetState = "UNKNOWN"
)

type Target struct {
CreatedAt *Time `db:"created_at"`
UpdatedAt *Time `db:"updated_at"`

Id string `db:"id"`
Name string `db:"name"`
Group string `db:"group"`
Visibility TargetVisibility `db:"visibility"`
State TargetState `db:"state"`
Metadata string `db:"metadata"`
}

type TargetStatus string

const (
TargetStatusSuccess TargetStatus = "SUCCESS"
TargetStatusFailure TargetStatus = "FAILURE"
TargetStatusUnknown TargetStatus = "UNKNOWN"
)

type TargetHistory struct {
CreatedAt *Time `db:"created_at"`

TargetId string `db:"target_id"`
WorkerGroupId string `db:"worker_group_id"`
CheckId string `db:"check_id"`

Status TargetStatus `db:"status"`
Note string `db:"note"`
}
30 changes: 30 additions & 0 deletions database/sqlite/migrations/2024-05-29_hooks.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- +migrate Up
CREATE TABLE hooks (
id TEXT NOT NULL,
name TEXT NOT NULL,
schedule TEXT NOT NULL,
script TEXT NOT NULL,

created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ')),
updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ')),

PRIMARY KEY (id),
CONSTRAINT unique_hooks_name UNIQUE (name)
) STRICT;
-- +migrate StatementBegin
CREATE TRIGGER hooks_updated_timestamp AFTER UPDATE ON hooks BEGIN
UPDATE hooks SET updated_at = strftime('%Y-%m-%dT%H:%M:%fZ') WHERE id = NEW.id;
END;
-- +migrate StatementEnd

CREATE TABLE hook_worker_groups (
worker_group_id TEXT NOT NULL,
hook_id TEXT NOT NULL,

PRIMARY KEY (worker_group_id,hook_id),
CONSTRAINT fk_hook_worker_groups_worker_group FOREIGN KEY (worker_group_id) REFERENCES worker_groups(id) ON DELETE CASCADE,
CONSTRAINT fk_hook_worker_groups_hook FOREIGN KEY (hook_id) REFERENCES hooks(id) ON DELETE CASCADE
) STRICT;
-- +migrate Down
DROP TABLE hook_worker_groups;
DROP TABLE hooks;
Binary file added docs/screenshot-checks-describe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot-checks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot-index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot-targets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/screenshot.png
Binary file not shown.
3 changes: 3 additions & 0 deletions internal/server/handlers/examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ check: |
http.get(metadata.spec.url);
}
hook: |
// TODO: Implement hook example
filter: |
target.metadata.kind == "Http" && target.metadata.spec.url != ""
Expand Down
2 changes: 2 additions & 0 deletions internal/server/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type examples struct {
Filter string `yaml:"filter"`
Trigger string `yaml:"trigger"`
Target string `yaml:"target"`
Hook string `yaml:"hook"`
}

var Pages = []*components.Page{
Expand Down Expand Up @@ -69,6 +70,7 @@ func NewBaseHandler(db *sqlx.DB, kvStore database.KeyValueStore, temporal client
examples.Filter = script.EscapeString(examples.Filter)
examples.Trigger = script.EscapeString(examples.Trigger)
examples.Target = script.EscapeString(examples.Target)
examples.Hook = script.EscapeString(examples.Hook)

return &BaseHandler{
db: db,
Expand Down
Loading

0 comments on commit 1ef49c4

Please sign in to comment.