package com.eactive.eai.rms.client.agent;

import com.eactive.eai.rms.client.SocketClient;
import com.eactive.eai.rms.client.context.RmsProperties;
import com.eactive.eai.rms.client.service.HostStatusService;
import com.eactive.eai.rms.onl.vo.HostStatusVo;
import com.eactive.eai.rms.onl.vo.ItsmVo;

public class ItsmMonitorAgent extends AbstractScheduledAgent {

    private HostStatusService hostStatusService;
    private RmsProperties rmsProperties;
    private SocketClient socketClient;

    private HostStatusVo hostStatusVo;

    public void run() {
        // ITSM 에 전송하기 위해 추가로 수집해야 할 리소스
        // Network I/O, Disk swap

//        ItsmVo itsmVo = (ItsmVo) applicationContext.getBean("itsmVo");
//
//        try {
//            String cmd = rmsProperties.getStringProperty(
//                RmsProperties.ITSM_NET_CMD, "/fsapp/eai/rms_util/nettot");
//            String tmp[] = hostStatusService.getInOutBps(cmd).split(",");
//            if (logger.isDebugEnabled()) {
//                if (tmp == null || "".equals(tmp)) {
//                    logger.debug("hostStatusService.getInOutBps() returned null");
//                } else {
//                    for (int i = 0; i < tmp.length; i++) {
//                        logger.debug(tmp[i]);
//                    }
//                }
//            }
//
//            if (tmp.length >= 2) {
//                itsmVo.setIn(tmp[0]);
//                itsmVo.setOut(tmp[1]);
//            }
//
//            cmd = rmsProperties.getStringProperty(RmsProperties.ITSM_DISK_CMD,
//                "/fsapp/eai/rms_util/disktot");
//            String tmp2 = hostStatusService.getSwapUsage(cmd);
//            if (logger.isDebugEnabled()) {
//                if (tmp2 == null || "".equals(tmp2)) {
//                    logger.debug("hostStatusService.getSwapSize() returned null");
//                } else {
//                    logger.debug(cmd + " : result=" + tmp2);
//                }
//            }
//
//            if (tmp2 != null && !tmp2.equals("")) {
//                itsmVo.setSwap(tmp2); // 실제는 디스크 SWAP 사용율 이다. ( usage % )
//            }
//
//            itsmVo.setTime(null); // use default
//
//            itsmVo.setCpu("" + hostStatusVo.getCpu());
//            itsmVo.setDisk("" + hostStatusVo.getDisk());
//            itsmVo.setMemory("" + hostStatusVo.getMemory());
//
//            socketClient.send(itsmVo);
//            logger.debug("SEND ItsmMonitorAgent : " + itsmVo );
//        } catch (Exception e) {
//            //e.printStackTrace();
//            logger.error("RMS : (rms_client) Exception !!!",e);
//        }
//
//        if (logger.isDebugEnabled()) {
//            logger.debug(itsmVo.toString());
//        }
    }

    /**
     * @param hostStatusService the hostStatusService to set
     */
    public void setHostStatusService(HostStatusService hostStatusService) {
        this.hostStatusService = hostStatusService;
    }

    /**
     * @param rmsProperties the rmsProperties to set
     */
    public void setRmsProperties(RmsProperties rmsProperties) {
        this.rmsProperties = rmsProperties;
    }

    /**
     * @param socketClient the socketClient to set
     */
    public void setSocketClient(SocketClient socketClient) {
        this.socketClient = socketClient;
    }

    /**
     * @param hostStatusVo the hostStatusVo to set
     */
    public void setHostStatusVo(HostStatusVo hostStatusVo) {
        this.hostStatusVo = hostStatusVo;
    }

}
