From cb59201353750184132cb9b08dafc668215d4f7d Mon Sep 17 00:00:00 2001 From: Marc-Antoine Hinse Date: Wed, 20 Nov 2024 11:41:44 -0500 Subject: [PATCH] Trigger the cron job right after the first configuration --- .../main/resources/splunk/default/inputs.conf | 2 +- .../src/utils/setupConfiguration.ts | 46 +++++++++++++++---- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/packages/flare/src/main/resources/splunk/default/inputs.conf b/packages/flare/src/main/resources/splunk/default/inputs.conf index 1ba716d..b50d06f 100644 --- a/packages/flare/src/main/resources/splunk/default/inputs.conf +++ b/packages/flare/src/main/resources/splunk/default/inputs.conf @@ -1,5 +1,5 @@ [script://$SPLUNK_HOME/etc/apps/flare/bin/cron_job_ingest_events.py] -interval = * * * * * +interval = 600 python.version = python3 index = flare source = flare diff --git a/packages/react-components/src/utils/setupConfiguration.ts b/packages/react-components/src/utils/setupConfiguration.ts index bd5772a..ab359b1 100644 --- a/packages/react-components/src/utils/setupConfiguration.ts +++ b/packages/react-components/src/utils/setupConfiguration.ts @@ -114,8 +114,30 @@ async function saveConfiguration( `${isIngestingMetadataOnly}` ); await saveIndexForIngestion(service, indexName); + const isFirstConfiguration = await fetchIsFirstConfiguration(); + if (isFirstConfiguration) { + await updateEventIngestionCronJobInterval(service, 1); + } await completeSetup(service); await reloadApp(service); + if (isFirstConfiguration) { + await updateEventIngestionCronJobInterval(service, 60); + await reloadApp(service); + } +} + +async function updateEventIngestionCronJobInterval( + service: SplunkService, + intervalInSeconds: number +): Promise { + await updateConfigurationFile( + service, + 'inputs', + 'script://$SPLUNK_HOME/etc/apps/flare/bin/cron_job_ingest_events.py', + { + interval: `${intervalInSeconds}`, + } + ); } async function fetchCollectionItems(): Promise { @@ -178,15 +200,8 @@ async function fetchIngestMetadataOnly(): Promise { async function createFlareIndex(): Promise { const service = createService(); - const isConfigured = - (await getConfigurationStanzaValue( - service, - 'app', - 'install', - 'is_configured', - 'unknown' - )) === '1'; - if (!isConfigured) { + const isFirstConfiguration = await fetchIsFirstConfiguration(); + if (isFirstConfiguration) { const currentIndexNames = await fetchAvailableIndexNames(); if (!currentIndexNames.find((indexName) => indexName === appName)) { await service.indexes().create(appName, {}); @@ -218,6 +233,19 @@ async function fetchAvailableIndexNames(): Promise> { return indexNames; } +async function fetchIsFirstConfiguration(): Promise { + const service = createService(); + return ( + (await getConfigurationStanzaValue( + service, + 'app', + 'install', + 'is_configured', + 'unknown' + )) !== '1' + ); +} + async function fetchCurrentIndexName(): Promise { const service = createService(); return getConfigurationStanzaValue(