Search in sources :

Example 16 with Ticket

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);
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket) Date(java.util.Date)

Example 17 with Ticket

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");
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Ticket(org.opennms.api.integration.ticketing.Ticket) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Resource(org.springframework.core.io.Resource) EasyMockUtils(org.opennms.test.mock.EasyMockUtils) AlarmDao(org.opennms.netmgt.dao.api.AlarmDao) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Plugin(org.opennms.api.integration.ticketing.Plugin) Before(org.junit.Before)

Example 18 with Ticket

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);
    }
}
Also used : CimFieldInfo(com.atlassian.jira.rest.client.api.domain.CimFieldInfo) LoadingCache(com.google.common.cache.LoadingCache) Issue(com.atlassian.jira.rest.client.api.domain.Issue) LoggerFactory(org.slf4j.LoggerFactory) Plugin(org.opennms.api.integration.ticketing.Plugin) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Ticket(org.opennms.api.integration.ticketing.Ticket) Strings(com.google.common.base.Strings) PluginException(org.opennms.api.integration.ticketing.PluginException) Lists(com.google.common.collect.Lists) FieldMapper(org.opennms.netmgt.ticketer.jira.fieldmapper.FieldMapper) Map(java.util.Map) Transition(com.atlassian.jira.rest.client.api.domain.Transition) FieldSchema(com.atlassian.jira.rest.client.api.domain.FieldSchema) Properties(java.util.Properties) Logger(org.slf4j.Logger) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) JiraRestClient(com.atlassian.jira.rest.client.api.JiraRestClient) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder) TransitionInput(com.atlassian.jira.rest.client.api.domain.input.TransitionInput) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) File(java.io.File) Sets(com.google.common.collect.Sets) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) TimeoutRefreshPolicy(org.opennms.netmgt.ticketer.jira.cache.TimeoutRefreshPolicy) Entry(java.util.Map.Entry) Comment(com.atlassian.jira.rest.client.api.domain.Comment) Cache(org.opennms.netmgt.ticketer.jira.cache.Cache) CimProject(com.atlassian.jira.rest.client.api.domain.CimProject) CacheBuilder(com.google.common.cache.CacheBuilder) InputStream(java.io.InputStream) CimFieldInfo(com.atlassian.jira.rest.client.api.domain.CimFieldInfo) PluginException(org.opennms.api.integration.ticketing.PluginException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 19 with Ticket

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;
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket)

Example 20 with 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);
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) PluginException(org.opennms.api.integration.ticketing.PluginException)

Aggregations

Ticket (org.opennms.api.integration.ticketing.Ticket)46 PluginException (org.opennms.api.integration.ticketing.PluginException)15 Date (java.util.Date)9 Test (org.junit.Test)7 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)4 MXStringType (com.ibm.maximo.MXStringType)3 Properties (java.util.Properties)3 Plugin (org.opennms.api.integration.ticketing.Plugin)3 DataRetrievalFailureException (org.springframework.dao.DataRetrievalFailureException)3 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)2 Issue (com.atlassian.jira.rest.client.api.domain.Issue)2 QuerySHSIMPINCResponseType (com.ibm.maximo.QuerySHSIMPINCResponseType)2 QuerySHSIMPINCType (com.ibm.maximo.QuerySHSIMPINCType)2 SHSIMPINCINCIDENTType (com.ibm.maximo.SHSIMPINCINCIDENTType)2 File (java.io.File)2 IOException (java.io.IOException)2 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Ignore (org.junit.Ignore)2