Skip to content

Commit

Permalink
更新example示例
Browse files Browse the repository at this point in the history
  • Loading branch information
jikun.zhang committed Nov 11, 2021
1 parent c7d130c commit 5172c1e
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 58 deletions.
Binary file modified example/linux/PrometheusAlert
Binary file not shown.
Binary file modified example/linux/db/PrometheusAlertDB.db
Binary file not shown.
25 changes: 25 additions & 0 deletions example/linux/db/prometheusalert.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,28 @@ INSERT INTO `prometheus_alert_d_b` VALUES ('26', 'dd', 'Jenkins', 'jenkins-dd-ex
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');
INSERT INTO `prometheus_alert_d_b` VALUES ('28', 'workwechat', 'Prometheus', 'prometheus-wechatapp', '{{ $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 ('29', 'rl', 'Prometheus', 'prometheus-ruliu', '{{ $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');


CREATE TABLE `alert_record` (
`id` bigint NOT NULL AUTO_INCREMENT,
`send_type` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`alertname` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`alert_level` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`business_type` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`instance` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`starts_at` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`ends_at` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`summary` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`description` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`handle_status` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`alert_status` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`alert_json` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`remark` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`revision` int NOT NULL DEFAULT '0',
`created_by` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`created_time` datetime NOT NULL,
`updated_by` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`updated_time` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

73 changes: 45 additions & 28 deletions example/linux/views/markdown_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,59 @@
{{template "head" .}}
<div class="bs-docs-header">
<div class="container">
<label class="col-sm-2">MarkDown测试</label>
<label class="col-sm-2">自定义模板测试</label>
</div>
</div>
<form class="form-horizontal" method="POST" action="##" enctype="multipart/form-data" onsubmit="return false" id="formtpl">
<div class="container">
<div class="bs-example" >
<label>*MarkDown内容:</label>
<label>*Json内容:</label>
<br />
<textarea id="content" name="content" cols="30" rows="10" class="form-control" placeholder="自定义Markdown内容文本" onkeyup=showHtml()>
[Prometheus故障恢复信息](https://prometheus.com)

**[测试告警消息Markdown](https://alertmanager.com)**

`告警级别:`严重

`开始时间:`2021-05-27T12:28:37.83Z

`结束时间:`2021-05-28T00:39:07.83Z

`故障主机IP:`127.0.0.1:80

**Too Many Alert Message PrometheusAlert**
</textarea>
<textarea id="jsoncontent" name="jsoncontent" cols="30" rows="10" class="form-control" placeholder="原始Json内容文本"></textarea>
<br />
<label>*模版内容:</label>
<br />
<textarea id="tplcontent" name="tplcontent" cols="30" rows="10" class="form-control" placeholder="自定义模版内容文本"></textarea>
<br />
<div class="text-right">
<button type="button" class="btn btn-primary" onclick="showHtml();">查看效果</button>
</div>
</div>
</div>
</form>
<div class="container">
<label>显示效果:</label>
<label>显示效果:(效果仅供参考,因部分机器人对markdown的支持不同,可能渲染的结果会不尽相同)</label>
<div id='MarkdownHtml' class="bs-example"></div>
<script type="text/javascript" src="/static/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/static/js/marked.min.js"></script>
<script type="text/javascript">
$(function () {
showHtml();
})
function showHtml(){
$("#MarkdownHtml").html(marked($("#content").val()));
};
</script>
</div>

<script type="text/javascript" src="/static/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/static/js/marked.min.js"></script>
<script type="text/javascript">
function showHtml(){
var jsoncontent=document.getElementById("jsoncontent");
var tplcontent=document.getElementById("tplcontent");

if (jsoncontent.value.length==0){
alert('原始Json内容文本不能为空');
return
};

if (tplcontent.value.length==0){
alert('自定义模版内容文本不能为空');
return
};

$.ajax({
type: "POST",
dataType: "json",
url: '{{ urlfor "MainController.MarkdownTest"}}',
data: $('#formtpl').serialize(),
success: function (result) {
console.log(result);
$("#MarkdownHtml").html(marked(result));
},
});

};
</script>
{{template "endhtml"}}
1 change: 1 addition & 0 deletions example/linux/views/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
{{if eq .Tpltype "email"}}Email{{end}}
{{if eq .Tpltype "tg"}}Telegram{{end}}
{{if eq .Tpltype "rl"}}百度Hi(如流){{end}}
{{if eq .Tpltype "bark"}}Bark(iPhone推送){{end}}
</th>
<th>{{if eq .Tpluse "ALiYun"}}阿里云-云监控{{else}}{{.Tpluse}}{{end}}</th>
<th>
Expand Down
6 changes: 5 additions & 1 deletion example/linux/views/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@
<th>百度Hi(如流)</th>
<th><button class="btn btn-primary" data-toggle='modal' id="bdrl">告警测试</button></th>
</tr>

<tr>
<th>17</th>
<th>Bark(iPhone推送)</th>
<th><button class="btn btn-primary" data-toggle='modal' id="bark">告警测试</button></th>
</tr>
</tbody>
</table>
</div>
Expand Down
Binary file modified example/windows/PrometheusAlert.exe
Binary file not shown.
Binary file modified example/windows/db/PrometheusAlertDB.db
Binary file not shown.
25 changes: 25 additions & 0 deletions example/windows/db/prometheusalert.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,28 @@ INSERT INTO `prometheus_alert_d_b` VALUES ('26', 'dd', 'Jenkins', 'jenkins-dd-ex
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');
INSERT INTO `prometheus_alert_d_b` VALUES ('28', 'workwechat', 'Prometheus', 'prometheus-wechatapp', '{{ $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 ('29', 'rl', 'Prometheus', 'prometheus-ruliu', '{{ $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');


CREATE TABLE `alert_record` (
`id` bigint NOT NULL AUTO_INCREMENT,
`send_type` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`alertname` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`alert_level` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`business_type` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`instance` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`starts_at` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`ends_at` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`summary` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`description` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`handle_status` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`alert_status` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`alert_json` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`remark` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`revision` int NOT NULL DEFAULT '0',
`created_by` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`created_time` datetime NOT NULL,
`updated_by` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
`updated_time` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

73 changes: 45 additions & 28 deletions example/windows/views/markdown_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,59 @@
{{template "head" .}}
<div class="bs-docs-header">
<div class="container">
<label class="col-sm-2">MarkDown测试</label>
<label class="col-sm-2">自定义模板测试</label>
</div>
</div>
<form class="form-horizontal" method="POST" action="##" enctype="multipart/form-data" onsubmit="return false" id="formtpl">
<div class="container">
<div class="bs-example" >
<label>*MarkDown内容:</label>
<label>*Json内容:</label>
<br />
<textarea id="content" name="content" cols="30" rows="10" class="form-control" placeholder="自定义Markdown内容文本" onkeyup=showHtml()>
[Prometheus故障恢复信息](https://prometheus.com)

**[测试告警消息Markdown](https://alertmanager.com)**

`告警级别:`严重

`开始时间:`2021-05-27T12:28:37.83Z

`结束时间:`2021-05-28T00:39:07.83Z

`故障主机IP:`127.0.0.1:80

**Too Many Alert Message PrometheusAlert**
</textarea>
<textarea id="jsoncontent" name="jsoncontent" cols="30" rows="10" class="form-control" placeholder="原始Json内容文本"></textarea>
<br />
<label>*模版内容:</label>
<br />
<textarea id="tplcontent" name="tplcontent" cols="30" rows="10" class="form-control" placeholder="自定义模版内容文本"></textarea>
<br />
<div class="text-right">
<button type="button" class="btn btn-primary" onclick="showHtml();">查看效果</button>
</div>
</div>
</div>
</form>
<div class="container">
<label>显示效果:</label>
<label>显示效果:(效果仅供参考,因部分机器人对markdown的支持不同,可能渲染的结果会不尽相同)</label>
<div id='MarkdownHtml' class="bs-example"></div>
<script type="text/javascript" src="/static/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/static/js/marked.min.js"></script>
<script type="text/javascript">
$(function () {
showHtml();
})
function showHtml(){
$("#MarkdownHtml").html(marked($("#content").val()));
};
</script>
</div>

<script type="text/javascript" src="/static/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/static/js/marked.min.js"></script>
<script type="text/javascript">
function showHtml(){
var jsoncontent=document.getElementById("jsoncontent");
var tplcontent=document.getElementById("tplcontent");

if (jsoncontent.value.length==0){
alert('原始Json内容文本不能为空');
return
};

if (tplcontent.value.length==0){
alert('自定义模版内容文本不能为空');
return
};

$.ajax({
type: "POST",
dataType: "json",
url: '{{ urlfor "MainController.MarkdownTest"}}',
data: $('#formtpl').serialize(),
success: function (result) {
console.log(result);
$("#MarkdownHtml").html(marked(result));
},
});

};
</script>
{{template "endhtml"}}
1 change: 1 addition & 0 deletions example/windows/views/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
{{if eq .Tpltype "email"}}Email{{end}}
{{if eq .Tpltype "tg"}}Telegram{{end}}
{{if eq .Tpltype "rl"}}百度Hi(如流){{end}}
{{if eq .Tpltype "bark"}}Bark(iPhone推送){{end}}
</th>
<th>{{if eq .Tpluse "ALiYun"}}阿里云-云监控{{else}}{{.Tpluse}}{{end}}</th>
<th>
Expand Down
6 changes: 5 additions & 1 deletion example/windows/views/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@
<th>百度Hi(如流)</th>
<th><button class="btn btn-primary" data-toggle='modal' id="bdrl">告警测试</button></th>
</tr>

<tr>
<th>17</th>
<th>Bark(iPhone推送)</th>
<th><button class="btn btn-primary" data-toggle='modal' id="bark">告警测试</button></th>
</tr>
</tbody>
</table>
</div>
Expand Down

0 comments on commit 5172c1e

Please sign in to comment.