diff --git a/jobs/job-scheduler/src/main/java/com/paladincloud/jobscheduler/service/JobScheduler.java b/jobs/job-scheduler/src/main/java/com/paladincloud/jobscheduler/service/JobScheduler.java index 6fe44fa2d8..4fae2dab53 100644 --- a/jobs/job-scheduler/src/main/java/com/paladincloud/jobscheduler/service/JobScheduler.java +++ b/jobs/job-scheduler/src/main/java/com/paladincloud/jobscheduler/service/JobScheduler.java @@ -146,136 +146,6 @@ public void scheduleCollectorJobs() { eventBrClient.close(); } - @Scheduled(initialDelayString = "${scheduler.shipper.initial.delay}", fixedDelayString = "${scheduler.interval}") - public void scheduleShipperJobs() { - // print the current milliseconds - logger.info(CURRENT_MILLISECONDS, System.currentTimeMillis()); - logger.info("Job Scheduler for shipper is running..."); - - EventBridgeClient eventBrClient = getEventBridgeClient(); - List putEventsRequestEntries = new ArrayList<>(); - - try { - ConfigUtil.setConfigProperties(); - azureEnabled=Boolean.parseBoolean(System.getProperty(AZURE_ENABLED)); - awsEnabled=Boolean.parseBoolean(System.getProperty(AWS_ENABLED)); - if (awsEnabled) { - addShipperEvent(putEventsRequestEntries, awsBusDetails); - } - if (azureEnabled) { - addShipperEvent(putEventsRequestEntries, azureBusDetails); - } - - if (!putEventsRequestEntries.isEmpty()) { - PutEventsRequest eventsRequest = PutEventsRequest.builder().entries(putEventsRequestEntries).build(); - - PutEventsResponse result = eventBrClient.putEvents(eventsRequest); - - for (PutEventsResultEntry resultEntry : result.entries()) { - if (resultEntry.eventId() != null) { - logger.info(EVENT_ID, resultEntry.eventId()); - } else { - logger.info(FAILED_WITH_ERROR_CODE, resultEntry.errorCode()); - } - } - } - } catch (EventBridgeException e) { - logger.error(e.awsErrorDetails().errorMessage()); - System.exit(1); - } catch (Exception e) { - logger.error(e.getMessage()); - System.exit(1); - } - eventBrClient.close(); - } - - @Scheduled(initialDelayString = "${scheduler.rules.initial.delay}", fixedDelayString = "${scheduler.interval}") - public void scheduleRules() { - // print the current milliseconds - logger.info(CURRENT_MILLISECONDS, System.currentTimeMillis()); - logger.info("Job Scheduler for rules is running..."); - - EventBridgeClient eventBrClient = getEventBridgeClient(); - - // busdetails e.g- aws.eventbridge.bus.details=paladincloud-aws:aws:289 - // azure.eventbridge.bus.details=paladincloud-azure:azure:102 - // gcp.eventbridge.bus.details=paladincloud-gcp:gcp:30 - //For custom plugins like qualys, aqua, tenable- "plugin-saasdev-all-clouds:145", - - try { - int totBatches = Integer.parseInt(this.noOfBatches); - logger.info("No of batches: {}", noOfBatches); - - ConfigUtil.setConfigProperties(); - azureEnabled=Boolean.parseBoolean(System.getProperty(AZURE_ENABLED)); - gcpEnabled=Boolean.parseBoolean(System.getProperty(GCP_ENABLED)); - awsEnabled=Boolean.parseBoolean(System.getProperty(AWS_ENABLED)); - qualysEnabled=Boolean.parseBoolean(System.getProperty(QUALYS_ENABLED)); - aquaEnabled=Boolean.parseBoolean(System.getProperty(AQUA_ENABLED)); - tenableEnabled=Boolean.parseBoolean(System.getProperty(TENABLE_ENABLED)); - boolean contrastEnabled = Boolean.parseBoolean(System.getProperty(CONTRAST_ENABLED)); - - for (int i = 0; i < totBatches; i++) { - List putEventsRequestEntries = new ArrayList<>(); - // add event for aws rules - if (awsEnabled) { - putRuleEventIntoRequestEntry(i, awsBusDetails, putEventsRequestEntries); - } - - // add event for azure rules - if (azureEnabled) { - putRuleEventIntoRequestEntry(i, azureBusDetails, putEventsRequestEntries); - } - - // add event for gcp rules - if (gcpEnabled) { - putRuleEventIntoRequestEntry(i, gcpBusDetails, putEventsRequestEntries); - } - // add event for qualys policies - if (qualysEnabled) { - putPluginRuleRequestEntries(i, vulnerabilityBusDetails, putEventsRequestEntries, PLUGIN_TYPE_QUALYS); - } - - // add event for aqua policies - if (aquaEnabled) { - putPluginRuleRequestEntries(i, vulnerabilityBusDetails, putEventsRequestEntries, PLUGIN_TYPE_AQUA); - } - // add event for tenable policies - if (tenableEnabled) { - putPluginRuleRequestEntries(i, vulnerabilityBusDetails, putEventsRequestEntries, PLUGIN_TYPE_TENABLE); - } - // add event for contrast policies - if (contrastEnabled) { - putPluginRuleRequestEntriesForContrast(i, vulnerabilityBusDetails, putEventsRequestEntries); - } - if (!putEventsRequestEntries.isEmpty()) { - PutEventsRequest eventsRequest = PutEventsRequest.builder().entries(putEventsRequestEntries).build(); - PutEventsResponse result = eventBrClient.putEvents(eventsRequest); - - for (PutEventsResultEntry resultEntry : result.entries()) { - if (resultEntry.eventId() != null) { - logger.info(EVENT_ID, resultEntry.eventId()); - } else { - logger.info("Injection failed with Error Code: {}", resultEntry.errorCode()); - } - } - //Delay of 1 min between each batch - Thread.sleep(1000 * 60); - } - } - - } catch (EventBridgeException e) { - logger.error(e.awsErrorDetails().errorMessage()); - System.exit(1); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } catch (Exception e) { - logger.error(e.getMessage()); - System.exit(1); - } - eventBrClient.close(); - } - private void putPluginRuleRequestEntries(int batchNo, String busDetails, List reqEntryList, String pluginType) { String detailString = null; //plugin-saasdev-all-clouds:2 @@ -389,40 +259,9 @@ public void schedulePluginShipperJobs() { } eventBrClient.close(); } - private void putRuleEventIntoRequestEntry(int batchNo, String busDetails, List reqEntryList) { - String detailString = null; - String cloudName = busDetails.split(":")[0].split("-")[1]; - Event event = populateEventForRule(cloudName, batchNo); - detailString = getMarshalledEvent(detailString, event); - PutEventsRequestEntry reqEntry = PutEventsRequestEntry.builder().source(EVENT_SOURCE).detailType(EVENT_DETAIL_TYPE).detail(detailString).eventBusName(busDetails.split(":")[0]).build(); - // print the request entry - logger.info("Request entry: {} ", reqEntry); - - // Add the PutEventsRequestEntry to a putEventsRequestEntries - reqEntryList.add(reqEntry); - } - private void addShipperEvent(List putEventsRequestEntries, String busDetails) { - String detailString = null; - - // populate events for each event bus - String[] busDetailsArray = busDetails.split(","); - for (String busDetail : busDetailsArray) { - String cloudName = busDetail.split(":")[0].split("-")[1]; - Event event = populateEventForShipper(cloudName); - detailString = getMarshalledEvent(detailString, event); - PutEventsRequestEntry reqEntry = PutEventsRequestEntry.builder().source(EVENT_SOURCE).detailType(EVENT_DETAIL_TYPE).detail(detailString).eventBusName(busDetail.split(":")[0]).build(); - - // Add the PutEventsRequestEntry to a putEventsRequestEntries - putEventsRequestEntries.add(reqEntry); - - // print the request entry - logger.info(REQUEST_ENTRY, reqEntry); - - } - } private void addCollectorEvent(List putEventsRequestEntries, String busDetails) { String detailString = null;