respect regex matchers when recreating silences (#1697)
* Respect regexes when recreating silences * Generate assets Signed-off-by: stuart nelson <stuartnelson3@gmail.com>
This commit is contained in:
parent
b437240bd9
commit
dba283edd0
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,6 @@
|
|||
module Views.SilenceForm.Parsing exposing (newSilenceFromAlertLabels, silenceFormEditParser, silenceFormNewParser)
|
||||
module Views.SilenceForm.Parsing exposing (newSilenceFromAlertLabels, newSilenceFromMatchers, silenceFormEditParser, silenceFormNewParser)
|
||||
|
||||
import Data.Matcher
|
||||
import Dict exposing (Dict)
|
||||
import Url exposing (percentEncode)
|
||||
import Url.Parser exposing ((</>), (<?>), Parser, map, oneOf, s, string)
|
||||
|
@ -12,9 +13,7 @@ newSilenceFromAlertLabels labels =
|
|||
labels
|
||||
|> Dict.toList
|
||||
|> List.map (\( k, v ) -> Utils.Filter.Matcher k Utils.Filter.Eq v)
|
||||
|> Utils.Filter.stringifyFilter
|
||||
|> percentEncode
|
||||
|> (++) "#/silences/new?filter="
|
||||
|> encodeMatchers
|
||||
|
||||
|
||||
silenceFormNewParser : Parser (List Matcher -> a) a
|
||||
|
@ -28,3 +27,29 @@ silenceFormNewParser =
|
|||
silenceFormEditParser : Parser (String -> a) a
|
||||
silenceFormEditParser =
|
||||
s "silences" </> string </> s "edit"
|
||||
|
||||
|
||||
newSilenceFromMatchers : List Data.Matcher.Matcher -> String
|
||||
newSilenceFromMatchers matchers =
|
||||
matchers
|
||||
|> List.map
|
||||
(\{ name, value, isRegex } ->
|
||||
let
|
||||
op =
|
||||
if isRegex then
|
||||
Utils.Filter.RegexMatch
|
||||
|
||||
else
|
||||
Utils.Filter.Eq
|
||||
in
|
||||
Utils.Filter.Matcher name op value
|
||||
)
|
||||
|> encodeMatchers
|
||||
|
||||
|
||||
encodeMatchers : List Utils.Filter.Matcher -> String
|
||||
encodeMatchers matchers =
|
||||
matchers
|
||||
|> Utils.Filter.stringifyFilter
|
||||
|> percentEncode
|
||||
|> (++) "#/silences/new?filter="
|
||||
|
|
|
@ -15,7 +15,7 @@ import Utils.List
|
|||
import Utils.Views exposing (buttonLink)
|
||||
import Views.FilterBar.Types as FilterBarTypes
|
||||
import Views.Shared.Dialog as Dialog
|
||||
import Views.SilenceForm.Parsing exposing (newSilenceFromAlertLabels)
|
||||
import Views.SilenceForm.Parsing exposing (newSilenceFromMatchers)
|
||||
import Views.SilenceList.Types exposing (SilenceListMsg(..))
|
||||
|
||||
|
||||
|
@ -100,9 +100,6 @@ matcherButton matcher =
|
|||
editButton : GettableSilence -> Html Msg
|
||||
editButton silence =
|
||||
let
|
||||
matchers =
|
||||
List.map (\s -> ( s.name, s.value )) silence.matchers
|
||||
|
||||
editUrl =
|
||||
String.join "/" [ "#/silences", silence.id, "edit" ]
|
||||
|
||||
|
@ -117,7 +114,7 @@ editButton silence =
|
|||
Expired ->
|
||||
a
|
||||
[ class "btn btn-outline-info border-0"
|
||||
, href (newSilenceFromAlertLabels <| Dict.fromList matchers)
|
||||
, href (newSilenceFromMatchers silence.matchers)
|
||||
]
|
||||
[ text "Recreate"
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue