Browse Source

Renaming notifications for edge. Minor refactoring

pull/10021/head
Andrii Landiak 3 years ago
parent
commit
d4d019beda
  1. 4
      application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcService.java
  2. 52
      application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java
  3. 26
      application/src/main/java/org/thingsboard/server/service/notification/rule/trigger/EdgeCommunicationFailureTriggerProcessor.java
  4. 18
      application/src/main/java/org/thingsboard/server/service/notification/rule/trigger/EdgeConnectionTriggerProcessor.java
  5. 12
      application/src/main/java/org/thingsboard/server/service/sync/ie/exporting/impl/NotificationRuleExportService.java
  6. 12
      application/src/main/java/org/thingsboard/server/service/sync/ie/importing/impl/NotificationRuleImportService.java
  7. 4
      common/data/src/main/java/org/thingsboard/server/common/data/notification/NotificationType.java
  8. 7
      common/data/src/main/java/org/thingsboard/server/common/data/notification/info/EdgeCommunicationFailureNotificationInfo.java
  9. 2
      common/data/src/main/java/org/thingsboard/server/common/data/notification/info/EdgeConnectionNotificationInfo.java
  10. 11
      common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/EdgeCommunicationFailureTrigger.java
  11. 7
      common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/EdgeConnectionTrigger.java
  12. 4
      common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/config/EdgeCommunicationFailureNotificationRuleTriggerConfig.java
  13. 5
      common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/config/EdgeConnectionNotificationRuleTriggerConfig.java
  14. 4
      common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/config/NotificationRuleTriggerConfig.java
  15. 4
      common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/config/NotificationRuleTriggerType.java
  16. 3
      common/data/src/main/java/org/thingsboard/server/common/data/util/TemplateUtils.java
  17. 14
      dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationSettingsService.java
  18. 39
      dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotifications.java
  19. 18
      ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.html
  20. 18
      ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.ts
  21. 8
      ui-ngx/src/app/shared/models/edge.models.ts
  22. 24
      ui-ngx/src/app/shared/models/notification.models.ts
  23. 10
      ui-ngx/src/assets/help/en_US/notification/edge_communication_failure.md
  24. 17
      ui-ngx/src/assets/help/en_US/notification/edge_connection.md
  25. 16
      ui-ngx/src/assets/locale/locale.constant-en_US.json

4
application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcService.java

@ -38,7 +38,7 @@ import org.thingsboard.server.common.data.kv.BasicTsKvEntry;
import org.thingsboard.server.common.data.kv.BooleanDataEntry; import org.thingsboard.server.common.data.kv.BooleanDataEntry;
import org.thingsboard.server.common.data.kv.LongDataEntry; import org.thingsboard.server.common.data.kv.LongDataEntry;
import org.thingsboard.server.common.data.msg.TbMsgType; import org.thingsboard.server.common.data.msg.TbMsgType;
import org.thingsboard.server.common.data.notification.rule.trigger.EdgeConnectivityTrigger; import org.thingsboard.server.common.data.notification.rule.trigger.EdgeConnectionTrigger;
import org.thingsboard.server.common.msg.TbMsg; import org.thingsboard.server.common.msg.TbMsg;
import org.thingsboard.server.common.msg.TbMsgDataType; import org.thingsboard.server.common.msg.TbMsgDataType;
import org.thingsboard.server.common.msg.TbMsgMetaData; import org.thingsboard.server.common.msg.TbMsgMetaData;
@ -467,7 +467,7 @@ public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase i
edgeState.put(DefaultDeviceStateService.ACTIVITY_STATE, false); edgeState.put(DefaultDeviceStateService.ACTIVITY_STATE, false);
edgeState.put(DefaultDeviceStateService.LAST_DISCONNECT_TIME, ts); edgeState.put(DefaultDeviceStateService.LAST_DISCONNECT_TIME, ts);
} }
ctx.getNotificationRuleProcessor().process(EdgeConnectivityTrigger.builder() ctx.getNotificationRuleProcessor().process(EdgeConnectionTrigger.builder()
.tenantId(tenantId) .tenantId(tenantId)
.customerId(edge.getCustomerId()) .customerId(edge.getCustomerId())
.edgeId(edgeId) .edgeId(edgeId)

52
application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java

@ -35,7 +35,7 @@ import org.thingsboard.server.common.data.kv.AttributeKvEntry;
import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry; import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry;
import org.thingsboard.server.common.data.kv.LongDataEntry; import org.thingsboard.server.common.data.kv.LongDataEntry;
import org.thingsboard.server.common.data.kv.StringDataEntry; import org.thingsboard.server.common.data.kv.StringDataEntry;
import org.thingsboard.server.common.data.notification.rule.trigger.EdgeFailureTrigger; import org.thingsboard.server.common.data.notification.rule.trigger.EdgeCommunicationFailureTrigger;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.page.SortOrder; import org.thingsboard.server.common.data.page.SortOrder;
@ -466,22 +466,24 @@ public final class EdgeGrpcSession implements Closeable {
if (isConnected() && sessionState.getPendingMsgsMap().values().size() > 0) { if (isConnected() && sessionState.getPendingMsgsMap().values().size() > 0) {
List<DownlinkMsg> copy = new ArrayList<>(sessionState.getPendingMsgsMap().values()); List<DownlinkMsg> copy = new ArrayList<>(sessionState.getPendingMsgsMap().values());
if (attempt > 1) { if (attempt > 1) {
String errorMsg = String.format("Failed to deliver the batch: {%s}", copy); String error = "Failed to deliver the batch";
String failureMsg = String.format("{%s}: {%s}", error, copy);
if (attempt == 2) { if (attempt == 2) {
// Send a failure notification only on the second attempt. // Send a failure notification only on the second attempt.
// This ensures that failure alerts are sent just once to avoid redundant notifications. // This ensures that failure alerts are sent just once to avoid redundant notifications.
ctx.getNotificationRuleProcessor().process(EdgeFailureTrigger.builder().tenantId(tenantId) ctx.getNotificationRuleProcessor().process(EdgeCommunicationFailureTrigger.builder().tenantId(tenantId)
.edgeId(edge.getId()).customerId(edge.getCustomerId()).edgeName(edge.getName()).errorMsg(errorMsg).build()); .edgeId(edge.getId()).customerId(edge.getCustomerId()).edgeName(edge.getName()).failureMsg(failureMsg).error(error).build());
} }
log.warn("[{}][{}] {}, attempt: {}", this.tenantId, this.sessionId, errorMsg, attempt); log.warn("[{}][{}] {}, attempt: {}", this.tenantId, this.sessionId, failureMsg, attempt);
} }
log.trace("[{}][{}][{}] downlink msg(s) are going to be send.", this.tenantId, this.sessionId, copy.size()); log.trace("[{}][{}][{}] downlink msg(s) are going to be send.", this.tenantId, this.sessionId, copy.size());
for (DownlinkMsg downlinkMsg : copy) { for (DownlinkMsg downlinkMsg : copy) {
if (this.clientMaxInboundMessageSize != 0 && downlinkMsg.getSerializedSize() > this.clientMaxInboundMessageSize) { if (this.clientMaxInboundMessageSize != 0 && downlinkMsg.getSerializedSize() > this.clientMaxInboundMessageSize) {
log.error("[{}][{}][{}] Downlink msg size [{}] exceeds client max inbound message size [{}]. Skipping this message. " + String message = String.format("Downlink msg size [{%s}] exceeds client max inbound message size [{%s}]. " +
"Please increase value of CLOUD_RPC_MAX_INBOUND_MESSAGE_SIZE env variable on the edge and restart it." + "Please increase value of CLOUD_RPC_MAX_INBOUND_MESSAGE_SIZE env variable on the edge and restart it.", downlinkMsg.getSerializedSize(), this.clientMaxInboundMessageSize);
"Message {}", this.tenantId, edge.getId(), this.sessionId, downlinkMsg.getSerializedSize(), log.error("[{}][{}][{}] {} Message {}", this.tenantId, edge.getId(), this.sessionId, message, downlinkMsg);
this.clientMaxInboundMessageSize, downlinkMsg); ctx.getNotificationRuleProcessor().process(EdgeCommunicationFailureTrigger.builder().tenantId(tenantId)
.edgeId(edge.getId()).customerId(edge.getCustomerId()).edgeName(edge.getName()).failureMsg(message).error(message).build());
sessionState.getPendingMsgsMap().remove(downlinkMsg.getDownlinkMsgId()); sessionState.getPendingMsgsMap().remove(downlinkMsg.getDownlinkMsgId());
} else { } else {
sendDownlinkMsg(ResponseMsg.newBuilder() sendDownlinkMsg(ResponseMsg.newBuilder()
@ -492,11 +494,12 @@ public final class EdgeGrpcSession implements Closeable {
if (attempt < MAX_DOWNLINK_ATTEMPTS) { if (attempt < MAX_DOWNLINK_ATTEMPTS) {
scheduleDownlinkMsgsPackSend(attempt + 1); scheduleDownlinkMsgsPackSend(attempt + 1);
} else { } else {
String errorMsg = String.format("Failed to deliver messages: %s", copy); String failureMsg = String.format("Failed to deliver messages: %s", copy);
log.warn("[{}][{}] Failed to deliver the batch after {} attempts. Next messages are going to be discarded {}", log.warn("[{}][{}] Failed to deliver the batch after {} attempts. Next messages are going to be discarded {}",
this.tenantId, this.sessionId, MAX_DOWNLINK_ATTEMPTS, copy); this.tenantId, this.sessionId, MAX_DOWNLINK_ATTEMPTS, copy);
ctx.getNotificationRuleProcessor().process(EdgeFailureTrigger.builder().tenantId(tenantId).edgeId(edge.getId()) ctx.getNotificationRuleProcessor().process(EdgeCommunicationFailureTrigger.builder().tenantId(tenantId).edgeId(edge.getId())
.customerId(edge.getCustomerId()).edgeName(edge.getName()).errorMsg(errorMsg).build()); .customerId(edge.getCustomerId()).edgeName(edge.getName()).failureMsg(failureMsg)
.error("Failed to deliver messages after " + MAX_DOWNLINK_ATTEMPTS + " attempts").build());
stopCurrentSendDownlinkMsgsTask(false); stopCurrentSendDownlinkMsgsTask(false);
} }
} else { } else {
@ -790,10 +793,10 @@ public final class EdgeGrpcSession implements Closeable {
} }
} }
} catch (Exception e) { } catch (Exception e) {
String errorMsg = String.format("Can't process uplink msg [%s] from edge", uplinkMsg); String failureMsg = String.format("Can't process uplink msg [%s] from edge", uplinkMsg);
log.error("[{}][{}] Can't process uplink msg [{}]", this.tenantId, this.sessionId, uplinkMsg, e); log.error("[{}][{}] Can't process uplink msg [{}]", this.tenantId, this.sessionId, uplinkMsg, e);
ctx.getNotificationRuleProcessor().process(EdgeFailureTrigger.builder().tenantId(tenantId).edgeId(edge.getId()) ctx.getNotificationRuleProcessor().process(EdgeCommunicationFailureTrigger.builder().tenantId(tenantId).edgeId(edge.getId())
.customerId(edge.getCustomerId()).edgeName(edge.getName()).errorMsg(errorMsg).build()); .customerId(edge.getCustomerId()).edgeName(edge.getName()).failureMsg(failureMsg).error(e.getMessage()).build());
return Futures.immediateFailedFuture(e); return Futures.immediateFailedFuture(e);
} }
return Futures.allAsList(result); return Futures.allAsList(result);
@ -817,21 +820,22 @@ public final class EdgeGrpcSession implements Closeable {
.setMaxInboundMessageSize(maxInboundMessageSize) .setMaxInboundMessageSize(maxInboundMessageSize)
.build(); .build();
} }
String errorMsg = String.format("Failed to validate the edge! Provided request secret: %s", request.getEdgeSecret()); String error = "Failed to validate the edge!";
ctx.getNotificationRuleProcessor().process(EdgeFailureTrigger.builder().tenantId(tenantId).edgeId(edge.getId()) String failureMsg = String.format("{%s} Provided request secret: %s", error, request.getEdgeSecret());
.customerId(edge.getCustomerId()).edgeName(edge.getName()).errorMsg(errorMsg).build()); ctx.getNotificationRuleProcessor().process(EdgeCommunicationFailureTrigger.builder().tenantId(tenantId).edgeId(edge.getId())
.customerId(edge.getCustomerId()).edgeName(edge.getName()).failureMsg(failureMsg).error(error).build());
return ConnectResponseMsg.newBuilder() return ConnectResponseMsg.newBuilder()
.setResponseCode(ConnectResponseCode.BAD_CREDENTIALS) .setResponseCode(ConnectResponseCode.BAD_CREDENTIALS)
.setErrorMsg(errorMsg) .setErrorMsg(failureMsg)
.setConfiguration(EdgeConfiguration.getDefaultInstance()).build(); .setConfiguration(EdgeConfiguration.getDefaultInstance()).build();
} catch (Exception e) { } catch (Exception e) {
String errorMsg = "Failed to process edge connection!"; String failureMsg = "Failed to process edge connection!";
ctx.getNotificationRuleProcessor().process(EdgeFailureTrigger.builder().tenantId(tenantId).edgeId(edge.getId()) ctx.getNotificationRuleProcessor().process(EdgeCommunicationFailureTrigger.builder().tenantId(tenantId).edgeId(edge.getId())
.customerId(edge.getCustomerId()).edgeName(edge.getName()).errorMsg(errorMsg).build()); .customerId(edge.getCustomerId()).edgeName(edge.getName()).failureMsg(failureMsg).error(e.getMessage()).build());
log.error(errorMsg, e); log.error(failureMsg, e);
return ConnectResponseMsg.newBuilder() return ConnectResponseMsg.newBuilder()
.setResponseCode(ConnectResponseCode.SERVER_UNAVAILABLE) .setResponseCode(ConnectResponseCode.SERVER_UNAVAILABLE)
.setErrorMsg(errorMsg) .setErrorMsg(failureMsg)
.setConfiguration(EdgeConfiguration.getDefaultInstance()).build(); .setConfiguration(EdgeConfiguration.getDefaultInstance()).build();
} }
} }

26
application/src/main/java/org/thingsboard/server/service/notification/rule/trigger/EdgeFailureTriggerProcessor.java → application/src/main/java/org/thingsboard/server/service/notification/rule/trigger/EdgeCommunicationFailureTriggerProcessor.java

@ -18,18 +18,18 @@ package org.thingsboard.server.service.notification.rule.trigger;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.notification.info.EdgeFailureNotificationInfo; import org.thingsboard.server.common.data.notification.info.EdgeCommunicationFailureNotificationInfo;
import org.thingsboard.server.common.data.notification.info.RuleOriginatedNotificationInfo; import org.thingsboard.server.common.data.notification.info.RuleOriginatedNotificationInfo;
import org.thingsboard.server.common.data.notification.rule.trigger.EdgeFailureTrigger; import org.thingsboard.server.common.data.notification.rule.trigger.EdgeCommunicationFailureTrigger;
import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeFailureNotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeCommunicationFailureNotificationRuleTriggerConfig;
import org.thingsboard.server.common.data.notification.rule.trigger.config.NotificationRuleTriggerType; import org.thingsboard.server.common.data.notification.rule.trigger.config.NotificationRuleTriggerType;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class EdgeFailureTriggerProcessor implements NotificationRuleTriggerProcessor<EdgeFailureTrigger, EdgeFailureNotificationRuleTriggerConfig> { public class EdgeCommunicationFailureTriggerProcessor implements NotificationRuleTriggerProcessor<EdgeCommunicationFailureTrigger, EdgeCommunicationFailureNotificationRuleTriggerConfig> {
@Override @Override
public boolean matchesFilter(EdgeFailureTrigger trigger, EdgeFailureNotificationRuleTriggerConfig triggerConfig) { public boolean matchesFilter(EdgeCommunicationFailureTrigger trigger, EdgeCommunicationFailureNotificationRuleTriggerConfig triggerConfig) {
if (CollectionUtils.isNotEmpty(triggerConfig.getEdges())) { if (CollectionUtils.isNotEmpty(triggerConfig.getEdges())) {
return !triggerConfig.getEdges().contains(trigger.getEdgeId().getId()); return !triggerConfig.getEdges().contains(trigger.getEdgeId().getId());
} }
@ -37,18 +37,26 @@ public class EdgeFailureTriggerProcessor implements NotificationRuleTriggerProce
} }
@Override @Override
public RuleOriginatedNotificationInfo constructNotificationInfo(EdgeFailureTrigger trigger) { public RuleOriginatedNotificationInfo constructNotificationInfo(EdgeCommunicationFailureTrigger trigger) {
return EdgeFailureNotificationInfo.builder() return EdgeCommunicationFailureNotificationInfo.builder()
.tenantId(trigger.getTenantId()) .tenantId(trigger.getTenantId())
.edgeId(trigger.getEdgeId()) .edgeId(trigger.getEdgeId())
.customerId(trigger.getCustomerId()) .customerId(trigger.getCustomerId())
.edgeName(trigger.getEdgeName()) .edgeName(trigger.getEdgeName())
.errorMsg(trigger.getErrorMsg()) .failureMsg(truncateFailureMsg(trigger.getFailureMsg()))
.build(); .build();
} }
@Override @Override
public NotificationRuleTriggerType getTriggerType() { public NotificationRuleTriggerType getTriggerType() {
return NotificationRuleTriggerType.EDGE_FAILURE; return NotificationRuleTriggerType.EDGE_COMMUNICATION_FAILURE;
}
private String truncateFailureMsg(String input) {
int maxLength = 800;
if (input != null && input.length() > maxLength) {
return input.substring(0, maxLength);
}
return input;
} }
} }

18
application/src/main/java/org/thingsboard/server/service/notification/rule/trigger/EdgeConnectivityTriggerProcessor.java → application/src/main/java/org/thingsboard/server/service/notification/rule/trigger/EdgeConnectionTriggerProcessor.java

@ -18,19 +18,19 @@ package org.thingsboard.server.service.notification.rule.trigger;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.notification.info.EdgeConnectivityNotificationInfo; import org.thingsboard.server.common.data.notification.info.EdgeConnectionNotificationInfo;
import org.thingsboard.server.common.data.notification.info.RuleOriginatedNotificationInfo; import org.thingsboard.server.common.data.notification.info.RuleOriginatedNotificationInfo;
import org.thingsboard.server.common.data.notification.rule.trigger.EdgeConnectivityTrigger; import org.thingsboard.server.common.data.notification.rule.trigger.EdgeConnectionTrigger;
import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeConnectivityNotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeConnectionNotificationRuleTriggerConfig;
import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeConnectivityNotificationRuleTriggerConfig.EdgeConnectivityEvent; import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeConnectionNotificationRuleTriggerConfig.EdgeConnectivityEvent;
import org.thingsboard.server.common.data.notification.rule.trigger.config.NotificationRuleTriggerType; import org.thingsboard.server.common.data.notification.rule.trigger.config.NotificationRuleTriggerType;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class EdgeConnectivityTriggerProcessor implements NotificationRuleTriggerProcessor<EdgeConnectivityTrigger, EdgeConnectivityNotificationRuleTriggerConfig> { public class EdgeConnectionTriggerProcessor implements NotificationRuleTriggerProcessor<EdgeConnectionTrigger, EdgeConnectionNotificationRuleTriggerConfig> {
@Override @Override
public boolean matchesFilter(EdgeConnectivityTrigger trigger, EdgeConnectivityNotificationRuleTriggerConfig triggerConfig) { public boolean matchesFilter(EdgeConnectionTrigger trigger, EdgeConnectionNotificationRuleTriggerConfig triggerConfig) {
EdgeConnectivityEvent event = trigger.isConnected() ? EdgeConnectivityEvent.CONNECTED : EdgeConnectivityEvent.DISCONNECTED; EdgeConnectivityEvent event = trigger.isConnected() ? EdgeConnectivityEvent.CONNECTED : EdgeConnectivityEvent.DISCONNECTED;
if (CollectionUtils.isEmpty(triggerConfig.getNotifyOn()) || !triggerConfig.getNotifyOn().contains(event)) { if (CollectionUtils.isEmpty(triggerConfig.getNotifyOn()) || !triggerConfig.getNotifyOn().contains(event)) {
return false; return false;
@ -42,8 +42,8 @@ public class EdgeConnectivityTriggerProcessor implements NotificationRuleTrigger
} }
@Override @Override
public RuleOriginatedNotificationInfo constructNotificationInfo(EdgeConnectivityTrigger trigger) { public RuleOriginatedNotificationInfo constructNotificationInfo(EdgeConnectionTrigger trigger) {
return EdgeConnectivityNotificationInfo.builder() return EdgeConnectionNotificationInfo.builder()
.eventType(trigger.isConnected() ? "connected" : "disconnected") .eventType(trigger.isConnected() ? "connected" : "disconnected")
.tenantId(trigger.getTenantId()) .tenantId(trigger.getTenantId())
.customerId(trigger.getCustomerId()) .customerId(trigger.getCustomerId())
@ -54,7 +54,7 @@ public class EdgeConnectivityTriggerProcessor implements NotificationRuleTrigger
@Override @Override
public NotificationRuleTriggerType getTriggerType() { public NotificationRuleTriggerType getTriggerType() {
return NotificationRuleTriggerType.EDGE_CONNECTIVITY; return NotificationRuleTriggerType.EDGE_CONNECTION;
} }
} }

12
application/src/main/java/org/thingsboard/server/service/sync/ie/exporting/impl/NotificationRuleExportService.java

@ -29,8 +29,8 @@ import org.thingsboard.server.common.data.notification.rule.EscalatedNotificatio
import org.thingsboard.server.common.data.notification.rule.NotificationRule; import org.thingsboard.server.common.data.notification.rule.NotificationRule;
import org.thingsboard.server.common.data.notification.rule.NotificationRuleRecipientsConfig; import org.thingsboard.server.common.data.notification.rule.NotificationRuleRecipientsConfig;
import org.thingsboard.server.common.data.notification.rule.trigger.config.DeviceActivityNotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.DeviceActivityNotificationRuleTriggerConfig;
import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeConnectivityNotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeConnectionNotificationRuleTriggerConfig;
import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeFailureNotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeCommunicationFailureNotificationRuleTriggerConfig;
import org.thingsboard.server.common.data.notification.rule.trigger.config.NotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.NotificationRuleTriggerConfig;
import org.thingsboard.server.common.data.notification.rule.trigger.config.RuleEngineComponentLifecycleEventNotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.RuleEngineComponentLifecycleEventNotificationRuleTriggerConfig;
import org.thingsboard.server.common.data.sync.ie.EntityExportData; import org.thingsboard.server.common.data.sync.ie.EntityExportData;
@ -75,13 +75,13 @@ public class NotificationRuleExportService<I extends EntityId, E extends Exporta
} }
break; break;
} }
case EDGE_CONNECTIVITY: { case EDGE_CONNECTION: {
EdgeConnectivityNotificationRuleTriggerConfig triggerConfig = (EdgeConnectivityNotificationRuleTriggerConfig) ruleTriggerConfig; EdgeConnectionNotificationRuleTriggerConfig triggerConfig = (EdgeConnectionNotificationRuleTriggerConfig) ruleTriggerConfig;
triggerConfig.setEdges(null); triggerConfig.setEdges(null);
break; break;
} }
case EDGE_FAILURE: { case EDGE_COMMUNICATION_FAILURE: {
EdgeFailureNotificationRuleTriggerConfig triggerConfig = (EdgeFailureNotificationRuleTriggerConfig) ruleTriggerConfig; EdgeCommunicationFailureNotificationRuleTriggerConfig triggerConfig = (EdgeCommunicationFailureNotificationRuleTriggerConfig) ruleTriggerConfig;
triggerConfig.setEdges(null); triggerConfig.setEdges(null);
break; break;
} }

12
application/src/main/java/org/thingsboard/server/service/sync/ie/importing/impl/NotificationRuleImportService.java

@ -33,8 +33,8 @@ import org.thingsboard.server.common.data.notification.rule.EscalatedNotificatio
import org.thingsboard.server.common.data.notification.rule.NotificationRule; import org.thingsboard.server.common.data.notification.rule.NotificationRule;
import org.thingsboard.server.common.data.notification.rule.NotificationRuleRecipientsConfig; import org.thingsboard.server.common.data.notification.rule.NotificationRuleRecipientsConfig;
import org.thingsboard.server.common.data.notification.rule.trigger.config.DeviceActivityNotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.DeviceActivityNotificationRuleTriggerConfig;
import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeConnectivityNotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeConnectionNotificationRuleTriggerConfig;
import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeFailureNotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeCommunicationFailureNotificationRuleTriggerConfig;
import org.thingsboard.server.common.data.notification.rule.trigger.config.NotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.NotificationRuleTriggerConfig;
import org.thingsboard.server.common.data.notification.rule.trigger.config.NotificationRuleTriggerType; import org.thingsboard.server.common.data.notification.rule.trigger.config.NotificationRuleTriggerType;
import org.thingsboard.server.common.data.notification.rule.trigger.config.RuleEngineComponentLifecycleEventNotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.RuleEngineComponentLifecycleEventNotificationRuleTriggerConfig;
@ -98,13 +98,13 @@ public class NotificationRuleImportService extends BaseEntityImportService<Notif
} }
break; break;
} }
case EDGE_CONNECTIVITY: { case EDGE_CONNECTION: {
EdgeConnectivityNotificationRuleTriggerConfig triggerConfig = (EdgeConnectivityNotificationRuleTriggerConfig) ruleTriggerConfig; EdgeConnectionNotificationRuleTriggerConfig triggerConfig = (EdgeConnectionNotificationRuleTriggerConfig) ruleTriggerConfig;
triggerConfig.setEdges(null); triggerConfig.setEdges(null);
break; break;
} }
case EDGE_FAILURE: { case EDGE_COMMUNICATION_FAILURE: {
EdgeFailureNotificationRuleTriggerConfig triggerConfig = (EdgeFailureNotificationRuleTriggerConfig) ruleTriggerConfig; EdgeCommunicationFailureNotificationRuleTriggerConfig triggerConfig = (EdgeCommunicationFailureNotificationRuleTriggerConfig) ruleTriggerConfig;
triggerConfig.setEdges(null); triggerConfig.setEdges(null);
break; break;
} }

4
common/data/src/main/java/org/thingsboard/server/common/data/notification/NotificationType.java

@ -29,6 +29,6 @@ public enum NotificationType {
API_USAGE_LIMIT, API_USAGE_LIMIT,
RULE_NODE, RULE_NODE,
RATE_LIMITS, RATE_LIMITS,
EDGE_CONNECTIVITY, EDGE_CONNECTION,
EDGE_FAILURE EDGE_COMMUNICATION_FAILURE
} }

7
common/data/src/main/java/org/thingsboard/server/common/data/notification/info/EdgeFailureNotificationInfo.java → common/data/src/main/java/org/thingsboard/server/common/data/notification/info/EdgeCommunicationFailureNotificationInfo.java

@ -19,7 +19,6 @@ import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.EdgeId; import org.thingsboard.server.common.data.id.EdgeId;
import org.thingsboard.server.common.data.id.EntityId; import org.thingsboard.server.common.data.id.EntityId;
@ -33,13 +32,13 @@ import static org.thingsboard.server.common.data.util.CollectionsUtil.mapOf;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public class EdgeFailureNotificationInfo implements RuleOriginatedNotificationInfo { public class EdgeCommunicationFailureNotificationInfo implements RuleOriginatedNotificationInfo {
private TenantId tenantId; private TenantId tenantId;
private CustomerId customerId; private CustomerId customerId;
private EdgeId edgeId; private EdgeId edgeId;
private String edgeName; private String edgeName;
private String errorMsg; private String failureMsg;
@Override @Override
public Map<String, String> getTemplateData() { public Map<String, String> getTemplateData() {
@ -47,7 +46,7 @@ public class EdgeFailureNotificationInfo implements RuleOriginatedNotificationIn
"tenantId", tenantId.toString(), "tenantId", tenantId.toString(),
"edgeId", edgeId.toString(), "edgeId", edgeId.toString(),
"edgeName", edgeName, "edgeName", edgeName,
"errorMsg", errorMsg "failureMsg", failureMsg
); );
} }

2
common/data/src/main/java/org/thingsboard/server/common/data/notification/info/EdgeConnectivityNotificationInfo.java → common/data/src/main/java/org/thingsboard/server/common/data/notification/info/EdgeConnectionNotificationInfo.java

@ -32,7 +32,7 @@ import static org.thingsboard.server.common.data.util.CollectionsUtil.mapOf;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public class EdgeConnectivityNotificationInfo implements RuleOriginatedNotificationInfo { public class EdgeConnectionNotificationInfo implements RuleOriginatedNotificationInfo {
private String eventType; private String eventType;
private TenantId tenantId; private TenantId tenantId;

11
common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/EdgeFailureTrigger.java → common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/EdgeCommunicationFailureTrigger.java

@ -27,13 +27,14 @@ import java.util.concurrent.TimeUnit;
@Data @Data
@Builder @Builder
public class EdgeFailureTrigger implements NotificationRuleTrigger { public class EdgeCommunicationFailureTrigger implements NotificationRuleTrigger {
private final TenantId tenantId; private final TenantId tenantId;
private final CustomerId customerId; private final CustomerId customerId;
private final EdgeId edgeId; private final EdgeId edgeId;
private final String edgeName; private final String edgeName;
private final String errorMsg; private final String failureMsg;
private final String error;
@Override @Override
public boolean deduplicate() { public boolean deduplicate() {
@ -42,17 +43,17 @@ public class EdgeFailureTrigger implements NotificationRuleTrigger {
@Override @Override
public String getDeduplicationKey() { public String getDeduplicationKey() {
return String.join(":", NotificationRuleTrigger.super.getDeduplicationKey(), edgeName, errorMsg); return String.join(":", NotificationRuleTrigger.super.getDeduplicationKey(), edgeId.toString(), error);
} }
@Override @Override
public long getDefaultDeduplicationDuration() { public long getDefaultDeduplicationDuration() {
return TimeUnit.HOURS.toMillis(2); return TimeUnit.MINUTES.toMillis(30);
} }
@Override @Override
public NotificationRuleTriggerType getType() { public NotificationRuleTriggerType getType() {
return NotificationRuleTriggerType.EDGE_FAILURE; return NotificationRuleTriggerType.EDGE_COMMUNICATION_FAILURE;
} }
@Override @Override

7
common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/EdgeConnectivityTrigger.java → common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/EdgeConnectionTrigger.java

@ -23,12 +23,11 @@ import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.notification.rule.trigger.config.NotificationRuleTriggerType; import org.thingsboard.server.common.data.notification.rule.trigger.config.NotificationRuleTriggerType;
import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Data @Data
@Builder @Builder
public class EdgeConnectivityTrigger implements NotificationRuleTrigger { public class EdgeConnectionTrigger implements NotificationRuleTrigger {
private final TenantId tenantId; private final TenantId tenantId;
private final CustomerId customerId; private final CustomerId customerId;
@ -48,12 +47,12 @@ public class EdgeConnectivityTrigger implements NotificationRuleTrigger {
@Override @Override
public long getDefaultDeduplicationDuration() { public long getDefaultDeduplicationDuration() {
return TimeUnit.HOURS.toMillis(3); return TimeUnit.MINUTES.toMillis(30);
} }
@Override @Override
public NotificationRuleTriggerType getType() { public NotificationRuleTriggerType getType() {
return NotificationRuleTriggerType.EDGE_CONNECTIVITY; return NotificationRuleTriggerType.EDGE_CONNECTION;
} }
@Override @Override

4
common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/config/EdgeFailureNotificationRuleTriggerConfig.java → common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/config/EdgeCommunicationFailureNotificationRuleTriggerConfig.java

@ -27,13 +27,13 @@ import java.util.UUID;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public class EdgeFailureNotificationRuleTriggerConfig implements NotificationRuleTriggerConfig { public class EdgeCommunicationFailureNotificationRuleTriggerConfig implements NotificationRuleTriggerConfig {
private Set<UUID> edges; // if empty - all edges private Set<UUID> edges; // if empty - all edges
@Override @Override
public NotificationRuleTriggerType getTriggerType() { public NotificationRuleTriggerType getTriggerType() {
return NotificationRuleTriggerType.EDGE_FAILURE; return NotificationRuleTriggerType.EDGE_COMMUNICATION_FAILURE;
} }
} }

5
common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/config/EdgeConnectivityNotificationRuleTriggerConfig.java → common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/config/EdgeConnectionNotificationRuleTriggerConfig.java

@ -20,7 +20,6 @@ import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import javax.validation.constraints.NotEmpty;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -28,14 +27,14 @@ import java.util.UUID;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public class EdgeConnectivityNotificationRuleTriggerConfig implements NotificationRuleTriggerConfig { public class EdgeConnectionNotificationRuleTriggerConfig implements NotificationRuleTriggerConfig {
private Set<UUID> edges; // if empty - all edges private Set<UUID> edges; // if empty - all edges
private Set<EdgeConnectivityEvent> notifyOn; private Set<EdgeConnectivityEvent> notifyOn;
@Override @Override
public NotificationRuleTriggerType getTriggerType() { public NotificationRuleTriggerType getTriggerType() {
return NotificationRuleTriggerType.EDGE_CONNECTIVITY; return NotificationRuleTriggerType.EDGE_CONNECTION;
} }
public enum EdgeConnectivityEvent { public enum EdgeConnectivityEvent {

4
common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/config/NotificationRuleTriggerConfig.java

@ -36,8 +36,8 @@ import java.io.Serializable;
@Type(value = EntitiesLimitNotificationRuleTriggerConfig.class, name = "ENTITIES_LIMIT"), @Type(value = EntitiesLimitNotificationRuleTriggerConfig.class, name = "ENTITIES_LIMIT"),
@Type(value = ApiUsageLimitNotificationRuleTriggerConfig.class, name = "API_USAGE_LIMIT"), @Type(value = ApiUsageLimitNotificationRuleTriggerConfig.class, name = "API_USAGE_LIMIT"),
@Type(value = RateLimitsNotificationRuleTriggerConfig.class, name = "RATE_LIMITS"), @Type(value = RateLimitsNotificationRuleTriggerConfig.class, name = "RATE_LIMITS"),
@Type(value = EdgeConnectivityNotificationRuleTriggerConfig.class, name = "EDGE_CONNECTIVITY"), @Type(value = EdgeConnectionNotificationRuleTriggerConfig.class, name = "EDGE_CONNECTION"),
@Type(value = EdgeFailureNotificationRuleTriggerConfig.class, name = "EDGE_FAILURE"), @Type(value = EdgeCommunicationFailureNotificationRuleTriggerConfig.class, name = "EDGE_COMMUNICATION_FAILURE"),
}) })
public interface NotificationRuleTriggerConfig extends Serializable { public interface NotificationRuleTriggerConfig extends Serializable {

4
common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/config/NotificationRuleTriggerType.java

@ -26,8 +26,8 @@ public enum NotificationRuleTriggerType {
ALARM_ASSIGNMENT, ALARM_ASSIGNMENT,
DEVICE_ACTIVITY, DEVICE_ACTIVITY,
RULE_ENGINE_COMPONENT_LIFECYCLE_EVENT, RULE_ENGINE_COMPONENT_LIFECYCLE_EVENT,
EDGE_CONNECTIVITY, EDGE_CONNECTION,
EDGE_FAILURE, EDGE_COMMUNICATION_FAILURE,
NEW_PLATFORM_VERSION(false), NEW_PLATFORM_VERSION(false),
ENTITIES_LIMIT(false), ENTITIES_LIMIT(false),
API_USAGE_LIMIT(false), API_USAGE_LIMIT(false),

3
common/data/src/main/java/org/thingsboard/server/common/data/util/TemplateUtils.java

@ -19,6 +19,7 @@ import org.apache.commons.lang3.StringUtils;
import java.util.Map; import java.util.Map;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static com.google.common.base.Strings.nullToEmpty; import static com.google.common.base.Strings.nullToEmpty;
@ -49,7 +50,7 @@ public class TemplateUtils {
value = FUNCTIONS.get(function).apply(value); value = FUNCTIONS.get(function).apply(value);
} }
} }
return value; return Matcher.quoteReplacement(value);
}); });
} }

14
dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationSettingsService.java

@ -189,8 +189,8 @@ public class DefaultNotificationSettingsService implements NotificationSettingsS
defaultNotifications.create(tenantId, DefaultNotifications.alarmComment, tenantAdmins.getId()); defaultNotifications.create(tenantId, DefaultNotifications.alarmComment, tenantAdmins.getId());
defaultNotifications.create(tenantId, DefaultNotifications.alarmAssignment, affectedUser.getId()); defaultNotifications.create(tenantId, DefaultNotifications.alarmAssignment, affectedUser.getId());
defaultNotifications.create(tenantId, DefaultNotifications.ruleEngineComponentLifecycleFailure, tenantAdmins.getId()); defaultNotifications.create(tenantId, DefaultNotifications.ruleEngineComponentLifecycleFailure, tenantAdmins.getId());
defaultNotifications.create(tenantId, DefaultNotifications.edgeConnectivity, tenantAdmins.getId()); defaultNotifications.create(tenantId, DefaultNotifications.edgeConnection, tenantAdmins.getId());
defaultNotifications.create(tenantId, DefaultNotifications.edgeFailure, tenantAdmins.getId()); defaultNotifications.create(tenantId, DefaultNotifications.edgeCommunicationFailures, tenantAdmins.getId());
} }
@Override @Override
@ -210,7 +210,7 @@ public class DefaultNotificationSettingsService implements NotificationSettingsS
defaultNotifications.create(tenantId, DefaultNotifications.exceededPerEntityRateLimits, affectedTenantAdmins.getId()); defaultNotifications.create(tenantId, DefaultNotifications.exceededPerEntityRateLimits, affectedTenantAdmins.getId());
defaultNotifications.create(tenantId, DefaultNotifications.exceededRateLimitsForSysadmin, sysAdmins.getId()); defaultNotifications.create(tenantId, DefaultNotifications.exceededRateLimitsForSysadmin, sysAdmins.getId());
} else { } else {
List<NotificationType> requiredNotificationTypes = List.of(NotificationType.EDGE_CONNECTIVITY, NotificationType.EDGE_FAILURE); List<NotificationType> requiredNotificationTypes = List.of(NotificationType.EDGE_CONNECTION, NotificationType.EDGE_COMMUNICATION_FAILURE);
List<NotificationType> existingNotificationTypes = notificationTemplateService.findNotificationTemplatesByTenantIdAndNotificationTypes( List<NotificationType> existingNotificationTypes = notificationTemplateService.findNotificationTemplatesByTenantIdAndNotificationTypes(
tenantId, requiredNotificationTypes, new PageLink(1)) tenantId, requiredNotificationTypes, new PageLink(1))
.getData() .getData()
@ -227,11 +227,11 @@ public class DefaultNotificationSettingsService implements NotificationSettingsS
for (NotificationType type : requiredNotificationTypes) { for (NotificationType type : requiredNotificationTypes) {
if (!existingNotificationTypes.contains(type)) { if (!existingNotificationTypes.contains(type)) {
switch (type) { switch (type) {
case EDGE_CONNECTIVITY: case EDGE_CONNECTION:
defaultNotifications.create(tenantId, DefaultNotifications.edgeConnectivity, tenantAdmins.getId()); defaultNotifications.create(tenantId, DefaultNotifications.edgeConnection, tenantAdmins.getId());
break; break;
case EDGE_FAILURE: case EDGE_COMMUNICATION_FAILURE:
defaultNotifications.create(tenantId, DefaultNotifications.edgeFailure, tenantAdmins.getId()); defaultNotifications.create(tenantId, DefaultNotifications.edgeCommunicationFailures, tenantAdmins.getId());
break; break;
} }
} }

39
dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotifications.java

@ -40,9 +40,9 @@ import org.thingsboard.server.common.data.notification.rule.trigger.config.Alarm
import org.thingsboard.server.common.data.notification.rule.trigger.config.ApiUsageLimitNotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.ApiUsageLimitNotificationRuleTriggerConfig;
import org.thingsboard.server.common.data.notification.rule.trigger.config.DeviceActivityNotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.DeviceActivityNotificationRuleTriggerConfig;
import org.thingsboard.server.common.data.notification.rule.trigger.config.DeviceActivityNotificationRuleTriggerConfig.DeviceEvent; import org.thingsboard.server.common.data.notification.rule.trigger.config.DeviceActivityNotificationRuleTriggerConfig.DeviceEvent;
import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeConnectivityNotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeConnectionNotificationRuleTriggerConfig;
import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeConnectivityNotificationRuleTriggerConfig.EdgeConnectivityEvent; import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeConnectionNotificationRuleTriggerConfig.EdgeConnectivityEvent;
import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeFailureNotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.EdgeCommunicationFailureNotificationRuleTriggerConfig;
import org.thingsboard.server.common.data.notification.rule.trigger.config.EntitiesLimitNotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.EntitiesLimitNotificationRuleTriggerConfig;
import org.thingsboard.server.common.data.notification.rule.trigger.config.EntityActionNotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.EntityActionNotificationRuleTriggerConfig;
import org.thingsboard.server.common.data.notification.rule.trigger.config.NewPlatformVersionNotificationRuleTriggerConfig; import org.thingsboard.server.common.data.notification.rule.trigger.config.NewPlatformVersionNotificationRuleTriggerConfig;
@ -328,34 +328,33 @@ public class DefaultNotifications {
.description("Send notification to tenant admins when any Rule chain or Rule node failed to start, update or stop") .description("Send notification to tenant admins when any Rule chain or Rule node failed to start, update or stop")
.build()) .build())
.build(); .build();
public static final DefaultNotification edgeConnectivity = DefaultNotification.builder() public static final DefaultNotification edgeConnection = DefaultNotification.builder()
.name("Edge connectivity notification") .name("Edge connection notification")
.type(NotificationType.EDGE_CONNECTIVITY) .type(NotificationType.EDGE_CONNECTION)
.subject("Edge '${edgeName}' is ${eventType}") .subject("Edge connection status change")
.text("Edge '${edgeName}' is now ${eventType}") .text("Edge '${edgeName}' is now ${eventType}")
.icon("info").color(null) .icon("info").color(null)
.button("Go to Edge").link("/edgeManagement/instances/${edgeId}") .button("Go to Edge").link("/edgeManagement/instances/${edgeId}")
.rule(DefaultRule.builder() .rule(DefaultRule.builder()
.name("Edge connectivity") .name("Edge connection status change")
.enabled(false) .triggerConfig(EdgeConnectionNotificationRuleTriggerConfig.builder()
.triggerConfig(EdgeConnectivityNotificationRuleTriggerConfig.builder()
.edges(null) .edges(null)
.notifyOn(Set.of(EdgeConnectivityEvent.CONNECTED, EdgeConnectivityEvent.DISCONNECTED)) .notifyOn(Set.of(EdgeConnectivityEvent.CONNECTED, EdgeConnectivityEvent.DISCONNECTED))
.build()) .build())
.description("Send notification to tenant admins when Edge changes its connectivity state") .description("Send notification to tenant admins when the connection status between TB and Edge changes")
.build()) .build())
.build(); .build();
public static final DefaultNotification edgeFailure = DefaultNotification.builder() public static final DefaultNotification edgeCommunicationFailures = DefaultNotification.builder()
.name("Edge error notification") .name("Edge communication failure notification")
.type(NotificationType.EDGE_FAILURE) .type(NotificationType.EDGE_COMMUNICATION_FAILURE)
.subject("Edge '${edgeName}' received error") .subject("Edge '${edgeName}' communication failure occured")
.text("Error message: '${errorMsg}'") .text("Failure message: '${failureMsg}'")
.icon("error").color(null) .icon("error").color(RED_COLOR)
.button("Go to Edge").link("/edgeManagement/instances/${edgeId}") .button("Go to Edge").link("/edgeManagement/instances/${edgeId}")
.rule(DefaultRule.builder() .rule(DefaultRule.builder()
.name("Edge error") .name("Edge communication failure")
.triggerConfig(EdgeFailureNotificationRuleTriggerConfig.builder().edges(null).build()) .triggerConfig(EdgeCommunicationFailureNotificationRuleTriggerConfig.builder().edges(null).build())
.description("Send notification to tenant admins or to assigned customers to Edge when error occurs") .description("Send notification to tenant admins when communication failures occur")
.build()) .build())
.build(); .build();

18
ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.html

@ -408,10 +408,10 @@
</form> </form>
</mat-step> </mat-step>
<mat-step [stepControl]="edgeConnectivityTemplateForm" <mat-step [stepControl]="edgeConnectionTemplateForm"
*ngIf="ruleNotificationForm.get('triggerType').value === triggerType.EDGE_CONNECTIVITY"> *ngIf="ruleNotificationForm.get('triggerType').value === triggerType.EDGE_CONNECTION">
<ng-template matStepLabel>{{ 'notification.edge-trigger-settings' | translate }}</ng-template> <ng-template matStepLabel>{{ 'notification.edge-trigger-settings' | translate }}</ng-template>
<form [formGroup]="edgeConnectivityTemplateForm"> <form [formGroup]="edgeConnectionTemplateForm">
<section formGroupName="triggerConfig"> <section formGroupName="triggerConfig">
<fieldset class="fields-group tb-margin-before-field"> <fieldset class="fields-group tb-margin-before-field">
<legend translate>notification.filter</legend> <legend translate>notification.filter</legend>
@ -426,9 +426,9 @@
<mat-form-field fxFlex class="mat-block" floatLabel="always"> <mat-form-field fxFlex class="mat-block" floatLabel="always">
<mat-label translate>notification.notify-on</mat-label> <mat-label translate>notification.notify-on</mat-label>
<mat-select formControlName="notifyOn" multiple <mat-select formControlName="notifyOn" multiple
placeholder="{{ !edgeConnectivityTemplateForm.get('triggerConfig.notifyOn').value?.length ? ('event.all-events' | translate) : '' }}"> placeholder="{{ !edgeConnectionTemplateForm.get('triggerConfig.notifyOn').value?.length ? ('event.all-events' | translate) : '' }}">
<mat-option *ngFor="let edgeEvent of edgeConnectivityEvents" [value]="edgeEvent"> <mat-option *ngFor="let edgeEvent of edgeConnectionEvents" [value]="edgeEvent">
{{ edgeConnectivityEventTranslationMap.get(edgeEvent) | translate }} {{ edgeConnectionEventTranslationMap.get(edgeEvent) | translate }}
</mat-option> </mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
@ -445,10 +445,10 @@
</form> </form>
</mat-step> </mat-step>
<mat-step [stepControl]="edgeFailureTemplateForm" <mat-step [stepControl]="edgeCommunicationFailureTemplateForm"
*ngIf="ruleNotificationForm.get('triggerType').value === triggerType.EDGE_FAILURE"> *ngIf="ruleNotificationForm.get('triggerType').value === triggerType.EDGE_COMMUNICATION_FAILURE">
<ng-template matStepLabel>{{ 'notification.edge-trigger-settings' | translate }}</ng-template> <ng-template matStepLabel>{{ 'notification.edge-trigger-settings' | translate }}</ng-template>
<form [formGroup]="edgeFailureTemplateForm"> <form [formGroup]="edgeCommunicationFailureTemplateForm">
<section formGroupName="triggerConfig"> <section formGroupName="triggerConfig">
<fieldset class="fields-group tb-margin-before-field"> <fieldset class="fields-group tb-margin-before-field">
<legend translate>notification.filter</legend> <legend translate>notification.filter</legend>

18
ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.ts

@ -68,7 +68,7 @@ import {
} from '@shared/models/api-usage.models'; } from '@shared/models/api-usage.models';
import { LimitedApi, LimitedApiTranslationMap } from '@shared/models/limited-api.models'; import { LimitedApi, LimitedApiTranslationMap } from '@shared/models/limited-api.models';
import { StringItemsOption } from '@shared/components/string-items-list.component'; import { StringItemsOption } from '@shared/components/string-items-list.component';
import { EdgeConnectivityEvent, EdgeConnectivityEventTranslationMap } from '@shared/models/edge.models'; import { EdgeConnectionEvent, EdgeConnectionEventTranslationMap } from '@shared/models/edge.models';
export interface RuleNotificationDialogData { export interface RuleNotificationDialogData {
rule?: NotificationRule; rule?: NotificationRule;
@ -99,8 +99,8 @@ export class RuleNotificationDialogComponent extends
apiUsageLimitTemplateForm: FormGroup; apiUsageLimitTemplateForm: FormGroup;
newPlatformVersionTemplateForm: FormGroup; newPlatformVersionTemplateForm: FormGroup;
rateLimitsTemplateForm: FormGroup; rateLimitsTemplateForm: FormGroup;
edgeFailureTemplateForm: FormGroup; edgeCommunicationFailureTemplateForm: FormGroup;
edgeConnectivityTemplateForm: FormGroup; edgeConnectionTemplateForm: FormGroup;
triggerType = TriggerType; triggerType = TriggerType;
triggerTypes: TriggerType[]; triggerTypes: TriggerType[];
@ -135,8 +135,8 @@ export class RuleNotificationDialogComponent extends
apiFeatures: ApiFeature[] = Object.values(ApiFeature); apiFeatures: ApiFeature[] = Object.values(ApiFeature);
apiFeatureTranslationMap = ApiFeatureTranslationMap; apiFeatureTranslationMap = ApiFeatureTranslationMap;
edgeConnectivityEvents: EdgeConnectivityEvent[] = Object.values(EdgeConnectivityEvent); edgeConnectionEvents: EdgeConnectionEvent[] = Object.values(EdgeConnectionEvent);
edgeConnectivityEventTranslationMap = EdgeConnectivityEventTranslationMap; edgeConnectionEventTranslationMap = EdgeConnectionEventTranslationMap;
limitedApis: StringItemsOption[]; limitedApis: StringItemsOption[];
@ -227,14 +227,14 @@ export class RuleNotificationDialogComponent extends
} }
}); });
this.edgeConnectivityTemplateForm = this.fb.group({ this.edgeConnectionTemplateForm = this.fb.group({
triggerConfig: this.fb.group({ triggerConfig: this.fb.group({
edges: [null], edges: [null],
notifyOn: [null] notifyOn: [null]
}) })
}); });
this.edgeFailureTemplateForm = this.fb.group({ this.edgeCommunicationFailureTemplateForm = this.fb.group({
triggerConfig: this.fb.group({ triggerConfig: this.fb.group({
edges: [null] edges: [null]
}) })
@ -348,8 +348,8 @@ export class RuleNotificationDialogComponent extends
[TriggerType.API_USAGE_LIMIT, this.apiUsageLimitTemplateForm], [TriggerType.API_USAGE_LIMIT, this.apiUsageLimitTemplateForm],
[TriggerType.NEW_PLATFORM_VERSION, this.newPlatformVersionTemplateForm], [TriggerType.NEW_PLATFORM_VERSION, this.newPlatformVersionTemplateForm],
[TriggerType.RATE_LIMITS, this.rateLimitsTemplateForm], [TriggerType.RATE_LIMITS, this.rateLimitsTemplateForm],
[TriggerType.EDGE_FAILURE, this.edgeFailureTemplateForm], [TriggerType.EDGE_COMMUNICATION_FAILURE, this.edgeCommunicationFailureTemplateForm],
[TriggerType.EDGE_CONNECTIVITY, this.edgeConnectivityTemplateForm] [TriggerType.EDGE_CONNECTION, this.edgeConnectionTemplateForm]
]); ]);
if (data.isAdd || data.isCopy) { if (data.isAdd || data.isCopy) {

8
ui-ngx/src/app/shared/models/edge.models.ts

@ -191,14 +191,14 @@ export enum EdgeInstructionsMethod {
export const edgeVersionAttributeKey = 'edgeVersion'; export const edgeVersionAttributeKey = 'edgeVersion';
export enum EdgeConnectivityEvent { export enum EdgeConnectionEvent {
CONNECTED= 'CONNECTED', CONNECTED= 'CONNECTED',
DISCONNECTED = 'DISCONNECTED' DISCONNECTED = 'DISCONNECTED'
} }
export const EdgeConnectivityEventTranslationMap = new Map<EdgeConnectivityEvent, string>( export const EdgeConnectionEventTranslationMap = new Map<EdgeConnectionEvent, string>(
[ [
[EdgeConnectivityEvent.CONNECTED, 'edge-event.connected'], [EdgeConnectionEvent.CONNECTED, 'edge.connected'],
[EdgeConnectivityEvent.DISCONNECTED, 'edge-event.disconnected'] [EdgeConnectionEvent.DISCONNECTED, 'edge.disconnected']
] ]
); );

24
ui-ngx/src/app/shared/models/notification.models.ts

@ -475,8 +475,8 @@ export enum NotificationType {
NEW_PLATFORM_VERSION = 'NEW_PLATFORM_VERSION', NEW_PLATFORM_VERSION = 'NEW_PLATFORM_VERSION',
RULE_NODE = 'RULE_NODE', RULE_NODE = 'RULE_NODE',
RATE_LIMITS = 'RATE_LIMITS', RATE_LIMITS = 'RATE_LIMITS',
EDGE_CONNECTIVITY = 'EDGE_CONNECTIVITY', EDGE_CONNECTION = 'EDGE_CONNECTION',
EDGE_FAILURE = 'EDGE_FAILURE' EDGE_COMMUNICATION_FAILURE = 'EDGE_COMMUNICATION_FAILURE'
} }
export const NotificationTypeIcons = new Map<NotificationType, string | null>([ export const NotificationTypeIcons = new Map<NotificationType, string | null>([
@ -588,16 +588,16 @@ export const NotificationTemplateTypeTranslateMap = new Map<NotificationType, No
helpId: 'notification/rate_limits' helpId: 'notification/rate_limits'
} }
], ],
[NotificationType.EDGE_CONNECTIVITY, [NotificationType.EDGE_CONNECTION,
{ {
name: 'notification.template-type.edge-connectivity', name: 'notification.template-type.edge-connection',
helpId: 'notification/edge_connectivity' helpId: 'notification/edge_connection'
} }
], ],
[NotificationType.EDGE_FAILURE, [NotificationType.EDGE_COMMUNICATION_FAILURE,
{ {
name: 'notification.template-type.edge-failure', name: 'notification.template-type.edge-communication-failure',
helpId: 'notification/edge_failure' helpId: 'notification/edge_communication_failure'
} }
] ]
]); ]);
@ -613,8 +613,8 @@ export enum TriggerType {
API_USAGE_LIMIT = 'API_USAGE_LIMIT', API_USAGE_LIMIT = 'API_USAGE_LIMIT',
NEW_PLATFORM_VERSION = 'NEW_PLATFORM_VERSION', NEW_PLATFORM_VERSION = 'NEW_PLATFORM_VERSION',
RATE_LIMITS = 'RATE_LIMITS', RATE_LIMITS = 'RATE_LIMITS',
EDGE_CONNECTIVITY = 'EDGE_CONNECTIVITY', EDGE_CONNECTION = 'EDGE_CONNECTION',
EDGE_FAILURE = 'EDGE_FAILURE' EDGE_COMMUNICATION_FAILURE = 'EDGE_COMMUNICATION_FAILURE'
} }
export const TriggerTypeTranslationMap = new Map<TriggerType, string>([ export const TriggerTypeTranslationMap = new Map<TriggerType, string>([
@ -628,8 +628,8 @@ export const TriggerTypeTranslationMap = new Map<TriggerType, string>([
[TriggerType.API_USAGE_LIMIT, 'notification.trigger.api-usage-limit'], [TriggerType.API_USAGE_LIMIT, 'notification.trigger.api-usage-limit'],
[TriggerType.NEW_PLATFORM_VERSION, 'notification.trigger.new-platform-version'], [TriggerType.NEW_PLATFORM_VERSION, 'notification.trigger.new-platform-version'],
[TriggerType.RATE_LIMITS, 'notification.trigger.rate-limits'], [TriggerType.RATE_LIMITS, 'notification.trigger.rate-limits'],
[TriggerType.EDGE_CONNECTIVITY, 'notification.trigger.edge-connectivity'], [TriggerType.EDGE_CONNECTION, 'notification.trigger.edge-connection'],
[TriggerType.EDGE_FAILURE, 'notification.trigger.edge-failure'] [TriggerType.EDGE_COMMUNICATION_FAILURE, 'notification.trigger.edge-communication-failure']
]); ]);
export interface NotificationUserSettings { export interface NotificationUserSettings {

10
ui-ngx/src/assets/help/en_US/notification/edge_failure.md → ui-ngx/src/assets/help/en_US/notification/edge_communication_failure.md

@ -11,7 +11,7 @@ Available template parameters:
* `edgeId` - the edge id as uuid string; * `edgeId` - the edge id as uuid string;
* `edgeName` - the name of the edge; * `edgeName` - the name of the edge;
* `errorMsg` - the string representation of the error, occurred on the Edge; * `failureMsg` - the string representation of the failure, occurred on the Edge;
Parameter names must be wrapped using `${...}`. For example: `${edgeName}`. Parameter names must be wrapped using `${...}`. For example: `${edgeName}`.
You may also modify the value of the parameter with one of the suffixes: You may also modify the value of the parameter with one of the suffixes:
@ -28,14 +28,14 @@ Let's assume the notification about the failing of processing connection to Edge
The following template: The following template:
```text ```text
Edge '${edgeName}' received error Edge '${edgeName}' communication failure occurred
{:copy-code} {:copy-code}
``` ```
will be transformed to: will be transformed to:
```text ```text
Edge 'DatacenterEdge' received error Edge 'DatacenterEdge' communication failure occurred
``` ```
<br/> <br/>
@ -43,14 +43,14 @@ Edge 'DatacenterEdge' received error
The following template: The following template:
```text ```text
Error message: '${errorMsg}' Failure message: '${failureMsg}'
{:copy-code} {:copy-code}
``` ```
will be transformed to: will be transformed to:
```text ```text
Error message: 'Failed to process edge connection!' Failure message: 'Failed to process edge connection!'
``` ```
<br> <br>

17
ui-ngx/src/assets/help/en_US/notification/edge_connectivity.md → ui-ngx/src/assets/help/en_US/notification/edge_connection.md

@ -28,30 +28,17 @@ Let's assume the notification about the connecting Edge into the ThingsBoard.
The following template: The following template:
```text ```text
Edge '${edgeName}' is ${eventType} Edge '${edgeName}' is now ${eventType}
{:copy-code} {:copy-code}
``` ```
will be transformed to: will be transformed to:
```text ```text
Edge 'DatacenterEdge' is connected Edge 'DatacenterEdge' is now connected
``` ```
<br/> <br/>
The following template:
```text
"Edge '${edgeName}' is now ${eventType}"
{:copy-code}
```
will be transformed to:
```text
Edge 'DatacenterEdge' is now connected
```
<br> <br>
<br> <br>

16
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -2030,7 +2030,9 @@
"missing-related-rule-chains-title": "Edge has missing related rule chain(s)", "missing-related-rule-chains-title": "Edge has missing related rule chain(s)",
"missing-related-rule-chains-text": "Assigned to edge rule chain(s) use rule nodes that forward message(s) to rule chain(s) that are not assigned to this edge. <br><br> List of missing rule chain(s): <br> {{missingRuleChains}}", "missing-related-rule-chains-text": "Assigned to edge rule chain(s) use rule nodes that forward message(s) to rule chain(s) that are not assigned to this edge. <br><br> List of missing rule chain(s): <br> {{missingRuleChains}}",
"upgrade-instructions": "Upgrade Instructions", "upgrade-instructions": "Upgrade Instructions",
"widget-datasource-error": "This widget supports only EDGE entity datasource" "widget-datasource-error": "This widget supports only EDGE entity datasource",
"connected": "Connected",
"disconnected": "Disconnected"
}, },
"edge-event": { "edge-event": {
"type-dashboard": "Dashboard", "type-dashboard": "Dashboard",
@ -2073,9 +2075,7 @@
"action-type-assigned-to-edge": "Assigned to Edge", "action-type-assigned-to-edge": "Assigned to Edge",
"action-type-unassigned-from-edge": "Unassigned from Edge", "action-type-unassigned-from-edge": "Unassigned from Edge",
"action-type-credentials-request": "Credentials Request", "action-type-credentials-request": "Credentials Request",
"action-type-entity-merge-request": "Entity Merge Request", "action-type-entity-merge-request": "Entity Merge Request"
"connected": "Connected",
"disconnected": "Disconnected"
}, },
"error": { "error": {
"unable-to-connect": "Unable to connect to the server! Please check your internet connection.", "unable-to-connect": "Unable to connect to the server! Please check your internet connection.",
@ -3430,8 +3430,8 @@
"rule-node": "Rule node", "rule-node": "Rule node",
"new-platform-version": "New platform version", "new-platform-version": "New platform version",
"rate-limits": "Exceeded rate limits", "rate-limits": "Exceeded rate limits",
"edge-failure": "Edge error", "edge-communication-failure": "Edge communication failure",
"edge-connectivity": "Edge connectivity" "edge-connection": "Edge connection"
}, },
"templates": "Templates", "templates": "Templates",
"notification-templates": "Notifications / Templates", "notification-templates": "Notifications / Templates",
@ -3452,8 +3452,8 @@
"rule-engine-lifecycle-event": "Rule engine lifecycle event", "rule-engine-lifecycle-event": "Rule engine lifecycle event",
"new-platform-version": "New platform version", "new-platform-version": "New platform version",
"rate-limits": "Exceeded rate limits", "rate-limits": "Exceeded rate limits",
"edge-connectivity": "Edge connectivity", "edge-connection": "Edge connection",
"edge-failure": "Edge failure", "edge-communication-failure": "Edge communication failure",
"trigger": "Trigger", "trigger": "Trigger",
"trigger-required": "Trigger is required" "trigger-required": "Trigger is required"
}, },

Loading…
Cancel
Save