diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8faf853 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,26 @@ +# Source: https://github.com/actions/starter-workflows/blob/main/ci/node.js.yml + +name: CI + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + 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: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - run: npm test 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; 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 f999ef1..fdf0d62 100755 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "@myndzi/glossy", - "version": "0.1.10", + "version": "0.1.11", "description": "Syslog parser and producer", "keywords": [ "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": [ { @@ -70,6 +67,6 @@ } ], "engines": { - "node": ">= 0.2.5" + "node": ">= 0.10.0" } } 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',