public void collect_data(String id, Hashtable gatherHash) { WasConfig wasconf = null; try { int serverflag = 0; String ipaddress = ""; WasConfigDao dao = new WasConfigDao(); try { wasconf = (WasConfig) dao.findByID(id); } catch (Exception e) { e.printStackTrace(); } finally { dao.close(); } // AdminClient5 wasadmin = new AdminClient5(); UrlConncetWas conWas = new UrlConncetWas(); Hashtable hst = new Hashtable(); com.afunms.polling.node.Was _tnode = (com.afunms.polling.node.Was) PollingEngine.getInstance().getWasByID(wasconf.getId()); Calendar _date = Calendar.getInstance(); Date _cc = _date.getTime(); String _tempsenddate = sdf.format(_cc); // 初始化Was对象的状态 _tnode.setLastTime(_tempsenddate); _tnode.setAlarm(false); _tnode.getAlarmMessage().clear(); _tnode.setStatus(0); if (gatherHash.containsKey("ping")) { // 对可用性进行检测 boolean collectWasIsOK = false; try { collectWasIsOK = conWas.connectWasIsOK(wasconf.getIpaddress(), wasconf.getPortnum()); } catch (Exception e) { // e.printStackTrace(); } if (collectWasIsOK) { // 运行状态 Pingcollectdata hostdata = null; hostdata = new Pingcollectdata(); hostdata.setIpaddress(wasconf.getIpaddress()); Calendar date = Calendar.getInstance(); hostdata.setCollecttime(date); hostdata.setCategory("WasPing"); hostdata.setEntity("Utilization"); hostdata.setSubentity("ConnectUtilization"); hostdata.setRestype("dynamic"); hostdata.setUnit("%"); hostdata.setThevalue("100"); WasConfigDao wasconfigdao = new WasConfigDao(); try { wasconfigdao.createHostData(wasconf, hostdata); if (wasdata.containsKey("was" + ":" + wasconf.getIpaddress())) wasdata.remove("was" + ":" + wasconf.getIpaddress()); } catch (Exception e) { e.printStackTrace(); } finally { wasconfigdao.close(); } // 进行数据采集 try { hst = conWas.ConncetWas( wasconf.getIpaddress(), String.valueOf(wasconf.getPortnum()), "", "", wasconf.getVersion(), gatherHash); } catch (Exception e) { } } else { // 依据配置判断是否需要告警 // if // (wlservers.containsKey(weblogicconf.getIpaddress()+":"+server.getServerRuntimeName())) // createSMS(weblogicconf,server); try { // com.afunms.polling.node.Weblogic tc = new com.afunms.polling.node.Weblogic(); // BeanUtils.copyProperties(tc, weblogicconf); // if (data_ht==null){ // 需要增加邮件服务所在的服务器是否能连通 Host host = (Host) PollingEngine.getInstance().getNodeByIP(wasconf.getIpaddress()); Vector ipPingData = (Vector) ShareData.getPingdata().get(wasconf.getIpaddress()); ipaddress = wasconf.getIpaddress(); if (ipPingData != null) { Pingcollectdata pingdata = (Pingcollectdata) ipPingData.get(0); Calendar tempCal = (Calendar) pingdata.getCollecttime(); Date cc = tempCal.getTime(); String _time = sdf.format(cc); String lastTime = _time; String pingvalue = pingdata.getThevalue(); if (pingvalue == null || pingvalue.trim().length() == 0) pingvalue = "0"; double pvalue = new Double(pingvalue); if (pvalue == 0) { // 主机服务器连接不上*********************************************** // com.afunms.polling.node.Weblogic // tnode=(com.afunms.polling.node.Weblogic)PollingEngine.getInstance().getWeblogicByIP(ipaddress); _tnode.setAlarm(true); _tnode.setStatus(1); List alarmList = _tnode.getAlarmMessage(); if (alarmList == null) alarmList = new ArrayList(); _tnode.getAlarmMessage().add("WAS服务停止"); String sysLocation = ""; Pingcollectdata hostdata = null; hostdata = new Pingcollectdata(); hostdata.setIpaddress(ipaddress); Calendar date = Calendar.getInstance(); hostdata.setCollecttime(date); hostdata.setCategory("WasPing"); hostdata.setEntity("Utilization"); hostdata.setSubentity("ConnectUtilization"); hostdata.setRestype("dynamic"); hostdata.setUnit("%"); hostdata.setThevalue("0"); WasConfigDao wasconfigdao = new WasConfigDao(); try { wasconfigdao.createHostData(wasconf, hostdata); if (wasdata.containsKey("was" + ":" + wasconf.getIpaddress())) wasdata.remove("was" + ":" + wasconf.getIpaddress()); } catch (Exception e) { e.printStackTrace(); } finally { wasconfigdao.close(); } try { SmscontentDao eventdao = new SmscontentDao(); String eventdesc = "WAS服务(" + wasconf.getName() + " IP:" + wasconf.getIpaddress() + ")" + "停止"; eventdao.createEventWithReasion( "poll", _tnode.getId() + "", _tnode.getAdminIp() + "(" + _tnode.getAdminIp() + ")", eventdesc, 3, "wasserver", "ping", "所在的服务器连接不上"); } catch (Exception e) { e.printStackTrace(); } } else { // com.afunms.polling.node.Weblogic // tnode=(com.afunms.polling.node.Weblogic)PollingEngine.getInstance().getWeblogicByIP(ipaddress); _tnode.setAlarm(true); _tnode.setStatus(3); List alarmList = _tnode.getAlarmMessage(); if (alarmList == null) alarmList = new ArrayList(); _tnode.getAlarmMessage().add("WAS服务停止"); Pingcollectdata hostdata = null; hostdata = new Pingcollectdata(); hostdata.setIpaddress(ipaddress); Calendar date = Calendar.getInstance(); hostdata.setCollecttime(date); hostdata.setCategory("WasPing"); hostdata.setEntity("Utilization"); hostdata.setSubentity("ConnectUtilization"); hostdata.setRestype("dynamic"); hostdata.setUnit("%"); hostdata.setThevalue("0"); WasConfigDao wasconfigdao = new WasConfigDao(); try { wasconfigdao.createHostData(wasconf, hostdata); if (wasdata.containsKey("was" + ":" + wasconf.getIpaddress())) wasdata.remove("was" + ":" + wasconf.getIpaddress()); } catch (Exception e) { e.printStackTrace(); } finally { wasconfigdao.close(); } } } else { // com.afunms.polling.node.Weblogic // tnode=(com.afunms.polling.node.Weblogic)PollingEngine.getInstance().getWeblogicByIP(ipaddress); _tnode.setAlarm(true); _tnode.setStatus(3); List alarmList = _tnode.getAlarmMessage(); if (alarmList == null) alarmList = new ArrayList(); _tnode.getAlarmMessage().add("WAS服务停止"); Pingcollectdata hostdata = null; hostdata = new Pingcollectdata(); hostdata.setIpaddress(ipaddress); Calendar date = Calendar.getInstance(); hostdata.setCollecttime(date); hostdata.setCategory("WasPing"); hostdata.setEntity("Utilization"); hostdata.setSubentity("ConnectUtilization"); hostdata.setRestype("dynamic"); hostdata.setUnit("%"); hostdata.setThevalue("0"); WasConfigDao wasconfigdao = new WasConfigDao(); try { wasconfigdao.createHostData(wasconf, hostdata); if (wasdata.containsKey("was" + ":" + wasconf.getIpaddress())) wasdata.remove("was" + ":" + wasconf.getIpaddress()); } catch (Exception e) { e.printStackTrace(); } finally { wasconfigdao.close(); } } try { createSMS("wasserver", wasconf); serverflag = 1; } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } // try{ // /** // * Author by QuZhi // * 可以取到的指标模块名称 // * JVM/JDBCProvider/SessionManager/SystemMetrics/DynaCache/TransactionService/ORB // * @return /ObjectPool/ThreadPool // */ // // com.afunms.common.util.ShareData.setWasdata("was"+":"+wasconf.getIpaddress(),hst); // }catch(Exception ex){ // ex.printStackTrace(); // } if (hst != null) { ShareData.getWasdata().put(wasconf.getIpaddress(), hst); } hst = null; } catch (Exception exc) { exc.printStackTrace(); } }
@SuppressWarnings("unchecked") public Hashtable collect_Data(NodeGatherIndicators nodeGatherIndicators) { WasConfig wasconf = null; String id = nodeGatherIndicators.getNodeid(); SysLogger.info("#######################WebSphere Ping 开始采集###################################"); try { WasConfigDao dao = new WasConfigDao(); try { wasconf = (WasConfig) dao.findByID(id); SysLogger.info( "###############WebSphere Ping 名称:" + wasconf.getName() + " ipaddress:" + wasconf.getIpaddress() + "#####################"); } catch (Exception e) { e.printStackTrace(); } finally { dao.close(); } Hashtable hst = (Hashtable) ShareData.getWasdata().get(wasconf.getIpaddress()); if (hst == null) { hst = new Hashtable(); } UrlConncetWas conWas = new UrlConncetWas(); boolean collectWasIsOK = false; // 采集数据 try { String url = "http://" + wasconf.getIpaddress() + ":" + wasconf.getPortnum() + "/wasPerfTool/servlet/perfservlet?refreshConfig=true"; System.out.println(url); collectWasIsOK = conWas.connectWasIsOK(wasconf.getIpaddress(), wasconf.getPortnum()); } catch (Exception e) { e.printStackTrace(); } String pingValue = "0"; if (collectWasIsOK) { pingValue = "100"; hst.put("ping", "100"); } else { hst.put("ping", "0"); } // 保存数据库 Pingcollectdata hostdata = new Pingcollectdata(); hostdata.setIpaddress(wasconf.getIpaddress()); Calendar date = Calendar.getInstance(); hostdata.setCollecttime(date); hostdata.setCategory("WasPing"); hostdata.setEntity("Utilization"); hostdata.setSubentity("ConnectUtilization"); hostdata.setRestype("dynamic"); hostdata.setUnit("%"); hostdata.setThevalue(pingValue); WasConfigDao wasconfigdao = new WasConfigDao(); try { wasconfigdao.createHostData(wasconf, hostdata); } catch (Exception e) { e.printStackTrace(); } finally { wasconfigdao.close(); } ShareData.getWasdata().put(wasconf.getIpaddress(), hst); // 告警,只告警PING值 if (pingValue != null) { NodeUtil nodeUtil = new NodeUtil(); NodeDTO nodeDTO = nodeUtil.conversionToNodeDTO(wasconf); // 判断是否存在此告警指标 AlarmIndicatorsUtil alarmIndicatorsUtil = new AlarmIndicatorsUtil(); List list = alarmIndicatorsUtil.getAlarmInicatorsThresholdForNode( nodeDTO.getId() + "", nodeDTO.getType(), nodeDTO.getSubtype()); CheckEventUtil checkEventUtil = new CheckEventUtil(); for (int i = 0; i < list.size(); i++) { AlarmIndicatorsNode alarmIndicatorsNode = (AlarmIndicatorsNode) list.get(i); if ("ping".equalsIgnoreCase(alarmIndicatorsNode.getName())) { if (pingValue != null) { checkEventUtil.checkEvent(nodeDTO, alarmIndicatorsNode, pingValue); } } } } } catch (Exception e) { e.printStackTrace(); } return null; }
public class WasDataCollector { private Hashtable sendeddata = ShareData.getSendeddata(); private Hashtable wasdata = ShareData.getWasdata(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public WasDataCollector() {} public void collect_data(String id, Hashtable gatherHash) { WasConfig wasconf = null; try { int serverflag = 0; String ipaddress = ""; WasConfigDao dao = new WasConfigDao(); try { wasconf = (WasConfig) dao.findByID(id); } catch (Exception e) { e.printStackTrace(); } finally { dao.close(); } // AdminClient5 wasadmin = new AdminClient5(); UrlConncetWas conWas = new UrlConncetWas(); Hashtable hst = new Hashtable(); com.afunms.polling.node.Was _tnode = (com.afunms.polling.node.Was) PollingEngine.getInstance().getWasByID(wasconf.getId()); Calendar _date = Calendar.getInstance(); Date _cc = _date.getTime(); String _tempsenddate = sdf.format(_cc); // 初始化Was对象的状态 _tnode.setLastTime(_tempsenddate); _tnode.setAlarm(false); _tnode.getAlarmMessage().clear(); _tnode.setStatus(0); if (gatherHash.containsKey("ping")) { // 对可用性进行检测 boolean collectWasIsOK = false; try { collectWasIsOK = conWas.connectWasIsOK(wasconf.getIpaddress(), wasconf.getPortnum()); } catch (Exception e) { // e.printStackTrace(); } if (collectWasIsOK) { // 运行状态 Pingcollectdata hostdata = null; hostdata = new Pingcollectdata(); hostdata.setIpaddress(wasconf.getIpaddress()); Calendar date = Calendar.getInstance(); hostdata.setCollecttime(date); hostdata.setCategory("WasPing"); hostdata.setEntity("Utilization"); hostdata.setSubentity("ConnectUtilization"); hostdata.setRestype("dynamic"); hostdata.setUnit("%"); hostdata.setThevalue("100"); WasConfigDao wasconfigdao = new WasConfigDao(); try { wasconfigdao.createHostData(wasconf, hostdata); if (wasdata.containsKey("was" + ":" + wasconf.getIpaddress())) wasdata.remove("was" + ":" + wasconf.getIpaddress()); } catch (Exception e) { e.printStackTrace(); } finally { wasconfigdao.close(); } // 进行数据采集 try { hst = conWas.ConncetWas( wasconf.getIpaddress(), String.valueOf(wasconf.getPortnum()), "", "", wasconf.getVersion(), gatherHash); } catch (Exception e) { } } else { // 依据配置判断是否需要告警 // if // (wlservers.containsKey(weblogicconf.getIpaddress()+":"+server.getServerRuntimeName())) // createSMS(weblogicconf,server); try { // com.afunms.polling.node.Weblogic tc = new com.afunms.polling.node.Weblogic(); // BeanUtils.copyProperties(tc, weblogicconf); // if (data_ht==null){ // 需要增加邮件服务所在的服务器是否能连通 Host host = (Host) PollingEngine.getInstance().getNodeByIP(wasconf.getIpaddress()); Vector ipPingData = (Vector) ShareData.getPingdata().get(wasconf.getIpaddress()); ipaddress = wasconf.getIpaddress(); if (ipPingData != null) { Pingcollectdata pingdata = (Pingcollectdata) ipPingData.get(0); Calendar tempCal = (Calendar) pingdata.getCollecttime(); Date cc = tempCal.getTime(); String _time = sdf.format(cc); String lastTime = _time; String pingvalue = pingdata.getThevalue(); if (pingvalue == null || pingvalue.trim().length() == 0) pingvalue = "0"; double pvalue = new Double(pingvalue); if (pvalue == 0) { // 主机服务器连接不上*********************************************** // com.afunms.polling.node.Weblogic // tnode=(com.afunms.polling.node.Weblogic)PollingEngine.getInstance().getWeblogicByIP(ipaddress); _tnode.setAlarm(true); _tnode.setStatus(1); List alarmList = _tnode.getAlarmMessage(); if (alarmList == null) alarmList = new ArrayList(); _tnode.getAlarmMessage().add("WAS服务停止"); String sysLocation = ""; Pingcollectdata hostdata = null; hostdata = new Pingcollectdata(); hostdata.setIpaddress(ipaddress); Calendar date = Calendar.getInstance(); hostdata.setCollecttime(date); hostdata.setCategory("WasPing"); hostdata.setEntity("Utilization"); hostdata.setSubentity("ConnectUtilization"); hostdata.setRestype("dynamic"); hostdata.setUnit("%"); hostdata.setThevalue("0"); WasConfigDao wasconfigdao = new WasConfigDao(); try { wasconfigdao.createHostData(wasconf, hostdata); if (wasdata.containsKey("was" + ":" + wasconf.getIpaddress())) wasdata.remove("was" + ":" + wasconf.getIpaddress()); } catch (Exception e) { e.printStackTrace(); } finally { wasconfigdao.close(); } try { SmscontentDao eventdao = new SmscontentDao(); String eventdesc = "WAS服务(" + wasconf.getName() + " IP:" + wasconf.getIpaddress() + ")" + "停止"; eventdao.createEventWithReasion( "poll", _tnode.getId() + "", _tnode.getAdminIp() + "(" + _tnode.getAdminIp() + ")", eventdesc, 3, "wasserver", "ping", "所在的服务器连接不上"); } catch (Exception e) { e.printStackTrace(); } } else { // com.afunms.polling.node.Weblogic // tnode=(com.afunms.polling.node.Weblogic)PollingEngine.getInstance().getWeblogicByIP(ipaddress); _tnode.setAlarm(true); _tnode.setStatus(3); List alarmList = _tnode.getAlarmMessage(); if (alarmList == null) alarmList = new ArrayList(); _tnode.getAlarmMessage().add("WAS服务停止"); Pingcollectdata hostdata = null; hostdata = new Pingcollectdata(); hostdata.setIpaddress(ipaddress); Calendar date = Calendar.getInstance(); hostdata.setCollecttime(date); hostdata.setCategory("WasPing"); hostdata.setEntity("Utilization"); hostdata.setSubentity("ConnectUtilization"); hostdata.setRestype("dynamic"); hostdata.setUnit("%"); hostdata.setThevalue("0"); WasConfigDao wasconfigdao = new WasConfigDao(); try { wasconfigdao.createHostData(wasconf, hostdata); if (wasdata.containsKey("was" + ":" + wasconf.getIpaddress())) wasdata.remove("was" + ":" + wasconf.getIpaddress()); } catch (Exception e) { e.printStackTrace(); } finally { wasconfigdao.close(); } } } else { // com.afunms.polling.node.Weblogic // tnode=(com.afunms.polling.node.Weblogic)PollingEngine.getInstance().getWeblogicByIP(ipaddress); _tnode.setAlarm(true); _tnode.setStatus(3); List alarmList = _tnode.getAlarmMessage(); if (alarmList == null) alarmList = new ArrayList(); _tnode.getAlarmMessage().add("WAS服务停止"); Pingcollectdata hostdata = null; hostdata = new Pingcollectdata(); hostdata.setIpaddress(ipaddress); Calendar date = Calendar.getInstance(); hostdata.setCollecttime(date); hostdata.setCategory("WasPing"); hostdata.setEntity("Utilization"); hostdata.setSubentity("ConnectUtilization"); hostdata.setRestype("dynamic"); hostdata.setUnit("%"); hostdata.setThevalue("0"); WasConfigDao wasconfigdao = new WasConfigDao(); try { wasconfigdao.createHostData(wasconf, hostdata); if (wasdata.containsKey("was" + ":" + wasconf.getIpaddress())) wasdata.remove("was" + ":" + wasconf.getIpaddress()); } catch (Exception e) { e.printStackTrace(); } finally { wasconfigdao.close(); } } try { createSMS("wasserver", wasconf); serverflag = 1; } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } // try{ // /** // * Author by QuZhi // * 可以取到的指标模块名称 // * JVM/JDBCProvider/SessionManager/SystemMetrics/DynaCache/TransactionService/ORB // * @return /ObjectPool/ThreadPool // */ // // com.afunms.common.util.ShareData.setWasdata("was"+":"+wasconf.getIpaddress(),hst); // }catch(Exception ex){ // ex.printStackTrace(); // } if (hst != null) { ShareData.getWasdata().put(wasconf.getIpaddress(), hst); } hst = null; } catch (Exception exc) { exc.printStackTrace(); } } private Runnable createTask(final WasConfig wasconf) { return new Runnable() { public void run() {} }; } public void createSMS(String was, WasConfig wasconf) { // 建立短信 // 从内存里获得当前这个IP的PING的值 Calendar date = Calendar.getInstance(); try { if (!sendeddata.containsKey(was + ":" + wasconf.getId())) { // 若不在,则建立短信,并且添加到发送列表里 Smscontent smscontent = new Smscontent(); String time = sdf.format(date.getTime()); smscontent.setLevel("2"); smscontent.setObjid(wasconf.getId() + ""); if ("wasserver".equals(was)) { smscontent.setMessage( "WAS" + " (" + wasconf.getName() + ":" + wasconf.getIpaddress() + ")" + "的服务停止!"); } smscontent.setRecordtime(time); smscontent.setSubtype("wasserver"); smscontent.setSubentity("ping"); smscontent.setIp(wasconf.getIpaddress()); // smscontent.setMessage("db&"+time+"&"+dbmonitorlist.getId()+"&"+db+"("+dbmonitorlist.getDbName()+" IP:"+dbmonitorlist.getIpAddress()+")"+"的数据库服务停止"); // 发送短信 SmscontentDao smsmanager = new SmscontentDao(); smsmanager.sendURLSmscontent(smscontent); sendeddata.put(was + ":" + wasconf.getId(), date); } else { // 若在,则从已发送短信列表里判断是否已经发送当天的短信 Calendar formerdate = (Calendar) sendeddata.get(was + ":" + wasconf.getId()); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Date last = null; Date current = null; Calendar sendcalen = formerdate; Date cc = sendcalen.getTime(); String tempsenddate = formatter.format(cc); Calendar currentcalen = date; cc = currentcalen.getTime(); last = formatter.parse(tempsenddate); String currentsenddate = formatter.format(cc); current = formatter.parse(currentsenddate); long subvalue = current.getTime() - last.getTime(); if (subvalue / (1000 * 60 * 60 * 24) >= 1) { // 超过一天,则再发信息 Smscontent smscontent = new Smscontent(); String time = sdf.format(date.getTime()); smscontent.setLevel("2"); smscontent.setObjid(wasconf.getId() + ""); if ("wasserver".equals(was)) { smscontent.setMessage( "WAS" + " (" + wasconf.getName() + ":" + wasconf.getIpaddress() + ")" + "的服务停止!"); } smscontent.setRecordtime(time); smscontent.setSubtype("wasserver"); smscontent.setSubentity("ping"); smscontent.setIp(wasconf.getIpaddress()); // smscontent.setMessage("db&"+time+"&"+dbmonitorlist.getId()+"&"+db+"("+dbmonitorlist.getDbName()+" IP:"+dbmonitorlist.getIpAddress()+")"+"的数据库服务停止"); // 发送短信 SmscontentDao smsmanager = new SmscontentDao(); smsmanager.sendURLSmscontent(smscontent); // 修改已经发送的短信记录 sendeddata.put(was + ":" + wasconf.getId(), date); } } } catch (Exception e) { e.printStackTrace(); } } }