forked from prometheus/alertmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlertView.elm
156 lines (134 loc) · 4.89 KB
/
AlertView.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
module Views.AlertList.AlertView exposing (addLabelMsg, view)
import Data.GettableAlert exposing (GettableAlert)
import Dict
import Html exposing (..)
import Html.Attributes exposing (class, href, style, title, value)
import Html.Events exposing (onClick)
import Types exposing (Msg(..))
import Url exposing (percentEncode)
import Utils.Filter
import Views.AlertList.Types exposing (AlertListMsg(..))
import Views.FilterBar.Types as FilterBarTypes
import Views.Shared.Alert exposing (annotation, annotationsButton, generatorUrlButton, titleView)
import Views.SilenceForm.Parsing exposing (newSilenceFromAlertLabels)
view : List ( String, String ) -> Maybe String -> GettableAlert -> Html Msg
view labels maybeActiveId alert =
let
-- remove the grouping labels, and bring the alertname to front
ungroupedLabels =
alert.labels
|> Dict.toList
|> List.filter ((\b a -> List.member a b) labels >> not)
|> List.partition (Tuple.first >> (==) "alertname")
|> (\( a, b ) -> a ++ b)
in
li
[ -- speedup rendering in Chrome, because list-group-item className
-- creates a new layer in the rendering engine
style "position" "static"
, class "align-items-start list-group-item border-0 p-0 mb-4"
]
[ div
[ class "w-100 mb-2 d-flex align-items-start" ]
[ titleView alert
, if Dict.size alert.annotations > 0 then
annotationsButton maybeActiveId alert
|> Html.map (\msg -> MsgForAlertList (SetActive msg))
else
text ""
, case alert.generatorURL of
Just url ->
generatorUrlButton url
Nothing ->
text ""
, silenceButton alert
, inhibitedIcon alert
, linkButton alert
]
, if maybeActiveId == Just alert.fingerprint then
table [ class "table w-100 mb-1" ] (List.map annotation <| Dict.toList alert.annotations)
else
text ""
, div [] (List.map labelButton ungroupedLabels)
]
labelButton : ( String, String ) -> Html Msg
labelButton ( key, val ) =
div
[ class "btn-group mr-2 mb-2" ]
[ span
[ class "btn btn-sm border-right-0 text-muted"
-- have to reset bootstrap button styles to make the text selectable
, style "user-select" "initial"
-- have to reset bootstrap button styles to make the text selectable
, style "-moz-user-select" "initial"
-- have to reset bootstrap button styles to make the text selectable
, style "-webkit-user-select" "initial"
-- have to reset bootstrap button styles to make the text selectable
, style "border-color" "#ccc"
]
[ text (key ++ "=\"" ++ val ++ "\"") ]
, button
[ class "btn btn-sm bg-faded btn-outline-secondary"
, onClick (addLabelMsg ( key, val ))
, title "Filter by this label"
]
[ text "+" ]
]
addLabelMsg : ( String, String ) -> Msg
addLabelMsg ( key, value ) =
FilterBarTypes.AddFilterMatcher False
{ key = key
, op = Utils.Filter.Eq
, value = value
}
|> MsgForFilterBar
|> MsgForAlertList
linkButton : GettableAlert -> Html Msg
linkButton alert =
let
link =
alert.labels
|> Dict.toList
|> List.map (\( k, v ) -> Utils.Filter.Matcher k Utils.Filter.Eq v)
|> Utils.Filter.stringifyFilter
|> percentEncode
|> (++) "#/alerts?filter="
in
a
[ class "btn btn-outline-info border-0"
, href link
]
[ i [ class "fa fa-link mr-2" ] []
, text "Link"
]
silenceButton : GettableAlert -> Html Msg
silenceButton alert =
case List.head alert.status.silencedBy of
Just sId ->
a
[ class "btn btn-outline-danger border-0"
, href ("#/silences/" ++ sId)
]
[ i [ class "fa fa-bell-slash mr-2" ] []
, text "Silenced"
]
Nothing ->
a
[ class "btn btn-outline-info border-0"
, href (newSilenceFromAlertLabels alert.labels)
]
[ i [ class "fa fa-bell-slash-o mr-2" ] []
, text "Silence"
]
inhibitedIcon : GettableAlert -> Html Msg
inhibitedIcon alert =
case List.head alert.status.inhibitedBy of
Just _ ->
a
[ class "btn btn-outline-info border-0 text-info"
]
[ i [ class "fa fa-eye-slash mr-2" ] []
, text "Inhibited"
]
Nothing ->
text ""