npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@teragrep/rlp_02

v1.1.1-rc1

Published

Client Library that implements the RELP protocol

Downloads

7

Readme

Teragrep Logo


RLP-02

rlp_02 minimal implementation of the RELP protocol using NodeJS. This embraces similar implementation of his big brother RLP-01 java library.

  • [Java implementation] (https://github.com/teragrep/rlp_01 "RLP-01 Java Library")

Specs

[Specs Link] (https://github.com/rsyslog/librelp/blob/master/doc/relp.html "RELP Protocol Specifications")


Install

npm install @teragrep/rlp_02

Importing modules

Supporting from version "@teragrep/rlp_02": "^1.0.19-rc12"


const { RelpConnection, RelpBatch, RelpRequest, RelpBatch, RelpWindow } = require('@teragrep/rlp_02')

Test

The Maven build executes the test goal. Karma is a testing harness that is configured to jasmine framework.

Example Relp Connection and Commit configuration


// Load the required modules

var config = require('dotenv');
const RelpConnection = require("../../main/js/RelpConnection")
const async = require('async');
const RelpRequest = require('../../main/js/RelpRequest');
const RelpBatch = require('../../main/js/RelpBatch');
const RelpWindow = require('../../main/js/RelpWindow');



// Syslog message for the RelpServer
let data = Buffer.from('<34>1 2003-10-11T22:14:15.003Z mymachine.example.com su - ID47 - su root failed for lonvick on /dev/pts/8\n', 'ascii'); 
let invalidData = Buffer.from('<344565>5 2003-08-24T05:14:15.000000003-07:00 mymachine.example.com su - ID47 - su root failed for lonvick on /dev/pts/8\n', 'ascii'); // This contains the invalid PRI value
let sampleData  = Buffer.from('<165>1 2003-10-11T22:14:15.003Z mymachine.example.comevntslog - ID47 [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"] BOMAn applicationevent log entry...\n','ascii');


// Set up the connection and commit  messages. adjust the port according to the needs.

let relpConnection = new RelpConnection();
let host = '127.0.0.1';
let port = 1337; 
let cfePort = 1601;

// Configure the connection
async function connect() {
		let conn = await relpConnection.connect(cfePort, host);	
		return conn;
}


async function disconnect(state) {
	if(state){
		 await relpConnection.disconnect();
	}
	else {
		console.log('Check the connection...')
	}
	
}


function commit(){

    return new Promise(async(resolve, reject) => {

    let relpBatch = new RelpBatch();
    relpBatch.insert(data);
    relpBatch.insert(data);
    relpBatch.insert(data);
    relpBatch.insert(data);
    console.log(relpBatch);

    let resWindow = await relpConnection.commit(relpBatch);
    console.log('After Batch-1 Completion....', resWindow)
    
    
    let notSent = (resWindow === true) ? true : false; //Test purpose 
          
           //a commit promise to return rsp for each of the msgs that are in the batch or fail the commit promise.

           while(notSent){           
            
            let res = await relpBatch.verifyTransactionAllPromise();  //                             
            if(res){
                notSent = false;
                console.log('VerifyTransactionAllPromise......', res);
                resolve(true);
            }
            else{
                reject(false);
            }                              
           }    

    let relpBatch2 = new RelpBatch();
    
    relpBatch2.insert(data2);
    relpBatch2.insert(invalidData); 
    relpBatch2.insert(data2);
    relpBatch2.insert(invalidData);
    relpBatch2.insert(data2);
    relpBatch2.insert(invalidData);
    relpBatch2.insert(data2);
    relpBatch2.insert(invalidData);
    //relpBatch2.insert(sampleData);

    // Commit the messages
    relpConnection.commit(relpBatch2);
    return resolve(true);
    })  
}


/** 
 * Using async module which provides straight-foreward, powerful  functions for working with asynchronus style.
 * As waterfall method takes the previous task output as the input for the next task,
 * thus need to feed the connection state for the disconnection.
 * 
*/


async.waterfall(
    [
		function init(setConnect) {
            setConnect(null, cfePort, host)
        },
		connect,
        commit,
        disconnect

    ],
    function (err) {
        if(err) {
            console.log(err);
        }
        else {
            console.log('No Error')
        }
    }
);

Usage of our RLP_02 RelpConnection with RLO_08 component


/*
* Note: This is ONLY shown the part of necessary code snippets. 
* In this demo, we use Relp Logging Out component generates the Syslog message, 
* then using RLP_02 component to setup the connection to our Java-Relp-Server-Demo 
* application. 
*/
let relpConnection;
const host = 'localhost';
const port = 1601;

/*
* Setup the relp connection to the Java-Relp-Demo application
* which in this use case configure to running on port 1601
*/
async function setupConnection(port, host){
    return new Promise(async (resolve, reject) => {
      relpConnection = new RelpConnection();
      let conn = await relpConnection.connect(port, host);	
      console.log('Connectig...',host,' at PORT ', port)
      resolve(relpConnection)
    })
}

/*
* This ensures to confirm the connection on the request, setup the relpconnection 
* 
*/
server.on("request", async(req, res) => {
    await setupConnection(port, host) // 
    if(req.url == '/'){
        return getHome(req, res)
    }
    else if(req.url == "/ua"){
        return getUA(req, res)
    }
})
/*
* Endpoint for access to the generated response with user agent and syslog message 
*/
async function getUA(req, res){

    const userAgent = req.headers['user-agent']
    const ip = req.headers['x-real-ip'] || req.headers['x-forwarded-for'] || req.connection.remoteAddres || req.socket.remoteAddress || '';
  
    // Set response header
    res.writeHead(200, { 'Content-Type': 'text/html' }); 
    const dateTimestamp = '2014-07-24T17:57:36+03:00';
    const timestamp = (new Date(dateTimestamp)).getTime();
          
    let message = new SyslogMessage.Builder()
            .withAppName('bulk-data-sorted') //valid
            .withHostname(ip) 
            .withFacility(Facility.LOCAL0)
            .withSeverity(Severity.INFORMATIONAL)
            .withProcId('8740') 
            .withMsgId('ID47')
            .withMsg(userAgent) 
            .withSDElement(new SDElement("exampleSDID@32473", new SDParam("iut", "3"), new SDParam("eventSource", "Application")))  
            .withDebug(true)
            .build()
  
    let rfc5424message;
        rfc5424message = await message.toRfc5424SyslogMessage();
        res.writeHead(200, { 'Content-Type': 'text/html' });
        res.write(rfc5424message.toString(), 'utf-8', async() => {
            await commit(rfc5424message)
        });
        res.end(); //end the response
}
/*
* Using the established relp connection commit the messages.
*/
async function commit(msg){
    return new Promise(async(resolve, reject) => {
      let relpBatch = new RelpBatch();
      relpBatch.insert(msg);
      
      let resWindow = await relpConnection.commit(relpBatch);
      console.log('After Batch-1 Completion....', resWindow)
      
      let notSent = (resWindow === true) ? true : false; //Test purpose 
      while(notSent){                          
        let res = await relpBatch.verifyTransactionAllPromise();                              
        if(res){
            notSent = false;
            console.log('VerifyTransactionAllPromise......', res);
            resolve(true);
            }
        else{
          reject(false);
            }                            
      }    
     return resolve(true);
    }) 
}

TODO

  • Handling Socket timeout
  • Error Management