Skip to content

Commit

Permalink
addd bean creation for rest endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Deer-WarLord committed May 27, 2024
1 parent f2209dc commit b489276
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
87 changes: 87 additions & 0 deletions core/src/main/java/org/zenoss/zep/rest/IncManResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package org.zenoss.zep.rest;

import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.jboss.resteasy.annotations.GZIP;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.zenoss.protobufs.ProtobufConstants;
import org.zenoss.protobufs.zep.Zep.EventDetail;
import org.zenoss.protobufs.zep.Zep.EventDetailSet;
import org.zenoss.protobufs.zep.Zep.EventTriggerSubscription;
import org.zenoss.zep.ZepException;
import org.zenoss.zep.dao.EventSignalSpool;
import org.zenoss.zep.dao.EventSignalSpoolDao;
import org.zenoss.zep.dao.EventTriggerSubscriptionDao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Path("1.0/incman")
public class IncManResource {
private static final Logger logger = LoggerFactory.getLogger(IncManResource.class);

public class TriggerSubscriptionNotFound extends ZepException {}

private EventTriggerSubscriptionDao eventTriggerSubscriptionDao;
private EventSignalSpoolDao eventSignalSpoolDao;

public void setEventTriggerSubscriptionDao(EventTriggerSubscriptionDao eventTriggerSubscriptionDao) {
this.eventTriggerSubscriptionDao = eventTriggerSubscriptionDao;
}

public void setEventSignalSpoolDao(EventSignalSpoolDao eventSignalSpoolDao) {
this.eventSignalSpoolDao = eventSignalSpoolDao;
}

private String getTriggerSubscriptionUuid(String triggerUuid, String notificationUuid) throws ZepException {
List<EventTriggerSubscription> triggerSubscriptions =
this.eventTriggerSubscriptionDao.findAll();

logger.debug("Searching for " + triggerUuid + "/" + notificationUuid);
for (EventTriggerSubscription triggerSubscription :
triggerSubscriptions) {
logger.debug("\tComparing to " + triggerSubscription.getTriggerUuid() + "/" + triggerSubscription.getSubscriberUuid());

if ((triggerSubscription.getTriggerUuid().equals(triggerUuid)) &&
(triggerSubscription.getSubscriberUuid().equals(notificationUuid))) {
logger.debug("Found!");
return triggerSubscription.getUuid();
}
}
logger.debug("Not found!");
throw new TriggerSubscriptionNotFound();
}

@POST
@Path("trigger_spool")
@Produces({ MediaType.APPLICATION_JSON, ProtobufConstants.CONTENT_TYPE_PROTOBUF })
@GZIP
public Response insertTriggerSpool(EventDetailSet update) throws ZepException {
EventSignalSpool spool;
Map<String, String> updatesByKey = new HashMap<String, String>();

for (EventDetail detail : update.getDetailsList()) {
updatesByKey.put(detail.getName(), detail.getValue(0));
}

String triggerSubscriptionUuid = this.getTriggerSubscriptionUuid(
updatesByKey.get("trigger_uuid"), updatesByKey.get("notification_uuid"));

spool = new EventSignalSpool();
spool.setSubscriptionUuid(triggerSubscriptionUuid);
spool.setEventSummaryUuid(updatesByKey.get("event_summary_uuid"));
spool.setSentSignal(true);
spool.setCreated(System.currentTimeMillis());
spool.setFlushTime(Long.MAX_VALUE);

this.eventSignalSpoolDao.create(spool);

return Response.noContent().build();
}

}
5 changes: 4 additions & 1 deletion core/src/main/resources/zep-config-rest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
</bean>
<bean id="diagnosticsResource" class="org.zenoss.zep.rest.DiagnosticsResource">
</bean>

<bean id="incManResource" class="org.zenoss.zep.rest.IncManResource">
<property name="eventTriggerSubscriptionDao" ref="eventTriggerSubscriptionDao" />
<property name="eventSignalSpoolDao" ref="eventSignalSpoolDao" />
</bean>

</beans>

0 comments on commit b489276

Please sign in to comment.