!function(e){function t(e,t){var o=new Date(e);return t.max-t.min<=864e5?(o.getHours()<10?"0":"")+o.getHours()+":"+(o.getMinutes()<10?"0":"")+o.getMinutes():o.getDate()+"."+(o.getMonth()+1)+"."+o.getFullYear()}e(document).ajaxError((function(e,t,o,s){MMONIT.error.json(t,s)}));var o=new function(){var o=this;o.timeout=null,o.loadErrors=0,o.issues=ko.observableArray(),o.issuesTotal=ko.observable(),o.showwelcome=ko.observable(!1),o.welcome=ko.observable(e("#showwelcome").val()),o.dismissEvent=function(t){e.post("reports/events/dismiss","id="+t.eventid,(function(e){o.issues.remove(t),o.issuesTotal(o.issuesTotal()-1),o.issues().length<1&&o.issuesTotal()&&o.load()}))},o.closeWelcome=function(){!1===o.welcome()?e.post("index.csp","dismiss=1"):o.showwelcome()&&e.post("session/put","welcome=0"),e("#welcome").hide()},o.reload=function(){var t=e.Deferred();return clearTimeout(o.timeout),o.timeout=setTimeout((function(){o.load(),t.resolve()}),1e4),t.promise()},o.load=function(){e.when(e.getJSON("status/hosts/summary"),e.getJSON("reports/events/summary"),e.getJSON("reports/events/list?active=2")).then(((i,n,r)=>{var a;document.querySelector("[rel=icon]").href=`img/ico/led${i[0].system}.ico`,function(t){for(var o=t.status.length?t.status:[{label:"No hosts",data:[[1,1]]}],s=0,i=0;i<o.length;i++)o[i].data&&s++;e.plot(e("#status"),o,{series:{pie:{show:!0,stroke:{width:0},radius:.99,highlight:{opacity:0},label:{show:!0,radius:s>1?.6:0,threshold:.05,formatter:function(e,t){return'<div style="font-size:10pt;text-align:center;color:white;">'+e+"<br/>"+Math.round(t.percent)+"%</div>"}}}},grid:{hoverable:!0,clickable:!0,autoHighlight:!1},colors:t.status.length?["#C0392B","#E74C3C","#F39C12","#2ECC71","#bec3c7","#95a4a7"]:["#95a4a7"],legend:{show:!1}})}(i[0]),a=n[0],e.each(a.events,(function(t,o){e.each(o.data,(function(e,t){t[0]*=1e3}))})),e.plot(e("#events"),a.events,{series:{stack:!0,lines:{show:!1},bars:{show:!0,fill:!0,lineWidth:0,barWidth:6e5,align:"center",fillColor:{colors:[{opacity:1},{opacity:1}]}},points:{show:!1}},colors:["#E74C3C","#F39C12","#2ECC71"],xaxis:{tickLength:0,min:1e3*a.datefrom,max:1e3*a.dateto,tickFormatter:t},yaxis:{min:0,tickDecimals:0,minTickSize:1},legend:{show:!1},grid:{borderWidth:0,autoHighlight:!1,hoverable:!0,clickable:!0,mouseActiveRadius:5}}),e("#events").on("plothover",{suffix:" events",data:a.events},MMONIT.chart.setTooltip),o.issues.removeAll(),e.each(r[0].records,(function(e,t){o.issues.push(new s(t))})),o.issuesTotal(r[0].totalRecords),MMONIT.error.ishidden()||MMONIT.error.hide()})).then(o.reload())};var s=function(e){var t=this;t.date=strftime("%b %d %Y %H:%M:%S",new Date(1e3*e.date)),t.host=e.hostname,t.hostid=e.hostid,t.service=e.servicename,t.eventid=e.id,t.servicenameid=e.servicenameid,t.type=e.eventtype,t.description=e.event};!0!==o.welcome()&&"1"!=o.welcome()||e.getJSON("session/get?key=welcome",(function(e){void 0!==e.welcome&&"0"==e.welcome||o.showwelcome(!0)})),e.ajaxSetup({timeout:3e4}),o.load()};ko.applyBindings(o),e("#statusbox").on("click",(function(e,t,o){return window.location="status/hosts/",!1})),e("#eventsbox").on("click",(function(e,t,o){return window.location="reports/events/",!1}))}(jQuery);