Skip to content

Commit d0170bf

Browse files
committed
updates
1 parent cddbf57 commit d0170bf

File tree

5 files changed

+76
-54
lines changed

5 files changed

+76
-54
lines changed

components/splunk/actions/run-search/run-search.mjs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,19 @@ export default {
88
type: "action",
99
props: {
1010
splunk,
11-
query: {
11+
name: {
1212
propDefinition: [
1313
splunk,
14-
"query",
14+
"savedSearchName",
1515
],
1616
},
17-
earliestTime: {
18-
type: "string",
19-
label: "Earliest Time",
20-
description: "Specify a time string. Sets the earliest (inclusive), respectively, time bounds for the search. The time string can be either a UTC time (with fractional seconds), a relative time specifier (to now) or a formatted time string. Refer to [Time modifiers](https://docs.splunk.com/Documentation/Splunk/9.4.1/SearchReference/SearchTimeModifiers) for search for information and examples of specifying a time string.",
21-
optional: true,
22-
},
23-
latestTime: {
24-
type: "string",
25-
label: "Latest Time",
26-
description: " Specify a time string. Sets the latest (exclusive), respectively, time bounds for the search. The time string can be either a UTC time (with fractional seconds), a relative time specifier (to now) or a formatted time string. Refer to [Time modifiers](https://docs.splunk.com/Documentation/Splunk/9.4.1/SearchReference/SearchTimeModifiers) for search for information and examples of specifying a time string.",
27-
optional: true,
28-
},
2917
},
3018
async run({ $ }) {
3119
const response = await this.splunk.executeSearchQuery({
3220
$,
33-
data: {
34-
search: this.query,
35-
earliest_time: this.earliestTime,
36-
latest_time: this.latestTime,
37-
},
21+
name: this.name,
3822
});
39-
$.export("$summary", `Executed Splunk search query: ${this.query}`);
23+
$.export("$summary", `Executed Splunk search: ${this.name}`);
4024
return response;
4125
},
4226
};
Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
1-
import common from "../common/base.mjs";
1+
import splunk from "../../splunk.app.mjs";
2+
import sampleEmit from "./test-event.mjs";
23

34
export default {
4-
...common,
55
key: "splunk-new-alert-fired",
6-
name: "New Alert Fired",
6+
name: "New Alert Fired (Instant)",
77
description: "Emit new event when a new alert is triggered in Splunk. [See the documentation](https://docs.splunk.com/Documentation/Splunk/9.4.1/RESTREF/RESTsearch#alerts.2Ffired_alerts)",
88
version: "0.0.1",
99
type: "source",
1010
dedupe: "unique",
11+
props: {
12+
splunk,
13+
http: "$.interface.http",
14+
},
1115
methods: {
12-
...common.methods,
1316
generateMeta(alert) {
17+
const ts = +alert.result._time;
1418
return {
15-
id: alert.id,
16-
summary: `New Alert Fired: ${alert.name}`,
17-
ts: Date.now(),
19+
id: ts,
20+
summary: `New Alert Fired for Source: ${alert.result.source}`,
21+
ts,
1822
};
1923
},
2024
},
21-
async run() {
22-
const results = this.splunk.paginate({
23-
resourceFn: this.splunk.listFiredAlerts,
24-
});
25-
26-
const alerts = [];
27-
for await (const item of results) {
28-
alerts.push(item);
25+
async run(event) {
26+
const { body } = event;
27+
if (!body) {
28+
return;
2929
}
3030

31-
alerts.forEach((alert) => {
32-
const meta = this.generateMeta(alert);
33-
this.$emit(alert, meta);
34-
});
31+
const meta = this.generateMeta(body);
32+
this.$emit(body, meta);
3533
},
34+
sampleEmit,
3635
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export default {
2+
"sid": "",
3+
"search_name": "",
4+
"app": "search",
5+
"owner": "",
6+
"results_link": "https://splunk:8000/app/search/search?q=",
7+
"result": {
8+
"_confstr": "source::Source|host::44.210.81.125|webhook",
9+
"_eventtype_color": "",
10+
"_indextime": "1742843623",
11+
"_raw": "{ \"name\": \"test\", \"value\": \"test\" }",
12+
"_serial": "3",
13+
"_si": [
14+
"main"
15+
],
16+
"_sourcetype": "webhook",
17+
"_time": "1742843623",
18+
"eventtype": "",
19+
"host": "44.210.81.125",
20+
"index": "main",
21+
"linecount": "",
22+
"name": "test",
23+
"punct": "{_\"\":_\"_\",_\"\":_\"\"_}",
24+
"source": "Source",
25+
"sourcetype": "webhook",
26+
"splunk_server": "",
27+
"timestamp": "none",
28+
"value": "test"
29+
}
30+
}

components/splunk/sources/new-search-result/new-search-result.mjs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,37 @@ export default {
1010
dedupe: "unique",
1111
methods: {
1212
...common.methods,
13+
async getRecentJobs() {
14+
const jobs = [];
15+
const results = this.splunk.paginate({
16+
resourceFn: this.splunk.listJobs,
17+
});
18+
for await (const job of results) {
19+
jobs.push(job);
20+
}
21+
return jobs;
22+
},
1323
generateMeta(result) {
1424
return {
15-
id: result.sid,
16-
summary: `New Search Results with SID: ${result.sid}`,
25+
id: result.id,
26+
summary: `New Search with ID: ${result.id}`,
1727
ts: Date.now(),
1828
};
1929
},
2030
},
2131
async run() {
22-
const jobIds = await this.getRecentJobIds();
23-
const searchResults = [];
24-
for (const jobId of jobIds) {
25-
try {
26-
const response = await this.splunk.getSearchResults({
27-
jobId,
32+
const jobs = await this.getRecentJobs();
33+
for (const job of jobs) {
34+
if (job.content?.resultCount > 0) {
35+
const { results } = await this.splunk.getSearchResults({
36+
jobId: job.content.sid,
2837
});
29-
if (response?.results?.length) {
30-
searchResults.push(...response.results);
38+
if (results) {
39+
job.results = results;
3140
}
32-
} catch {
33-
console.log(`No results found for sid: ${jobId}`);
3441
}
3542
}
36-
searchResults.forEach((result) => {
43+
jobs.forEach((result) => {
3744
const meta = this.generateMeta(result);
3845
this.$emit(result, meta);
3946
});

components/splunk/splunk.app.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,12 @@ export default {
111111
...opts,
112112
});
113113
},
114-
executeSearchQuery(opts = {}) {
114+
executeSearchQuery({
115+
name, ...opts
116+
}) {
115117
return this._makeRequest({
116118
method: "POST",
117-
path: "/search/jobs",
119+
path: `/saved/searches/${name}/dispatch`,
118120
...opts,
119121
});
120122
},

0 commit comments

Comments
 (0)