CollUnion_NEW.java 2.95 KB
/**
 * 功能:并发监控agent所在主机的主机状态
 * 作者:毛志荣
 * 日期:2008-5-2 12:34
 * 版本:v1.00
 * 
 */
package com.sitech.ismp.coll;

import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import sitech.www.frame.jdbc.SqlQuery;
import sitech.www.frame.util.DataSourceUtils;

public class CollUnion_NEW {

	// private static ExecutorService executorService;

	// static List hosts = new ArrayList();

	public static String host_type;

	public static String times;

	public static String count;

	public static String swap_up_cmd;

	// public static String swap_down_cmd;

	public static String kpi_id = "FM-00-01-001-01";
	/**
	 * 根据unit_id与kpi_id得到相应的值
	 */

	static {

	}

	private static String getFilterNet() {
		String result = "";
		ResourceBundle resourceBundle = ResourceBundle.getBundle("netfilter");
		result = resourceBundle.getString("net");
		if (result.equals("")) {
			return "";
		} else {
			String temp = "";
			String[] strs = result.split(",");
			for (int i = 0; i < strs.length; i++) {
				temp = temp + " and t.ip_addr not like '" + strs[i] + "%'";
			}
			result = temp;
		}
		return result;
	}

	/** --- 主机状态监控--- */
	public void start() {

		ArrayList hosts = new ArrayList();

		ResourceBundle config = ResourceBundle.getBundle("conf");
		host_type = config.getString("host_type");
		times = config.getString("ping_times");
		count = config.getString("count");
		swap_up_cmd = config.getString("swap_up_cmd");
		// swap_down_cmd = config.getString("swap_down_cmd");

		String filterString = getFilterNet();

		String sql = "select t.ip_addr, SUBSTR(t.unit_id, 0, instr(t.unit_id, ':')-1) || '-10' || SUBSTR(t.unit_id, instr(t.unit_id, ':') ) || '-total',t.flag  from "
				+ "tb_asset_host t where t.enable = '1'" + filterString;
		System.out.println("[监控主机状态:" + sql + "]");
		java.sql.Connection conn = DataSourceUtils.getConnection();
		System.out.println("数据库连接" + conn);
		try {
			List list = SqlQuery.findList(sql);
			int size = list.size();
			for (int i = 0; i < size; i++) {
				hosts.add((String[]) list.get(i));
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DataSourceUtils.closeConnection(conn);
			conn = null;
		}

		// //////////////////////////////////////////////////////////

		// executorService = Executors.newFixedThreadPool(20);
		System.out.println("[主机台数: " + hosts.size() + "]");
		for (int index = 0; index < hosts.size(); index++) {
			String[] db_msg = (String[]) hosts.get(index);
			String host_ip = db_msg[0];
			String unit_id = db_msg[1];
			String flag = db_msg[2];
			System.out.println(unit_id);
			// executorService.execute(new CollUnionWorker_NEW(host_ip, unit_id,
			// flag));
			Thread thread = new Thread(new CollUnionWorker_NEW(host_ip,
					unit_id, flag));
			thread.start();
		}
	}

	public static void main(String[] args) {
		CollUnion_NEW moni_db = new CollUnion_NEW();
		moni_db.start();
	}
}