use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class TestHelpers method createAdvisorAction.
public static Action createAdvisorAction(String accountId, String eventType) {
Action emailActionMessage = new Action();
emailActionMessage.setBundle("rhel");
emailActionMessage.setApplication("advisor");
emailActionMessage.setTimestamp(LocalDateTime.of(2020, 10, 3, 15, 22, 13, 25));
emailActionMessage.setEventType(eventType);
emailActionMessage.setAccountId(accountId);
if (eventType.equals("deactivated-recommendation")) {
emailActionMessage.setContext(new Context.ContextBuilder().build());
emailActionMessage.setEvents(List.of(new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("rule_id", "retire-rule1").withAdditionalProperty("rule_description", "Rule being deactivated for retirement").withAdditionalProperty("total_risk", "1").withAdditionalProperty("affected_systems", "1").withAdditionalProperty("deactivation_reason", "Retirement").build()).build(), new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("rule_id", "enhance-rule2").withAdditionalProperty("rule_description", "Rule being deactivated for enhancement").withAdditionalProperty("total_risk", "2").withAdditionalProperty("affected_systems", "2").withAdditionalProperty("deactivation_reason", "Enhancement").build()).build()));
} else {
emailActionMessage.setContext(new Context.ContextBuilder().withAdditionalProperty("inventory_id", "host-01").withAdditionalProperty("hostname", "my-host").withAdditionalProperty("display_name", "My Host").withAdditionalProperty("rhel_version", "8.3").withAdditionalProperty("host_url", "this-is-my-host-url").build());
emailActionMessage.setEvents(List.of(new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("rule_id", "rule-id-low-001").withAdditionalProperty("rule_description", "nice rule with low risk").withAdditionalProperty("total_risk", "1").withAdditionalProperty("publish_date", "2020-08-03T15:22:42.199046").withAdditionalProperty("report_url", "http://the-report-for-rule-id-low-001").withAdditionalProperty("rule_url", "http://the-rule-id-low-001").build()).build(), new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("rule_id", "rule-id-moderate-001").withAdditionalProperty("rule_description", "nice rule with moderate risk").withAdditionalProperty("total_risk", "2").withAdditionalProperty("publish_date", "2020-08-03T15:22:42.199046").withAdditionalProperty("report_url", "http://the-report-for-rule-id-moderate-001").withAdditionalProperty("rule_url", "http://the-rule-id-moderate-001").build()).build(), new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("rule_id", "rule-id-important-001").withAdditionalProperty("rule_description", "nice rule with important risk").withAdditionalProperty("total_risk", "3").withAdditionalProperty("publish_date", "2020-08-03T15:22:42.199046").withAdditionalProperty("report_url", "http://the-report-for-rule-id-important-001").withAdditionalProperty("rule_url", "http://the-rule-id-important-001").build()).build(), new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("rule_id", "rule-id-critical-001").withAdditionalProperty("rule_description", "nice rule with critical risk").withAdditionalProperty("total_risk", "4").withAdditionalProperty("publish_date", "2020-08-03T15:22:42.199046").withAdditionalProperty("report_url", "http://the-report-for-rule-id-critical-001").withAdditionalProperty("rule_url", "http://the-rule-id-critical-001").build()).build()));
}
return emailActionMessage;
}
use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class TestHelpers method createPoliciesAction.
public static Action createPoliciesAction(String accountId, String bundle, String application, String hostDisplayName) {
Action emailActionMessage = new Action();
emailActionMessage.setBundle(bundle);
emailActionMessage.setApplication(application);
emailActionMessage.setTimestamp(LocalDateTime.of(2020, 10, 3, 15, 22, 13, 25));
emailActionMessage.setEventType(eventType);
emailActionMessage.setRecipients(List.of());
emailActionMessage.setContext(new Context.ContextBuilder().withAdditionalProperty("inventory_id", "host-01").withAdditionalProperty("system_check_in", "2020-08-03T15:22:42.199046").withAdditionalProperty("display_name", hostDisplayName).withAdditionalProperty("tags", List.of()).build());
emailActionMessage.setEvents(List.of(new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("policy_id", policyId1).withAdditionalProperty("policy_name", policyName1).withAdditionalProperty("policy_description", "not-used-desc").withAdditionalProperty("policy_condition", "not-used-condition").build()).build(), new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("policy_id", policyId2).withAdditionalProperty("policy_name", policyName2).withAdditionalProperty("policy_description", "not-used-desc").withAdditionalProperty("policy_condition", "not-used-condition").build()).build()));
emailActionMessage.setAccountId(accountId);
return emailActionMessage;
}
use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class BaseTransformer method toJsonObject.
protected JsonObject toJsonObject(Action action) {
JsonObject message = new JsonObject();
message.put("bundle", action.getBundle());
message.put("application", action.getApplication());
message.put("event_type", action.getEventType());
message.put("account_id", action.getAccountId());
message.put("timestamp", action.getTimestamp().toString());
message.put("events", new JsonArray(action.getEvents().stream().map(event -> Map.of("metadata", JsonObject.mapFrom(event.getMetadata()), "payload", JsonObject.mapFrom(event.getPayload()))).collect(Collectors.toList())));
message.put("context", JsonObject.mapFrom(action.getContext()));
return message;
}
use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class ComplianceTestHelpers method createEmailAggregation.
public static EmailAggregation createEmailAggregation(String tenant, String bundle, String application, String eventType, String policyId, String inventoryId) {
EmailAggregation aggregation = new EmailAggregation();
aggregation.setBundleName(bundle);
aggregation.setApplicationName(application);
aggregation.setAccountId(tenant);
aggregation.setCreated(LocalDateTime.now(UTC).minusHours(5L));
Action emailActionMessage = new Action();
emailActionMessage.setBundle(bundle);
emailActionMessage.setApplication(application);
emailActionMessage.setTimestamp(LocalDateTime.now());
emailActionMessage.setEventType(eventType);
emailActionMessage.setContext(new Context.ContextBuilder().withAdditionalProperty("inventory_id", inventoryId).withAdditionalProperty("system_check_in", "2020-08-03T15:22:42.199046").withAdditionalProperty("display_name", "My test machine").withAdditionalProperty("tags", List.of()).build());
emailActionMessage.setEvents(List.of(new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("policy_id", policyId).withAdditionalProperty("policy_name", "not-tested-name").withAdditionalProperty("policy_description", "not-used-desc").withAdditionalProperty("policy_condition", "not-used-condition").build()).build()));
emailActionMessage.setAccountId(tenant);
JsonObject payload = baseTransformer.transform(emailActionMessage);
aggregation.setPayload(payload);
return aggregation;
}
use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class DriftTestHelpers method createEmailAggregation.
public static EmailAggregation createEmailAggregation(String tenant, String bundle, String application, String baselineId, String baselineName, String inventory_id, String inventory_name) {
EmailAggregation aggregation = new EmailAggregation();
aggregation.setBundleName(bundle);
aggregation.setApplicationName(application);
aggregation.setAccountId(tenant);
Action emailActionMessage = new Action();
emailActionMessage.setBundle(bundle);
emailActionMessage.setApplication(application);
emailActionMessage.setTimestamp(LocalDateTime.now());
emailActionMessage.setEventType("testEmailSubscriptionInstant");
emailActionMessage.setContext(new Context.ContextBuilder().withAdditionalProperty("inventory_id", inventory_id).withAdditionalProperty("system_check_in", "2021-07-13T15:22:42.199046").withAdditionalProperty("display_name", inventory_name).withAdditionalProperty("tags", List.of()).build());
emailActionMessage.setEvents(List.of(new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("baseline_id", baselineId).withAdditionalProperty("baseline_name", baselineName).build()).build()));
emailActionMessage.setAccountId(tenant);
JsonObject payload = baseTransformer.transform(emailActionMessage);
aggregation.setPayload(payload);
return aggregation;
}
Aggregations