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

📄 notificationmanager.java

📁 opennms得相关源码 请大家看看
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        int id = 0;            Connection connection = null;            try {            connection = getConnection();            Statement stmt = connection.createStatement();            ResultSet results = stmt.executeQuery(m_configManager.getNextNotifIdSql());                results.next();                id = results.getInt(1);                stmt.close();            results.close();        } finally {            if (connection != null) {                try {                    connection.close();                } catch (SQLException e) {                }            }        }        return id;    }    /**     * This method returns a boolean indicating if the page has been responded     * to by any member of the group the page was sent to.     */    public boolean noticeOutstanding(int noticeId) throws IOException, MarshalException, ValidationException {        boolean outstanding = false;            Connection connection = null;        try {            connection = getConnection();            PreparedStatement statement = connection.prepareStatement(getConfigManager().getConfiguration().getOutstandingNoticesSql());                statement.setInt(1, noticeId);                ResultSet results = statement.executeQuery();                // count how many rows were returned, if there is even one then the            // page            // has been responded too.            int count = 0;            while (results.next()) {                count++;            }                if (count == 0) {                outstanding = true;            }                statement.close();            results.close();        } catch (SQLException e) {            ThreadCategory.getInstance(getClass()).error("Error getting notice status: " + e.getMessage(), e);        } finally {            if (connection != null) {                try {                    connection.close();                } catch (SQLException e) {                }            }        }            return outstanding;    }    /**     *      */    public Collection acknowledgeNotice(Event event, String uei, String[] matchList) throws SQLException, IOException, MarshalException, ValidationException {        Category log = ThreadCategory.getInstance(getClass());        Connection connection = null;        Collection notifIDs = new LinkedList();        try {            // First get most recent eventid from notifications             // that match the matchList, then get all notifications            // with this eventid            connection = getConnection();            int eventID = 0;            boolean wasAcked = false;            StringBuffer sql = new StringBuffer("SELECT eventid FROM notifications WHERE eventuei=? ");            for (int i = 0; i < matchList.length; i++) {                sql.append("AND ").append(matchList[i]).append("=? ");            }            sql.append("ORDER BY eventid desc limit 1");            PreparedStatement statement = connection.prepareStatement(sql.toString());            statement.setString(1, uei);                for (int i = 0; i < matchList.length; i++) {                if (matchList[i].equals("nodeid")) {                    statement.setLong(i + 2, event.getNodeid());                }                    if (matchList[i].equals("interfaceid")) {                    statement.setString(i + 2, event.getInterface());                }                    if (matchList[i].equals("serviceid")) {                    statement.setInt(i + 2, getServiceId(event.getService()));                }            }                ResultSet results = statement.executeQuery();            if (results != null && results.next()) {                eventID = results.getInt(1);                log.debug("EventID for notice(s) to be acked: " + eventID);                sql = new StringBuffer("SELECT notifyid, answeredby, respondtime FROM notifications WHERE eventID=?");                    statement = connection.prepareStatement(sql.toString());                statement.setInt(1, eventID);                    results = statement.executeQuery();                    if (results != null) {                    while (results.next()) {                        int notifID = results.getInt(1);                        String ansBy = results.getString(2);                        Timestamp ts = results.getTimestamp(3);                        if(ansBy == null) {                            ansBy = "auto-acknowledged";                            ts = new Timestamp((new Date()).getTime());                        } else if(ansBy.indexOf("auto-acknowledged") > -1) {                            log.debug("Notice has previously been auto-acknowledged. Skipping...");                            continue;                        } else {                            wasAcked = true;                            ansBy = ansBy + "/auto-acknowledged";                        }                        log.debug("Matching DOWN notifyID = " + notifID + ", was acked by user = " + wasAcked + ", ansBy = " +ansBy);                        PreparedStatement update = connection.prepareStatement(getConfigManager().getConfiguration().getAcknowledgeUpdateSql());                            update.setString(1, ansBy);                        update.setTimestamp(2, ts);                        update.setInt(3, notifID);                            update.executeUpdate();                        update.close();                        if(wasAcked) {                            notifIDs.add(new Integer(-1 * notifID));                        } else {                            notifIDs.add(new Integer(notifID));                        }                    }                }            } else {                log.debug("No matching DOWN eventID found");            }                statement.close();            results.close();        } finally {            if (connection != null) {                try {                    connection.close();                } catch (SQLException e) {                }            }        }        return notifIDs;    }    /**     */    public List getActiveNodes() throws SQLException {        String NODE_QUERY = "SELECT   n.nodeid " + "FROM     node n " + "WHERE    n.nodetype != 'D' " + "ORDER BY n.nodelabel";            java.sql.Connection connection = null;        List allNodes = new ArrayList();            try {            connection = getConnection();                Statement stmt = connection.createStatement();            ResultSet rset = stmt.executeQuery(NODE_QUERY);                if (rset != null) {                // Iterate through the result and build the array list                while (rset.next()) {                    int nodeID = rset.getInt(1);                        allNodes.add(new Integer(nodeID));                }            }            return allNodes;        } finally {            if (connection != null) {                try {                    connection.close();                } catch (SQLException e) {                }            }        }    }    /**     *      */    public String getServiceNoticeStatus(String nodeID, String ipaddr, String service) throws SQLException {        String notify = "Y";            String query = "SELECT notify FROM ifservices, service WHERE nodeid=? AND ipaddr=? AND ifservices.serviceid=service.serviceid AND service.servicename=?";        java.sql.Connection connection = null;            try {            connection = getConnection();                PreparedStatement statement = connection.prepareStatement(query);            statement.setInt(1, Integer.parseInt(nodeID));            statement.setString(2, ipaddr);            statement.setString(3, service);                ResultSet rs = statement.executeQuery();                if (rs.next() && rs.getString("notify") != null) {                notify = rs.getString("notify");                if (notify == null)                    notify = "Y";            }            return notify;        } finally {            if (connection != null) {                try {                    connection.close();                } catch (SQLException e) {                }            }        }    }    /**     *      */    public void updateNoticeWithUserInfo(String userId, int noticeId, String media, String contactInfo, String autoNotify) throws SQLException {        Category log = ThreadCategory.getInstance(getClass());        if (noticeId < 0) return;        log.debug("updating usersnotified: User = " + userId + ", notice ID = " + noticeId + ", conctactinfo = " + contactInfo + ", media = " + media + ", autoNotify = " + autoNotify);        Connection connection = null;        try {            connection = getConnection();            PreparedStatement insert = connection.prepareStatement("INSERT INTO usersNotified (userid, notifyid, notifytime, media, contactinfo, autonotify) values (?,?,?,?,?,?)");                insert.setString(1, userId);            insert.setInt(2, noticeId);                insert.setTimestamp(3, new Timestamp((new Date()).getTime()));                insert.setString(4, media);            insert.setString(5, contactInfo);            insert.setString(6, autoNotify);                insert.executeUpdate();            insert.close();        } finally {            if (connection != null) {                try {                    connection.close();                } catch (SQLException e) {                }            }        }    }    /**     * This method inserts a row into the notifications table in the database.     * This row indicates that the page has been sent out.     * @param queueID     */    public void insertNotice(int notifyId, Map params, String queueID) throws SQLException {        Connection connection = null;        try {            connection = getConnection();            PreparedStatement statement = connection.prepareStatement("INSERT INTO notifications (textmsg, numericmsg, notifyid, pagetime, nodeid, interfaceid, serviceid, eventid, eventuei, subject, queueID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");                // notifications textMsg field            statement.setString(1, (String) params.get(NotificationManager.PARAM_TEXT_MSG));                // notifications numericMsg field            statement.setString(2, (String) params.get(NotificationManager.PARAM_NUM_MSG));                // notifications notifyID field            statement.setInt(3, notifyId);                // notifications pageTime field            statement.setTimestamp(4, new Timestamp((new Date()).getTime()));                // notifications nodeID field            String node = (String) params.get(NotificationManager.PARAM_NODE);            if (node != null && !node.trim().equals("") && !node.toLowerCase().equals("null") && !node.toLowerCase().equals("%nodeid%")) {                statement.setInt(5, Integer.parseInt(node));            } else {                statement.setNull(5, Types.INTEGER);

⌨️ 快捷键说明

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