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 e61c918
Show file tree
Hide file tree
Showing 2 changed files with 35 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
43 changes: 34 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,27 @@ 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, 600);
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 +197,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 +230,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 e61c918

Please sign in to comment.