use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class NotificationManager method updateNoticeWithUserInfo.
/**
* <p>updateNoticeWithUserInfo</p>
*
* @throws java.io.IOException if any.
* @param userId a {@link java.lang.String} object.
* @param noticeId a int.
* @param media a {@link java.lang.String} object.
* @param contactInfo a {@link java.lang.String} object.
* @param autoNotify a {@link java.lang.String} object.
* @throws java.sql.SQLException if any.
*/
public void updateNoticeWithUserInfo(final String userId, final int noticeId, final String media, final String contactInfo, final String autoNotify) throws SQLException, IOException {
if (noticeId < 0)
return;
int userNotifId = getUserNotifId();
LOG.debug("updating usersnotified: ID = {} User = {}, notice ID = {}, contactinfo = {}, media = {}, autoNotify = {}", autoNotify, userNotifId, userId, noticeId, contactInfo, media);
Connection connection = null;
final DBUtils d = new DBUtils(getClass());
try {
connection = getConnection();
d.watch(connection);
final PreparedStatement insert = connection.prepareStatement("INSERT INTO usersNotified (id, userid, notifyid, notifytime, media, contactinfo, autonotify) values (?,?,?,?,?,?,?)");
d.watch(insert);
insert.setInt(1, userNotifId);
insert.setString(2, userId);
insert.setInt(3, noticeId);
insert.setTimestamp(4, new Timestamp((new Date()).getTime()));
insert.setString(5, media);
insert.setString(6, contactInfo);
insert.setString(7, autoNotify);
insert.executeUpdate();
} finally {
d.cleanUp();
}
}
use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class NotificationManager method insertNotice.
/**
* This method inserts a row into the notifications table in the database.
* This row indicates that the page has been sent out.
*
* @param queueID a {@link java.lang.String} object.
* @param notification TODO
* @param notifyId a int.
* @param params a {@link java.util.Map} object.
* @throws java.sql.SQLException if any.
*/
public void insertNotice(final int notifyId, final Map<String, String> params, final String queueID, final Notification notification) throws SQLException {
Connection connection = null;
final DBUtils d = new DBUtils(getClass());
try {
connection = getConnection();
d.watch(connection);
final PreparedStatement statement = connection.prepareStatement("INSERT INTO notifications (" + "textmsg, numericmsg, notifyid, pagetime, nodeid, interfaceid, serviceid, eventid, " + "eventuei, subject, queueID, notifConfigName) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
d.watch(statement);
// notifications textMsg field
statement.setString(1, params.get(NotificationManager.PARAM_TEXT_MSG));
// notifications numericMsg field
String numMsg = params.get(NotificationManager.PARAM_NUM_MSG);
if (numMsg != null && numMsg.length() > 256) {
LOG.warn("numericmsg too long, it will be truncated");
numMsg = numMsg.substring(0, 256);
}
statement.setString(2, numMsg);
// notifications notifyID field
statement.setInt(3, notifyId);
// notifications pageTime field
statement.setTimestamp(4, new Timestamp((new Date()).getTime()));
// notifications nodeID field
String node = params.get(NotificationManager.PARAM_NODE);
if (node != null && !node.trim().equals("") && !node.equalsIgnoreCase("null") && !node.equalsIgnoreCase("%nodeid%")) {
statement.setInt(5, Integer.parseInt(node));
} else {
statement.setNull(5, Types.INTEGER);
}
// notifications interfaceID field
String ipaddr = params.get(NotificationManager.PARAM_INTERFACE);
if (ipaddr != null && !ipaddr.trim().equals("") && !ipaddr.equalsIgnoreCase("null") && !ipaddr.equalsIgnoreCase("%interface%")) {
statement.setString(6, ipaddr);
} else {
statement.setString(6, null);
}
// notifications serviceID field
String service = params.get(NotificationManager.PARAM_SERVICE);
if (service != null && !service.trim().equals("") && !service.equalsIgnoreCase("null") && !service.equalsIgnoreCase("%service%")) {
statement.setInt(7, getServiceId(service));
} else {
statement.setNull(7, Types.INTEGER);
}
// eventID field
final String eventID = params.get("eventID");
if (eventID != null && !eventID.trim().equals("") && !eventID.trim().equals("0") && !eventID.equalsIgnoreCase("null") && !eventID.equalsIgnoreCase("%eventid%")) {
statement.setInt(8, Integer.parseInt(eventID));
} else {
statement.setNull(8, Types.INTEGER);
}
statement.setString(9, params.get("eventUEI"));
// notifications subject field
statement.setString(10, params.get(NotificationManager.PARAM_SUBJECT));
// the queue this will be sent on
statement.setString(11, queueID);
statement.setString(12, notification.getName());
statement.executeUpdate();
} finally {
d.cleanUp();
}
}
use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class NotificationManager method acknowledgeNoticeBasedOnAlarms.
/**
* <p>acknowledgeNoticeBasedOnAlarms</p>
*
* @param event a {@link org.opennms.netmgt.xml.event.Event} object.
* @return a {@link java.utilCollection} object.
* @throws java.sql.SQLException if any.
* @throws java.io.IOException if any.
*/
public Collection<Integer> acknowledgeNoticeBasedOnAlarms(final Event event) throws SQLException, IOException {
Set<Integer> notifIDs = new TreeSet<Integer>();
if (event.getAlarmData() == null || event.getAlarmData().getAlarmType() != 2) {
return notifIDs;
}
final DBUtils dbUtils = new DBUtils(getClass());
try {
Connection connection = getConnection();
dbUtils.watch(connection);
PreparedStatement statement = connection.prepareStatement("SELECT e.eventId FROM events e, alarms a WHERE e.alarmid = a.alarmid AND a.reductionkey= ?");
dbUtils.watch(statement);
statement.setString(1, event.getAlarmData().getClearKey());
ResultSet results = statement.executeQuery();
dbUtils.watch(results);
while (results.next()) {
int eventID = results.getInt(1);
notifIDs.addAll(doAcknowledgeNotificationsFromEvent(connection, dbUtils, eventID));
}
} finally {
dbUtils.cleanUp();
}
return notifIDs;
}
use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class NotificationManager method getServiceNoticeStatus.
/**
* <p>getServiceNoticeStatus</p>
*
* @param nodeID a {@link java.lang.String} object.
* @param ipaddr a {@link java.lang.String} object.
* @param service a {@link java.lang.String} object.
* @return a {@link java.lang.String} object.
* @throws java.sql.SQLException if any.
*/
public String getServiceNoticeStatus(final String nodeID, final String ipaddr, final String service) throws SQLException {
String notify = "Y";
final String query = "SELECT notify FROM ifservices, ipInterface, node, service WHERE ifServices.ipInterfaceId = ipInterface.id AND ipInterface.nodeId = node.nodeId AND node.nodeid=? AND ipInterface.ipaddr=? AND ifservices.serviceid=service.serviceid AND service.servicename=?";
java.sql.Connection connection = null;
final DBUtils d = new DBUtils(getClass());
try {
connection = getConnection();
d.watch(connection);
final PreparedStatement statement = connection.prepareStatement(query);
d.watch(statement);
statement.setInt(1, Integer.parseInt(nodeID));
statement.setString(2, ipaddr);
statement.setString(3, service);
final ResultSet rs = statement.executeQuery();
d.watch(rs);
if (rs.next() && rs.getString("notify") != null) {
notify = rs.getString("notify");
if (notify == null)
notify = "Y";
}
return notify;
} finally {
d.cleanUp();
}
}
use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class NotificationManager method getServiceId.
/**
* This method queries the database in search of a service id for a given service name
*
* @param service
* the name of the service
* @return the serviceID of the service
*/
private int getServiceId(final String service) throws SQLException {
int serviceID = 0;
Connection connection = null;
final DBUtils d = new DBUtils(getClass());
try {
connection = getConnection();
d.watch(connection);
final PreparedStatement statement = connection.prepareStatement("SELECT serviceID from service where serviceName = ?");
d.watch(statement);
statement.setString(1, service);
final ResultSet results = statement.executeQuery();
d.watch(results);
results.next();
serviceID = results.getInt(1);
return serviceID;
} finally {
d.cleanUp();
}
}
Aggregations