Skip to content

Commit

Permalink
Add notification status (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino authored Nov 24, 2022
1 parent 81de755 commit b3fe1dc
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ For Mac Machines, if unable to download Erlang via `asdf` then run:

```sh
brew install erlang@23
cp -r /opt/homebrew/opt/erlang@23/lib/erlang ~/.asdf/installs/erlang/23.1.5
asdf reshim erlang 23.1.5
cp -r /opt/homebrew/opt/erlang@23/lib/erlang ~/.asdf/installs/erlang/23.3
asdf reshim erlang 23.3
```
5 changes: 4 additions & 1 deletion lib/console/graphql/users.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ defmodule Console.GraphQl.Users do
use Console.GraphQl.Schema.Base
alias Console.GraphQl.Resolvers.User
alias Console.Middleware.{Authenticated, AdminRequired, AllowJwt}
alias Console.Schema.Notification.{Severity, Status}

enum_from_list :permission, Console.Schema.Role, :permissions, []
ecto_enum :severity, Console.Schema.Notification.Severity
ecto_enum :severity, Severity
ecto_enum :notification_status, Status

input_object :user_attributes do
field :name, :string
Expand Down Expand Up @@ -119,6 +121,7 @@ defmodule Console.GraphQl.Users do
field :title, non_null(:string)
field :description, :string
field :fingerprint, non_null(:string)
field :status, :notification_status
field :labels, :map
field :annotations, :map
field :repository, non_null(:string)
Expand Down
4 changes: 3 additions & 1 deletion lib/console/schema/notification.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ defmodule Console.Schema.Notification do
use Piazza.Ecto.Schema

defenum Severity, none: 0, low: 1, medium: 2, high: 3, critical: 4
defenum Status, firing: 0, resolved: 1

schema "notifications" do
field :title, :string
field :description, :string
field :repository, :string
field :status, Status
field :labels, :map
field :annotations, :map
field :fingerprint, :string
Expand All @@ -31,7 +33,7 @@ defmodule Console.Schema.Notification do
from(n in query, order_by: ^order)
end

@valid ~w(title description repository labels annotations fingerprint seen_at severity)a
@valid ~w(title description repository labels annotations fingerprint seen_at severity status)a

def changeset(model, attrs \\ %{}) do
model
Expand Down
1 change: 1 addition & 0 deletions lib/console/services/alertmanager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ defmodule Console.Services.Alertmanager do
labels: alert.labels,
annotations: alert.annotations,
repository: repo,
status: alert.status,
severity: Map.get(alert.labels || %{}, "severity", :none),
seen_at: Timex.now()
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Console.Repo.Migrations.AddNotificationStatus do
use Ecto.Migration

def change do
alter table(:notifications) do
add :status, :integer, default: 0
end
end
end
1 change: 1 addition & 0 deletions test/console/services/alertmanager_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ defmodule Console.Services.AlertmanagerTest do
assert notif.title == alert.summary
assert notif.fingerprint == alert.fingerprint
assert notif.seen_at
assert notif.status == :firing
assert notif.severity == :critical

assert_receive {:event, %PubSub.NotificationCreated{item: found}}
Expand Down

0 comments on commit b3fe1dc

Please sign in to comment.