Skip to content

New Components - splunk_http_event_collector #16058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import splunk from "../../splunk_http_event_collector.app.mjs";

export default {
key: "splunk_http_event_collector-check-health",
name: "Check Splunk HTTP Event Collector Health",
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)",
version: "0.0.1",
type: "action",
props: {
splunk,
},
async run({ $ }) {
try {
const response = await this.splunk.checkHealth({
$,
});
$.export("$summary", `Splunk HTTP Event Collector health status: "${response.text}"`);
return response;
} catch (error) {
$.export("$summary", `Failed to check Splunk HTTP Event Collector health: ${error.message}`);
throw new Error(`Health check failed: ${error.message}`);
}
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import splunk from "../../splunk_http_event_collector.app.mjs";
import { parseJson } from "../../common/utils.mjs";

export default {
key: "splunk_http_event_collector-send-batch-events",
name: "Send Batch Events",
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)",
version: "0.0.1",
type: "action",
props: {
splunk,
batchEvents: {
type: "string[]",
label: "Batch Events",
description: "A batch of event data to send to Splunk",
},
channel: {
propDefinition: [
splunk,
"channel",
],
},
sourcetype: {
propDefinition: [
splunk,
"sourcetype",
],
},
index: {
propDefinition: [
splunk,
"index",
],
},
host: {
propDefinition: [
splunk,
"host",
],
},
},
async run({ $ }) {
const response = await this.splunk.sendMultipleEvents({
$,
params: {
channel: this.channel,
sourcetype: this.sourcetype,
index: this.index,
host: this.host,
},
data: parseJson(this.batchEvents),
});

$.export("$summary", `Successfully sent ${this.batchEvents.length} events to Splunk.`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import splunk from "../../splunk_http_event_collector.app.mjs";
import { parseJson } from "../../common/utils.mjs";

export default {
key: "splunk_http_event_collector-send-event",
name: "Send Event",
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)",
version: "0.0.1",
type: "action",
props: {
splunk,
eventData: {
type: "string",
label: "Event Data",
description: "The event data to send to Splunk",
},
channel: {
propDefinition: [
splunk,
"channel",
],
},
sourcetype: {
propDefinition: [
splunk,
"sourcetype",
],
},
index: {
propDefinition: [
splunk,
"index",
],
},
host: {
propDefinition: [
splunk,
"host",
],
},
},
async run({ $ }) {
const response = await this.splunk.sendEvent({
$,
params: {
channel: this.channel,
},
data: {
event: parseJson(this.eventData),
sourcetype: this.sourcetype,
index: this.index,
host: this.host,
},
});
$.export("$summary", "Successfully sent event to Splunk HTTP Event Collector");
return response;
},
};
32 changes: 32 additions & 0 deletions components/splunk_http_event_collector/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function parseJson(obj) {
if (!obj) {
return undefined;
}

if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch {
return obj;
}
}

if (Array.isArray(obj)) {
return obj.map((o) => {
if (typeof o === "string") {
try {
return JSON.parse(o);
} catch {
return o;
}
}
return o;
});
}

return obj;
}

export {
parseJson,
};
7 changes: 5 additions & 2 deletions components/splunk_http_event_collector/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/splunk_http_event_collector",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Splunk HTTP Event Collector Components",
"main": "splunk_http_event_collector.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,68 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "splunk_http_event_collector",
propDefinitions: {},
propDefinitions: {
channel: {
type: "string",
label: "Channel",
description: "Channel GUID to differentiate data from different clients",
},
sourcetype: {
type: "string",
label: "Sourcetype",
description: "The sourcetype of the event",
},
index: {
type: "string",
label: "Index",
description: "The index to send the event to",
optional: true,
},
host: {
type: "string",
label: "Host",
description: "The host sending the event",
optional: true,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return `${this.$auth.api_url}:${this.$auth.port}`;
},
_makeRequest({
$ = this,
path,
...otherOpts
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
headers: {
"Authorization": `Splunk ${this.$auth.api_token}`,
},
...otherOpts,
});
},
checkHealth(opts = {}) {
return this._makeRequest({
path: "/services/collector/health",
...opts,
});
},
sendEvent(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/services/collector",
...opts,
});
},
sendMultipleEvents(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/services/collector/raw",
...opts,
});
},
},
};
};
8 changes: 7 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading