Skip to content

Commit

Permalink
0002547: Notification of system event problems
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Jun 27, 2016
1 parent c4cc1a0 commit 30bae72
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 8 deletions.
Expand Up @@ -338,6 +338,8 @@ private ParameterConstants() {
public static final String SMTP_USE_AUTH = "smtp.auth";

public final static String CHANNEL_THREADING = "channel.threading.enabled";

public final static String MONITOR_EVENTS_CAPTURE_ENABLED = "monitor.events.capture.enabled";

public static Map<String, ParameterMetaData> getParameterMetaData() {
return parameterMetaData;
Expand Down
Expand Up @@ -132,6 +132,7 @@ protected static List<String> populateConfigTables(String tablePrefix) {
configTables.add(getTableName(tablePrefix, TableConstants.SYM_NODE_IDENTITY));
configTables.add(getTableName(tablePrefix, TableConstants.SYM_EXTENSION));
configTables.add(getTableName(tablePrefix, TableConstants.SYM_MONITOR));
configTables.add(getTableName(tablePrefix, TableConstants.SYM_MONITOR_EVENT));
configTables.add(getTableName(tablePrefix, TableConstants.SYM_NOTIFICATION));
return configTables;
}
Expand Down
Expand Up @@ -33,7 +33,6 @@
import org.jumpmind.symmetric.model.MonitorEvent;
import org.jumpmind.symmetric.model.Node;
import org.jumpmind.symmetric.model.Notification;
import org.jumpmind.symmetric.service.INodeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -68,8 +67,7 @@ public void notify(Notification notification, List<MonitorEvent> monitorEvents)
subject = "Monitor events for " + typesString + " from " + nodeIds.size() + " nodes";
}

INodeService nodeService = engine.getNodeService();
Map<String, Node> nodes = nodeService.findAllNodesAsMap();
Map<String, Node> nodes = engine.getNodeService().findAllNodesAsMap();
StringBuilder text = new StringBuilder();
for (MonitorEvent event : monitorEvents) {
Node node = nodes.get(event.getNodeId());
Expand Down
Expand Up @@ -21,20 +21,30 @@
package org.jumpmind.symmetric.notification;

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

import org.jumpmind.symmetric.ISymmetricEngine;
import org.jumpmind.symmetric.ext.ISymmetricEngineAware;
import org.jumpmind.symmetric.model.Monitor;
import org.jumpmind.symmetric.model.MonitorEvent;
import org.jumpmind.symmetric.model.Node;
import org.jumpmind.symmetric.model.Notification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NotificationTypeLog implements INotificationType {
public class NotificationTypeLog implements INotificationType, ISymmetricEngineAware {

private final Logger log = LoggerFactory.getLogger(getClass());

protected ISymmetricEngine engine;

public void notify(Notification notification, List<MonitorEvent> monitorEvents) {
Map<String, Node> nodes = engine.getNodeService().findAllNodesAsMap();

for (MonitorEvent monitorEvent : monitorEvents) {
String message = "Monitor " + monitorEvent.getType() + " on " + monitorEvent.getNodeId() + " recorded "
Node node = nodes.get(monitorEvent.getNodeId());
String nodeString = node != null ? node.toString() : monitorEvent.getNodeId();
String message = "Monitor " + monitorEvent.getType() + " on " + nodeString + " recorded "
+ monitorEvent.getValue();
if (monitorEvent.getSeverityLevel() >= Monitor.SEVERE) {
log.error(message);
Expand All @@ -51,4 +61,9 @@ public String getName() {
return "log";
}

@Override
public void setSymmetricEngine(ISymmetricEngine engine) {
this.engine = engine;
}

}
Expand Up @@ -120,7 +120,8 @@ public Set<String> routeToNodes(SimpleRouterContext routingContext, DataMetaData

if (tableMatches(dataMetaData, TableConstants.SYM_NODE)
|| tableMatches(dataMetaData, TableConstants.SYM_NODE_SECURITY)
|| tableMatches(dataMetaData, TableConstants.SYM_NODE_HOST)) {
|| tableMatches(dataMetaData, TableConstants.SYM_NODE_HOST)
|| tableMatches(dataMetaData, TableConstants.SYM_MONITOR_EVENT)) {
/*
* If this is sym_node or sym_node_security determine which
* nodes it goes to.
Expand Down
Expand Up @@ -488,8 +488,8 @@ protected Trigger buildTriggerForSymmetricTable(String tableName) {
trigger.setSyncOnIncomingBatch(syncOnIncoming);
trigger.setSourceTableName(tableName);
trigger.setUseCaptureOldData(false);
if (TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_HOST)
.equals(tableName)) {
if (TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_HOST).equals(tableName)
|| TableConstants.getTableName(tablePrefix, TableConstants.SYM_MONITOR_EVENT).equals(tableName)) {
trigger.setChannelId(Constants.CHANNEL_HEARTBEAT);
} else if (TableConstants.getTableName(tablePrefix, TableConstants.SYM_FILE_SNAPSHOT)
.equals(tableName)) {
Expand All @@ -506,6 +506,13 @@ protected Trigger buildTriggerForSymmetricTable(String tableName) {
trigger.setChannelId(Constants.CHANNEL_CONFIG);
}

if (TableConstants.getTableName(tablePrefix, TableConstants.SYM_MONITOR_EVENT).equals(tableName)
&& !parameterService.is(ParameterConstants.MONITOR_EVENTS_CAPTURE_ENABLED)) {
trigger.setSyncOnInsert(false);
trigger.setSyncOnUpdate(false);
trigger.setSyncOnDelete(false);
}

if (!TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_HOST)
.equals(tableName) &&
!TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE)
Expand Down
Expand Up @@ -1754,3 +1754,10 @@ node.offline.error.dir=
# DatabaseOverridable: true
# Tags: other
node.offline.archive.dir=

# Enable capturing of monitor events and syncing to other nodes.
#
# DatabaseOverridable: true
# Tags: other
# Type: boolean
monitor.events.capture.enabled=true

0 comments on commit 30bae72

Please sign in to comment.