"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4679],{73632:(H,W,e)=>{e.r(W),e.d(W,{default:()=>B,defaultPageNav:()=>z});var n=e(85960),V=e(90857),x=e(49199),A=e(8958),Q=e(3693),I=e(65892),h=e(94498),K=e(60956);const M=(0,Q.Q)(()=>Promise.all([e.e(3638),e.e(9244),e.e(9210),e.e(3827),e.e(4405),e.e(8408)]).then(e.bind(e,38408))),c=n.lazy(()=>Promise.all([e.e(3638),e.e(9244),e.e(9210),e.e(3827),e.e(4405),e.e(4380)]).then(e.bind(e,44380))),L=!!V.config.featureToggles.alertingDetailsViewV2,y=f=>L?n.createElement(Z,{...f}):n.createElement(Y,{...f}),z={id:"alert-rule-view",text:""},Y=f=>n.createElement(M,{...f}),Z=f=>{const N=(0,K.s4)(f.match.params),S=(0,n.useMemo)(()=>{if(!N)throw new Error("Rule ID is required");return(0,K.Qc)(N,!0)},[N]),{loading:T,error:t,result:a}=(0,h.HO)({ruleIdentifier:S});return t?typeof t=="string"?t:n.createElement(x.b,{title:"Uh-oh"},"Something went wrong loading the rule"):T?n.createElement(I.J,{pageNav:z,navId:"alert-list",isLoading:!0},n.createElement(n.Fragment,null)):a?n.createElement(c,{rule:a,identifier:S}):null},B=(0,A.Pf)(y,{style:"page"})},65892:(H,W,e)=>{e.d(W,{J:()=>m,O:()=>v});var n=e(85960),V=e(8134),x=e(20989),A=e(90857),Q=e(79055),I=e(66681),h=e(6753),K=e(47257),M=e(74042),c=e(14607),L=e(29165),y=e(49199);const z=({localStoreKey:r,startClosed:i=!1,severity:s="error",collapseText:R,collapseTooltip:F,collapseJustify:U="flex-end",alertTitle:l,children:P})=>{const E=(0,K.l4)(),D=Y(E,s),[O,G]=(0,h.Z)(r,i);return n.createElement(n.Fragment,null,O&&n.createElement(M.Lh,{justify:U},n.createElement(c.u,{content:F,placement:"bottom"},n.createElement(L.zx,{fill:"text",variant:"secondary",icon:(0,y.j)(s),className:D.warningButton,onClick:()=>G(!1)},R))),!O&&n.createElement(y.b,{severity:s,title:l,onRemove:()=>G(!0)},P))},Y=(r,i)=>{const s=r.colors[i];return{warningButton:(0,I.css)({color:s.text,"&:hover":{background:s.transparent}})}},Z="grafana.unifiedalerting.upgrade.previewNotice",B=()=>A.config.unifiedAlertingEnabled||!A.config.featureToggles.alertingPreviewUpgrade?null:n.createElement(z,{localStoreKey:Z,alertTitle:"This is a preview of the upgraded Grafana Alerting",collapseText:"Grafana Alerting Preview",collapseTooltip:"Show preview warning",severity:"warning"},n.createElement("p",null,"No rules are being evaluated and legacy alerting is still running.",n.createElement("br",null),"Please contact your administrator to upgrade permanently."),n.createElement(Q.h,{external:!0,href:"https://grafana.com/docs/grafana/latest/alerting/set-up/migrating-alerts/"},"Read about upgrading"));var f=e(84954),N=e(84933),S=e(27436),T=e(76679);function t(r){return r.name===T.GC?"Grafana":r.name.slice(0,37)}const a=({disabled:r=!1})=>{const i=(0,K.wW)(u),{selectedAlertmanager:s,availableAlertManagers:R,setSelectedAlertmanager:F}=(0,f.ZA)(),U=(0,n.useMemo)(()=>R.map(l=>({label:t(l),value:l.name,imgUrl:l.imgUrl,meta:l.meta})),[R]);return n.createElement(N._,{className:i.field,label:r?"Alertmanager":"Choose Alertmanager",disabled:r||U.length===1,"data-testid":"alertmanager-picker"},n.createElement(S.Ph,{"aria-label":r?"Alertmanager":"Choose Alertmanager",width:29,className:"ds-picker select-container",backspaceRemovesValue:!1,onChange:l=>{l?.value&&F(l.value)},options:U,maxMenuHeight:500,noOptionsMessage:"No datasources found",value:s,getOptionLabel:l=>l.label}))},u=r=>({field:(0,I.css)`
    margin: 0;
  `}),o=()=>n.createElement(y.b,{title:"No Alertmanager found",severity:"warning"},"We could not find any external Alertmanagers and you may not have access to the built-in Grafana Alertmanager."),p=()=>n.createElement(y.b,{title:"Selected Alertmanager not found.",severity:"warning"},"The selected Alertmanager no longer exists or you may not have permission to access it. You can select a different Alertmanager from the dropdown."),g=({availableAlertManagers:r})=>{const i=r.length>0;return n.createElement("div",null,i?n.createElement(p,null):n.createElement(o,null))},m=({children:r,isLoading:i,...s})=>n.createElement(x.T,{...s},n.createElement(x.T.Contents,{isLoading:i},n.createElement("div",null,n.createElement(B,null),r))),v=({children:r,accessType:i,...s})=>{const R=d();return n.createElement(f.h5,{accessType:i},n.createElement(m,{...s,actions:n.createElement(a,{disabled:R})},n.createElement(C,null,r)))};function d(){const r=(0,V.Z)();return["/edit","/new"].some(s=>r?.pathname?.includes(s))}const C=({children:r})=>{const{availableAlertManagers:i,selectedAlertmanager:s}=(0,f.ZA)();return s?n.createElement(n.Fragment,null,r):n.createElement(g,{availableAlertManagers:i})}},94498:(H,W,e)=>{e.d(W,{F3:()=>Y,HO:()=>f,eq:()=>T});var n=e(85960),V=e(81445),x=e(95162),A=e(14411),Q=e(80679),I=e(5970),h=e(76679),K=e(30422),M=e(60956),c=e(9001),L=e(68700),y=e(92746);function z(t,a){const u=Z(a),o=useCombinedRuleNamespaces(a),p=useMemo(()=>{if(!t||!a||o.length===0)return[];const g=[];for(const m of o)for(const v of m.groups)for(const d of v.rules)d.name===t&&g.push(d);return g},[t,a,o]);return{...u,result:p}}function Y(t,a,u){const o=(0,h.c$)(a),{dsFeatures:p,isLoadingDsFeatures:g}=T(a),{currentData:m=[],isLoading:v,error:d}=A.alertRuleApi.endpoints.prometheusRuleNamespaces.useQuery({ruleSourceName:a,ruleName:t,namespace:u?.namespace,groupName:u?.groupName}),[C]=A.alertRuleApi.endpoints.rulerRuleGroup.useLazyQuery(),{loading:r,error:i,value:s}=(0,V.Z)(async()=>{if(!o)throw new Error("Unable to obtain data source settings");if(d)throw new Error("Unable to obtain Prometheus rules");const R=[];if(p?.rulerConfig){const l=p.rulerConfig,P=m.map(E=>E.groups.map(D=>({namespace:E,group:D}))).flat();await Promise.allSettled(P.map(async E=>{const D=await C({rulerConfig:l,namespace:E.namespace.name,group:E.group.name}).unwrap();R.push(D)}))}return m.map(l=>(0,L.K$)(o,l,R)).flatMap(l=>l.groups.flatMap(P=>P.rules))},[o,p,v,d,m,C]);return{loading:g||r,error:i,rules:s}}function Z(t,a){const u=useDispatch(),o=useUnifiedAlertingSelector(d=>d.promRules),p=B(t,o),g=useUnifiedAlertingSelector(d=>d.rulerRules),m=B(t,g),{loading:v}=useAsync(async()=>{t&&await u(fetchPromAndRulerRulesAction({rulesSourceName:t,identifier:a}))},[u,t]);return{loading:v,error:p.error??isRulerNotSupportedResponse(m)?void 0:m.error,dispatched:p.dispatched&&m.dispatched}}function B(t,a){if(!t)return initialAsyncRequestState;const u=a[t];return u||initialAsyncRequestState}function f({ruleIdentifier:t}){const{ruleSourceName:a}=t,u=(0,h.c$)(a),{dsFeatures:o,isLoadingDsFeatures:p}=T(a),{currentData:g,isLoading:m,error:v}=A.alertRuleApi.endpoints.prometheusRuleNamespaces.useQuery({ruleSourceName:t.ruleSourceName,namespace:(0,c.qE)(t)||(0,c.E4)(t)?t.namespace:void 0,groupName:(0,c.qE)(t)||(0,c.E4)(t)?t.groupName:void 0,ruleName:(0,c.qE)(t)||(0,c.E4)(t)?t.ruleName:void 0}),[d,{currentData:C,isLoading:r,error:i}]=A.alertRuleApi.endpoints.rulerRuleGroup.useLazyQuery(),[s,{currentData:R,isLoading:F,error:U}]=A.alertRuleApi.endpoints.rulerRules.useLazyQuery();(0,n.useEffect)(()=>{o?.rulerConfig&&(o.rulerConfig&&(0,c.E4)(t)?d({rulerConfig:o.rulerConfig,namespace:t.namespace,group:t.groupName}):(0,c.Kl)(t)&&s({rulerConfig:o.rulerConfig}))},[o,d,s,t]);const l=(0,n.useMemo)(()=>{if(g){if((0,c.Kl)(t)){const P=(0,L.bU)("grafana",g,R);for(const E of P)for(const D of E.groups)for(const O of D.rules){const G=M.Yd(a,O);if(M.Dg(G,t))return O}}if(u&&g.length>0&&((0,c.E4)(t)||(0,c.qE)(t))){const P=g.map(E=>(0,L.K$)(u,E,C?[C]:[]));for(const E of P)for(const D of E.groups)for(const O of D.rules){const G=M.Yd(a,O);if(M.Dg(G,t))return O}}}},[t,a,g,C,R,u]);return{loading:p||m||r||F,error:v??i??U,result:l}}const S={rulerConfig:{dataSourceName:h.GC,apiVersion:"legacy"}};function T(t){const a=(0,h.HY)(t),{currentData:u,isLoading:o}=Q.T.endpoints.discoverDsFeatures.useQuery({rulesSourceName:t},{skip:a});return a?{isLoadingDsFeatures:!1,dsFeatures:S}:{isLoadingDsFeatures:o,dsFeatures:u}}}}]);

//# sourceMappingURL=AlertingRule.f39c43a244504283c9cb.js.map