Commit 84b84a72 authored by MaxSol1's avatar MaxSol1
Browse files

wip: perf data mode (now with polling and less bugs)

parent 86191ecd
......@@ -115,12 +115,13 @@ type varsBefore struct {
func handleCheckResult(w http.ResponseWriter, r *http.Request) {
service := r.URL.Query().Get("service")
object := r.URL.Query().Get("object")
attrs := r.URL.Query().Get("attrs")
objType := r.URL.Query().Get("objtype")
fmt.Println(service)
fmt.Println(object)
if service == "" {
if object == "" {
http.Error(w, "No unique queue name specified", http.StatusBadRequest)
return
}
......@@ -141,7 +142,12 @@ func handleCheckResult(w http.ResponseWriter, r *http.Request) {
return
}
req_url.Path = path.Join(req_url.Path, "/v1/objects/services", service)
if objType == "service" {
req_url.Path = path.Join(req_url.Path, "/v1/objects/services", object)
} else {
req_url.Path = path.Join(req_url.Path, "/v1/objects/hosts", object)
}
req_url.RawQuery = strings.ReplaceAll(url.Values{"attrs": []string{attrs}}.Encode(), "+", "%20")
req, err := http.NewRequest("GET", req_url.String(), nil)
......
import { h, Fragment } from 'preact';
import { h, Fragment, forceUpdate } from 'preact';
import { route } from 'preact-router';
import { useEffect, useReducer, useState, useRef, useLayoutEffect } from 'preact/hooks';
......@@ -150,12 +150,12 @@ export function Editor({slug, selectedElementId}) {
setHighlightedElementId={setHighlightedElementId} />
<ElementSettings selectedElement={selectedElement} updateElement={updateElement} />
</div>
</div>
<div class="side-bar-footer lefty-righty">
<button class="btn btn-outline-primary " onClick={e => route('/')}>Home</button>
<button onClick={saveDashboard} class={ savingDashboard ? 'loading' : ''} class="rounded btn-primary btn-large">Save Dashboard</button>
</div>
</div>
</div>
<div class="side-bar-footer lefty-righty">
<button class="btn btn-outline-primary " onClick={e => route('/')}>Home</button>
<button onClick={saveDashboard} class={ savingDashboard ? 'loading' : ''} class="rounded btn-primary btn-large">Save Dashboard</button>
</div>
</header>
</Fragment>
}
......
......@@ -28,6 +28,20 @@ export function CheckCard({options, slug, dashboard}) {
//Handle state update
const updateState = async () => {
meerkat.getCheckResult(options.objectType, options.id).then(async c => {
let perfData = c.results[0].attrs.last_check_result.performance_data.join().replace(',', ';').split(';');
if (typeof perfData !== "undefined" && perfData.length > 0) {
let arrPerf = [];
for( var i = 0; i < perfData.length; i++){
if (perfData[i].includes('=')) {
arrPerf.push(perfData[i].replace(',', ''));
}
}
let objPerf = Object.fromEntries(arrPerf.map(s => s.split('=')));
setPerfData(objPerf);
perfDataSelected(objPerf);
}
});
meerkat.getDashboard(slug).then(async d => {
dash = await d
......@@ -94,22 +108,8 @@ export function CheckCard({options, slug, dashboard}) {
//Setup check refresher
useEffect(() => {
console.log("HI")
if(options.objectType !== null && options.filter !== null) {
meerkat.getCheckResult(options.id).then(async c => {
let perfData = c.results[0].attrs.last_check_result.performance_data.join().replace(',', ';').split(';');
if (typeof perfData !== "undefined") {
let arrPerf = [];
for( var i = 0; i < perfData.length; i++){
if (perfData[i].includes('=')) {
arrPerf.push(perfData[i].replace(',', ''));
}
}
let objPerf = Object.fromEntries(arrPerf.map(s => s.split('=')));
setPerfData(objPerf);
perfDataSelected(objPerf);
console.log(objPerf)
}
});
initState();
updateState();
const intervalID = window.setInterval(updateState, 30*1000)
......@@ -160,9 +160,7 @@ const PerfDataOptions = ({options, updateOptions}) => {
options.perfDataMode ? setShowPerf(true) : setShowPerf(false);
clearPerfData();
setShowPerf(false)
meerkat.getCheckResult(options.id).then(async c => {
let erfData = c.results[0].attrs.last_check_result.performance_data
console.log(erfData)
meerkat.getCheckResult(options.objectType, options.id).then(async c => {
let perfData = c.results[0].attrs.last_check_result.performance_data.join().replace(',', ';').split(';');
if (typeof perfData !== "undefined") {
let arrPerf = [];
......@@ -185,21 +183,13 @@ const PerfDataOptions = ({options, updateOptions}) => {
}
}
const perfDataMode = (e) => {
let perfDataModeChecked = options.perfDataMode;
perfDataModeChecked = !perfDataModeChecked;
updateOptions({
perfDataMode: perfDataModeChecked
})
}
if(perfData === null) {
return <div><label>No Performance Data Available</label><br/></div>
}
return <div>
<label class="status-font-size">Performance Data Mode</label>
<input type="checkbox" defaultChecked={options.perfDataMode} onChange={e => perfDataMode(e)} class="form-control perf-data-mode"/>
<label id="perf-mode" class="status-font-size">Performance Data Mode</label>
<input type="checkbox" defaultChecked={options.perfDataMode} onClick={e => updateOptions({perfDataMode: e.currentTarget.checked})} class="form-control perf-data-mode"/>
{options.perfDataMode || showPerfOptions ?
<select onInput={e => updateOptions({perfDataSelection: e.currentTarget.value})}>
<option value={null} selected disabled>Choose away...</option>
......
......@@ -30,8 +30,8 @@ export async function getIcingaObjectState(objectType, filter) {
}
}
export async function getCheckResult(service, attrs="last_check_result") {
const res = await fetch(`/icinga/check_result?service=${encodeURIComponent(service)};attrs=${encodeURIComponent(attrs)}`);
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)}`);
if (res.status !== 200) {
return console.log("query succesful");
......
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