Skip to content

Commit

Permalink
更新PrometheusAlert对mysql的支持,修复飞书显示标题
Browse files Browse the repository at this point in the history
  • Loading branch information
jikun.zhang committed Dec 22, 2020
1 parent 103418b commit 247abb7
Show file tree
Hide file tree
Showing 49 changed files with 7,333 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ PrometheusAlert具备如下特性
- 增加Dashboard,提供配置测试,告警消息模版自定义,告警模版测试等功能
- 增加自定义告警消息模版支持,可以通过自定义模版对任意服务WebHook进行支持
- 增加代理支持
- 增加支持mysql、sqlite3作为模版存储,便于集群化部署

---------------------

Expand Down
6 changes: 6 additions & 0 deletions conf/app-example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ logtype=file
logpath=logs/prometheusalertcenter.log
#转换Prometheus,graylog告警消息的时区为CST时区(如默认已经是CST时区,请勿开启)
prometheus_cst_time=0
#数据库驱动,支持sqlite3,mysql,如使用mysql,请开启db_host,db_user,db_password,db_name的注释
db_driver=sqlite3
#db_host=127.0.0.1:3306
#db_user=root
#db_password=root
#db_name=prometheusalert

#---------------------↓webhook-----------------------
#是否开启钉钉告警通道,可同时开始多个通道0为关闭,1为开启
Expand Down
16 changes: 16 additions & 0 deletions controllers/feishu.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,19 @@ type Element struct {
Text Te `json:"text"`
}

type Titles struct {
Content string `json:"content"`
Tag string `json:"tag"`
}

type Headers struct {
Title Titles `json:"title"`
}

type Cards struct {
Config Conf `json:"config"`
Elements []Element `json:"elements"`
Header Headers `json:"header"`
}

type FSMessagev2 struct {
Expand All @@ -104,6 +114,12 @@ func PostToFeiShuv2(title, text, Fsurl, logsign string) string {
WideScreenMode: true,
EnableForward: true,
},
Header:Headers{
Title:Titles{
Content:title,
Tag:"plain_text",
},
},
Elements: []Element{
Element{
Tag: "div",
Expand Down
61 changes: 61 additions & 0 deletions db/prometheusalert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Navicat MySQL Data Transfer
Source Server : xx.xx.xx.xx
Source Server Version : 3306
Source Host : xx.xx.xx.xx:3306
Source Database : prometheusalert
Target Server Type : MYSQL
Target Server Version : 50732
File Encoding : 65001
Date: 2020-12-22 11:16:43
*/

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `prometheus_alert_d_b`
-- ----------------------------
DROP TABLE IF EXISTS `prometheus_alert_d_b`;
CREATE TABLE `prometheus_alert_d_b` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tpltype` varchar(255) NOT NULL DEFAULT '',
`tpluse` varchar(255) NOT NULL DEFAULT '',
`tplname` varchar(255) NOT NULL DEFAULT '',
`tpl` longtext NOT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `prometheus_alert_d_b_tplname` (`tplname`)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8mb4;

-- ----------------------------
-- Records of prometheus_alert_d_b
-- ----------------------------
INSERT INTO `prometheus_alert_d_b` VALUES ('1', 'dd', 'Prometheus', 'prometheus-dd', '{{ $var := .externalURL}}{{ range $k,$v:=.alerts }}\r\n{{if eq $v.status \"resolved\"}}\r\n## [Prometheus恢复信息]({{$v.generatorURL}})\r\n#### [{{$v.labels.alertname}}]({{$var}})\r\n###### 告警级别:{{$v.labels.level}}\r\n###### 开始时间:{{$v.startsAt}}\r\n###### 结束时间:{{$v.endsAt}}\r\n###### 故障主机IP:{{$v.labels.instance}}\r\n##### {{$v.annotations.description}}\r\n![Prometheus](https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/alert-center.png)\r\n{{else}}\r\n## [Prometheus告警信息]({{$v.generatorURL}})\r\n#### [{{$v.labels.alertname}}]({{$var}})\r\n###### 告警级别:{{$v.labels.level}}\r\n###### 开始时间:{{$v.startsAt}}\r\n###### 结束时间:{{$v.endsAt}}\r\n###### 故障主机IP:{{$v.labels.instance}}\r\n##### {{$v.annotations.description}}\r\n![Prometheus](https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/alert-center.png)\r\n{{end}}\r\n{{ end }}', '2020-12-22 03:06:55');
INSERT INTO `prometheus_alert_d_b` VALUES ('2', 'wx', 'Prometheus', 'prometheus-wx', '{{ $var := .externalURL}}{{ range $k,$v:=.alerts }}\r\n{{if eq $v.status \"resolved\"}}\r\n[Prometheus恢复信息]($v.generatorURL}})\r\n>**[{{$v.labels.alertname}}]({{$var}})**\r\n>告警级别: {{$v.labels.level}}\r\n开始时间: {{$v.startsAt}}\r\n结束时间: {{$v.endsAt}}\r\n故障主机IP: {{$v.labels.instance}}\r\n**{{$v.annotations.description}}**\r\n{{else}}\r\n[Prometheus告警信息]($v.generatorURL}})\r\n>**[{{$v.labels.alertname}}]({{$var}})**\r\n>告警级别: {{$v.labels.level}}\r\n开始时间: {{$v.startsAt}}\r\n结束时间: {{$v.endsAt}}\r\n故障主机IP: {{$v.labels.instance}}\r\n**{{$v.annotations.description}}**\r\n{{end}}\r\n{{ end }}', '2020-12-22 03:07:19');
INSERT INTO `prometheus_alert_d_b` VALUES ('3', 'fs', 'Prometheus', 'prometheus-fs', '{{ $var := .externalURL}}{{ range $k,$v:=.alerts }}\r\n{{if eq $v.status \"resolved\"}}\r\n**[Prometheus恢复信息]({{$v.generatorURL}})**\r\n*[{{$v.labels.alertname}}]({{$var}})*\r\n告警级别:{{$v.labels.level}}\r\n开始时间:{{$v.startsAt}}\r\n结束时间:{{$v.endsAt}}\r\n故障主机IP:{{$v.labels.instance}}\r\n**{{$v.annotations.description}}**\r\n{{else}}\r\n**[Prometheus告警信息]({{$v.generatorURL}})**\r\n*[{{$v.labels.alertname}}]({{$var}})*\r\n告警级别:{{$v.labels.level}}\r\n开始时间:{{$v.startsAt}}\r\n结束时间:{{$v.endsAt}}\r\n故障主机IP:{{$v.labels.instance}}\r\n**{{$v.annotations.description}}**\r\n{{end}}\r\n{{ end }}', '2020-12-22 03:07:39');
INSERT INTO `prometheus_alert_d_b` VALUES ('4', 'txdx', 'Prometheus', 'prometheus-dx', '{{ range $k,$v:=.alerts }}{{if eq $v.status \"resolved\"}}\r\n[Prometheus恢复信息]\r\n{{$v.labels.alertname}}\r\n告警级别:{{$v.labels.level}}\r\n故障主机IP:{{$v.labels.instance}}\r\n{{$v.annotations.description}}\r\n{{else}}\r\nPrometheus告警信息]\r\n{{$v.labels.alertname}}\r\n告警级别:{{$v.labels.level}}\r\n故障主机IP:{{$v.labels.instance}}\r\n{{$v.annotations.description}}\r\n{{end}}\r\n{{ end }}', '2020-12-22 03:08:01');
INSERT INTO `prometheus_alert_d_b` VALUES ('5', 'txdh', 'Prometheus', 'prometheus-dh', '{{ range $k,$v:=.alerts }}{{if eq $v.status \"resolved\"}}恢复信息故障主机IP{{$v.labels.instance}}{{$v.annotations.description}}{{else}}告警信息故障主机IP{{$v.labels.instance}}{{$v.annotations.description}}{{end}}{{ end }}', '2020-12-22 03:08:22');
INSERT INTO `prometheus_alert_d_b` VALUES ('6', 'email', 'Prometheus', 'prometheus-email', '{{ $var := .externalURL}}{{ range $k,$v:=.alerts }}\r\n{{if eq $v.status \"resolved\"}}\r\n<h1><a href ={{$v.generatorURL}}>Prometheus恢复信息</a></h1>\r\n<h2><a href ={{$var}}>{{$v.labels.alertname}}</a></h2>\r\n<h5>告警级别:{{$v.labels.level}}</h5>\r\n<h5>开始时间:{{$v.startsAt}}</h5>\r\n<h5>结束时间:{{$v.endsAt}}</h5>\r\n<h5>故障主机IP:{{$v.labels.instance}}</h5>\r\n<h3>{{$v.annotations.description}}</h3>\r\n<img src=https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/alert-center.png />\r\n{{else}}\r\n<h1><a href ={{$v.generatorURL}}>Prometheus告警信息</a></h1>\r\n<h2><a href ={{$var}}>{{$v.labels.alertname}}</a></h2>\r\n<h5>告警级别:{{$v.labels.level}}</h5>\r\n<h5>开始时间:{{$v.startsAt}}</h5>\r\n<h5>结束时间:{{$v.endsAt}}</h5>\r\n<h5>故障主机IP:{{$v.labels.instance}}</h5>\r\n<h3>{{$v.annotations.description}}</h3>\r\n<img src=https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/alert-center.png />\r\n{{end}}\r\n{{ end }}', '2020-12-22 03:08:44');
INSERT INTO `prometheus_alert_d_b` VALUES ('7', 'dd', 'Graylog2', 'graylog2-dd', '## [Graylog2告警信息](http://graylog.org)\r\n#### {{.check_result.result_description}}\r\n{{ range $k,$v:=.check_result.matching_messages }}\r\n###### 告警索引:{{$v.index}}\r\n###### 开始时间:{{GetCSTtime $v.timestamp}}\r\n###### 告警主机:{{$v.fields.gl2_remote_ip}}:{{$v.fields.gl2_remote_port}}\r\n##### {{$v.message}}\r\n{{end}}\r\n![Prometheus](https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/alert-center.png)', '2020-12-22 03:09:02');
INSERT INTO `prometheus_alert_d_b` VALUES ('8', 'wx', 'Graylog2', 'graylog2-wx', '[Graylog2告警信息](http://graylog.org)\r\n>**{{.check_result.result_description}}**\r\n{{ range $k,$v:=.check_result.matching_messages }}\r\n>告警索引:{{$v.index}}\r\n开始时间:{{GetCSTtime $v.timestamp}}\r\n告警主机:{{$v.fields.gl2_remote_ip}}:{{$v.fields.gl2_remote_port}}\r\n**{{$v.message}}**\r\n{{end}}', '2020-12-22 03:09:22');
INSERT INTO `prometheus_alert_d_b` VALUES ('9', 'fs', 'Graylog2', 'graylog2-fs', '**[Graylog2告警信息](http://graylog.org)**\r\n*{{.check_result.result_description}}*\r\n{{ range $k,$v:=.check_result.matching_messages }}\r\n告警索引:{{$v.index}}\r\n开始时间:{{GetCSTtime $v.timestamp}}\r\n告警主机:{{$v.fields.gl2_remote_ip}}:{{$v.fields.gl2_remote_port}}\r\n**{{$v.message}}**\r\n{{end}}', '2020-12-22 03:09:44');
INSERT INTO `prometheus_alert_d_b` VALUES ('10', 'txdx', 'Graylog2', 'graylog2-dx', '{{ range $k,$v:=.check_result.matching_messages }}\r\n告警主机 {{$v.fields.gl2_remote_ip}}端口 {{$v.fields.gl2_remote_port}}告警消息 {{$v.message}}\r\n{{end}}', '2020-12-22 03:10:04');
INSERT INTO `prometheus_alert_d_b` VALUES ('11', 'txdh', 'Graylog2', 'graylog2-dh', '{{ range $k,$v:=.check_result.matching_messages }}\r\n告警主机 {{$v.fields.gl2_remote_ip}}端口 {{$v.fields.gl2_remote_port}}告警消息 {{$v.message}}\r\n{{end}}', '2020-12-22 03:10:26');
INSERT INTO `prometheus_alert_d_b` VALUES ('12', 'email', 'Graylog2', 'graylog2-email', '<h1><a href =http://graylog.org>Graylog2告警信息</a></h1>\r\n<h2>{{.check_result.result_description}}</h2>\r\n{{ range $k,$v:=.check_result.matching_messages }}\r\n<h5>告警索引:{{$v.index}}</h5>\r\n<h5>开始时间:{{GetCSTtime $v.timestamp}}</h5>\r\n<h5>告警主机:{{$v.fields.gl2_remote_ip}}:{{$v.fields.gl2_remote_port}}</h5>\r\n<h3>{{$v.message}}</h3>\r\n{{end}}\r\n<img src=https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/alert-center.png />', '2020-12-22 03:10:47');
INSERT INTO `prometheus_alert_d_b` VALUES ('13', 'dd', 'Graylog3', 'graylog3-dd', '## [Graylog3告警信息](.check_result.Event.Source)\r\n#### {{.check_result.event_definition_description}}\r\n{{ range $k,$v:=.backlog }}\r\n###### 告警索引:{{$v.index}}\r\n###### 开始时间:{{GetCSTtime $v.timestamp}}\r\n###### 告警主机:{{$v.fields.gl2_remote_ip}}:{{$v.fields.gl_2_remote_port}}\r\n##### {{$v.message}}\r\n{{end}}\r\n![Prometheus](https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/alert-center.png)', '2020-12-22 03:11:07');
INSERT INTO `prometheus_alert_d_b` VALUES ('14', 'wx', 'Graylog3', 'graylog3-wx', '[Graylog3告警信息](.check_result.Event.Source)\r\n>**{{.check_result.event_definition_description}}**\r\n{{ range $k,$v:=.backlog }}\r\n>告警索引:{{$v.index}}\r\n开始时间:{{GetCSTtime $v.timestamp}}\r\n告警主机:{{$v.fields.gl2_remote_ip}}:{{$v.fields.gl_2_remote_port}}\r\n**{{$v.message}}**\r\n{{end}}', '2020-12-22 03:11:28');
INSERT INTO `prometheus_alert_d_b` VALUES ('15', 'fs', 'Graylog3', 'graylog3-fs', '**[Graylog3告警信息](.check_result.Event.Source)**\r\n*{{.check_result.event_definition_description}}*\r\n{{ range $k,$v:=.backlog }}\r\n告警索引:{{$v.index}}\r\n开始时间:{{GetCSTtime $v.timestamp}}\r\n告警主机:{{$v.fields.gl2_remote_ip}}:{{$v.fields.gl_2_remote_port}}\r\n**{{$v.message}}**\r\n{{end}}', '2020-12-22 03:11:49');
INSERT INTO `prometheus_alert_d_b` VALUES ('16', 'txdx', 'Graylog3', 'graylog3-dx', '{{ range $k,$v:=.backlog }}\r\n告警主机 {{$v.fields.gl2_remote_ip}}端口 {{$v.fields.gl_2_remote_port}}告警消息 {{$v.message}}\r\n{{end}}', '2020-12-22 03:12:18');
INSERT INTO `prometheus_alert_d_b` VALUES ('17', 'txdh', 'Graylog3', 'graylog3-dh', '{{ range $k,$v:=.backlog }}\r\n告警主机 {{$v.fields.gl2_remote_ip}}端口 {{$v.fields.gl_2_remote_port}}告警消息 {{$v.message}}\r\n{{end}}', '2020-12-22 03:12:39');
INSERT INTO `prometheus_alert_d_b` VALUES ('18', 'email', 'Graylog3', 'graylog3-email', '<h1><a href =.check_result.Event.Source>Graylog3告警信息</a></h1>\r\n<h2>{{.check_result.event_definition_description}}</h2>\r\n{{ range $k,$v:=.backlog }}\r\n<h5>告警索引:{{$v.index}}</h5>\r\n<h5>开始时间:{{GetCSTtime $v.timestamp}}</h5>\r\n<h5>告警主机:{{$v.fields.gl2_remote_ip}}:{{$v.fields.gl_2_remote_port}}</h5>\r\n<h3>{{$v.message}}</h3>\r\n{{end}}\r\n<img src=https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/alert-center.png />', '2020-12-22 03:13:01');
INSERT INTO `prometheus_alert_d_b` VALUES ('19', 'dd', 'Grafana', 'grafana-dd', '{{if eq .state \"ok\"}}\r\n## [Grafana恢复信息]({{.ruleUrl}})\r\n#### {{.ruleName}}\r\n###### 告警级别:严重\r\n###### 开始时间:{{GetCSTtime \"\"}}\r\n##### {{.message}}\r\n{{else}}\r\n## [Grafana告警信息]({{.ruleUrl}})\r\n#### {{.ruleName}}\r\n###### 告警级别:严重\r\n###### 开始时间:{{GetCSTtime \"\"}}\r\n##### {{.message}}\r\n{{end}}\r\n![Prometheus](https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/alert-center.png)', '2020-12-22 03:13:28');
INSERT INTO `prometheus_alert_d_b` VALUES ('20', 'wx', 'Grafana', 'grafana-wx', '{{if eq .state \"ok\"}}\r\n[Grafana恢复信息]({{.ruleUrl}})\r\n>**{{.ruleName}}**\r\n>告警级别:严重\r\n开始时间:{{GetCSTtime \"\"}}\r\n{{.message}}\r\n{{else}}\r\n[Grafana告警信息]({{.ruleUrl}})\r\n>**{{.ruleName}}**\r\n>告警级别:严重\r\n开始时间:{{GetCSTtime \"\"}}\r\n{{.message}}\r\n{{end}}', '2020-12-22 03:13:50');
INSERT INTO `prometheus_alert_d_b` VALUES ('21', 'fs', 'Grafana', 'grafana-fs', '{{if eq .state \"ok\"}}\r\n**[Grafana恢复信息]({{.ruleUrl}})**\r\n*{{.ruleName}}*\r\n告警级别:严重\r\n开始时间:{{GetCSTtime \"\"}}\r\n**{{.message}}**\r\n{{else}}\r\n**[Grafana告警信息]({{.ruleUrl}})**\r\n*{{.ruleName}}*\r\n告警级别:严重\r\n开始时间:{{GetCSTtime \"\"}}\r\n**{{.message}}**\r\n{{end}}', '2020-12-22 03:14:13');
INSERT INTO `prometheus_alert_d_b` VALUES ('22', 'txdx', 'Grafana', 'grafana-dx', '{{if eq .state \"ok\"}}\r\nGrafana恢复信息{{.message}}\r\n{{else}}\r\nGrafana告警信息{{.message}}\r\n{{end}}', '2020-12-22 03:14:33');
INSERT INTO `prometheus_alert_d_b` VALUES ('23', 'txdh', 'Grafana', 'grafana-dh', '{{if eq .state \"ok\"}}\r\nGrafana恢复信息{{.message}}\r\n{{else}}\r\nGrafana告警信息{{.message}}\r\n{{end}}', '2020-12-22 03:14:54');
INSERT INTO `prometheus_alert_d_b` VALUES ('24', 'email', 'Grafana', 'grafana-email', '{{if eq .state \"ok\"}}\r\n<h1><a href ={{.ruleUrl}}>Grafana恢复信息</a></h1>\r\n<h2>{{.ruleName}}</h2>\r\n<h5>告警级别:严重</h5>\r\n<h5>开始时间:{{GetCSTtime \"\"}}</h5>\r\n<h3>{{.message}}</h3>\r\n{{else}}\r\n<h1><a href ={{.ruleUrl}}>Grafana恢复信息</a></h1>\r\n<h2>{{.ruleName}}</h2>\r\n<h5>告警级别:严重</h5>\r\n<h5>开始时间:{{GetCSTtime \"\"}}</h5>\r\n<h3>{{.message}}</h3>\r\n{{end}}\r\n<img src=https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/alert-center.png />', '2020-12-22 03:15:15');
INSERT INTO `prometheus_alert_d_b` VALUES ('25', 'dd', 'SonarQube', 'sonar-dd-example', '## [Sonar告警信息]({{.serverUrl}})\r\n###### 检测状态:{{.status}}\r\n###### 检测时间:{{.analysedAt}}\r\n###### ---------------------------------\r\n{{ range $k,$v:=.qualityGate.conditions}}\r\n###### metric:{{$v.metric}}\r\n###### errorThreshold:{{$v.errorThreshold}}\r\n###### operator:{{$v.operator}}\r\n###### status:{{$v.status}}\r\n###### -----------------------------------\r\n{{ end }}\r\n![Prometheus](https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/alert-center.png)', '2020-12-22 03:15:34');
INSERT INTO `prometheus_alert_d_b` VALUES ('26', 'dd', 'Jenkins', 'jenkins-dd-example', '## [Jenkins构建信息]({{.buildUrl}})\r\n###### Jenkins地址:[{{.buildUrl}}]({{.buildUrl}})\r\n###### 构建项目:{{.projectName}}\r\n###### 构建事件:{{.event}}\r\n###### 构建名称:{{.buildName}}\r\n###### 构建时间:{{GetCSTtime \"\"}}\r\n![Prometheus](https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/alert-center.png)', '2020-12-22 03:15:54');
INSERT INTO `prometheus_alert_d_b` VALUES ('27', 'fs', 'Prometheus', 'prometheus-fsv2', '{{ $var := .externalURL}}{{ range $k,$v:=.alerts }}\r\n{{if eq $v.status \"resolved\"}}\r\n**[Prometheus恢复信息]({{$v.generatorURL}})**\r\n*[{{$v.labels.alertname}}]({{$var}})*\r\n告警级别:{{$v.labels.level}}\r\n开始时间:{{$v.startsAt}}\r\n结束时间:{{$v.endsAt}}\r\n故障主机IP:{{$v.labels.instance}}\r\n**{{$v.annotations.description}}**\r\n{{else}}\r\n**[Prometheus告警信息]({{$v.generatorURL}})**\r\n*[{{$v.labels.alertname}}]({{$var}})*\r\n告警级别:{{$v.labels.level}}\r\n开始时间:{{$v.startsAt}}\r\n结束时间:{{$v.endsAt}}\r\n故障主机IP:{{$v.labels.instance}}\r\n**{{$v.annotations.description}}**\r\n{{end}}\r\n{{ end }}', '2020-12-22 03:16:15');
27 changes: 26 additions & 1 deletion doc/readme/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,29 @@ cd PrometheusAlert/example/helm/prometheusalert
helm install -n monitoring .
#启动后可使用浏览器打开以下地址查看: http://[Ingress_url]:[Ingress_port]
```
```
--------------------------------------------------------------------

配置PrometheusAlert使用mysql作为后端数据存储
----
- PrometheusAlert默认使用sqlite3作为后端自定义模板的存储,这种方式适合于单机部署,满足绝大部分生产场景使用。考虑到部分企业对于服务的高可用要求较高,同时也为了让PrometheusAlert更易于横向扩展,用户可以更改PrometheusAlert的默认存储为mysql。(推荐使用mysql 5.7及以上版本)
- 1.创建数据库
```
CREATE DATABASE prometheusalert CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
```
- 2.利用`Navicat`或命令行将`db目录`中的 `prometheusalert.sql` 导入数据库`prometheusalert`
```
use prometheusalert
source prometheusalert.sql
```
- 3.开启PrometheusAlert配置文件中关于mysql的配置 conf/app.conf,数据库名称与上面创建的数据一致

```
#数据库驱动,支持sqlite3,mysql,如使用mysql,请开启db_host,db_user,db_password,db_name的注释
db_driver=mysql
db_host=127.0.0.1:3306
db_user=root
db_password=root
db_name=prometheusalert
```
- 重启PrometheusAlert,这样即完成配置PrometheusAlert使用mysql数据库作为默认后端存储。
6 changes: 6 additions & 0 deletions example/helm/prometheusalert/config/app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ logtype=file
logpath=logs/prometheusalertcenter.log
#转换Prometheus,graylog告警消息的时区为CST时区(如默认已经是CST时区,请勿开启)
prometheus_cst_time=0
#数据库驱动,支持sqlite3,mysql,如使用mysql,请开启db_host,db_user,db_password,db_name的注释
db_driver=sqlite3
#db_host=127.0.0.1:3306
#db_user=root
#db_password=root
#db_name=prometheusalert

#---------------------↓webhook-----------------------
#是否开启钉钉告警通道,可同时开始多个通道0为关闭,1为开启
Expand Down
10 changes: 8 additions & 2 deletions example/kubernetes/PrometheusAlert-Deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ data:
logpath=logs/prometheusalertcenter.log
#转换Prometheus,graylog告警消息的时区为CST时区(如默认已经是CST时区,请勿开启)
prometheus_cst_time=0
#数据库驱动,支持sqlite3,mysql,如使用mysql,请开启db_host,db_user,db_password,db_name的注释
db_driver=sqlite3
#db_host=127.0.0.1:3306
#db_user=root
#db_password=root
#db_name=prometheusalert
#---------------------↓webhook-----------------------
#是否开启钉钉告警通道,可同时开始多个通道0为关闭,1为开启
Expand Down Expand Up @@ -164,7 +170,7 @@ data:
7MOOR_WEBCALL_SERVICENO=xxx
# 文本节点里被替换的变量,我配置的是text。如果被替换的变量不是text,请修改此配置
7MOOR_WEBCALL_VOICE_VAR=text
#---------------------↓telegram接口-----------------------
#是否开启telegram告警通道,可同时开始多个通道0为关闭,1为开启
open-tg=0
Expand All @@ -178,7 +184,7 @@ data:
TG_CHANNAME=xxxxx
#tg api地址, 可以配置为代理地址
#TG_API_PROXY="https://api.telegram.org/bot%s/%s"
#---------------------↓workwechat接口-----------------------
#是否开启workwechat告警通道,可同时开始多个通道0为关闭,1为开启
open-workwechat=0
Expand Down
Binary file modified example/linux/PrometheusAlert
Binary file not shown.
Loading

0 comments on commit 247abb7

Please sign in to comment.