Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@
<artifactId>cloud-mom-webhook</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-resource-alerts</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-framework-agent-lb</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,46 @@ WHERE rule = 'quotaStatement' AND NOT EXISTS(SELECT 1 FROM cloud.role_permission

-- Add description for secondary IP addresses
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.nic_secondary_ips', 'description', 'VARCHAR(2048) DEFAULT NULL');

-- resource_alert_rules: stores per-resource or generic metric threshold rules
CREATE TABLE IF NOT EXISTS `cloud`.`resource_alert_rules` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`uuid` varchar(255) NOT NULL UNIQUE,
`name` varchar(255) NOT NULL,
`resource_type` varchar(64) NOT NULL COMMENT 'VirtualMachine, Volume, Host, StoragePool',
`resource_id` bigint unsigned DEFAULT NULL COMMENT 'null = applies to all resources of the type in scope',
`account_id` bigint unsigned NOT NULL,
`domain_id` bigint unsigned NOT NULL,
`metric` varchar(64) NOT NULL,
`condition_operator` varchar(8) NOT NULL COMMENT 'GT, GTE, LT, LTE, EQ',
`threshold` double NOT NULL,
`severity` varchar(32) NOT NULL COMMENT 'CRITICAL, HIGH, MEDIUM, LOW',
`message` varchar(4096) DEFAULT NULL,
`email` tinyint(1) NOT NULL DEFAULT 0,
`reset_interval` int unsigned NOT NULL DEFAULT 600 COMMENT 'minimum seconds between repeat firings of this rule',
`created` datetime DEFAULT NULL,
`updated` datetime DEFAULT NULL,
`removed` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `i_resource_alert_rules__account_id`(`account_id`),
INDEX `i_resource_alert_rules__domain_id`(`domain_id`),
CONSTRAINT `fk_resource_alert_rules__account_id` FOREIGN KEY (`account_id`) REFERENCES `account`(`id`) ON DELETE CASCADE,
CONSTRAINT `fk_resource_alert_rules__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- resource_alerts: immutable log of fired alerts
CREATE TABLE IF NOT EXISTS `cloud`.`resource_alerts` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`uuid` varchar(255) NOT NULL UNIQUE,
`alert_rule_id` bigint unsigned NOT NULL,
`resource_id` bigint unsigned DEFAULT NULL COMMENT 'the specific resource that triggered the alert',
`metric_type` varchar(64) NOT NULL,
`metric_value` double NOT NULL,
`severity` varchar(32) NOT NULL,
`message` varchar(4096) DEFAULT NULL,
`alert_timestamp` datetime NOT NULL,
PRIMARY KEY (`id`),
INDEX `i_resource_alerts__alert_rule_id`(`alert_rule_id`),
INDEX `i_resource_alerts__alert_timestamp`(`alert_timestamp`),
CONSTRAINT `fk_resource_alerts__alert_rule_id` FOREIGN KEY (`alert_rule_id`) REFERENCES `resource_alert_rules`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied. See the License for the
-- specific language governing permissions and limitations
-- under the License.

-- VIEW `cloud`.`resource_alert_rule_view`;

DROP VIEW IF EXISTS `cloud`.`resource_alert_rule_view`;
CREATE VIEW `cloud`.`resource_alert_rule_view` AS
SELECT
r.id,
r.uuid,
r.name,
r.resource_type,
r.resource_id,
r.metric,
r.condition_operator,
r.threshold,
r.severity,
r.message,
r.email,
r.reset_interval,
r.created,
r.updated,
r.removed,
a.id account_id,
a.uuid account_uuid,
a.account_name,
a.type account_type,
d.id domain_id,
d.uuid domain_uuid,
d.name domain_name,
d.path domain_path
FROM `cloud`.`resource_alert_rules` r
INNER JOIN `cloud`.`account` a ON r.account_id = a.id
INNER JOIN `cloud`.`domain` d ON r.domain_id = d.id;
2 changes: 2 additions & 0 deletions plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@

<module>metrics</module>

<module>resource-alerts</module>

<module>network-elements/bigswitch</module>
<module>network-elements/dns-notifier</module>
<module>network-elements/elastic-loadbalancer</module>
Expand Down
37 changes: 37 additions & 0 deletions plugins/resource-alerts/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-plugin-resource-alerts</artifactId>
<name>Apache CloudStack Plugin - Resource Alerts</name>
<parent>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloudstack-plugins</artifactId>
<version>4.23.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-engine-schema</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.cloudstack.resourcealert;

public enum AlertCondition {
GT, GTE, LT, LTE, EQ;

public boolean evaluate(double value, double threshold) {
switch (this) {
case GT: return value > threshold;
case GTE: return value >= threshold;
case LT: return value < threshold;
case LTE: return value <= threshold;
case EQ: return Double.compare(value, threshold) == 0;
default: return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.cloudstack.resourcealert;

public enum AlertSeverity {
CRITICAL, HIGH, MEDIUM, LOW
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.cloudstack.resourcealert;

import java.util.Date;

import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;

public interface ResourceAlert extends Identity, InternalIdentity {

long getAlertRuleId();
Long getResourceId();
String getMetricType();
double getMetricValue();
AlertSeverity getSeverity();
String getMessage();
Date getAlertTimestamp();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.cloudstack.resourcealert;

public interface ResourceAlertManager {
void evaluateRules();
}
Loading
Loading