⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nsclientmanager.java

📁 opennms得相关源码 请大家看看
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    }    /**     * This method performs a check of the state of NT services on the remote     * service. The services to check are contained in the 'parameter' string     * in a comma delimited format (that is prepared to the client format     * using the <code>prepList</code> method.) The default result code is     * <code>NsclientPacket.RES_STATE_OK</code> unless one of the services     * responds as 'Stopped' - in which case the result code is set to     * <code>NsclientPacket.RES_STATE_CRIT</code>     *      * @param param     *            The param string member should contain a comma delimited     *            list of NT services on the remote service.     * @return the processed <code>NsclientPacket</code>.     * @throws NsclientException     *             this method rethrows the exception thrown by     *             <code>sendCheckRequest</code>     */    private NsclientPacket checkServiceState(NsclientCheckParams param)            throws NsclientException {        NsclientPacket pack = null;        try {            pack = sendCheckRequest(m_Password + "&" + CHECK_SERVICESTATE                    + "&ShowAll&" + prepList(param.getParamString()));            pack.setResultCode(NsclientPacket.RES_STATE_OK);            // check up response from "1& Service1: State - Service2: State"            String[] services = pack.getResponse().replaceFirst("^\\d&\\s+",                                                                "").split(                                                                          "\\s+-\\s+");            for (int i = 0; i < services.length; i++) {                if (services[i].split(":\\s+")[1].equals("Stopped"))                    pack.setResultCode(NsclientPacket.RES_STATE_CRIT);            }            return pack;        } catch (NsclientException e) {            throw e;        }    }    /**     * This method performs a check of the state of NT process on the remote     * service. The processes to check are contained in the 'parameter' string     * in a comma delimited format (that is prepared to the client format     * using the <code>prepList</code> method.) The default result code is     * <code>NsclientPacket.RES_STATE_OK</code> unless one of the processes     * responds as 'not running' - in which case the result code is set to     * <code>NsclientPacket.RES_STATE_CRIT</code>     *      * @param param     *            The param string member should contain a comma delimited     *            list of NT processes on the remote service.     * @return the processed <code>NsclientPacket</code>.     * @throws NsclientException     *             this method rethrows the exception thrown by     *             <code>sendCheckRequest</code>     */    private NsclientPacket checkProcState(NsclientCheckParams param)            throws NsclientException {        NsclientPacket pack = null;        try {            pack = sendCheckRequest(m_Password + "&" + CHECK_PROCSTATE                    + "&ShowAll&" + prepList(param.getParamString()));            pack.setResultCode(NsclientPacket.RES_STATE_OK);            // Check for "ERROR" string.            if (pack.getResponse().matches(".*ERROR.*")) {                pack.setResultCode(NsclientPacket.RES_STATE_UNKNOWN);                return pack;            }            // check up response from "1& Prc1: State - Proc2: State"            String[] services = pack.getResponse().replaceFirst("^\\d&\\s+",                                                                "").split(                                                                          "\\s+-\\s+");            for (int i = 0; i < services.length; i++) {                if (services[i].split(":\\s+")[1].matches("not running\\s*"))                    pack.setResultCode(NsclientPacket.RES_STATE_CRIT);            }            return pack;        } catch (NsclientException e) {            throw e;        }    }    /**     * This method performs a check of the disk space available on the drive     * specified in the 'parameter' string. The warning and critical     * thresholds defined by 'warningPercent' and 'criticalPercent' are used     * to validate the percent of used disk space.     *      * @param param     *            The param string should contain a drive letter, warning and     *            critical should contain non-zero percentages.     * @return the processed <code>NsclientPacket</code>.     * @throws NsclientException     *             this method rethrows the exception thrown by     *             <code>sendCheckRequest</code>     */    private NsclientPacket checkUsedDiskSpace(NsclientCheckParams param)            throws NsclientException {        NsclientPacket pack = null;        try {            // send/receive the request            pack = sendCheckRequest(m_Password + "&" + CHECK_USEDDISKSPACE                    + "&" + param.getParamString());            pack.setResultCode(NsclientPacket.RES_STATE_OK);            // Check for "ERROR" string.            if (pack.getResponse().matches(".*ERROR.*")) {                pack.setResultCode(NsclientPacket.RES_STATE_UNKNOWN);                return pack;            }            // parse out the response.            String[] results = pack.getResponse().split("&");            double freeDisk = Double.parseDouble(results[0]);            double totalDisk = Double.parseDouble(results[1]);            double usedPerc = ((totalDisk - freeDisk) / totalDisk) * 100;            // check to see if the drives even exist.            if (freeDisk < 0 || totalDisk < 0) {                pack.setResultCode(NsclientPacket.RES_STATE_UNKNOWN);                return pack;            }            // Process checks.            if (param.getWarningPercent() != 0) {                if (usedPerc > param.getWarningPercent()) {                    pack.setResultCode(NsclientPacket.RES_STATE_WARNING);                }            }            if (param.getCriticalPercent() != 0) {                if (usedPerc > param.getCriticalPercent()) {                    pack.setResultCode(NsclientPacket.RES_STATE_CRIT);                }            }            return pack;        } catch (NsclientException e) {            throw e;        }    }    /**     * This method performs a check of the memory space used on the remote     * server. The warning and critical thresholds defined by 'warningPercent'     * and 'criticalPercent' are used to validate the percent of used memory.     *      * @param param     *            The params warning and critical should contain non-zero     *            percentages.     * @return the processed <code>NsclientPacket</code>.     * @throws NsclientException     *             this method rethrows the exception thrown by     *             <code>sendCheckRequest</code>     */    private NsclientPacket checkMemoryUsage(NsclientCheckParams param)            throws NsclientException {        NsclientPacket pack = null;        try {            // send/receive the request            pack = sendCheckRequest(m_Password + "&" + CHECK_MEMUSE + "&7");            pack.setResultCode(NsclientPacket.RES_STATE_OK);            // Check for "ERROR" string.            if (pack.getResponse().matches(".*ERROR.*")) {                pack.setResultCode(NsclientPacket.RES_STATE_UNKNOWN);                return pack;            }            // parse out the response            String[] results = pack.getResponse().split("&");            float memCommitLimit = Float.parseFloat(results[0]);            float memCommitByte = Float.parseFloat(results[1]);            float memUsedPerc = (memCommitByte / memCommitLimit) * 100;            // if a warning percent was configured, check it.            if (param.getWarningPercent() != 0) {                if (memUsedPerc > (float) param.getWarningPercent()) {                    pack.setResultCode(NsclientPacket.RES_STATE_WARNING);                }            }            // if a crtical percent was configured, check it, overriding            // warning percent.            if (param.getCriticalPercent() != 0) {                if (memUsedPerc > (float) param.getCriticalPercent()) {                    pack.setResultCode(NsclientPacket.RES_STATE_CRIT);                }            }            return pack;        } catch (NsclientException e) {            throw e;        }    }    /**     * This method performs a check of a perfmon object as defined by the     * 'parameter' string. An example of this string would be:     * \Memory(_Total)\Pool Paged Bytes - the warning and crtical members of     * param will define thresholds used to validate the perfmon object value.     *      * @param param     *            The param string should contain a perfmon OID, warning and     *            critical should contain non-zero values.     * @return the processed <code>NsclientPacket</code>.     * @throws NsclientException     *             this method rethrows the exception thrown by     *             <code>sendCheckRequest</code>     */    private NsclientPacket checkPerfCounter(NsclientCheckParams param)            throws NsclientException {        NsclientPacket pack = null;        try {            // send/receive the request            pack = sendCheckRequest(m_Password + "&" + CHECK_COUNTER + "&"                    + prepList(param.getParamString()));            pack.setResultCode(NsclientPacket.RES_STATE_OK);            // Check for "ERROR" string.            if (pack.getResponse().matches(".*ERROR.*")) {                pack.setResultCode(NsclientPacket.RES_STATE_UNKNOWN);                return pack;            }            // parse out the response.            float counterValue = Float.parseFloat(pack.getResponse());            // if a warning percent was configured, check it.            if (param.getWarningPercent() != 0) {                if (counterValue > (float) param.getWarningPercent()) {                    pack.setResultCode(NsclientPacket.RES_STATE_WARNING);                }            }            // if a crtical percent was configured, check it, overriding            // warning percent.            if (param.getCriticalPercent() != 0) {                if (counterValue > (float) param.getCriticalPercent()) {                    pack.setResultCode(NsclientPacket.RES_STATE_CRIT);                }            }            return pack;        } catch (NsclientException e) {            throw e;        }    }    /**     * This method performs a check of a file's age as defined by the     * 'parameter' string.     *      * @param param     *            The param string should contain a full path to a file,     *            warning and critical should contain non-zero ages in     *            minutes.     * @return the processed <code>NsclientPacket</code>.     * @throws NsclientException     *             this method rethrows the exception thrown by     *             <code>sendCheckRequest</code>     */    private NsclientPacket checkFileAge(NsclientCheckParams param)            throws NsclientException {        NsclientPacket pack = null;        try {            // send/receive the request            pack = sendCheckRequest(m_Password + "&" + CHECK_FILEAGE + "&"                    + param.getParamString());            pack.setResultCode(NsclientPacket.RES_STATE_OK);            // Check for "ERROR" string.            if (pack.getResponse().matches(".*ERROR.*")) {                pack.setResultCode(NsclientPacket.RES_STATE_UNKNOWN);                return pack;            }            // this will store our date.            // SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy            // h:mm:ss a");            String[] results = pack.getResponse().split("&");            double minutes = Double.parseDouble(results[0]);            // check the age of the file, if it's newer than the            // warning/critical, change the state.            if (param.getWarningPercent() != 0) {                if (minutes < param.getWarningPercent())                    pack.setResultCode(NsclientPacket.RES_STATE_WARNING);            }            if (param.getCriticalPercent() != 0) {                if (minutes < param.getCriticalPercent())                    pack.setResultCode(NsclientPacket.RES_STATE_CRIT);            }            return pack;        } catch (NsclientException e) {            throw e;        }    }    private String prepList(String list) {        return list.replaceAll(",", "&");    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -