use of org.opennms.api.integration.ticketing.Ticket in project opennms by OpenNMS.
the class QuickBaseTicketerPluginTest method testUpdate.
public void testUpdate() throws Exception {
String summary = "A Ticket at " + new Date();
Ticket ticket = new Ticket();
ticket.setState(Ticket.State.OPEN);
ticket.setSummary(summary);
ticket.setDetails("Ticket details for ticket: " + new Date());
m_ticketer.saveOrUpdate(ticket);
assertNotNull(ticket.getId());
Ticket newTicket = m_ticketer.get(ticket.getId());
assertNotNull(newTicket);
assertTicketEquals(ticket, newTicket);
newTicket.setState(Ticket.State.CANCELLED);
newTicket.setDetails("These details have changed");
System.err.println("TicketId = " + newTicket.getId());
m_ticketer.saveOrUpdate(newTicket);
Thread.sleep(500);
Ticket newerTicket = m_ticketer.get(newTicket.getId());
assertTicketEquals(newTicket, newerTicket);
}
use of org.opennms.api.integration.ticketing.Ticket in project opennms by OpenNMS.
the class DroolsTicketerServiceLayerTest method setUp.
@Before
public void setUp() throws Exception {
m_eventIpcManager = new MockEventIpcManager();
EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
MockLogAppender.setupLogging();
ResourceLoader loader = new DefaultResourceLoader();
Resource resource = loader.getResource("classpath:/drools-ticketer-rules.drl");
m_easyMockUtils = new EasyMockUtils();
m_configDao = m_easyMockUtils.createMock(DroolsTicketerConfigDao.class);
EasyMock.expect(m_configDao.getRulesFile()).andReturn(resource.getFile()).times(1);
EasyMock.replay(m_configDao);
m_alarmDao = m_easyMockUtils.createMock(AlarmDao.class);
m_ticketerPlugin = m_easyMockUtils.createMock(Plugin.class);
m_droolsTicketerServiceLayer = new DroolsTicketerServiceLayer(m_configDao);
m_droolsTicketerServiceLayer.setAlarmDao(m_alarmDao);
m_droolsTicketerServiceLayer.setTicketerPlugin(m_ticketerPlugin);
EasyMock.reset(m_configDao);
m_alarm = new OnmsAlarm();
m_alarm.setId(1);
m_alarm.setLogMsg("Test Logmsg");
m_alarm.setDescription("Test Description");
m_alarm.setUei("uei.opennms.org/nodes/nodeDown");
m_ticket = new Ticket();
m_ticket.setId("4");
}
use of org.opennms.api.integration.ticketing.Ticket in project opennms by OpenNMS.
the class JiraTicketerPlugin method populateFields.
/**
* Convenient method to populate additional fields in the {@link IssueInputBuilder}.
* The fields are read from {@link Ticket#getAttributes()}.
*
* @param ticket The ticket to read the attributes from.
* @param builder The builder to set additional fields.
*/
private void populateFields(Ticket ticket, IssueInputBuilder builder) {
// Only convert additional attributes to field values, if available
if (!ticket.hasAttributes()) {
return;
}
// List of fields already populated
final List<String> populatedFields = Lists.newArrayList();
final Collection<CimFieldInfo> fields = getFields();
for (Entry<String, String> eachEntry : ticket.getAttributes().entrySet()) {
if (!Strings.isNullOrEmpty(eachEntry.getValue())) {
// Find a field representation in jira
for (CimFieldInfo eachField : fields) {
if (eachEntry.getKey().equals(eachField.getId())) {
try {
final String attributeValue = eachEntry.getValue();
final Object mappedFieldValue = fieldMapFunctionCache.get(eachField.getSchema()).mapToFieldValue(eachField.getId(), eachField.getSchema(), attributeValue);
builder.setFieldValue(eachField.getId(), mappedFieldValue);
populatedFields.add(eachField.getId());
// we found a representation, now continue with next attribute
break;
} catch (Exception ex) {
LOG.error("Could not convert attribute (id={}, value={}) to jira field value. Ignoring attribute.", eachField.getId(), eachEntry.getValue(), ex);
}
}
}
}
}
// Inform about not found attributes
if (populatedFields.size() != ticket.getAttributes().size()) {
for (String eachKey : ticket.getAttributes().keySet()) {
if (!populatedFields.contains(eachKey)) {
LOG.warn("Ticket attribute '{}' is defined, but was not mapped to a (custom) field in JIRA. Attribute is skipped.", eachKey);
}
}
}
// Inform if required attribute has not been set
final List<CimFieldInfo> requiredFieldsNotSet = fields.stream().filter(f -> f.isRequired()).filter(f -> !populatedFields.contains(f)).collect(Collectors.toList());
if (!requiredFieldsNotSet.isEmpty()) {
final String missingFields = requiredFieldsNotSet.stream().map(f -> String.format("id: %s, name: %s", f.getId(), f.getName())).collect(Collectors.joining(", "));
LOG.warn("Not all required (custom) jira fields have been set. The following are unset: %s", missingFields);
}
}
use of org.opennms.api.integration.ticketing.Ticket in project opennms by OpenNMS.
the class DefaultTicketerServiceLayer method createTicketFromAlarm.
/**
* Called from API implemented method after successful retrieval of Alarm.
*
* @param alarm OpenNMS Model class alarm
* @param attributes
* @return OpenNMS Ticket with contents of alarm.
* TODO: Add alarm attributes to Ticket.
* TODO: Add alarmid to Ticket class for ability to reference back to Alarm (waffling on this
* since ticket isn't a persisted object and other reasons)
*/
protected Ticket createTicketFromAlarm(OnmsAlarm alarm, Map<String, String> attributes) {
Ticket ticket = new Ticket();
ticket.setSummary(alarm.getLogMsg());
ticket.setDetails(alarm.getDescription());
ticket.setId(alarm.getTTicketId());
ticket.setAlarmId(alarm.getId());
ticket.setNodeId(alarm.getNodeId());
ticket.setIpAddress(alarm.getIpAddr());
ticket.setAttributes(attributes);
if (attributes.containsKey("user"))
ticket.setUser(attributes.get("user"));
return ticket;
}
use of org.opennms.api.integration.ticketing.Ticket in project opennms by OpenNMS.
the class DefaultTicketerServiceLayer method createTicketForAlarm.
/*
* (non-Javadoc)
* @see org.opennms.netmgt.ticketd.TicketerServiceLayer#createTicketForAlarm(int)
*/
/** {@inheritDoc} */
@Override
public void createTicketForAlarm(int alarmId, Map<String, String> attributes) {
OnmsAlarm alarm = m_alarmDao.get(alarmId);
if (alarm == null) {
LOG.error("No alarm with id {} was found. No ticket will be created.", alarmId);
return;
}
if (SKIP_CREATE_WHEN_CLEARED) {
final OnmsSeverity currentSeverity = alarm.getSeverity();
if (currentSeverity != null && currentSeverity.equals(OnmsSeverity.CLEARED)) {
LOG.info("Alarm with id {} is currently cleared. No ticket will be created.", alarmId);
return;
}
}
Ticket ticket = createTicketFromAlarm(alarm, attributes);
try {
m_ticketerPlugin.saveOrUpdate(ticket);
alarm.setTTicketId(ticket.getId());
alarm.setTTicketState(TroubleTicketState.OPEN);
} catch (PluginException e) {
alarm.setTTicketState(TroubleTicketState.CREATE_FAILED);
LOG.error("Unable to create ticket for alarm: {}", e.getMessage(), e);
m_eventIpcManager.sendNow(createEvent(e.getMessage()));
}
m_alarmDao.saveOrUpdate(alarm);
}
Aggregations