/** * Checks if multiple alerts of the same type for the same host are ignored if repeatable is set to {@code false} */ @Test public void testMultipleAlertsWithSameTypeAndHostAreIgnored() { AuditLog entry = new AuditLog(AuditLogType.VDS_ALERT_FENCE_DISABLED_BY_CLUSTER_POLICY, AuditLogSeverity.ALERT); entry.setVdsId(FixturesTool.VDS_RHEL6_NFS_SPM); entry.setVdsName(FixturesTool.GLUSTER_SERVER_NAME3); entry.setMessage("Testing alert"); // test if no alert of the same type for the same host exists assertEquals(0L, getAlertCount(entry, dao.getAll(null, false))); dao.save(entry); AuditLog savedAlert = dao.get(entry.getAuditLogId()); assertNotNull(savedAlert); // test if 1st alert was stored in db assertEquals(1L, getAlertCount(entry, dao.getAll(null, false))); // try to store 2nd alert in db entry.setLogTime(new Date()); dao.save(entry); savedAlert = dao.get(entry.getAuditLogId()); assertNotNull(savedAlert); // test if 2nd alert was ignored assertEquals(1L, getAlertCount(entry, dao.getAll(null, false))); }
Guid guid = GuidUtils.asGuid(event.getHost().getId()); if (!Guid.isNullOrEmpty(guid)) { auditLog.setVdsId(guid);
/** * Checks if multiple alerts of the same type for the same host are saved if repeatable is set to {@code true} */ @Test public void testMultipleAlertsWithSameTypeAndHostAreSavedIfRepeatableTrue() { AuditLog entry = new AuditLog(AuditLogType.VDS_ALERT_FENCE_DISABLED_BY_CLUSTER_POLICY, AuditLogSeverity.ALERT); entry.setVdsId(FixturesTool.VDS_RHEL6_NFS_SPM); entry.setVdsName(FixturesTool.GLUSTER_SERVER_NAME3); entry.setMessage("Testing alert"); entry.setRepeatable(true); // test if no alert of the same type for the same host exists assertEquals(0L, getAlertCount(entry, dao.getAll(null, false))); dao.save(entry); AuditLog savedAlert = dao.get(entry.getAuditLogId()); assertNotNull(savedAlert); // test if 1st alert was stored in db assertEquals(1L, getAlertCount(entry, dao.getAll(null, false))); // try to save 2nd alert entry.setLogTime(new Date()); dao.save(entry); savedAlert = dao.get(entry.getAuditLogId()); assertNotNull(savedAlert); // test if 2nd alert was also stored in db assertEquals(2L, getAlertCount(entry, dao.getAll(null, false))); }
@BeforeEach @Override public void setUp() throws Exception { super.setUp(); // create some test data newAuditLog = new AuditLog(); newAuditLog.setAuditLogId(44000); newAuditLog.setUserId(new Guid("9bf7c640-b620-456f-a550-0348f366544b")); newAuditLog.setUserName("userportal3"); newAuditLog.setVmId(VM_ID); newAuditLog.setVmName(VM_NAME); newAuditLog.setVmTemplateId(VM_TEMPLATE_ID); newAuditLog.setVmTemplateName(VM_TEMPLATE_NAME); newAuditLog.setVdsId(FixturesTool.VDS_RHEL6_NFS_SPM); newAuditLog.setVdsName(FixturesTool.GLUSTER_SERVER_NAME3); newAuditLog.setLogTime(EXPECTED_DATE_FORMAT.parse("2010-12-22 14:00:00")); newAuditLog.setLogType(AuditLogType.IRS_DISK_SPACE_LOW_ERROR); newAuditLog.setSeverity(AuditLogSeverity.ERROR); newAuditLog.setMessage("Critical, Low disk space. domain has 1 GB of free space"); newAuditLog.setStoragePoolId(FixturesTool.DATA_CENTER); newAuditLog.setStoragePoolName("rhel6.iscsi"); newAuditLog.setStorageDomainId(FixturesTool.STORAGE_DOMAIN_SCALE_SD5); newAuditLog.setStorageDomainName("fDMzhE-wx3s-zo3q-Qcxd-T0li-yoYU-QvVePk"); newAuditLog.setQuotaId(FixturesTool.DEFAULT_QUOTA_GENERAL); newAuditLog.setQuotaName("General Quota"); newAuditLog.setGlusterVolumeId(new Guid("0e0abdbc-2a0f-4df0-8b99-cc577a7a9bb5")); newAuditLog.setGlusterVolumeName("gluster_volume_name-1"); existingAuditLog = dao.get(EXISTING_ENTRY_ID); externalAuditLog = dao.get(EXTERNAL_ENTRY_ID); }