Skip to content

Commit 3ae4bcf

Browse files
committed
api,server: allow configuring repetitive alerts
Fixes #6613 Introduces support for configuring additional alert types that can be published repeatedly, beyond the default set. Operators can now use the dynamic configuration `alert.allowed.repetitive.types` to specify a comma-separated list of alert type names that should be allowed for repetitive publication. Signed-off-by: Abhishek Kumar <[email protected]>
1 parent cca8b2f commit 3ae4bcf

File tree

6 files changed

+124
-75
lines changed

6 files changed

+124
-75
lines changed

api/src/main/java/org/apache/cloudstack/alert/AlertService.java

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
// under the License.
1717
package org.apache.cloudstack.alert;
1818

19+
import java.util.HashMap;
1920
import java.util.HashSet;
21+
import java.util.Map;
2022
import java.util.Set;
2123

2224
import com.cloud.capacity.Capacity;
@@ -25,55 +27,59 @@
2527
public interface AlertService {
2628
public static class AlertType {
2729
private static Set<AlertType> defaultAlertTypes = new HashSet<AlertType>();
30+
private static Map<String, AlertType> allAlertTypesMap = new HashMap<>();
2831
private final String name;
2932
private final short type;
33+
private final boolean repetitionAllowed;
3034

31-
private AlertType(short type, String name, boolean isDefault) {
35+
private AlertType(short type, String name, boolean isDefault, boolean repetitionAllowed) {
3236
this.name = name;
3337
this.type = type;
38+
this.repetitionAllowed = repetitionAllowed;
3439
if (isDefault) {
3540
defaultAlertTypes.add(this);
3641
}
42+
allAlertTypesMap.put(name, this);
3743
}
3844

39-
public static final AlertType ALERT_TYPE_MEMORY = new AlertType(Capacity.CAPACITY_TYPE_MEMORY, "ALERT.MEMORY", true);
40-
public static final AlertType ALERT_TYPE_CPU = new AlertType(Capacity.CAPACITY_TYPE_CPU, "ALERT.CPU", true);
41-
public static final AlertType ALERT_TYPE_STORAGE = new AlertType(Capacity.CAPACITY_TYPE_STORAGE, "ALERT.STORAGE", true);
42-
public static final AlertType ALERT_TYPE_STORAGE_ALLOCATED = new AlertType(Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, "ALERT.STORAGE.ALLOCATED", true);
45+
public static final AlertType ALERT_TYPE_MEMORY = new AlertType(Capacity.CAPACITY_TYPE_MEMORY, "ALERT.MEMORY", true, false);
46+
public static final AlertType ALERT_TYPE_CPU = new AlertType(Capacity.CAPACITY_TYPE_CPU, "ALERT.CPU", true, false);
47+
public static final AlertType ALERT_TYPE_STORAGE = new AlertType(Capacity.CAPACITY_TYPE_STORAGE, "ALERT.STORAGE", true, false);
48+
public static final AlertType ALERT_TYPE_STORAGE_ALLOCATED = new AlertType(Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, "ALERT.STORAGE.ALLOCATED", true, false);
4349
public static final AlertType ALERT_TYPE_VIRTUAL_NETWORK_PUBLIC_IP = new AlertType(Capacity.CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP, "ALERT.NETWORK.PUBLICIP",
44-
true);
45-
public static final AlertType ALERT_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET = new AlertType(Capacity.CAPACITY_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET, "ALERT.NETWORK.IPV6SUBNET", true);
46-
public static final AlertType ALERT_TYPE_PRIVATE_IP = new AlertType(Capacity.CAPACITY_TYPE_PRIVATE_IP, "ALERT.NETWORK.PRIVATEIP", true);
47-
public static final AlertType ALERT_TYPE_SECONDARY_STORAGE = new AlertType(Capacity.CAPACITY_TYPE_SECONDARY_STORAGE, "ALERT.STORAGE.SECONDARY", true);
48-
public static final AlertType ALERT_TYPE_HOST = new AlertType((short)7, "ALERT.COMPUTE.HOST", true);
49-
public static final AlertType ALERT_TYPE_USERVM = new AlertType((short)8, "ALERT.USERVM", true);
50-
public static final AlertType ALERT_TYPE_DOMAIN_ROUTER = new AlertType((short)9, "ALERT.SERVICE.DOMAINROUTER", true);
51-
public static final AlertType ALERT_TYPE_CONSOLE_PROXY = new AlertType((short)10, "ALERT.SERVICE.CONSOLEPROXY", true);
52-
public static final AlertType ALERT_TYPE_ROUTING = new AlertType((short)11, "ALERT.NETWORK.ROUTING", true);
53-
public static final AlertType ALERT_TYPE_STORAGE_MISC = new AlertType((short)12, "ALERT.STORAGE.MISC", true);
54-
public static final AlertType ALERT_TYPE_USAGE_SERVER = new AlertType((short)13, "ALERT.USAGE", true);
55-
public static final AlertType ALERT_TYPE_MANAGEMENT_NODE = new AlertType((short)14, "ALERT.MANAGEMENT", true);
56-
public static final AlertType ALERT_TYPE_DOMAIN_ROUTER_MIGRATE = new AlertType((short)15, "ALERT.NETWORK.DOMAINROUTERMIGRATE", true);
57-
public static final AlertType ALERT_TYPE_CONSOLE_PROXY_MIGRATE = new AlertType((short)16, "ALERT.SERVICE.CONSOLEPROXYMIGRATE", true);
58-
public static final AlertType ALERT_TYPE_USERVM_MIGRATE = new AlertType((short)17, "ALERT.USERVM.MIGRATE", true);
59-
public static final AlertType ALERT_TYPE_VLAN = new AlertType((short)18, "ALERT.NETWORK.VLAN", true);
60-
public static final AlertType ALERT_TYPE_SSVM = new AlertType((short)19, "ALERT.SERVICE.SSVM", true);
61-
public static final AlertType ALERT_TYPE_USAGE_SERVER_RESULT = new AlertType((short)20, "ALERT.USAGE.RESULT", true);
62-
public static final AlertType ALERT_TYPE_STORAGE_DELETE = new AlertType((short)21, "ALERT.STORAGE.DELETE", true);
63-
public static final AlertType ALERT_TYPE_UPDATE_RESOURCE_COUNT = new AlertType((short)22, "ALERT.RESOURCE.COUNT", true);
64-
public static final AlertType ALERT_TYPE_USAGE_SANITY_RESULT = new AlertType((short)23, "ALERT.USAGE.SANITY", true);
65-
public static final AlertType ALERT_TYPE_DIRECT_ATTACHED_PUBLIC_IP = new AlertType((short)24, "ALERT.NETWORK.DIRECTPUBLICIP", true);
66-
public static final AlertType ALERT_TYPE_LOCAL_STORAGE = new AlertType((short)25, "ALERT.STORAGE.LOCAL", true);
67-
public static final AlertType ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED = new AlertType((short)26, "ALERT.RESOURCE.EXCEED", true);
68-
public static final AlertType ALERT_TYPE_SYNC = new AlertType((short)27, "ALERT.TYPE.SYNC", true);
69-
public static final AlertType ALERT_TYPE_UPLOAD_FAILED = new AlertType((short)28, "ALERT.UPLOAD.FAILED", true);
70-
public static final AlertType ALERT_TYPE_OOBM_AUTH_ERROR = new AlertType((short)29, "ALERT.OOBM.AUTHERROR", true);
71-
public static final AlertType ALERT_TYPE_HA_ACTION = new AlertType((short)30, "ALERT.HA.ACTION", true);
72-
public static final AlertType ALERT_TYPE_CA_CERT = new AlertType((short)31, "ALERT.CA.CERT", true);
73-
public static final AlertType ALERT_TYPE_VM_SNAPSHOT = new AlertType((short)32, "ALERT.VM.SNAPSHOT", true);
74-
public static final AlertType ALERT_TYPE_VR_PUBLIC_IFACE_MTU = new AlertType((short)32, "ALERT.VR.PUBLIC.IFACE.MTU", true);
75-
public static final AlertType ALERT_TYPE_VR_PRIVATE_IFACE_MTU = new AlertType((short)32, "ALERT.VR.PRIVATE.IFACE.MTU", true);
76-
public static final AlertType ALERT_TYPE_EXTENSION_PATH_NOT_READY = new AlertType((short)33, "ALERT.TYPE.EXTENSION.PATH.NOT.READY", true);
50+
true, false);
51+
public static final AlertType ALERT_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET = new AlertType(Capacity.CAPACITY_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET, "ALERT.NETWORK.IPV6SUBNET", true, false);
52+
public static final AlertType ALERT_TYPE_PRIVATE_IP = new AlertType(Capacity.CAPACITY_TYPE_PRIVATE_IP, "ALERT.NETWORK.PRIVATEIP", true, false);
53+
public static final AlertType ALERT_TYPE_SECONDARY_STORAGE = new AlertType(Capacity.CAPACITY_TYPE_SECONDARY_STORAGE, "ALERT.STORAGE.SECONDARY", true, false);
54+
public static final AlertType ALERT_TYPE_HOST = new AlertType((short)7, "ALERT.COMPUTE.HOST", true, true);
55+
public static final AlertType ALERT_TYPE_USERVM = new AlertType((short)8, "ALERT.USERVM", true, true);
56+
public static final AlertType ALERT_TYPE_DOMAIN_ROUTER = new AlertType((short)9, "ALERT.SERVICE.DOMAINROUTER", true, true);
57+
public static final AlertType ALERT_TYPE_CONSOLE_PROXY = new AlertType((short)10, "ALERT.SERVICE.CONSOLEPROXY", true, true);
58+
public static final AlertType ALERT_TYPE_ROUTING = new AlertType((short)11, "ALERT.NETWORK.ROUTING", true, false);
59+
public static final AlertType ALERT_TYPE_STORAGE_MISC = new AlertType((short)12, "ALERT.STORAGE.MISC", true, true);
60+
public static final AlertType ALERT_TYPE_USAGE_SERVER = new AlertType((short)13, "ALERT.USAGE", true, false);
61+
public static final AlertType ALERT_TYPE_MANAGEMENT_NODE = new AlertType((short)14, "ALERT.MANAGEMENT", true, true);
62+
public static final AlertType ALERT_TYPE_DOMAIN_ROUTER_MIGRATE = new AlertType((short)15, "ALERT.NETWORK.DOMAINROUTERMIGRATE", true, false);
63+
public static final AlertType ALERT_TYPE_CONSOLE_PROXY_MIGRATE = new AlertType((short)16, "ALERT.SERVICE.CONSOLEPROXYMIGRATE", true, false);
64+
public static final AlertType ALERT_TYPE_USERVM_MIGRATE = new AlertType((short)17, "ALERT.USERVM.MIGRATE", true, false);
65+
public static final AlertType ALERT_TYPE_VLAN = new AlertType((short)18, "ALERT.NETWORK.VLAN", true, false);
66+
public static final AlertType ALERT_TYPE_SSVM = new AlertType((short)19, "ALERT.SERVICE.SSVM", true, true);
67+
public static final AlertType ALERT_TYPE_USAGE_SERVER_RESULT = new AlertType((short)20, "ALERT.USAGE.RESULT", true, false);
68+
public static final AlertType ALERT_TYPE_STORAGE_DELETE = new AlertType((short)21, "ALERT.STORAGE.DELETE", true, false);
69+
public static final AlertType ALERT_TYPE_UPDATE_RESOURCE_COUNT = new AlertType((short)22, "ALERT.RESOURCE.COUNT", true, false);
70+
public static final AlertType ALERT_TYPE_USAGE_SANITY_RESULT = new AlertType((short)23, "ALERT.USAGE.SANITY", true, false);
71+
public static final AlertType ALERT_TYPE_DIRECT_ATTACHED_PUBLIC_IP = new AlertType((short)24, "ALERT.NETWORK.DIRECTPUBLICIP", true, false);
72+
public static final AlertType ALERT_TYPE_LOCAL_STORAGE = new AlertType((short)25, "ALERT.STORAGE.LOCAL", true, false);
73+
public static final AlertType ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED = new AlertType((short)26, "ALERT.RESOURCE.EXCEED", true, true);
74+
public static final AlertType ALERT_TYPE_SYNC = new AlertType((short)27, "ALERT.TYPE.SYNC", true, false);
75+
public static final AlertType ALERT_TYPE_UPLOAD_FAILED = new AlertType((short)28, "ALERT.UPLOAD.FAILED", true, true);
76+
public static final AlertType ALERT_TYPE_OOBM_AUTH_ERROR = new AlertType((short)29, "ALERT.OOBM.AUTHERROR", true, true);
77+
public static final AlertType ALERT_TYPE_HA_ACTION = new AlertType((short)30, "ALERT.HA.ACTION", true, true);
78+
public static final AlertType ALERT_TYPE_CA_CERT = new AlertType((short)31, "ALERT.CA.CERT", true, true);
79+
public static final AlertType ALERT_TYPE_VM_SNAPSHOT = new AlertType((short)32, "ALERT.VM.SNAPSHOT", true, false);
80+
public static final AlertType ALERT_TYPE_VR_PUBLIC_IFACE_MTU = new AlertType((short)32, "ALERT.VR.PUBLIC.IFACE.MTU", true, false);
81+
public static final AlertType ALERT_TYPE_VR_PRIVATE_IFACE_MTU = new AlertType((short)32, "ALERT.VR.PRIVATE.IFACE.MTU", true, false);
82+
public static final AlertType ALERT_TYPE_EXTENSION_PATH_NOT_READY = new AlertType((short)33, "ALERT.TYPE.EXTENSION.PATH.NOT.READY", true, true);
7783

7884
public short getType() {
7985
return type;
@@ -83,6 +89,10 @@ public String getName() {
8389
return name;
8490
}
8591

92+
public boolean isRepetitionAllowed() {
93+
return repetitionAllowed;
94+
}
95+
8696
private static AlertType getAlertType(short type) {
8797
for (AlertType alertType : defaultAlertTypes) {
8898
if (alertType.getType() == type) {
@@ -106,9 +116,13 @@ public static AlertType generateAlert(short type, String name) {
106116
if (defaultAlert != null && !defaultAlert.getName().equalsIgnoreCase(name)) {
107117
throw new InvalidParameterValueException("There is a default alert having type " + type + " and name " + defaultAlert.getName());
108118
} else {
109-
return new AlertType(type, name, false);
119+
return new AlertType(type, name, false, false);
110120
}
111121
}
122+
123+
public static AlertType getAlertTypeByName(String name) {
124+
return allAlertTypesMap.get(name);
125+
}
112126
}
113127

114128
boolean generateAlert(AlertType alertType, long dataCenterId, Long podId, String msg);

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ public class ApiConstants {
469469
public static final String RECONNECT = "reconnect";
470470
public static final String RECOVER = "recover";
471471
public static final String REPAIR = "repair";
472+
public static final String REPETITION_ALLOWED = "repetitionallowed";
472473
public static final String REQUIRES_HVM = "requireshvm";
473474
public static final String RESOURCES = "resources";
474475
public static final String RESOURCE_COUNT = "resourcecount";

api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListAlertTypesCmd.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.resource;
1818

19-
import com.cloud.user.Account;
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
import java.util.Set;
22+
2023
import org.apache.cloudstack.alert.AlertService;
2124
import org.apache.cloudstack.api.APICommand;
2225
import org.apache.cloudstack.api.BaseCmd;
2326
import org.apache.cloudstack.api.response.AlertResponse;
2427
import org.apache.cloudstack.api.response.AlertTypeResponse;
2528
import org.apache.cloudstack.api.response.ListResponse;
2629

27-
import java.util.ArrayList;
28-
import java.util.List;
29-
import java.util.Set;
30+
import com.cloud.user.Account;
3031

3132
@APICommand(name = "listAlertTypes", description = "Lists all alerts types", responseObject = AlertResponse.class,
3233
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@@ -43,7 +44,8 @@ public void execute() {
4344
ListResponse<AlertTypeResponse> response = new ListResponse<>();
4445
List<AlertTypeResponse> typeResponseList = new ArrayList<>();
4546
for (AlertService.AlertType alertType : result) {
46-
AlertTypeResponse alertResponse = new AlertTypeResponse(alertType.getType(), alertType.getName());
47+
AlertTypeResponse alertResponse = new AlertTypeResponse(alertType.getType(), alertType.getName(),
48+
alertType.isRepetitionAllowed());
4749
alertResponse.setObjectName("alerttype");
4850
typeResponseList.add(alertResponse);
4951
}

api/src/main/java/org/apache/cloudstack/api/response/AlertTypeResponse.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.response;
1818

19-
import com.cloud.serializer.Param;
20-
import com.google.gson.annotations.SerializedName;
2119
import org.apache.cloudstack.api.ApiConstants;
2220
import org.apache.cloudstack.api.BaseResponse;
2321

22+
import com.cloud.serializer.Param;
23+
import com.google.gson.annotations.SerializedName;
24+
2425
public class AlertTypeResponse extends BaseResponse {
2526

2627
@SerializedName("alerttypeid")
@@ -31,6 +32,10 @@ public class AlertTypeResponse extends BaseResponse {
3132
@Param(description = "description of alert type")
3233
private String name;
3334

35+
@SerializedName(ApiConstants.REPETITION_ALLOWED)
36+
@Param(description = "Whether repetitive alerts allowed for the alert type", since = "4.22.0")
37+
private boolean repetitionAllowed = true;
38+
3439
public String getName() {
3540
return name;
3641
}
@@ -47,9 +52,10 @@ public void setUsageType(short alertType) {
4752
this.alertType = alertType;
4853
}
4954

50-
public AlertTypeResponse(short alertType, String name) {
55+
public AlertTypeResponse(short alertType, String name, boolean repetitionAllowed) {
5156
this.alertType = alertType;
5257
this.name = name;
58+
this.repetitionAllowed = repetitionAllowed;
5359
setObjectName("alerttype");
5460
}
5561
}

engine/components-api/src/main/java/com/cloud/alert/AlertManager.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,36 @@
2323

2424
public interface AlertManager extends Manager, AlertService {
2525

26-
static final ConfigKey<Double> StorageCapacityThreshold = new ConfigKey<Double>(Double.class, "cluster.storage.capacity.notificationthreshold", "Alert", "0.75",
26+
ConfigKey<Double> StorageCapacityThreshold = new ConfigKey<Double>(Double.class, "cluster.storage.capacity.notificationthreshold", "Alert", "0.75",
2727
"Percentage (as a value between 0 and 1) of storage utilization above which alerts will be sent about low storage available.", true, ConfigKey.Scope.Cluster,
2828
null);
29-
static final ConfigKey<Double> CPUCapacityThreshold = new ConfigKey<Double>(Double.class, "cluster.cpu.allocated.capacity.notificationthreshold", "Alert", "0.75",
29+
ConfigKey<Double> CPUCapacityThreshold = new ConfigKey<Double>(Double.class, "cluster.cpu.allocated.capacity.notificationthreshold", "Alert", "0.75",
3030
"Percentage (as a value between 0 and 1) of cpu utilization above which alerts will be sent about low cpu available.", true, ConfigKey.Scope.Cluster, null);
31-
static final ConfigKey<Double> MemoryCapacityThreshold = new ConfigKey<Double>(Double.class, "cluster.memory.allocated.capacity.notificationthreshold", "Alert",
31+
ConfigKey<Double> MemoryCapacityThreshold = new ConfigKey<Double>(Double.class, "cluster.memory.allocated.capacity.notificationthreshold", "Alert",
3232
"0.75", "Percentage (as a value between 0 and 1) of memory utilization above which alerts will be sent about low memory available.", true,
3333
ConfigKey.Scope.Cluster, null);
34-
static final ConfigKey<Double> StorageAllocatedCapacityThreshold = new ConfigKey<Double>(Double.class, "cluster.storage.allocated.capacity.notificationthreshold",
34+
ConfigKey<Double> StorageAllocatedCapacityThreshold = new ConfigKey<Double>(Double.class, "cluster.storage.allocated.capacity.notificationthreshold",
3535
"Alert", "0.75", "Percentage (as a value between 0 and 1) of allocated storage utilization above which alerts will be sent about low storage available.", true,
3636
ConfigKey.Scope.Cluster, null);
3737

38-
public static final ConfigKey<Boolean> AlertSmtpUseStartTLS = new ConfigKey<Boolean>("Advanced", Boolean.class, "alert.smtp.useStartTLS", "false",
38+
ConfigKey<Boolean> AlertSmtpUseStartTLS = new ConfigKey<Boolean>("Advanced", Boolean.class, "alert.smtp.useStartTLS", "false",
3939
"If set to true and if we enable security via alert.smtp.useAuth, this will enable StartTLS to secure the connection.", true);
4040

41-
public static final ConfigKey<Boolean> AlertSmtpUseAuth = new ConfigKey<>(ConfigKey.CATEGORY_ALERT, Boolean.class, "alert.smtp.useAuth", "false", "If true, use SMTP authentication when sending emails.", false, ConfigKey.Scope.ManagementServer);
41+
ConfigKey<Boolean> AlertSmtpUseAuth = new ConfigKey<>(ConfigKey.CATEGORY_ALERT, Boolean.class, "alert.smtp.useAuth", "false", "If true, use SMTP authentication when sending emails.", false, ConfigKey.Scope.ManagementServer);
4242

43-
public static final ConfigKey<String> AlertSmtpEnabledSecurityProtocols = new ConfigKey<String>(ConfigKey.CATEGORY_ADVANCED, String.class, "alert.smtp.enabledSecurityProtocols", "",
43+
ConfigKey<String> AlertSmtpEnabledSecurityProtocols = new ConfigKey<String>(ConfigKey.CATEGORY_ADVANCED, String.class, "alert.smtp.enabledSecurityProtocols", "",
4444
"White-space separated security protocols; ex: \"TLSv1 TLSv1.1\". Supported protocols: SSLv2Hello, SSLv3, TLSv1, TLSv1.1 and TLSv1.2", true, ConfigKey.Kind.WhitespaceSeparatedListWithOptions, "SSLv2Hello,SSLv3,TLSv1,TLSv1.1,TLSv1.2");
4545

46-
public static final ConfigKey<Double> Ipv6SubnetCapacityThreshold = new ConfigKey<Double>("Advanced", Double.class,
46+
ConfigKey<Double> Ipv6SubnetCapacityThreshold = new ConfigKey<Double>("Advanced", Double.class,
4747
"zone.virtualnetwork.ipv6subnet.capacity.notificationthreshold",
4848
"0.75",
4949
"Percentage (as a value between 0 and 1) of guest network IPv6 subnet utilization above which alerts will be sent.",
5050
true);
5151

52+
ConfigKey<String> AllowedRepetitiveAlertTypes = new ConfigKey<>(ConfigKey.CATEGORY_ALERT, String.class,
53+
"alert.allowed.repetitive.types", "",
54+
"Comma-separated list of alert types (by name) that can be sent multiple times", true);
55+
5256
void clearAlert(AlertType alertType, long dataCenterId, long podId);
5357

5458
void recalculateCapacity();

0 commit comments

Comments
 (0)