完成授权文件下载功能

This commit is contained in:
zhangxin10 2015-12-23 17:02:17 +08:00
parent 0573841923
commit 7b7e9259d4
13 changed files with 445 additions and 291 deletions

View File

@ -35,7 +35,7 @@ public class AlarmRuleCtl {
/***
* 查询用户默认规则
*
*
* @param root
* @return
* @throws Exception
@ -74,7 +74,7 @@ public class AlarmRuleCtl {
/***
* 查询用户默认规则
*
*
* @param root
* @return
* @throws Exception
@ -114,7 +114,7 @@ public class AlarmRuleCtl {
/***
* 创建用户默认规则
*
*
* @param root
* @return
* @throws Exception
@ -258,7 +258,7 @@ public class AlarmRuleCtl {
/***
* 创建用户默认规则
*
*
* @param root
* @return
* @throws Exception
@ -333,7 +333,6 @@ public class AlarmRuleCtl {
ruleMVO.setTodoType(todoType);
JSONObject confArgs = new JSONObject();
confArgs.put("period", period);
confArgs.put("excludeExceptions", json.get("excludeExceptions"));
if (Constants.TODO_TYPE_0.equals(todoType)) {
// 设置邮件相关的信息
JSONObject mailInfo = new JSONObject();

View File

@ -1,91 +1,116 @@
package com.ai.cloud.controller;
import com.ai.cloud.service.inter.IAuthFileSer;
import com.ai.cloud.service.inter.ISystemConfigSer;
import com.ai.cloud.util.Constants;
import com.ai.cloud.util.common.StringUtil;
import com.alibaba.fastjson.JSONObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.OutputStream;
import java.net.URLDecoder;
import java.net.URLEncoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import com.ai.cloud.util.Constants;
import com.ai.cloud.util.common.StringUtil;
import com.alibaba.fastjson.JSONObject;
import java.util.Map;
import java.util.Properties;
@Controller
public class AuthFileCtl {
private static Logger logger = LogManager.getLogger(AlarmRuleCtl.class);
private static Logger logger = LogManager.getLogger(AlarmRuleCtl.class);
@RequestMapping("/exportAuth/{appCode}")
public void exportApplicationAuthFile(HttpServletRequest request, HttpServletResponse response,
@PathVariable("appCode") String appCode) throws Exception {
HttpSession session = request.getSession();
String uid = (String) session.getAttribute("uid");
@Autowired
private IAuthFileSer authFileSer;
JSONObject reJson = new JSONObject();
@Autowired
private ISystemConfigSer systemConfigSer;
if (StringUtil.isBlank(uid)) {
reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "用户会话超时");
return ;
}
String filepath = "sky-walking.auth";
response.reset();
response.setContentType("application/octet-stream");
String fileName = URLDecoder.decode(filepath, "utf-8");
java.net.URLEncoder.encode(fileName, "utf-8");
response.addHeader("Content-Disposition",
"attachment;" + "filename=\"" + URLEncoder.encode(fileName, "utf-8") + "\"");
@RequestMapping("/exportAuth/{appCode}")
public void exportApplicationAuthFile(HttpServletRequest request, HttpServletResponse response,
@PathVariable("appCode") String appCode) throws Exception {
HttpSession session = request.getSession();
String uid = (String) session.getAttribute("uid");
StringBuilder sb = new StringBuilder("");
sb.append("测试魂牵梦萦魂牵梦萦" + "\r\n");
BufferedOutputStream output = null;
BufferedInputStream input = null;
OutputStream os = null;
try {
os = response.getOutputStream();
byte[] byt = sb.toString().getBytes();
os.write(byt);
} catch (Exception e) {
logger.error("导出 {} 应用制空权文件异常", appCode);
e.printStackTrace();
} finally {
os.flush();
os.close();
if (input != null) {
input.close();
}
if (output != null) {
output.close();
}
}
return;
}
@RequestMapping("/confAuthInfo/{appCode}")
public String confAuthInfo(HttpServletRequest request, HttpServletResponse response,
@PathVariable("appCode") String appCode) throws Exception {
HttpSession session = request.getSession();
String uid = (String) session.getAttribute("uid");
JSONObject reJson = new JSONObject();
JSONObject reJson = new JSONObject();
if (StringUtil.isBlank(uid)) {
reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "用户会话超时");
return;
}
if (StringUtil.isBlank(uid)) {
reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "用户会话超时");
return reJson.toJSONString();
}
return reJson.toJSONString();
}
String filepath = "sky-walking.auth";
response.reset();
response.setContentType("application/octet-stream");
String fileName = URLDecoder.decode(filepath, "utf-8");
java.net.URLEncoder.encode(fileName, "utf-8");
response.addHeader("Content-Disposition",
"attachment;" + "filename=\"" + URLEncoder.encode(fileName, "utf-8") + "\"");
Properties properties = authFileSer.queryAuthFile();
String propertyValue;
for (Map.Entry<Object, Object> value : properties.entrySet()) {
propertyValue = String.valueOf(value.getValue());
if (propertyValue.startsWith("#")) {
value.setValue(systemConfigSer.querySystemConfigByKey(propertyValue.substring(1)).getConfValue());
continue;
}
if (propertyValue.startsWith("$")){
if (request.getParameter((propertyValue.substring(1))) != null ) {
value.setValue(request.getParameter(propertyValue.substring(1)));
}
}
}
properties.setProperty("skywalking.user_id", uid);
properties.setProperty("skywalking.application_code", appCode);
BufferedOutputStream output = null;
BufferedInputStream input = null;
OutputStream os = null;
try {
os = response.getOutputStream();
//byte[] byt = sb.toString().getBytes();
properties.store(os, "test");
// os.write(byt);
} catch (Exception e) {
logger.error("导出 {} 应用制空权文件异常", appCode);
e.printStackTrace();
} finally {
os.flush();
os.close();
if (input != null) {
input.close();
}
if (output != null) {
output.close();
}
}
return;
}
@RequestMapping("/confAuthInfo/{appCode}")
public String confAuthInfo(HttpServletRequest request, HttpServletResponse response,
@PathVariable("appCode") String appCode) throws Exception {
HttpSession session = request.getSession();
String uid = (String) session.getAttribute("uid");
JSONObject reJson = new JSONObject();
if (StringUtil.isBlank(uid)) {
reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "用户会话超时");
return reJson.toJSONString();
}
return reJson.toJSONString();
}
}

View File

@ -0,0 +1,36 @@
package com.ai.cloud.dao.impl;
import com.ai.cloud.dao.inter.IAuthConfigMDAO;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.stereotype.Repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
@Repository
public class AuthConfigMDAO implements IAuthConfigMDAO {
@Autowired
private JdbcTemplate jdbcTemplate;
private static Logger logger = LogManager.getLogger(AuthConfigMDAO.class);
@Override
public Properties queryAllAuthConfig() {
final Properties properties = new Properties();
String sql = "select auth_file_config.key, auth_file_config.value from auth_file_config where auth_file_config.sts = ? ";
final Object[] params = new Object[]{"A"};
jdbcTemplate.query(sql, params,new RowCallbackHandler() {
@Override
public void processRow(ResultSet resultSet) throws SQLException {
properties.setProperty(resultSet.getString("key"), resultSet.getString("value"));
}
});
return properties;
}
}

View File

@ -0,0 +1,37 @@
package com.ai.cloud.dao.impl;
import com.ai.cloud.dao.inter.ISystemConfigMDAO;
import com.ai.cloud.vo.mvo.SystemConfigMVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.stereotype.Repository;
import java.sql.ResultSet;
import java.sql.SQLException;
@Repository
public class SystemConfigMDAO implements ISystemConfigMDAO {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public SystemConfigMVO querySystemConfigByKey(String key) {
final SystemConfigMVO systemConfigMVO = new SystemConfigMVO();
String sql = "SELECT config_id, conf_key, conf_value, val_type, val_desc from system_config where conf_key = ? and sts = ?";
final Object[] params = new Object[]{key, "A"};
jdbcTemplate.query(sql, params, new RowCallbackHandler() {
@Override
public void processRow(ResultSet resultSet) throws SQLException {
systemConfigMVO.setConfigId(resultSet.getString("config_id"));
systemConfigMVO.setConfKey(resultSet.getString("conf_key"));
systemConfigMVO.setConfValue(resultSet.getString("conf_value"));
systemConfigMVO.setValueType(resultSet.getString("val_type"));
systemConfigMVO.setValueDesc(resultSet.getString("val_desc"));
}
});
return systemConfigMVO;
}
}

View File

@ -0,0 +1,7 @@
package com.ai.cloud.dao.inter;
import java.util.Properties;
public interface IAuthConfigMDAO {
Properties queryAllAuthConfig();
}

View File

@ -0,0 +1,7 @@
package com.ai.cloud.dao.inter;
import com.ai.cloud.vo.mvo.SystemConfigMVO;
public interface ISystemConfigMDAO {
SystemConfigMVO querySystemConfigByKey(String key);
}

View File

@ -0,0 +1,20 @@
package com.ai.cloud.service.impl;
import com.ai.cloud.dao.inter.IAuthConfigMDAO;
import com.ai.cloud.service.inter.IAuthFileSer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Properties;
@Service
public class AuthFileSerImpl implements IAuthFileSer {
@Autowired
private IAuthConfigMDAO authConfigMDAO;
@Override
public Properties queryAuthFile() {
return authConfigMDAO.queryAllAuthConfig();
}
}

View File

@ -0,0 +1,19 @@
package com.ai.cloud.service.impl;
import com.ai.cloud.dao.inter.ISystemConfigMDAO;
import com.ai.cloud.service.inter.ISystemConfigSer;
import com.ai.cloud.vo.mvo.SystemConfigMVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SystemConfigSerImpl implements ISystemConfigSer {
@Autowired
private ISystemConfigMDAO iSystemConfigMDAO;
@Override
public SystemConfigMVO querySystemConfigByKey(String key) {
return iSystemConfigMDAO.querySystemConfigByKey(key);
}
}

View File

@ -0,0 +1,7 @@
package com.ai.cloud.service.inter;
import java.util.Properties;
public interface IAuthFileSer {
Properties queryAuthFile();
}

View File

@ -0,0 +1,8 @@
package com.ai.cloud.service.inter;
import com.ai.cloud.vo.mvo.SystemConfigMVO;
public interface ISystemConfigSer {
SystemConfigMVO querySystemConfigByKey(String key);
}

View File

@ -0,0 +1,50 @@
package com.ai.cloud.vo.mvo;
public class SystemConfigMVO {
private String configId;
private String confKey;
private String confValue;
private String valueType;
private String valueDesc;
public String getConfigId() {
return configId;
}
public void setConfigId(String configId) {
this.configId = configId;
}
public String getConfKey() {
return confKey;
}
public void setConfKey(String confKey) {
this.confKey = confKey;
}
public String getConfValue() {
return confValue;
}
public void setConfValue(String confValue) {
this.confValue = confValue;
}
public String getValueType() {
return valueType;
}
public void setValueType(String valueType) {
this.valueType = valueType;
}
public String getValueDesc() {
return valueDesc;
}
public void setValueDesc(String valueDesc) {
this.valueDesc = valueDesc;
}
}

View File

@ -0,0 +1,20 @@
#test
#Wed Dec 23 15:24:10 CST 2015
buriedpoint.businesskey_max_length=300
sender.retry_get_sender_wait_interval=2000
buffer.pool_size=5
senderchecker.check_polling_time=200
sender.is_off=false
sender.max_send_length=20000
consumer.max_consumer=2
consumer.max_wait_time=5
sender.max_copy_num=2
skywalking.application_code=test
consumer.consumer_fail_retry_wait_interval=50
skywalking.user_id=1
buriedpoint.printf=false
buriedpoint.exclusive_exceptions=
buriedpoint.max_exception_stack_length=4000
sender.connect_percent=100
buffer.buffer_max_size=18000
sender.servers_addr=127.0.0.1\:34000;

View File

@ -5,7 +5,7 @@
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Sky Walking</title>
<meta name="generator" content="Bootply"/>
<meta name="generator" content="Bootply" />
<meta name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1">
<link href="${base}/css/bootstrap.min.css" rel="stylesheet">
@ -49,7 +49,7 @@
<div class="form-group">
<label for="todoType" class="col-sm-4 control-label">告警操作:</label>
<div class="col-sm-4">
<select class="form-control" id="todoType">
<select class="form-control" id="todoType" >
<option value="0">发送邮件</option>
<option value="1">回调接口</option>
</select>
@ -81,12 +81,6 @@
<input type="text" class="form-control" id="urlCall" placeholder="回调接口地址">
</div>
</div>
<div class="form-group">
<label for="excludeExceptions" class="col-sm-4 control-label">异常过滤:</label>
<div class="col-sm-4">
<textarea class="form-control" id="excludeExceptions" rows="3" placeholder="过滤异常,需要配置异常的全名,多个以,分割"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-4">
<input type='hidden' id="ruleId">
@ -99,101 +93,9 @@
</div>
<div class="form-horizontal" id="authInfo" style="display:none">
<div class="form-group">
<label for="buriedpoint.printf" class="col-sm-4 control-label">是否打印数据:</label>
<label for="period" class="col-sm-4 control-label">需要排除的异常</label>
<div class="col-sm-4">
<select class="form-control" id="buriedpoint.printf">
<option value="true">是</option>
<option selected="selected" value="false">否</option>
</select>
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">埋点异常的最大长度(字节)</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="buriedpoint.max_exception_stack_length"
placeholder="埋点异常的最大长度(字节)" value="4000">
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">业务字段的最大长度(字节)</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="buriedpoint.max_exception_stack_length"
placeholder="业务字段的最大长度" value="300">
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">发送的最大长度(字节)</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="sender.max_send_length" placeholder="发送的最大长度" value="20000">
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">最大发送者的连接数阀比例(百分比)</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="sender.max_send_length" placeholder="最大发送者的连接数阀比例"
value="100">
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">sender的等待周期(秒)</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="sender.retry_get_sender_wait_interval"
placeholder="当没有Sender时,尝试获取sender的等待周期" value="2000">
</div>
</div>
<div class="form-group">
<label for="sender.is_off" class="col-sm-4 control-label">是否开启发送消息:</label>
<div class="col-sm-4">
<select class="form-control" id="sender.is_off">
<option value="true">是</option>
<option selected="selected" value="false">否</option>
</select>
</div>
</div>
<div class="form-group">
<label for="mailTemp" class="col-sm-4 control-label">发送服务端配置(,分隔)</label>
<div class="col-sm-4">
<textarea class="form-control" id="sender.servers_addr" rows="4"
placeholder="发送服务端配置">127.0.0.1:34000</textarea>
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">最大消费线程数:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="consumer.max_consumer" placeholder="最大消费线程数" value="2">
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">消费者最大等待时间(秒)</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="consumer.max_wait_time" placeholder="消费者最大等待时间" value="5">
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">发送失败等待时间(秒)</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="consumer.consumer_fail_retry_wait_interval"
placeholder="发送失败等待时间" value="50">
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">每个Buffer的最大个数</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="buffer.buffer_max_size" placeholder="每个Buffer的最大个数"
value="18000">
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">Buffer池的最大长度</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="buffer.pool_size" placeholder="Buffer池的最大长度" value="5">
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">发送检查线程检查周期(秒)</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="senderchecker.check_polling_time" placeholder="发送检查线程检查周期"
value="200">
<input type="text" class="form-control" id="exclusiveException" placeholder="java.lang.Exception,java.io.IOException">
</div>
</div>
<div class="form-group">
@ -210,9 +112,7 @@
&nbsp;
<button id="crtAlarm" type="button" class="btn btn-warning" href="#">默认告警规则</button>
&nbsp;
<button type="button" class="btn btn-success" href="#" onclick="window.location.reload(); return false;">
刷新
</button>
<button type="button" class="btn btn-success" href="#" onclick="window.location.reload(); return false;">刷新</button>
</caption>
<thead>
<tr>
@ -228,14 +128,9 @@
<th scope="row">${appInfo_index + 1}</th>
<td>${appInfo.appCode!}</td>
<td>
<button name="conf" appId="${appInfo.appId!}" appCode="${appInfo.appCode!}" type="button"
class="btn btn-default btn-xs">配置告警规则
</button>
<button name="exportAuthInfo" appId="${appInfo.appId!}" appCode="${appInfo.appCode!}" type="button"
class="btn btn-default btn-xs">生成授权
</button>
<button name="del" appId="${appInfo.appId!}" type="button" class="btn btn-default btn-xs">删除
</button>
<button name="conf" appId="${appInfo.appId!}" appCode="${appInfo.appCode!}" type="button" class="btn btn-default btn-xs">配置告警规则</button>
<button name="exportAuthInfo" appId="${appInfo.appId!}" appCode="${appInfo.appCode!}" type="button" class="btn btn-default btn-xs">生成授权文件</button>
<button name="del" appId="${appInfo.appId!}" type="button" class="btn btn-default btn-xs">删除</button>
</td>
</tr>
</#list>
@ -243,18 +138,21 @@
</#if>
</table>
</div>
<iframe id="authFiledownLoad" style="width:0px;height:0px;display:none"></iframe>
<div id="authFiledownLoad">
</div>
<#--<iframe id="authFiledownLoad" style="width:0px;height:0px;display:none"></iframe>-->
<!-- script references -->
<@common.importJavaScript />
<script type="text/javascript">
$().ready(function () {
$("#crtApp").bind("click", function () {
$().ready(function(){
$("#crtApp").bind("click",function(){
$("#cannelRuleBtn").click();
$("#createAppDiv").show();
});
$("#crtBtn").bind("click", function () {
if ($("#appCode").val() == '') {
$("#crtBtn").bind("click",function(){
if($("#appCode").val() == ''){
alert("请输入应用名称");
return false;
}
@ -262,31 +160,31 @@
$.ajax({
type: 'POST',
url: urlStr,
contentType: "application/json",
data: "{'appCode':'" + $("#appCode").val() + "'}",
contentType:"application/json",
data:"{'appCode':'" + $("#appCode").val() + "'}",
dataType: 'json',
async: false,
success: function (data) {
async : false,
success: function(data){
console.log(data);
var result = data.result;
if (result == 'OK') {
if(result == 'OK'){
alert(data.msg);
//$("#createAppDiv").hide();
window.location.reload();
} else {
}else{
alert(data.msg);
}
},
error: function (xhr, type) {
error: function(xhr, type){
alert("操作失败");
}
});
});
$("button[name='del']").each(function () {
$(this).bind("click", function () {
$("button[name='del']").each(function(){
$(this).bind("click",function(){
var appId = $(this).attr("appId");
if (appId < 0) {
if(appId < 0){
alert("请选择应用");
return false;
}
@ -294,37 +192,37 @@
$.ajax({
type: 'POST',
url: urlStr,
contentType: "application/json",
data: {},
contentType:"application/json",
data:{},
dataType: 'json',
async: false,
success: function (data) {
async : false,
success: function(data){
console.log(data);
var result = data.result;
if (result == 'OK') {
if(result == 'OK'){
alert(data.msg);
window.location.reload();
} else {
}else{
alert(data.msg);
}
},
error: function (xhr, type) {
error: function(xhr, type){
alert("操作失败");
}
});
});
});
$("#cannelBtn").bind("click", function () {
$("#cannelBtn").bind("click",function(){
$("#appCode").val("");
$("#createAppDiv").hide();
});
$("#cannelRuleBtn").bind("click", function () {
$("#cannelRuleBtn").bind("click",function(){
$("#crtAlarmDiv").hide();
});
$("#crtAlarm").bind("click", function () {
$("#crtAlarm").bind("click",function(){
$("#cannelBtn").click();
$("#crtAlarmDiv").show();
@ -332,58 +230,57 @@
$.ajax({
type: 'POST',
url: urlStr,
contentType: "application/json",
data: "{}",
contentType:"application/json",
data:"{}",
dataType: 'json',
async: false,
success: function (data) {
async : false,
success: function(data){
console.log(data);
var result = data.result;
$("#isGlobal").val("1");
$("#appName").text("所有应用");
if (result == 'OK') {
if(result == 'OK'){
var obj = jQuery.parseJSON(data.data);
var confArg = jQuery.parseJSON(obj.configArgs);
$("#period").val(confArg.period);
$("#todoType").val(obj.todoType).change();
if (obj.todoType == 1) {
if(obj.todoType == 1){
$("#urlCall").val(confArg.urlInfo.urlCall);
} else {
}else {
$("#mailTo").val(confArg.mailInfo.mailTo);
$("#mailCc").val(confArg.mailInfo.mailCc);
$("#mailTemp").val(confArg.mailInfo.mailTemp);
}
$("#excludeExceptions").val(confArg.mailInfo.excludeExceptions);
$("#ruleId").val(obj.ruleId);
$("#crtRuleBtn").text("修改规则");
$("#cannelRuleBtn").text("取消修改");
$("#appId").val("");
}
},
error: function (xhr, type) {
error: function(xhr, type){
alert("操作失败");
}
});
});
$("#todoType").bind("change", function () {
if ($(this).val() == 0) {
$("#todoType").bind("change",function(){
if($(this).val() == 0){
$("#mailTempDiv").show();
$("#callBackDiv").hide();
} else if ($(this).val() == 1) {
}else if($(this).val() == 1){
$("#mailTempDiv").hide();
$("#callBackDiv").show();
}
});
$("button[name='conf']").each(function () {
$(this).bind("click", function () {
$("button[name='conf']").each(function(){
$(this).bind("click",function(){
$("#cannelBtn").click();
$("#crtAlarmDiv").show();
var appId = $(this).attr("appId");
var appCode = $(this).attr("appCode");
if (appId < 0) {
if(appId < 0){
alert("请选择应用");
return false;
}
@ -392,34 +289,33 @@
$.ajax({
type: 'POST',
url: urlStr,
contentType: "application/json",
data: "{}",
contentType:"application/json",
data:"{}",
dataType: 'json',
async: false,
success: function (data) {
async : false,
success: function(data){
console.log(data);
var result = data.result;
$("#isGlobal").val("0");
$("#appId").val(appId);
if (result == 'OK') {
if(result == 'OK'){
$("#appName").text(appCode);
var obj = jQuery.parseJSON(data.data);
var confArg = jQuery.parseJSON(obj.configArgs);
$("#period").val(confArg.period);
$("#todoType").val(obj.todoType).change();
if (obj.todoType == 1) {
if(obj.todoType == 1){
$("#urlCall").val(confArg.urlInfo.urlCall);
} else {
}else {
$("#mailTo").val(confArg.mailInfo.mailTo);
$("#mailCc").val(confArg.mailInfo.mailCc);
$("#mailTemp").val(confArg.mailInfo.mailTemp);
}
$("#excludeExceptions").val(confArg.excludeExceptions);
$("#ruleId").val(obj.ruleId);
$("#crtRuleBtn").text("修改规则");
$("#cannelRuleBtn").text("取消修改");
} else {
$("#appName").html(appCode + "(<b>使用默认规则</b>)");
}else{
$("#appName").html(appCode+"(<b>使用默认规则</b>)");
$("#period").val("");
$("#todoType").val("0").change();
$("#urlCall").val("");
@ -427,12 +323,11 @@
$("#mailCc").val("");
$("#mailTemp").val("");
$("#ruleId").val("");
$("#excludeExceptions").val("");
$("#crtRuleBtn").text("创建规则");
$("#cannelRuleBtn").text("取消创建");
}
},
error: function (xhr, type) {
error: function(xhr, type){
alert("操作失败");
}
});
@ -440,21 +335,21 @@
});
//创建规则操作
$("#crtRuleBtn").bind("click", function () {
$("#crtRuleBtn").bind("click",function(){
var ruleId = $("#ruleId").val();
var appId = $("#appId").val();//可空
var period = $("#period").val();//不可空
if (period == null || period.length < 1) {
if(period == null || period.length < 1){
alert("告警频率不能为空");
return false;
}
var isGlobal = $("#isGlobal").val();//不可空
if (isGlobal == null || isGlobal.length < 1) {
if(isGlobal == null || isGlobal.length < 1){
alert("规则标识不能为空");
return false;
} else {
if (isGlobal == 0) {
if (appId == null || appId.length < 1) {
}else{
if(isGlobal ==0){
if(appId == null || appId.length < 1){
alert("应用标识不能为空");
return false;
}
@ -462,75 +357,74 @@
}
var todoType = $("#todoType").val();//不可空
if (todoType == null || todoType.length < 1) {
if(todoType == null || todoType.length < 1){
alert("告警操作不能为空");
return false;
}
var urlCall = $("#urlCall").val();
var mailTemp = $("#mailTemp").val();
var todoContent = "";
if (todoType == 0) {
if (mailTemp == null || mailTemp.length < 1) {
if(todoType == 0){
if(mailTemp == null || mailTemp.length < 1){
alert("邮件模板不能为空");
return false;
}
var mailTo = $("#mailTo").val();
var mailCc = $("#mailCc").val();
} else if (todoType == 1) {
if (urlCall == null || urlCall.length < 1) {
}else if(todoType == 1){
if(urlCall == null || urlCall.length < 1){
alert("回调接口不能为空");
return false;
}
} else {
}else{
alert("告警规则不能为空");
return false;
}
var ruleId = $("#ruleId").val();
var excludeExceptions = $("#excludeExceptions").val();
var jsonData = "";
if (ruleId > 0) {
if(ruleId > 0){
//调用修改规则
if (ruleId == null || ruleId.length < 0) {
if(ruleId == null || ruleId.length < 0){
alert("告警规则不能为空");
return false;
}
var urlStr = '${base}/alarmRule/modify';
if (todoType == 0) {
jsonData = "{ruleId:'" + ruleId + "',appId:'" + appId + "',period:'" + period + "',isGlobal:'" + isGlobal + "',todoType:'" + todoType + "',mailTemp:'" + mailTemp + "',mailTo:'" + mailTo + "',mailCc:'" + mailCc + "',excludeExceptions:'" + excludeExceptions+"'}";
} else if (todoType == 1) {
jsonData = "{ruleId:'" + ruleId + "',appId:'" + appId + "',period:'" + period + "',isGlobal:'" + isGlobal + "',todoType:'" + todoType + "',urlCall:'" + urlCall + "',excludeExceptions:'" + excludeExceptions+"'}";
} else {
if(todoType ==0){
jsonData = "{ruleId:'"+ruleId+"',appId:'"+appId+"',period:'"+period+"',isGlobal:'"+isGlobal+"',todoType:'"+todoType+"',mailTemp:'"+mailTemp+"',mailTo:'"+mailTo+"',mailCc:'"+mailCc+"'}";
}else if(todoType ==1){
jsonData = "{ruleId:'"+ruleId+"',appId:'"+appId+"',period:'"+period+"',isGlobal:'"+isGlobal+"',todoType:'"+todoType+"',urlCall:'"+urlCall+"'}";
}else{
alert("请选择正确的告警操作");
return false;
}
alert(jsonData);
//alert(jsonData);
$.ajax({
type: 'POST',
url: urlStr,
contentType: "application/json",
data: jsonData,
contentType:"application/json",
data:jsonData,
dataType: 'json',
async: false,
success: function (data) {
if (data.result == "OK") {
async : false,
success: function(data){
if(data.result == "OK"){
alert(data.msg);
window.location.reload();
} else {
}else{
alert(data.msg);
}
},
error: function (xhr, type) {
error: function(xhr, type){
alert("操作失败");
}
});
} else {
}else{
//调用创建规则
var urlStr = '${base}/alarmRule/create';
if (todoType == 0) {
jsonData = "{appId:'" + appId + "',period:'" + period + "',isGlobal:'" + isGlobal + "',todoType:'" + todoType + "',mailTemp:'" + mailTemp + "',mailTo:'" + mailTo + "',mailCc:'" + mailCc + "',excludeExceptions:'" + excludeExceptions+"'}";
} else if (todoType == 1) {
jsonData = "{appId:'" + appId + "',period:'" + period + "',isGlobal:'" + isGlobal + "',todoType:'" + todoType + "',urlCall:'" + urlCall + "',excludeExceptions:'" + excludeExceptions+"'}";
} else {
if(todoType ==0){
jsonData = "{appId:'"+appId+"',period:'"+period+"',isGlobal:'"+isGlobal+"',todoType:'"+todoType+"',mailTemp:'"+mailTemp+"',mailTo:'"+mailTo+"',mailCc:'"+mailCc+"'}";
}else if(todoType ==1){
jsonData = "{appId:'"+appId+"',period:'"+period+"',isGlobal:'"+isGlobal+"',todoType:'"+todoType+"',urlCall:'"+urlCall+"'}";
}else{
alert("请选择正确的告警操作");
return false;
}
@ -538,45 +432,70 @@
$.ajax({
type: 'POST',
url: urlStr,
contentType: "application/json",
data: jsonData,
contentType:"application/json",
data:jsonData,
dataType: 'json',
async: false,
success: function (data) {
if (data.result == "OK") {
async : false,
success: function(data){
if(data.result == "OK"){
alert(data.msg);
window.location.reload();
} else {
}else{
alert(data.msg);
}
},
error: function (xhr, type) {
error: function(xhr, type){
alert("操作失败");
}
});
}
});
$("button[name='export']").each(function () {
$(this).bind("click", function () {
$("button[name='export']").each(function(){
$(this).bind("click",function(){
var downLoadFrame = document.getElementById('authFiledownLoad');
downLoadFrame.src = '${base}/exportAuth/test';
});
});
$("button[name='exportAuthInfo']").each(function () {
$(this).bind("click", function () {
$("button[name='exportAuthInfo']").each(function(){
$(this).bind("click",function(){
$("#authInfo").show();
$("#authAppCode").val($(this).attr("appCode"));
//var downLoadFrame = document.getElementById('authFiledownLoad');
//downLoadFrame.src = '${base}/exportAuth/test';
});
});
$("#export").bind("click", function () {
var downLoadFrame = document.getElementById('authFiledownLoad');
downLoadFrame.src = '${base}/exportAuth/test';
$("#export").bind("click",function(){
<#--var downLoadFrame = document.getElementById('authFiledownLoad');-->
<#--downLoadFrame.src = '${base}/exportAuth/test';-->
var appCode = $("#authAppCode").val();
if (appCode == null){
alert("没有发现应用编码.");
return;
}
var form=$("<form>");//定义一个form表单
form.attr("style","display:none");
//form.attr("target","${base}/exportAuth/test");
form.attr("method","post");
form.attr("action","${base}/exportAuth/" + appCode);
var exportData=$("<input>");
exportData.attr("type","hidden");
exportData.attr("name","exportData");
exportData.attr("value",(new Date()).getMilliseconds());
var exclusiveException=$("<input>");
exclusiveException.attr("type","hidden");
exclusiveException.attr("name","exclusiveException");
exclusiveException.attr("value",$("#exclusiveException").val());
$("#authFiledownLoad").append(form);//将表单放置在web中
form.append(exportData);
form.append(exclusiveException);
form.submit();//表单提交
});
$("#cannelExport").bind("click", function () {
$("#cannelExport").bind("click",function(){
$("#authInfo").hide();
});