Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

splunk-events

Package Overview
Dependencies
Maintainers
5
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

splunk-events - npm Package Compare versions

Comparing version 1.0.1 to 1.1.1

6

package.json
{
"name": "splunk-events",
"version": "1.0.1",
"version": "1.1.1",
"description": "Javascript lib to create Splunk Logs via HTTP",

@@ -20,6 +20,2 @@ "main": "SplunkEvents.js",

},
"dependencies": {
"axios": "^0.13.0",
"debounce": "^1.0.0"
},
"contributors": [

@@ -26,0 +22,0 @@ {

89

README.md

@@ -8,3 +8,3 @@ # Splunk Events

- Node
- Node (with axios as dependency)
- Browser (IE8+, Firefox, Chrome, Safari and Opera)

@@ -23,3 +23,3 @@

let splunkEvents = new SplunkEvents();
const splunkEvents = new SplunkEvents();

@@ -31,5 +31,5 @@ splunkEvents.config({

splunkEvents.logEvent(
'Critical',
'Info',
'WeaponConstruction',
'Critical',
'Info',
'WeaponConstruction',
'DeathStar'

@@ -53,5 +53,5 @@ { username: 'vader'}

splunkEvents.logEvent(
'Critical',
'Info',
'WeaponConstruction',
'Critical',
'Info',
'WeaponConstruction',
'DeathStar'

@@ -74,10 +74,10 @@ { username: 'vader'}

token: 'YOUR_TOKEN',
// Optional. Index created in Splunk. The 'token' option already associates the index info.
// Optional. Index created in Splunk. The 'token' option already associates the index info.
// This option is useful when the token have multiple indexes.
index: 'YOUR_INDEX',
// Optional. Unique identifier in your system used to associate the events with the device
host: 'YOUR_HOST',
// A debounced function will automatically flush your events after some time

@@ -91,15 +91,18 @@ autoFlush: true, //default

debounceTime: 2000, //default
// Max time to wait until flush events. Requires 'autoFlush' option.
debounceMaxWait: 5000 //default
// If the request fail, retry to send events using the debounced flush function
// Fetcher to do Splunk Events requests
request: function with axios signature that uses global Fetch API by default // default (see more details below)
// If the request fail, retry to send events using the debounced flush function
autoRetryFlush: true, //default
// Splunk's default path
path: '/services/collector/event', //default
// Important steps will be logged in the console
debug: false, //default
// Source of the logs

@@ -141,5 +144,55 @@ source: 'splunkeventsjs', //default

#### Working on Node and old browsers
By default this lib doesn't have any dependencies for the newer browsers (it tries to use Fetch API)
But to make it work on old browsers and Node you must use axios (0.13+) as a dependency by installing it (```npm install --save axios```) and setting it on Splunk events config:
```javascript
import SplunkEvents from 'splunk-events';
import axios from 'axios';
const splunkEvents = new SplunkEvents();
splunkEvents.config({
token: 'YOUR_TOKEN_HERE', // required
request: axios, // this make it work on old browsers and node environments
});
```
You can also write your own fetcher to choose your own dependencies for doing the requests (see the next section).
#### Write your own fetcher
Just like you can pass axios as a request config (see section above), you can write your own fetcher by just following the same signature that axios use (see axios API documentation: https://github.com/mzabriskie/axios#axios-api).
The following example is how to make the node-fetch (https://github.com/bitinn/node-fetch) module work with axios signature:
```javascript
import SplunkEvents from 'splunk-events';
import fetch from 'node-fetch';
function nodeFetchRequest(context) {
return fetch(context.url, {
...context,
body: context.data
})
.then((response) => {
if (context.responseType === 'json') {
return response.json();
}
return response;
});
}
const splunkEvents = new SplunkEvents();
splunkEvents.config({
token: 'YOUR_TOKEN_HERE', // required
request: nodeFetchRequest,
});
```
-------
### Splunk Documentation
http://dev.splunk.com/view/event-collector/SP-CAAAE6P

@@ -11,14 +11,70 @@ 'use strict';

var _debounce = require('debounce');
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _debounce2 = _interopRequireDefault(_debounce);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _axios = require('axios');
// debounce helper
var _axios2 = _interopRequireDefault(_axios);
function debounce(func, wait, immediate) {
var timeout, args, context, timestamp, result;
if (wait == null) wait = 100;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function later() {
var last = Date.now() - timestamp;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
if (last < wait && last >= 0) {
timeout = setTimeout(later, wait - last);
} else {
timeout = null;
if (!immediate) {
result = func.apply(context, args);
context = args = null;
}
}
};
var debounced = function debounced() {
context = this;
args = arguments;
timestamp = Date.now();
var callNow = immediate && !timeout;
if (!timeout) timeout = setTimeout(later, wait);
if (callNow) {
result = func.apply(context, args);
context = args = null;
}
return result;
};
debounced.clear = function () {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
};
return debounced;
}
// fetch helper
function fetchRequest(context) {
if (typeof window !== 'undefined' && typeof window.fetch !== 'function' || typeof global !== 'undefined' && typeof global.fetch !== 'function') {
console.log('Error, using fetchRequest without fetch object');
return null;
}
return fetch(context.url, _extends({}, context, {
body: context.data
})).then(function (response) {
if (context.responseType === 'json') {
return response.json();
}
return response;
});
}
// splunk class
var SplunkEvents = function () {

@@ -45,11 +101,7 @@ function SplunkEvents() {

this.debounceTime = _config.debounceTime !== undefined ? _config.debounceTime : 2000;
this.debouncedFlush = (0, _debounce2.default)(this.flush, this.debounceTime);
this.axiosInstance = _axios2.default.create({
baseURL: '' + this.endpoint,
headers: {
'Authorization': 'Splunk ' + this.token
},
responseType: 'json'
});
this.debouncedFlush = debounce(this.flush, this.debounceTime);
this.request = _config.request !== undefined ? _config.request : fetchRequest;
this.headers = {
'Authorization': 'Splunk ' + this.token
};
}

@@ -147,3 +199,9 @@ }, {

this.axiosInstance.post(this.path, splunkBatchedFormattedEvents).then(function (response) {
this.request({
url: '' + this.endpoint + this.path,
method: 'POST',
data: splunkBatchedFormattedEvents,
headers: this.headers,
responseType: 'json'
}).then(function (response) {
if (_this.debug) {

@@ -150,0 +208,0 @@ console.log(_this.pendingEvents.length + ' events successfuly sent to splunk');

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc