Commit ff832ccc authored by MaxSol1's avatar MaxSol1
Browse files

popup global red indicator when meerkat frontend isn't getting updates

parent 75d84ca9
...@@ -101,12 +101,16 @@ export function CheckCard({options, slug, dashboard}) { ...@@ -101,12 +101,16 @@ export function CheckCard({options, slug, dashboard}) {
} }
if (options.objectType !== null && options.filter !== null) { if (options.objectType !== null && options.filter !== null) {
const res = await meerkat.getIcingaObjectState(options.objectType, options.filter, dashboard); try {
const state = icingaResultCodeToCheckState(options.objectType, res.MaxState); const res = await meerkat.getIcingaObjectState(options.objectType, options.filter, dashboard);
res.Acknowledged ? setAcknowledged('ack') : setAcknowledged(""); const state = icingaResultCodeToCheckState(options.objectType, res.MaxState);
setCheckState(state); res.Acknowledged ? setAcknowledged('ack') : setAcknowledged("");
muteAlerts(); setCheckState(state);
alertSound(state); muteAlerts();
alertSound(state);
} catch (error) {
window.flash(`This dashboard isn't updating: ${error}`, 'error')
}
} }
}); });
} }
......
...@@ -246,12 +246,16 @@ export function CheckImage({options, dashboard, slug}) { ...@@ -246,12 +246,16 @@ export function CheckImage({options, dashboard, slug}) {
} }
} }
if (options.objectType !== null && options.filter !== null) { if (options.objectType !== null && options.filter !== null) {
const res = await meerkat.getIcingaObjectState(options.objectType, options.filter, dashboard); try {
const state = icingaResultCodeToCheckState(options.objectType, res.MaxState); const res = await meerkat.getIcingaObjectState(options.objectType, options.filter, dashboard);
res.Acknowledged ? setAcknowledged('ack') : setAcknowledged(""); const state = icingaResultCodeToCheckState(options.objectType, res.MaxState);
setCheckState(state); res.Acknowledged ? setAcknowledged('ack') : setAcknowledged("");
muteAlerts(); setCheckState(state);
alertSound(state); muteAlerts();
alertSound(state);
} catch (error) {
window.flash("This dashboard isn't updating", 'error')
}
} }
}); });
} }
......
...@@ -205,12 +205,16 @@ export function CheckLine({options, dashboard, slug}) { ...@@ -205,12 +205,16 @@ export function CheckLine({options, dashboard, slug}) {
} }
if (options.objectType !== null && options.filter !== null) { if (options.objectType !== null && options.filter !== null) {
const res = await meerkat.getIcingaObjectState(options.objectType, options.filter, dashboard); try {
const state = icingaResultCodeToCheckState(options.objectType, res.MaxState); const res = await meerkat.getIcingaObjectState(options.objectType, options.filter, dashboard);
res.Acknowledged ? setAcknowledged("ack") : setAcknowledged(""); const state = icingaResultCodeToCheckState(options.objectType, res.MaxState);
setCheckState(state); res.Acknowledged ? setAcknowledged('ack') : setAcknowledged("");
muteAlerts(); setCheckState(state);
alertSound(state); muteAlerts();
alertSound(state);
} catch (error) {
window.flash("This dashboard isn't updating", 'error')
}
} }
}); });
} }
......
...@@ -178,12 +178,16 @@ export function CheckSVG({options, dashboard, slug}) { ...@@ -178,12 +178,16 @@ export function CheckSVG({options, dashboard, slug}) {
} }
} }
if (options.objectType !== null && options.filter !== null) { if (options.objectType !== null && options.filter !== null) {
const res = await meerkat.getIcingaObjectState(options.objectType, options.filter, dashboard); try {
const state = icingaResultCodeToCheckState(options.objectType, res.MaxState); const res = await meerkat.getIcingaObjectState(options.objectType, options.filter, dashboard);
res.Acknowledged ? setAcknowledged("ack") : setAcknowledged(""); const state = icingaResultCodeToCheckState(options.objectType, res.MaxState);
setCheckState(state); res.Acknowledged ? setAcknowledged('ack') : setAcknowledged("");
muteAlerts(); setCheckState(state);
alertSound(state); muteAlerts();
alertSound(state);
} catch (error) {
window.flash("This dashboard isn't updating", 'error')
}
} }
}); });
} }
......
import { h, Fragment } from 'preact';
import { useState, useEffect } from 'preact/hooks';
import bus from '../utils/bus';
export const Flash = () => {
let [visibility, setVisibility] = useState(false);
let [message, setMessage] = useState('');
let [type, setType] = useState('');
useEffect(() => {
bus.addListener('flash', ({message, type}) => {
setVisibility(true);
setMessage(message);
setType(type);
setTimeout(() => {
setVisibility(false);
}, 4000);
});
}, []);
const alert = {
color: 'white',
background: '#ff4a4a',
borderRadius: '5px',
position: 'absolute',
top: '40px',
right: '30px',
paddingTop: '38px',
paddingBottom: '25px',
paddingTop: '38px',
paddingLeft: '40px',
paddingRight: '40px',
display: 'flex',
alignItems: 'center',
marginTop: '20px',
zIndex: 2,
margin: 0,
fontSize: '20px',
}
const close = {
color: 'white',
cursor: 'pointer',
marginLeft: '30px',
marginRight: '5px',
marginBottom: '14px',
}
// const error = {
// background: 'red',
// }
// const success = {
// background: 'lightgreen',
// }
useEffect(() => {
if(document.getElementById('close') !== null) {
document.getElementById('close').addEventListener('click', () => setVisibility(false));
}
})
return (
visibility && <div style={alert}>
<p>{message}</p>
<span style={close} id="close"><strong>X</strong></span>
</div>
)
}
\ No newline at end of file
...@@ -4,9 +4,12 @@ import { Router } from 'preact-router'; ...@@ -4,9 +4,12 @@ import { Router } from 'preact-router';
import { Home } from './home'; import { Home } from './home';
import { Editor } from './editor'; import { Editor } from './editor';
import { Viewer } from './viewer'; import { Viewer } from './viewer';
import { Flash } from './flash';
import bus from '../utils/bus';
function Main() { function Main() {
return <Fragment> return <Fragment>
<Flash />
<Router> <Router>
<Home path="/" /> <Home path="/" />
<Editor path="/edit/:slug" /> <Editor path="/edit/:slug" />
...@@ -17,6 +20,8 @@ function Main() { ...@@ -17,6 +20,8 @@ function Main() {
</Fragment> </Fragment>
} }
window.flash = (message, type="success") => bus.emit('flash', ({message, type}));
function NotFound() { function NotFound() {
return <div>404</div> return <div>404</div>
} }
......
import EventEmitter from 'events';
export default new EventEmitter();
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment