From 6a4d06994bcb16062f79a0830ec3d43d661393de Mon Sep 17 00:00:00 2001 From: Pavel Kriz Date: Fri, 9 Sep 2016 15:23:18 +0200 Subject: [PATCH 1/9] Fix: Generate correct date-times in RFC 3339 format for RFC5424 syslog protocol In contrast to original fix by @rcrichton: Fixed getFullYear instead of getUTCFullYear (would be an issues around the New Year's Eve). Fixed zero-padding of getMilliseconds value (getMilliseconds() returning 8 means xxx.008, not xxx.8). More efficient calculation of the offset (no more loops). --- lib/glossy/produce.js | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/lib/glossy/produce.js b/lib/glossy/produce.js index 6dd5fd9..dcf3c36 100644 --- a/lib/glossy/produce.js +++ b/lib/glossy/produce.js @@ -354,7 +354,7 @@ function generateBSDDate(dateObject) { /* * Generate date in RFC 3339 format. If no date is supplied, the default is - * the current time in GMT + 0. + * the current time in local timezone. * @param {Date} dateObject optional Date object * @returns {String} formatted date */ @@ -364,11 +364,8 @@ function generateDate(dateObject) { // Calcutate the offset var timeOffset; var minutes = Math.abs(dateObject.getTimezoneOffset()); - var hours = 0; - while(minutes >= 60) { - hours++; - minutes -= 60; - } + var hours = Math.floor(Math.abs(minutes) / 60); + minutes = Math.abs(minutes) % 60; if(dateObject.getTimezoneOffset() < 0) { // Ahead of UTC @@ -383,20 +380,20 @@ function generateDate(dateObject) { // Date - var formattedDate = dateObject.getUTCFullYear() + '-' + - // N.B. Javascript Date objects return months of the year indexed from - // zero, while the RFC 5424 syslog standard expects months indexed from - // one. - leadZero(dateObject.getMonth() + 1) + '-' + - // N.B. Javascript Date objects return days of the month indexed from one - // (unlike months of year), so this does not need any correction. - leadZero(dateObject.getDate()) + 'T' + - // Time - leadZero(dateObject.getHours()) + ':' + - leadZero(dateObject.getMinutes()) + ':' + - leadZero(dateObject.getSeconds()) + '.' + - leadZero(dateObject.getMilliseconds()) + - timeOffset; + var formattedDate = dateObject.getFullYear() + '-' + + // N.B. Javascript Date objects return months of the year indexed from + // zero, while the RFC 5424 syslog standard expects months indexed from + // one. + leadZero(dateObject.getMonth() + 1) + '-' + + // N.B. Javascript Date objects return days of the month indexed from one + // (unlike months of year), so this does not need any correction. + leadZero(dateObject.getDate()) + 'T' + + // Time + leadZero(dateObject.getHours()) + ':' + + leadZero(dateObject.getMinutes()) + ':' + + leadZero(dateObject.getSeconds()) + '.' + + (dateObject.getMilliseconds() / 1000).toFixed(3).slice(2, 5) + + timeOffset; return formattedDate; From 07d1ec3f20d77c435647578afce485faa2419438 Mon Sep 17 00:00:00 2001 From: bmaupin Date: Wed, 29 Sep 2021 10:53:28 -0400 Subject: [PATCH 2/9] chore: Update supported version of Node.js Math.abs, Math.foor, and Number.prototype.toFixed all require Node 0.10.0 or greater --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f999ef1..3caecf1 100755 --- a/package.json +++ b/package.json @@ -70,6 +70,6 @@ } ], "engines": { - "node": ">= 0.2.5" + "node": ">= 0.10.0" } } From 8e39e0a27a525ca7f6edb14883d002ff26a4a2a1 Mon Sep 17 00:00:00 2001 From: bmaupin Date: Wed, 29 Sep 2021 10:54:36 -0400 Subject: [PATCH 3/9] test: Update tests to reflect fixes to milliseconds --- test/produce.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/produce.js b/test/produce.js index 1aaca6b..6a6e1ba 100755 --- a/test/produce.js +++ b/test/produce.js @@ -33,7 +33,7 @@ var msg = syslogProducer.produce({ date: new Date(1234567890000), message: 'Test Message' }); -assert.equal(msg, "<163>1 2009-02-14T00:31:30.00+01:00 localhost sudo 123 - - Test Message",'Valid message returned'); +assert.equal(msg, "<163>1 2009-02-14T00:31:30.000+01:00 localhost sudo 123 - - Test Message",'Valid message returned'); syslogProducer.produce({ facility: 'audit', @@ -41,10 +41,10 @@ syslogProducer.produce({ host: '127.0.0.1', appName: 'sudo', pid: '419', - date: new Date(1234567890000), + date: new Date(1234567890001), message: 'Test Message' }, function(cbMsg) { - assert.equal(cbMsg, '<107>1 2009-02-14T00:31:30.00+01:00 127.0.0.1 sudo 419 - - Test Message', 'Valid message in callback returned'); + assert.equal(cbMsg, '<107>1 2009-02-14T00:31:30.001+01:00 127.0.0.1 sudo 419 - - Test Message', 'Valid message in callback returned'); }); BSDProducer.produce({ @@ -137,7 +137,7 @@ var structuredMsg = syslogProducer.produce({ host: 'mymachine.example.com', appName: 'evntslog', msgID: 'ID47', - date: new Date(1234567890000), + date: new Date(1234567890010), structuredData: { 'exampleSDID@32473': { 'iut': "3", @@ -150,7 +150,7 @@ var structuredMsg = syslogProducer.produce({ }); assert.ok(structuredMsg); -assert.equal(structuredMsg, '<163>1 2009-02-14T00:31:30.00+01:00 mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011" seqNo="1"] BOMAn application event log entry...'); +assert.equal(structuredMsg, '<163>1 2009-02-14T00:31:30.010+01:00 mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011" seqNo="1"] BOMAn application event log entry...'); var structuredWithArray = syslogProducer.produce({ facility: 'local4', @@ -158,17 +158,17 @@ var structuredWithArray = syslogProducer.produce({ host: 'mymachine.example.com', appName: 'evntslog', msgID: 'ID47', - date: new Date(1234567890000), + date: new Date(1234567890100), structuredData: { 'origin': { 'ip': ['127.0.1.1', '127.0.0.1'] } }, - message: 'BOMAn application event log entry...' + message: 'BOMAn application event log entry...' }); assert.ok(structuredWithArray); -assert.equal(structuredWithArray, '<163>1 2009-02-14T00:31:30.00+01:00 mymachine.example.com evntslog - ID47 [origin ip="127.0.1.1" ip="127.0.0.1"] BOMAn application event log entry...'); +assert.equal(structuredWithArray, '<163>1 2009-02-14T00:31:30.100+01:00 mymachine.example.com evntslog - ID47 [origin ip="127.0.1.1" ip="127.0.0.1"] BOMAn application event log entry...'); var messageWithOneDigitDate = presetProducer.emergency({ facility: 'news', From 26141fdfdc747956eeecc9889c07adfec2898280 Mon Sep 17 00:00:00 2001 From: bmaupin Date: Wed, 29 Sep 2021 11:02:24 -0400 Subject: [PATCH 4/9] chore: Update repository URL This way the correct URL will be used in the NPM registry (https://www.npmjs.com/package/@myndzi/glossy) --- package.json | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 3caecf1..20810a2 100755 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "syslog", "logging" ], - "url": "http://github.com/squeeks/glossy", + "url": "http://github.com/myndzi/glossy", "main": "./index.js", "author": "Squeeks ", "maintainers": [ @@ -58,10 +58,7 @@ }, "repository": { "type": "git", - "url": "http://github.com/squeeks/glossy.git" - }, - "bugs": { - "url": "http://github.com/squeeks/glossy/issues" + "url": "http://github.com/myndzi/glossy.git" }, "licenses": [ { From 32d7c4a7dde18698812a2630ef6d8c595c4523d0 Mon Sep 17 00:00:00 2001 From: bmaupin Date: Wed, 29 Sep 2021 11:21:48 -0400 Subject: [PATCH 5/9] ci: Add GitHub actions starter template ... from https://github.com/actions/starter-workflows/blob/main/ci/node.js.yml --- .github/workflows/ci.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..485cf06 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,31 @@ +# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Node.js CI + +on: + push: + branches: [ $default-branch ] + pull_request: + branches: [ $default-branch ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [12.x, 14.x, 16.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - run: npm ci + - run: npm run build --if-present + - run: npm test \ No newline at end of file From 845ff8fb32f422f85f536adef53deb57390dc53e Mon Sep 17 00:00:00 2001 From: bmaupin Date: Wed, 29 Sep 2021 11:25:24 -0400 Subject: [PATCH 6/9] ci: Update CI template to work with this repo - Set branch name (-branch is only for templates) - Add all desired supported node versions - Add link to upstream template for reference --- .github/workflows/ci.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 485cf06..a5b3401 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,22 +1,20 @@ -# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions +# Source: https://github.com/actions/starter-workflows/blob/main/ci/node.js.yml -name: Node.js CI +name: CI on: push: - branches: [ $default-branch ] + branches: [master] pull_request: - branches: [ $default-branch ] + branches: [master] jobs: build: - runs-on: ubuntu-latest strategy: matrix: - node-version: [12.x, 14.x, 16.x] + node-version: [0.10.x, 0.12.x, 4.x, 6.x, 8.x, 10.x, 12.x, 14.x, 16.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: @@ -28,4 +26,4 @@ jobs: cache: 'npm' - run: npm ci - run: npm run build --if-present - - run: npm test \ No newline at end of file + - run: npm test From 476c28c6a04d1836123f1573bf14be7f666bee1f Mon Sep 17 00:00:00 2001 From: bmaupin Date: Wed, 29 Sep 2021 11:36:22 -0400 Subject: [PATCH 7/9] ci: Remove npm ci npm ci doesn't exist on really old versions of Node, and since this package doesn't have any dependencies we don't need it anyway. Remove npm run build too while we're at it. --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a5b3401..13b55fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,4 @@ jobs: with: node-version: ${{ matrix.node-version }} cache: 'npm' - - run: npm ci - - run: npm run build --if-present - run: npm test From f266ab12143a8550583b10632dd655ef365fbe79 Mon Sep 17 00:00:00 2001 From: bmaupin Date: Wed, 29 Sep 2021 11:43:24 -0400 Subject: [PATCH 8/9] ci: Remove cache It's causing errors, I guess because this package has no dependencies, there's nothing to cache? This is the error: 'Error: Cache folder path is retrieved for npm but doesn't exist on disk: /home/runner/.npm' --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13b55fb..8faf853 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,5 +23,4 @@ jobs: uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - cache: 'npm' - run: npm test From c276535c2f6ef850a98cf19807aecaf02cfa7012 Mon Sep 17 00:00:00 2001 From: bmaupin Date: Wed, 29 Sep 2021 11:48:52 -0400 Subject: [PATCH 9/9] chore: Bump version to 0.1.11 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0142031..a00113d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { "name": "@myndzi/glossy", - "version": "0.1.10", + "version": "0.1.11", "lockfileVersion": 1 } diff --git a/package.json b/package.json index 20810a2..fdf0d62 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@myndzi/glossy", - "version": "0.1.10", + "version": "0.1.11", "description": "Syslog parser and producer", "keywords": [ "syslog",