Blame view

src/com/sitech/ismp/coll/net/CollNetDevice.java 6.26 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
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();
	}
}