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

//# sourceMappingURL=6860.77543ff6ff742f57ff39.js.map