template_add.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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="/template" 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-12">
  46. <!-- text input -->
  47. <div class="form-group">
  48. <label>*模版名称</label>
  49. <input type="text" id="name" name="name" class="form-control" placeholder="模版名称不可重复且必须为英文字母,如prometheustpl">
  50. </div>
  51. </div>
  52. </div>
  53. <br />
  54. <div class="row">
  55. <div class="col-sm-6">
  56. <!-- select -->
  57. <div class="form-group">
  58. <label>*模版类型</label>
  59. <select class="form-control" name="type" id="type" onchange="typeChange()">
  60. <option value="dd">钉钉</option>
  61. <option value="wx">企业微信</option>
  62. <option value="workwechat">企业微信应用</option>
  63. <option value="fs">飞书</option>
  64. <option value="webhook">WebHook</option>
  65. <option value="txdx">腾讯云短信</option>
  66. <option value="txdh">腾讯云电话</option>
  67. <option value="alydx">阿里云短信</option>
  68. <option value="alydh">阿里云电话</option>
  69. <option value="hwdx">华为云短信</option>
  70. <option value="bddx">百度云短信</option>
  71. <option value="rlydh">容联云电话</option>
  72. <option value="7moordx">七陌短信</option>
  73. <option value="7moordh">七陌语音电话</option>
  74. <option value="email">Email</option>
  75. <option value="tg">Telegram</option>
  76. <option value="rl">百度Hi(如流)</option>
  77. <option value="voice">语音播报</option>
  78. <option value="fsapp">飞书机器人应用</option>
  79. </select>
  80. </div>
  81. </div>
  82. <div class="col-sm-6">
  83. <!-- select -->
  84. <div class="form-group">
  85. <label>*模版用途</label>
  86. <select class="form-control" name="use" id="use">
  87. <option value="Prometheus">Prometheus</option>
  88. <option value="Graylog2">Graylog2</option>
  89. <option value="Graylog3">Graylog3</option>
  90. <option value="Grafana">Grafana</option>
  91. <option value="SonarQube">SonarQube</option>
  92. <option value="Jenkins">Jenkins</option>
  93. <option value="WebHook">WebHook</option>
  94. <option value="ALiYun">阿里云-云监控</option>
  95. <option value="Other">Other</option>
  96. </select>
  97. </div>
  98. </div>
  99. </div>
  100. <br />
  101. <div class="row">
  102. <div class="col-sm-6">
  103. <!-- textarea -->
  104. <div class="form-group">
  105. <label>*模版内容:</label>
  106. <textarea class="form-control" style="color:#dc1aa9;background-color:black" cols="30" rows="10" id="content" name="content" placeholder="模版内容请参照go语言模版进行填写,匹配的JSON内容可在PrometheusAlert的日志中寻找对应监控告警系统发来的消息"></textarea>
  107. </div>
  108. </div>
  109. <div class="col-sm-6">
  110. <!-- textarea -->
  111. <div class="form-group">
  112. <label>消息协议JSON内容:</label>
  113. <textarea class="form-control" style="color:white;background-color:black" cols="30" rows="10" id="pjson" name="pjson" placeholder="可在PrometheusAlert日志中查找"></textarea>
  114. </div>
  115. </div>
  116. </div>
  117. <br />
  118. <div class="row">
  119. <div id="Purl" class="col-sm-6">
  120. <!-- text input -->
  121. <div class="form-group">
  122. <label id="typestr">钉钉机器人地址</label>
  123. <input type="text" id="purl" class="form-control" name="purl" value="">
  124. </div>
  125. </div>
  126. <div id="Pat" class="col-sm-6">
  127. <!-- text input -->
  128. <div class="form-group">
  129. <label id="typestr">@某人</label>
  130. <input type="text" id="pat" class="form-control" name="pat" value="" placeholder="钉钉@使用的是手机号码,企业微信机器人@使用的是用户帐号,飞书V2 @使用的是用户Email邮箱">
  131. </div>
  132. </div>
  133. <div id="Party" class="col-sm-6" style="display:none">
  134. <!-- text input -->
  135. <div class="form-group">
  136. <label id="typestr">接受部门</label>
  137. <input type="text" id="pparty" class="form-control" name="pparty" value="">
  138. </div>
  139. </div>
  140. <div id="Tag" class="col-sm-6" style="display:none">
  141. <!-- text input -->
  142. <div class="form-group">
  143. <label id="typestr">接受标签</label>
  144. <input type="text" id="ptag" class="form-control" name="ptag" value="">
  145. </div>
  146. </div>
  147. </div>
  148. <br />
  149. <div class="text-right">
  150. <span style="color:red;font-weight:bold">进行模版测试前请先点击保存模版</span>
  151. <a class="btn btn-app bg-success" onclick="savetpl();">
  152. <i class="fas fa-save"></i> 保存模版
  153. </a>
  154. <a class="btn btn-app bg-info" onclick="sendtest();">
  155. <i class="fas fa-bullhorn"></i> 模版测试
  156. </a>
  157. </div>
  158. </form>
  159. </div>
  160. <!-- /.card-body -->
  161. <div class="card-footer">
  162. 特别提醒:自定义模板仅支持 /prometheusalert 接口,其他接口均为固定模版接口,不支持自定义模板
  163. </div>
  164. <!-- /.card-footer-->
  165. </div>
  166. <!-- /.card -->
  167. </section>
  168. <!-- /.content -->
  169. </div>
  170. <!-- /.content-wrapper -->
  171. {{template "endhtml"}}
  172. <script>
  173. function typeChange(){
  174. var objS = document.getElementById("type");
  175. var typeStr = document.getElementById("typestr");
  176. var typeSelect = objS.options[objS.selectedIndex].value;
  177. if (typeSelect=="dd"){
  178. typeStr.innerText="钉钉机器人地址";
  179. document.getElementById("Purl").style.display="";
  180. document.getElementById("Pat").style.display="";
  181. document.getElementById("Party").style.display="none";
  182. document.getElementById("Tag").style.display="none";
  183. } else if(typeSelect=="wx"){
  184. typeStr.innerText="微信机器人地址";
  185. document.getElementById("Purl").style.display="";
  186. document.getElementById("Pat").style.display="";
  187. document.getElementById("Party").style.display="none";
  188. document.getElementById("Tag").style.display="none";
  189. } else if(typeSelect=="fs"){
  190. typeStr.innerText="飞书机器人地址";
  191. document.getElementById("Purl").style.display="";
  192. document.getElementById("Pat").style.display="";
  193. document.getElementById("Party").style.display="none";
  194. document.getElementById("Tag").style.display="none";
  195. } else if(typeSelect=="fsapp"){
  196. typeStr.innerText="飞书 用户open_id、user_id、union_ids、部门open_department_id";
  197. document.getElementById("Purl").style.display="none";
  198. document.getElementById("Pat").style.display="";
  199. document.getElementById("Party").style.display="none";
  200. document.getElementById("Tag").style.display="none";
  201. } else if(typeSelect=="voice"){
  202. typeStr.innerText="";
  203. document.getElementById("Purl").style.display="none";
  204. document.getElementById("Pat").style.display="none";
  205. document.getElementById("Party").style.display="none";
  206. document.getElementById("Tag").style.display="none";
  207. } else if(typeSelect=="webhook"){
  208. typeStr.innerText="WebHook地址";
  209. document.getElementById("Purl").style.display="";
  210. document.getElementById("Pat").style.display="none";
  211. document.getElementById("Party").style.display="none";
  212. document.getElementById("Tag").style.display="none";
  213. } else if(typeSelect=="email"){
  214. typeStr.innerText="邮箱(多个请以,隔开)";
  215. document.getElementById("Purl").style.display="";
  216. document.getElementById("Pat").style.display="none";
  217. document.getElementById("Party").style.display="none";
  218. document.getElementById("Tag").style.display="none";
  219. } else if(typeSelect=="rl"){
  220. typeStr.innerText="百度Hi(如流)群id";
  221. document.getElementById("Purl").style.display="";
  222. document.getElementById("Pat").style.display="none";
  223. document.getElementById("Party").style.display="none";
  224. document.getElementById("Tag").style.display="none";
  225. } else if(typeSelect=="workwechat"){
  226. typeStr.innerText="接受用户";
  227. document.getElementById("Purl").style.display="";
  228. document.getElementById("Pat").style.display="none";
  229. document.getElementById("Party").style.display="";
  230. document.getElementById("Tag").style.display="";
  231. } else{
  232. typeStr.innerText="手机号";
  233. document.getElementById("Purl").style.display="";
  234. document.getElementById("Pat").style.display="none";
  235. document.getElementById("Party").style.display="none";
  236. document.getElementById("Tag").style.display="none";
  237. }
  238. }
  239. function savetpl(){
  240. var uname=document.getElementById("name");
  241. if (uname.value.length==0){
  242. alert('模版名称不能为空');
  243. return
  244. };
  245. var ucontent=document.getElementById("content");
  246. if (ucontent.value.length==0){
  247. alert('模版内容不能为空');
  248. return
  249. };
  250. $.ajax({
  251. type: "POST",
  252. dataType: "json",
  253. url: '{{ urlfor "MainController.AddTpl"}}',
  254. data: $('#formtpl').serialize(),
  255. success: function (result) {
  256. console.log(result);
  257. if (result == null) {
  258. alert("模版保存成功!");
  259. } else {
  260. alert(result);
  261. };
  262. },
  263. });
  264. }
  265. function sendtest(){
  266. var uname=document.getElementById("name");
  267. var utype=document.getElementById("type");
  268. var upjson=document.getElementById("pjson");
  269. var upurl=document.getElementById("purl");
  270. var upat=document.getElementById("pat");
  271. var upparty=document.getElementById("pparty");
  272. var uptag=document.getElementById("ptag");
  273. var sendurl="";
  274. if (utype.value=="dd"){
  275. sendurl='{{ urlfor "PrometheusAlertController.PrometheusAlert"}}?type='+utype.value+'&tpl='+uname.value+'&ddurl='+upurl.value+'&at='+upat.value;
  276. } else if(utype.value=="wx"){
  277. sendurl='{{ urlfor "PrometheusAlertController.PrometheusAlert"}}?type='+utype.value+'&tpl='+uname.value+'&wxurl='+upurl.value+'&at='+upat.value;
  278. } else if(utype.value=="fs"){
  279. sendurl='{{ urlfor "PrometheusAlertController.PrometheusAlert"}}?type='+utype.value+'&tpl='+uname.value+'&fsurl='+upurl.value+'&at='+upat.value;
  280. } else if(utype.value=="fsapp"){
  281. sendurl='{{ urlfor "PrometheusAlertController.PrometheusAlert"}}?type='+utype.value+'&tpl='+uname.value+'&at='+upat.value;
  282. } else if(utype.value=="webhook"){
  283. sendurl='{{ urlfor "PrometheusAlertController.PrometheusAlert"}}?type='+utype.value+'&tpl='+uname.value+'&webhookurl='+upurl.value;
  284. } else if(utype.value=="email"){
  285. sendurl='{{ urlfor "PrometheusAlertController.PrometheusAlert"}}?type='+utype.value+'&tpl='+uname.value+'&email='+upurl.value;
  286. } else if(utype.value=="rl"){
  287. sendurl='{{ urlfor "PrometheusAlertController.PrometheusAlert"}}?type='+utype.value+'&tpl='+uname.value+'&groupid='+upurl.value;
  288. } else if(utype.value=="workwechat"){
  289. sendurl='{{ urlfor "PrometheusAlertController.PrometheusAlert"}}?type='+utype.value+'&tpl='+uname.value+'&wxuser='+upurl.value+'&wxparty='+upparty.value+'&wxtag='+uptag.value;
  290. } else{
  291. sendurl='{{ urlfor "PrometheusAlertController.PrometheusAlert"}}?type='+utype.value+'&tpl='+uname.value+'&phone='+upurl.value;
  292. }
  293. if (upjson.value.length==0){
  294. alert('消息协议JSON内容不能为空');
  295. }else{
  296. var json_data = JSON.stringify(upjson.value);
  297. $.ajax({
  298. url: sendurl,
  299. async: false,
  300. type: "post",
  301. data: upjson.value,
  302. success: function (data, status) {
  303. alert(data);
  304. },
  305. });
  306. };
  307. }
  308. </script>
  309. {{template "jshtml"}}