!function(e){function t(e,t){var s=new Date(e);return t.max-t.min<=864e5?(s.getHours()<10?"0":"")+s.getHours()+":"+(s.getMinutes()<10?"0":"")+s.getMinutes():s.getDate()+"."+(s.getMonth()+1)+"."+s.getFullYear()}e(document).ajaxError((function(e,t,s,i){MMONIT.error.json(t,i)}));var s=new function(){var s=this;s.timeout=null,s.loadErrors=0,s.issues=ko.observableArray(),s.issuesTotal=ko.observable(),s.dismissEvent=function(t){e.post("reports/events/dismiss","id="+t.eventid,(function(e){s.issues.remove(t),s.issuesTotal(s.issuesTotal()-1),s.issues().length<1&&s.issuesTotal()&&s.load()}))},s.reload=function(){var t=e.Deferred();return clearTimeout(s.timeout),s.timeout=setTimeout((function(){s.load(),t.resolve()}),1e4),t.promise()},s.setFavicon=e=>{document.querySelector("[rel=icon]").setAttribute("href","img/ico/led"+e+".ico")},s.load=function(){e.when(e.getJSON("status/hosts/summary"),e.getJSON("reports/events/summary"),e.getJSON("reports/events/list?active=2"),e.getJSON("admin/general/messages")).then(((i,o,n,r)=>{var a;s.setFavicon(i[0].system),function(t){for(var s=t.status.length?t.status:[{label:"No hosts",data:[[1,1]]}],i=0,o=0;o<s.length;o++)s[o].data&&i++;e.plot(e("#status"),s,{series:{pie:{show:!0,stroke:{width:0},radius:.99,highlight:{opacity:0},label:{show:!0,radius:i>1?.5: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=o[0],e.each(a.events,(function(t,s){e.each(s.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),s.issues.removeAll(),e.each(r[0],(function(e,t){var i={type:0,date:strftime("%b %d %Y %H:%M:%S",new Date(1e3*t.timestamp)),severity:t.severity,description:t.message,dismiss:-3!=t.id};s.issues.push(i)})),e.each(n[0].records,(function(e,t){var i={type:1,date:strftime("%b %d %Y %H:%M:%S",new Date(1e3*t.date)),severity:1==t.eventtype?3:2,description:t.event,dismiss:!0,host:t.hostname,hostid:t.hostid,service:t.servicename,eventid:t.id};s.issues.push(i)})),s.issuesTotal(s.issues().length),MMONIT.error.ishidden()||MMONIT.error.hide()})).then(s.reload())},e.ajaxSetup({timeout:3e4}),s.load()};ko.applyBindings(s),e("#statusbox").on("click",(function(e,t,s){return window.location="status/hosts/",!1})),e("#eventsbox").on("click",(function(e,t,s){return window.location="reports/events/",!1}))}(jQuery);