1234567 |
- "use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[476],{77264:(e,t,n)=>{n.r(t),n.d(t,{default:()=>b});var r,s=n(68404),i=n(18745),a=n(90923),l=n(69783),o=n(33801),c=n(8674),d=n(51114),u=n(9191),p=n(61988),g=n(97130),h=n(45916);function f(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class m extends s.PureComponent{constructor(){super(...arguments),f(this,"onSubmit",(e=>{this.props.createNotificationChannel((0,g.YV)(Object.assign({},g.Pg,e)))})),f(this,"onTestChannel",(e=>{this.props.testNotificationChannel((0,g.dv)(Object.assign({},g.Pg,e)))}))}componentDidMount(){this.props.loadNotificationTypes()}render(){const{navModel:e,notificationChannelTypes:t}=this.props;return(0,h.jsx)(o.Z,{navModel:e,children:(0,h.jsxs)(o.Z.Contents,{children:[r||(r=(0,h.jsx)("h2",{className:"page-sub-heading",children:"New notification channel"})),(0,h.jsx)(l.Form,{onSubmit:this.onSubmit,validateOn:"onChange",defaultValues:g.Pg,maxWidth:600,children:e=>{let{register:n,errors:r,control:s,getValues:i,watch:l}=e;const o=t.find((e=>e.value===i().type.value));return(0,h.jsx)(d.w,{selectableChannels:(0,g.t7)(t,!0),selectedChannel:o,onTestChannel:this.onTestChannel,register:n,errors:r,getValues:i,control:s,watch:l,imageRendererAvailable:a.config.rendererAvailable,resetSecureField:this.props.resetSecureField,secureFields:{}})}})]})})}}const v={createNotificationChannel:u.C2,loadNotificationTypes:u.fA,testNotificationChannel:u.c1,resetSecureField:p.J0},b=(0,i.connect)((e=>({navModel:(0,c.h)(e.navIndex,"channels"),notificationChannelTypes:e.notificationChannel.notificationChannelTypes})),v)(m)},51114:(e,t,n)=>{n.d(t,{w:()=>x});var r=n(36636),s=n(68404),i=n(69783),a=n(78837),l=n(45916);const o=["ref"];const c=e=>{let{control:t,option:n,register:r,invalid:s}=e;const a=n.secure?`secureSettings.${n.propertyName}`:`settings.${n.propertyName}`;switch(n.element){case"input":return(0,l.jsx)(i.Input,Object.assign({},r(`${a}`,{required:!!n.required&&"Required",validate:e=>""===n.validationRule||d(e,n.validationRule)}),{invalid:s,type:n.inputType,placeholder:n.placeholder}));case"select":return(0,l.jsx)(i.InputControl,{control:t,name:`${a}`,render:e=>{var t;let{}=e,r=function(e,t){if(null==e)return{};var n,r,s={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(s[n]=e[n]);return s}(e.field,o);return(0,l.jsx)(i.Select,Object.assign({},r,{options:null!==(t=n.selectOptions)&&void 0!==t?t:void 0,invalid:s}))}});case"textarea":return(0,l.jsx)(i.TextArea,Object.assign({invalid:s},r(`${a}`,{required:!!n.required&&"Required",validate:e=>""===n.validationRule||d(e,n.validationRule)})));default:return console.error("Element not supported",n.element),null}},d=(e,t)=>!!RegExp(t).test(e)||"Invalid format",u=e=>{let{control:t,currentFormValues:n,errors:r,selectedChannelOptions:s,register:a,onResetSecureField:o,secureFields:d}=e;return(0,l.jsx)(l.Fragment,{children:s.map(((e,s)=>{var u;const p=`${e.label}-${s}`,g=n[`settings.${e.showWhen.field}`]&&n[`settings.${e.showWhen.field}`].value;return e.showWhen.field&&g!==e.showWhen.is?null:"checkbox"===e.element?(0,l.jsx)(i.Field,{children:(0,l.jsx)(i.Checkbox,Object.assign({},a(e.secure?`secureSettings.${e.propertyName}`:`settings.${e.propertyName}`),{label:e.label,description:e.description}))},p):(0,l.jsx)(i.Field,{label:e.label,description:e.description,invalid:r.settings&&!!r.settings[e.propertyName],error:r.settings&&(null===(u=r.settings[e.propertyName])||void 0===u?void 0:u.message),children:d&&d[e.propertyName]?(0,l.jsx)(i.Input,{readOnly:!0,value:"Configured",suffix:(0,l.jsx)(i.Button,{onClick:()=>o(e.propertyName),fill:"text",type:"button",size:"sm",children:"Clear"})}):(0,l.jsx)(c,{option:e,register:a,control:t})},p)}))})},p=["ref"];const g=e=>{let{control:t,currentFormValues:n,errors:r,secureFields:s,selectedChannel:a,channels:o,register:c,resetSecureField:d}=e;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(i.Field,{label:"Name",invalid:!!r.name,error:r.name&&r.name.message,children:(0,l.jsx)(i.Input,Object.assign({},c("name",{required:"Name is required"})))}),(0,l.jsx)(i.Field,{label:"Type",children:(0,l.jsx)(i.InputControl,{name:"type",render:e=>{let{}=e,t=function(e,t){if(null==e)return{};var n,r,s={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(s[n]=e[n]);return s}(e.field,p);return(0,l.jsx)(i.Select,Object.assign({},t,{options:o}))},control:t,rules:{required:!0}})}),(0,l.jsx)(u,{selectedChannelOptions:a.options.filter((e=>e.required)),currentFormValues:n,secureFields:s,onResetSecureField:d,register:c,errors:r,control:t})]})},h=e=>{var t;let{control:n,currentFormValues:r,errors:s,selectedChannel:a,secureFields:o,register:c,resetSecureField:d}=e;return(0,l.jsxs)(i.CollapsableSection,{label:`Optional ${a.heading}`,isOpen:!1,children:[""!==a.info&&(0,l.jsx)(i.Alert,{severity:"info",title:null!==(t=a.info)&&void 0!==t?t:""}),(0,l.jsx)(u,{selectedChannelOptions:a.options.filter((e=>!e.required)),currentFormValues:r,register:c,errors:s,control:n,onResetSecureField:d,secureFields:o})]})};var f;const m=e=>{let{currentFormValues:t,imageRendererAvailable:n,register:r}=e;return(0,l.jsxs)(i.CollapsableSection,{label:"Notification settings",isOpen:!1,children:[(0,l.jsx)(i.Field,{children:(0,l.jsx)(i.Checkbox,Object.assign({},r("isDefault"),{label:"Default",description:"Use this notification for all alerts"}))}),(0,l.jsx)(i.Field,{children:(0,l.jsx)(i.Checkbox,Object.assign({},r("settings.uploadImage"),{label:"Include image",description:"Captures an image and include it in the notification"}))}),t.uploadImage&&!n&&(f||(f=(0,l.jsx)(i.InfoBox,{title:"No image renderer available/installed",children:"Grafana cannot find an image renderer to capture an image for the notification. Please make sure the Grafana Image Renderer plugin is installed. Please contact your Grafana administrator to install the plugin."}))),(0,l.jsx)(i.Field,{children:(0,l.jsx)(i.Checkbox,Object.assign({},r("disableResolveMessage"),{label:"Disable Resolve Message",description:"Disable the resolve message [OK] that is sent when alerting state returns to false"}))}),(0,l.jsx)(i.Field,{children:(0,l.jsx)(i.Checkbox,Object.assign({},r("sendReminder"),{label:"Send reminders",description:"Send additional notifications for triggered alerts"}))}),t.sendReminder&&(0,l.jsx)(l.Fragment,{children:(0,l.jsx)(i.Field,{label:"Send reminder every",description:"Specify how often reminders should be sent, e.g. every 30s, 1m, 10m, 30m', or 1h etc. Alert reminders are sent after rules are evaluated. A reminder can never be sent more frequently than a configured alert rule evaluation interval.",children:(0,l.jsx)(i.Input,Object.assign({},r("frequency"),{width:8}))})})]})};var v,b,j;const x=e=>{let{control:t,errors:n,selectedChannel:r,selectableChannels:o,register:c,watch:d,getValues:u,imageRendererAvailable:p,onTestChannel:f,resetSecureField:x,secureFields:C}=e;const S=y((0,i.useTheme)());(0,s.useEffect)((()=>{const e=new Set(null==r?void 0:r.options.filter((e=>e.showWhen.field)).map((e=>`settings.${e.showWhen.field}`)))||[];d(["type","sendReminder","uploadImage",...e])}),[null==r?void 0:r.options,d]);const F=u();return r?(0,l.jsxs)("div",{className:S.formContainer,children:[(0,l.jsx)("div",{className:S.formItem,children:(0,l.jsx)(g,{selectedChannel:r,channels:o,secureFields:C,resetSecureField:x,currentFormValues:F,register:c,errors:n,control:t})}),r.options.filter((e=>!e.required)).length>0&&(0,l.jsx)("div",{className:S.formItem,children:(0,l.jsx)(h,{selectedChannel:r,secureFields:C,resetSecureField:x,currentFormValues:F,register:c,errors:n,control:t})}),(0,l.jsx)("div",{className:S.formItem,children:(0,l.jsx)(m,{imageRendererAvailable:p,currentFormValues:F,register:c,errors:n,control:t})}),(0,l.jsx)("div",{className:S.formButtons,children:(0,l.jsxs)(i.HorizontalGroup,{children:[b||(b=(0,l.jsx)(i.Button,{type:"submit",children:"Save"})),(0,l.jsx)(i.Button,{type:"button",variant:"secondary",onClick:()=>f(u()),children:"Test"}),(0,l.jsx)("a",{href:`${a.ZP.appSubUrl}/alerting/notifications`,children:j||(j=(0,l.jsx)(i.Button,{type:"button",variant:"secondary",children:"Back"}))})]})})]}):v||(v=(0,l.jsx)(i.Spinner,{}))},y=(0,i.stylesFactory)((e=>({formContainer:r.css``,formItem:r.css`
- flex-grow: 1;
- padding-top: ${e.spacing.md};
- `,formButtons:r.css`
- padding-top: ${e.spacing.xl};
- `})))},9191:(e,t,n)=>{n.d(t,{Au:()=>l,C2:()=>c,c1:()=>u,en:()=>o,fA:()=>p,fg:()=>d,tk:()=>g});var r=n(90923),s=n(36537),i=n(58257),a=n(61988);function l(e){return async t=>{t((0,a.gz)());const n=await(0,r.getBackendSrv)().get("/api/alerts",e);t((0,a.Oc)(n))}}function o(e,t){return async n=>{await(0,r.getBackendSrv)().post(`/api/alerts/${e}/pause`,t);n(l({state:(r.locationService.getSearchObject().state||"all").toString()}))}}function c(e){return async t=>{try{await(0,r.getBackendSrv)().post("/api/alert-notifications",e),t((0,s.$l)((0,i.AT)("Notification created"))),r.locationService.push("/alerting/notifications")}catch(e){t((0,s.$l)((0,i.t_)(e.data.error)))}}}function d(e){return async t=>{try{await(0,r.getBackendSrv)().put(`/api/alert-notifications/${e.id}`,e),t((0,s.$l)((0,i.AT)("Notification updated")))}catch(e){t((0,s.$l)((0,i.t_)(e.data.error)))}}}function u(e){return async(t,n)=>{const s=n().notificationChannel.notificationChannel;await(0,r.getBackendSrv)().post("/api/alert-notifications/test",Object.assign({id:s.id},e))}}function p(){return async e=>{const t=(await(0,r.getBackendSrv)().get("/api/alert-notifiers")).sort(((e,t)=>e.name>t.name?1:-1));e((0,a.T2)(t))}}function g(e){return async t=>{await t(p());const n=await(0,r.getBackendSrv)().get(`/api/alert-notifications/${e}`);t((0,a.K)(n))}}},97130:(e,t,n)=>{n.d(t,{Pg:()=>s,YV:()=>a,dv:()=>l,t7:()=>i});var r=n(58635);const s={id:-1,name:"",type:{value:"email",label:"Email"},sendReminder:!1,disableResolveMessage:!1,frequency:"15m",settings:{uploadImage:n(90923).config.rendererAvailable,autoResolve:!0,httpMethod:"POST",severity:"critical"},secureSettings:{},secureFields:{},isDefault:!1},i=(0,r.Z)(((e,t)=>e.map((e=>t?{value:e.value,label:e.label,description:e.description}:{value:e.value,label:e.label})))),a=e=>{const t=Object.fromEntries(Object.entries(e.settings).map((e=>{let[t,n]=e;return[t,n&&n.hasOwnProperty("value")?n.value:n]})));return Object.assign({},s,e,{frequency:""===e.frequency?s.frequency:e.frequency,type:e.type.value,settings:Object.assign({},s.settings,t),secureSettings:Object.assign({},e.secureSettings)})},l=e=>{var t;return{name:e.name,type:e.type.value,frequency:null!==(t=e.frequency)&&void 0!==t?t:s.frequency,settings:Object.assign({},Object.assign(s.settings,e.settings)),secureSettings:Object.assign({},e.secureSettings)}}}}]);
- //# sourceMappingURL=NewNotificationChannel.f5e783ccddea5ec5863c.js.map
|