splunk-events
Advanced tools
Comparing version 1.0.1 to 1.1.1
{ | ||
"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 @@ { |
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
0
1
192
0
3
15044
4
225
- Removedaxios@^0.13.0
- Removeddebounce@^1.0.0
- Removedaxios@0.13.1(transitive)
- Removeddebounce@1.2.1(transitive)
- Removeddebug@2.6.9(transitive)
- Removedfollow-redirects@0.0.7(transitive)
- Removedms@2.0.0(transitive)
- Removedstream-consume@0.1.1(transitive)