"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2461,4286],{29507:(e,a,r)=>{r.d(a,{x:()=>l});var s=r(68404),t=r(18745),n=r(45193);function l(e){const a=(0,t.useDispatch)(),r=(0,s.useRef)(e);r.current=e,(0,s.useEffect)((()=>()=>{a((0,n.e)({stateSelector:r.current}))}),[a])}},10029:(e,a,r)=>{r.r(a),r.d(a,{AlertRuleListUnconnected:()=>F,default:()=>A});var s,t=r(68404),n=r(18745),l=r(90923),i=r(69783),o=r(5831),c=r(33801),d=r(8674),u=r(21169),p=r(45916);function g(e){let{onDismiss:a}=e;return(0,p.jsx)(i.Modal,{title:"Adding an Alert",isOpen:!0,onDismiss:a,onClickBackdrop:a,children:s||(s=(0,p.jsxs)(i.VerticalGroup,{spacing:"sm",children:[(0,p.jsx)("img",{src:"public/img/alert_howto_new.png",alt:"link to how to alert image"}),(0,p.jsx)("p",{children:"Alerts are added and configured in the Alert tab of any dashboard graph panel, letting you build and visualize an alert using existing queries."}),(0,p.jsx)("p",{children:"Remember to save the dashboard to persist your alert rule changes."})]}))})}var m=r(9575),h=r.n(m);const x=e=>{let{rule:a,search:r,onTogglePause:s}=e;const n=`${a.url}?editPanel=${a.panelId}&tab=alert`,l=(0,t.useCallback)((e=>(0,p.jsx)(h(),{highlightClassName:"highlight-search-match",textToHighlight:e,searchWords:[r]},e)),[r]);return(0,p.jsxs)(i.Card,{children:[(0,p.jsx)(i.Card.Heading,{children:l(a.name)}),(0,p.jsx)(i.Card.Figure,{children:(0,p.jsx)(i.Icon,{size:"xl",name:a.stateIcon,className:`alert-rule-item__icon ${a.stateClass}`})}),(0,p.jsxs)(i.Card.Meta,{children:[(0,p.jsxs)("span",{children:[(0,p.jsxs)("span",{className:`${a.stateClass}`,children:[l(a.stateText)," "]},"text"),"for ",a.stateAge]},"state"),a.info?l(a.info):null]}),(0,p.jsxs)(i.Card.Actions,{children:[(0,p.jsx)(i.Button,{variant:"secondary",icon:"paused"===a.state?"play":"pause",onClick:s,children:"paused"===a.state?"Resume":"Pause"},"play"),(0,p.jsx)(i.LinkButton,{variant:"secondary",href:n,icon:"cog",children:"Edit alert"},"edit")]})]})};var v;const j=()=>v||(v=(0,p.jsxs)(i.Alert,{severity:"warning",title:"Grafana legacy alerting is going away soon",children:[(0,p.jsxs)("p",{children:["You are using Grafana legacy alerting, it has been deprecated and will be removed in the next major version of Grafana.",(0,p.jsx)("br",{}),"We encourage you to upgrade to the new Grafana alerting experience."]}),(0,p.jsxs)("p",{children:["See"," ",(0,p.jsx)("a",{href:"https://grafana.com/docs/grafana/latest/alerting/unified-alerting/difference-old-new/",children:"What’s New with Grafana alerting"})," ","to learn more about what‘s new or learn"," ",(0,p.jsx)("a",{href:"https://grafana.com/docs/grafana/latest/alerting/unified-alerting/opt-in/",children:"how to enable the new Grafana alerting feature"}),"."]})]}));var f=r(9191),b=r(61988);const S=e=>e.searchQuery,y=e=>{const a=new RegExp(e.alertRules.searchQuery,"i");return e.alertRules.items.filter((e=>a.test(e.name)||a.test(e.stateText)||a.test(e.info)))};var w,C,N,R;function k(e,a,r){return a in e?Object.defineProperty(e,a,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[a]=r,e}const $={getAlertRulesAsync:f.Au,setSearchQuery:b.ql,togglePauseAlertRule:f.en},_=(0,n.connect)((function(e){return{navModel:(0,d.h)(e.navIndex,"alert-list"),alertRules:y(e),search:S(e.alertRules),isLoading:e.alertRules.isLoading}}),$);class F extends t.PureComponent{constructor(){super(...arguments),k(this,"stateFilters",[{label:"All",value:"all"},{label:"OK",value:"ok"},{label:"Not OK",value:"not_ok"},{label:"Alerting",value:"alerting"},{label:"No data",value:"no_data"},{label:"Paused",value:"paused"},{label:"Pending",value:"pending"}]),k(this,"onStateFilterChanged",(e=>{l.locationService.partial({state:e.value})})),k(this,"onOpenHowTo",(()=>{o.Z.publish(new u.Dn({component:g}))})),k(this,"onSearchQueryChange",(e=>{this.props.setSearchQuery(e)})),k(this,"onTogglePause",(e=>{this.props.togglePauseAlertRule(e.id,{paused:"paused"!==e.state})})),k(this,"alertStateFilterOption",(e=>{let{text:a,value:r}=e;return(0,p.jsx)("option",{value:r,children:a},r)}))}componentDidMount(){this.fetchRules()}componentDidUpdate(e){e.queryParams.state!==this.props.queryParams.state&&this.fetchRules()}async fetchRules(){await this.props.getAlertRulesAsync({state:this.getStateFilter()})}getStateFilter(){var e;return null!==(e=this.props.queryParams.state)&&void 0!==e?e:"all"}render(){const{navModel:e,alertRules:a,search:r,isLoading:s}=this.props;return(0,p.jsx)(c.Z,{navModel:e,children:(0,p.jsxs)(c.Z.Contents,{isLoading:s,children:[(0,p.jsxs)("div",{className:"page-action-bar",children:[(0,p.jsx)("div",{className:"gf-form gf-form--grow",children:(0,p.jsx)(i.FilterInput,{placeholder:"Search alerts",value:r,onChange:this.onSearchQueryChange})}),(0,p.jsxs)("div",{className:"gf-form",children:[w||(w=(0,p.jsx)("label",{className:"gf-form-label",htmlFor:"alert-state-filter",children:"States"})),(0,p.jsx)("div",{className:"width-13",children:(0,p.jsx)(i.Select,{inputId:"alert-state-filter",options:this.stateFilters,onChange:this.onStateFilterChanged,value:this.getStateFilter()})})]}),C||(C=(0,p.jsx)("div",{className:"page-action-bar__spacer"})),l.config.unifiedAlertingEnabled&&(N||(N=(0,p.jsx)(i.LinkButton,{variant:"primary",href:"alerting/ng/new",children:"Add NG Alert"}))),(0,p.jsx)(i.Button,{variant:"secondary",onClick:this.onOpenHowTo,children:"How to add an alert"})]}),R||(R=(0,p.jsx)(j,{})),(0,p.jsx)(i.VerticalGroup,{spacing:"none",children:a.map((e=>(0,p.jsx)(x,{rule:e,search:r,onTogglePause:()=>this.onTogglePause(e)},e.id)))})]})})}}const A=_(F)},9191:(e,a,r)=>{r.d(a,{Au:()=>i,C2:()=>c,c1:()=>u,en:()=>o,fA:()=>p,fg:()=>d,tk:()=>g});var s=r(90923),t=r(36537),n=r(58257),l=r(61988);function i(e){return async a=>{a((0,l.gz)());const r=await(0,s.getBackendSrv)().get("/api/alerts",e);a((0,l.Oc)(r))}}function o(e,a){return async r=>{await(0,s.getBackendSrv)().post(`/api/alerts/${e}/pause`,a);r(i({state:(s.locationService.getSearchObject().state||"all").toString()}))}}function c(e){return async a=>{try{await(0,s.getBackendSrv)().post("/api/alert-notifications",e),a((0,t.$l)((0,n.AT)("Notification created"))),s.locationService.push("/alerting/notifications")}catch(e){a((0,t.$l)((0,n.t_)(e.data.error)))}}}function d(e){return async a=>{try{await(0,s.getBackendSrv)().put(`/api/alert-notifications/${e.id}`,e),a((0,t.$l)((0,n.AT)("Notification updated")))}catch(e){a((0,t.$l)((0,n.t_)(e.data.error)))}}}function u(e){return async(a,r)=>{const t=r().notificationChannel.notificationChannel;await(0,s.getBackendSrv)().post("/api/alert-notifications/test",Object.assign({id:t.id},e))}}function p(){return async e=>{const a=(await(0,s.getBackendSrv)().get("/api/alert-notifiers")).sort(((e,a)=>e.name>a.name?1:-1));e((0,l.T2)(a))}}function g(e){return async a=>{await a(p());const r=await(0,s.getBackendSrv)().get(`/api/alert-notifications/${e}`);a((0,l.K)(r))}}},41401:(e,a,r)=>{r.r(a),r.d(a,{default:()=>Oe});var s,t,n=r(36636),l=r(68404),i=r(18745),o=r(42326),c=r(43215),d=r(69783),u=r(26011),p=r(40256),g=r(28436),m=r(69450),h=r(45916);const x=()=>{const{canCreateGrafanaRules:e,canCreateCloudRules:a}=(0,m.B)();return e||a?s||(s=(0,h.jsx)(g.Z,{title:"You haven`t created any alert rules yet",buttonIcon:"bell",buttonLink:"alerting/new",buttonTitle:"New alert rule",proTip:"you can also create alert rules from existing panels and queries.",proTipLink:"https://grafana.com/docs/",proTipLinkTitle:"Learn more",proTipTarget:"_blank"})):t||(t=(0,h.jsx)(d.CallToActionCard,{message:"No rules exist yet.",callToActionElement:(0,h.jsx)("div",{})}))};var v=r(71788),j=r.n(v),f=r(40652),b=r(33899),S=r(19462),y=r(86647);function w(){const[e,a]=(0,l.useState)(!1),[r,s]=(0,f.Z)("grafana.unifiedalerting.hideErrors",!1),t=(0,b._)((e=>e.dataSources)),n=(0,b._)((e=>e.promRules)),i=(0,b._)((e=>e.rulerRules)),o=(0,d.useStyles2)(N),c=(0,l.useMemo)((()=>{var e,a;const[r,s,l]=[t,n,i].map((e=>(0,S.Eu)().reduce(((a,r)=>{var s;const t=null===(s=e[r.name])||void 0===s?void 0:s.error;return e[r.name]&&t&&!(0,y.m$)(e[r.name])?[...a,{dataSource:r,error:t}]:a}),[]))),o=null===(e=n[S.GC])||void 0===e?void 0:e.error,c=null===(a=i[S.GC])||void 0===a?void 0:a.error,d=[];return o&&d.push((0,h.jsxs)(h.Fragment,{children:["Failed to load Grafana rules state: ",o.message||"Unknown error."]})),c&&d.push((0,h.jsxs)(h.Fragment,{children:["Failed to load Grafana rules config: ",c.message||"Unknown error."]})),r.forEach((e=>{let{dataSource:a,error:r}=e;d.push((0,h.jsxs)(h.Fragment,{children:["Failed to load the data source configuration for"," ",(0,h.jsx)("a",{href:`datasources/edit/${a.uid}`,children:a.name}),": ",r.message||"Unknown error."]}))})),s.forEach((e=>{let{dataSource:a,error:r}=e;return d.push((0,h.jsxs)(h.Fragment,{children:["Failed to load rules state from ",(0,h.jsx)("a",{href:`datasources/edit/${a.uid}`,children:a.name}),":"," ",r.message||"Unknown error."]}))})),l.forEach((e=>{let{dataSource:a,error:r}=e;return d.push((0,h.jsxs)(h.Fragment,{children:["Failed to load rules config from ",(0,h.jsx)("a",{href:`datasources/edit/${a.uid}`,children:a.name}),":"," ",r.message||"Unknown error."]}))})),d}),[t,n,i]);return(0,h.jsxs)(h.Fragment,{children:[!!c.length&&r&&(0,h.jsx)(C,{count:c.length,onClick:()=>s((e=>!e))}),!!c.length&&!r&&(0,h.jsxs)(d.Alert,{"data-testid":"cloud-rulessource-errors",title:"Errors loading rules",severity:"error",onRemove:()=>s(!0),children:[e&&c.map(((e,a)=>(0,h.jsx)("div",{children:e},a))),!e&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)("div",{children:c[0]}),c.length>=2&&(0,h.jsxs)(d.Button,{className:o.moreButton,fill:"text",icon:"angle-right",size:"sm",onClick:()=>a(!0),children:[c.length-1," more ",j()("error",c.length-1)]})]})]})]})}const C=e=>{let{count:a,onClick:r}=e;const s=(0,d.useStyles2)(N);return(0,h.jsx)("div",{className:s.floatRight,children:(0,h.jsx)(d.Tooltip,{content:"Show all errors",placement:"bottom",children:(0,h.jsx)(d.Button,{fill:"text",variant:"destructive",icon:"exclamation-triangle",onClick:r,children:a>1?(0,h.jsxs)(h.Fragment,{children:[a," errors"]}):(0,h.jsx)(h.Fragment,{children:"1 error"})})})})},N=e=>({moreButton:n.css` padding: 0; `,floatRight:n.css` display: flex; justify-content: flex-end; `});var R=r(58170),k=r(53262),$=r(39132),_=r(13309),F=r(26980),A=r(83809),T=r(91045),G=r(85598),I=r(3799),B=r(29507),E=r(8455),L=r(66322);function O(e){var a,r;const{namespace:s,group:t,onClose:n}=e,o=(0,d.useStyles2)(P),c=(0,i.useDispatch)(),{loading:u,error:p,dispatched:g}=null!==(a=(0,b._)((e=>e.updateLotexNamespaceAndGroup)))&&void 0!==a?a:E.oq,m=(0,l.useMemo)((()=>{var e;return{namespaceName:s.name,groupName:t.name,groupInterval:null!==(e=t.interval)&&void 0!==e?e:""}}),[s,t]);(0,l.useEffect)((()=>{!g||u||p||n()}),[g,u,n,p]),(0,B.x)((e=>e.unifiedAlerting.updateLotexNamespaceAndGroup));return(0,h.jsx)(d.Modal,{className:o.modal,isOpen:!0,title:"Edit namespace or rule group",onDismiss:n,onClickBackdrop:n,children:(0,h.jsx)(d.Form,{defaultValues:m,onSubmit:e=>{c((0,A.hv)({rulesSourceName:(0,S.EG)(s.rulesSource),groupName:t.name,newGroupName:e.groupName,namespaceName:s.name,newNamespaceName:e.namespaceName,groupInterval:e.groupInterval||void 0}))},children:e=>{var a,s,t;let{register:l,errors:i,formState:{isDirty:o}}=e;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(d.Field,{label:"Namespace",invalid:!!i.namespaceName,error:null===(a=i.namespaceName)||void 0===a?void 0:a.message,children:(0,h.jsx)(d.Input,Object.assign({id:"namespaceName"},l("namespaceName",{required:"Namespace name is required."})))}),(0,h.jsx)(d.Field,{label:"Rule group",invalid:!!i.groupName,error:null===(s=i.groupName)||void 0===s?void 0:s.message,children:(0,h.jsx)(d.Input,Object.assign({id:"groupName"},l("groupName",{required:"Rule group name is required."})))}),(0,h.jsx)(d.Field,{label:"Rule group evaluation interval",invalid:!!i.groupInterval,error:null===(t=i.groupInterval)||void 0===t?void 0:t.message,children:(0,h.jsx)(d.Input,Object.assign({id:"groupInterval",placeholder:"1m"},l("groupInterval",{pattern:L.lR})))}),(0,h.jsxs)(d.Modal.ButtonRow,{children:[r||(r=(0,h.jsx)(d.Button,{variant:"secondary",type:"button",disabled:u,onClick:n,fill:"outline",children:"Close"})),(0,h.jsx)(d.Button,{type:"submit",disabled:!o||u,children:u?"Saving...":"Save changes"})]})]})}},JSON.stringify(m))})}const P=()=>({modal:n.css` max-width: 560px; `});var M=r(51542);const q=e=>{let{children:a,status:r}=e;const s=(0,d.useStyles2)(D);return(0,h.jsx)("span",{className:s[r],children:a||r})},D=e=>({[M.x_.Inactive]:n.css` color: ${e.colors.success.text}; `,[M.x_.Pending]:n.css` color: ${e.colors.warning.text}; `,[M.x_.Firing]:n.css` color: ${e.colors.error.text}; `,neutral:n.css` color: ${e.colors.text.secondary}; `});var z,H;const U={total:0,recording:0,[M.x_.Firing]:0,[M.x_.Pending]:0,[M.x_.Inactive]:0,error:0},V=e=>{let{showInactive:a,showRecording:r,group:s,namespaces:t}=e;const n=(0,l.useMemo)((()=>{const e=Object.assign({},U),a=a=>{var r,s;a.promRule&&(0,y.x_)(a.promRule)&&(e[a.promRule.state]+=1),"err"!==(null===(r=a.promRule)||void 0===r?void 0:r.health)&&"error"!==(null===(s=a.promRule)||void 0===s?void 0:s.health)||(e.error+=1),(a.promRule&&(0,y.OP)(a.promRule)||a.rulerRule&&(0,y.yF)(a.rulerRule))&&(e.recording+=1),e.total+=1};return s&&s.rules.forEach(a),t&&t.forEach((e=>e.groups.forEach((e=>e.rules.forEach(a))))),e}),[s,t]),i=[];return n[M.x_.Firing]&&i.push((0,h.jsxs)(q,{status:M.x_.Firing,children:[n[M.x_.Firing]," firing"]},"firing")),n.error&&i.push((0,h.jsxs)(q,{status:M.x_.Firing,children:[n.error," errors"]},"errors")),n[M.x_.Pending]&&i.push((0,h.jsxs)(q,{status:M.x_.Pending,children:[n[M.x_.Pending]," pending"]},"pending")),a&&n[M.x_.Inactive]&&i.push((0,h.jsxs)(q,{status:"neutral",children:[n[M.x_.Inactive]," normal"]},"inactive")),r&&n.recording&&i.push((0,h.jsxs)(q,{status:"neutral",children:[n.recording," recording"]},"recording")),(0,h.jsxs)("div",{children:[(0,h.jsxs)("span",{children:[n.total," ",j()("rule",n.total)]}),!!i.length&&(0,h.jsxs)(h.Fragment,{children:[z||(z=(0,h.jsx)("span",{children:": "})),i.reduce(((e,a,r)=>e.length?[e,(0,h.jsx)(l.Fragment,{children:H||(H=(0,h.jsx)("span",{children:", "}))},r),a]:[a]),[])]})]})};var W,Z,K,J,Q=r(86692);const Y=l.memo((e=>{var a;let{group:r,namespace:s,expandAll:t}=e;const{rulesSource:n}=s,o=(0,i.useDispatch)(),c=(0,d.useStyles2)(X),[u,p]=(0,l.useState)(!1),[g,x]=(0,l.useState)(!1),[v,f]=(0,l.useState)(!t),{canEditRules:b}=(0,m.B)();(0,l.useEffect)((()=>{f(!t)}),[t]);const{hasRuler:w,rulerRulesLoaded:C}=(0,F.h)(),N=null===(a=r.rules[0])||void 0===a?void 0:a.rulerRule,R=N&&(0,y.Pc)(N)&&N.grafana_alert.namespace_uid||void 0,{folder:k}=(0,_.W)(R),B=w(n)&&C(n)&&!r.rules.find((e=>!!e.rulerRule)),E=(0,y.Jq)(r),L=[];if(B)L.push(W||(W=(0,h.jsxs)(d.HorizontalGroup,{children:[(0,h.jsx)(d.Spinner,{}),"deleting"]},"is-deleting")));else if(n===S.GC){if(R){const e=`/dashboards/f/${R}/${$.Z.slugifyForUrl(s.name)}`;null!=k&&k.canSave&&L.push((0,h.jsx)(I.A,{"aria-label":"edit folder",icon:"pen",tooltip:"edit folder",to:e+"/settings",target:"__blank"},"edit")),null!=k&&k.canAdmin&&L.push((0,h.jsx)(I.A,{"aria-label":"manage permissions",icon:"lock",tooltip:"manage permissions",to:e+"/permissions",target:"__blank"},"manage-perms"))}}else b(n.name)&&w(n)&&(E||L.push((0,h.jsx)(I.A,{"aria-label":"edit rule group","data-testid":"edit-group",icon:"pen",tooltip:"edit rule group",onClick:()=>p(!0)},"edit")),L.push((0,h.jsx)(I.A,{"aria-label":"delete rule group","data-testid":"delete-group",icon:"trash-alt",tooltip:"delete rule group",onClick:()=>x(!0)},"delete-group")));const P="default"===r.name?(0,h.jsx)(G.V,{namespace:s.name}):(0,h.jsx)(G.V,{namespace:s.name,group:r.name});return(0,h.jsxs)("div",{className:c.wrapper,"data-testid":"rule-group",children:[(0,h.jsxs)("div",{className:c.header,"data-testid":"rule-group-header",children:[(0,h.jsx)(T.U,{className:c.collapseToggle,isCollapsed:v,onToggle:f,"data-testid":"group-collapse-toggle"}),(0,h.jsx)(d.Icon,{name:v?"folder":"folder-open"}),(0,S.jq)(n)&&(0,h.jsx)(d.Tooltip,{content:n.name,placement:"top",children:(0,h.jsx)("img",{alt:n.meta.name,className:c.dataSourceIcon,src:n.meta.info.logos.small})}),(0,h.jsxs)("h6",{className:c.heading,children:[E&&(Z||(Z=(0,h.jsx)(d.Badge,{color:"purple",text:"Federated"})))," ",P]}),(0,h.jsx)("div",{className:c.spacer}),(0,h.jsx)("div",{className:c.headerStats,children:(0,h.jsx)(V,{showInactive:!1,group:r})}),!!L.length&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)("div",{className:c.actionsSeparator,children:"|"}),(0,h.jsx)("div",{className:c.actionIcons,children:L})]})]}),!v&&(0,h.jsx)(Q.i,{showSummaryColumn:!0,className:c.rulesTable,showGuidelines:!0,rules:r.rules}),u&&(0,h.jsx)(O,{group:r,namespace:s,onClose:()=>p(!1)}),(0,h.jsx)(d.ConfirmModal,{isOpen:g,title:"Delete group",body:(0,h.jsxs)("div",{children:["Deleting this group will permanently remove the group",K||(K=(0,h.jsx)("br",{})),"and ",r.rules.length," alert ",j()("rule",r.rules.length)," belonging to it.",J||(J=(0,h.jsx)("br",{})),"Are you sure you want to delete this group?"]}),onConfirm:()=>{o((0,A.oE)(s,r)),x(!1)},onDismiss:()=>x(!1),confirmText:"Delete"})]})}));Y.displayName="RulesGroup";const X=e=>({wrapper:n.css` & + & { margin-top: ${e.spacing(2)}; } `,header:n.css` display: flex; flex-direction: row; align-items: center; padding: ${e.spacing(1)} ${e.spacing(1)} ${e.spacing(1)} 0; background-color: ${e.colors.background.secondary}; flex-wrap: wrap; `,headerStats:n.css` span { vertical-align: middle; } ${e.breakpoints.down("sm")} { order: 2; width: 100%; padding-left: ${e.spacing(1)}; } `,heading:n.css` margin-left: ${e.spacing(1)}; margin-bottom: 0; `,spacer:n.css` flex: 1; `,collapseToggle:n.css` background: none; border: none; margin-top: -${e.spacing(1)}; margin-bottom: -${e.spacing(1)}; svg { margin-bottom: 0; } `,dataSourceIcon:n.css` width: ${e.spacing(2)}; height: ${e.spacing(2)}; margin-left: ${e.spacing(2)}; `,dataSourceOrigin:n.css` margin-right: 1em; color: ${e.colors.text.disabled}; `,actionsSeparator:n.css` margin: 0 ${e.spacing(2)}; `,actionIcons:n.css` & > * + * { margin-left: ${e.spacing(.5)}; } `,rulesTable:n.css` margin-top: ${e.spacing(3)}; `});var ee,ae,re,se;const te=e=>{let{namespaces:a,expandAll:r}=e;const s=(0,d.useStyles2)(ne),t=(0,b._)((e=>e.dataSources)),n=(0,b._)((e=>e.promRules)),i=(0,l.useMemo)(S.Eu,[]),o=(0,l.useMemo)((()=>i.filter((e=>{var a,r;return(null===(a=n[e.name])||void 0===a?void 0:a.loading)||(null===(r=t[e.name])||void 0===r?void 0:r.loading)}))),[n,t,i]);return(0,h.jsxs)("section",{className:s.wrapper,children:[(0,h.jsxs)("div",{className:s.sectionHeader,children:[ee||(ee=(0,h.jsx)("h5",{children:"Mimir / Cortex / Loki"})),o.length?(0,h.jsx)(d.LoadingPlaceholder,{className:s.loader,text:`Loading rules from ${o.length} ${j()("source",o.length)}`}):ae||(ae=(0,h.jsx)("div",{}))]}),a.map((e=>{const{groups:a,rulesSource:s}=e;return a.map((a=>(0,h.jsx)(Y,{group:a,namespace:e,expandAll:r},`${(0,S.EG)(s)}-${name}-${a.name}`)))})),0===(null==a?void 0:a.length)&&!!i.length&&(re||(re=(0,h.jsx)("p",{children:"No rules found."}))),!i.length&&(se||(se=(0,h.jsx)("p",{children:"There are no Prometheus or Loki datas sources configured."})))]})},ne=e=>({loader:n.css` margin-bottom: 0; `,sectionHeader:n.css` display: flex; justify-content: space-between; `,wrapper:n.css` margin-bottom: ${e.v1.spacing.xl}; `});var le,ie,oe,ce=r(75678);const de=e=>{let{namespaces:a,expandAll:r}=e;const s=(0,d.useStyles)(ue),[t]=(0,u.K)(),{loading:n}=(0,b._)((e=>e.promRules[S.GC]||E.oq)),l="grouped"===t.view?a:(0,ce.Kd)(a);return(0,h.jsxs)("section",{className:s.wrapper,children:[(0,h.jsxs)("div",{className:s.sectionHeader,children:[le||(le=(0,h.jsx)("h5",{children:"Grafana"})),n?(0,h.jsx)(d.LoadingPlaceholder,{className:s.loader,text:"Loading..."}):ie||(ie=(0,h.jsx)("div",{}))]}),null==l?void 0:l.map((e=>e.groups.map((a=>(0,h.jsx)(Y,{group:a,namespace:e,expandAll:r},`${e.name}-${a.name}`))))),0===(null==l?void 0:l.length)&&(oe||(oe=(0,h.jsx)("p",{children:"No rules found."})))]})},ue=e=>({loader:n.css` margin-bottom: 0; `,sectionHeader:n.css` display: flex; justify-content: space-between; `,wrapper:n.css` margin-bottom: ${e.spacing.xl}; `});var pe=r(39357);const ge=e=>{let{rules:a,state:r,defaultCollapsed:s=!1}=e;const[t,n]=(0,l.useState)(s),i=(0,d.useStyles2)(me);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)("h4",{className:i.header,children:[(0,h.jsx)(T.U,{className:i.collapseToggle,size:"xxl",isCollapsed:t,onToggle:()=>n(!t)}),(0,y.SS)(r)," (",a.length,")"]}),!t&&(0,h.jsx)(Q.i,{className:i.rulesTable,rules:a,showGroupColumn:!0})]})},me=e=>({collapseToggle:n.css` vertical-align: middle; `,header:n.css` margin-top: ${e.spacing(2)}; `,rulesTable:n.css` margin-top: ${e.spacing(3)}; `});var he,xe,ve,je,fe,be=r(82897),Se=r(90747),ye=r(90923);const we=[{icon:"list-ul",label:"List",value:"list"},{icon:"folder",label:"Grouped",value:"grouped"},{icon:"heart-rate",label:"State",value:"state"}],Ce=[{label:"Alert ",value:M.pz.Alerting},{label:"Recording ",value:M.pz.Recording}],Ne=e=>({container:n.css` display: flex; flex-direction: column; padding-bottom: ${e.spacing.sm}; margin-bottom: ${e.spacing.sm}; `,inputWidth:n.css` width: 340px; flex-grow: 0; `,flexRow:n.css` display: flex; flex-direction: row; align-items: flex-end; width: 100%; flex-wrap: wrap; `,spaceBetween:n.css` justify-content: space-between; `,rowChild:n.css` margin: 0 ${e.spacing.sm} 0 0; `,clearButton:n.css` margin-top: ${e.spacing.sm}; `}),Re=()=>{var e;const[a,r]=(0,u.K)(),[s,t]=(0,l.useState)(Math.floor(100*Math.random())),i=`dataSource-${s}`,o=`queryString-${s}`,{dataSource:c,alertState:p,queryString:g,ruleType:m}=(0,pe.lC)(a),x=(0,d.useStyles)(Ne),v=Object.entries(M.x_).map((e=>{let[a,r]=e;return{label:(0,y.SS)(r),value:r}})),j=(0,be.debounce)((e=>{const a=e.target;r({queryString:a.value||null})}),600),f=he||(he=(0,h.jsx)(d.Icon,{name:"search"}));return(0,h.jsxs)("div",{className:x.container,children:[(0,h.jsx)(d.Field,{className:x.inputWidth,label:"Search by data source",children:(0,h.jsx)(ye.DataSourcePicker,{alerting:!0,noDefault:!0,placeholder:"All data sources",current:c,onChange:e=>{r({dataSource:e.name})},onClear:()=>{r({dataSource:null})}},i)}),(0,h.jsxs)("div",{className:(0,n.cx)(x.flexRow,x.spaceBetween),children:[(0,h.jsxs)("div",{className:x.flexRow,children:[(0,h.jsx)(d.Field,{className:x.rowChild,label:xe||(xe=(0,h.jsx)(d.Label,{children:(0,h.jsxs)(Se.Stack,{gap:.5,children:[(0,h.jsx)("span",{children:"Search by label"}),(0,h.jsx)(d.Tooltip,{content:(0,h.jsxs)("div",{children:["Filter rules and alerts using label querying, ex:",(0,h.jsx)("code",{children:'{severity="critical", instance=~"cluster-us-.+"}'})]}),children:(0,h.jsx)(d.Icon,{name:"info-circle",size:"sm"})})]})})),children:(0,h.jsx)(d.Input,{className:x.inputWidth,prefix:f,onChange:j,defaultValue:g,placeholder:"Search","data-testid":"search-query-input"},o)}),(0,h.jsxs)("div",{className:x.rowChild,children:[ve||(ve=(0,h.jsx)(d.Label,{children:"State"})),(0,h.jsx)(d.RadioButtonGroup,{options:v,value:p,onChange:e=>{r({alertState:e})}})]}),(0,h.jsxs)("div",{className:x.rowChild,children:[je||(je=(0,h.jsx)(d.Label,{children:"Rule type"})),(0,h.jsx)(d.RadioButtonGroup,{options:Ce,value:m,onChange:e=>{r({ruleType:e})}})]}),(0,h.jsxs)("div",{className:x.rowChild,children:[fe||(fe=(0,h.jsx)(d.Label,{children:"View as"})),(0,h.jsx)(d.RadioButtonGroup,{options:we,value:String(null!==(e=a.view)&&void 0!==e?e:we[0].value),onChange:e=>{r({view:e})}})]})]}),(c||p||g||m)&&(0,h.jsx)("div",{className:x.flexRow,children:(0,h.jsx)(d.Button,{className:x.clearButton,fullWidth:!1,icon:"times",variant:"secondary",onClick:()=>{r({alertState:null,queryString:null,dataSource:null,ruleType:null}),setTimeout((()=>t(s+1)),100)},children:"Clear filters"})})]})]})};var ke=r(82139);const $e=e=>(a,r)=>{const s=r.groups.reduce(_e(e),[]);return s.length&&a.push(Object.assign({},r,{groups:s})),a},_e=e=>(a,r)=>{const s=r.rules.filter((a=>{var r;if(e.ruleType&&e.ruleType!==(null===(r=a.promRule)||void 0===r?void 0:r.type))return!1;if(e.dataSource&&(0,y.Pc)(a.rulerRule)&&!Fe(a.rulerRule,e))return!1;if(e.queryString){var s;const r=e.queryString.toLocaleLowerCase(),t=null===(s=a.name)||void 0===s?void 0:s.toLocaleLowerCase().includes(r),n=(0,ke.Zh)(e.queryString),l=(0,ke.eD)(a.labels,n),i=a.promRule&&a.promRule.type===M.pz.Alerting&&a.promRule.alerts&&a.promRule.alerts.some((e=>(0,ke.eD)(e.labels,n)));if(!(t||l||i))return!1}return!!(!e.alertState||a.promRule&&(0,y.x_)(a.promRule)&&a.promRule.state===e.alertState)}));return s.length&&a.push(Object.assign({},r,{rules:s})),a},Fe=(e,a)=>!a.dataSource||!!e.grafana_alert.data.find((e=>{if(!e.datasourceUid)return!1;const r=(0,ye.getDataSourceSrv)().getInstanceSettings(e.datasourceUid);return(null==r?void 0:r.name)===a.dataSource}));var Ae,Te,Ge,Ie=r(85464);const Be={groups:e=>{let{namespaces:a,expandAll:r}=e;const[s,t]=(0,l.useMemo)((()=>{const e=a.map((e=>Object.assign({},e,{groups:e.groups.sort(((e,a)=>e.name.localeCompare(a.name)))}))).sort(((e,a)=>e.name.localeCompare(a.name)));return[e.filter((e=>(0,S.HY)(e.rulesSource))),e.filter((e=>(0,S.jq)(e.rulesSource)))]}),[a]);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(k.q,{actions:[R.bW.AlertingRuleRead],children:(0,h.jsx)(de,{namespaces:s,expandAll:r})}),(0,h.jsx)(k.q,{actions:[R.bW.AlertingRuleExternalRead],children:(0,h.jsx)(te,{namespaces:t,expandAll:r})})]})},state:e=>{let{namespaces:a}=e;const r=(0,pe.lC)((0,u.K)()[0]),s=(0,l.useMemo)((()=>{const e={[M.x_.Firing]:[],[M.x_.Inactive]:[],[M.x_.Pending]:[]};return a.forEach((a=>a.groups.forEach((a=>a.rules.forEach((a=>{a.promRule&&(0,y.x_)(a.promRule)&&e[a.promRule.state].push(a)})))))),Object.values(e).forEach((e=>e.sort(((e,a)=>e.name.localeCompare(a.name))))),e}),[a]);return(0,h.jsxs)(h.Fragment,{children:[(!r.alertState||r.alertState===M.x_.Firing)&&(0,h.jsx)(ge,{state:M.x_.Firing,rules:s[M.x_.Firing]}),(!r.alertState||r.alertState===M.x_.Pending)&&(0,h.jsx)(ge,{state:M.x_.Pending,rules:s[M.x_.Pending]}),(!r.alertState||r.alertState===M.x_.Inactive)&&(0,h.jsx)(ge,{defaultCollapsed:r.alertState!==M.x_.Inactive,state:M.x_.Inactive,rules:s[M.x_.Inactive]})]})}},Ee=(0,d.withErrorBoundary)((()=>{const e=(0,i.useDispatch)(),a=(0,d.useStyles2)(Le),r=(0,l.useMemo)(S.mA,[]),s=(0,o.TH)(),[t,n]=(0,l.useState)(!1),[g]=(0,u.K)(),v=(0,pe.lC)(g),j=Object.values(v).some((e=>void 0!==e)),{canCreateGrafanaRules:f,canCreateCloudRules:y}=(0,m.B)(),C=Be[g.view]?g.view:"groups",N=Be[C];(0,l.useEffect)((()=>{e((0,A.ei)());const a=setInterval((()=>e((0,A.ei)())),Ie.p4);return()=>{clearInterval(a)}}),[e]);const R=(0,b._)((e=>e.promRules)),k=(0,b._)((e=>e.rulerRules)),$=r.some((e=>{var a,r;return(null===(a=R[e])||void 0===a?void 0:a.dispatched)||(null===(r=k[e])||void 0===r?void 0:r.dispatched)})),_=r.some((e=>{var a,r;return(null===(a=R[e])||void 0===a?void 0:a.loading)||(null===(r=k[e])||void 0===r?void 0:r.loading)})),F=r.some((e=>{var a,r,s,t,n;return(null===(a=R[e])||void 0===a||null===(r=a.result)||void 0===r?void 0:r.length)&&!(null!==(s=R[e])&&void 0!==s&&s.error)||Object.keys((null===(t=k[e])||void 0===t?void 0:t.result)||{}).length&&!(null!==(n=k[e])&&void 0!==n&&n.error)})),T=$&&!_&&!F,G=(e=>{const[a]=(0,u.K)(),r=(0,pe.lC)(a);return(0,l.useMemo)((()=>e.filter((e=>{let{rulesSource:a}=e;return!r.dataSource||!(0,S.jq)(a)||a.name===r.dataSource})).reduce($e(r),[])),[e,r])})((0,ce.Zo)());return(0,h.jsxs)(p.J,{pageId:"alert-list",isLoading:_&&!F,children:[Ae||(Ae=(0,h.jsx)(w,{})),!T&&(0,h.jsxs)(h.Fragment,{children:[Te||(Te=(0,h.jsx)(Re,{})),(0,h.jsx)("div",{className:a.break}),(0,h.jsxs)("div",{className:a.buttonsContainer,children:[(0,h.jsxs)("div",{className:a.statsContainer,children:["groups"===C&&j&&(0,h.jsx)(d.Button,{className:a.expandAllButton,icon:t?"angle-double-up":"angle-double-down",variant:"secondary",onClick:()=>n(!t),children:t?"Collapse all":"Expand all"}),(0,h.jsx)(V,{showInactive:!0,showRecording:!0,namespaces:G})]}),(f||y)&&(0,h.jsx)(d.LinkButton,{href:c.urlUtil.renderUrl("alerting/new",{returnTo:s.pathname+s.search}),icon:"plus",children:"New alert rule"})]})]}),T&&(Ge||(Ge=(0,h.jsx)(x,{}))),F&&(0,h.jsx)(N,{expandAll:t,namespaces:G})]})}),{style:"page"}),Le=e=>({break:n.css` width: 100%; height: 0; margin-bottom: ${e.spacing(2)}; border-bottom: solid 1px ${e.colors.border.medium}; `,buttonsContainer:n.css` margin-bottom: ${e.spacing(2)}; display: flex; justify-content: space-between; `,statsContainer:n.css` display: flex; flex-direction: row; align-items: center; `,expandAllButton:n.css` margin-right: ${e.spacing(1)}; `}),Oe=Ee},40256:(e,a,r)=>{r.d(a,{J:()=>i});r(68404);var s=r(18745),t=r(33801),n=r(8674),l=r(45916);const i=e=>{let{children:a,pageId:r,isLoading:i}=e;const o=(0,n.h)((0,s.useSelector)((e=>e.navIndex)),r);return(0,l.jsx)(t.Z,{navModel:o,children:(0,l.jsx)(t.Z.Contents,{isLoading:i,children:a})})}},53262:(e,a,r)=>{r.d(a,{q:()=>n});r(68404);var s=r(61959),t=r(45916);const n=e=>{let{actions:a,children:r,fallback:n=!0}=e;return a.some((e=>s.Vt.hasAccess(e,n)))?(0,t.jsx)(t.Fragment,{children:r}):null}},29e3:(e,a,r)=>{r.d(a,{F:()=>o});var s=r(36636),t=(r(68404),r(69783)),n=r(9019),l=r(45916);const i=["renderExpandedContent"];const o=e=>{let{renderExpandedContent:a}=e,r=function(e,a){if(null==e)return{};var r,s,t={},n=Object.keys(e);for(s=0;s=0||(t[r]=e[r]);return t}(e,i);const o=(0,t.useStyles2)(c);return(0,l.jsx)(n.t,Object.assign({renderExpandedContent:a?(e,r,t)=>(0,l.jsxs)(l.Fragment,{children:[!(r===t.length-1)&&(0,l.jsx)("div",{className:(0,s.cx)(o.contentGuideline,o.guideline)}),a(e,r,t)]}):void 0,renderPrefixHeader:()=>(0,l.jsx)("div",{className:o.relative,children:(0,l.jsx)("div",{className:(0,s.cx)(o.headerGuideline,o.guideline)})}),renderPrefixCell:(e,a,r)=>(0,l.jsxs)("div",{className:o.relative,children:[(0,l.jsx)("div",{className:(0,s.cx)(o.topGuideline,o.guideline)}),!(a===r.length-1)&&(0,l.jsx)("div",{className:(0,s.cx)(o.bottomGuideline,o.guideline)})]})},r))},c=e=>({relative:s.css` position: relative; height: 100%; `,guideline:s.css` left: -19px; border-left: 1px solid ${e.colors.border.medium}; position: absolute; ${e.breakpoints.down("md")} { display: none; } `,topGuideline:s.css` width: 18px; border-bottom: 1px solid ${e.colors.border.medium}; top: 0; bottom: 50%; `,bottomGuideline:s.css` top: 50%; bottom: 0; `,contentGuideline:s.css` top: 0; bottom: 0; left: -49px !important; `,headerGuideline:s.css` top: -25px; bottom: 0; `})},85598:(e,a,r)=>{r.d(a,{V:()=>l});r(68404);var s,t=r(69783),n=r(45916);const l=e=>{let{namespace:a,group:r}=e;return r?(0,n.jsxs)(n.Fragment,{children:[a," ",s||(s=(0,n.jsx)(t.Icon,{name:"angle-right"}))," ",r]}):(0,n.jsx)(n.Fragment,{children:a})}},3799:(e,a,r)=>{r.d(a,{A:()=>l});r(68404);var s=r(69783),t=r(45916);const n=["tooltip","icon","to","target","onClick","className","tooltipPlacement"];const l=e=>{let{tooltip:a,icon:r,to:l,target:i,onClick:o,className:c,tooltipPlacement:d="top"}=e,u=function(e,a){if(null==e)return{};var r,s,t={},n=Object.keys(e);for(s=0;s=0||(t[r]=e[r]);return t}(e,n);const p="string"==typeof a?a:void 0;return(0,t.jsx)(s.Tooltip,{content:a,placement:d,children:l?(0,t.jsx)(s.LinkButton,Object.assign({variant:"secondary",fill:"text",icon:r,href:l,size:"sm",target:i},u,{"aria-label":p})):(0,t.jsx)(s.Button,Object.assign({className:c,variant:"secondary",fill:"text",size:"sm",icon:r,type:"button",onClick:o},u,{"aria-label":p}))})}},86692:(e,a,r)=>{r.d(a,{i:()=>w});var s=r(36636),t=r(68404),n=r(69783),l=r(26980),i=r(85464),o=r(9019),c=r(29e3),d=r(85598),u=r(94322),p=r(52510),g=r(83039),m=r(97292),h=r(79842),x=r(85351),v=r(12135),j=r(45916);const f=e=>{let{rule:a}=e;const r=(0,n.useStyles2)(b),{namespace:{rulesSource:s}}=a,t=Object.entries(a.annotations).filter((e=>{let[a,r]=e;return!!r.trim()}));return(0,j.jsxs)("div",{children:[(0,j.jsx)(g.f,{rule:a,rulesSource:s}),(0,j.jsxs)("div",{className:r.wrapper,children:[(0,j.jsxs)("div",{className:r.leftSide,children:[!!a.labels&&!!Object.keys(a.labels).length&&(0,j.jsx)(p.C,{label:"Labels",horizontal:!0,children:(0,j.jsx)(u.s,{labels:a.labels})}),(0,j.jsx)(x.C,{rulesSource:s,rule:a,annotations:t}),(0,j.jsx)(m.J,{annotations:t})]}),(0,j.jsx)("div",{className:r.rightSide,children:(0,j.jsx)(h.C,{rulesSource:s,rule:a})})]}),(0,j.jsx)(v.M,{rule:a})]})},b=e=>({wrapper:s.css` display: flex; flex-direction: row; ${e.breakpoints.down("md")} { flex-direction: column; } `,leftSide:s.css` flex: 1; `,rightSide:s.css` ${e.breakpoints.up("md")} { padding-left: 90px; width: 300px; } `});var S=r(82434),y=r(18181);const w=e=>{let{rules:a,className:r,showGuidelines:u=!1,emptyMessage:p="No rules found.",showGroupColumn:g=!1,showSummaryColumn:m=!1}=e;const h=(0,n.useStyles2)(C),x=(0,s.cx)(h.wrapper,r,{[h.wrapperMargin]:u}),v=(0,t.useMemo)((()=>{const e=[];return a.map(((a,r)=>{var s;let t=JSON.stringify([null===(s=a.promRule)||void 0===s?void 0:s.type,a.labels,a.query,a.name,a.annotations]);return e.includes(t)&&(t+=`-${r}`),e.push(t),{id:t,data:a}}))}),[a]),b=function(e,a){const{hasRuler:r,rulerRulesLoaded:s}=(0,l.h)();return(0,t.useMemo)((()=>{const t=[{id:"state",label:"State",renderCell:e=>{let{data:a}=e;const{namespace:t}=a,{rulesSource:n}=t,{promRule:l,rulerRule:i}=a,o=!(!(r(n)&&s(n)&&l)||i),c=!(!(r(n)&&s(n)&&i)||l);return(0,j.jsx)(y.p,{rule:a,isDeleting:o,isCreating:c})},size:"165px"},{id:"name",label:"Name",renderCell:e=>{let{data:a}=e;return a.name},size:5},{id:"health",label:"Health",renderCell:e=>{let{data:{promRule:a}}=e;return a?(0,j.jsx)(S.V,{rule:a}):null},size:"75px"}];return e&&t.push({id:"summary",label:"Summary",renderCell:e=>{var a;let{data:r}=e;return null!==(a=r.annotations[i.q6.summary])&&void 0!==a?a:""},size:5}),a&&t.push({id:"group",label:"Group",renderCell:e=>{let{data:a}=e;const{namespace:r,group:s}=a;return"default"===s.name?(0,j.jsx)(d.V,{namespace:r.name}):(0,j.jsx)(d.V,{namespace:r.name,group:s.name})},size:5}),t}),[r,s,e,a])}(m,g);if(!a.length)return(0,j.jsx)("div",{className:(0,s.cx)(x,h.emptyMessage),children:p});const w=u?c.F:o.t;return(0,j.jsx)("div",{className:x,"data-testid":"rules-table",children:(0,j.jsx)(w,{cols:b,isExpandable:!0,items:v,renderExpandedContent:e=>{let{data:a}=e;return(0,j.jsx)(f,{rule:a})}})})},C=e=>({wrapperMargin:s.css` ${e.breakpoints.up("md")} { margin-left: 36px; } `,emptyMessage:s.css` padding: ${e.spacing(1)}; `,wrapper:s.css` width: auto; background-color: ${e.colors.background.secondary}; border-radius: ${e.shape.borderRadius()}; `})},26980:(e,a,r)=>{r.d(a,{h:()=>l});var s=r(68404),t=r(19462),n=r(33899);function l(){const e=(0,n._)((e=>e.rulerRules));return{hasRuler:(0,s.useCallback)((a=>{var r;const s="string"==typeof a?a:a.name;return s===t.GC||!(null===(r=e[s])||void 0===r||!r.result)}),[e]),rulerRulesLoaded:(0,s.useCallback)((a=>{var r;const s=(0,t.EG)(a),n=null===(r=e[s])||void 0===r?void 0:r.result;return Boolean(n)}),[e])}}},69450:(e,a,r)=>{r.d(a,{B:()=>n});var s=r(68404),t=r(82969);function n(){return(0,s.useMemo)((()=>(0,t.Rv)()),[])}}}]); //# sourceMappingURL=AlertRuleListIndex.9cec8b2b3fa934d35f27.js.map