alertrouter_add.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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="/alertrouter" 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>
  25. </div><!-- /.container-fluid -->
  26. </section>
  27. <!-- Main content -->
  28. <section class="content">
  29. <!-- Default box -->
  30. <div class="card">
  31. <div class="card-header">
  32. <h3 class="card-title"></h3>
  33. <div class="card-tools">
  34. <button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
  35. <i class="fas fa-minus"></i>
  36. </button>
  37. <button type="button" class="btn btn-tool" data-card-widget="remove" title="Remove">
  38. <i class="fas fa-times"></i>
  39. </button>
  40. </div>
  41. </div>
  42. <div class="card-body">
  43. <form class="form-horizontal" method="POST" action="##" enctype="multipart/form-data" onsubmit="return false" id="formtpl">
  44. <div class="row">
  45. <div class="col-sm-6">
  46. <!-- text input -->
  47. <div class="form-group">
  48. <label>路由名称</label>
  49. <input type="text" id="name" class="form-control" name="name" value="">
  50. </div>
  51. </div>
  52. <div class="col-sm-6">
  53. <!-- select -->
  54. <div class="form-group">
  55. <label>生效模版名称</label>
  56. <select class="form-control" name="tpl_id" id="tpl_id" onchange="typeChange()">
  57. {{range .Template}}
  58. <option value="{{.Id}}">{{.Tplname}}</option>
  59. {{end}}
  60. </select>
  61. </div>
  62. </div>
  63. </div>
  64. <div class="row" style="display:none;">
  65. <div class="col-sm-6">
  66. <!-- text input -->
  67. <div class="form-group">
  68. <label>模版类型</label>
  69. <input type="text" id="tpltype" class="form-control" name="tpltype" value="" disabled>
  70. </div>
  71. </div>
  72. </div>
  73. <br />
  74. <div id="labelx">
  75. <div class="row">
  76. <div class="col-3">
  77. <!-- text input -->
  78. <div class="form-group">
  79. <label>Label Name: 可以去告警记录中查询</label>
  80. <input type="text" id="rules" class="form-control" name="rules" value="" placeholder="如 app">
  81. </div>
  82. </div>
  83. <div class="col-3">
  84. <!-- text input -->
  85. <div class="form-group">
  86. <label>Label Value: 可以去告警记录中查询</label>
  87. <input type="text" id="rulesvalue" class="form-control" name="rulesvalue" value="" placeholder="如 nginx">
  88. </div>
  89. </div>
  90. <div class="col-1 d-flex align-items-center">
  91. <!-- text input -->
  92. <div class="form-check">
  93. <input id="rulesregex" class="form-check-input" name="rulesregex" type="checkbox">
  94. <label class="form-check-label">Regex</label>
  95. </div>
  96. </div>
  97. </div>
  98. <br />
  99. </div>
  100. <div class="row">
  101. <div class="col-sm-6">
  102. <!-- text input -->
  103. <div class="form-group">
  104. <button id='labeladd' type="button" class="btn btn-info btn-flat"><i class="far fa-plus-square"></i></button>
  105. </div>
  106. </div>
  107. </div>
  108. <br />
  109. <div class="row">
  110. <div id="Purl" class="col-sm-6">
  111. <!-- text input -->
  112. <div class="form-group">
  113. <label id="typestr">钉钉机器人地址</label>
  114. <input type="text" id="purl" class="form-control" name="purl" value="">
  115. </div>
  116. </div>
  117. <div id="Pat" class="col-sm-6">
  118. <!-- text input -->
  119. <div class="form-group">
  120. <label id="typestr">@某人</label>
  121. <input type="text" id="pat" class="form-control" name="pat" value="" placeholder="钉钉@使用的是手机号码,企业微信机器人@使用的是用户帐号,">
  122. <!-- <input type="text" id="pat" class="form-control" name="pat" value="" placeholder="钉钉@使用的是手机号码,企业微信机器人@使用的是用户帐号,飞书V2 @使用的是用户Email邮箱"> -->
  123. </div>
  124. </div>
  125. <div id="Party" class="col-sm-6" style="display:none">
  126. <!-- text input -->
  127. <div class="form-group">
  128. <label id="typestr">接受部门</label>
  129. <input type="text" id="pparty" class="form-control" name="pparty" value="">
  130. </div>
  131. </div>
  132. <div id="Tag" class="col-sm-6" style="display:none">
  133. <!-- text input -->
  134. <div class="form-group">
  135. <label id="typestr">接受标签</label>
  136. <input type="text" id="ptag" class="form-control" name="ptag" value="">
  137. </div>
  138. </div>
  139. </div>
  140. <br />
  141. <div class="text-right">
  142. <a class="btn btn-app bg-success" onclick="savetpl();">
  143. <i class="fas fa-save"></i> 保存路由
  144. </a>
  145. </div>
  146. </form>
  147. </div>
  148. <!-- /.card-body -->
  149. <div class="card-footer">
  150. </div>
  151. <!-- /.card-footer-->
  152. </div>
  153. <!-- /.card -->
  154. </section>
  155. <!-- /.content -->
  156. </div>
  157. <!-- /.content-wrapper -->
  158. {{template "endhtml"}}
  159. <script>
  160. $(function () {
  161. typeChange();
  162. $('#labeladd').click(function(){
  163. var labeldiv='<div class="row"> <div class="col-3"> <div class="form-group"> <label>Label Name</label> <input type="text" id="rules" class="form-control" name="rules" value="" placeholder="如 app"> </div> </div> <div class="col-3"> <div class="form-group"> <label>Label Value</label> <input type="text" id="rulesvalue" class="form-control" name="rulesvalue" value="" placeholder="如 nginx"> </div> </div> <div class="col-1 d-flex align-items-center"> <div class="form-check"> <input id="rulesregex" class="form-check-input" name="rulesregex" type="checkbox"> <label class="form-check-label">Regex</label> </div> </div> <div class="col-sm-1 d-flex align-items-center"> <div class="form-group"> <button id="labeldel" type="button" class="btn btn-danger btn-flat"><i class="fa fa-trash"></i></button> </div> </div></div> <br />';
  164. $('#labelx').append(labeldiv);
  165. });
  166. $("#labelx").delegate('#labeldel','click',function(){
  167. $(this).parents(".row").remove();
  168. });
  169. })
  170. function typeChange(){
  171. var tpl_id = document.getElementById("tpl_id");
  172. var tpltype = document.getElementById("tpltype");
  173. var typeStr = document.getElementById("typestr");
  174. var tpl_idSelect = tpl_id.options[tpl_id.selectedIndex].value; //get id
  175. var tpls={{.Template}};
  176. tpls.forEach(function(tpl){
  177. if (tpl.Id==tpl_idSelect){
  178. tpltype.value=tpl.Tpltype
  179. }
  180. });
  181. if (tpltype.value=="dd"){
  182. typeStr.innerText="钉钉机器人地址(多个请以,隔开)";
  183. document.getElementById("Purl").style.display="";
  184. document.getElementById("Pat").style.display="";
  185. document.getElementById("Party").style.display="none";
  186. document.getElementById("Tag").style.display="none";
  187. } else if(tpltype.value=="wx"){
  188. typeStr.innerText="微信机器人地址(多个请以,隔开)";
  189. document.getElementById("Purl").style.display="";
  190. document.getElementById("Pat").style.display="";
  191. document.getElementById("Party").style.display="none";
  192. document.getElementById("Tag").style.display="none";
  193. } else if(tpltype.value=="fs"){
  194. typeStr.innerText="飞书机器人地址(多个请以,隔开)";
  195. document.getElementById("Purl").style.display="";
  196. document.getElementById("Pat").style.display="";
  197. document.getElementById("Party").style.display="none";
  198. document.getElementById("Tag").style.display="none";
  199. } else if(tpltype.value=="fsapp"){
  200. typeStr.innerText="飞书 用户open_id、user_id、union_ids、部门open_department_id";
  201. document.getElementById("Purl").style.display="none";
  202. document.getElementById("Pat").style.display="";
  203. document.getElementById("Party").style.display="none";
  204. document.getElementById("Tag").style.display="none";
  205. } else if(tpltype.value=="voice"){
  206. typeStr.innerText="";
  207. document.getElementById("Purl").style.display="none";
  208. document.getElementById("Pat").style.display="none";
  209. document.getElementById("Party").style.display="none";
  210. document.getElementById("Tag").style.display="none";
  211. } else if(tpltype.value=="webhook"){
  212. typeStr.innerText="webhook地址(多个请以,隔开)";
  213. document.getElementById("Purl").style.display="";
  214. document.getElementById("Pat").style.display="none";
  215. document.getElementById("Party").style.display="none";
  216. document.getElementById("Tag").style.display="none";
  217. } else if(tpltype.value=="email"){
  218. typeStr.innerText="邮箱(多个请以,隔开)";
  219. document.getElementById("Purl").style.display="";
  220. document.getElementById("Pat").style.display="none";
  221. document.getElementById("Party").style.display="none";
  222. document.getElementById("Tag").style.display="none";
  223. } else if(tpltype.value=="rl"){
  224. typeStr.innerText="百度Hi(如流)群id";
  225. document.getElementById("Purl").style.display="";
  226. document.getElementById("Pat").style.display="none";
  227. document.getElementById("Party").style.display="none";
  228. document.getElementById("Tag").style.display="none";
  229. } else if(tpltype.value=="workwechat"){
  230. alert("workwechat暂不支持告警路由,待后期开启!");
  231. /*typeStr.innerText="接受用户";
  232. document.getElementById("Pat").style.display="none";
  233. document.getElementById("Party").style.display="";
  234. document.getElementById("Tag").style.display="";*/
  235. } else{
  236. typeStr.innerText="手机号(多个请以,隔开)";
  237. document.getElementById("Purl").style.display="";
  238. document.getElementById("Pat").style.display="none";
  239. document.getElementById("Party").style.display="none";
  240. document.getElementById("Tag").style.display="none";
  241. }
  242. }
  243. function savetpl(){
  244. var uname=document.getElementById("rules");
  245. if (uname.value.length==0){
  246. alert('路由规则不能为空');
  247. return
  248. };
  249. var ucontent=document.getElementById("purl");
  250. if (ucontent.value.length==0){
  251. alert('url 或 手机号参数不能为空');
  252. return
  253. };
  254. //取到所有rules
  255. var RouterRules =new Array();
  256. $("#labelx > div").each(function() {
  257. var LabelMap={
  258. Name: $(this).find("#rules").val(),
  259. Value: $(this).find("#rulesvalue").val(),
  260. Regex: $(this).find("#rulesregex").is(":checked")
  261. };
  262. RouterRules.push(LabelMap);
  263. });
  264. var alert_router_json_str={
  265. RouterId: $('#id').val(),
  266. RouterName: $('#name').val(),
  267. RouterTplId: $('#tpl_id').val(),
  268. RouterPurl: $('#purl').val(),
  269. RouterPat: $('#pat').val(),
  270. Rules: RouterRules
  271. };
  272. var json_data = JSON.stringify(alert_router_json_str);
  273. $.ajax({
  274. type: "POST",
  275. dataType: "json",
  276. url: '{{ urlfor "MainController.AddRouter"}}',
  277. data: json_data,
  278. success: function (result) {
  279. if (result == null) {
  280. alert("告警路由保存成功!");
  281. window.location.replace("/alertrouter")
  282. } else {
  283. alert("告警路由保存失败!");
  284. };
  285. },
  286. });
  287. }
  288. </script>
  289. {{template "jshtml"}}