"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4286],{10029:(e,a,t)=>{t.r(a),t.d(a,{AlertRuleListUnconnected:()=>B,default:()=>T});var n,r=t(68404),s=t(18745),i=t(90923),l=t(69783),o=t(5831),c=t(33801),d=t(8674),u=t(21169),h=t(45916);function g(e){let{onDismiss:a}=e;return(0,h.jsx)(l.Modal,{title:"Adding an Alert",isOpen:!0,onDismiss:a,onClickBackdrop:a,children:n||(n=(0,h.jsxs)(l.VerticalGroup,{spacing:"sm",children:[(0,h.jsx)("img",{src:"public/img/alert_howto_new.png",alt:"link to how to alert image"}),(0,h.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,h.jsx)("p",{children:"Remember to save the dashboard to persist your alert rule changes."})]}))})}var p=t(9575),f=t.n(p);const x=e=>{let{rule:a,search:t,onTogglePause:n}=e;const s=`${a.url}?editPanel=${a.panelId}&tab=alert`,i=(0,r.useCallback)((e=>(0,h.jsx)(f(),{highlightClassName:"highlight-search-match",textToHighlight:e,searchWords:[t]},e)),[t]);return(0,h.jsxs)(l.Card,{children:[(0,h.jsx)(l.Card.Heading,{children:i(a.name)}),(0,h.jsx)(l.Card.Figure,{children:(0,h.jsx)(l.Icon,{size:"xl",name:a.stateIcon,className:`alert-rule-item__icon ${a.stateClass}`})}),(0,h.jsxs)(l.Card.Meta,{children:[(0,h.jsxs)("span",{children:[(0,h.jsxs)("span",{className:`${a.stateClass}`,children:[i(a.stateText)," "]},"text"),"for ",a.stateAge]},"state"),a.info?i(a.info):null]}),(0,h.jsxs)(l.Card.Actions,{children:[(0,h.jsx)(l.Button,{variant:"secondary",icon:"paused"===a.state?"play":"pause",onClick:n,children:"paused"===a.state?"Resume":"Pause"},"play"),(0,h.jsx)(l.LinkButton,{variant:"secondary",href:s,icon:"cog",children:"Edit alert"},"edit")]})]})};var v;const m=()=>v||(v=(0,h.jsxs)(l.Alert,{severity:"warning",title:"Grafana legacy alerting is going away soon",children:[(0,h.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,h.jsx)("br",{}),"We encourage you to upgrade to the new Grafana alerting experience."]}),(0,h.jsxs)("p",{children:["See"," ",(0,h.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,h.jsx)("a",{href:"https://grafana.com/docs/grafana/latest/alerting/unified-alerting/opt-in/",children:"how to enable the new Grafana alerting feature"}),"."]})]}));var j=t(9191),y=t(61988);const b=e=>e.searchQuery,w=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 S,C,A,k;function R(e,a,t){return a in e?Object.defineProperty(e,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[a]=t,e}const N={getAlertRulesAsync:j.Au,setSearchQuery:y.ql,togglePauseAlertRule:j.en},P=(0,s.connect)((function(e){return{navModel:(0,d.h)(e.navIndex,"alert-list"),alertRules:w(e),search:b(e.alertRules),isLoading:e.alertRules.isLoading}}),N);class B extends r.PureComponent{constructor(){super(...arguments),R(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"}]),R(this,"onStateFilterChanged",(e=>{i.locationService.partial({state:e.value})})),R(this,"onOpenHowTo",(()=>{o.Z.publish(new u.Dn({component:g}))})),R(this,"onSearchQueryChange",(e=>{this.props.setSearchQuery(e)})),R(this,"onTogglePause",(e=>{this.props.togglePauseAlertRule(e.id,{paused:"paused"!==e.state})})),R(this,"alertStateFilterOption",(e=>{let{text:a,value:t}=e;return(0,h.jsx)("option",{value:t,children:a},t)}))}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:t,isLoading:n}=this.props;return(0,h.jsx)(c.Z,{navModel:e,children:(0,h.jsxs)(c.Z.Contents,{isLoading:n,children:[(0,h.jsxs)("div",{className:"page-action-bar",children:[(0,h.jsx)("div",{className:"gf-form gf-form--grow",children:(0,h.jsx)(l.FilterInput,{placeholder:"Search alerts",value:t,onChange:this.onSearchQueryChange})}),(0,h.jsxs)("div",{className:"gf-form",children:[S||(S=(0,h.jsx)("label",{className:"gf-form-label",htmlFor:"alert-state-filter",children:"States"})),(0,h.jsx)("div",{className:"width-13",children:(0,h.jsx)(l.Select,{inputId:"alert-state-filter",options:this.stateFilters,onChange:this.onStateFilterChanged,value:this.getStateFilter()})})]}),C||(C=(0,h.jsx)("div",{className:"page-action-bar__spacer"})),i.config.unifiedAlertingEnabled&&(A||(A=(0,h.jsx)(l.LinkButton,{variant:"primary",href:"alerting/ng/new",children:"Add NG Alert"}))),(0,h.jsx)(l.Button,{variant:"secondary",onClick:this.onOpenHowTo,children:"How to add an alert"})]}),k||(k=(0,h.jsx)(m,{})),(0,h.jsx)(l.VerticalGroup,{spacing:"none",children:a.map((e=>(0,h.jsx)(x,{rule:e,search:t,onTogglePause:()=>this.onTogglePause(e)},e.id)))})]})})}}const T=P(B)},9191:(e,a,t)=>{t.d(a,{Au:()=>l,C2:()=>c,c1:()=>u,en:()=>o,fA:()=>h,fg:()=>d,tk:()=>g});var n=t(90923),r=t(36537),s=t(58257),i=t(61988);function l(e){return async a=>{a((0,i.gz)());const t=await(0,n.getBackendSrv)().get("/api/alerts",e);a((0,i.Oc)(t))}}function o(e,a){return async t=>{await(0,n.getBackendSrv)().post(`/api/alerts/${e}/pause`,a);t(l({state:(n.locationService.getSearchObject().state||"all").toString()}))}}function c(e){return async a=>{try{await(0,n.getBackendSrv)().post("/api/alert-notifications",e),a((0,r.$l)((0,s.AT)("Notification created"))),n.locationService.push("/alerting/notifications")}catch(e){a((0,r.$l)((0,s.t_)(e.data.error)))}}}function d(e){return async a=>{try{await(0,n.getBackendSrv)().put(`/api/alert-notifications/${e.id}`,e),a((0,r.$l)((0,s.AT)("Notification updated")))}catch(e){a((0,r.$l)((0,s.t_)(e.data.error)))}}}function u(e){return async(a,t)=>{const r=t().notificationChannel.notificationChannel;await(0,n.getBackendSrv)().post("/api/alert-notifications/test",Object.assign({id:r.id},e))}}function h(){return async e=>{const a=(await(0,n.getBackendSrv)().get("/api/alert-notifiers")).sort(((e,a)=>e.name>a.name?1:-1));e((0,i.T2)(a))}}function g(e){return async a=>{await a(h());const t=await(0,n.getBackendSrv)().get(`/api/alert-notifications/${e}`);a((0,i.K)(t))}}}}]); //# sourceMappingURL=AlertRuleList.127ffbe22c8c11985cdc.js.map