Skip to content

Commit

Permalink
Merge pull request #54 from Flared/mahinse/run_cron_job_post_configur…
Browse files Browse the repository at this point in the history
…ation

Trigger the cron job right after the first configuration
  • Loading branch information
TyMarc authored Nov 20, 2024
2 parents 2621d6c + af22b0a commit 9524b14
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 = 0 0 1 1 *
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 @@ -117,13 +117,35 @@ async function saveConfiguration(
`${isIngestingMetadataOnly}`
);
await saveIndexForIngestion(service, indexName);
const isFirstConfiguration = await fetchIsFirstConfiguration();
if (isFirstConfiguration) {
await updateEventIngestionCronJobInterval(service, '1');
}
await updateSavedSearchQuery(
service,
flareSavedSearchName,
`source=${appName} index=${indexName}`
);
await completeSetup(service);
await reloadApp(service);
if (isFirstConfiguration) {
await updateEventIngestionCronJobInterval(service, '* * * * *');
await reloadApp(service);
}
}

async function updateEventIngestionCronJobInterval(
service: SplunkService,
interval: string
): Promise<void> {
await updateConfigurationFile(
service,
'inputs',
'script://$SPLUNK_HOME/etc/apps/flare/bin/cron_job_ingest_events.py',
{
interval: `${interval}`,
}
);
}

async function updateSavedSearchQuery(
Expand Down Expand Up @@ -200,15 +222,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 @@ -240,6 +255,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 9524b14

Please sign in to comment.