use of org.opennms.netmgt.config.notificationCommands.Command in project opennms by OpenNMS.
the class BroadcastEventProcessor method makeEmailTask.
/**
*
*/
NotificationTask makeEmailTask(long sendTime, Map<String, String> parameters, int noticeId, String address, String[] commandList, List<NotificationTask> siblings, String autoNotify) throws IOException {
NotificationTask task = null;
task = new NotificationTask(getNotificationManager(), getUserManager(), sendTime, parameters, siblings, autoNotify);
User user = new User();
user.setUserId(address);
Contact contact = new Contact();
contact.setType("email");
LOG.debug("email address = {}, using contact type {}", address, contact.getType());
contact.setInfo(address);
user.addContact(contact);
Command[] commands = new Command[commandList.length];
for (int i = 0; i < commandList.length; i++) {
commands[i] = getNotificationCommandManager().getCommand(commandList[i]);
}
task.setUser(user);
task.setCommands(commands);
task.setNoticeId(noticeId);
task.setAutoNotify(autoNotify);
return task;
}
use of org.opennms.netmgt.config.notificationCommands.Command in project opennms by OpenNMS.
the class NotificationCommandManager method parseXML.
/**
* Populate the internal list of notification commands from an XML file.
*
* @param reader contains the XML file to be parsed
* @throws IOException
*/
protected void parseXML(InputStream stream) throws IOException {
final NotificationCommands config;
try (final Reader reader = new InputStreamReader(stream)) {
config = JaxbUtils.unmarshal(NotificationCommands.class, reader);
}
Map<String, Command> commands = new HashMap<String, Command>();
for (Command curCommand : getCommandsFromConfig(config)) {
if (curCommand != null && curCommand.getName() != null) {
commands.put(curCommand.getName(), curCommand);
} else {
LOG.warn("invalid notification command: {}", curCommand);
}
}
m_commands = commands;
}
use of org.opennms.netmgt.config.notificationCommands.Command in project opennms by OpenNMS.
the class NotificationTask method run.
/**
* <p>run</p>
*/
@Override
public void run() {
boolean outstanding = false;
try {
outstanding = getNotificationManager().noticeOutstanding(m_notifyId);
} catch (Throwable e) {
LOG.error("Unable to get response status on notice #{}", m_notifyId, e);
}
// check to see if someone has responded, if so remove all the brothers
if (outstanding) {
try {
if (getUserManager().isUserOnDuty(m_user.getUserId(), Calendar.getInstance())) {
// send the notice
ExecutorStrategy strategy = null;
String cntct = "";
for (Command command : m_commands) {
try {
cntct = getContactInfo(command.getName());
try {
getNotificationManager().updateNoticeWithUserInfo(m_user.getUserId(), m_notifyId, command.getName(), cntct, m_autoNotify);
} catch (Throwable e) {
LOG.error("Could not insert notice info into database, aborting send notice", e);
continue;
}
Boolean binaryCommand = command.getBinary();
if (binaryCommand) {
strategy = new CommandExecutor();
} else {
strategy = new ClassExecutor();
}
LOG.debug("Class created is: {}", command.getClass());
getNotificationManager().incrementAttempted(strategy instanceof CommandExecutor);
int returnCode = strategy.execute(command.getExecute(), getArgumentList(command));
LOG.debug("command {} return code = {}", command.getName(), returnCode);
if (returnCode == 0) {
getNotificationManager().incrementSucceeded(strategy instanceof CommandExecutor);
} else {
getNotificationManager().incrementFailed(strategy instanceof CommandExecutor);
}
} catch (Throwable e) {
LOG.warn("Notification command failed: {}", command.getName(), e);
if (strategy == null) {
getNotificationManager().incrementUnknownInterrupted();
} else {
getNotificationManager().incrementInterrupted(strategy instanceof CommandExecutor);
}
}
}
} else {
LOG.debug("User {} is not on duty, skipping", m_user.getUserId());
}
} catch (IOException e) {
LOG.warn("Could not get user duty schedule information: ", e);
}
} else {
// remove all the related notices that have yet to be sent
//for (int i = 0; i < m_siblings.size(); i++) {
// NotificationTask task = (NotificationTask) m_siblings.get(i);
// FIXME: Reported on discuss list and not found to ever
// be initialized anywhere.
// m_notifTree.remove(task);
//}
}
}
use of org.opennms.netmgt.config.notificationCommands.Command in project opennms by OpenNMS.
the class NotificationTask method toString.
/**
* <p>toString</p>
*
* @return a {@link java.lang.String} object.
*/
@Override
public String toString() {
StringBuffer buffer = new StringBuffer("Send ");
if (m_commands == null) {
buffer.append("Null Commands");
} else {
for (Command command : m_commands) {
buffer.append((command == null ? "null" : command.getName()));
buffer.append("/");
buffer.append("[#" + m_notifyId + "]");
}
}
buffer.append(" to " + m_user.getUserId() + " at " + new Date(m_sendTime));
return buffer.toString();
}
use of org.opennms.netmgt.config.notificationCommands.Command in project opennms by OpenNMS.
the class BroadcastEventProcessor method makeUserTask.
/**
*
*/
NotificationTask makeUserTask(long sendTime, Map<String, String> parameters, int noticeId, String targetName, String[] commandList, List<NotificationTask> siblings, String autoNotify) throws IOException {
NotificationTask task = null;
task = new NotificationTask(getNotificationManager(), getUserManager(), sendTime, parameters, siblings, autoNotify);
User user = getUserManager().getUser(targetName);
if (user == null) {
LOG.error("user {} is not a valid user, not adding this user to escalation thread", targetName);
return null;
}
Command[] commands = new Command[commandList.length];
for (int i = 0; i < commandList.length; i++) {
commands[i] = getNotificationCommandManager().getCommand(commandList[i]);
if (commands[i] != null && commands[i].getContactType().isPresent()) {
if (!userHasContactType(user, commands[i].getContactType().orElse(null))) {
LOG.warn("User {} lacks contact of type {} which is required for notification command {} on notice #{}. Scheduling task anyway.", user.getUserId(), commands[i].getContactType(), commands[i].getName(), noticeId);
}
}
}
task.setUser(user);
task.setCommands(commands);
task.setNoticeId(noticeId);
task.setAutoNotify(autoNotify);
return task;
}
Aggregations