Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
hapi-statsd
Advanced tools
A hapi plugin for sending request round trip metrics to statsd, also exposing statsd client to the server.
This module makes use of a Makefile
for building/testing purposes. After obtaining a copy of the repo, run the following commands to make sure everything is in working condition before you start your work:
make install
make test
Before committing a change to your fork/branch, run the following commands to make sure nothing is broken:
make test
make test-cov
Don't forget to bump the version in the package.json
using the semver spec as a guide for which part to bump. Submit a pull request when your work is complete.
Notes:
npm install hapi-statsd
To install this plugin on your Hapi server, do something similar to this:
var Hapi = require('@hapi/hapi');
var server = new Hapi.Server();
var hapiStatsdConfig = {};
server.register({ register: require('hapi-statsd'), options: hapiStatsdConfig }, function(err) {
if (err) {
console.log('error', 'Failed loading plugin: hapi-statsd');
}
});
template
A template to use for the stat names to send to statsd. This can be any string that could include the following tokens that get replaced with their actual values:
{path}
- the path that the request was routed to (e.g '/users/{id}'
){method}
- the HTTP verb used on the request (e.g. 'GET'
){statusCode}
- the numerical status code of the response that the server sent back to the client (e.g. 200
)Defaults to '{path}.{method}.{statusCode}'
statsdClient
An instance of a particular statsd client that you prefer to use for sending metrics to statsd. If this is used, then the statsdHost
and prefix
options are ignored. Defaults to null
host
The host athat an instance of statsd is running on. An instance of the statsd-client
NPM module will be created and will be configured to use this host. Defaults to 'localhost'
port
The port that an instance of statsd is listening on. An instance of the statsd-client
NPM module will be created and will be configured to use this port. Defaults to 8125
prefix
The prefix to add to every stat collected. Usually used for grouping a set of stats under one hierarchy in graphite. Defaults to 'hapi'
pathSeparator
A character or set of characters to replace the '/' (forward slash) characters in your URL path since forward slashes cannot be used in stat names. Defaults to '_'
defaultFilter
Defines whether increment and timer stats are turned on by default. Defaults to { enableCounter: true, enableTimer: true }
.
filters
An array of custom filters. A successful match requires one of these fields to be defined and match the route:
id
: The route id defined in the route's configpath
: The path defined in the routemethod
: The HTTP method of the request/routestatus
: The returned HTTP status code of the responseParameters that are not included are considered wildcard and will match all values. Note that if none of these parameters are included in the filter, then you will get a match on ALL route-response combinations.
In addition to matching, the field can contain the following configuration options:
Example configuration:
defaultFilter: { // by default, enable timer and disable counter stats
enableCounter: false,
enableTimer: true,
}
filters: [
{ path: '/', enableCounter: true }, // enable counters (keep timers on as well) for this path
{ path: '/test/{param}', enableCounter: true }, // path with a parameter
{ path: '/rename', name: 'rename_stat' }, // rename the metric
{ id: 'match-my-id', enableCounter: true, enableTimer: true }, // match by route id
{ status: 407, name: 'match_on_status', enableCounter: true, enableTimer: true }, // match by status code
]
A Hapi route configured like this:
server.route({
method: 'GET',
path: '/test/{param}',
handler: function(request, reply) {
reply('Success!');
}
});
would send an increment and timing stat to statsd with the following stat name (assuming all options are set to their defaults):
hapi.test_{param}.GET.200
As the statsd client is also exposed to the hapi server, you can use any of its methods, e.g.:
server.statsd.increment('systemname.subsystem.value');
server.statsd.gauge('what.you.gauge', 100);
server.statsd.set('your.set', 200);
The MIT License (MIT)
Copyright (c) 2013 Mac Angell
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
A hapi plugin for sending request round trip metrics to statsd
The npm package hapi-statsd receives a total of 123 weekly downloads. As such, hapi-statsd popularity was classified as not popular.
We found that hapi-statsd demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.