template_edit.html 14 KB

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