Skip to content

Commit 541fa7f

Browse files
author
Daman Arora
committed
Add rule owner account and domain to resource alert email and event bus messages
1 parent 4574edd commit 541fa7f

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎plugins/resource-alerts/src/main/java/org/apache/cloudstack/resourcealert/ResourceAlertManagerImpl.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656

5757
import com.cloud.cluster.ManagementServerHostVO;
5858
import com.cloud.cluster.dao.ManagementServerHostDao;
59+
import com.cloud.domain.DomainVO;
5960
import com.cloud.domain.dao.DomainDao;
6061
import com.cloud.event.AlertGenerator;
6162
import com.cloud.host.Host;
@@ -72,6 +73,7 @@
7273
import com.cloud.storage.dao.VolumeDao;
7374
import com.cloud.tags.dao.ResourceTagDao;
7475
import com.cloud.user.Account;
76+
import com.cloud.user.AccountVO;
7577
import com.cloud.user.dao.AccountDao;
7678
import com.cloud.utils.Pair;
7779
import com.cloud.utils.component.ComponentContext;
@@ -547,6 +549,14 @@ private String buildSubject(ResourceAlertRuleVO rule, Pair<String, String> resou
547549
private String buildBody(ResourceAlertRuleVO rule, Pair<String, String> resource, double value) {
548550
StringBuilder sb = new StringBuilder();
549551
sb.append("Rule: ").append(rule.getName()).append('\n');
552+
AccountVO owner = accountDao.findByIdIncludingRemoved(rule.getAccountId());
553+
if (owner != null) {
554+
sb.append("Account: ").append(owner.getAccountName()).append('\n');
555+
}
556+
DomainVO domain = domainDao.findByIdIncludingRemoved(rule.getDomainId());
557+
if (domain != null) {
558+
sb.append("Domain: ").append(domain.getPath()).append('\n');
559+
}
550560
sb.append("Resource Type: ").append(rule.getResourceType().name()).append('\n');
551561
if (resource != null) {
552562
sb.append("Resource: ").append(StringUtils.defaultString(resource.second())).append('\n');

‎plugins/resource-alerts/src/test/java/org/apache/cloudstack/resourcealert/ResourceAlertManagerImplTest.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767
import com.cloud.cluster.ManagementServerHostVO;
6868
import com.cloud.cluster.dao.ManagementServerHostDao;
69+
import com.cloud.domain.DomainVO;
6970
import com.cloud.domain.dao.DomainDao;
7071
import com.cloud.host.HostStats;
7172
import com.cloud.host.HostVO;
@@ -478,6 +479,12 @@ public void testSubjectContainsKeyAlertFields() throws Exception {
478479
when(vm.getUuid()).thenReturn("vm-uuid");
479480
when(vm.getDisplayName()).thenReturn("web-01");
480481
when(userVmDao.findByIdIncludingRemoved(VM_ID)).thenReturn(vm);
482+
AccountVO account = mock(AccountVO.class);
483+
when(account.getAccountName()).thenReturn("acme");
484+
when(accountDao.findByIdIncludingRemoved(1L)).thenReturn(account);
485+
DomainVO domain = mock(DomainVO.class);
486+
when(domain.getPath()).thenReturn("/acme/");
487+
when(domainDao.findByIdIncludingRemoved(1L)).thenReturn(domain);
481488

482489
manager.evaluateRules();
483490

@@ -490,6 +497,8 @@ public void testSubjectContainsKeyAlertFields() throws Exception {
490497
assertTrue(subject.contains("VirtualMachine web-01"));
491498
assertTrue(body.contains("Resource: web-01"));
492499
assertTrue(body.contains("Resource ID: vm-uuid"));
500+
assertTrue(body.contains("Account: acme"));
501+
assertTrue(body.contains("Domain: /acme/"));
493502
}
494503

495504
@Test

0 commit comments

Comments
 (0)