From 1db252643fa8a471f84647af783d56de79f2eb42 Mon Sep 17 00:00:00 2001 From: Jade McGough Date: Thu, 3 Nov 2016 13:28:10 -0700 Subject: [PATCH] parse results from alerts query Signed-off-by: Kevin Fitzpatrick --- ui/src/alerts/apis/index.js | 2 +- ui/src/alerts/containers/AlertsApp.js | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ui/src/alerts/apis/index.js b/ui/src/alerts/apis/index.js index 5f314638d8..26cebf2dcb 100644 --- a/ui/src/alerts/apis/index.js +++ b/ui/src/alerts/apis/index.js @@ -3,7 +3,7 @@ import {proxy} from 'utils/queryUrlGenerator'; export function getAlerts(proxyLink) { return proxy({ source: proxyLink, - query: "select host, value, name, time, level from alerts", + query: "select host, value, level, alert_name from alert", db: "chronograf", }); } diff --git a/ui/src/alerts/containers/AlertsApp.js b/ui/src/alerts/containers/AlertsApp.js index a080757a99..82eb16a022 100644 --- a/ui/src/alerts/containers/AlertsApp.js +++ b/ui/src/alerts/containers/AlertsApp.js @@ -1,6 +1,7 @@ import React, {PropTypes} from 'react'; import AlertsTable from '../components/AlertsTable'; import {getAlerts} from '../apis'; +import _ from 'lodash'; // Kevin: because we were getting strange errors saying // "Failed prop type: Required prop `source` was not specified in `AlertsApp`." @@ -27,7 +28,26 @@ const AlertsApp = React.createClass({ componentDidMount() { return getAlerts(this.props.source.links.proxy).then((resp) => { - this.setState({alerts: resp.alerts}); + const results = []; + + const alertSeries = _.get(resp, ['data', 'results', '0', 'series'], []); + + const timeIndex = alertSeries[0].columns.findIndex((col) => col === 'time'); + const hostIndex = alertSeries[0].columns.findIndex((col) => col === 'host'); + const valueIndex = alertSeries[0].columns.findIndex((col) => col === 'value'); + const levelIndex = alertSeries[0].columns.findIndex((col) => col === 'level'); + const nameIndex = alertSeries[0].columns.findIndex((col) => col === 'alert_name'); + + alertSeries[0].values.forEach((s) => { + results.push({ + time: `${s[timeIndex]}`, + host: s[hostIndex], + value: `${s[valueIndex]}`, + level: s[levelIndex], + name: `${s[nameIndex]}`, + }); + }); + this.setState({alerts: results}); }); },