agave-monitors/monitors-core/src/main/java/org/iplantc/service/monitor/events/MonitorEventProcessor.java
/**
	 * Generates notification events for each {@link MonitorCheck} run on schedule 
	 * {@link Monitor}.
	 * 
	 * @param monitor the {@link Monitor} on which the even is triggered
	 * @param lastCheck the {@link MonitorCheck} that just ran
	 * @param currentCheck the {@link MonitorCheck} that is currently being run
	 * @param createdBy the user who caused this event
	 * @return the {@link DomainEntityEvent} with the association to the {@link Monitor}
	 */
Generates notification events for each  MonitorCheck run on schedule
Monitor.


Generates notification events for each MonitorCheck run on schedule Monitor .
public DomainEntityEvent processCheckEvent(Monitor monitor, MonitorCheck lastCheck, MonitorCheck currentCheck, String createdBy) {
		DomainEntityEvent event = null;
		try {
			if (monitor == null) {
				throw new EntityEventProcessingException("Valid monitor must be provided to process event.");
			}
			if (currentCheck == null) {
				throw new EntityEventProcessingException("Valid monitor check must be provided to process event.");
			}
			if (StringUtils.isEmpty(createdBy)) {
				throw new EntityEventProcessingException("Valid monitor check creator must be provided to process event.");
			}
			MonitorEventType eventType = MonitorEventType.valueOfCheckStatus(currentCheck.getResult());
			String sJson = null;
			try {
				ObjectNode json = mapper.createObjectNode();
			    json.set("monitor", mapper.readTree(monitor.toJSON()));
			    json.set("monitorcheck", mapper.readTree(currentCheck.toJSON()));
			    json.set("system", mapper.readTree(monitor.getSystem().toJSON()));
			    sJson = json.toString();
			} catch (Throwable e) {
			    log.error(String.format("Failed to serialize monitor "
			            + "%s to json for %s event notification", 
			            monitor.getUuid(), eventType.name()), e);
			}
			processNotification(monitor.getUuid(), eventType.name(), createdBy, sJson);
			if (lastCheck != null && !currentCheck.getResult().equals(lastCheck.getResult())) {
				processNotification(monitor.getUuid(), MonitorEventType.RESULT_CHANGE.name(), createdBy, sJson);
				processNotification(monitor.getSystem().getUuid(), "MONITOR_" + eventType.name(), createdBy, sJson);
			}
			RemoteSystem system = monitor.getSystem();
			if (currentCheck.getResult().getSystemStatus() != system.getStatus()) {
				processNotification(monitor.getUuid(), MonitorEventType.STATUS_CHANGE.name(), createdBy, sJson);
				processNotification(monitor.getSystem().getUuid(), "MONITOR_" + MonitorEventType.STATUS_CHANGE.name(), createdBy, sJson);
				if (monitor.isUpdateSystemStatus() && userCanUpdateSystemStatus(system, monitor.getOwner())) {
					SystemManager systemManager = new SystemManager();
					systemManager.updateSystemStatus(monitor.getSystem(), currentCheck.getResult().getSystemStatus(), monitor.getOwner());
				}
			}
			event = new DomainEntityEvent(monitor.getUuid(), eventType, eventType.getDescription() + " by " + createdBy, createdBy);
		}
		catch (EntityEventProcessingException e) {
			log.error(e.getMessage());
		}
		return event;
	}
public DomainEntityEvent processCheckEvent ( Monitor monitor , MonitorCheck lastCheck , MonitorCheck currentCheck , String createdBy ) { DomainEntityEvent event = null ; try { if ( monitor == null ) { throw new EntityEventProcessingException ( "Valid monitor must be provided to process event." ) ; } if ( currentCheck == null ) { throw new EntityEventProcessingException ( "Valid monitor check must be provided to process event." ) ; } if ( StringUtils . isEmpty ( createdBy ) ) { throw new EntityEventProcessingException ( "Valid monitor check creator must be provided to process event." ) ; } MonitorEventType eventType = MonitorEventType . valueOfCheckStatus ( currentCheck . getResult ( ) ) ; String sJson = null ; try { ObjectNode json = mapper . createObjectNode ( ) ; json . set ( "monitor" , mapper . readTree ( monitor . toJSON ( ) ) ) ; json . set ( "monitorcheck" , mapper . readTree ( currentCheck . toJSON ( ) ) ) ; json . set ( "system" , mapper . readTree ( monitor . getSystem ( ) . toJSON ( ) ) ) ; sJson = json . toString ( ) ; } catch ( Throwable e ) { log . error ( String . format ( "Failed to serialize monitor " + "%s to json for %s event notification" , monitor . getUuid ( ) , eventType . name ( ) ) , e ) ; } processNotification ( monitor . getUuid ( ) , eventType . name ( ) , createdBy , sJson ) ; if ( lastCheck != null && ! currentCheck . getResult ( ) . equals ( lastCheck . getResult ( ) ) ) { processNotification ( monitor . getUuid ( ) , MonitorEventType . RESULT_CHANGE . name ( ) , createdBy , sJson ) ; processNotification ( monitor . getSystem ( ) . getUuid ( ) , "MONITOR_" + eventType . name ( ) , createdBy , sJson ) ; } RemoteSystem system = monitor . getSystem ( ) ; if ( currentCheck . getResult ( ) . getSystemStatus ( ) != system . getStatus ( ) ) { processNotification ( monitor . getUuid ( ) , MonitorEventType . STATUS_CHANGE . name ( ) , createdBy , sJson ) ; processNotification ( monitor . getSystem ( ) . getUuid ( ) , "MONITOR_" + MonitorEventType . STATUS_CHANGE . name ( ) , createdBy , sJson ) ; if ( monitor . isUpdateSystemStatus ( ) && userCanUpdateSystemStatus ( system , monitor . getOwner ( ) ) ) { SystemManager systemManager = new SystemManager ( ) ; systemManager . updateSystemStatus ( monitor . getSystem ( ) , currentCheck . getResult ( ) . getSystemStatus ( ) , monitor . getOwner ( ) ) ; } } event = new DomainEntityEvent ( monitor . getUuid ( ) , eventType , eventType . getDescription ( ) + " by " + createdBy , createdBy ) ; } catch ( EntityEventProcessingException e ) { log . error ( e . getMessage ( ) ) ; } return event ; }
Generates notification events for each {@link MonitorCheck} run on schedule
 {@link Monitor}.
Generates notification events for each { @link MonitorCheck } run on schedule { @link Monitor } .
// fire event on monitor // if the result of this check was different from the last, sent a MonitorEventType.RESULT_CHANGE event // multiple checks can run for a single monitor. if this check tips the scale and  // changes the overall monitor status, send a result // monitor event // delegated system event // if the monitor is configured to update a system on monitor status change and the user has permission // to do so on the target system, then do so here. The SystemManager will handle its own event // propagation of system update events.