Skip to content

Commit 0d52798

Browse files
authored
New Components - splunk_http_event_collector (#16058)
* new actions * new components * pnpm-lock.yaml * pnpm-lock.yaml * package.json * pnpm-lock.yaml * fix prop
1 parent 349720e commit 0d52798

File tree

7 files changed

+243
-8
lines changed

7 files changed

+243
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import splunk from "../../splunk_http_event_collector.app.mjs";
2+
3+
export default {
4+
key: "splunk_http_event_collector-check-health",
5+
name: "Check Splunk HTTP Event Collector Health",
6+
description: "Checks the health status of the Splunk HTTP Event Collector to ensure it is available and ready to receive events. [See the documentation](https://docs.splunk.com/Documentation/Splunk/8.2.0/RESTREF/RESTinput#services.2Fcollector.2Fhealth)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
splunk,
11+
},
12+
async run({ $ }) {
13+
try {
14+
const response = await this.splunk.checkHealth({
15+
$,
16+
});
17+
$.export("$summary", `Splunk HTTP Event Collector health status: "${response.text}"`);
18+
return response;
19+
} catch (error) {
20+
$.export("$summary", `Failed to check Splunk HTTP Event Collector health: ${error.message}`);
21+
throw new Error(`Health check failed: ${error.message}`);
22+
}
23+
},
24+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import splunk from "../../splunk_http_event_collector.app.mjs";
2+
import { parseJson } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "splunk_http_event_collector-send-batch-events",
6+
name: "Send Batch Events",
7+
description: "Sends multiple events in a single request to the Splunk HTTP Event Collector. [See the documentation](https://docs.splunk.com/Documentation/Splunk/8.2.0/RESTREF/RESTinput#services.2Fcollector.2Fraw)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
splunk,
12+
batchEvents: {
13+
type: "string[]",
14+
label: "Batch Events",
15+
description: "A batch of event data to send to Splunk",
16+
},
17+
channel: {
18+
propDefinition: [
19+
splunk,
20+
"channel",
21+
],
22+
},
23+
sourcetype: {
24+
propDefinition: [
25+
splunk,
26+
"sourcetype",
27+
],
28+
},
29+
index: {
30+
propDefinition: [
31+
splunk,
32+
"index",
33+
],
34+
},
35+
host: {
36+
propDefinition: [
37+
splunk,
38+
"host",
39+
],
40+
},
41+
},
42+
async run({ $ }) {
43+
const response = await this.splunk.sendMultipleEvents({
44+
$,
45+
params: {
46+
channel: this.channel,
47+
sourcetype: this.sourcetype,
48+
index: this.index,
49+
host: this.host,
50+
},
51+
data: parseJson(this.batchEvents),
52+
});
53+
54+
$.export("$summary", `Successfully sent ${this.batchEvents.length} events to Splunk.`);
55+
return response;
56+
},
57+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import splunk from "../../splunk_http_event_collector.app.mjs";
2+
import { parseJson } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "splunk_http_event_collector-send-event",
6+
name: "Send Event",
7+
description: "Sends an event to Splunk HTTP Event Collector. [See the documentation](https://docs.splunk.com/Documentation/Splunk/8.2.0/RESTREF/RESTinput#services.2Fcollector.2Fevent)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
splunk,
12+
eventData: {
13+
type: "string",
14+
label: "Event Data",
15+
description: "The event data to send to Splunk",
16+
},
17+
channel: {
18+
propDefinition: [
19+
splunk,
20+
"channel",
21+
],
22+
},
23+
sourcetype: {
24+
propDefinition: [
25+
splunk,
26+
"sourcetype",
27+
],
28+
},
29+
index: {
30+
propDefinition: [
31+
splunk,
32+
"index",
33+
],
34+
},
35+
host: {
36+
propDefinition: [
37+
splunk,
38+
"host",
39+
],
40+
},
41+
},
42+
async run({ $ }) {
43+
const response = await this.splunk.sendEvent({
44+
$,
45+
params: {
46+
channel: this.channel,
47+
},
48+
data: {
49+
event: parseJson(this.eventData),
50+
sourcetype: this.sourcetype,
51+
index: this.index,
52+
host: this.host,
53+
},
54+
});
55+
$.export("$summary", "Successfully sent event to Splunk HTTP Event Collector");
56+
return response;
57+
},
58+
};
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function parseJson(obj) {
2+
if (!obj) {
3+
return undefined;
4+
}
5+
6+
if (typeof obj === "string") {
7+
try {
8+
return JSON.parse(obj);
9+
} catch {
10+
return obj;
11+
}
12+
}
13+
14+
if (Array.isArray(obj)) {
15+
return obj.map((o) => {
16+
if (typeof o === "string") {
17+
try {
18+
return JSON.parse(o);
19+
} catch {
20+
return o;
21+
}
22+
}
23+
return o;
24+
});
25+
}
26+
27+
return obj;
28+
}
29+
30+
export {
31+
parseJson,
32+
};

Diff for: components/splunk_http_event_collector/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/splunk_http_event_collector",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Splunk HTTP Event Collector Components",
55
"main": "splunk_http_event_collector.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,68 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "splunk_http_event_collector",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
channel: {
8+
type: "string",
9+
label: "Channel",
10+
description: "Channel GUID to differentiate data from different clients",
11+
},
12+
sourcetype: {
13+
type: "string",
14+
label: "Sourcetype",
15+
description: "The sourcetype of the event",
16+
},
17+
index: {
18+
type: "string",
19+
label: "Index",
20+
description: "The index to send the event to",
21+
optional: true,
22+
},
23+
host: {
24+
type: "string",
25+
label: "Host",
26+
description: "The host sending the event",
27+
optional: true,
28+
},
29+
},
530
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
31+
_baseUrl() {
32+
return `${this.$auth.api_url}:${this.$auth.port}`;
33+
},
34+
_makeRequest({
35+
$ = this,
36+
path,
37+
...otherOpts
38+
}) {
39+
return axios($, {
40+
url: `${this._baseUrl()}${path}`,
41+
headers: {
42+
"Authorization": `Splunk ${this.$auth.api_token}`,
43+
},
44+
...otherOpts,
45+
});
46+
},
47+
checkHealth(opts = {}) {
48+
return this._makeRequest({
49+
path: "/services/collector/health",
50+
...opts,
51+
});
52+
},
53+
sendEvent(opts = {}) {
54+
return this._makeRequest({
55+
method: "POST",
56+
path: "/services/collector",
57+
...opts,
58+
});
59+
},
60+
sendMultipleEvents(opts = {}) {
61+
return this._makeRequest({
62+
method: "POST",
63+
path: "/services/collector/raw",
64+
...opts,
65+
});
966
},
1067
},
11-
};
68+
};

Diff for: pnpm-lock.yaml

+5-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)