record.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. {{template "main" .}}
  2. <!-- Navbar -->
  3. <nav class="main-header navbar navbar-expand navbar-white navbar-light">
  4. <!-- Left navbar links -->
  5. <ul class="navbar-nav">
  6. <li class="nav-item">
  7. <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
  8. </li>
  9. <li class="nav-item d-none d-sm-inline-block">
  10. <a href="/record" class="nav-link">告警管理</a>
  11. </li>
  12. </ul>
  13. </nav>
  14. <!-- /.navbar -->
  15. <!-- Content Wrapper. Contains page content -->
  16. <div class="content-wrapper">
  17. <!-- Content Header (Page header) -->
  18. <section class="content-header">
  19. <div class="container-fluid">
  20. <div class="row mb-2">
  21. <div class="col-sm-6">
  22. <h1>告警记录查询</h1>
  23. </div>
  24. <div class="col-sm-6">
  25. <ol class="breadcrumb float-sm-right">
  26. <a href="javascript:if(confirm('确实要清空所有记录吗?清空后无法恢复'))location='/record/clean'" class="btn btn-default bg-danger">
  27. <i class="fas fa-inbox"></i> 清空记录
  28. </a>
  29. </ol>
  30. </div>
  31. </div>
  32. </div><!-- /.container-fluid -->
  33. </section>
  34. <!-- Main content -->
  35. <section class="content">
  36. <!-- Default box -->
  37. <div class="card">
  38. <div class="card-header">
  39. <h3 class="card-title" style="color:red">** 非实时告警展示</h3>
  40. <div class="card-tools">
  41. <button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
  42. <i class="fas fa-minus"></i>
  43. </button>
  44. <button type="button" class="btn btn-tool" data-card-widget="remove" title="Remove">
  45. <i class="fas fa-times"></i>
  46. </button>
  47. </div>
  48. </div>
  49. <div class="card-body">
  50. <table id="example1" class="table table-bordered table-striped">
  51. <thead>
  52. <tr>
  53. <th>告警名称</th>
  54. <th>开始时间</th>
  55. <th>结束时间</th>
  56. <th>级别</th>
  57. <th>Instance</th>
  58. <th>Summary</th>
  59. <th>Description</th>
  60. <th>告警状态</th>
  61. <th>Label</th>
  62. </tr>
  63. </thead>
  64. <tbody>
  65. {{range .Record}}
  66. <tr>
  67. <!--<td>{{.Id}}</td>-->
  68. <td>
  69. <span class="badge bg-primary">
  70. {{.Alertname}}
  71. </span>
  72. </td>
  73. <td>
  74. <span class="badge bg-warning">
  75. {{.StartsAt}}
  76. </span>
  77. </td>
  78. <td>
  79. {{if eq .EndsAt "0001-01-01T00:00:00Z"}}<span class="badge bg-warning">持续中</span>{{else}}{{if eq .EndsAt "0001-01-01 08:00:00"}}<span class="badge bg-warning">持续中</span>{{else}}<span class="badge bg-success">{{.EndsAt}}</span>{{end}}{{end}}
  80. </td>
  81. <td> <!-- 0 信息,1 警告,2 一般严重,3 严重,4 灾难 -->
  82. <span class="badge bg-navy">
  83. {{if eq .AlertLevel ""}}信息{{else}}
  84. {{if eq .AlertLevel "0"}}信息{{else}}
  85. {{if eq .AlertLevel "1"}}警告{{else}}
  86. {{if eq .AlertLevel "2"}}一般严重{{else}}
  87. {{if eq .AlertLevel "3"}}严重{{else}}
  88. {{if eq .AlertLevel "4"}}灾难{{else}}
  89. {{.AlertLevel}}
  90. {{end}}{{end}}{{end}}{{end}}{{end}}{{end}}
  91. </span>
  92. </td>
  93. <td>
  94. <span class="badge bg-fuchsia">
  95. {{.Instance}}
  96. </span>
  97. </td>
  98. <td>
  99. <span class="badge bg-olive">
  100. {{.Summary}}
  101. </span>
  102. </td>
  103. <td>
  104. <span class="badge bg-danger">
  105. {{.Description}}
  106. </span>
  107. </td>
  108. <td>
  109. {{if eq .AlertStatus "firing"}}<span class="badge bg-danger">告警</span>{{else}}<span class="badge bg-success">恢复</span>{{end}}
  110. </td>
  111. <td>
  112. {{.Labels}}
  113. <!--<span class="badge bg-gray">
  114. </span>-->
  115. </td>
  116. </tr>
  117. {{end}}
  118. </tbody>
  119. <tfoot>
  120. <tr>
  121. <th>告警名称</th>
  122. <th>开始时间</th>
  123. <th>结束时间</th>
  124. <th>级别</th>
  125. <th>Instance</th>
  126. <th>Summary</th>
  127. <th>Description</th>
  128. <th>告警状态</th>
  129. <th>Label</th>
  130. </tr>
  131. </tfoot>
  132. </table>
  133. </div>
  134. <!-- /.card-body -->
  135. <div class="card-footer">
  136. </div>
  137. <!-- /.card-footer-->
  138. </div>
  139. <!-- /.card -->
  140. </section>
  141. <!-- /.content -->
  142. </div>
  143. <!-- /.content-wrapper -->
  144. {{template "endhtml"}}
  145. <script>
  146. $(function () {
  147. $("#example1").DataTable({
  148. "responsive": true, "lengthChange": false, "autoWidth": false,
  149. "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
  150. }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');
  151. var tb = document.getElementById('example1');//获取表格的dom节点
  152. var td = tb.rows[1].cells[8];//获取0行0列的td单元格
  153. //td.innerHTML = '222';//动态修改表格的内容为222
  154. for(var i=1,rows=tb.rows.length; i<rows-1; i++){
  155. var td = tb.rows[i].cells[8];//获取0行0列的td单元格
  156. var str = td.innerHTML;
  157. var obj = JSON.parse(str);
  158. var table_str = ""
  159. for(var p in obj){
  160. //console.log(p + " " + obj[p]);
  161. table_str = table_str + '<span class="badge bg-gray">'+p+'='+obj[p]+'</span><br />'
  162. }
  163. td.innerHTML = table_str;
  164. }
  165. });
  166. </script>
  167. {{template "jshtml"}}