Skip to content

Commit

Permalink
Trigger the cron job right after the first configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-Antoine Hinse committed Nov 20, 2024
1 parent dafc78e commit cb59201
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
46 changes: 37 additions & 9 deletions packages/react-components/src/utils/setupConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
await updateConfigurationFile(
service,
'inputs',
'script://$SPLUNK_HOME/etc/apps/flare/bin/cron_job_ingest_events.py',
{
interval: `${intervalInSeconds}`,
}
);
}

async function fetchCollectionItems(): Promise<SplunkCollectionItem[]> {
Expand Down Expand Up @@ -178,15 +200,8 @@ async function fetchIngestMetadataOnly(): Promise<boolean> {

async function createFlareIndex(): Promise<void> {
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, {});
Expand Down Expand Up @@ -218,6 +233,19 @@ async function fetchAvailableIndexNames(): Promise<Array<string>> {
return indexNames;
}

async function fetchIsFirstConfiguration(): Promise<boolean> {
const service = createService();
return (
(await getConfigurationStanzaValue(
service,
'app',
'install',
'is_configured',
'unknown'
)) !== '1'
);
}

async function fetchCurrentIndexName(): Promise<string> {
const service = createService();
return getConfigurationStanzaValue(
Expand Down

0 comments on commit cb59201

Please sign in to comment.