Closed damomurf closed 11 years ago
The cause: RFC 3164 specifies that the date be formatted "Mmm dd hh:mm:ss", with single space division being visible between month, date and time but it is not explicitly mentioned. Since there's two spaces between "May" and the date, it's breaking at about here for you, where we assume there isn't kind of thing going on.
The (possible) solution:
A while back I removed a lot of code that split the message up on /\s+/
, as it's painfully slow. I may have to change my decision on that, or I may have to think of a smarter way of doing this. I've got a little bit of time on my hands, hold tight. Suggestions welcome.
how about removing any empty spaces from the rawMessage, like so:
var segments = rawMessage.split(' ').filter( function( elem, index, ar )
{
return elem != "";
});
UPDATE: on second thoughts maybe we'd only want to remove the empty space segments up until we reach the actual message.
In my case, I could certainly split on just the first instance, so a slight modification to your code:
var segments = rawMessage.split(' ',1).filter( function( elem, index, ar )
{
return elem != "";
});
Thanks for the workaround!
UPDATE:
Ah, no - didn't understand the use of split(' ',1) - so that won't work.
Appears to still be an issue.
if(segments[1] == '') segments.splice(1,1);
var timeStamp = segments.splice(0,3).join(' ').replace(/^(<\d+>)/,'');
parsedMessage.time = parseTimeStamp(timeStamp);
parsedMessage.host = segments.shift();
parsedMessage.message = segments.join(' ');
Remove the bad array element when present for RFC3164 messages?
@stancarney as small as it is, would it be possible for you to please make a pull request out of that? Credit should be where it's due.
Apologies for ignoring this, I am finding it difficult to find time to look after my code as well as I should these days.
No problem. I just sent the pull request.
Thank you, Stan.
This is now fixed and available in npm as 0.1.3.
I've been using glossy reliably for some time now, but since midnight on the 1st May (local time), the library appears to be mis-parsing syslog packets. The sources are both OSX Lion, and Ubuntu 11.10.
You can see that the time and host appear to be borked, and this is happening consistently on all logs received.
An example parsed object dumped via console.log:
I don't believe anything else has changed in terms of dependencies, etc. to cause this. The code I'm using that exhibits the behaviour is below. This is with glossy 0.1.2 and node v0.6.15.