index.jsp 14.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="java.util.Properties" %>
<%@ page import="java.io.*" %>
<%@ page import="java.text.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.net.*" %>
<%@ page import="java.util.zip.*" %>
<%@ page import="org.apache.commons.io.IOUtils" %>
<%

	final String ecologyPath = request.getRealPath("/");
	weaver.hrm.User user = (weaver.hrm.User)request.getSession(true).getAttribute("weaver_user@bean");
	final String ResinPath = System.getProperty("user.dir")+File.separator;
	boolean isResin = ResinPath.toLowerCase().indexOf("resin")!=-1;
	String ecologyWeaverPath = "";
	if(ecologyPath.endsWith(File.separator)){
		ecologyWeaverPath = ecologyPath+"WEB-INF"+File.separator+"prop"+File.separator+"weaver.properties"; 
	}else{
		ecologyWeaverPath = ecologyPath+File.separator+"WEB-INF"+File.separator+"prop"+File.separator+"weaver.properties"; 
	}

	File ecolpogyProp = new File(ecologyWeaverPath);
	File resinProp = new File(ResinPath+"bin"+File.separator+"startresin.sh");

	Set ipList = readEcologyProp(ecolpogyProp);
	String localIp = getInnerIp();
	if(ipList.size()==0){
		ipList.addAll(readResinProp(resinProp));
	}
	boolean isCluster = true;
	if(ipList.size()==0){//没有集群的时候
		//ipList.add(localIp);
		isCluster = false;
	}else{
		boolean status = false;
		java.util.Iterator it = ipList.iterator();
			while(it.hasNext()){
			String ip = (String)it.next();
			if(ip.indexOf(localIp)!=-1 || "127.0.0.1".equals(ip) || "127.0.0.1".equals(localIp)){
				status = true;
			}	
		}
		if(!status){
			ipList.add(localIp);
		}
	}
	

%>

<%!
	/**
	 * 当前机器内网ip
	 * 
	 * @return
	 */
	private String getInnerIp() {
		try {
			Enumeration netInterfaces = NetworkInterface.getNetworkInterfaces();
			while (netInterfaces.hasMoreElements()) {
				NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement();
				Enumeration nii = ni.getInetAddresses();
				while (nii.hasMoreElements()) {
					InetAddress inetAddress = (InetAddress) nii.nextElement();
					if (inetAddress.getHostAddress().indexOf(":") == -1) {
						String ip = inetAddress.getHostAddress();
						if (ip.startsWith("10.") || ip.startsWith("192.168.")) {// ||
							return ip;
						} else {
							if (ip.startsWith("172.")) {
									return ip;
							}
						}
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "127.0.0.1";
	}
		private Set readResinProp(File startResinFile) {
		  Set liststr = new HashSet();
		  if(!startResinFile.exists()){
				return liststr;
			}
	        if(startResinFile.isFile() && startResinFile.length() > 0){
	            FileInputStream fileInput = null;
	            BufferedReader bufferedReader = null;
	            try {
	                fileInput = new FileInputStream(startResinFile);
	                bufferedReader = new BufferedReader(new InputStreamReader(fileInput));
	                String str = null;
	                while((str = bufferedReader.readLine()) != null) {
	                    if( str.indexOf("-Dinitial_hosts")!=-1 || str.indexOf("-J-Dinitial_hosts")!=-1 ){
							if(str.indexOf("-J-Dinitial_hosts")!=-1){
								str = str.substring(str.indexOf("-J-Dinitial_hosts")+17,str.length());
							}
							if(str.indexOf("-Dinitial_hosts")!=-1){
								str = str.substring(str.indexOf("-Dinitial_hosts")+15,str.length());
							}
	                        str = str.indexOf("=")!=-1? str.substring(str.indexOf("=")+1,str.length()):str;
	                        str = str.indexOf("-")!=-1?str.substring(0,str.indexOf("-")):str;
							str = str.indexOf(" ")!=-1?str.substring(0,str.indexOf(" ")):str;
	                        String[] ips  = str.split(",");
	                        for(int i=0;i<ips.length;i++){
								String ip = ips[i];
	                        	try{
	                        		String tmpip = ip.replace(".", "").replace(":", "");
		                        	Long.parseLong(tmpip.trim());
		                        	liststr.add(ip.trim());
	                        	}catch (Exception e) {
								}
	                        }
	                    }
	                }
	            } catch (Throwable t) {
	            	t.printStackTrace();
	            } finally {
	                IOUtils.closeQuietly(fileInput);
	                IOUtils.closeQuietly(bufferedReader);
	            }
	        }
	        return liststr;
	    }
	
	
	private Set readEcologyProp(File file){
		Set liststr = new HashSet();
		try {
			if(!file.exists()){
				return liststr;
			}
			Properties registerProp = new Properties();
			InputStreamReader reader = new InputStreamReader(new FileInputStream(file));
			registerProp.load(reader);
			String initial_host = registerProp.getProperty("initial_hosts");
			if(initial_host!=null&&!"".equals(initial_host)){
				String[] initial_hosts = initial_host.split(",");
				for(int i=0;i<initial_hosts.length;i++){
					String initial_hostStr = initial_hosts[i];
					if(!initial_hostStr.isEmpty()){
						liststr.add(initial_hostStr);
					}
				}
			}
			IOUtils.closeQuietly(reader);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return liststr;
	}
%>

<html>
<head>
	<link rel="stylesheet" href="css/index.css">
	
	<script type="text/javascript"src="js/jquery.js"></script>
	<script type="text/javascript"src="js/data.js"></script>
	<script type="text/javascript"src="js/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript">
		$(function(){
			
			if(<%=user==null || !"sysadmin".equals(user.getLoginid())%>){
				alert("请使用sysadmin账号登录!");
				window.location.href="/";
				return;
			}
			$("#downstartlogDate").val(new Date().format("yyyy-MM-dd"));
			$("#downendlogDate").val(new Date().format("yyyy-MM-dd"));
			
		})
		
		function collectLog(){
			var clusterips = "";
			$("[name='clusterip']:checked").each(function(){  
				clusterips+=$(this).val()+",";  
			})  
			if(<%=isCluster%>&&clusterips==''){
				alert("请选择服务器节点!")
				return;
			}
			clusterips = clusterips.substr(0,clusterips.length-1) ;
			
			var loytype = "";
			$("[name='loytype']:checked").each(function(){  
				loytype+=$(this).val()+",";  
			})  
			if(loytype==''){
				alert("请选择日志类型!")
				return;
			}
			loytype = loytype.substr(0,loytype.length-1) ;	
			var startDate = $("#downstartlogDate").val();
			var endDate = $("#downendlogDate").val();
			if(startDate==''){
				alert("请选择开始日期!")
				return;
			}
			if(endDate==''){
				alert("请选择结束日期!")
				return;
			}
			var oDate1 = new Date(startDate);
		    var oDate2 = new Date(endDate);
		    if(oDate1.getTime() > oDate2.getTime()){
		    	alert("结束日志不能少于开始日期!")
		    	return;
		    }
		    waitInt = 0;
		    $("#start").attr("disabled","disabled");
		    var clts = clusterips.split(",");
		    for(var i=0;i<clts.length&&clts.length>0;i++){
		    	var ip = clts[i];
		    	var clt = ip.replace(/\./g, "");
		    	clt = clt.replace(/\:/g, "");
		    	if(clt.indexOf("<%=localIp%>")!=-1){
		    		waitInt+=1
		    		getLog(clt,ip,loytype,startDate,endDate);
		    	}else{
		    		waitInt+=1
		    		getOtherLog(clt,ip,loytype,startDate,endDate);
		    	}
			   
		    }
		    if(<%=!isCluster%>){
		    	waitInt+=1
		    	getLog('log','<%=localIp%>',loytype,startDate,endDate);
		    }
		}
		
		function getold7Day(){
			var now = new Date();
			var date = new Date(now.getTime() - 7 * 24 * 3600 * 1000);
			var year = date.getFullYear();
			var month = date.getMonth() + 1;
			var day = date.getDate();
			return year+'-'+month+'-'+day;
		}
		
		function getLog(div,ip,loytype,startDate,endDate){
			$.ajax({
		            type : 'GET',
		            contentType: " charset=utf-8",
		            url : '/getlog/getlog.jsp?loytype='+loytype+'&startDate='+startDate+'&endDate='+endDate,
		            beforeSend : function(){
		            	$("#"+div+"div").html('<img alt="" style = "width: 20px;height: 20px;" src="img/loading.gif">')
		            	$("#"+div+"messagediv").html('')
		            },
		            success : function(data){
		            	waitInt--;
		            	if(waitInt==0){
		            		$("#start").removeAttr("disabled");
		            	}
		            	var dataTmp = data.split(",");
		            	if(dataTmp[0]!='0KB'&&dataTmp[0].trim()!=''){
		            		var iptmp = ip.indexOf(":")>0?ip.substr(0,ip.indexOf(":")):ip;
							
							$("#"+div+"div").html('<a href="/getlog/downlog.jsp?logName='+iptmp+'downLog.zip">'+iptmp+'downLog.zip('+dataTmp[0]+') 下载</a>')
							if(dataTmp[1]!=null && dataTmp[1]!=undefined && dataTmp[1].trim()!=''){
								var messtr = dataTmp[1];
								$("#"+div+"messagediv").html(messtr.substr(1,messtr.length)+'日志内容大于1G,此次日志收集内容只取日志后面的1G内容,如需完整日志,请在服务器器上获取.请知晓!');
							}
		            	}else{
		            		$("#"+div+"div").html('收集失败,请手动收集!')
		            	}
		            }
				});	
		}
		var waitInt = 0;
		function getOtherLog(div,clusterIp,loytype,startDate,endDate){
			$.ajax({
		            type : 'GET',
		            contentType: " charset=utf-8",
		            url : '/getlog/sendUrl.jsp?clusterIp='+clusterIp+'&loytype='+loytype+'&startDate='+startDate+'&endDate='+endDate,
		            beforeSend : function(){
		            	$("#"+div+"div").html('<img alt="" style = "width: 20px;height: 20px;" src="img/loading.gif">');
		            	$("#"+div+"messagediv").html('')
		            },
		            success : function(data){
		            	var dataTmp = data.split(",");
		            	waitInt--;
		            	if(waitInt==0){
		            		$("#start").removeAttr("disabled");
		            	}
		            	if(data.trim()=='1'){
		            		$("#"+div+"div").html('收集失败,系统参数不全!')
		            	}else if(data.trim()=='2'){
		            		$("#"+div+"div").html(clusterIp+'请求被拦截,请将/getlog/getlog.jsp请求')
		            	}else if(data.trim()=='3'){
		            		$("#"+div+"div").html('收集失败,请手动收集!')
		            	}else if(data.trim()=='4'){
		            		$("#"+div+"div").html('收集失败,请手动收集!')
		            	}else if(data.trim()!='0KB'&&dataTmp[0].trim()!=''){
		            		var iptmp = clusterIp.indexOf(":")>0?clusterIp.substr(0,clusterIp.indexOf(":")):clusterIp;
							var otherIp = clusterIp.replace(":","-"); 
							//console.info('<a href="/getlog/downlog.jsp?logName='+iptmp+'downLog.zip&otherIp='+otherIp+'">'+iptmp+'downLog.zip('+data+') 下载</a>')
								$("#"+div+"div").html('<a href="/getlog/downlog.jsp?logName='+iptmp+'downLog.zip&otherIp='+otherIp+'">'+iptmp+'downLog.zip('+data+') 下载</a>')
						
							if(dataTmp[1]!=null && dataTmp[1]!=undefined && dataTmp[1].trim()!=''){
								var messtr = dataTmp[1];
								$("#"+div+"messagediv").html(messtr.substr(1,messtr.length)+'日志内容大于1G,此次日志收集内容只取日志后面的1G内容,如需完整日志,请在服务器器上获取.请知晓!');
							}
		            	}else {
		            		$("#"+div+"div").html('收集失败,请手动收集!')
		            	}
						
		            }
				});			
		}
	</script>
</head>
	<body style="margin-top: 0px;">
		<div class="box" style="margin-top: 0px;">
			<div class="mytitle">
				<div style="padding-top: 10px;padding-left: 16px">
					ecology日志下载
				</div>
			</div>
			
			<div style="" class="contend">
			<%if(isCluster){ %>
				<div class="cluster">
					<div>服务器节点</div>
					<div class="clusterPlan">
				<% 
							java.util.Iterator it = ipList.iterator();
							while(it.hasNext()){
								String ip = (String)it.next();
				%>
						<div class="clusterIp" style="width:180px">
							<label>
								<input type="checkbox" class="checkbox" name="clusterip" value="<%=ip %>" checked>
								<span></span>
								<%=ip %>
							</label>
						</div>
				<%}%>
					</div>
				</div>
				<%}%>
				
				
				
				<div class="cluster">
					<div>日志类型</div>
					<div class="clusterPlan">
						<div class="clusterIp">
							<label>
								<input type="checkbox" class="checkbox" name="loytype" value="monitor" checked>
								性能日志
							</label>
						</div>
						
						<div class="clusterIp" style="width: 140px">
							<label>
								<input type="checkbox" class="checkbox" name="loytype" value="ecology" checked >
								ecology日志
							</label>
						</div>

						<div class="clusterIp">
							<label>
								<input type="checkbox" class="checkbox" name="loytype" value="Resin" checked >
								Resin日志
							</label>
						</div>

						<div class="clusterIp">
							<label>
								<input type="checkbox"  class="checkbox"name="loytype" value="security" >
								安全日志
							</label>
						</div>

						
						<div class="clusterIp">
							<label>
								<input type="checkbox" class="checkbox" name="loytype" value="integration" >
								集成日志
							</label>
						</div>
						
						<div class="clusterIp">
							<label>
								<input type="checkbox" class="checkbox" name="loytype" value="sql" >
								sql日志
							</label>
						</div>
						
					</div>
				</div>
				
				
				<div class="cluster">
					<div>时间范围</div>
					<div class="clusterPlan" >
							<div style="text-algin:center;font-family: PingFangSC-Regular;font-size: 12px;color: #999999;letter-spacing: -0.07px;">
								<span style="padding-right:10px;color:#6d6d6d;">开始时间</span>
						         <input id="downstartlogDate" class="Wdate" type="text" onclick="WdatePicker({minDate:'#F{getold7Day()}',maxDate:'%y-%M-%d'})" size="16" readonly/>
						         -
								<span style="padding-right:10px;color:#6d6d6d;">结束时间</span>
						         <input id="downendlogDate" class="Wdate" type="text" onclick="WdatePicker({minDate:'#F{getold7Day()}',maxDate:'%y-%M-%d'})" size="16" readonly/>
						         <span style="width: 10px;display:inline-block"></span>
						         <button class="Button" id="start" onclick="collectLog()">收集日志</button>
							</div>
					</div>
				</div>
				
				<div class="cluster" style="height: 300px;max-height: 300px;overflow-y:auto ">
					<div>下载列表</div>
						<div class="clusterPlan">
							<% 
							java.util.Iterator it = ipList.iterator();
							while(it.hasNext()){
								String ip = (String)it.next();
								ip = ip.replaceAll("\\.","");
								ip = ip.replaceAll(":","") ;
							%>
							<div id="<%=ip%>div">
							</div>
							<div id="<%=ip%>messagediv" class="messages"></div>
							<%}%>
							
							<%if(!isCluster){ %>
								<div id="logdiv"></div>
								<div id="logmessagediv" class="messages"></div>
							<%} %>
							
						</div>
				</div>
			
			
			</div>
			
		</div>
	</body>
</html>