Commit aadf0a89 authored by MaxSol1's avatar MaxSol1
Browse files

error flash message

parent 323fed75
......@@ -21,6 +21,9 @@ export function CheckCard({options, slug, dashboard}) {
const initState = async () => {
setPerfValue(null);
const res = await meerkat.getIcingaObjectState(options.objectType, options.filter, dashboard);
if (res === false) {
window.flash(`This dashboard isn't updating`, 'error')
}
const state = icingaResultCodeToCheckState(options.objectType, res.MaxState);
res.Acknowledged ? setAcknowledged('ack') : setAcknowledged("");
if (state === 'ok') ok = true;
......@@ -34,6 +37,9 @@ export function CheckCard({options, slug, dashboard}) {
//Handle state update
const updateState = async () => {
meerkat.getCheckResult(options.objectType, options.id).then(async c => {
if (c === false) {
window.flash(`This dashboard isn't updating`, 'error')
}
let perfData = c.results ? c.results[0].attrs.last_check_result.performance_data : null;
if (perfData !== null) {
if (typeof perfData !== "undefined" && perfData.length > 0) {
......@@ -53,6 +59,10 @@ export function CheckCard({options, slug, dashboard}) {
});
meerkat.getDashboard(slug).then(async d => {
if (d === false) {
window.flash(`This dashboard isn't updating`, 'error')
}
dash = await d
const o = options.okSound ? new Audio(options.okSound) : new Audio(dash.okSound);
......@@ -101,16 +111,15 @@ export function CheckCard({options, slug, dashboard}) {
}
if (options.objectType !== null && options.filter !== null) {
try {
const res = await meerkat.getIcingaObjectState(options.objectType, options.filter, dashboard);
if (res === false) {
window.flash(`This dashboard isn't updating`, 'error')
}
const state = icingaResultCodeToCheckState(options.objectType, res.MaxState);
res.Acknowledged ? setAcknowledged('ack') : setAcknowledged("");
setCheckState(state);
muteAlerts();
alertSound(state);
} catch (error) {
window.flash(`This dashboard isn't updating: ${error}`, 'error')
}
}
});
}
......@@ -129,7 +138,7 @@ export function CheckCard({options, slug, dashboard}) {
if(options.objectType !== null && options.filter !== null) {
initState();
updateState();
const intervalID = window.setInterval(updateState, 30*1000)
const intervalID = window.setInterval(updateState, 5*1000)
return () => window.clearInterval(intervalID);
}
}, [options.objectType, options.filter, options.perfDataSelection]);
......
......@@ -186,6 +186,9 @@ export function CheckImage({options, dashboard, slug}) {
const initState = async () => {
const res = await meerkat.getIcingaObjectState(options.objectType, options.filter, dashboard);
if (res === false) {
window.flash('This dashbaord isnt updating', 'error');
}
const state = icingaResultCodeToCheckState(options.objectType, res.MaxState);
res.Acknowledged ? setAcknowledged('ack') : setAcknowledged("");
if (state === 'ok') ok = true;
......@@ -199,6 +202,9 @@ export function CheckImage({options, dashboard, slug}) {
//Handle state update
const updateState = async () => {
meerkat.getDashboard(slug).then(async d => {
if (d === false) {
window.flash('This dashbaord isnt updating', 'error');
}
dash = await d
const o = options.okSound ? new Audio(options.okSound) : new Audio(dash.okSound);
......@@ -211,6 +217,9 @@ export function CheckImage({options, dashboard, slug}) {
//get globalMute from dashboard JSON
const muteAlerts = () => {
meerkat.getDashboard(slug).then(async d => {
if (d === false) {
window.flash('This dashbaord isnt updating', 'error');
}
if (options.muteAlerts || d.globalMute) {
o.volume = 0.0; w.volume = 0.0; c.volume = 0.0; u.volume = 0.0; up.volume = 0.0; dow.volume = 0.0;
} else {
......@@ -248,6 +257,9 @@ export function CheckImage({options, dashboard, slug}) {
if (options.objectType !== null && options.filter !== null) {
try {
const res = await meerkat.getIcingaObjectState(options.objectType, options.filter, dashboard);
if (res === false) {
window.flash(`This dashboard isn't updating`, 'error')
}
const state = icingaResultCodeToCheckState(options.objectType, res.MaxState);
res.Acknowledged ? setAcknowledged('ack') : setAcknowledged("");
setCheckState(state);
......
......@@ -144,6 +144,9 @@ export function CheckLine({options, dashboard, slug}) {
const initState = async () => {
const res = await meerkat.getIcingaObjectState(options.objectType, options.filter, dashboard);
if (res === false) {
window.flash('This dashbaord isnt updating', 'error');
}
const state = icingaResultCodeToCheckState(options.objectType, res.MaxState);
res.Acknowledged ? setAcknowledged("ack") : setAcknowledged("");
if (state === 'ok') ok = true;
......@@ -157,6 +160,9 @@ export function CheckLine({options, dashboard, slug}) {
//Handle state update
const updateState = async () => {
meerkat.getDashboard(slug).then(async d => {
if (d === false) {
window.flash('This dashbaord isnt updating', 'error');
}
dash = await d
const o = options.okSound ? new Audio(options.okSound) : new Audio(dash.okSound);
......@@ -169,6 +175,9 @@ export function CheckLine({options, dashboard, slug}) {
//get globalMute from dashboard JSON
const muteAlerts = () => {
meerkat.getDashboard(slug).then(async d => {
if (d === false) {
window.flash('This dashbaord isnt updating', 'error');
}
if (options.muteAlerts || d.globalMute) {
o.volume = 0.0; w.volume = 0.0; c.volume = 0.0; u.volume = 0.0; up.volume = 0.0; dow.volume = 0.0;
} else {
......@@ -207,6 +216,9 @@ export function CheckLine({options, dashboard, slug}) {
if (options.objectType !== null && options.filter !== null) {
try {
const res = await meerkat.getIcingaObjectState(options.objectType, options.filter, dashboard);
if (res === false) {
window.flash(`This dashboard isn't updating`, 'error')
}
const state = icingaResultCodeToCheckState(options.objectType, res.MaxState);
res.Acknowledged ? setAcknowledged('ack') : setAcknowledged("");
setCheckState(state);
......
......@@ -118,6 +118,9 @@ export function CheckSVG({options, dashboard, slug}) {
const initState = async () => {
const res = await meerkat.getIcingaObjectState(options.objectType, options.filter, dashboard);
if (res === false) {
window.flash('This dashbaord isnt updating', 'error');
}
const state = icingaResultCodeToCheckState(options.objectType, res.MaxState);
res.Acknowledged ? setAcknowledged("ack") : setAcknowledged("");
if (state === 'ok') ok = true;
......@@ -131,6 +134,9 @@ export function CheckSVG({options, dashboard, slug}) {
//Handle state update
const updateState = async () => {
meerkat.getDashboard(slug).then(async d => {
if (d === false) {
window.flash('This dashbaord isnt updating', 'error');
}
dash = await d
const o = options.okSound ? new Audio(options.okSound) : new Audio(dash.okSound);
......@@ -143,6 +149,9 @@ export function CheckSVG({options, dashboard, slug}) {
//get globalMute from dashboard JSON
const muteAlerts = () => {
meerkat.getDashboard(slug).then(async d => {
if (d === false) {
window.flash('This dashbaord isnt updating', 'error');
}
if (options.muteAlerts || d.globalMute) {
o.volume = 0.0; w.volume = 0.0; c.volume = 0.0; u.volume = 0.0; up.volume = 0.0; dow.volume = 0.0;
} else {
......@@ -180,6 +189,9 @@ export function CheckSVG({options, dashboard, slug}) {
if (options.objectType !== null && options.filter !== null) {
try {
const res = await meerkat.getIcingaObjectState(options.objectType, options.filter, dashboard);
if (res === false) {
window.flash(`This dashboard isn't updating`, 'error')
}
const state = icingaResultCodeToCheckState(options.objectType, res.MaxState);
res.Acknowledged ? setAcknowledged('ack') : setAcknowledged("");
setCheckState(state);
......
//TODO error handling in here
function filterReplace(filter, dashboard) {
if (dashboard.hasOwnProperty('variables')) {
for (const [key, value] of Object.entries(dashboard.variables)) {
if (filter.includes(`~${key}~`)) {
let reg = new RegExp('~(' + key + ')~', 'g');
filter = filter.replaceAll(reg, value);
}
}
}
return filter;
}
async function fetchHandler(string) {
if (navigator.onLine) {
try {
const res = await fetch(string);
if (res.status !== 200) {
return false;
}
return res.json();
} catch (e) {
return false;
}
} else {
return false;
}
}
export async function getIcingaHosts() {
const res = await fetch(`/icinga/hosts`)
return res.json();
......@@ -21,44 +50,16 @@ export async function getIcingaServiceGroups() {
return res.json();
}
function filterReplace(filter, dashboard) {
if (dashboard.hasOwnProperty('variables')) {
for (const [key, value] of Object.entries(dashboard.variables)) {
if (filter.includes(`~${key}~`)) {
let reg = new RegExp('~(' + key + ')~', 'g');
filter = filter.replaceAll(reg, value);
}
}
}
return filter;
}
export async function getIcingaObjectState(objectType, filter, dashboard) {
let failed = 0;
filter = filterReplace(filter, dashboard);
const res = await fetch(`/icinga/check_state?object_type=${encodeURIComponent(objectType)};filter=${encodeURIComponent(filter)}`);
if (res.status !== 200) {
failed++;
if (failed > 2) {
window.flash(`This dashboard isn't updating`, 'error');
return;
}
return 3;
} else {
failed = 0;
return res.json();
}
return fetchHandler(`/icinga/check_state?object_type=${encodeURIComponent(objectType)};filter=${encodeURIComponent(filterReplace(filter, dashboard))}`);
}
export async function getCheckResult(objType, object, attrs="last_check_result") {
const res = await fetch(`/icinga/check_result?objtype=${objType};object=${encodeURIComponent(object)};attrs=${encodeURIComponent(attrs)}`);
return fetchHandler(`/icinga/check_result?objtype=${objType};object=${encodeURIComponent(object)};attrs=${encodeURIComponent(attrs)}`);
}
if (res.status !== 200) {
return console.log("query unsuccesful");
} else {
return res.json();
}
export async function getDashboard(slug) {
return fetchHandler(`/dashboard/${slug}`);
}
export async function getAllDashboards() {
......@@ -68,11 +69,6 @@ export async function getAllDashboards() {
return data;
}
export async function getDashboard(slug) {
const res = await fetch(`/dashboard/${slug}`);
return res.json();
}
export async function createDashboard(dashboard) {
const res = await fetch(`/dashboard`, {
method: 'POST',
......
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