"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4312,9292],{93562(Le,J,t){t.d(J,{E3:()=>v,vj:()=>f});var e=t(5709);const n=`{{ define "__subject" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ if gt (.Alerts.Resolved | len) 0 }}, RESOLVED:{{ .Alerts.Resolved | len }}{{ end }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }} {{ if gt (len .CommonLabels) (len .GroupLabels) }}({{ with .CommonLabels.Remove .GroupLabels.Names }}{{ .Values | join " " }}{{ end }}){{ end }}{{ end }}

{{ define "__text_values_list" }}{{ if len .Values }}{{ $first := true }}{{ range $refID, $value := .Values -}}
{{ if $first }}{{ $first = false }}{{ else }}, {{ end }}{{ $refID }}={{ $value }}{{ end -}}
{{ else }}[no value]{{ end }}{{ end }}

{{ define "__text_alert_list" }}{{ range . }}
Value: {{ template "__text_values_list" . }}
Labels:
{{ range .Labels.SortedPairs }} - {{ .Name }} = {{ .Value }}
{{ end }}Annotations:
{{ range .Annotations.SortedPairs }} - {{ .Name }} = {{ .Value }}
{{ end }}{{ if gt (len .GeneratorURL) 0 }}Source: {{ .GeneratorURL }}
{{ end }}{{ if gt (len .SilenceURL) 0 }}Silence: {{ .SilenceURL }}
{{ end }}{{ if gt (len .DashboardURL) 0 }}Dashboard: {{ .DashboardURL }}
{{ end }}{{ if gt (len .PanelURL) 0 }}Panel: {{ .PanelURL }}
{{ end }}{{ end }}{{ end }}

{{ define "default.title" }}{{ template "__subject" . }}{{ end }}

{{ define "default.message" }}{{ if gt (len .Alerts.Firing) 0 }}**Firing**
{{ template "__text_alert_list" .Alerts.Firing }}{{ if gt (len .Alerts.Resolved) 0 }}

{{ end }}{{ end }}{{ if gt (len .Alerts.Resolved) 0 }}**Resolved**
{{ template "__text_alert_list" .Alerts.Resolved }}{{ end }}{{ end }}

{{ define "__teams_text_alert_list" }}{{ range . }}
Value: {{ template "__text_values_list" . }}
Labels:
{{ range .Labels.SortedPairs }} - {{ .Name }} = {{ .Value }}
{{ end }}
Annotations:
{{ range .Annotations.SortedPairs }} - {{ .Name }} = {{ .Value }}
{{ end }}
{{ if gt (len .GeneratorURL) 0 }}Source: [{{ .GeneratorURL }}]({{ .GeneratorURL }})

{{ end }}{{ if gt (len .SilenceURL) 0 }}Silence: [{{ .SilenceURL }}]({{ .SilenceURL }})

{{ end }}{{ if gt (len .DashboardURL) 0 }}Dashboard: [{{ .DashboardURL }}]({{ .DashboardURL }})

{{ end }}{{ if gt (len .PanelURL) 0 }}Panel: [{{ .PanelURL }}]({{ .PanelURL }})

{{ end }}
{{ end }}{{ end }}

{{ define "teams.default.message" }}{{ if gt (len .Alerts.Firing) 0 }}**Firing**
{{ template "__teams_text_alert_list" .Alerts.Firing }}{{ if gt (len .Alerts.Resolved) 0 }}

{{ end }}{{ end }}{{ if gt (len .Alerts.Resolved) 0 }}**Resolved**
{{ template "__teams_text_alert_list" .Alerts.Resolved }}{{ end }}{{ end }}`;var c=t(87988);const H="/api/alertmanager/grafana/config/api/v1/templates/test",v=e.H.injectEndpoints({endpoints:S=>({previewTemplate:S.mutation({query:({template:o,alerts:h,name:R})=>({url:H,data:{template:o,alerts:h,name:R},method:"POST"})}),getDefaultTemplates:S.query({queryFn:async()=>({data:(0,c.D)(n)})})})}),{usePreviewTemplateMutation:f}=v},9573(Le,J,t){t.d(J,{D:()=>f});var e=t(14553),n=t(22803),c=t(41654),H=t(72636),v=t(63142);function f({label:o,actions:h,id:R,children:u}){const G=(0,v.of)(S);return u?(0,e.jsx)("div",{className:G.container,children:u}):(0,e.jsxs)("div",{className:G.container,children:[(0,e.jsx)(H.J,{className:G.label,id:R,children:o}),h&&(0,e.jsx)(c.B,{direction:"row",gap:1,children:h})]})}const S=o=>({container:(0,n.css)({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center",padding:o.spacing(1,2),backgroundColor:o.colors.background.secondary,border:`1px solid ${o.colors.border.medium}`,borderTopLeftRadius:o.shape.radius.default,borderTopRightRadius:o.shape.radius.default}),label:(0,n.css)({margin:0})})},69960(Le,J,t){t.r(J),t.d(J,{ActiveTab:()=>Ee,ContactPointsPageContents:()=>ye,default:()=>qe});var e=t(14553),n=t(55501),c=t(92745),H=t(43173),v=t(6975),f=t(50201),S=t(45861),o=t(41654),h=t(34999),R=t(66404),u=t(54314),G=t(60208),p=t(13941),Q=t(34213),A=t(15130),re=t(56476),fe=t(77256),ue=t(11257),s=t(16692),Oe=t(74048),he=t(20962),Be=t(57276),k=t(5358),de=t(52161),xe=t(88547),r=t(36826),y=t(35526),j=t(84591),q=t(16704),I=t(22803),C=t(40996),ae=t(63142),O=t(37386),_=t(63527),W=t(30703);const we=()=>{const i=(0,ae.of)(Te),[T,U]=(0,he.l)(),Z=T.get("search")??"",[z,N]=(0,n.useState)(Z),[Y,V]=(0,C.A)(()=>{U({search:z},!0)},300,[U,z]),w=(0,n.useCallback)(()=>{V(),N(""),U({search:""},!0)},[V,U]),me=!!Z;return(0,e.jsxs)(o.B,{direction:"row",alignItems:"end",gap:.5,children:[(0,e.jsx)(O.D,{className:i.noBottom,label:(0,c.t)("alerting.contact-points-filter.label-search-by-name-or-type","Search by name or type"),children:(0,e.jsx)(_.p,{"aria-label":(0,c.t)("alerting.contact-points-filter.aria-label-search-contact-points","search contact points"),placeholder:(0,c.t)("alerting.contact-points-filter.placeholder-search","Search"),width:46,prefix:(0,e.jsx)(W.I,{name:"search"}),onChange:X=>{N(X.currentTarget.value)},value:z})}),(0,e.jsx)(S.$n,{variant:"secondary",icon:"times",onClick:()=>w(),disabled:!me,"aria-label":(0,c.t)("alerting.contact-points-filter.aria-label-clear","clear"),children:(0,e.jsx)(c.x6,{i18nKey:"alerting.contact-points-filter.clear",children:"Clear"})})]})},Te=()=>({noBottom:(0,I.css)({marginBottom:0})});var Pe=t(24898);const Re=({alertManagerName:i})=>{const T=(0,de.AL)(i);return(0,e.jsx)(Pe._,{actions:[s.QI.UpdateExternalConfiguration],children:(0,e.jsxs)(h.F,{severity:"info",title:(0,c.t)("alerting.global-config-alert.title-global-config-for-contact-points","Global config for contact points"),children:[(0,e.jsx)("p",{children:(0,e.jsx)(c.x6,{i18nKey:"alerting.global-config-alert.body",children:"For each external Alertmanager you can define global settings, like server addresses, usernames and password, for all the supported contact points."})}),(0,e.jsx)(S.z9,{href:(0,fe.nL)("alerting/notifications/global-config",i),variant:"secondary",children:T?(0,c.t)("alerting.global-config-alert.view-global-config","View global config"):(0,c.t)("alerting.global-config-alert.edit-global-config","Edit global config")})]})})};var Ne=t(23242),Qe=t(84139),Fe=t(2543),Ze=t(3887);const Ye=new Qe.A({intraMode:1,intraIns:1,intraSub:1,intraDel:1,intraTrn:1}),Xe=(i,T)=>{const U=(0,n.useMemo)(()=>i.map(V=>V.name),[i]),Z=(0,n.useMemo)(()=>i.map(V=>V.grafana_managed_receiver_configs.map(w=>w[Ze.MX].name).join(" ")),[i]);if(!T)return i;const z=Ye.filter(U,T)??[],N=Ye.filter(Z,T)??[],Y=[...z,...N];return(0,Fe.uniq)(Y).map(V=>i[V])??[]};var Ue=t(8307),Ee=(i=>(i.ContactPoints="contact_points",i.NotificationTemplates="templates",i))(Ee||{});const We=10,ve=()=>{const{selectedAlertmanager:i}=(0,k.VI)(),[T]=(0,he.l)(),U=!(0,re.dM)(i),Z=A.TP.hasPermission(ue.w.AlertingNotificationsRead),{isLoading:z,error:N,contactPoints:Y}=(0,Ne.dK)({alertmanager:i,fetchPolicies:U,fetchStatuses:Z}),[V,w]=(0,s.L7)(s.QI.CreateContactPoint),[me,X]=(0,s.L7)(s.QI.ExportContactPoint),[je,Ve]=(0,Ue.G)(),_e=T.get("search");if(z)return(0,e.jsx)(v._,{text:(0,c.t)("alerting.contact-points-tab.text-loading","Loading...")});const et=i===de.hY;return Y.length===0?(0,e.jsx)(f.p,{variant:w?"call-to-action":"not-found",button:w&&(0,e.jsx)(S.z9,{href:(0,fe.nL)("/alerting/notifications/receivers/new",i),icon:"plus",size:"lg",children:(0,e.jsx)(c.x6,{i18nKey:"alerting.contact-points.create",children:"New contact point"})}),message:(0,c.t)("alerting.contact-points.empty-state.title","You don't have any contact points yet")}):(0,e.jsxs)(o.B,{direction:"column",gap:1,children:[(0,e.jsxs)(o.B,{direction:"row",alignItems:"end",justifyContent:"space-between",children:[(0,e.jsx)(we,{}),(0,e.jsxs)(o.B,{direction:"row",gap:1,children:[V&&(0,e.jsx)(S.z9,{icon:"plus","aria-label":(0,c.t)("alerting.contact-points-tab.aria-label-add-contact-point","add contact point"),variant:"primary",href:"/alerting/notifications/receivers/new",disabled:!w,children:(0,e.jsx)(c.x6,{i18nKey:"alerting.contact-points.create",children:"New contact point"})}),me&&(0,e.jsx)(S.$n,{icon:"download-alt",variant:"secondary","aria-label":(0,c.t)("alerting.contact-points-tab.aria-label-export-all","export all"),disabled:!X,onClick:()=>Ve(Ue.B),children:(0,e.jsx)(c.x6,{i18nKey:"alerting.contact-points-tab.export-all",children:"Export all"})})]})]}),N?(0,e.jsx)(h.F,{title:(0,c.t)("alerting.contact-points-tab.title-failed-to-fetch-contact-points","Failed to fetch contact points"),children:(0,fe.JZ)(N)}):(0,e.jsx)(ke,{contactPoints:Y,search:_e,pageSize:We}),!et&&(0,e.jsx)(Re,{alertManagerName:i}),je]})},ze=()=>{const[i,T]=(0,s.L7)(s.QI.CreateNotificationTemplate);return(0,e.jsxs)(o.B,{direction:"column",gap:1,children:[(0,e.jsxs)(o.B,{direction:"row",alignItems:"center",justifyContent:"space-between",children:[(0,e.jsx)(R.E,{variant:"body",color:"secondary",children:(0,e.jsx)(c.x6,{i18nKey:"alerting.notification-templates-tab.create-notification-templates-customize-notifications",children:"Create notification templates to customize your notifications."})}),i&&(0,e.jsx)(S.z9,{icon:"plus",variant:"primary",href:"/alerting/notifications/templates/new",disabled:!T,children:(0,e.jsx)(c.x6,{i18nKey:"alerting.notification-templates-tab.add-notification-template-group",children:"New notification template"})})]}),(0,e.jsx)(q.v,{})]})},$e=i=>{const[T,U]=(0,he.l)();return[(0,n.useMemo)(()=>{const N=T.get("tab");return!N||!Object.values(Ee).map(String).includes(N)?i:N||i},[i,T]),N=>U({tab:N})]},ye=()=>{const{selectedAlertmanager:i}=(0,k.VI)(),[,T]=(0,s.L7)(s.QI.ViewContactPoint),[,U]=(0,s.L7)(s.QI.CreateContactPoint),[,Z]=(0,s.L7)(s.QI.ViewNotificationTemplate),z=T||U,N=H.$.featureToggles.alertingNavigationV2,Y=[z&&"contact_points",Z&&"templates"].filter(Ve=>!!Ve)[0],[V,w]=$e(Y),{contactPoints:me}=(0,Ne.dK)({alertmanager:i}),X=V==="contact_points",je=V==="templates";return N?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(y.e,{currentAlertmanager:i}),(0,e.jsx)(ve,{})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(y.e,{currentAlertmanager:i}),(0,e.jsxs)(o.B,{direction:"column",children:[(0,e.jsxs)(u.U,{children:[z&&(0,e.jsx)(G.o,{label:(0,c.t)("alerting.contact-points-page-contents.label-contact-points","Contact Points"),active:X,counter:me.length,onChangeTab:()=>w("contact_points")}),Z&&(0,e.jsx)(G.o,{label:(0,c.t)("alerting.contact-points-page-contents.label-notification-templates","Notification Templates"),active:je,onChangeTab:()=>w("templates")})]}),(0,e.jsx)(p.J,{children:(0,e.jsxs)(o.B,{direction:"column",children:[X&&(0,e.jsx)(ve,{}),je&&(0,e.jsx)(ze,{})]})})]})]})},ke=({contactPoints:i,search:T,pageSize:U=We})=>{const Z=Xe(i,T),{page:z,pageItems:N,numberOfPages:Y,onPageChange:V}=(0,Oe.W)(Z,1,U);if(N.length===0){const w=(0,c.t)("alerting.contact-points.no-contact-points-found","No contact points found");return(0,e.jsx)(f.p,{variant:"not-found",message:w})}return(0,e.jsxs)(e.Fragment,{children:[N.map((w,me)=>{const X=`${w.name}-${me}`;return(0,e.jsx)(j.z8,{contactPoint:w},X)}),(0,e.jsx)(Q.d,{currentPage:z,numberOfPages:Y,onNavigate:V,hideWhenSinglePage:!0})]})};function De(){const{navId:i,pageNav:T}=(0,Be.We)();return(0,e.jsx)(r.y,{navId:i,pageNav:T,accessType:"notification",children:(0,e.jsx)(ye,{})})}const qe=(0,xe.S)(De)},89292(Le,J,t){t.d(J,{By:()=>wt,R_:()=>nt});var e=t(14553),n=t(22803),c=t(16172);function H(a,m,d){return(0,c.f)(a,-m,d)}const v=null;var f=t(61501),S=t(29407);function o(a,m,d){const l=(0,S.a)(a,d?.in);return l.setTime(l.getTime()+m*f.Cg),l}const h=null;var R=t(79197);function u(a,m,d){return(0,R.A)(a,m*f.s0,d)}const G=null;function p(a,m,d){return u(a,-m,d)}const Q=null;var A=t(55501),re=t(49785),fe=t(42941),ue=t(70713),s=t(92745),Oe=t(43173),he=t(36490),Be=t(68143),k=t(63142),de=t(93008),xe=t(34999),r=t(31286),y=t(16780),j=t(41654),q=t(18027),I=t(63527),C=t(45861),ae=t(88559),O=t(61848),_=t(8207),W=t(66404),we=t(64762),Te=t(15130),Pe=t(69960),Re=t(11257),Ne=t(36303),Qe=t(74268);let Fe=null;const Ze=a=>{if(!Fe)return null;const m=(0,Ne.Xc)(Fe,{title:(0,s.t)("alerting.ai.error-boundary.template-button","AI Template Button failed to load"),style:"alertbox",errorLogger:Qe.vV});return(0,A.createElement)(m,a)};function Ye(a){Fe=a}var Xe=t(25050),Ue=t(52161),Ee=t(74035),We=t(56476),ve=t(77256),ze=t(29442),$e=t(9573),ye=t(1972),ke=t(49779),De=t(40403),qe=t(66056),i=t(59243),T=t(50992),U=t(97222),Z=t(30703),z=t(45967),N=t(94018),Y=t(22787),V=t(12737),w=t(6975),me=t(91984),X=t(39659),je=t(19161);function Ve({onSelect:a,isOpen:m,onClose:d}){const l=(0,k.of)(_e),[b,se]=(0,A.useState)(),[P,ee]=(0,A.useState)(null),{useGetAlertmanagerAlertsQuery:pe}=me.m,{currentData:le=[],isFetching:K,isError:ie}=pe({amSourceName:Ue.hY,filter:{inhibited:!0,silenced:!0,active:!0}}),[ce,oe]=(0,A.useState)(""),M=(0,A.useMemo)(()=>{const x={};return!K&&le&&le.forEach(g=>{x[g.labels.alertname]||(x[g.labels.alertname]=[]);const D=Object.fromEntries(Object.entries(g.annotations).filter(([te])=>!te.startsWith("__"))),F=Object.fromEntries(Object.entries(g.labels).filter(([te])=>!te.startsWith("__")));g={...g,annotations:D,labels:F},x[g.labels.alertname].push(g)}),x},[K,le]),$=(0,A.useCallback)(x=>{se(x),ee(null)},[]),E=(0,A.useMemo)(()=>{const x=Object.keys(M).filter(D=>D.toLowerCase().includes(ce.toLowerCase())),g={};return x.forEach(D=>{g[D]=M[D]}),g},[M,ce]);if(ie)return null;const L=Object.keys(E||[]),B=({index:x,style:g})=>{if(!E)return null;const D=L[x],F=D===b;return(0,e.jsxs)("button",{type:"button",title:D,style:g,className:(0,n.cx)(l.rowButton,{[l.rowOdd]:x%2===1,[l.rowSelected]:F}),onClick:()=>$(D),children:[(0,e.jsx)("div",{className:(0,n.cx)(l.ruleTitle,l.rowButtonTitle),children:D}),(0,e.jsxs)("div",{className:l.alertFolder,children:[(0,e.jsx)(Z.I,{name:"folder"})," ",E[D][0].labels.grafana_folder??""]})]})},ge=(x,g)=>{const F=x.map(Ae=>Ae.labels).map(X.Dd),te=(0,je.Qx)(F),Se=(0,je.$A)((0,X.Dd)(g.labels),te);return Se.length?(0,X.M4)((0,X.zm)(Se)):(0,X.M4)(g.labels)},Ie=({index:x,style:g})=>{const D=(0,A.useMemo)(()=>b?M[b]:[],[]),F=D[x],te=P?.includes(F),Se=(0,A.useMemo)(()=>ge(D,F),[D,F]),Je=()=>{if(te&&P){ee(P.filter(Ae=>Ae!==F));return}ee([...P||[],F])};return(0,e.jsx)("button",{type:"button",style:g,className:(0,n.cx)(l.rowButton,l.instanceButton,{[l.rowOdd]:x%2===1,[l.rowSelected]:te}),onClick:Je,children:(0,e.jsx)("div",{className:l.rowButtonTitle,title:F.labels.alertname,children:(0,e.jsx)(z.m,{placement:"bottom",content:(0,e.jsx)("pre",{children:JSON.stringify(F,null,2)}),theme:"info",children:(0,e.jsx)("div",{children:Se.map((Ae,He)=>(0,e.jsx)(N.v,{name:Ae,className:l.tag},He))})})})})},at=()=>{const x=P?.map(g=>({status:"firing",annotations:g.annotations,labels:g.labels,startsAt:g.startsAt,endsAt:g.endsAt,generatorURL:g.generatorURL,fingerprint:g.fingerprint}))||[];a(x),Ke()},Ke=()=>{se(void 0),ee(null),oe(""),be("")},Me=()=>{Ke(),d()},be=x=>{oe(x)};return(0,e.jsx)("div",{children:(0,e.jsxs)(Y.a,{title:(0,s.t)("alerting.alert-instance-modal-selector.title-select-alert-instances","Select alert instances"),className:l.modal,closeOnEscape:!0,isOpen:m,onDismiss:Me,contentClassName:l.modalContent,children:[(0,e.jsxs)("div",{className:l.container,children:[(0,e.jsx)(V.Z,{value:ce,onChange:be,title:(0,s.t)("alerting.alert-instance-modal-selector.title-search-alert-rule","Search alert rule"),placeholder:(0,s.t)("alerting.alert-instance-modal-selector.placeholder-search-alert-rule","Search alert rule"),autoFocus:!0}),(0,e.jsx)("div",{children:b&&"Select one or more instances from the list below"||""}),(0,e.jsxs)("div",{className:l.column,children:[K&&(0,e.jsx)(w._,{text:(0,s.t)("alerting.alert-instance-modal-selector.text-loading-rules","Loading rules..."),className:l.loadingPlaceholder}),!K&&(0,e.jsx)(ue.Ay,{children:({height:x,width:g})=>(0,e.jsx)(U.Y1,{itemSize:50,height:x,width:g,itemCount:L.length,children:B})})]}),(0,e.jsxs)("div",{className:l.column,children:[!b&&!K&&(0,e.jsx)("div",{className:l.selectedRulePlaceholder,children:(0,e.jsx)("div",{children:(0,e.jsx)(s.x6,{i18nKey:"alerting.alert-instance-modal-selector.select-alert-rule",children:"Select an alert rule to get a list of available firing instances"})})}),K&&(0,e.jsx)(w._,{text:(0,s.t)("alerting.alert-instance-modal-selector.text-loading-rule","Loading rule..."),className:l.loadingPlaceholder}),b&&M[b].length&&!K&&(0,e.jsx)(ue.Ay,{children:({width:x,height:g})=>(0,e.jsx)(U.Y1,{itemSize:32,height:g,width:x,itemCount:M[b].length||0,children:Ie})})]})]}),(0,e.jsxs)(Y.a.ButtonRow,{children:[(0,e.jsx)(C.$n,{type:"button",variant:"secondary",onClick:Me,children:(0,e.jsx)(s.x6,{i18nKey:"alerting.common.cancel",children:"Cancel"})}),(0,e.jsx)(C.$n,{type:"button",variant:"primary",disabled:!(b&&P),onClick:()=>{b&&P&&at()},children:(0,e.jsx)(s.x6,{i18nKey:"alerting.alert-instance-modal-selector.add-alert-data-to-payload",children:"Add alert data to payload"})})]})]})})}const _e=a=>{const m=(0,C.my)(a);return{container:(0,n.css)({display:"grid",gridTemplateColumns:"1fr 1.5fr",gridTemplateRows:"min-content auto",gap:a.spacing(2),flex:1}),tag:(0,n.css)({margin:"5px"}),column:(0,n.css)({flex:"1 1 auto"}),alertLabels:(0,n.css)({overflowX:"auto",height:"32px"}),ruleTitle:(0,n.css)({height:"22px",fontWeight:a.typography.fontWeightBold}),rowButton:(0,n.css)(m,{padding:a.spacing(.5),overflow:"hidden",textOverflow:"ellipsis",textAlign:"left",whiteSpace:"nowrap",cursor:"pointer",border:"2px solid transparent","&:disabled":{cursor:"not-allowed",color:a.colors.text.disabled}}),rowButtonTitle:(0,n.css)({overflowX:"auto"}),rowSelected:(0,n.css)({borderColor:a.colors.primary.border}),rowOdd:(0,n.css)({backgroundColor:a.colors.background.secondary}),instanceButton:(0,n.css)({display:"flex",gap:a.spacing(1),justifyContent:"space-between",alignItems:"center"}),loadingPlaceholder:(0,n.css)({height:"100%",display:"flex",justifyContent:"center",alignItems:"center"}),selectedRulePlaceholder:(0,n.css)({width:"100%",height:"100%",display:"flex",flexDirection:"column",justifyContent:"center",textAlign:"center",fontWeight:a.typography.fontWeightBold}),modal:(0,n.css)({height:"100%"}),modalContent:(0,n.css)({flex:1,display:"flex",flexDirection:"column"}),modalAlert:(0,n.css)({flexGrow:0}),warnIcon:(0,n.css)({fill:a.colors.warning.main}),labels:(0,n.css)({justifyContent:"flex-start"}),alertFolder:(0,n.css)({height:"20px",fontSize:a.typography.bodySmall.fontSize,color:a.colors.text.secondary,display:"flex",flexDirection:"row",justifyContent:"flex-start",columnGap:a.spacing(1),alignItems:"center"})}},et=[{name:"Receiver",type:"string",notes:"Name of the contact point that the notification is being sent to."},{name:"Status",type:"string",notes:"firing if at least one alert is firing, otherwise resolved"},{name:"Alerts",type:"[]Alert",notes:"List of alert objects that are included in this notification."},{name:"Alerts.Firing",type:"[]Alert",notes:"List of firing alerts"},{name:"Alerts.Resolved",type:"[]Alert",notes:"List of resolved alerts"},{name:"GroupLabels",type:"KeyValue",notes:"Labels these alerts were grouped by."},{name:"CommonLabels",type:"KeyValue",notes:"Labels common to all the alerts included in this notification."},{name:"CommonAnnotations",type:"KeyValue",notes:"Annotations common to all the alerts included in this notification."},{name:"ExternalURL",type:"string",notes:"Back link to the Grafana that sent the notification."}],mt=[{name:"labels",type:"Object{}",notes:"Set of labels attached to the alert."},{name:"annotations",type:"Object{}",notes:"Set of annotations attached to the alert."},{name:"startsAt",type:"string (ISO8601)",notes:"Time the alert started firing."},{name:"endsAt",type:"string (ISO8601)",notes:"Time the alert ends firing."}],ut=[{name:"Status",type:"string",notes:"firing or resolved."},{name:"Labels",type:"KeyValue",notes:"Set of labels attached to the alert."},{name:"Annotations",type:"KeyValue",notes:"Set of annotations attached to the alert."},{name:"Values",type:"KeyValue",notes:"The values of all instant queries, reduce and math expressions, and classic conditions for the alert. It does not contain time series data."},{name:"StartsAt",type:"time.Time",notes:"Time the alert started firing."},{name:"EndsAt",type:"time.Time",notes:"Only set if the end time of an alert is known. Otherwise set to a configurable timeout period from the time since the last alert was received."},{name:"GeneratorURL",type:"string",notes:"A back link to Grafana or external Alertmanager."},{name:"SilenceURL",type:"string",notes:"Link to Grafana silence for with labels for this alert pre-filled. Only for Grafana managed alerts."},{name:"DashboardURL",type:"string",notes:"Link to Grafana dashboard, if alert rule belongs to one. Only for Grafana managed alerts."},{name:"PanelURL",type:"string",notes:"Link to Grafana dashboard panel, if alert rule belongs to one. Only for Grafana managed alerts."},{name:"Fingerprint",type:"string",notes:"Fingerprint that can be used to identify the alert."},{name:"ValueString",type:"string",notes:"String that contains the labels and value of each reduced expression in the alert."}],pt=[{name:"SortedPairs",returns:"KeyValue",notes:"Returns sorted list of key & value string pairs"},{name:"Remove",args:"[]string",returns:"KeyValue",notes:"Returns a copy of the Key/Value map without the given keys."},{name:"Names",returns:"[]string",notes:"List of label names"},{name:"Values",returns:"[]string",notes:"List of label values"}],gt=`{
  "summary": "alert summary",
  "description": "alert description"
}
`;var lt=t(38055);function ft(){const a=(0,k.of)(ht),m=(0,e.jsx)(tt,{caption:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(W.E,{variant:"h4",element:"h4",color:"primary",children:(0,e.jsx)(s.x6,{i18nKey:"alerting.template-data-docs.alert-template-data-table.alert-template-data",children:"Alert template data"})}),(0,e.jsx)(W.E,{variant:"bodySmall",children:(0,e.jsx)(s.x6,{i18nKey:"alerting.template-data-docs.alert-template-data-table.only-in-alert",children:"Available only when in the context of an Alert (e.g. inside .Alerts loop)"})})]}),dataItems:ut});return(0,e.jsx)(j.B,{gap:2,children:(0,e.jsx)(tt,{caption:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(W.E,{variant:"h4",element:"h4",color:"primary",children:(0,e.jsx)(s.x6,{i18nKey:"alerting.template-data-docs.notification-template-data",children:"Notification template data"})}),(0,e.jsx)(W.E,{variant:"bodySmall",children:(0,e.jsx)(s.x6,{i18nKey:"alerting.template-data-docs.available-context-notification",children:"Available in the context of a notification."})})]}),dataItems:et,typeRenderer:d=>d==="[]Alert"?(0,e.jsx)(lt.B,{content:m,children:(0,e.jsx)("div",{className:a.interactiveType,children:d})}):d==="KeyValue"?(0,e.jsx)(lt.B,{content:(0,e.jsx)(xt,{}),children:(0,e.jsx)("div",{className:a.interactiveType,children:d})}):d})})}const ht=a=>({interactiveType:(0,n.css)({color:a.colors.text.link})});function tt({dataItems:a,caption:m,typeRenderer:d}){const l=(0,k.of)(ot);return(0,e.jsxs)("table",{className:l.table,children:[m&&(0,e.jsx)("caption",{children:m}),(0,e.jsx)("thead",{children:(0,e.jsxs)("tr",{children:[(0,e.jsx)("th",{children:(0,e.jsx)(s.x6,{i18nKey:"alerting.template-data-table.name",children:"Name"})}),(0,e.jsx)("th",{children:(0,e.jsx)(s.x6,{i18nKey:"alerting.template-data-table.type",children:"Type"})}),(0,e.jsx)("th",{children:(0,e.jsx)(s.x6,{i18nKey:"alerting.template-data-table.notes",children:"Notes"})})]})}),(0,e.jsx)("tbody",{children:a.map(({name:b,type:se,notes:P},ee)=>(0,e.jsxs)("tr",{children:[(0,e.jsx)("td",{children:b}),(0,e.jsx)("td",{children:d?d(se):se}),(0,e.jsx)("td",{children:P})]},ee))})]})}function xt(){const a=(0,k.of)(ot);return(0,e.jsxs)("div",{children:[(0,e.jsx)(s.x6,{i18nKey:"alerting.key-value-template-data-table.description",children:"KeyValue is a set of key/value string pairs that represent labels and annotations."}),(0,e.jsx)("pre",{children:(0,e.jsx)("code",{children:gt})}),(0,e.jsxs)("table",{className:a.table,children:[(0,e.jsx)("caption",{children:(0,e.jsx)(s.x6,{i18nKey:"alerting.key-value-template-data-table.keyvalue-methods",children:"Key-value methods"})}),(0,e.jsx)("thead",{children:(0,e.jsxs)("tr",{children:[(0,e.jsx)("th",{children:(0,e.jsx)(s.x6,{i18nKey:"alerting.key-value-template-data-table.name",children:"Name"})}),(0,e.jsx)("th",{children:(0,e.jsx)(s.x6,{i18nKey:"alerting.key-value-template-data-table.arguments",children:"Arguments"})}),(0,e.jsx)("th",{children:(0,e.jsx)(s.x6,{i18nKey:"alerting.key-value-template-data-table.returns",children:"Returns"})}),(0,e.jsx)("th",{children:(0,e.jsx)(s.x6,{i18nKey:"alerting.key-value-template-data-table.notes",children:"Notes"})})]})}),(0,e.jsx)("tbody",{children:pt.map(({name:m,args:d,returns:l,notes:b})=>(0,e.jsxs)("tr",{children:[(0,e.jsx)("td",{children:m}),(0,e.jsx)("td",{children:d}),(0,e.jsx)("td",{children:l}),(0,e.jsx)("td",{children:b})]},m))})]})]})}const ot=a=>({table:(0,n.css)({borderCollapse:"collapse",width:"100%",caption:{captionSide:"top"},"td, th":{padding:a.spacing(1,1)},thead:{fontWeight:a.typography.fontWeightBold},"tbody tr:nth-child(2n + 1)":{backgroundColor:a.colors.background.secondary},"tbody td:nth-child(1)":{fontWeight:a.typography.fontWeightBold},"tbody td:nth-child(2)":{fontStyle:"italic"}})});var vt=t(2543),yt=t(8073),jt=t(77824),bt=t(81645),St=t(8402);const At={annotations:[{key:"",value:""}],labels:[{key:"",value:""}],status:"firing"},Ct=({isOpen:a,onDismiss:m,onAccept:d})=>{const l=(0,k.of)(Lt),[b,se]=(0,A.useState)([]),P=(0,re.mN)({defaultValues:At,mode:"onBlur"}),ee=P.watch("annotations"),pe=P.watch("labels"),[le,K]=(0,A.useState)("firing"),ie=()=>{const $={annotations:ee.filter(({key:E,value:L})=>!!E&&!!L).reduce((E,{key:L,value:B})=>({...E,[L]:B}),{}),labels:pe.filter(({key:E,value:L})=>!!E&&!!L).reduce((E,{key:L,value:B})=>({...E,[L]:B}),{}),startsAt:"2023-04-01T00:00:00Z",endsAt:le==="firing"?(0,c.f)(new Date,1).toISOString():H(new Date,1).toISOString(),status:le,fingerprint:(0,vt.uniqueId)("fingerprint_")};se(E=>[...E,$]),P.reset()},ce=()=>{d(b),se([]),P.reset(),K("firing")},oe=()=>{const $=pe.some(L=>L.key!==""&&L.value!==""),E=ee.some(L=>L.key!==""&&L.value!=="");return $||E},M=[{label:(0,s.t)("alerting.generate-alert-data-modal.alert-options.label.firing","Firing"),value:"firing"},{label:(0,s.t)("alerting.generate-alert-data-modal.alert-options.label.resolved","Resolved"),value:"resolved"}];return(0,e.jsx)(Y.a,{onDismiss:m,isOpen:a,title:(0,s.t)("alerting.generate-alert-data-modal.title-add-custom-alerts","Add custom alerts"),children:(0,e.jsx)(re.Op,{...P,children:(0,e.jsxs)("form",{onSubmit:$=>{$.preventDefault(),$.stopPropagation(),P.reset(),K("firing")},children:[(0,e.jsx)(yt.Z,{noMargin:!0,children:(0,e.jsxs)(j.B,{direction:"column",gap:1,children:[(0,e.jsx)("div",{className:l.section,children:(0,e.jsx)(bt.A,{})}),(0,e.jsx)("div",{className:l.section,children:(0,e.jsx)(St.Ay,{})}),(0,e.jsxs)("div",{className:l.flexWrapper,children:[(0,e.jsx)(jt.z,{value:le,options:M,onChange:$=>K($)}),(0,e.jsx)(C.$n,{onClick:ie,className:l.onAddButton,icon:"plus-circle",type:"button",variant:"secondary",disabled:!oe(),children:(0,e.jsx)(s.x6,{i18nKey:"alerting.generate-alert-data-modal.add-alert-data",children:"Add alert data"})})]})]})}),(0,e.jsx)("div",{className:l.onSubmitWrapper}),b.length>0&&(0,e.jsxs)(j.B,{direction:"column",gap:1,children:[(0,e.jsx)("h5",{children:(0,e.jsxs)(s.x6,{i18nKey:"alerting.generate-alert-data-modal.review-alert-payload",children:[" ","Review alert data to add to the payload:"]})}),(0,e.jsx)("pre",{className:l.result,"data-testid":"payloadJSON",children:JSON.stringify(b,null,2)})]}),(0,e.jsx)("div",{className:l.onSubmitWrapper,children:(0,e.jsx)(Y.a.ButtonRow,{children:(0,e.jsx)(C.$n,{onClick:ce,disabled:b.length===0,className:l.onSubmitButton,children:(0,e.jsx)(s.x6,{i18nKey:"alerting.generate-alert-data-modal.add-alert-data-to-payload",children:"Add alert data to payload"})})})})]})})})},Lt=a=>({section:(0,n.css)({marginBottom:a.spacing(2)}),onAddButton:(0,n.css)({flex:"none",width:"fit-content",paddingRight:a.spacing(1),marginLeft:"auto"}),flexWrapper:(0,n.css)({display:"flex",flexDirection:"row",justifyContent:"space-between"}),onSubmitWrapper:(0,n.css)({display:"flex",flexDirection:"row",alignItems:"baseline",justifyContent:"flex-end"}),onSubmitButton:(0,n.css)({marginLeft:a.spacing(2)}),result:(0,n.css)({width:"570px",height:"363px"})}),Tt="Reset to defaults";function Pt({payload:a,setPayload:m,defaultPayload:d,setPayloadFormatError:l,payloadFormatError:b,className:se}){const P=(0,k.of)(Nt),ee=()=>{m(d)},[pe,le]=(0,A.useState)(!1),K=()=>{le(!1)},ie=b!==null,ce=()=>{try{const B=JSON.parse(a);JSON.stringify([...B]),l(null)}catch(B){throw l(B instanceof Error?B.message:"Invalid JSON."),B}},oe=()=>{try{ce(),le(!0)}catch{}},M=()=>{try{ce(),L(!0)}catch{}},$=B=>{K(),L(!1),m(ge=>{const Ie=JSON.parse(ge);return JSON.stringify([...Ie,...B],void 0,2)})},[E,L]=(0,A.useState)(!1);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:(0,n.cx)(P.wrapper,se),children:[(0,e.jsx)($e.D,{label:(0,s.t)("alerting.payload-editor.label-payload","Payload"),actions:(0,e.jsxs)(j.B,{direction:"row",alignItems:"center",gap:.5,children:[(0,e.jsx)(ae.m,{overlay:(0,e.jsxs)(O.W,{children:[(0,e.jsx)(O.W.Item,{label:(0,s.t)("alerting.payload-editor.label-use-existing-alert-instances","Use existing alert instances"),disabled:ie,onClick:M}),(0,e.jsx)(O.W.Item,{label:(0,s.t)("alerting.payload-editor.label-add-custom-alert-instance","Add custom alert instance"),disabled:ie,onClick:oe}),(0,e.jsx)(O.W.Divider,{}),(0,e.jsx)(O.W.Item,{label:Tt,onClick:ee,destructive:!0})]}),children:(0,e.jsx)(C.$n,{variant:"secondary",size:"sm",icon:"angle-down",children:(0,e.jsx)(s.x6,{i18nKey:"alerting.payload-editor.edit-payload",children:"Edit payload"})})}),(0,e.jsx)(i.G,{content:(0,e.jsx)(Rt,{}),placement:"top",fitContent:!0,children:(0,e.jsx)(C.$n,{variant:"secondary",fill:"outline",size:"sm",icon:"question-circle",children:(0,e.jsx)(s.x6,{i18nKey:"alerting.payload-editor.reference",children:"Reference"})})})]})}),(0,e.jsx)("div",{className:P.editorWrapper,children:(0,e.jsx)(ue.Ay,{children:({width:B,height:ge})=>(0,e.jsx)(T.B,{containerStyles:P.editorContainer,width:B,height:ge,language:"json",showLineNumbers:!0,showMiniMap:!1,value:a,readOnly:!1,onBlur:m,monacoOptions:{scrollBeyondLastLine:!1}})})})]}),(0,e.jsx)(Ct,{isOpen:pe,onDismiss:K,onAccept:$}),(0,e.jsx)(Ve,{onSelect:$,isOpen:E,onClose:()=>L(!1)})]})}const Rt=()=>(0,e.jsx)(tt,{dataItems:mt}),Nt=a=>({wrapper:(0,n.css)({display:"flex",flexDirection:"column",height:"100%"}),tooltip:(0,n.css)({paddingLeft:a.spacing(1)}),label:(0,n.css)({margin:0}),editorWrapper:(0,n.css)({flex:1}),editorContainer:(0,n.css)({width:"fit-content",border:"none"}),templateDataDocsHeader:(0,n.css)({color:a.colors.text.primary,span:{color:a.colors.text.secondary,fontSize:a.typography.bodySmall.fontSize}})}),Et=[{description:"Default templates for notification titles",example:`{{- /* This is a copy of the "default.title" template. */ -}}
{{- /* Edit the template name and template content as needed. */ -}}
{{ define "default.title.copy" }}
  [{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ if gt (.Alerts.Resolved | len) 0 }}, RESOLVED:{{ .Alerts.Resolved | len }}{{ end }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }} {{ if gt (len .CommonLabels) (len .GroupLabels) }}({{ with .CommonLabels.Remove .GroupLabels.Names }}{{ .Values | join " " }}{{ end }}){{ end }}
{{ end }}`},{description:"Default templates for notification messages",example:`{{- /* This is a copy of the "default.message" template. */ -}}
{{- /* Edit the template name and template content as needed. */ -}}
{{ define "default.message.copy" }}{{ if gt (len .Alerts.Firing) 0 }}**Firing**
{{ template "__text_alert_list.copy" .Alerts.Firing }}{{ if gt (len .Alerts.Resolved) 0 }}

{{ end }}{{ end }}{{ if gt (len .Alerts.Resolved) 0 }}**Resolved**
{{ template "__text_alert_list.copy" .Alerts.Resolved }}{{ end }}{{ end }}

{{ define "__text_alert_list.copy" }}{{ range . }}
Value: {{ template "__text_values_list.copy" . }}
Labels:
{{ range .Labels.SortedPairs }} - {{ .Name }} = {{ .Value }}
{{ end }}Annotations:
{{ range .Annotations.SortedPairs }} - {{ .Name }} = {{ .Value }}
{{ end }}{{ if gt (len .GeneratorURL) 0 }}Source: {{ .GeneratorURL }}
{{ end }}{{ if gt (len .SilenceURL) 0 }}Silence: {{ .SilenceURL }}
{{ end }}{{ if gt (len .DashboardURL) 0 }}Dashboard: {{ .DashboardURL }}
{{ end }}{{ if gt (len .PanelURL) 0 }}Panel: {{ .PanelURL }}
{{ end }}{{ end }}{{ end }}

{{ define "__text_values_list.copy" }}{{ if len .Values }}{{ $first := true }}{{ range $refID, $value := .Values -}}
{{ if $first }}{{ $first = false }}{{ else }}, {{ end }}{{ $refID }}={{ $value }}{{ end -}}
{{ else }}[no value]{{ end }}{{ end }}`},{description:"Print alerts with summary and description",example:`{{- /* Example displaying the summary and description annotations of each alert in the notification. */ -}}
{{- /* Edit the template name and template content as needed. */ -}}
{{ define "custom.alerts" -}}
{{ len .Alerts }} alert(s)
{{ range .Alerts -}}
  {{ template "alert.summary_and_description" . -}}
{{ end -}}
{{ end -}}

{{ define "alert.summary_and_description" }}
  Summary: {{.Annotations.summary}}
  Status: {{ .Status }}
  Description: {{.Annotations.description}}
{{ end -}}`},{description:"Print firing and resolved alerts",example:`{{- /* Example displaying firing and resolved alerts separately in the notification. */ -}}
{{- /* Edit the template name and template content as needed. */ -}}
{{ define "custom.firing_and_resolved_alerts" -}}
{{ len .Alerts.Resolved }} resolved alert(s)
{{ range .Alerts.Resolved -}}
  {{ template "alert.summary_and_description" . -}}
{{ end }}
{{ len .Alerts.Firing }} firing alert(s)
{{ range .Alerts.Firing -}}
  {{ template "alert.summary_and_description" . -}}
{{ end -}}
{{ end -}}

{{ define "alert.summary_and_description" }}
  Summary: {{.Annotations.summary}}
  Status: {{ .Status }}
  Description: {{.Annotations.description}}
{{ end -}}`},{description:"Print common labels and annotations",example:`{{- /* Example displaying labels and annotations that are common to all alerts in the notification.*/ -}}
{{- /* Edit the template name and template content as needed. */ -}}
{{ define "custom.common_labels_and_annotations" -}}
{{ len .Alerts.Resolved }} resolved alert(s)
{{ len .Alerts.Firing }} firing alert(s)

Common labels: {{ len .CommonLabels.SortedPairs }}
{{ range .CommonLabels.SortedPairs -}}
- {{ .Name }} = {{ .Value }}
{{ end }}

Common annotations: {{ len .CommonAnnotations.SortedPairs }}
{{ range .CommonAnnotations.SortedPairs }}
- {{ .Name }} = {{ .Value }}
{{ end }}

{{ end -}}`},{description:"Print individual labels and annotations",example:`{{- /* Example displaying all labels and annotations for each alert in the notification.*/ -}}
{{- /* Edit the template name and template content as needed. */ -}}
{{ define "custom.alert_labels_and_annotations" -}}
{{ len .Alerts.Resolved }} resolved alert(s)
{{ range .Alerts.Resolved -}}
  {{ template "alert.labels_and_annotations" . -}}
{{ end }}
{{ len .Alerts.Firing }} firing alert(s)
{{ range .Alerts.Firing -}}
  {{ template "alert.labels_and_annotations" . -}}
{{ end -}}
{{ end -}}

{{ define "alert.labels_and_annotations" }}
Alert labels: {{ len .Labels.SortedPairs }}
{{ range .Labels.SortedPairs -}}
- {{ .Name }} = {{ .Value }}
{{ end -}}
Alert annotations: {{ len .Annotations.SortedPairs }}
{{ range .Annotations.SortedPairs -}}
- {{ .Name }} = {{ .Value }}
{{ end -}}
{{ end -}}`},{description:"Print URLs for runbook and alert data in Grafana",example:`{{- /* Example displaying additional information, such as runbook link, DashboardURL and SilenceURL, for each alert in the notification.*/ -}}
{{- /* Edit the template name and template content as needed. */ -}}
{{ define "custom.alert_additional_details" -}}
{{ len .Alerts.Resolved }} resolved alert(s)
{{ range .Alerts.Resolved -}}
  {{ template "alert.additional_details" . -}}
{{ end }}
{{ len .Alerts.Firing }} firing alert(s)
{{ range .Alerts.Firing -}}
  {{ template "alert.additional_details" . -}}
{{ end -}}
{{ end -}}

{{ define "alert.additional_details" }}
- Dashboard: {{ .DashboardURL }}
- Panel: {{ .PanelURL }}
- AlertGenerator: {{ .GeneratorURL }}
- Silence: {{ .SilenceURL }}
- RunbookURL: {{ .Annotations.runbook_url}}
{{ end -}}`},{description:"Create JSON payload for webhook contact point",example:`{{- /* Example displaying a custom JSON payload for a webhook contact point.*/ -}}
{{- /* Edit the template name and template content as needed. */ -}}
{{- /* Variables defined in the webhook contact point can be accessed in .Vars but will not be previewable. */ -}}
{{ define "webhook.custom.payload" -}}
  {{ coll.Dict
  "receiver" .Receiver
  "status" .Status
  "alerts" (tmpl.Exec "webhook.custom.simple_alerts" .Alerts | data.JSON)
  "groupLabels" .GroupLabels
  "commonLabels" .CommonLabels
  "commonAnnotations" .CommonAnnotations
  "externalURL" .ExternalURL
  "version" "1"
  "orgId"  (index .Alerts 0).OrgID
  "truncatedAlerts"  .TruncatedAlerts
  "groupKey" .GroupKey
  "state"  (tmpl.Inline "{{ if eq .Status \\"resolved\\" }}ok{{ else }}alerting{{ end }}" . )
  "allVariables"  .Vars
  "title" (tmpl.Exec "default.title" . )
  "message" (tmpl.Exec "default.message" . )
  | data.ToJSONPretty " "}}
{{- end }}

{{- /* Example showcasing embedding json templates in other json templates. */ -}}
{{ define "webhook.custom.simple_alerts" -}}
  {{- $alerts := coll.Slice -}}
  {{- range . -}}
    {{ $alerts = coll.Append (coll.Dict
    "status" .Status
    "labels" .Labels
    "startsAt" .StartsAt
    "endsAt" .EndsAt
    ) $alerts}}
  {{- end -}}
  {{- $alerts | data.ToJSON -}}
{{- end }}`}];var Dt=t(1332),It=t(17374),Ot=t(32443);const Bt=Object.freeze({title:"",content:""}),zt=a=>a.pathname.endsWith("/duplicate"),wt=({originalTemplate:a,prefill:m,alertmanager:d})=>{const l=(0,k.of)(rt),b=(0,we._2)(),[se,{error:P}]=(0,De.xW)({alertmanager:d}),[ee,{error:pe}]=(0,De.A1)({alertmanager:d}),{titleIsUnique:le}=(0,De.lx)({alertmanager:d,originalTemplate:a}),K=(0,A.useRef)(null),ie=d===Ue.hY,ce=Te.TP.hasPermission(Re.w.AlertingNotificationsTemplatesTest)||Te.TP.hasPermission(Re.w.AlertingNotificationsWrite),oe=ie&&ce,M=pe??P,[$,E]=(0,fe.A)(!1),[L,B]=(0,A.useState)(nt),[ge,Ie]=(0,A.useState)(null),[at,Ke]=(0,A.useState)(!1),{provenance:Me}=(0,De.OA)(a),be=(0,We.RC)(Me),x=Me===Xe.X.ConvertedPrometheus,g=a?(0,qe.eI)(a):!1,D=a?{title:a.title,content:a.content}:void 0,F=(0,de.h)({direction:"column",initialSize:oe?.5:1,dragPosition:"middle"}),te=(0,de.h)({direction:"row",initialSize:oe?.6:1,dragPosition:"middle"}),Se=(0,re.mN)({mode:"onSubmit",defaultValues:m??D??Bt}),{handleSubmit:Je,register:Ae,formState:{errors:He,isSubmitting:it},getValues:ct,setValue:st,watch:dt}=Se,Kt=async ne=>{const Ge=Oe.$.featureToggles.alertingNavigationV2?(0,ve.nL)(ze.qI.TEMPLATES,d):(0,ve.nL)(ze.qI.NOTIFICATIONS,d,{tab:Pe.ActiveTab.NotificationTemplates});try{a?await ee.execute({template:a,patch:ne}):await se.execute({templateValues:ne}),b.success("Template saved",`Template ${ne.title} has been saved`),he.Ny.push(Ge)}catch(Wt){b.error("Error saving template",(0,ve.JZ)(Wt))}},Mt=ne=>{const Ce=ct("content"),Ge=Ce?`${Ce}
${ne}`:ne;st("content",Ge)},Gt=ne=>{st("content",ne),Ke(!0)};return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(re.Op,{...Se,children:(0,e.jsxs)("form",{onSubmit:Je(Kt),ref:K,className:l.form,"aria-label":(0,s.t)("alerting.template-form.aria-label-template-form","Template form"),children:[M&&(0,e.jsx)(xe.F,{severity:"error",title:(0,s.t)("alerting.template-form.title-error-saving-template","Error saving template"),children:M.message||(0,Be.NF)(M)&&M.data?.message||String(M)}),be&&x&&(0,e.jsx)(r.a,{grow:0,children:(0,e.jsx)(ye.zt,{resource:ye.hk.Template})}),be&&!x&&(0,e.jsx)(r.a,{grow:0,children:(0,e.jsx)(ye.Yi,{resource:ye.hk.Template})}),g&&(0,e.jsx)(r.a,{grow:0,children:(0,e.jsx)(xe.F,{title:(0,s.t)("alerting.template-form.title-legacy","This template uses a legacy format"),severity:"warning",children:(0,e.jsx)(s.x6,{i18nKey:"alerting.template-form.body-legacy",children:"This template was imported from a Mimir Alertmanager and uses a legacy format."})})}),(0,e.jsx)(y.n,{disabled:be,className:l.fieldset,children:(0,e.jsxs)(j.B,{direction:"column",gap:1,alignItems:"stretch",minHeight:"100%",children:[(0,e.jsxs)(j.B,{direction:"row",alignItems:"center",children:[(0,e.jsx)(q.I,{label:(0,s.t)("alerting.template-form.label-template-group-name","Template group name"),error:He?.title?.message,invalid:!!He.title?.message,required:!0,children:(0,e.jsx)(I.p,{...Ae("title",{required:{value:!0,message:(0,s.t)("alerting.template-form.message.required","Required.")},validate:{titleIsUnique:le}}),placeholder:(0,s.t)("alerting.template-form.new-template-name-placeholder-give-your-template-group-a-name","Give your template group a name"),width:42,autoFocus:!0,id:"new-template-name"})}),(0,e.jsx)(ke.h,{}),(0,e.jsxs)(j.B,{children:[(0,e.jsx)(C.$n,{onClick:()=>K.current?.requestSubmit(),variant:"primary",disabled:it,children:(0,e.jsx)(s.x6,{i18nKey:"common.save",children:"Save"})}),(0,e.jsx)(C.z9,{disabled:it,href:(0,ve.nL)("alerting/notifications",d,{tab:Pe.ActiveTab.NotificationTemplates}),variant:"secondary",children:(0,e.jsx)(s.x6,{i18nKey:"common.cancel",children:"Cancel"})})]})]}),(0,e.jsxs)("div",{...te.containerProps,className:l.contentContainer,children:[(0,e.jsx)("div",{...te.primaryProps,children:(0,e.jsxs)("div",{...F.containerProps,className:l.contentField,children:[(0,e.jsx)("div",{...F.primaryProps,children:(0,e.jsxs)("div",{className:(0,n.cx)(l.flexColumn,l.containerWithBorderAndRadius,l.minEditorSize),children:[(0,e.jsx)("div",{children:(0,e.jsx)($e.D,{label:(0,s.t)("alerting.template-form.label-template-group","Template group"),actions:(0,e.jsxs)(e.Fragment,{children:[ie&&(0,e.jsx)(ae.m,{overlay:(0,e.jsxs)(O.W,{children:[Et.map((ne,Ce)=>(0,e.jsx)(O.W.Item,{label:ne.description,onClick:()=>Mt(ne.example)},Ce)),(0,e.jsx)(O.W.Divider,{}),(0,e.jsx)(O.W.Item,{label:(0,s.t)("alerting.template-form.label-examples-documentation","Examples documentation"),url:Ee.t9,target:"_blank",icon:"external-link-alt"})]}),children:(0,e.jsx)(C.$n,{variant:"secondary",size:"sm",icon:"angle-down",children:(0,e.jsx)(s.x6,{i18nKey:"alerting.templates.editor.add-example",children:"Add example"})})}),ie&&(0,e.jsx)(Ze,{onTemplateGenerated:Gt,disabled:be}),(0,e.jsx)(C.$n,{icon:"question-circle",size:"sm",fill:"outline",variant:"secondary",onClick:E,children:(0,e.jsx)(s.x6,{i18nKey:"common.help",children:"Help"})})]})})}),(0,e.jsx)(r.a,{flex:1,children:(0,e.jsx)(ue.Ay,{children:({width:ne,height:Ce})=>(0,e.jsx)(Dt.K,{value:ct("content"),onBlur:Ge=>st("content",Ge),containerStyles:l.editorContainer,width:ne,height:Ce})})})]})}),oe&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{...F.splitterProps}),(0,e.jsx)("div",{...F.secondaryProps,children:(0,e.jsx)("div",{className:(0,n.cx)(l.containerWithBorderAndRadius,l.minEditorSize,l.payloadEditor,l.flexFull),children:(0,e.jsx)(Pt,{payload:L,defaultPayload:nt,setPayload:B,setPayloadFormatError:Ie,payloadFormatError:ge})})})]})]})}),oe&&(0,e.jsxs)("div",{...te.secondaryProps,children:[(0,e.jsx)("div",{...te.splitterProps}),(0,e.jsx)(It.p,{payload:L,templateName:dt("title"),templateContent:dt("content"),setPayloadFormatError:Ie,payloadFormatError:ge,className:(0,n.cx)(l.templatePreview,l.minEditorSize),aiGeneratedTemplate:at,setAiGeneratedTemplate:Ke})]})]})]})})]})}),$&&(0,e.jsx)(_._,{title:(0,s.t)("alerting.template-form.title-templating-cheat-sheet","Templating cheat sheet"),onClose:E,size:"lg",children:(0,e.jsx)(Ut,{})})]})};function Ft(){const a=(0,k.of)(rt),m=(0,s.t)("alerting.templates.help.intro",`Notification templates use Go templating language to create notification messages.

In Grafana, a template group can define multiple notification templates using {{ define "<NAME>" }}.
These templates can then be used in contact points and within other notification templates by calling {{ template "<NAME>" }}.
For detailed information about notification templates, refer to our documentation.`);return(0,e.jsx)(xe.F,{title:"",severity:"info",children:(0,e.jsxs)(j.B,{direction:"column",gap:2,children:[(0,e.jsxs)(j.B,{direction:"row",children:[(0,e.jsx)("div",{style:{whiteSpace:"pre"},children:m}),(0,e.jsx)("div",{children:(0,e.jsx)(C.z9,{href:Ee.gZ,target:"_blank",icon:"external-link-alt",variant:"secondary",children:(0,e.jsx)(s.x6,{i18nKey:"alerting.templates.editor.goto-docs",children:"Notification templates documentation"})})})]}),(0,e.jsxs)(W.E,{variant:"bodySmall",children:[(0,e.jsx)(s.x6,{i18nKey:"alerting.templates.editor.auto-complete",children:"For auto-completion of common templating code, type the following keywords in the content editor:"}),(0,e.jsx)("div",{className:a.code,children:Object.values(Ot.L).map(d=>d.label).join(", ")})]})]})})}function Ut(){return(0,e.jsxs)(j.B,{direction:"column",gap:1,children:[(0,e.jsx)(Ft,{}),(0,e.jsx)(ft,{})]})}const rt=a=>{const m=a.breakpoints.down("md");return{flexFull:(0,n.css)({flex:1}),minEditorSize:(0,n.css)({minHeight:300,minWidth:300}),payloadEditor:(0,n.css)({minHeight:0}),containerWithBorderAndRadius:(0,n.css)({borderRadius:a.shape.radius.default,border:`1px solid ${a.colors.border.medium}`}),flexColumn:(0,n.css)({display:"flex",flex:1,flexDirection:"column"}),form:(0,n.css)({label:"template-form",height:"100%",display:"flex",flexDirection:"column"}),fieldset:(0,n.css)({label:"template-fieldset",flex:1,display:"flex",flexDirection:"column"}),label:(0,n.css)({margin:0}),contentContainer:(0,n.css)({flex:1,display:"flex",flexDirection:"row"}),contentField:(0,n.css)({display:"flex",flexDirection:"column",flex:1,marginBottom:0}),templatePreview:(0,n.css)({flex:1,display:"flex"}),templatePayload:(0,n.css)({flex:1}),editorContainer:(0,n.css)({width:"fit-content",border:"none"}),payloadCollapseButton:(0,n.css)({backgroundColor:a.colors.info.transparent,margin:0,[m]:{display:"none"}}),code:(0,n.css)({color:a.colors.text.secondary,fontWeight:a.typography.fontWeightBold})}},Vt=[{status:"firing",annotations:{summary:"Instance instance1 has been down for more than 5 minutes",description:"The instance instance1 has been unreachable for more than 5 minutes, indicating a potential service outage."},labels:{alertname:"InstanceDown",instance:"instance1",severity:"critical",service:"service1",environment:"production"},startsAt:H(new Date,1).toISOString(),endsAt:o(new Date,5).toISOString(),fingerprint:"a5331f0d5a9d81d4",generatorURL:"http://grafana.com/alerting/grafana/cdeqmlhvflz40f/view"},{status:"resolved",annotations:{summary:"CPU usage above 90%",description:"The CPU usage on instance1 has exceeded 90% for an extended period, which may indicate performance issues or resource constraints."},labels:{alertname:"CpuUsage",instance:"instance1",severity:"warning",service:"service1",environment:"dev"},startsAt:p(new Date,4).toISOString(),endsAt:new Date().toISOString(),fingerprint:"b77d941310f9d381",generatorURL:"http://grafana.com/alerting/grafana/oZSMdGj7z/view"}],nt=JSON.stringify(Vt,null,2)},17374(Le,J,t){t.d(J,{p:()=>he});var e=t(14553),n=t(22803),c=t(2543),H=t(70713),v=t(92745),f=t(63142),S=t(45861),o=t(31286),h=t(50992),R=t(34999),u=t(55501),G=t(36303),p=t(74268);let Q=null;const A=r=>{if(!Q)return null;const y=(0,G.Xc)(Q,{title:(0,v.t)("alerting.ai.error-boundary.feedback-button","AI Feedback Button failed to load"),style:"alertbox",errorLogger:p.vV}),j={shouldShowFeedbackButton:!0,useRouteDetection:!1,...r};return(0,u.createElement)(y,j)};function re(r){Q=r}var fe=t(77256),ue=t(9573),s=t(93562);function Oe(r,y,j,q){const[I,{data:C,error:ae,isLoading:O}]=(0,s.vj)(),_=(0,u.useCallback)(()=>{try{const W=JSON.parse(j);JSON.stringify([...W]),I({template:r,alerts:W,name:y}),q(null)}catch(W){q(W instanceof Error?W.message:"Invalid JSON.")}},[r,y,j,q,I]);return(0,u.useEffect)(()=>_(),[_]),{data:C,error:ae,isLoading:O,onPreview:_}}function he({payload:r,templateName:y,templateContent:j,payloadFormatError:q,setPayloadFormatError:I,className:C,aiGeneratedTemplate:ae,setAiGeneratedTemplate:O}){const _=(0,f.of)(de),{data:W,isLoading:we,onPreview:Te,error:Pe}=Oe(j,y,r,I),Re=xe(Pe,q,W);return(0,e.jsxs)("div",{className:(0,n.cx)(_.container,C),children:[(0,e.jsx)(ue.D,{label:(0,v.t)("alerting.template-preview.label-preview","Preview"),actions:(0,e.jsx)(S.$n,{disabled:we,icon:"sync","aria-label":(0,v.t)("alerting.template-preview.aria-label-refresh-preview","Refresh preview"),onClick:()=>{Te(),O?.(!1)},size:"sm",variant:"secondary",children:(0,e.jsx)(v.x6,{i18nKey:"alerting.template-preview.refresh",children:"Refresh"})})}),(0,e.jsx)("div",{className:_.viewer.feedbackContainer,children:(0,e.jsx)(A,{origin:"template",shouldShowFeedbackButton:!!ae})}),(0,e.jsx)(o.a,{flex:1,children:(0,e.jsx)(H.Ay,{disableWidth:!0,children:({height:Ne})=>(0,e.jsx)("div",{className:_.viewerContainer({height:Ne}),children:Re})})})]})}function Be({previews:r}){const y=(0,f.of)(de),j=r.length===1,q=I=>{try{return JSON.parse(I),!0}catch{return!1}};return(0,e.jsx)("ul",{className:y.viewer.container,"data-testid":"template-preview",children:r.map(I=>{const C=q(I.text)?"json":"plaintext";return(0,e.jsxs)("li",{className:y.viewer.box,children:[j?null:(0,e.jsxs)("header",{className:y.viewer.header,children:[I.name,(0,e.jsx)("div",{className:y.viewer.language,children:C})]}),(0,e.jsx)(h.B,{containerStyles:y.editorContainer,language:C,showLineNumbers:!1,showMiniMap:!1,value:I.text,readOnly:!0,monacoOptions:{scrollBeyondLastLine:!1}})]},I.name)})})}function k({errors:r}){return r.map(y=>(0,e.jsx)(R.F,{title:(0,c.compact)([y.name,y.kind]).join(" \u2013 "),children:y.message},(0,c.uniqueId)("errors-list")))}const de=r=>({container:(0,n.css)({label:"template-preview-container",display:"flex",flexDirection:"column",borderRadius:r.shape.radius.default,border:`1px solid ${r.colors.border.medium}`}),editorContainer:(0,n.css)({width:"100%",height:"100%",border:"none"}),viewerContainer:({height:y})=>(0,n.css)({height:y,overflow:"auto",backgroundColor:r.colors.background.primary}),viewer:{container:(0,n.css)({display:"flex",flexDirection:"column",height:"inherit"}),box:(0,n.css)({display:"flex",flexDirection:"column",borderBottom:`1px solid ${r.colors.border.medium}`,height:"inherit"}),header:(0,n.css)({display:"flex",justifyContent:"space-between",fontSize:r.typography.bodySmall.fontSize,padding:r.spacing(1,2),borderBottom:`1px solid ${r.colors.border.medium}`,backgroundColor:r.colors.background.secondary}),language:(0,n.css)({marginLeft:"auto",fontStyle:"italic"}),errorText:(0,n.css)({color:r.colors.error.text}),feedbackContainer:(0,n.css)({display:"flex",justifyContent:"center",alignItems:"center",borderTop:`1px solid ${r.colors.border.medium}`,backgroundColor:r.colors.background.secondary,minHeight:"auto"}),emptyState:(0,n.css)({display:"flex",alignItems:"center",justifyContent:"center",height:"100%",color:r.colors.text.secondary,fontSize:r.typography.bodySmall.fontSize})}});function xe(r,y,j){const q=r?(0,fe.JZ)(r):void 0,I=y||q,C=(0,f.of)(de),ae=j?.results??[],O=j?.errors,_=ae.length>0||O||I;return(0,e.jsxs)(e.Fragment,{children:[I&&(0,e.jsx)(R.F,{severity:"error",title:(0,v.t)("alerting.get-preview-results.title-error","Error"),children:I}),O&&(0,e.jsx)(k,{errors:O}),ae.length>0&&(0,e.jsx)(Be,{previews:ae}),!_&&(0,e.jsx)("div",{className:C.viewer.emptyState,children:(0,e.jsx)(v.x6,{i18nKey:"alerting.template-preview.empty-state",children:"Add template content to see preview"})})]})}},87988(Le,J,t){t.d(J,{D:()=>e,G7:()=>H,Jl:()=>n,gY:()=>c});function e(v){const f={},S=[],o=/{{-?\s*(define|end|if|range|else|with|template|block)\b(.*?)-?}}/gs;let h,R=0;for(;(h=o.exec(v))!==null;){const[,u,G]=h;if(R=h.index,u==="define"){const p=G?.match(/"([^"]+)"/);p&&S.push({type:"define",startIndex:R,name:p[1]})}else if(u==="end"){let p=S.pop();for(;p&&p.type!=="define"&&p.type!=="if"&&p.type!=="range"&&p.type!=="with"&&p.type!=="block";)p=S.pop();if(p){const Q=o.lastIndex;p.type==="define"&&!p.name?.startsWith("__")&&(f[p.name]={name:p.name,content:v.slice(p.startIndex,Q)})}}else(u==="if"||u==="range"||u==="else"||u==="with"||u==="block")&&S.push({type:u,startIndex:R})}for(const u of Object.values(f)){const G=/{{ template "([^"]+)" }}/g;let p;for(;(p=G.exec(u.content))!==null;){const Q=p[1];f[Q]?.content&&(u.content+=`
`+f[Q]?.content,delete f[Q])}}return Object.values(f)}function n(v){return`{{ template "${v}" . }}`}function c(v){const f=v.match(/\{\{\s*template\s*"(.*)"\s*\.\s*\}\}/);return f?f[1]:""}function H(v){const f=/\{\{\s*template\s*".*?"\s*\.\s*\}\}/g;if(v.match(f)?.length!==1)return!1;const o=v.split(f);for(const h of o)if(h.trim()!=="")return!1;return!0}},19161(Le,J,t){t.d(J,{$A:()=>c,Qx:()=>H,f5:()=>v});var e=t(2543),n=t.n(e);function c(o,h){return o.filter(R=>!h.find(u=>JSON.stringify(u)===JSON.stringify(R)))}function H(o){const h=o.flatMap(u=>u);return(0,e.uniqBy)(h.filter(u=>h.filter(p=>(0,e.isEqual)(u,p)).length===Object.keys(o).length),u=>JSON.stringify(u))}function v(o){if(!o?.data||!o.data.values||!Array.isArray(o.data.values))return[];const[h,R]=o.data.values;return!Array.isArray(h)||!Array.isArray(R)||h.length!==R.length?[]:(f(h)?h:[]).reduce((p,Q,A)=>{const re=R[A];return S(re)&&p.push({timestamp:Q,line:re}),p},[])}function f(o){return o.every(h=>typeof h=="number")}function S(o){return typeof o=="object"&&o!==null&&"current"in o&&"previous"in o}}}]);

//# sourceMappingURL=9292-react19.394d7ee8699d047812f8.js.map