CollCiscoSwitchWithSNMP.java 19.8 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 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
package com.sitech.ismp.coll;

import java.util.List;
import java.util.Vector;

import org.apache.log4j.Logger;

import com.sitech.ismp.coll.basic.TblATO_KPIDETAIL;
import com.sitech.ismp.coll.net.ifOperStatusHelper;
import com.sitech.ismp.coll.net.ifTypeHelper;
import com.sitech.ismp.coll.net.cisco.FanEntry;
import com.sitech.ismp.coll.net.cisco.FanEntryWalker;
import com.sitech.ismp.coll.net.cisco.SupplyEntry;
import com.sitech.ismp.coll.net.cisco.SupplyEntryWalker;
import com.sitech.ismp.coll.net.cisco.TemperatureEntry;
import com.sitech.ismp.coll.net.cisco.TemperatureEntryWalker;
import com.sitech.ismp.coll.net.config.IpAddEntryWalker;
import com.sitech.ismp.coll.net.config.IpAddrEntry;
import com.sitech.ismp.coll.net.table.IfTable;
import com.sitech.ismp.coll.net.table.IfTableRow;
import com.sitech.ismp.util.SnmpHandler;
import com.sitech.util.Formater;

/**
 * ClassName:CollCiscoSwitchWithSNMP
 * Description: 思科交换机采集
 *
 * @author   Linxc
 * @version  
 * @since    Ver 1.1
 * @Date	 2012	Feb 28, 2012		6:34:42 PM
 */
public class CollCiscoSwitchWithSNMP {
	private Logger logger = Logger.getLogger("COLL");
	// Cisco Switch
	private String PRE_UNITID = "10-16-10"; 
	
	private String ipAddr;
	private int port;
	private String community;
	private String deviceName;
	private String neatDeviceName;


	public CollCiscoSwitchWithSNMP(String ip, int port, String community,
			String deviceName) {
		this.ipAddr = ip;
		this.port = port;
		this.community = community;
		this.deviceName = deviceName;
		this.neatDeviceName = Formater.neatenunitid(deviceName);
	}

	/**
	 * 采集设备名称
	 */
	public Vector<TblATO_KPIDETAIL> getHostName() {
		CollBase collBase = new CollBase();
		String unitId = PRE_UNITID + "-10" + ":" + neatDeviceName + "-total";
		collBase.addKPI(unitId, "CM-00-01-001-01", deviceName);
		return collBase.KPISet;
	}

	/**
	 * 采集IpAddr
	 */
	public Vector<TblATO_KPIDETAIL> getIpAddr() {
		CollBase collBase = new CollBase();
		String unitId = PRE_UNITID + "-10" + ":" + neatDeviceName + "-total";
		collBase.addKPI(unitId, "CM-00-02-001-05", ipAddr);
		return collBase.KPISet;
	}
	
	public Vector<TblATO_KPIDETAIL> getConfig(){
		CollBase collBase = new CollBase();
		String unitId = PRE_UNITID + "-10" + ":" + neatDeviceName + "-total";
		
		SnmpHandler snmpHandler = null;
		try{
			snmpHandler = new SnmpHandler(ipAddr, port, community, 1);
			
			String sysDescr = snmpHandler.get(".1.3.6.1.2.1.1.1.0");
			sysDescr =sysDescr.replaceAll("\n", " ");
			sysDescr =sysDescr.replaceAll("\r", " ");
			
			String sysUptime = snmpHandler.get(".1.3.6.1.2.1.1.3.0");			
			
			collBase.addKPI(unitId, "CM-01-02-03-04", sysDescr);
			collBase.addKPI(unitId, "CM-01-02-03-05", sysUptime);
		}catch (Exception e) {
			logger.error("Exception while getConfig", e);
		}finally{
			if(snmpHandler != null){
				snmpHandler.destroy();
			}
		}
		collBase.displayKPI();
		return collBase.KPISet;
	}
	

	/**
	 * 采集主机状态
	 * 
	 * @return
	 */
	public Vector<TblATO_KPIDETAIL> getDeviceState() {
		CollBase collBase = new CollBase();
		String unitId = PRE_UNITID + "-10" + ":" + neatDeviceName + "-total";
		
		SnmpHandler snmpHandler = null;
		try{
			snmpHandler = new SnmpHandler(ipAddr, port, community, 1);
			
			String status = snmpHandler.get(".1.3.6.1.2.1.1.2.0");
			if(status == null || status.equals("")){
				status = "DOWN";
			}else{
				status = "UP";
			}
			
			collBase.addKPI(unitId, "FM-00-02-001-01", status);
		}catch (Exception e) {
			logger.error("Exception while getConfig", e);
		}finally{
			if(snmpHandler != null){
				snmpHandler.destroy();
			}
		}
		collBase.displayKPI();
		return collBase.KPISet;
	}

	/**
	 * 采集端口数量
	 */
	public Vector<TblATO_KPIDETAIL> getPortNum() {
		CollBase collBase = new CollBase();
		String unitId = PRE_UNITID + "-10" + ":" + neatDeviceName + "-total";
		
		SnmpHandler snmpHandler = null;
		try{
			snmpHandler = new SnmpHandler(ipAddr, port, community, 1);
			
			String num = snmpHandler.get(".1.3.6.1.2.1.2.1.0");
			if(num == null || num.equals("")){
				num = "0";
			}
			
			collBase.addKPI(unitId, "CM-00-02-002-06", num);
		}catch (Exception e) {
			logger.error("Exception while getConfig", e);
		}finally{
			if(snmpHandler != null){
				snmpHandler.destroy();
			}
		}
		collBase.displayKPI();
		return collBase.KPISet;
	}

	/**
	 * 采集主机软件版本
	 * 
	 * @return
	 */
	public Vector<TblATO_KPIDETAIL> getSoftVersion() {
		CollBase collBase = new CollBase();
		String unitId = PRE_UNITID + "-10" + ":" + neatDeviceName + "-total";
		
		SnmpHandler snmpHandler = null;
		try{
			snmpHandler = new SnmpHandler(ipAddr, port, community, 1);
			
			String version = snmpHandler.get(".1.3.6.1.2.1.1.1.0");
			System.out.println(version);
			if(version == null || version.equals("")){
				version = "-";
			}else{
				version = version.substring(version.indexOf("IOS"));
				String[] ss = version.split(",");
				version = ss[0].trim() + "," + ss[1];
			}			
			collBase.addKPI(unitId, "CM-00-02-001-03", version);
		}catch (Exception e) {
			logger.error("Exception while getConfig", e);
		}finally{
			if(snmpHandler != null){
				snmpHandler.destroy();
			}
		}
		collBase.displayKPI();
		return collBase.KPISet;
	}

	/**
	 * 端口指标采集
	 * 
	 * @return
	 */
	public Vector<TblATO_KPIDETAIL> getPortKpi() {
		CollBase collBase = new CollBase();
		IfTable ifTable = new IfTable();
		ifTable.FillTable(ipAddr, port, community);
		Vector<?> ifTableRows = ifTable.getRrows();
		
		try{
			Thread.sleep(2000);
		}catch(Exception e){
			e.printStackTrace();
		}
		ifTable.FillTable(ipAddr, port, community);
		//休息2秒后的采集值
		Vector<?> ifTableRows2 = ifTable.getRrows();
		
		for (int i = 0; i < ifTableRows.size(); i++) {
			IfTableRow row = (IfTableRow) ifTableRows.get(i);
			String ifIndex = row.getIfindex();
			IfTableRow row2=null;
			for(int j=0;j<ifTableRows2.size();j++){
				row2 = (IfTableRow) ifTableRows2.get(j);
				String ifIndex2 = row2.getIfindex();
				if(ifIndex!=null&&ifIndex.equals(ifIndex2)){
					break;
				}
			}
			
			String r_ifDesc = "--";
			String ifDesc = row.getIfdesc();
			if (ifDesc != null && (!(ifDesc.equals("")))
					&& (!(ifDesc.equalsIgnoreCase("null")))) {
				r_ifDesc = ifDesc;
			}
			String ifType = ifTypeHelper.getTypeDesc(row.getIftype());
			String ifOperStatus = ifOperStatusHelper.getOperStatusDesc(row
					.getIfoperstatus());
			String r_ifPhyAddr = "--";
			String ifPhyAddr = row.getIfphyaddr();
			if (ifPhyAddr != null && (!(ifPhyAddr.equals("")))) {
				r_ifPhyAddr = ifPhyAddr;
			}

			String unitId = PRE_UNITID + "-11" + ":" + neatDeviceName + "-" + ifIndex + "-interface";
			// 端口索引号 CM-01-02-02-01
			collBase.addKPI(unitId, "CM-01-02-02-01", ifIndex);
			// 端口描述 CM-01-02-02-05
			collBase.addKPI(unitId, "CM-01-02-02-05", r_ifDesc);
			// 端口类型 CM-01-02-02-02
			collBase.addKPI(unitId, "CM-01-02-02-02", ifType);
			// 端口Mac地址 CM-01-02-02-04
			collBase.addKPI(unitId, "CM-01-02-02-04", r_ifPhyAddr);
			// 端口状态 FM-01-02-01-02
			collBase.addKPI(unitId, "FM-01-02-01-02", ifOperStatus);
			// 
			
			//-------------------zhangdj modify , remove caculate and use original value---------------------
			if(row2!=null){
				try{
					String ifspped=row.getIfspeed();
					String inocts1= row.getIfinoctets();
					String inocts2= row2.getIfinoctets();
					
					String outocts1= row.getIfoutoctets();
					String outocts2 = row2.getIfoutoctets();
					
					//String inpackage1=row.getIfinucastpkts();
					String inpackage= row2.getIfinucastpkts();
					String outpackage=row2.getIfoutucastpkts();
					String outdiscard=row2.getIfoutdiscards();
					String indiscard = row2.getIfindiscards();
					String inerrors = row2.getIfinerrors();
					String outerror = row2.getIfouterrors();
					
					
					float speed = Float.parseFloat(ifspped) / 64; // 一个octet8字节,1字节8bit
					//float inoctets = Float.parseFloat(inocts2)
					//		- Float.parseFloat(inocts1);// /speed;
					//float outoctets = Float
					//		.parseFloat(outocts2)
					//		- Float.parseFloat(outocts1); // /speed;

					float totalpackage = Float.parseFloat(inpackage)
							+ Float.parseFloat(outpackage);
					
					float totalerrorpackage = Float.parseFloat(inerrors)
							+ Float.parseFloat(outerror);
					
					float totaldiscardpackage = Float.parseFloat(indiscard)
							+ Float.parseFloat(outdiscard);
					if (totalpackage < 1)
						totalpackage = 1F;
					
					String cerrorper = Formater.formatDecimalByScale(String
							.valueOf((totalerrorpackage / totalpackage) * 5000F), 4); // 表示十万分之X的误码率
					String cdiscardper = Formater.formatDecimalByScale(String
							.valueOf((totaldiscardpackage / totalpackage) * 5000F), 4); // 表示十万分之X的丢包率
					//String cinper = Formater.formatDecimalByScale(String
					//		.valueOf(inoctets / speed * 50F), 4); // 千分比,等待了2秒
					//String coutper = Formater.formatDecimalByScale(String
					//		.valueOf(outoctets / speed * 50F), 4); // 千分比,等待了2秒
					//String cinoutper = Formater.formatDecimalByScale(String
					//		.valueOf((inoctets + outoctets) / speed * 50F), 4);
					
					
					// 端口误码率
					collBase.addKPI(unitId, "FM-00-02-002-01", cerrorper);
					// 端口丢包率
					collBase.addKPI(unitId, "FM-00-02-002-02", cdiscardper);
					// 流入总量
					collBase.addKPI(unitId, "PM-00-02-001-10", row.getIfinoctets());
					// 流出总量
					collBase.addKPI(unitId, "PM-00-02-001-09", row.getIfoutoctets());
					// 端口当前数据速率
					collBase.addKPI(unitId, "PM-00-02-001-11", row.getIfspeed());
					// 端口状态
					String portStatus = "";
					String realStatus = row.getIfoperstatus();
					String adminStatus = row.getIfadminstatus();
					// 如果用户配置的是up,但实际情况为down,则表示该端口处于down的状态;
					if("1".equals(adminStatus)){
						if("2".equals(realStatus)){
							portStatus = "down";
						}else 
						if("1".equals(realStatus)){
							portStatus = "up";
						}else 
						if("3".equals(realStatus)){
								portStatus = "testing";
						}
					}else if("2".equals(adminStatus)){
						portStatus = "---";
					}else if("3".equals(adminStatus)){
						portStatus = "testing";
					}
					
					collBase.addKPI(unitId, "FM-00-02-001-02", portStatus);
					// LAN(半双工)端口利用率
					//collBase.addKPI(unitId, "PM-00-02-001-01", cinoutper);
					// WAN(全双工)端口流入利用率率
					//collBase.addKPI(unitId, "PM-00-02-001-02", cinper);
					// WAN(全双工)端口流出利用率率
					//collBase.addKPI(unitId, "PM-00-02-001-03", coutper);
				}catch(Exception e){
					e.printStackTrace();
				}				
			}
		}
		return collBase.KPISet;
	}
	
	public Vector<TblATO_KPIDETAIL> getTemperature(){
		CollBase collBase = new CollBase();
		TemperatureEntryWalker walker = new TemperatureEntryWalker();
		walker.walker(ipAddr, port, community);
		Vector<?> temperatureVector = walker.getEntry();
		for (int i = 0; i < temperatureVector.size(); i++) {
			TemperatureEntry row = (TemperatureEntry) temperatureVector.get(i);
			String unitId = PRE_UNITID + "-12" + ":" + neatDeviceName+"-"+this.getOIDIndex(row.getRowIndex());
			//CM-01-02-03-01    温度描述
			collBase.addKPI(unitId, "CM-01-02-03-01", row.getStatusDesc());
			//PM-00-02-800-02    10-13    温度    string    ℃    
			collBase.addKPI(unitId, "PM-00-02-800-02", row.getStatusValue());
			//PM-00-02-800-03    温度状态
			collBase.addKPI(unitId, "PM-00-02-800-03", row.getState());
		}
		collBase.displayKPI();
		return collBase.KPISet;
	}
	

	
	public Vector<TblATO_KPIDETAIL> getFan(){
		CollBase collBase = new CollBase();
		FanEntryWalker walker = new FanEntryWalker();
		walker.walker(ipAddr, port, community);
		Vector<?> FanVector = walker.getEntry();
		for (int i = 0; i < FanVector.size(); i++) {
			FanEntry row = (FanEntry) FanVector.get(i);
			String unitId = PRE_UNITID + "-13" + ":" + neatDeviceName+"-"+this.getOIDIndex(row.getFanIndex());
			//CM-01-02-03-02    10-13    风扇描述  
			collBase.addKPI(unitId, "CM-01-02-03-02", row.getFanStatusDesc());
			//PM-00-02-800-04    10-13    风扇状态  
			collBase.addKPI(unitId, "PM-00-02-800-04", row.getFanState());
		}
		collBase.displayKPI();
		return collBase.KPISet;
	}
	
	public Vector<TblATO_KPIDETAIL> getSupply(){
		CollBase result = new CollBase();
		SupplyEntryWalker walker = new SupplyEntryWalker();
		walker.walker(ipAddr, port, community);
		Vector<?> SupplyVector = walker.getEntry();
		for (int i = 0; i < SupplyVector.size(); i++) {
			SupplyEntry row = (SupplyEntry) SupplyVector.get(i);
            String unitId = PRE_UNITID + "-14" + ":" + neatDeviceName+"-"+this.getOIDIndex(row.getSupplyIndex());
            //CM-01-02-03-03    10-13    电源描述
            result.addKPI(unitId, "CM-01-02-03-03", row.getSupplyDesc());
			//PM-00-02-800-05    10-13    电源状态  
            result.addKPI(unitId, "CM-01-02-03-03", row.getSupplyState());
		}
		result.displayKPI();
		return result.KPISet;
	}
	
	public Vector<TblATO_KPIDETAIL> getIpEntry(){
		CollBase result = new CollBase();
		IpAddEntryWalker walker = new IpAddEntryWalker();
		walker.walker(ipAddr, port, community);
		Vector<?> SupplyVector = walker.getEntry();
		for (int i = 0; i < SupplyVector.size(); i++) {
			IpAddrEntry row = (IpAddrEntry) SupplyVector.get(i);
            String unitId = PRE_UNITID + "-16" + ":" + neatDeviceName +"-" + row.getIpAdEntAddr();
			
			//CM-01-02-03-04    10-13    IP地址   
			result.addKPI(unitId, "CM-01-02-03-04", row.getIpAdEntAddr());		
			//CM-01-02-03-05    10-13    子网掩码
			result.addKPI(unitId, "CM-01-02-03-05", row.getIpAdEntNetMask());
			//CM-01-02-03-06    10-13    广播地址
			result.addKPI(unitId, "CM-01-02-03-06", row.getIpAdEntNetMask());
			//CM-01-02-03-07    10-13 端口索引号
			result.addKPI(unitId, "CM-01-02-03-07", row.getIpAdEntIfIndex());
			//CM-01-02-03-08    10-13 可接受的最大数据报
			result.addKPI(unitId, "CM-01-02-03-08", row.getIpAdEntReasmMaxSize());
			
		}
		result.displayKPI();
		return result.KPISet;
	}
	
	public Vector<TblATO_KPIDETAIL> getRouterEntry(){
		CollBase result = new CollBase();
//		RouterEntryWalker walker = new RouterEntryWalker();
//		walker.walker(ipAddr, port, community);
//		
//		Vector<?> SupplyVector = walker.getEntry();
//		for (int i = 0; i < SupplyVector.size(); i++) {
//			RouterEntry row = (RouterEntry) SupplyVector.get(i);
//            String unitId = PRE_UNITID + "-16" + ":" + neatDeviceName +"-" + row.getIpRouteDest();
//            //CM-01-02-03-09    10-13   目标IP地址   
//			result.addKPI(unitId, "CM-01-02-03-09", row.getIpRouteDest());
//			//CM-01-02-03-10   10-13    下一跳地址
//			result.addKPI(unitId, "CM-01-02-03-10", row.getIpRouteNextHop());
//			//CM-01-02-03-11    10-13    路由类型
//			result.addKPI(unitId, "CM-01-02-03-11", row.getIpRouteType());
//			//CM-01-02-03-12   10-13 路由协议
//			result.addKPI(unitId, "CM-01-02-03-12", row.getIpRouteProto());
//			//CM-01-02-03-13    10-13 路由掩码
//			result.addKPI(unitId, "CM-01-02-03-13", row.getIpRouteMask());
//			//CM-01-02-03-14    10-13 存活时间
//			result.addKPI(unitId, "CM-01-02-03-14", row.getIpRouteMask());
//		}
		return result.KPISet;
	}
	
	
	/**
	 * PM-00-02-800-07 历史最大连接数 
	 * PM-00-02-800-08 当前连接数
	 * (采集不到)
	 */
	public Vector<TblATO_KPIDETAIL> getConnection(){	
		CollBase result = new CollBase();
		String unitId = PRE_UNITID + "-15" + ":" + neatDeviceName;
		
		SnmpHandler snmpHandler = null;
		try{
			snmpHandler = new SnmpHandler(ipAddr, port, community, 1);
			
			String hisMaxConnCount = snmpHandler.get(".1.3.6.1.4.1.9.9.147.1.2.2.2.1.5.40.7");
			String currentConnCount = snmpHandler.get(".1.3.6.1.4.1.9.9.147.1.2.2.2.1.5.40.6");
			result.addKPI(unitId, "PM-00-02-800-07", hisMaxConnCount);
			result.addKPI(unitId, "PM-00-02-800-08", currentConnCount);

			result.displayKPI();
		}catch (Exception e) {
			logger.error("Exception while getSystemPerformance", e);
		}finally{
			if(snmpHandler != null){
				snmpHandler.destroy();
			}
		}

		return result.KPISet;		
	}

	/**
	 * PM-00-02-001-07 设备内存利用率
	 * PM-00-02-001-06 设备CPU利用率
	 */
	public Vector<TblATO_KPIDETAIL> getSystemPerformance() {
		CollBase result = new CollBase();
		String unitId = PRE_UNITID + "-10" + ":" + neatDeviceName + "-total";
		
		SnmpHandler snmpHandler = null;
		try{
			snmpHandler = new SnmpHandler(ipAddr, port, community, 1);
			
			String cpuUseRate = snmpHandler.get(".1.3.6.1.4.1.9.2.1.57.0");
			
			//System.out.println("cpu use rate : " + cpuUseRate);
			
			result.addKPI(unitId, "PM-00-02-001-06", cpuUseRate);
			
			List<String> memusedpool = snmpHandler.walk(".1.3.6.1.4.1.9.9.48.1.1.1.5");
			
			List<String> memfreepool = snmpHandler.walk(".1.3.6.1.4.1.9.9.48.1.1.1.6");
			
			String sMemPer = "0";
			if (memusedpool != null && memusedpool.size() > 0
					&& memfreepool != null && memfreepool.size() > 0) {
				float memSumUsed = 0;
				float memSumFree = 0;
				for (String str : memusedpool) {
					memSumUsed += Float.parseFloat(str);
				}
				for(String str : memfreepool){
					memSumFree += Float.parseFloat(str);
				}
				//System.out.println("memSumUsed : " + memSumUsed + " , memSumFree : " + memSumFree + " , percentage : " + (memSumUsed / (memSumUsed + memSumFree)));
				float fMemPer = (memSumUsed / (memSumUsed + memSumFree))* 100f;
				sMemPer = Formater.formatDecimalKpivalue(Float.toString(fMemPer));
				//System.out.println("memSumUsed : " + memSumUsed + " , memSumFree : " + memSumFree + " , fMemPer : " + fMemPer);
			}
			result.addKPI(unitId, "PM-00-02-001-07", sMemPer);

			result.displayKPI();
		}catch (Exception e) {
			logger.error("Exception while getSystemPerformance", e);
		}finally{
			if(snmpHandler != null){
				snmpHandler.destroy();
			}
		}

		return result.KPISet;
	}
	
	public Vector<TblATO_KPIDETAIL> getSwitchCpuInfo(){
		CollBase result = new CollBase();
		String unitId = PRE_UNITID + "-10" + ":" + neatDeviceName + "-cpu";
		
		SnmpHandler snmpHandler = null;
		try{
			snmpHandler = new SnmpHandler(ipAddr, port, community, 1);
			
			String cpuUseRate = snmpHandler.get(".1.3.6.1.4.1.9.2.1.57.0");
			result.addKPI(unitId, "PM-00-02-001-07", cpuUseRate);
			result.displayKPI();
		}catch (Exception e) {
			logger.error("Exception while getSwitchCpuInfo", e);
		}finally{
			if(snmpHandler != null){
				snmpHandler.destroy();
			}
		}
		return result.KPISet;
	}
	
	public Vector<TblATO_KPIDETAIL> getSwitchMemInfo(){
		CollBase result = new CollBase();
		String unitId = PRE_UNITID + "-10" + ":" + neatDeviceName + "-memory";
		
		SnmpHandler snmpHandler = null;
		try{
			snmpHandler = new SnmpHandler(ipAddr, port, community, 1);
			
			List<String> memusedpool = snmpHandler.walk(".1.3.6.1.4.1.9.9.48.1.1.1.5");
			
			List<String> memfreepool = snmpHandler.walk(".1.3.6.1.4.1.9.9.48.1.1.1.6");
			
			String sMemPer = "0";
			if (memusedpool != null && memusedpool.size() > 0
					&& memfreepool != null && memfreepool.size() > 0) {
				int memSumUsed = 0;
				int memSumFree = 0;
				for (String str : memusedpool) {
					memSumUsed += Integer.parseInt(str);
				}
				for(String str : memfreepool){
					memSumFree += Integer.parseInt(str);
				}
				float fMemPer = memSumUsed * 100 / (memSumUsed + memSumFree);
				sMemPer = Formater.formatDecimalKpivalue(Float.toString(fMemPer));
			}
			result.addKPI(unitId, "PM-00-02-001-06", sMemPer);

			result.displayKPI();
		}catch (Exception e) {
			logger.error("Exception while getSystemPerformance", e);
		}finally{
			if(snmpHandler != null){
				snmpHandler.destroy();
			}
		}

		return result.KPISet;
	}
	
	private String getOIDIndex(String oid){
		String id="0";
		if("".equals(oid)||null==oid){
			id="";
		}else{
			if(oid.indexOf(".")>=0){
				int i=0;
				i=oid.lastIndexOf(".")+1;
				id= oid.substring(i);
			}
		}
		return id;
	}
	
	public static void main(String[] args) {
		new CollCiscoSwitchWithSNMP("172.21.2.254", 161, "public", "c2918_2_1").getConfig();
	}
}