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

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

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

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

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

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

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

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

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

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

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

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

{{ end }}{{ end }}{{ if gt (len .Alerts.Resolved) 0 }}**Resolved**
{{ template "__teams_text_alert_list" .Alerts.Resolved }}{{ end }}{{ end }}`;var i=t(87988);const q="/api/alertmanager/grafana/config/api/v1/templates/test",x=e.H.injectEndpoints({endpoints:T=>({previewTemplate:T.mutation({query:({template:u,alerts:V,name:z})=>({url:q,data:{template:u,alerts:V,name:z},method:"POST"})}),getDefaultTemplates:T.query({queryFn:async()=>({data:(0,i.D)(n)})})})}),{usePreviewTemplateMutation:g}=x},9573(Ee,k,t){t.d(k,{D:()=>g});var e=t(74848),n=t(22803),i=t(41654),q=t(72636),x=t(63142);function g({label:u,actions:V,id:z,children:A}){const J=(0,x.of)(T);return A?(0,e.jsx)("div",{className:J.container,children:A}):(0,e.jsxs)("div",{className:J.container,children:[(0,e.jsx)(q.J,{className:J.label,id:z,children:u}),V&&(0,e.jsx)(i.B,{direction:"row",gap:1,children:V})]})}const T=u=>({container:(0,n.css)({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center",padding:u.spacing(1,2),backgroundColor:u.colors.background.secondary,border:`1px solid ${u.colors.border.medium}`,borderTopLeftRadius:u.shape.radius.default,borderTopRightRadius:u.shape.radius.default}),label:(0,n.css)({margin:0})})},69960(Ee,k,t){t.r(k),t.d(k,{ActiveTab:()=>Ue,ContactPointsPageContents:()=>Qe,default:()=>qe});var e=t(74848),n=t(96540),i=t(92745),q=t(43173),x=t(6975),g=t(50201),T=t(45861),u=t(41654),V=t(34999),z=t(66404),A=t(54314),J=t(60208),f=t(13941),_=t(34213),P=t(15130),fe=t(56476),he=t(77256),de=t(11257),s=t(16692),De=t(74048),xe=t(20962),Ie=t(57276),H=t(5358),me=t(15633),ve=t(52161),r=t(88547),v=t(36826),h=t(35526),Q=t(24961),D=t(16704),j=t(22803),ee=t(40996),I=t(63142),Z=t(37386),M=t(63527),Be=t(30703);const Se=()=>{const o=(0,I.of)(Ae),[C,K]=(0,xe.l)(),$=C.get("search")??"",[O,N]=(0,n.useState)($),[te,F]=(0,ee.A)(()=>{K({search:O},!0)},300,[K,O]),R=(0,n.useCallback)(()=>{F(),N(""),K({search:""},!0)},[F,K]),oe=!!$;return(0,e.jsxs)(u.B,{direction:"row",alignItems:"end",gap:.5,children:[(0,e.jsx)(Z.D,{className:o.noBottom,label:(0,i.t)("alerting.contact-points-filter.label-search-by-name-or-type","Search by name or type"),children:(0,e.jsx)(M.p,{"aria-label":(0,i.t)("alerting.contact-points-filter.aria-label-search-contact-points","search contact points"),placeholder:(0,i.t)("alerting.contact-points-filter.placeholder-search","Search"),width:46,prefix:(0,e.jsx)(Be.I,{name:"search"}),onChange:re=>{N(re.currentTarget.value)},value:O})}),(0,e.jsx)(T.$n,{variant:"secondary",icon:"times",onClick:()=>R(),disabled:!oe,"aria-label":(0,i.t)("alerting.contact-points-filter.aria-label-clear","clear"),children:(0,e.jsx)(i.x6,{i18nKey:"alerting.contact-points-filter.clear",children:"Clear"})})]})},Ae=()=>({noBottom:(0,j.css)({marginBottom:0})});var Ce=t(24898);const Oe=({alertManagerName:o})=>{const C=(0,ve.AL)(o);return(0,e.jsx)(Ce._,{actions:[s.QI.UpdateExternalConfiguration],children:(0,e.jsxs)(V.F,{severity:"info",title:(0,i.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)(i.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)(T.z9,{href:(0,he.nL)("alerting/notifications/global-config",o),variant:"secondary",children:C?(0,i.t)("alerting.global-config-alert.view-global-config","View global config"):(0,i.t)("alerting.global-config-alert.edit-global-config","Edit global config")})]})})};var ze=t(97507),we=t(84139),Xe=t(2543),lt=t(3887);const $e=new we.default({intraMode:1,intraIns:1,intraSub:1,intraDel:1,intraTrn:1}),Je=(o,C)=>{const K=(0,n.useMemo)(()=>o.map(F=>F.name),[o]),$=(0,n.useMemo)(()=>o.map(F=>F.grafana_managed_receiver_configs.map(R=>R[lt.MX].name).join(" ")),[o]);if(!C)return o;const O=$e.filter(K,C)??[],N=$e.filter($,C)??[],te=[...O,...N];return(0,Xe.uniq)(te).map(F=>o[F])??[]};var Fe=t(8307),Ue=(o=>(o.ContactPoints="contact_points",o.NotificationTemplates="templates",o))(Ue||{});const ye=10,Ve=()=>{const{selectedAlertmanager:o}=(0,H.VI)(),[C]=(0,xe.l)(),K=!(0,fe.dM)(o),$=P.TP.hasPermission(de.w.AlertingNotificationsRead),{isLoading:O,error:N,contactPoints:te}=(0,ze.dK)({alertmanager:o,fetchPolicies:K,fetchStatuses:$}),[F,R]=(0,s.L7)(s.QI.CreateContactPoint),[oe,re]=(0,s.L7)(s.QI.ExportContactPoint),[Pe,Ke]=(0,Fe.G)(),_e=C.get("search");if(O)return(0,e.jsx)(x._,{text:(0,i.t)("alerting.contact-points-tab.text-loading","Loading...")});const et=o===ve.hY;return te.length===0?(0,e.jsx)(g.p,{variant:R?"call-to-action":"not-found",button:R&&(0,e.jsx)(T.z9,{href:(0,he.nL)("/alerting/notifications/receivers/new",o),icon:"plus",size:"lg",children:(0,e.jsx)(i.x6,{i18nKey:"alerting.contact-points.create",children:"Create contact point"})}),message:(0,i.t)("alerting.contact-points.empty-state.title","You don't have any contact points yet")}):(0,e.jsxs)(u.B,{direction:"column",gap:3,children:[(0,e.jsxs)(u.B,{direction:"row",alignItems:"end",justifyContent:"space-between",children:[(0,e.jsx)(Se,{}),(0,e.jsxs)(u.B,{direction:"row",gap:1,children:[F&&(0,e.jsx)(T.z9,{icon:"plus","aria-label":(0,i.t)("alerting.contact-points-tab.aria-label-add-contact-point","add contact point"),variant:"primary",href:"/alerting/notifications/receivers/new",disabled:!R,children:(0,e.jsx)(i.x6,{i18nKey:"alerting.contact-points.create",children:"Create contact point"})}),oe&&(0,e.jsx)(T.$n,{icon:"download-alt",variant:"secondary","aria-label":(0,i.t)("alerting.contact-points-tab.aria-label-export-all","export all"),disabled:!re,onClick:()=>Ke(Fe.B),children:(0,e.jsx)(i.x6,{i18nKey:"alerting.contact-points-tab.export-all",children:"Export all"})})]})]}),N?(0,e.jsx)(V.F,{title:(0,i.t)("alerting.contact-points-tab.title-failed-to-fetch-contact-points","Failed to fetch contact points"),children:(0,he.JZ)(N)}):(0,e.jsx)(Te,{contactPoints:te,search:_e,pageSize:ye}),!et&&!(0,me.b)(o)&&(0,e.jsx)(Oe,{alertManagerName:o}),Pe]})},He=()=>{const[o,C]=(0,s.L7)(s.QI.CreateNotificationTemplate);return(0,e.jsxs)(u.B,{direction:"column",gap:3,children:[(0,e.jsxs)(u.B,{direction:"row",alignItems:"center",justifyContent:"space-between",children:[(0,e.jsx)(z.E,{variant:"body",color:"secondary",children:(0,e.jsx)(i.x6,{i18nKey:"alerting.notification-templates-tab.create-notification-templates-customize-notifications",children:"Create notification templates to customize your notifications."})}),o&&(0,e.jsx)(T.z9,{icon:"plus",variant:"primary",href:"/alerting/notifications/templates/new",disabled:!C,children:(0,e.jsx)(i.x6,{i18nKey:"alerting.notification-templates-tab.add-notification-template-group",children:"Add notification template group"})})]}),(0,e.jsx)(D.v,{})]})},Le=o=>{const[C,K]=(0,xe.l)();return[(0,n.useMemo)(()=>{const N=C.get("tab");return!N||!Object.values(Ue).map(String).includes(N)?o:N||o},[o,C]),N=>K({tab:N})]},Qe=()=>{const{selectedAlertmanager:o}=(0,H.VI)(),[,C]=(0,s.L7)(s.QI.ViewContactPoint),[,K]=(0,s.L7)(s.QI.CreateContactPoint),[,$]=(0,s.L7)(s.QI.ViewNotificationTemplate),O=C||K,N=q.$.featureToggles.alertingNavigationV2,te=[O&&"contact_points",$&&"templates"].filter(Ke=>!!Ke)[0],[F,R]=Le(te),{contactPoints:oe}=(0,ze.dK)({alertmanager:o}),re=F==="contact_points",Pe=F==="templates";return N?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(h.e,{currentAlertmanager:o}),(0,e.jsx)(Ve,{})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(h.e,{currentAlertmanager:o}),(0,e.jsxs)(u.B,{direction:"column",children:[(0,e.jsxs)(A.U,{children:[O&&(0,e.jsx)(J.o,{label:(0,i.t)("alerting.contact-points-page-contents.label-contact-points","Contact Points"),active:re,counter:oe.length,onChangeTab:()=>R("contact_points")}),$&&(0,e.jsx)(J.o,{label:(0,i.t)("alerting.contact-points-page-contents.label-notification-templates","Notification Templates"),active:Pe,onChangeTab:()=>R("templates")})]}),(0,e.jsx)(f.J,{children:(0,e.jsxs)(u.B,{direction:"column",children:[re&&(0,e.jsx)(Ve,{}),Pe&&(0,e.jsx)(He,{})]})})]})]})},Te=({contactPoints:o,search:C,pageSize:K=ye})=>{const $=Je(o,C),{page:O,pageItems:N,numberOfPages:te,onPageChange:F}=(0,De.W)($,1,K);if(N.length===0){const R=(0,i.t)("alerting.contact-points.no-contact-points-found","No contact points found");return(0,e.jsx)(g.p,{variant:"not-found",message:R})}return(0,e.jsxs)(e.Fragment,{children:[N.map((R,oe)=>{const re=`${R.name}-${oe}`;return(0,e.jsx)(Q.z8,{contactPoint:R},re)}),(0,e.jsx)(_.d,{currentPage:O,numberOfPages:te,onNavigate:F,hideWhenSinglePage:!0})]})};function ke(){const{navId:o,pageNav:C}=(0,Ie.We)();return(0,e.jsx)(v.y,{navId:o,pageNav:C,accessType:"notification",children:(0,e.jsx)(Qe,{})})}const qe=(0,r.S)(ke)},89292(Ee,k,t){t.d(k,{By:()=>Bt,R_:()=>nt});var e=t(74848),n=t(22803),i=t(16172);function q(a,d,c){return(0,i.f)(a,-d,c)}const x=null;var g=t(61501),T=t(29407);function u(a,d,c){const l=(0,T.a)(a,c?.in);return l.setTime(l.getTime()+d*g.Cg),l}const V=null;var z=t(79197);function A(a,d,c){return(0,z.A)(a,d*g.s0,c)}const J=null;function f(a,d,c){return A(a,-d,c)}const _=null;var P=t(96540),fe=t(49785),he=t(42941),de=t(70713),s=t(92745),De=t(43173),xe=t(36490),Ie=t(68143),H=t(63142),me=t(93008),ve=t(34999),r=t(31286),v=t(16780),h=t(41654),Q=t(18027),D=t(63527),j=t(45861),ee=t(88559),I=t(87063),Z=t(8207),M=t(66404),Be=t(64762),Se=t(15130),Ae=t(69960),Ce=t(11257),Oe=t(58684),ze=t(74268);let we=null;const Xe=a=>{if(!we)return null;const d=(0,Oe.Xc)(we,{title:(0,s.t)("alerting.ai.error-boundary.template-button","AI Template Button failed to load"),style:"alertbox",errorLogger:ze.vV});return(0,P.createElement)(d,a)};function lt(a){we=a}var $e=t(25050),Je=t(52161),Fe=t(74035),Ue=t(56476),ye=t(77256),Ve=t(29442),He=t(9573),Le=t(1972),Qe=t(49779),Te=t(40403),ke=t(59243),qe=t(50992),o=t(97222),C=t(30703),K=t(45967),$=t(94018),O=t(22787),N=t(12737),te=t(6975),F=t(91984),R=t(39659),oe=t(19161);function re({onSelect:a,isOpen:d,onClose:c}){const l=(0,H.of)(Pe),[y,ne]=(0,P.useState)(),[L,Y]=(0,P.useState)(null),{useGetAlertmanagerAlertsQuery:ue}=F.m,{currentData:ae=[],isFetching:U,isError:ie}=ue({amSourceName:Je.hY,filter:{inhibited:!0,silenced:!0,active:!0}}),[ce,se]=(0,P.useState)(""),G=(0,P.useMemo)(()=>{const p={};return!U&&ae&&ae.forEach(m=>{p[m.labels.alertname]||(p[m.labels.alertname]=[]);const S=Object.fromEntries(Object.entries(m.annotations).filter(([le])=>!le.startsWith("__"))),w=Object.fromEntries(Object.entries(m.labels).filter(([le])=>!le.startsWith("__")));m={...m,annotations:S,labels:w},p[m.labels.alertname].push(m)}),p},[U,ae]),W=(0,P.useCallback)(p=>{ne(p),Y(null)},[]),E=(0,P.useMemo)(()=>{const p=Object.keys(G).filter(S=>S.toLowerCase().includes(ce.toLowerCase())),m={};return p.forEach(S=>{m[S]=G[S]}),m},[G,ce]);if(ie)return null;const b=Object.keys(E||[]),B=({index:p,style:m})=>{if(!E)return null;const S=b[p],w=S===y;return(0,e.jsxs)("button",{type:"button",title:S,style:m,className:(0,n.cx)(l.rowButton,{[l.rowOdd]:p%2===1,[l.rowSelected]:w}),onClick:()=>W(S),children:[(0,e.jsx)("div",{className:(0,n.cx)(l.ruleTitle,l.rowButtonTitle),children:S}),(0,e.jsxs)("div",{className:l.alertFolder,children:[(0,e.jsx)(C.I,{name:"folder"})," ",E[S][0].labels.grafana_folder??""]})]})},pe=(p,m)=>{const w=p.map(ge=>ge.labels).map(R.Dd),le=(0,oe.Qx)(w),Ne=(0,oe.$A)((0,R.Dd)(m.labels),le);return Ne.length?(0,R.M4)((0,R.zm)(Ne)):(0,R.M4)(m.labels)},Re=({index:p,style:m})=>{const S=(0,P.useMemo)(()=>y?G[y]:[],[]),w=S[p],le=L?.includes(w),Ne=(0,P.useMemo)(()=>pe(S,w),[S,w]),Ze=()=>{if(le&&L){Y(L.filter(ge=>ge!==w));return}Y([...L||[],w])};return(0,e.jsx)("button",{type:"button",style:m,className:(0,n.cx)(l.rowButton,l.instanceButton,{[l.rowOdd]:p%2===1,[l.rowSelected]:le}),onClick:Ze,children:(0,e.jsx)("div",{className:l.rowButtonTitle,title:w.labels.alertname,children:(0,e.jsx)(K.m,{placement:"bottom",content:(0,e.jsx)("pre",{children:JSON.stringify(w,null,2)}),theme:"info",children:(0,e.jsx)("div",{children:Ne.map((ge,Ye)=>(0,e.jsx)($.v,{name:ge,className:l.tag},Ye))})})})})},at=()=>{const p=L?.map(m=>({status:"firing",annotations:m.annotations,labels:m.labels,startsAt:m.startsAt,endsAt:m.endsAt,generatorURL:m.generatorURL,fingerprint:m.fingerprint}))||[];a(p),Ge()},Ge=()=>{ne(void 0),Y(null),se(""),je("")},Me=()=>{Ge(),c()},je=p=>{se(p)};return(0,e.jsx)("div",{children:(0,e.jsxs)(O.a,{title:(0,s.t)("alerting.alert-instance-modal-selector.title-select-alert-instances","Select alert instances"),className:l.modal,closeOnEscape:!0,isOpen:d,onDismiss:Me,contentClassName:l.modalContent,children:[(0,e.jsxs)("div",{className:l.container,children:[(0,e.jsx)(N.Z,{value:ce,onChange:je,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:y&&"Select one or more instances from the list below"||""}),(0,e.jsxs)("div",{className:l.column,children:[U&&(0,e.jsx)(te._,{text:(0,s.t)("alerting.alert-instance-modal-selector.text-loading-rules","Loading rules..."),className:l.loadingPlaceholder}),!U&&(0,e.jsx)(de.Ay,{children:({height:p,width:m})=>(0,e.jsx)(o.Y1,{itemSize:50,height:p,width:m,itemCount:b.length,children:B})})]}),(0,e.jsxs)("div",{className:l.column,children:[!y&&!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)(te._,{text:(0,s.t)("alerting.alert-instance-modal-selector.text-loading-rule","Loading rule..."),className:l.loadingPlaceholder}),y&&G[y].length&&!U&&(0,e.jsx)(de.Ay,{children:({width:p,height:m})=>(0,e.jsx)(o.Y1,{itemSize:32,height:m,width:p,itemCount:G[y].length||0,children:Re})})]})]}),(0,e.jsxs)(O.a.ButtonRow,{children:[(0,e.jsx)(j.$n,{type:"button",variant:"secondary",onClick:Me,children:(0,e.jsx)(s.x6,{i18nKey:"alerting.common.cancel",children:"Cancel"})}),(0,e.jsx)(j.$n,{type:"button",variant:"primary",disabled:!(y&&L),onClick:()=>{y&&L&&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 Pe=a=>{const d=(0,j.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)(d,{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"})}},Ke=[{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."}],_e=[{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."}],et=[{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."}],mt=[{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"}],ut=`{
  "summary": "alert summary",
  "description": "alert description"
}
`;var ot=t(38055);function pt(){const a=(0,H.of)(gt),d=(0,e.jsx)(tt,{caption:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(M.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)(M.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:et});return(0,e.jsx)(h.B,{gap:2,children:(0,e.jsx)(tt,{caption:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(M.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)(M.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:Ke,typeRenderer:c=>c==="[]Alert"?(0,e.jsx)(ot.B,{content:d,children:(0,e.jsx)("div",{className:a.interactiveType,children:c})}):c==="KeyValue"?(0,e.jsx)(ot.B,{content:(0,e.jsx)(ft,{}),children:(0,e.jsx)("div",{className:a.interactiveType,children:c})}):c})})}const gt=a=>({interactiveType:(0,n.css)({color:a.colors.text.link})});function tt({dataItems:a,caption:d,typeRenderer:c}){const l=(0,H.of)(rt);return(0,e.jsxs)("table",{className:l.table,children:[d&&(0,e.jsx)("caption",{children:d}),(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:y,type:ne,notes:L},Y)=>(0,e.jsxs)("tr",{children:[(0,e.jsx)("td",{children:y}),(0,e.jsx)("td",{children:c?c(ne):ne}),(0,e.jsx)("td",{children:L})]},Y))})]})}function ft(){const a=(0,H.of)(rt);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:ut})}),(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:mt.map(({name:d,args:c,returns:l,notes:y})=>(0,e.jsxs)("tr",{children:[(0,e.jsx)("td",{children:d}),(0,e.jsx)("td",{children:c}),(0,e.jsx)("td",{children:l}),(0,e.jsx)("td",{children:y})]},d))})]})]})}const rt=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 ht=t(2543),xt=t(8073),vt=t(77824),yt=t(81645),jt=t(8402);const bt={annotations:[{key:"",value:""}],labels:[{key:"",value:""}],status:"firing"},St=({isOpen:a,onDismiss:d,onAccept:c})=>{const l=(0,H.of)(At),[y,ne]=(0,P.useState)([]),L=(0,fe.mN)({defaultValues:bt,mode:"onBlur"}),Y=L.watch("annotations"),ue=L.watch("labels"),[ae,U]=(0,P.useState)("firing"),ie=()=>{const W={annotations:Y.filter(({key:E,value:b})=>!!E&&!!b).reduce((E,{key:b,value:B})=>({...E,[b]:B}),{}),labels:ue.filter(({key:E,value:b})=>!!E&&!!b).reduce((E,{key:b,value:B})=>({...E,[b]:B}),{}),startsAt:"2023-04-01T00:00:00Z",endsAt:ae==="firing"?(0,i.f)(new Date,1).toISOString():q(new Date,1).toISOString(),status:ae,fingerprint:(0,ht.uniqueId)("fingerprint_")};ne(E=>[...E,W]),L.reset()},ce=()=>{c(y),ne([]),L.reset(),U("firing")},se=()=>{const W=ue.some(b=>b.key!==""&&b.value!==""),E=Y.some(b=>b.key!==""&&b.value!=="");return W||E},G=[{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)(O.a,{onDismiss:d,isOpen:a,title:(0,s.t)("alerting.generate-alert-data-modal.title-add-custom-alerts","Add custom alerts"),children:(0,e.jsx)(fe.Op,{...L,children:(0,e.jsxs)("form",{onSubmit:W=>{W.preventDefault(),W.stopPropagation(),L.reset(),U("firing")},children:[(0,e.jsx)(xt.Z,{noMargin:!0,children:(0,e.jsxs)(h.B,{direction:"column",gap:1,children:[(0,e.jsx)("div",{className:l.section,children:(0,e.jsx)(yt.A,{})}),(0,e.jsx)("div",{className:l.section,children:(0,e.jsx)(jt.Ay,{})}),(0,e.jsxs)("div",{className:l.flexWrapper,children:[(0,e.jsx)(vt.z,{value:ae,options:G,onChange:W=>U(W)}),(0,e.jsx)(j.$n,{onClick:ie,className:l.onAddButton,icon:"plus-circle",type:"button",variant:"secondary",disabled:!se(),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}),y.length>0&&(0,e.jsxs)(h.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(y,null,2)})]}),(0,e.jsx)("div",{className:l.onSubmitWrapper,children:(0,e.jsx)(O.a.ButtonRow,{children:(0,e.jsx)(j.$n,{onClick:ce,disabled:y.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"})})})})]})})})},At=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"})}),Ct="Reset to defaults";function Lt({payload:a,setPayload:d,defaultPayload:c,setPayloadFormatError:l,payloadFormatError:y,className:ne}){const L=(0,H.of)(Pt),Y=()=>{d(c)},[ue,ae]=(0,P.useState)(!1),U=()=>{ae(!1)},ie=y!==null,ce=()=>{try{const B=JSON.parse(a);JSON.stringify([...B]),l(null)}catch(B){throw l(B instanceof Error?B.message:"Invalid JSON."),B}},se=()=>{try{ce(),ae(!0)}catch{}},G=()=>{try{ce(),b(!0)}catch{}},W=B=>{U(),b(!1),d(pe=>{const Re=JSON.parse(pe);return JSON.stringify([...Re,...B],void 0,2)})},[E,b]=(0,P.useState)(!1);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:(0,n.cx)(L.wrapper,ne),children:[(0,e.jsx)(He.D,{label:(0,s.t)("alerting.payload-editor.label-payload","Payload"),actions:(0,e.jsxs)(h.B,{direction:"row",alignItems:"center",gap:.5,children:[(0,e.jsx)(ee.m,{overlay:(0,e.jsxs)(I.W,{children:[(0,e.jsx)(I.W.Item,{label:(0,s.t)("alerting.payload-editor.label-use-existing-alert-instances","Use existing alert instances"),disabled:ie,onClick:G}),(0,e.jsx)(I.W.Item,{label:(0,s.t)("alerting.payload-editor.label-add-custom-alert-instance","Add custom alert instance"),disabled:ie,onClick:se}),(0,e.jsx)(I.W.Divider,{}),(0,e.jsx)(I.W.Item,{label:Ct,onClick:Y,destructive:!0})]}),children:(0,e.jsx)(j.$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)(ke.G,{content:(0,e.jsx)(Tt,{}),placement:"top",fitContent:!0,children:(0,e.jsx)(j.$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:L.editorWrapper,children:(0,e.jsx)(de.Ay,{children:({width:B,height:pe})=>(0,e.jsx)(qe.B,{containerStyles:L.editorContainer,width:B,height:pe,language:"json",showLineNumbers:!0,showMiniMap:!1,value:a,readOnly:!1,onBlur:d,monacoOptions:{scrollBeyondLastLine:!1}})})})]}),(0,e.jsx)(St,{isOpen:ue,onDismiss:U,onAccept:W}),(0,e.jsx)(re,{onSelect:W,isOpen:E,onClose:()=>b(!1)})]})}const Tt=()=>(0,e.jsx)(tt,{dataItems:_e}),Pt=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}})}),Rt=[{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 Nt=t(1332),Et=t(17374),Dt=t(32443);const It=Object.freeze({title:"",content:""}),Mt=a=>a.pathname.endsWith("/duplicate"),Bt=({originalTemplate:a,prefill:d,alertmanager:c})=>{const l=(0,H.of)(it),y=(0,Be._2)(),[ne,{error:L}]=(0,Te.xW)({alertmanager:c}),[Y,{error:ue}]=(0,Te.A1)({alertmanager:c}),{titleIsUnique:ae}=(0,Te.lx)({alertmanager:c,originalTemplate:a}),U=(0,P.useRef)(null),ie=c===Je.hY,ce=Se.TP.hasPermission(Ce.w.AlertingNotificationsTemplatesTest)||Se.TP.hasPermission(Ce.w.AlertingNotificationsWrite),se=ie&&ce,G=ue??L,[W,E]=(0,he.A)(!1),[b,B]=(0,P.useState)(nt),[pe,Re]=(0,P.useState)(null),[at,Ge]=(0,P.useState)(!1),{provenance:Me}=(0,Te.OA)(a),je=(0,Ue.RC)(Me),p=Me===$e.X.ConvertedPrometheus,m=a?{title:a.title,content:a.content}:void 0,S=(0,me.h)({direction:"column",initialSize:se?.5:1,dragPosition:"middle"}),w=(0,me.h)({direction:"row",initialSize:se?.6:1,dragPosition:"middle"}),le=(0,fe.mN)({mode:"onSubmit",defaultValues:d??m??It}),{handleSubmit:Ne,register:Ze,formState:{errors:ge,isSubmitting:Ye},getValues:ct,setValue:st,watch:dt}=le,Ut=async X=>{const We=De.$.featureToggles.alertingNavigationV2?(0,ye.nL)(Ve.qI.TEMPLATES,c):(0,ye.nL)(Ve.qI.NOTIFICATIONS,c,{tab:Ae.ActiveTab.NotificationTemplates});try{a?await Y.execute({template:a,patch:X}):await ne.execute({templateValues:X}),y.success("Template saved",`Template ${X.title} has been saved`),xe.Ny.push(We)}catch(Gt){y.error("Error saving template",(0,ye.JZ)(Gt))}},Vt=X=>{const be=ct("content"),We=be?`${be}
${X}`:X;st("content",We)},Kt=X=>{st("content",X),Ge(!0)};return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(fe.Op,{...le,children:(0,e.jsxs)("form",{onSubmit:Ne(Ut),ref:U,className:l.form,"aria-label":(0,s.t)("alerting.template-form.aria-label-template-form","Template form"),children:[G&&(0,e.jsx)(ve.F,{severity:"error",title:(0,s.t)("alerting.template-form.title-error-saving-template","Error saving template"),children:G.message||(0,Ie.NF)(G)&&G.data?.message||String(G)}),je&&p&&(0,e.jsx)(r.a,{grow:0,children:(0,e.jsx)(Le.zt,{resource:Le.hk.Template})}),je&&!p&&(0,e.jsx)(r.a,{grow:0,children:(0,e.jsx)(Le.Yi,{resource:Le.hk.Template})}),(0,e.jsx)(v.n,{disabled:je,className:l.fieldset,children:(0,e.jsxs)(h.B,{direction:"column",gap:1,alignItems:"stretch",minHeight:"100%",children:[(0,e.jsxs)(h.B,{direction:"row",alignItems:"center",children:[(0,e.jsx)(Q.I,{label:(0,s.t)("alerting.template-form.label-template-group-name","Template group name"),error:ge?.title?.message,invalid:!!ge.title?.message,required:!0,children:(0,e.jsx)(D.p,{...Ze("title",{required:{value:!0,message:(0,s.t)("alerting.template-form.message.required","Required.")},validate:{titleIsUnique:ae}}),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)(Qe.h,{}),(0,e.jsxs)(h.B,{children:[(0,e.jsx)(j.$n,{onClick:()=>U.current?.requestSubmit(),variant:"primary",disabled:Ye,children:(0,e.jsx)(s.x6,{i18nKey:"common.save",children:"Save"})}),(0,e.jsx)(j.z9,{disabled:Ye,href:(0,ye.nL)("alerting/notifications",c,{tab:Ae.ActiveTab.NotificationTemplates}),variant:"secondary",children:(0,e.jsx)(s.x6,{i18nKey:"common.cancel",children:"Cancel"})})]})]}),(0,e.jsxs)("div",{...w.containerProps,className:l.contentContainer,children:[(0,e.jsx)("div",{...w.primaryProps,children:(0,e.jsxs)("div",{...S.containerProps,className:l.contentField,children:[(0,e.jsx)("div",{...S.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)(He.D,{label:(0,s.t)("alerting.template-form.label-template-group","Template group"),actions:(0,e.jsxs)(e.Fragment,{children:[ie&&(0,e.jsx)(ee.m,{overlay:(0,e.jsxs)(I.W,{children:[Rt.map((X,be)=>(0,e.jsx)(I.W.Item,{label:X.description,onClick:()=>Vt(X.example)},be)),(0,e.jsx)(I.W.Divider,{}),(0,e.jsx)(I.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)(j.$n,{variant:"secondary",size:"sm",icon:"angle-down",children:(0,e.jsx)(s.x6,{i18nKey:"alerting.templates.editor.add-example",children:"Add example"})})}),ie&&(0,e.jsx)(Xe,{onTemplateGenerated:Kt,disabled:je}),(0,e.jsx)(j.$n,{icon:"question-circle",size:"sm",fill:"outline",variant:"secondary",onClick:E,children:(0,e.jsx)(s.x6,{i18nKey:"common.help",children:"Help"})})]})})}),(0,e.jsx)(r.a,{flex:1,children:(0,e.jsx)(de.Ay,{children:({width:X,height:be})=>(0,e.jsx)(Nt.K,{value:ct("content"),onBlur:We=>st("content",We),containerStyles:l.editorContainer,width:X,height:be})})})]})}),se&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{...S.splitterProps}),(0,e.jsx)("div",{...S.secondaryProps,children:(0,e.jsx)("div",{className:(0,n.cx)(l.containerWithBorderAndRadius,l.minEditorSize,l.payloadEditor,l.flexFull),children:(0,e.jsx)(Lt,{payload:b,defaultPayload:nt,setPayload:B,setPayloadFormatError:Re,payloadFormatError:pe})})})]})]})}),se&&(0,e.jsxs)("div",{...w.secondaryProps,children:[(0,e.jsx)("div",{...w.splitterProps}),(0,e.jsx)(Et.p,{payload:b,templateName:dt("title"),templateContent:dt("content"),setPayloadFormatError:Re,payloadFormatError:pe,className:(0,n.cx)(l.templatePreview,l.minEditorSize),aiGeneratedTemplate:at,setAiGeneratedTemplate:Ge})]})]})]})})]})}),W&&(0,e.jsx)(Z._,{title:(0,s.t)("alerting.template-form.title-templating-cheat-sheet","Templating cheat sheet"),onClose:E,size:"lg",children:(0,e.jsx)(wt,{})})]})};function Ot(){const a=(0,H.of)(it),d=(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)(ve.F,{title:"",severity:"info",children:(0,e.jsxs)(h.B,{direction:"column",gap:2,children:[(0,e.jsxs)(h.B,{direction:"row",children:[(0,e.jsx)("div",{style:{whiteSpace:"pre"},children:d}),(0,e.jsx)("div",{children:(0,e.jsx)(j.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)(M.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(Dt.L).map(c=>c.label).join(", ")})]})]})})}function wt(){return(0,e.jsxs)(h.B,{direction:"column",gap:1,children:[(0,e.jsx)(Ot,{}),(0,e.jsx)(pt,{})]})}const it=a=>{const d=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,[d]:{display:"none"}}),code:(0,n.css)({color:a.colors.text.secondary,fontWeight:a.typography.fontWeightBold})}},Ft=[{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:q(new Date,1).toISOString(),endsAt:u(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:f(new Date,4).toISOString(),endsAt:new Date().toISOString(),fingerprint:"b77d941310f9d381",generatorURL:"http://grafana.com/alerting/grafana/oZSMdGj7z/view"}],nt=JSON.stringify(Ft,null,2)},17374(Ee,k,t){t.d(k,{p:()=>xe});var e=t(74848),n=t(22803),i=t(2543),q=t(70713),x=t(92745),g=t(63142),T=t(45861),u=t(31286),V=t(50992),z=t(34999),A=t(96540),J=t(58684),f=t(74268);let _=null;const P=r=>{if(!_)return null;const v=(0,J.Xc)(_,{title:(0,x.t)("alerting.ai.error-boundary.feedback-button","AI Feedback Button failed to load"),style:"alertbox",errorLogger:f.vV}),h={shouldShowFeedbackButton:!0,useRouteDetection:!1,...r};return(0,A.createElement)(v,h)};function fe(r){_=r}var he=t(77256),de=t(9573),s=t(93562);function De(r,v,h,Q){const[D,{data:j,error:ee,isLoading:I}]=(0,s.vj)(),Z=(0,A.useCallback)(()=>{try{const M=JSON.parse(h);JSON.stringify([...M]),D({template:r,alerts:M,name:v}),Q(null)}catch(M){Q(M instanceof Error?M.message:"Invalid JSON.")}},[r,v,h,Q,D]);return(0,A.useEffect)(()=>Z(),[Z]),{data:j,error:ee,isLoading:I,onPreview:Z}}function xe({payload:r,templateName:v,templateContent:h,payloadFormatError:Q,setPayloadFormatError:D,className:j,aiGeneratedTemplate:ee,setAiGeneratedTemplate:I}){const Z=(0,g.of)(me),{data:M,isLoading:Be,onPreview:Se,error:Ae}=De(h,v,r,D),Ce=ve(Ae,Q,M);return(0,e.jsxs)("div",{className:(0,n.cx)(Z.container,j),children:[(0,e.jsx)(de.D,{label:(0,x.t)("alerting.template-preview.label-preview","Preview"),actions:(0,e.jsx)(T.$n,{disabled:Be,icon:"sync","aria-label":(0,x.t)("alerting.template-preview.aria-label-refresh-preview","Refresh preview"),onClick:()=>{Se(),I?.(!1)},size:"sm",variant:"secondary",children:(0,e.jsx)(x.x6,{i18nKey:"alerting.template-preview.refresh",children:"Refresh"})})}),(0,e.jsx)("div",{className:Z.viewer.feedbackContainer,children:(0,e.jsx)(P,{origin:"template",shouldShowFeedbackButton:!!ee})}),(0,e.jsx)(u.a,{flex:1,children:(0,e.jsx)(q.Ay,{disableWidth:!0,children:({height:Oe})=>(0,e.jsx)("div",{className:Z.viewerContainer({height:Oe}),children:Ce})})})]})}function Ie({previews:r}){const v=(0,g.of)(me),h=r.length===1,Q=D=>{try{return JSON.parse(D),!0}catch{return!1}};return(0,e.jsx)("ul",{className:v.viewer.container,"data-testid":"template-preview",children:r.map(D=>{const j=Q(D.text)?"json":"plaintext";return(0,e.jsxs)("li",{className:v.viewer.box,children:[h?null:(0,e.jsxs)("header",{className:v.viewer.header,children:[D.name,(0,e.jsx)("div",{className:v.viewer.language,children:j})]}),(0,e.jsx)(V.B,{containerStyles:v.editorContainer,language:j,showLineNumbers:!1,showMiniMap:!1,value:D.text,readOnly:!0,monacoOptions:{scrollBeyondLastLine:!1}})]},D.name)})})}function H({errors:r}){return r.map(v=>(0,e.jsx)(z.F,{title:(0,i.compact)([v.name,v.kind]).join(" \u2013 "),children:v.message},(0,i.uniqueId)("errors-list")))}const me=r=>({container:(0,n.css)({label:"template-preview-container",display:"flex",flexDirection:"column",borderRadius:r.shape.radius.default,border:`1px solid ${r.colors.border.medium}`}),editorContainer:(0,n.css)({width:"100%",height:"100%",border:"none"}),viewerContainer:({height:v})=>(0,n.css)({height:v,overflow:"auto",backgroundColor:r.colors.background.primary}),viewer:{container:(0,n.css)({display:"flex",flexDirection:"column",height:"inherit"}),box:(0,n.css)({display:"flex",flexDirection:"column",borderBottom:`1px solid ${r.colors.border.medium}`,height:"inherit"}),header:(0,n.css)({display:"flex",justifyContent:"space-between",fontSize:r.typography.bodySmall.fontSize,padding:r.spacing(1,2),borderBottom:`1px solid ${r.colors.border.medium}`,backgroundColor:r.colors.background.secondary}),language:(0,n.css)({marginLeft:"auto",fontStyle:"italic"}),errorText:(0,n.css)({color:r.colors.error.text}),feedbackContainer:(0,n.css)({display:"flex",justifyContent:"center",alignItems:"center",borderTop:`1px solid ${r.colors.border.medium}`,backgroundColor:r.colors.background.secondary,minHeight:"auto"}),emptyState:(0,n.css)({display:"flex",alignItems:"center",justifyContent:"center",height:"100%",color:r.colors.text.secondary,fontSize:r.typography.bodySmall.fontSize})}});function ve(r,v,h){const Q=r?(0,he.JZ)(r):void 0,D=v||Q,j=(0,g.of)(me),ee=h?.results??[],I=h?.errors,Z=ee.length>0||I||D;return(0,e.jsxs)(e.Fragment,{children:[D&&(0,e.jsx)(z.F,{severity:"error",title:(0,x.t)("alerting.get-preview-results.title-error","Error"),children:D}),I&&(0,e.jsx)(H,{errors:I}),ee.length>0&&(0,e.jsx)(Ie,{previews:ee}),!Z&&(0,e.jsx)("div",{className:j.viewer.emptyState,children:(0,e.jsx)(x.x6,{i18nKey:"alerting.template-preview.empty-state",children:"Add template content to see preview"})})]})}},87988(Ee,k,t){t.d(k,{D:()=>e,G7:()=>q,Jl:()=>n,gY:()=>i});function e(x){const g={},T=[],u=/{{-?\s*(define|end|if|range|else|with|template|block)\b(.*?)-?}}/gs;let V,z=0;for(;(V=u.exec(x))!==null;){const[,A,J]=V;if(z=V.index,A==="define"){const f=J?.match(/"([^"]+)"/);f&&T.push({type:"define",startIndex:z,name:f[1]})}else if(A==="end"){let f=T.pop();for(;f&&f.type!=="define"&&f.type!=="if"&&f.type!=="range"&&f.type!=="with"&&f.type!=="block";)f=T.pop();if(f){const _=u.lastIndex;f.type==="define"&&!f.name?.startsWith("__")&&(g[f.name]={name:f.name,content:x.slice(f.startIndex,_)})}}else(A==="if"||A==="range"||A==="else"||A==="with"||A==="block")&&T.push({type:A,startIndex:z})}for(const A of Object.values(g)){const J=/{{ template "([^"]+)" }}/g;let f;for(;(f=J.exec(A.content))!==null;){const _=f[1];g[_]?.content&&(A.content+=`
`+g[_]?.content,delete g[_])}}return Object.values(g)}function n(x){return`{{ template "${x}" . }}`}function i(x){const g=x.match(/\{\{\s*template\s*"(.*)"\s*\.\s*\}\}/);return g?g[1]:""}function q(x){const g=/\{\{\s*template\s*".*?"\s*\.\s*\}\}/g;if(x.match(g)?.length!==1)return!1;const u=x.split(g);for(const V of u)if(V.trim()!=="")return!1;return!0}}}]);

//# sourceMappingURL=9292.e529ff736f28256e424f.js.map