Skip to content

Commit 4875ab5

Browse files
committed
Improve documentation & Add Elasticsearch
1 parent 1db84a4 commit 4875ab5

File tree

5 files changed

+109
-2
lines changed

5 files changed

+109
-2
lines changed

elasticsearch/nodejs/app.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const elasticsearch = require('elasticsearch');
2+
3+
const client = new elasticsearch.Client({
4+
host: [
5+
{
6+
host: 'XXXXXX.stackhero-network.com', // This is the host you'll find on Stackhero's console
7+
auth: 'admin:<yourPassword>', // This is the password you've defined on Stackhero's console
8+
protocol: 'https',
9+
port: 9200
10+
}
11+
],
12+
log: 'trace' // Enable debug logs
13+
});
14+
15+
(async () => {
16+
console.log('Try to ping Elasticsearch');
17+
await client.ping({ requestTimeout: 1000 });
18+
console.log('Ping is OK :)');
19+
20+
console.log('All done, your Elasticsearch is up and running :)');
21+
})();

elasticsearch/nodejs/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "nodejs",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"scripts": {
7+
"start": "node app.js"
8+
},
9+
"dependencies": {
10+
"elasticsearch": "^15.1.1"
11+
}
12+
}

graylog/nodejs/app.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const graylog2 = require('graylog2');
2+
const crypto = require('crypto');
3+
4+
const logger = new graylog2.graylog({
5+
servers: [{ 'host': '<yourEndpoint>.stackhero-network.com', port: 12201 }]
6+
});
7+
8+
9+
// Send a simple message to Graylog
10+
logger.log('Simple message example');
11+
12+
13+
// Attach datas to a message
14+
logger.log(
15+
'Password recovery email', // Message
16+
// A json with what you want in it
17+
{
18+
subject: 'Password recovery',
19+
language: 'en_US',
20+
domain: 'gmail.com'
21+
}
22+
);
23+
24+
25+
26+
// Advanced example
27+
const ip = '1.2.3.4';
28+
const ipHash = crypto.createHash('md5').update(ip).digest('hex');
29+
30+
const userId = '1234';
31+
const userIdHash = crypto.createHash('md5').update(userId).digest('hex');
32+
33+
logger.log(
34+
'API request', // Message
35+
// A json with what you want in it
36+
{
37+
route: '/v1/messages/1234/',
38+
method: 'POST',
39+
40+
reponseTime: 12, // ms
41+
reponseCode: 200,
42+
43+
ipHash,
44+
userIdHash
45+
}
46+
);
47+
48+
49+
50+
// Log your NodeJS uncaught errors
51+
process.on('uncaughtException', function(err) {
52+
logger.log(err, {
53+
type: 'uncaughtException'
54+
});
55+
}
56+
57+
58+
INPUT:
59+
GELF UDP

graylog/nodejs/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "nodejs",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"dependencies": {
7+
"graylog2": "0.2.1"
8+
},
9+
"scripts": {
10+
"start": "node app.js"
11+
}
12+
}

rethinkdb/nodejs/app.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
const r = require('rethinkdbdash')({
2-
host: 'XXXXXX.stackhero-network.com', // This is the host you'll find on Stackhero console
2+
host: 'XXXXXX.stackhero-network.com', // This is the host you'll find on Stackhero's console
33
port: 29015,
44
user: 'admin',
5-
password: 'XXXXXXXXXXXXX', // This is the admin password you've defined on Stackhero console
5+
password: 'XXXXXXXXXXXXX', // This is the RethinkDB admin password
6+
// Note: it's not the password you use to connect to the web interface!
7+
// If you haven't defined it yet, go to the web ui and define it like this:
8+
// r.db('rethinkdb').table('users').get('admin').update({ password: '<youSecuredPassword>' })
69
ssl: true,
710
silent: true
811
});

0 commit comments

Comments
 (0)