From 01a3e99102f8c58083b502a568f2fe7ee68dc697 Mon Sep 17 00:00:00 2001 From: silenceqi Date: Sun, 26 Sep 2021 11:32:49 +0800 Subject: [PATCH] alerting monitor request url bug fixed --- service/alerting/monitor.go | 5 +- service/alerting/overview.go | 1 + web/src/locales/en-US/alert.js | 1 + web/src/locales/zh-CN/alert.js | 1 + .../components/AlertList/alertitem.scss | 8 +- web/src/pages/Alerting/pages/Home/Home.js | 7 ++ .../MonitorHistory/Legend/Legend.js | 9 +- .../pages/Alerting/pages/Overview/Overview.js | 103 +++++++++++++++++- 8 files changed, 120 insertions(+), 15 deletions(-) diff --git a/service/alerting/monitor.go b/service/alerting/monitor.go index 7fddc8c0..7c866b9e 100644 --- a/service/alerting/monitor.go +++ b/service/alerting/monitor.go @@ -1,7 +1,6 @@ package alerting import ( - "encoding/json" "errors" "fmt" httprouter "infini.sh/framework/core/api/router" @@ -200,8 +199,6 @@ func GetMonitors(w http.ResponseWriter, req *http.Request, ps httprouter.Params) }, } assignTo(params, sortPageData) - buf, _ := json.Marshal(params) - fmt.Println(string(buf)) config := getDefaultConfig() reqUrl := fmt.Sprintf("%s/%s/_search", config.Endpoint, orm.GetIndexName(alerting.Config{}) ) res, err := doRequest(reqUrl, http.MethodGet, nil, params) @@ -576,7 +573,7 @@ func AcknowledgeAlerts(w http.ResponseWriter, req *http.Request, ps httprouter.P } config := getDefaultConfig() - reqUrl := fmt.Sprintf("%s/%s/_update_by_query", getAlertIndexName(INDEX_ALERT), config.Endpoint) + reqUrl := fmt.Sprintf("%s/%s/_update_by_query", config.Endpoint, getAlertIndexName(INDEX_ALERT)) reqBody := IfaceMap{ "query": IfaceMap{ "bool": IfaceMap{ diff --git a/service/alerting/overview.go b/service/alerting/overview.go index 701ef3d7..db7a9370 100644 --- a/service/alerting/overview.go +++ b/service/alerting/overview.go @@ -16,6 +16,7 @@ func GetAlertOverview(w http.ResponseWriter, req *http.Request, ps httprouter.Pa "metrics": IfaceMap{ "alert_day": alertDayMetricData, }, + "ok": true, }, http.StatusOK) } diff --git a/web/src/locales/en-US/alert.js b/web/src/locales/en-US/alert.js index 5bf5da28..7697dd77 100644 --- a/web/src/locales/en-US/alert.js +++ b/web/src/locales/en-US/alert.js @@ -19,6 +19,7 @@ export default { 'alert.dashboard.state-options.completed': 'Completed', 'alert.dashboard.state-options.error': 'Error', 'alert.dashboard.state-options.deleted': 'Deleted', + 'alert.dashboard.state-options.normal': 'No alerts', 'alert.dashboard.create-monitor-text': 'There are no existing alerts. Create a monitor to add triggers and actions. Once an alarm is triggered, the state will show in this table.', 'alert.dashboard.create-trigger-text': 'There are no existing alerts. Create a trigger to start alerting. Once an alarm is triggered, the state will show in this table.', 'alert.dashboard.table.columns.start_time': 'Alert start time', diff --git a/web/src/locales/zh-CN/alert.js b/web/src/locales/zh-CN/alert.js index 4cd403f1..2b5f4dd4 100644 --- a/web/src/locales/zh-CN/alert.js +++ b/web/src/locales/zh-CN/alert.js @@ -19,6 +19,7 @@ export default { 'alert.dashboard.state-options.completed': '已恢复', 'alert.dashboard.state-options.error': '错误', 'alert.dashboard.state-options.deleted': '已删除', + 'alert.dashboard.state-options.normal': '正常', 'alert.dashboard.create-monitor-text': '暂无监控项。 创建监控项以添加触发器和操作。 一旦触发警报,状态将显示在此表中。', 'alert.dashboard.create-trigger-text': '暂无监控项。 创建触发器以开始警报。 一旦触发警报,状态将显示在此表中。', 'alert.dashboard.table.columns.start_time': '告警开始时间', diff --git a/web/src/pages/Alerting/pages/Dashboard/components/AlertList/alertitem.scss b/web/src/pages/Alerting/pages/Dashboard/components/AlertList/alertitem.scss index 97629ed4..87d54c25 100644 --- a/web/src/pages/Alerting/pages/Dashboard/components/AlertList/alertitem.scss +++ b/web/src/pages/Alerting/pages/Dashboard/components/AlertList/alertitem.scss @@ -23,16 +23,16 @@ color: #fff; font-size: 20px; &.COMPLETED{ - background-color: sandybrown; + background-color: rgb(208, 2, 27); } &.ACKNOWLEDGED{ - background-color: seagreen; + background-color: pink; } &.ACTIVE{ - background-color:tomato; + background-color: rgb(208, 2, 27); } &.ERROR{ - background-color:red; + background-color:lightgrey; } &.DELETED{ background-color: gray; diff --git a/web/src/pages/Alerting/pages/Home/Home.js b/web/src/pages/Alerting/pages/Home/Home.js index a8221edb..f4bac654 100644 --- a/web/src/pages/Alerting/pages/Home/Home.js +++ b/web/src/pages/Alerting/pages/Home/Home.js @@ -22,6 +22,7 @@ import Monitors from '../Monitors/containers/Monitors'; import DestinationsList from '../Destinations/containers/DestinationsList'; import { formatMessage } from 'umi/locale'; import {AlertOverview} from '../Dashboard/containers/AlertOverview'; +import Overview from '../Overview/Overview'; const getSelectedTabId = (pathname) => { if (pathname.includes('monitors')) return 'monitors'; @@ -122,6 +123,12 @@ export default class Home extends Component { notifications={notifications} /> )} + /> + ( + + )} /> { + const {httpClient, history} = props; + const [data, setData] = useState({ + metrics: { + alert_day: [], + } + }); + useEffect(()=>{ + httpClient.get('/alerting/overview', {}).then((resp) => { + if (resp.ok) { + const { metrics } = resp; + setData({ + metrics + }); + } else { + console.log('error getting alerts:', resp); + } + }); + }, []) return ( -
- +
+ + + + + +
); } \ No newline at end of file