Search in sources :

Example 41 with Action

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;
}
Also used : Context(com.redhat.cloud.notifications.ingress.Context) Action(com.redhat.cloud.notifications.ingress.Action) Event(com.redhat.cloud.notifications.ingress.Event) Payload(com.redhat.cloud.notifications.ingress.Payload)

Example 42 with Action

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;
}
Also used : Action(com.redhat.cloud.notifications.ingress.Action) Event(com.redhat.cloud.notifications.ingress.Event) Payload(com.redhat.cloud.notifications.ingress.Payload)

Example 43 with Action

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;
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonArray(io.vertx.core.json.JsonArray) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Action(com.redhat.cloud.notifications.ingress.Action) Collectors(java.util.stream.Collectors) JsonObject(io.vertx.core.json.JsonObject)

Example 44 with Action

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;
}
Also used : Action(com.redhat.cloud.notifications.ingress.Action) Event(com.redhat.cloud.notifications.ingress.Event) JsonObject(io.vertx.core.json.JsonObject) Payload(com.redhat.cloud.notifications.ingress.Payload) EmailAggregation(com.redhat.cloud.notifications.models.EmailAggregation)

Example 45 with Action

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;
}
Also used : Action(com.redhat.cloud.notifications.ingress.Action) Event(com.redhat.cloud.notifications.ingress.Event) JsonObject(io.vertx.core.json.JsonObject) Payload(com.redhat.cloud.notifications.ingress.Payload) EmailAggregation(com.redhat.cloud.notifications.models.EmailAggregation)

Aggregations

Action (com.redhat.cloud.notifications.ingress.Action)49 Test (org.junit.jupiter.api.Test)22 QuarkusTest (io.quarkus.test.junit.QuarkusTest)20 Payload (com.redhat.cloud.notifications.ingress.Payload)19 JsonObject (io.vertx.core.json.JsonObject)17 Event (com.redhat.cloud.notifications.ingress.Event)15 Context (com.redhat.cloud.notifications.ingress.Context)14 EmailAggregation (com.redhat.cloud.notifications.models.EmailAggregation)12 Event (com.redhat.cloud.notifications.models.Event)12 TestHelpers.serializeAction (com.redhat.cloud.notifications.TestHelpers.serializeAction)9 Endpoint (com.redhat.cloud.notifications.models.Endpoint)8 EventType (com.redhat.cloud.notifications.models.EventType)7 NotificationHistory (com.redhat.cloud.notifications.models.NotificationHistory)7 LocalDateTime (java.time.LocalDateTime)7 JsonArray (io.vertx.core.json.JsonArray)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Inject (javax.inject.Inject)6 TemplateInstance (io.quarkus.qute.TemplateInstance)5 MockServerLifecycleManager (com.redhat.cloud.notifications.MockServerLifecycleManager)4