"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4312,6860],{13531(Le,J,t){t.d(J,{E3:()=>h,vj:()=>y});var e=t(11332);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(25739);const Q="/api/alertmanager/grafana/config/api/v1/templates/test",h=e.H.injectEndpoints({endpoints:j=>({previewTemplate:j.mutation({query:({template:o,alerts:f,name:N})=>({url:Q,data:{template:o,alerts:f,name:N},method:"POST"})}),getDefaultTemplates:j.query({queryFn:async()=>({data:(0,c.D)(n)})})})}),{usePreviewTemplateMutation:y}=h},16714(Le,J,t){t.d(J,{D:()=>y});var e=t(74848),n=t(22803),c=t(68763),Q=t(84035),h=t(49439);function y({label:o,actions:f,id:N,children:u}){const G=(0,h.of)(j);return u?(0,e.jsx)("div",{className:G.container,children:u}):(0,e.jsxs)("div",{className:G.container,children:[(0,e.jsx)(Q.J,{className:G.label,id:N,children:o}),f&&(0,e.jsx)(c.B,{direction:"row",gap:1,children:f})]})}const j=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})})},92112(Le,J,t){t.r(J),t.d(J,{ActiveTab:()=>Ve,ContactPointsPageContents:()=>Je,default:()=>et});var e=t(74848),n=t(96540),c=t(52358),Q=t(64702),h=t(13400),y=t(58807),j=t(45270),o=t(68763),f=t(33100),N=t(74144),u=t(82147),G=t(62461),g=t(40954),H=t(26242),C=t(68049),ne=t(29959),ie=t(94564),ae=t(87284),s=t(84285),Y=t(32658),Ie=t(92537),ye=t(32210),se=t(30465),ue=t(71897),fe=t(82586),i=t(77628),b=t(25877),v=t(75325),X=t(42943),O=t(60699),L=t(22803),le=t(40996),B=t(49439),k=t(49669),W=t(16244),Oe=t(37916);const Te=()=>{const r=(0,B.of)(Be),[A,w]=(0,ye.l)(),Z=A.get("search")??"",[z,T]=(0,n.useState)(Z),[ce,E]=(0,le.A)(()=>{w({search:z},!0)},300,[w,z]),K=(0,n.useCallback)(()=>{E(),T(""),w({search:""},!0)},[E,w]),q=!!Z;return(0,e.jsxs)(o.B,{direction:"row",alignItems:"end",gap:.5,children:[(0,e.jsx)(k.D,{className:r.noBottom,label:(0,c.t)("alerting.contact-points-filter.label-search-by-name-or-type","Search by name or type"),children:(0,e.jsx)(W.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)(Oe.I,{name:"search"}),onChange:de=>{T(de.currentTarget.value)},value:z})}),(0,e.jsx)(j.$n,{variant:"secondary",icon:"times",onClick:()=>K(),disabled:!q,"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"})})]})},Be=()=>({noBottom:(0,L.css)({marginBottom:0})});var Re=t(48148);function ve(r){const{hasConfigurationAPI:A}=(0,ue.VI)();return(0,n.useMemo)(()=>{switch(r){case Y.Bk.ViewExternalConfiguration:return(0,ie.DA)(!0,[Re.w.AlertingNotificationsExternalRead]);case Y.Bk.UpdateExternalConfiguration:return(0,ie.DA)(A,[Re.w.AlertingNotificationsExternalWrite])}},[r,A])}const Ze=({alertManagerName:r})=>{const A=(0,fe.AL)(r);return(0,ie.kR)(ve(Y.Bk.UpdateExternalConfiguration))?(0,e.jsxs)(f.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)(j.z9,{href:(0,ne.nL)("alerting/notifications/global-config",r),variant:"secondary",children:A?(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")})]}):null};var Qe=t(45329),Xe=t(84139),ke=t(2543),qe=t(59970);const We=new Xe.A({intraMode:1,intraIns:1,intraSub:1,intraDel:1,intraTrn:1}),ze=(r,A)=>{const w=(0,n.useMemo)(()=>r.map(E=>E.name),[r]),Z=(0,n.useMemo)(()=>r.map(E=>E.grafana_managed_receiver_configs.map(K=>K[qe.MX].name).join(" ")),[r]);if(!A)return r;const z=We.filter(w,A)??[],T=We.filter(Z,A)??[],ce=[...z,...T];return(0,ke.uniq)(ce).map(E=>r[E])??[]};var Fe=t(95165),Ve=(r=>(r.ContactPoints="contact_points",r.NotificationTemplates="templates",r))(Ve||{});const je=10,we=()=>{const{selectedAlertmanager:r}=(0,ue.VI)(),[A]=(0,ye.l)(),w=!(0,C.dM)(r),Z=(0,ie.kR)((0,ae.Z2)(Y.VY.View)),{isLoading:z,error:T,contactPoints:ce}=(0,Qe.dK)({alertmanager:r,fetchPolicies:w,fetchStatuses:Z}),E=(0,ae.OY)({action:Y.VY.Create}),K=(0,ae.OY)({action:Y.VY.BulkExport}),[q,de]=(0,Fe.G)(),Ee=A.get("search");if(z)return(0,e.jsx)(h._,{text:(0,c.t)("alerting.contact-points-tab.text-loading","Loading...")});const Ue=r===fe.hY;return ce.length===0?(0,e.jsx)(y.p,{variant:E.granted?"call-to-action":"not-found",button:E.granted&&(0,e.jsx)(j.z9,{href:(0,ne.nL)("/alerting/notifications/receivers/new",r),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)(Te,{}),(0,e.jsxs)(o.B,{direction:"row",gap:1,children:[(0,ie.TT)(E)&&(0,e.jsx)(j.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:!E.granted,children:(0,e.jsx)(c.x6,{i18nKey:"alerting.contact-points.create",children:"New contact point"})}),(0,ie.TT)(K)&&(0,e.jsx)(j.$n,{icon:"download-alt",variant:"secondary","aria-label":(0,c.t)("alerting.contact-points-tab.aria-label-export-all","export all"),disabled:!K.granted,onClick:()=>de(Fe.B),children:(0,e.jsx)(c.x6,{i18nKey:"alerting.contact-points-tab.export-all",children:"Export all"})})]})]}),T?(0,e.jsx)(f.F,{title:(0,c.t)("alerting.contact-points-tab.title-failed-to-fetch-contact-points","Failed to fetch contact points"),children:(0,ne.JZ)(T)}):(0,e.jsx)(Ne,{contactPoints:ce,search:Ee,pageSize:je}),!Ue&&(0,e.jsx)(Ze,{alertManagerName:r}),q]})},$e=()=>{const r=(0,s.Fm)({action:Y.mF.Create});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)(N.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."})}),(0,ie.TT)(r)&&(0,e.jsx)(j.z9,{icon:"plus",variant:"primary",href:"/alerting/notifications/templates/new",disabled:!r.granted,children:(0,e.jsx)(c.x6,{i18nKey:"alerting.notification-templates-tab.add-notification-template-group",children:"New notification template"})})]}),(0,e.jsx)(O.v,{})]})},Pe=r=>{const[A,w]=(0,ye.l)();return[(0,n.useMemo)(()=>{const T=A.get("tab");return!T||!Object.values(Ve).map(String).includes(T)?r:T||r},[r,A]),T=>w({tab:T})]},Je=()=>{const{selectedAlertmanager:r}=(0,ue.VI)(),{granted:A}=(0,ae.OY)({action:Y.VY.View}),{granted:w}=(0,ae.OY)({action:Y.VY.Create}),{granted:Z}=(0,s.Fm)({action:Y.mF.View}),z=A||w,T=Q.$.featureToggles.alertingNavigationV2,ce=[z&&"contact_points",Z&&"templates"].filter(Ue=>!!Ue)[0],[E,K]=Pe(ce),{contactPoints:q}=(0,Qe.dK)({alertmanager:r}),de=E==="contact_points",Ee=E==="templates";return T?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(v.e,{currentAlertmanager:r}),(0,e.jsx)(we,{})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(v.e,{currentAlertmanager:r}),(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:de,counter:q.length,onChangeTab:()=>K("contact_points")}),Z&&(0,e.jsx)(G.o,{label:(0,c.t)("alerting.contact-points-page-contents.label-notification-templates","Notification Templates"),active:Ee,onChangeTab:()=>K("templates")})]}),(0,e.jsx)(g.J,{children:(0,e.jsxs)(o.B,{direction:"column",children:[de&&(0,e.jsx)(we,{}),Ee&&(0,e.jsx)($e,{})]})})]})]})},Ne=({contactPoints:r,search:A,pageSize:w=je})=>{const Z=ze(r,A),{page:z,pageItems:T,numberOfPages:ce,onPageChange:E}=(0,Ie.W)(Z,1,w);if(T.length===0){const K=(0,c.t)("alerting.contact-points.no-contact-points-found","No contact points found");return(0,e.jsx)(y.p,{variant:"not-found",message:K})}return(0,e.jsxs)(e.Fragment,{children:[T.map((K,q)=>{const de=`${K.name}-${q}`;return(0,e.jsx)(X.z,{contactPoint:K},de)}),(0,e.jsx)(H.d,{currentPage:z,numberOfPages:ce,onNavigate:E,hideWhenSinglePage:!0})]})};function _e(){const{navId:r,pageNav:A}=(0,se.We)();return(0,e.jsx)(b.y,{navId:r,pageNav:A,accessType:"notification",children:(0,e.jsx)(Je,{})})}const et=(0,i.S)(_e)},36860(Le,J,t){t.d(J,{By:()=>Vt,R_:()=>nt});var e=t(74848),n=t(22803),c=t(61501),Q=t(29407);function h(a,m,d){const l=(0,Q.a)(a,d?.in);return l.setTime(l.getTime()+m*c.Cg),l}const y=null;var j=t(16172);function o(a,m,d){return(0,j.f)(a,-m,d)}const f=null;var N=t(79197);function u(a,m,d){return(0,N.A)(a,m*c.s0,d)}const G=null;function g(a,m,d){return u(a,-m,d)}const H=null;var C=t(96540),ne=t(49785),ie=t(42941),ae=t(70713),s=t(52358),Y=t(64702),Ie=t(98391),ye=t(29318),se=t(49439),ue=t(45839),fe=t(33100),i=t(5195),b=t(21453),v=t(68763),X=t(72480),O=t(16244),L=t(45270),le=t(58908),B=t(77127),k=t(68004),W=t(74144),Oe=t(44155),Te=t(92112),Be=t(31612),Re=t(34273);let ve=null;const Ze=a=>{if(!ve)return null;const m=(0,Be.Xc)(ve,{title:(0,s.t)("alerting.ai.error-boundary.template-button","AI Template Button failed to load"),style:"alertbox",errorLogger:Re.vV});return(0,C.createElement)(m,a)};function Qe(a){ve=a}var Xe=t(94564),ke=t(84285),qe=t(32658),We=t(22599),ze=t(82586),Fe=t(37008),Ve=t(68049),je=t(29959),we=t(93621),$e=t(16714),Pe=t(62943),Je=t(73904),Ne=t(63184),_e=t(97283),et=t(17352),r=t(23172),A=t(91793),w=t(37916),Z=t(34244),z=t(64715),T=t(8208),ce=t(28789),E=t(13400),K=t(75129),q=t(51644),de=t(46264);function Ee({onSelect:a,isOpen:m,onClose:d}){const l=(0,se.of)(Ue),[S,oe]=(0,C.useState)(),[P,_]=(0,C.useState)(null),{useGetAlertmanagerAlertsQuery:he}=K.m,{currentData:re=[],isFetching:U,isError:ge}=he({amSourceName:ze.hY,filter:{inhibited:!0,silenced:!0,active:!0}}),[pe,me]=(0,C.useState)(""),M=(0,C.useMemo)(()=>{const x={};return!U&&re&&re.forEach(p=>{x[p.labels.alertname]||(x[p.labels.alertname]=[]);const I=Object.fromEntries(Object.entries(p.annotations).filter(([ee])=>!ee.startsWith("__"))),V=Object.fromEntries(Object.entries(p.labels).filter(([ee])=>!ee.startsWith("__")));p={...p,annotations:I,labels:V},x[p.labels.alertname].push(p)}),x},[U,re]),$=(0,C.useCallback)(x=>{oe(x),_(null)},[]),D=(0,C.useMemo)(()=>{const x=Object.keys(M).filter(I=>I.toLowerCase().includes(pe.toLowerCase())),p={};return x.forEach(I=>{p[I]=M[I]}),p},[M,pe]);if(ge)return null;const R=Object.keys(D||[]),F=({index:x,style:p})=>{if(!D)return null;const I=R[x],V=I===S;return(0,e.jsxs)("button",{type:"button",title:I,style:p,className:(0,n.cx)(l.rowButton,{[l.rowOdd]:x%2===1,[l.rowSelected]:V}),onClick:()=>$(I),children:[(0,e.jsx)("div",{className:(0,n.cx)(l.ruleTitle,l.rowButtonTitle),children:I}),(0,e.jsxs)("div",{className:l.alertFolder,children:[(0,e.jsx)(w.I,{name:"folder"})," ",D[I][0].labels.grafana_folder??""]})]})},xe=(x,p)=>{const V=x.map(Se=>Se.labels).map(q.Dd),ee=(0,de.Qx)(V),Ae=(0,de.$A)((0,q.Dd)(p.labels),ee);return Ae.length?(0,q.M4)((0,q.zm)(Ae)):(0,q.M4)(p.labels)},De=({index:x,style:p})=>{const I=(0,C.useMemo)(()=>S?M[S]:[],[]),V=I[x],ee=P?.includes(V),Ae=(0,C.useMemo)(()=>xe(I,V),[I,V]),He=()=>{if(ee&&P){_(P.filter(Se=>Se!==V));return}_([...P||[],V])};return(0,e.jsx)("button",{type:"button",style:p,className:(0,n.cx)(l.rowButton,l.instanceButton,{[l.rowOdd]:x%2===1,[l.rowSelected]:ee}),onClick:He,children:(0,e.jsx)("div",{className:l.rowButtonTitle,title:V.labels.alertname,children:(0,e.jsx)(Z.m,{placement:"bottom",content:(0,e.jsx)("pre",{children:JSON.stringify(V,null,2)}),theme:"info",children:(0,e.jsx)("div",{children:Ae.map((Se,Ye)=>(0,e.jsx)(z.v,{name:Se,className:l.tag},Ye))})})})})},at=()=>{const x=P?.map(p=>({status:"firing",annotations:p.annotations,labels:p.labels,startsAt:p.startsAt,endsAt:p.endsAt,generatorURL:p.generatorURL,fingerprint:p.fingerprint}))||[];a(x),Ke()},Ke=()=>{oe(void 0),_(null),me(""),be("")},Me=()=>{Ke(),d()},be=x=>{me(x)};return(0,e.jsx)("div",{children:(0,e.jsxs)(T.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)(ce.Z,{value:pe,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:S&&"Select one or more instances from the list below"||""}),(0,e.jsxs)("div",{className:l.column,children:[U&&(0,e.jsx)(E._,{text:(0,s.t)("alerting.alert-instance-modal-selector.text-loading-rules","Loading rules..."),className:l.loadingPlaceholder}),!U&&(0,e.jsx)(ae.Ay,{children:({height:x,width:p})=>(0,e.jsx)(A.Y1,{itemSize:50,height:x,width:p,itemCount:R.length,children:F})})]}),(0,e.jsxs)("div",{className:l.column,children:[!S&&!U&&(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"})})}),U&&(0,e.jsx)(E._,{text:(0,s.t)("alerting.alert-instance-modal-selector.text-loading-rule","Loading rule..."),className:l.loadingPlaceholder}),S&&M[S].length&&!U&&(0,e.jsx)(ae.Ay,{children:({width:x,height:p})=>(0,e.jsx)(A.Y1,{itemSize:32,height:p,width:x,itemCount:M[S].length||0,children:De})})]})]}),(0,e.jsxs)(T.a.ButtonRow,{children:[(0,e.jsx)(L.$n,{type:"button",variant:"secondary",onClick:Me,children:(0,e.jsx)(s.x6,{i18nKey:"alerting.common.cancel",children:"Cancel"})}),(0,e.jsx)(L.$n,{type:"button",variant:"primary",disabled:!(S&&P),onClick:()=>{S&&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 Ue=a=>{const m=(0,L.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"})}},mt=[{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."}],ut=[{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."}],gt=[{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"}],ft=`{
  "summary": "alert summary",
  "description": "alert description"
}
`;var lt=t(38422);function ht(){const a=(0,se.of)(xt),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:gt});return(0,e.jsx)(v.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:mt,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)(yt,{}),children:(0,e.jsx)("div",{className:a.interactiveType,children:d})}):d})})}const xt=a=>({interactiveType:(0,n.css)({color:a.colors.text.link})});function tt({dataItems:a,caption:m,typeRenderer:d}){const l=(0,se.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:S,type:oe,notes:P},_)=>(0,e.jsxs)("tr",{children:[(0,e.jsx)("td",{children:S}),(0,e.jsx)("td",{children:d?d(oe):oe}),(0,e.jsx)("td",{children:P})]},_))})]})}function yt(){const a=(0,se.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:ft})}),(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:S})=>(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:S})]},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),jt=t(10470),bt=t(23820),At=t(44327),St=t(28341);const Ct={annotations:[{key:"",value:""}],labels:[{key:"",value:""}],status:"firing"},Lt=({isOpen:a,onDismiss:m,onAccept:d})=>{const l=(0,se.of)(Tt),[S,oe]=(0,C.useState)([]),P=(0,ne.mN)({defaultValues:Ct,mode:"onBlur"}),_=P.watch("annotations"),he=P.watch("labels"),[re,U]=(0,C.useState)("firing"),ge=()=>{const $={annotations:_.filter(({key:D,value:R})=>!!D&&!!R).reduce((D,{key:R,value:F})=>({...D,[R]:F}),{}),labels:he.filter(({key:D,value:R})=>!!D&&!!R).reduce((D,{key:R,value:F})=>({...D,[R]:F}),{}),startsAt:"2023-04-01T00:00:00Z",endsAt:re==="firing"?(0,j.f)(new Date,1).toISOString():o(new Date,1).toISOString(),status:re,fingerprint:(0,vt.uniqueId)("fingerprint_")};oe(D=>[...D,$]),P.reset()},pe=()=>{d(S),oe([]),P.reset(),U("firing")},me=()=>{const $=he.some(R=>R.key!==""&&R.value!==""),D=_.some(R=>R.key!==""&&R.value!=="");return $||D},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)(T.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)(ne.Op,{...P,children:(0,e.jsxs)("form",{onSubmit:$=>{$.preventDefault(),$.stopPropagation(),P.reset(),U("firing")},children:[(0,e.jsx)(jt.Z,{noMargin:!0,children:(0,e.jsxs)(v.B,{direction:"column",gap:1,children:[(0,e.jsx)("div",{className:l.section,children:(0,e.jsx)(At.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)(bt.z,{value:re,options:M,onChange:$=>U($)}),(0,e.jsx)(L.$n,{onClick:ge,className:l.onAddButton,icon:"plus-circle",type:"button",variant:"secondary",disabled:!me(),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}),S.length>0&&(0,e.jsxs)(v.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(S,null,2)})]}),(0,e.jsx)("div",{className:l.onSubmitWrapper,children:(0,e.jsx)(T.a.ButtonRow,{children:(0,e.jsx)(L.$n,{onClick:pe,disabled:S.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"})})})})]})})})},Tt=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"})}),Rt="Reset to defaults";function Pt({payload:a,setPayload:m,defaultPayload:d,setPayloadFormatError:l,payloadFormatError:S,className:oe}){const P=(0,se.of)(Et),_=()=>{m(d)},[he,re]=(0,C.useState)(!1),U=()=>{re(!1)},ge=S!==null,pe=()=>{try{const F=JSON.parse(a);JSON.stringify([...F]),l(null)}catch(F){throw l(F instanceof Error?F.message:"Invalid JSON."),F}},me=()=>{try{pe(),re(!0)}catch{}},M=()=>{try{pe(),R(!0)}catch{}},$=F=>{U(),R(!1),m(xe=>{const De=JSON.parse(xe);return JSON.stringify([...De,...F],void 0,2)})},[D,R]=(0,C.useState)(!1);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:(0,n.cx)(P.wrapper,oe),children:[(0,e.jsx)($e.D,{label:(0,s.t)("alerting.payload-editor.label-payload","Payload"),actions:(0,e.jsxs)(v.B,{direction:"row",alignItems:"center",gap:.5,children:[(0,e.jsx)(le.m,{overlay:(0,e.jsxs)(B.W,{children:[(0,e.jsx)(B.W.Item,{label:(0,s.t)("alerting.payload-editor.label-use-existing-alert-instances","Use existing alert instances"),disabled:ge,onClick:M}),(0,e.jsx)(B.W.Item,{label:(0,s.t)("alerting.payload-editor.label-add-custom-alert-instance","Add custom alert instance"),disabled:ge,onClick:me}),(0,e.jsx)(B.W.Divider,{}),(0,e.jsx)(B.W.Item,{label:Rt,onClick:_,destructive:!0})]}),children:(0,e.jsx)(L.$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)(et.G,{content:(0,e.jsx)(Nt,{}),placement:"top",fitContent:!0,children:(0,e.jsx)(L.$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)(ae.Ay,{children:({width:F,height:xe})=>(0,e.jsx)(r.B,{containerStyles:P.editorContainer,width:F,height:xe,language:"json",showLineNumbers:!0,showMiniMap:!1,value:a,readOnly:!1,onBlur:m,monacoOptions:{scrollBeyondLastLine:!1}})})})]}),(0,e.jsx)(Lt,{isOpen:he,onDismiss:U,onAccept:$}),(0,e.jsx)(Ee,{onSelect:$,isOpen:D,onClose:()=>R(!1)})]})}const Nt=()=>(0,e.jsx)(tt,{dataItems:ut}),Et=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}})}),Dt=[{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 It=t(92815),Ot=t(69166),Bt=t(16902);const Ft=Object.freeze({title:"",content:""}),Vt=({originalTemplate:a,prefill:m,alertmanager:d})=>{const l=(0,se.of)(rt),S=(0,Oe._2)(),[oe,{error:P}]=(0,Ne.xW)({alertmanager:d}),[_,{error:he}]=(0,Ne.A1)({alertmanager:d}),{titleIsUnique:re}=(0,Ne.lx)({alertmanager:d,originalTemplate:a}),U=(0,C.useRef)(null),ge=d===ze.hY,pe=(0,Xe.kR)((0,ke.Fm)({action:qe.mF.Test,context:a})),me=ge&&pe,M=he??P,[$,D]=(0,ie.A)(!1),[R,F]=(0,C.useState)(nt),[xe,De]=(0,C.useState)(null),[at,Ke]=(0,C.useState)(!1),{provenance:Me}=(0,Ne.OA)(a),be=(0,Ve.RC)(Me),x=Me===We.X.ConvertedPrometheus,p=a?(0,_e.eI)(a):!1,I=a?{title:a.title,content:a.content}:void 0,V=(0,ue.h)({direction:"column",initialSize:me?.5:1,dragPosition:"middle"}),ee=(0,ue.h)({direction:"row",initialSize:me?.6:1,dragPosition:"middle"}),Ae=(0,ne.mN)({mode:"onSubmit",defaultValues:m??I??Ft}),{handleSubmit:He,register:Se,formState:{errors:Ye,isSubmitting:it},getValues:ct,setValue:st,watch:dt}=Ae,Mt=async te=>{const Ge=Y.$.featureToggles.alertingNavigationV2?(0,je.nL)(we.qI.TEMPLATES,d):(0,je.nL)(we.qI.NOTIFICATIONS,d,{tab:Te.ActiveTab.NotificationTemplates});try{a?await _.execute({template:a,patch:te}):await oe.execute({templateValues:te}),S.success("Template saved",`Template ${te.title} has been saved`),Ie.Ny.push(Ge)}catch(zt){S.error("Error saving template",(0,je.JZ)(zt))}},Gt=te=>{const Ce=ct("content"),Ge=Ce?`${Ce}
${te}`:te;st("content",Ge)},Wt=te=>{st("content",te),Ke(!0)};return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(ne.Op,{...Ae,children:(0,e.jsxs)("form",{onSubmit:He(Mt),ref:U,className:l.form,"aria-label":(0,s.t)("alerting.template-form.aria-label-template-form","Template form"),children:[M&&(0,e.jsx)(fe.F,{severity:"error",title:(0,s.t)("alerting.template-form.title-error-saving-template","Error saving template"),children:M.message||(0,ye.NF)(M)&&M.data?.message||String(M)}),be&&x&&(0,e.jsx)(i.a,{grow:0,children:(0,e.jsx)(Pe.zt,{resource:Pe.hk.Template})}),be&&!x&&(0,e.jsx)(i.a,{grow:0,children:(0,e.jsx)(Pe.Yi,{resource:Pe.hk.Template})}),p&&(0,e.jsx)(i.a,{grow:0,children:(0,e.jsx)(fe.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)(b.n,{disabled:be,className:l.fieldset,children:(0,e.jsxs)(v.B,{direction:"column",gap:1,alignItems:"stretch",minHeight:"100%",children:[(0,e.jsxs)(v.B,{direction:"row",alignItems:"center",children:[(0,e.jsx)(X.I,{label:(0,s.t)("alerting.template-form.label-template-group-name","Template group name"),error:Ye?.title?.message,invalid:!!Ye.title?.message,required:!0,children:(0,e.jsx)(O.p,{...Se("title",{required:{value:!0,message:(0,s.t)("alerting.template-form.message.required","Required.")},validate:{titleIsUnique:re}}),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)(Je.h,{}),(0,e.jsxs)(v.B,{children:[(0,e.jsx)(L.$n,{onClick:()=>U.current?.requestSubmit(),variant:"primary",disabled:it,children:(0,e.jsx)(s.x6,{i18nKey:"common.save",children:"Save"})}),(0,e.jsx)(L.z9,{disabled:it,href:(0,je.nL)("alerting/notifications",d,{tab:Te.ActiveTab.NotificationTemplates}),variant:"secondary",children:(0,e.jsx)(s.x6,{i18nKey:"common.cancel",children:"Cancel"})})]})]}),(0,e.jsxs)("div",{...ee.containerProps,className:l.contentContainer,children:[(0,e.jsx)("div",{...ee.primaryProps,children:(0,e.jsxs)("div",{...V.containerProps,className:l.contentField,children:[(0,e.jsx)("div",{...V.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:[ge&&(0,e.jsx)(le.m,{overlay:(0,e.jsxs)(B.W,{children:[Dt.map((te,Ce)=>(0,e.jsx)(B.W.Item,{label:te.description,onClick:()=>Gt(te.example)},Ce)),(0,e.jsx)(B.W.Divider,{}),(0,e.jsx)(B.W.Item,{label:(0,s.t)("alerting.template-form.label-examples-documentation","Examples documentation"),url:Fe.t9,target:"_blank",icon:"external-link-alt"})]}),children:(0,e.jsx)(L.$n,{variant:"secondary",size:"sm",icon:"angle-down",children:(0,e.jsx)(s.x6,{i18nKey:"alerting.templates.editor.add-example",children:"Add example"})})}),ge&&(0,e.jsx)(Ze,{onTemplateGenerated:Wt,disabled:be}),(0,e.jsx)(L.$n,{icon:"question-circle",size:"sm",fill:"outline",variant:"secondary",onClick:D,children:(0,e.jsx)(s.x6,{i18nKey:"common.help",children:"Help"})})]})})}),(0,e.jsx)(i.a,{flex:1,children:(0,e.jsx)(ae.Ay,{children:({width:te,height:Ce})=>(0,e.jsx)(It.K,{value:ct("content"),onBlur:Ge=>st("content",Ge),containerStyles:l.editorContainer,width:te,height:Ce})})})]})}),me&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{...V.splitterProps}),(0,e.jsx)("div",{...V.secondaryProps,children:(0,e.jsx)("div",{className:(0,n.cx)(l.containerWithBorderAndRadius,l.minEditorSize,l.payloadEditor,l.flexFull),children:(0,e.jsx)(Pt,{payload:R,defaultPayload:nt,setPayload:F,setPayloadFormatError:De,payloadFormatError:xe})})})]})]})}),me&&(0,e.jsxs)("div",{...ee.secondaryProps,children:[(0,e.jsx)("div",{...ee.splitterProps}),(0,e.jsx)(Ot.p,{payload:R,templateName:dt("title"),templateContent:dt("content"),setPayloadFormatError:De,payloadFormatError:xe,className:(0,n.cx)(l.templatePreview,l.minEditorSize),aiGeneratedTemplate:at,setAiGeneratedTemplate:Ke})]})]})]})})]})}),$&&(0,e.jsx)(k._,{title:(0,s.t)("alerting.template-form.title-templating-cheat-sheet","Templating cheat sheet"),onClose:D,size:"lg",children:(0,e.jsx)(Ut,{})})]})};function wt(){const a=(0,se.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)(fe.F,{title:"",severity:"info",children:(0,e.jsxs)(v.B,{direction:"column",gap:2,children:[(0,e.jsxs)(v.B,{direction:"row",children:[(0,e.jsx)("div",{style:{whiteSpace:"pre"},children:m}),(0,e.jsx)("div",{children:(0,e.jsx)(L.z9,{href:Fe.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(Bt.L).map(d=>d.label).join(", ")})]})]})})}function Ut(){return(0,e.jsxs)(v.B,{direction:"column",gap:1,children:[(0,e.jsx)(wt,{}),(0,e.jsx)(ht,{})]})}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})}},Kt=[{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:o(new Date,1).toISOString(),endsAt:h(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:g(new Date,4).toISOString(),endsAt:new Date().toISOString(),fingerprint:"b77d941310f9d381",generatorURL:"http://grafana.com/alerting/grafana/oZSMdGj7z/view"}],nt=JSON.stringify(Kt,null,2)},69166(Le,J,t){t.d(J,{p:()=>Ie});var e=t(74848),n=t(22803),c=t(2543),Q=t(70713),h=t(52358),y=t(49439),j=t(45270),o=t(5195),f=t(23172),N=t(33100),u=t(96540),G=t(31612),g=t(34273);let H=null;const C=i=>{if(!H)return null;const b=(0,G.Xc)(H,{title:(0,h.t)("alerting.ai.error-boundary.feedback-button","AI Feedback Button failed to load"),style:"alertbox",errorLogger:g.vV}),v={shouldShowFeedbackButton:!0,useRouteDetection:!1,...i};return(0,u.createElement)(b,v)};function ne(i){H=i}var ie=t(29959),ae=t(16714),s=t(13531);function Y(i,b,v,X){const[O,{data:L,error:le,isLoading:B}]=(0,s.vj)(),k=(0,u.useCallback)(()=>{try{const W=JSON.parse(v);JSON.stringify([...W]),O({template:i,alerts:W,name:b}),X(null)}catch(W){X(W instanceof Error?W.message:"Invalid JSON.")}},[i,b,v,X,O]);return(0,u.useEffect)(()=>k(),[k]),{data:L,error:le,isLoading:B,onPreview:k}}function Ie({payload:i,templateName:b,templateContent:v,payloadFormatError:X,setPayloadFormatError:O,className:L,aiGeneratedTemplate:le,setAiGeneratedTemplate:B}){const k=(0,y.of)(ue),{data:W,isLoading:Oe,onPreview:Te,error:Be}=Y(v,b,i,O),Re=fe(Be,X,W);return(0,e.jsxs)("div",{className:(0,n.cx)(k.container,L),children:[(0,e.jsx)(ae.D,{label:(0,h.t)("alerting.template-preview.label-preview","Preview"),actions:(0,e.jsx)(j.$n,{disabled:Oe,icon:"sync","aria-label":(0,h.t)("alerting.template-preview.aria-label-refresh-preview","Refresh preview"),onClick:()=>{Te(),B?.(!1)},size:"sm",variant:"secondary",children:(0,e.jsx)(h.x6,{i18nKey:"alerting.template-preview.refresh",children:"Refresh"})})}),(0,e.jsx)("div",{className:k.viewer.feedbackContainer,children:(0,e.jsx)(C,{origin:"template",shouldShowFeedbackButton:!!le})}),(0,e.jsx)(o.a,{flex:1,children:(0,e.jsx)(Q.Ay,{disableWidth:!0,children:({height:ve})=>(0,e.jsx)("div",{className:k.viewerContainer({height:ve}),children:Re})})})]})}function ye({previews:i}){const b=(0,y.of)(ue),v=i.length===1,X=O=>{try{return JSON.parse(O),!0}catch{return!1}};return(0,e.jsx)("ul",{className:b.viewer.container,"data-testid":"template-preview",children:i.map(O=>{const L=X(O.text)?"json":"plaintext";return(0,e.jsxs)("li",{className:b.viewer.box,children:[v?null:(0,e.jsxs)("header",{className:b.viewer.header,children:[O.name,(0,e.jsx)("div",{className:b.viewer.language,children:L})]}),(0,e.jsx)(f.B,{containerStyles:b.editorContainer,language:L,showLineNumbers:!1,showMiniMap:!1,value:O.text,readOnly:!0,monacoOptions:{scrollBeyondLastLine:!1}})]},O.name)})})}function se({errors:i}){return i.map(b=>(0,e.jsx)(N.F,{title:(0,c.compact)([b.name,b.kind]).join(" \u2013 "),children:b.message},(0,c.uniqueId)("errors-list")))}const ue=i=>({container:(0,n.css)({label:"template-preview-container",display:"flex",flexDirection:"column",borderRadius:i.shape.radius.default,border:`1px solid ${i.colors.border.medium}`}),editorContainer:(0,n.css)({width:"100%",height:"100%",border:"none"}),viewerContainer:({height:b})=>(0,n.css)({height:b,overflow:"auto",backgroundColor:i.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 ${i.colors.border.medium}`,height:"inherit"}),header:(0,n.css)({display:"flex",justifyContent:"space-between",fontSize:i.typography.bodySmall.fontSize,padding:i.spacing(1,2),borderBottom:`1px solid ${i.colors.border.medium}`,backgroundColor:i.colors.background.secondary}),language:(0,n.css)({marginLeft:"auto",fontStyle:"italic"}),errorText:(0,n.css)({color:i.colors.error.text}),feedbackContainer:(0,n.css)({display:"flex",justifyContent:"center",alignItems:"center",borderTop:`1px solid ${i.colors.border.medium}`,backgroundColor:i.colors.background.secondary,minHeight:"auto"}),emptyState:(0,n.css)({display:"flex",alignItems:"center",justifyContent:"center",height:"100%",color:i.colors.text.secondary,fontSize:i.typography.bodySmall.fontSize})}});function fe(i,b,v){const X=i?(0,ie.JZ)(i):void 0,O=b||X,L=(0,y.of)(ue),le=v?.results??[],B=v?.errors,k=le.length>0||B||O;return(0,e.jsxs)(e.Fragment,{children:[O&&(0,e.jsx)(N.F,{severity:"error",title:(0,h.t)("alerting.get-preview-results.title-error","Error"),children:O}),B&&(0,e.jsx)(se,{errors:B}),le.length>0&&(0,e.jsx)(ye,{previews:le}),!k&&(0,e.jsx)("div",{className:L.viewer.emptyState,children:(0,e.jsx)(h.x6,{i18nKey:"alerting.template-preview.empty-state",children:"Add template content to see preview"})})]})}},25739(Le,J,t){t.d(J,{D:()=>e,G7:()=>Q,Jl:()=>n,gY:()=>c});function e(h){const y={},j=[],o=/{{-?\s*(define|end|if|range|else|with|template|block)\b(.*?)-?}}/gs;let f,N=0;for(;(f=o.exec(h))!==null;){const[,u,G]=f;if(N=f.index,u==="define"){const g=G?.match(/"([^"]+)"/);g&&j.push({type:"define",startIndex:N,name:g[1]})}else if(u==="end"){let g=j.pop();for(;g&&g.type!=="define"&&g.type!=="if"&&g.type!=="range"&&g.type!=="with"&&g.type!=="block";)g=j.pop();if(g){const H=o.lastIndex;g.type==="define"&&!g.name?.startsWith("__")&&(y[g.name]={name:g.name,content:h.slice(g.startIndex,H)})}}else(u==="if"||u==="range"||u==="else"||u==="with"||u==="block")&&j.push({type:u,startIndex:N})}for(const u of Object.values(y)){const G=/{{ template "([^"]+)" }}/g;let g;for(;(g=G.exec(u.content))!==null;){const H=g[1];y[H]?.content&&(u.content+=`
`+y[H]?.content,delete y[H])}}return Object.values(y)}function n(h){return`{{ template "${h}" . }}`}function c(h){const y=h.match(/\{\{\s*template\s*"(.*)"\s*\.\s*\}\}/);return y?y[1]:""}function Q(h){const y=/\{\{\s*template\s*".*?"\s*\.\s*\}\}/g;if(h.match(y)?.length!==1)return!1;const o=h.split(y);for(const f of o)if(f.trim()!=="")return!1;return!0}},46264(Le,J,t){t.d(J,{$A:()=>c,Qx:()=>Q,f5:()=>h});var e=t(2543),n=t.n(e);function c(o,f){return o.filter(N=>!f.find(u=>JSON.stringify(u)===JSON.stringify(N)))}function Q(o){const f=o.flatMap(u=>u);return(0,e.uniqBy)(f.filter(u=>f.filter(g=>(0,e.isEqual)(u,g)).length===Object.keys(o).length),u=>JSON.stringify(u))}function h(o){if(!o?.data||!o.data.values||!Array.isArray(o.data.values))return[];const[f,N]=o.data.values;return!Array.isArray(f)||!Array.isArray(N)||f.length!==N.length?[]:(y(f)?f:[]).reduce((g,H,C)=>{const ne=N[C];return j(ne)&&g.push({timestamp:H,line:ne}),g},[])}function y(o){return o.every(f=>typeof f=="number")}function j(o){return typeof o=="object"&&o!==null&&"current"in o&&"previous"in o}}}]);

//# sourceMappingURL=6860.bdfe058dd3f903307c80.js.map