CollNetDevice.java 6.26 KB
package com.sitech.ismp.coll.net;

import java.util.HashMap;
import java.util.Scanner;
import java.util.Vector;

import com.sitech.database.dao.TbTmpInterfaceDao;
import com.sitech.ismp.coll.basic.TblATO_KPIDETAIL;
import com.sitech.util.DES3;
import com.sitech.util.LogUtil;

/**
 * User: LJ
 * Date: 2010-1-18
 * Time: 16:57:21
 */
public class CollNetDevice implements CollNetDeviceMBean {

    static{
        // 初始化MBean时清理临时表
        new TbTmpInterfaceDao().clean();
    }

    /**
     * 设备总体指标:
     * CM-00-02-001-01 网元类型
     * CM-00-02-001-02 网元厂商
     * CM-00-02-001-03 设备软件版本
     * CM-00-02-001-04 网元名
     * CM-00-02-001-05 网元管理端口IP地址
     * CM-00-02-002-06 端口数量
     * CM-00-02-001-07 开机时间
     * 采集时间间隔(月)
     */
    public Vector<TblATO_KPIDETAIL> getSysConfig(HashMap<String, String> params) {
        try {
            return new CollNetDeviceWithSNMP().getTotal(params);
        } catch (Exception e) {
            LogUtil.error("Exception while getSysConfig()", e);
        }

        return null;
    }

    public Vector<TblATO_KPIDETAIL> getStatus(HashMap<String, String> params) {
        try {
            return new CollNetDeviceWithSNMP().getStatus(params);
        } catch (Exception e) {
            LogUtil.error("Exception while getSysConfig()", e);
        }

        return null;
    }
	

	/**
	 * PM-00-02-001-06 设备CPU利用率
	 * PM-00-02-001-07 设备内存利用率
	 * 采集时间间隔(15分钟)
	 * 10-13-10-12
	 */
	public Vector<TblATO_KPIDETAIL> getCpuMem(HashMap<String, String> params) {
		try {
			return new CollNetDeviceWithSNMP().getCpuMem(params);
		} catch (Exception e) {
			LogUtil.error("Exception while getCpuMem()", e);
		}

		return null;
    }

    /**
     * 设备链路性能指标
     * PM-00-02-001-30	ping链路最小时延
     * PM-00-02-001-31	ping链路平均时延
     * PM-00-02-001-32	ping链路最大时延
     * PM-00-02-001-33	ping链路状态
     * 采集时间间隔(15分钟)
     *
     * @param params HashMap KEY:[IP,PORT,COMMUNITY,HOST_NAME]
     */
	public Vector<TblATO_KPIDETAIL> getPing(HashMap<String, String> params) {
		return null;
	}

    @Override
    public Vector<TblATO_KPIDETAIL> getFirewall(HashMap<String, String> params) {
        try {
            return new CollNetDeviceWithSNMP().getFirewall(params);
        } catch (Exception e) {
            LogUtil.error("Exception while getFirewall()", e);
        }

        return null;
    }
    public Vector<TblATO_KPIDETAIL> getSubnetMask(HashMap<String, String> params) {
        try {
            return new CollNetDeviceWithSNMP().getSubnetMask(params);
        } catch (Exception e) {
            LogUtil.error("Exception while getSubnetMask()", e);
        }

        return null;
    }

    /**
	 * 采集端口指标
	 */
	public Vector<TblATO_KPIDETAIL> getPort(HashMap<String, String> params) {
		try {
			return new CollNetDeviceWithSNMP().getPort(params);
		} catch (Exception e) {
			LogUtil.error("Exception while getPort()", e);
		}

		return null;
    }

    public static void main(String[] args) {
		System.out.println("***************Net Device Collect Test Begin*********************");

		String ipAddr = "172.21.21.253";
		String port = "161";
		String community = "public1";
		String deviceName = "ZERO";
		String kbpClass = "10-16-10";
		String type = "7";
        String serurityName ="csdtestna";
        String authenticationPassphrase="";
        String privacyPassphrase="";
        String securityLevel="3";
//		String ipAddr = "127.0.0.1";
//		String port = "161";
//		String community = "public";
//		String deviceName = "ZERO";
//		String kbpClass = "10-16-10";
//		String type = "6";

//		String ipAddr = "10.208.208.242";
//		String port = "161";
//		String community = "public";
//		String deviceName = "5_S3528_A";
//		String kbpClass = "10-16-11";
//		String type = "5";

        // FIREWALL CISCO PIX 535
//		String ipAddr = "192.168.1.43";
//		String port = "161";
//		String community = "public";
//		String deviceName = "PIX_535";
//		String kbpClass = "10-16-11";
//		String type = "1";

//        // SWITCH Quidway S8505
//		String ipAddr = "192.168.1.1";
//		String port = "161";
//		String community = "public";
//		String deviceName = "hw_quidway";
//		String kbpClass = "10-16-10";
//		String type = "1";

		System.out.println("IP_ADDR=" + ipAddr + ", SNMP_PORT=" + port
				+ ", READ_COMMUNITY=" + community + ", DEVICE_NAME=" + deviceName);

	    HashMap<String, String> params = new HashMap<String, String>();
	    // 网络设备IP地址
		params.put("IP", ipAddr);
		// SNMP端口
		params.put("PORT", port);
		// SNMP Read Community
		params.put("COMMUNITY", DES3.encrypt(community));
		// 网络设备名称
		params.put("HOST_NAME", deviceName);
		// 网络设备类型代表的KBP_CLASS
		params.put("KBP_CLASS", kbpClass);
		params.put("VERSION", "v2c");
		params.put("securityName", serurityName);
		params.put("auth_priv_mode", securityLevel);

		Vector<TblATO_KPIDETAIL> result = new Vector<TblATO_KPIDETAIL>();
		CollNetDevice collector = new CollNetDevice();

		int method = Integer.parseInt(type);

		switch (method) {
		case 0:
			result.addAll(collector.getSysConfig(params));
			result.addAll(collector.getCpuMem(params));
			result.addAll(collector.getPing(params));
			result.addAll(collector.getPort(params));
			break;
		case 1:
			result.addAll(collector.getSysConfig(params));
			break;
		case 2:
			result.addAll(collector.getCpuMem(params));
			break;
		case 3:
			result.addAll(collector.getPing(params));
			break;
		case 4:
			result.addAll(collector.getPort(params));
			break;
		case 5:
			result.addAll(collector.getFirewall(params));
			break;
		case 6:
			result.addAll(collector.getSubnetMask(params));
			break;
		case 7:
			result.addAll(collector.getStatus(params));
			break;
		default:
			break;
		}

		System.out.println("***************Net Device Collect Test End*********************");

		for (int i = 0; i < result.size(); i++) {
			TblATO_KPIDETAIL record = (TblATO_KPIDETAIL) result.get(i);
			System.out.println(record.UNIT_ID + "\t" + record.KPI_ID + "\t"
					+ record.KPI_VALUE);
		}
	}

	private static String read(String prompt) {
		Scanner scanner = new Scanner(System.in);
		System.out.print(prompt);
		return scanner.nextLine();
	}
}