{"id":26233965,"url":"https://github.com/teragrep/rlp_02","last_synced_at":"2025-03-13T01:18:19.045Z","repository":{"id":45234863,"uuid":"421720437","full_name":"teragrep/rlp_02","owner":"teragrep","description":"Teragrep RELP client for JavaScript","archived":false,"fork":false,"pushed_at":"2024-09-05T11:42:41.000Z","size":249,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-02T05:50:01.841Z","etag":null,"topics":["javascript","nodejs","relp","relp-client","syslog","syslog-client","teragrep"],"latest_commit_sha":null,"homepage":"https://teragrep.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/teragrep.png","metadata":{"files":{"readme":"readme.adoc","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-10-27T07:34:13.000Z","updated_at":"2025-02-04T12:20:42.000Z","dependencies_parsed_at":"2024-01-09T10:33:21.388Z","dependency_job_id":"75b057bf-fcc9-4381-b440-61fb0113fc2a","html_url":"https://github.com/teragrep/rlp_02","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teragrep%2Frlp_02","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teragrep%2Frlp_02/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teragrep%2Frlp_02/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teragrep%2Frlp_02/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teragrep","download_url":"https://codeload.github.com/teragrep/rlp_02/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243318776,"owners_count":20272145,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","nodejs","relp","relp-client","syslog","syslog-client","teragrep"],"created_at":"2025-03-13T01:18:18.495Z","updated_at":"2025-03-13T01:18:19.035Z","avatar_url":"https://github.com/teragrep.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"image::https://avatars.githubusercontent.com/u/71876378?s=200\u0026v=4[Teragrep Logo]\n\nimage::https://scan.coverity.com/projects/24236/badge.svg[Coverity Scan Build Status, link=\"https://scan.coverity.com/projects/teragrep-rlp_02\"]\n\n= RLP_02\n\nrlp_02 minimal implementation of the RELP protocol using NodeJS.\nThis embraces similar implementation of his big brother RLP-01 java library.\n\n* https://github.com/teragrep/rlp_01[Java implementation]\n\n== Specs\n\nhttps://github.com/rsyslog/librelp/blob/master/doc/relp.html[Specs Link] \n\n== Documentation\n \nSee the official documentation on https://docs.teragrep.com[docs.teragrep.com].\n\n== Install\n\n[source,npm]\n----\nnpm install @teragrep/rlp_02\n----\n\n== Importing modules\n\nSupporting from version \"@teragrep/rlp_02\": \"^1.0.19-rc12\"\n\n[source,javascript]\n----\nconst { RelpConnection, RelpBatch, RelpRequest, RelpBatch, RelpWindow } = require('@teragrep/rlp_02')\n----\n\n== Test\n\nThe Maven build executes the test goal. Karma is a testing harness that is configured to jasmine framework. \n\nJasmine async works completely control the asynchronus behaviour.\n\n== Example Relp Connection and Commit configuration\n\n[source,javascript] \n----\n// Load the required modules\n\nvar config = require('dotenv');\nconst RelpConnection = require(\"../../main/js/RelpConnection\")\nconst async = require('async');\nconst RelpRequest = require('../../main/js/RelpRequest');\nconst RelpBatch = require('../../main/js/RelpBatch');\nconst RelpWindow = require('../../main/js/RelpWindow');\n\n\n\n// Syslog message for the RelpServer\nlet data = Buffer.from('\u003c34\u003e1 2003-10-11T22:14:15.003Z mymachine.example.com su - ID47 - su root failed for lonvick on /dev/pts/8\\n', 'ascii'); \nlet invalidData = Buffer.from('\u003c344565\u003e5 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\nlet sampleData  = Buffer.from('\u003c165\u003e1 2003-10-11T22:14:15.003Z mymachine.example.comevntslog - ID47 [exampleSDID@32473 iut=\"3\" eventSource=\"Application\" eventID=\"1011\"] BOMAn applicationevent log entry...\\n','ascii');\n\n\n// Set up the connection and commit  messages. adjust the port according to the needs.\n\nlet relpConnection = new RelpConnection();\nlet host = '127.0.0.1';\nlet port = 1337; \nlet cfePort = 1601;\n\n// Configure the connection\nasync function connect() {\n\t\tlet conn = await relpConnection.connect(cfePort, host);\t\n\t\treturn conn;\n}\n\n\nasync function disconnect(state) {\n\tif(state){\n\t\t await relpConnection.disconnect();\n\t}\n\telse {\n\t\tconsole.log('Check the connection...')\n\t}\n\t\n}\n/**\n * Jasmine async works handles the asynchronus execution \n * */\nbeforeEach(async function() {\n    let conn = await connect();\n    await commit(conn)\n    await disconnect()\n})\n\n\n\nfunction commit(){\n\n    return new Promise(async(resolve, reject) =\u003e {\n\n    let relpBatch = new RelpBatch();\n    relpBatch.insert(data);\n    relpBatch.insert(data);\n    relpBatch.insert(data);\n    relpBatch.insert(data);\n    console.log(relpBatch);\n\n    let resWindow = await relpConnection.commit(relpBatch);\n    console.log('After Batch-1 Completion....', resWindow)\n    \n    \n    let notSent = (resWindow === true) ? true : false; //Test purpose \n          \n           //a commit promise to return rsp for each of the msgs that are in the batch or fail the commit promise.\n\n           while(notSent){           \n            \n            let res = await relpBatch.verifyTransactionAllPromise();  //                             \n            if(res){\n                notSent = false;\n                console.log('VerifyTransactionAllPromise......', res);\n                resolve(true);\n            }\n            else{\n                reject(false);\n            }                              \n           }    \n\n    let relpBatch2 = new RelpBatch();\n    \n    relpBatch2.insert(data2);\n    relpBatch2.insert(invalidData); \n    relpBatch2.insert(data2);\n    relpBatch2.insert(invalidData);\n    relpBatch2.insert(data2);\n    relpBatch2.insert(invalidData);\n    relpBatch2.insert(data2);\n    relpBatch2.insert(invalidData);\n    //relpBatch2.insert(sampleData);\n\n    // Commit the messages\n    relpConnection.commit(relpBatch2);\n    return resolve(true);\n    })  \n}\n----\n\n== Usage of our RLP_02 RelpConnection with RLO_08 component\n\n[source,javascript] \n----\n/*\n* Note: This is ONLY shown the part of necessary code snippets. \n* In this demo, we use Relp Logging Out component generates the Syslog message, \n* then using RLP_02 component to setup the connection to our Java-Relp-Server-Demo \n* application. \n*/\nlet relpConnection;\nconst host = 'localhost';\nconst port = 1601;\n\n/*\n* Setup the relp connection to the Java-Relp-Demo application\n* which in this use case configure to running on port 1601\n*/\nasync function setupConnection(port, host){\n    return new Promise(async (resolve, reject) =\u003e {\n      relpConnection = new RelpConnection();\n      let conn = await relpConnection.connect(port, host);\t\n      console.log('Connectig...',host,' at PORT ', port)\n      resolve(relpConnection)\n    })\n}\n\n/*\n* This ensures to confirm the connection on the request, setup the relpconnection \n* \n*/\nserver.on(\"request\", async(req, res) =\u003e {\n    await setupConnection(port, host) // \n    if(req.url == '/'){\n        return getHome(req, res)\n    }\n    else if(req.url == \"/ua\"){\n        return getUA(req, res)\n    }\n})\n/*\n* Endpoint for access to the generated response with user agent and syslog message \n*/\nasync function getUA(req, res){\n\n    const userAgent = req.headers['user-agent']\n    const ip = req.headers['x-real-ip'] || req.headers['x-forwarded-for'] || req.connection.remoteAddres || req.socket.remoteAddress || '';\n  \n    // Set response header\n    res.writeHead(200, { 'Content-Type': 'text/html' }); \n    const dateTimestamp = '2014-07-24T17:57:36+03:00';\n    const timestamp = (new Date(dateTimestamp)).getTime();\n          \n    let message = new SyslogMessage.Builder()\n            .withAppName('bulk-data-sorted') //valid\n            .withHostname(ip) \n            .withFacility(Facility.LOCAL0)\n            .withSeverity(Severity.INFORMATIONAL)\n            .withProcId('8740') \n            .withMsgId('ID47')\n            .withMsg(userAgent) \n            .withSDElement(new SDElement(\"exampleSDID@32473\", new SDParam(\"iut\", \"3\"), new SDParam(\"eventSource\", \"Application\")))  \n            .withDebug(true)\n            .build()\n  \n    let rfc5424message;\n        rfc5424message = await message.toRfc5424SyslogMessage();\n        res.writeHead(200, { 'Content-Type': 'text/html' });\n        res.write(rfc5424message.toString(), 'utf-8', async() =\u003e {\n            await commit(rfc5424message)\n        });\n        res.end(); //end the response\n}\n/*\n* Using the established relp connection commit the messages.\n*/\nasync function commit(msg){\n    return new Promise(async(resolve, reject) =\u003e {\n      let relpBatch = new RelpBatch();\n      relpBatch.insert(msg);\n      \n      let resWindow = await relpConnection.commit(relpBatch);\n      console.log('After Batch-1 Completion....', resWindow)\n      \n      let notSent = (resWindow === true) ? true : false; //Test purpose \n      while(notSent){                          \n        let res = await relpBatch.verifyTransactionAllPromise();                              \n        if(res){\n            notSent = false;\n            console.log('VerifyTransactionAllPromise......', res);\n            resolve(true);\n            }\n        else{\n          reject(false);\n            }                            \n      }    \n     return resolve(true);\n    }) \n}\n----\n\n== TODO\n\n* Handling Socket timeout \n* Error Management\n\n== Contributing\n \n// Change the repository name in the issues link to match with your project's name\n \nYou can involve yourself with our project by https://github.com/teragrep/rlp_02/issues/new/choose[opening an issue] or submitting a pull request.\n \nContribution requirements:\n \n. *All changes must be accompanied by a new or changed test.* If you think testing is not required in your pull request, include a sufficient explanation as why you think so.\n. Security checks must pass\n. Pull requests must align with the principles and http://www.extremeprogramming.org/values.html[values] of extreme programming.\n. Pull requests must follow the principles of Object Thinking and Elegant Objects (EO).\n \nRead more in our https://github.com/teragrep/teragrep/blob/main/contributing.adoc[Contributing Guideline].\n \n=== Contributor License Agreement\n \nContributors must sign https://github.com/teragrep/teragrep/blob/main/cla.adoc[Teragrep Contributor License Agreement] before a pull request is accepted to organization's repositories.\n \nYou need to submit the CLA only once. After submitting the CLA you can contribute to all Teragrep's repositories. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteragrep%2Frlp_02","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteragrep%2Frlp_02","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteragrep%2Frlp_02/lists"}