use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class TestHelpers method createAdvisorOpenshiftAction.
public static Action createAdvisorOpenshiftAction(String accountId, String eventType) {
Action emailActionMessage = new Action();
emailActionMessage.setBundle("openshift");
emailActionMessage.setApplication("advisor");
emailActionMessage.setTimestamp(LocalDateTime.of(2021, 5, 20, 15, 22, 13, 25));
emailActionMessage.setEventType(eventType);
emailActionMessage.setAccountId(accountId);
if (eventType.equals("new-recommendation")) {
emailActionMessage.setContext(new Context.ContextBuilder().withAdditionalProperty("display_name", "some-cluster-name").withAdditionalProperty("host_url", "some-ocm-url-to-the-cluster").build());
emailActionMessage.setEvents(List.of(new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("rule_description", "nice rule with low risk").withAdditionalProperty("total_risk", "1").withAdditionalProperty("publish_date", "2020-08-03T15:22:42.199046").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_description", "nice rule with moderate risk").withAdditionalProperty("total_risk", "2").withAdditionalProperty("publish_date", "2020-08-03T15:22:42.199046").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_description", "nice rule with important risk").withAdditionalProperty("total_risk", "3").withAdditionalProperty("publish_date", "2020-08-03T15:22:42.199046").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_description", "nice rule with critical risk").withAdditionalProperty("total_risk", "4").withAdditionalProperty("publish_date", "2020-08-03T15:22:42.199046").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 createEmailAggregation.
public static EmailAggregation createEmailAggregation(String tenant, String bundle, String application, String policyId, String inventory_id) {
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(eventType);
emailActionMessage.setContext(new Context.ContextBuilder().withAdditionalProperty("inventory_id", inventory_id).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 VulnerabilityTestHelpers method createEmailAggregation.
public static EmailAggregation createEmailAggregation(String tenant, String bundle, String application, String eventType, String cve) {
EmailAggregation aggregation = new EmailAggregation();
aggregation.setAccountId(tenant);
aggregation.setBundleName(bundle);
aggregation.setApplicationName(application);
Action emailActionMessage = new Action();
emailActionMessage.setAccountId(tenant);
emailActionMessage.setApplication(application);
emailActionMessage.setBundle(bundle);
emailActionMessage.setTimestamp(LocalDateTime.now());
emailActionMessage.setEventType(eventType);
emailActionMessage.setEvents(List.of(new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("reported_cve", cve).build()).build()));
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 TemplateEngineResource method render.
@PUT
@Path("/render")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public Response render(@NotNull @Valid RenderEmailTemplateRequest renderEmailTemplateRequest) {
User user = createInternalUser();
String payload = renderEmailTemplateRequest.getPayload();
try {
Action action = actionParser.fromJsonString(payload);
TemplateInstance subjectTemplate = templateService.compileTemplate(renderEmailTemplateRequest.getSubjectTemplate(), "subject");
String subject = templateService.renderTemplate(user, action, subjectTemplate);
TemplateInstance bodyTemplate = templateService.compileTemplate(renderEmailTemplateRequest.getBodyTemplate(), "body");
String body = templateService.renderTemplate(user, action, bodyTemplate);
return Response.ok(new RenderEmailTemplateResponse.Success(subject, body)).build();
} catch (Exception e) {
return Response.status(Response.Status.BAD_REQUEST).entity(new RenderEmailTemplateResponse.Error(e.getMessage())).build();
}
}
use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class DriftTestHelpers method createDriftAction.
public static Action createDriftAction(String tenant, String bundle, String application, String inventory_id, String inventory_name) {
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", "baseline_01").withAdditionalProperty("baseline_name", "Baseline 1").build()).build(), new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("baseline_id", "baseline_02").withAdditionalProperty("baseline_name", "Baseline 2").build()).build()));
emailActionMessage.setAccountId(tenant);
return emailActionMessage;
}
Aggregations