Set default time for alerts page

pull/1109/head
Andrew Watkins 2017-03-28 17:57:44 -07:00
parent feb89dda2d
commit 172c8369ad
2 changed files with 16 additions and 10 deletions

View File

@ -1,9 +1,9 @@
import {proxy} from 'utils/queryUrlGenerator'
export function getAlerts(proxyLink) {
export function getAlerts(source, timeRange) {
return proxy({
source: proxyLink,
query: "select host, value, level, alertName from alerts order by time desc",
source,
query: `SELECT host, value, level, alertName FROM alerts WHERE time >= '${timeRange.lower}' AND time <= '${timeRange.upper}' ORDER BY time desc`,
db: "chronograf",
})
}

View File

@ -1,12 +1,15 @@
import React, {PropTypes} from 'react'
import AlertsTable from '../components/AlertsTable'
import SourceIndicator from '../../shared/components/SourceIndicator'
import {getAlerts} from '../apis'
import AJAX from 'utils/ajax'
import _ from 'lodash'
import AlertsTable from '../components/AlertsTable'
import NoKapacitorError from '../../shared/components/NoKapacitorError'
import CustomTimeRange from '../../shared/components/CustomTimeRange'
import {getAlerts} from '../apis'
import AJAX from 'utils/ajax'
import _ from 'lodash'
import moment from 'moment'
const AlertsApp = React.createClass({
propTypes: {
source: PropTypes.shape({
@ -26,6 +29,10 @@ const AlertsApp = React.createClass({
hasKapacitor: false,
alerts: [],
isTimeOpen: false,
timeRange: {
upper: moment().format(),
lower: moment().subtract(1, 'h').format(),
},
}
},
// TODO: show a loading screen until we figure out if there is a kapacitor and fetch the alerts
@ -46,9 +53,8 @@ const AlertsApp = React.createClass({
},
fetchAlerts() {
getAlerts(this.props.source.links.proxy).then((resp) => {
const results = []
getAlerts(this.props.source.links.proxy, this.state.timeRange).then((resp) => {
const results = [];
const alertSeries = _.get(resp, ['data', 'results', '0', 'series'], [])
if (alertSeries.length === 0) {
this.setState({loading: false, alerts: []})