public static void main(String args[]) throws SQLException { WasConfigDao wasconf = new WasConfigDao(); wasconf.findByID("137"); }
@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 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(); } }