Skip to content

Commit b0684db

Browse files
committed
add two vars to the alert template variable list
Signed-off-by: Richard Ogin <rogin@users.noreply.github.com>
1 parent 4be01c9 commit b0684db

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

client/src/com/mirth/connect/client/ui/alert/DefaultAlertEditPanel.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import javax.swing.JLabel;
1919
import javax.swing.JPanel;
2020

21-
import net.miginfocom.swing.MigLayout;
22-
2321
import org.apache.commons.collections4.CollectionUtils;
2422
import org.apache.commons.lang3.StringUtils;
2523

@@ -35,6 +33,8 @@
3533
import com.mirth.connect.model.alert.ChannelTrigger;
3634
import com.mirth.connect.model.alert.DefaultTrigger;
3735

36+
import net.miginfocom.swing.MigLayout;
37+
3838
public class DefaultAlertEditPanel extends AlertEditPanel {
3939

4040
private Frame parent;
@@ -105,6 +105,8 @@ public void updateVariableList() {
105105
variables.add("alertId");
106106
variables.add("alertName");
107107
variables.add("serverId");
108+
variables.add("serverName");
109+
variables.add("environmentName");
108110
variables.add("globalMapVariable");
109111
variables.add("date");
110112

server/src/com/mirth/connect/server/alert/Alert.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,24 @@
99

1010
package com.mirth.connect.server.alert;
1111

12+
import static java.util.Map.entry;
13+
1214
import java.util.HashMap;
1315
import java.util.Map;
1416
import java.util.concurrent.atomic.AtomicInteger;
1517

18+
import org.apache.commons.lang3.StringUtils;
19+
import org.apache.logging.log4j.LogManager;
20+
import org.apache.logging.log4j.Logger;
1621
import org.apache.velocity.tools.generic.DateTool;
1722

23+
import com.mirth.connect.client.core.ControllerException;
24+
import com.mirth.connect.model.ServerSettings;
1825
import com.mirth.connect.model.alert.AlertModel;
1926
import com.mirth.connect.server.controllers.ConfigurationController;
2027

2128
public class Alert {
29+
private Logger logger = LogManager.getLogger(this.getClass());
2230

2331
private AlertModel model;
2432
private Long enabledDateTime;
@@ -56,11 +64,25 @@ public Map<String, Object> createContext() {
5664
context.put("alertId", model.getId());
5765
context.put("alertName", model.getName());
5866
context.put("serverId", ConfigurationController.getInstance().getServerId());
67+
context.putAll(getServerSettings());
5968
context.put("date", new DateTool());
6069

6170
return context;
6271
}
6372

73+
private Map<String, Object> getServerSettings() {
74+
try {
75+
ServerSettings settings = ConfigurationController.getInstance().getServerSettings();
76+
// ensure an empty string as Velocity won't replace when given a null value
77+
return Map.ofEntries(entry("serverName", StringUtils.defaultString(settings.getServerName())),
78+
entry("environmentName", StringUtils.defaultString(settings.getEnvironmentName())));
79+
} catch (ControllerException e) {
80+
logger.warn("Failed to retrieve server settings", e);
81+
}
82+
83+
return Map.of();
84+
}
85+
6486
public int getAlertedCount() {
6587
return alertedCount.get();
6688
}

0 commit comments

Comments
 (0)