7c7981066d9b0a599496183f5409b6456c48d692
[public/netxms.git] / src / server / core / syslogd.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** Copyright (C) 2003-2014 Victor Kirhenshtein
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 **
19 ** File: syslogd.cpp
20 **
21 **/
22
23 #include "nxcore.h"
24 #include <nxlog.h>
25 #include <nxlpapi.h>
26
27 /**
28 * Max syslog message length
29 */
30 #define MAX_SYSLOG_MSG_LEN 1024
31
32 /**
33 * Queued syslog message structure
34 */
35 struct QUEUED_SYSLOG_MESSAGE
36 {
37 UINT32 dwSourceIP;
38 int nBytes;
39 char *psMsg;
40 };
41
42 /**
43 * Queues
44 */
45 Queue g_syslogProcessingQueue(1000, 100);
46 Queue g_syslogWriteQueue(1000, 100);
47
48 /**
49 * Node matching policy
50 */
51 enum NodeMatchingPolicy
52 {
53 SOURCE_IP_THEN_HOSTNAME = 0,
54 HOSTNAME_THEN_SOURCE_IP = 1
55 };
56
57 /**
58 * Static data
59 */
60 static UINT64 s_msgId = 1;
61 static LogParser *s_parser = NULL;
62 static MUTEX s_parserLock = INVALID_MUTEX_HANDLE;
63 static NodeMatchingPolicy s_nodeMatchingPolicy = SOURCE_IP_THEN_HOSTNAME;
64
65 /**
66 * Parse timestamp field
67 */
68 static BOOL ParseTimeStamp(char **ppStart, int nMsgSize, int *pnPos, time_t *ptmTime)
69 {
70 static char psMonth[12][5] = { "Jan ", "Feb ", "Mar ", "Apr ",
71 "May ", "Jun ", "Jul ", "Aug ",
72 "Sep ", "Oct ", "Nov ", "Dec " };
73 struct tm timestamp;
74 time_t t;
75 char szBuffer[16], *pCurr = *ppStart;
76 int i;
77
78 if (nMsgSize - *pnPos < 16)
79 return FALSE; // Timestamp cannot be shorter than 16 bytes
80
81 // Prepare local time structure
82 t = time(NULL);
83 memcpy(&timestamp, localtime(&t), sizeof(struct tm));
84
85 // Month
86 for(i = 0; i < 12; i++)
87 if (!memcmp(pCurr, psMonth[i], 4))
88 {
89 timestamp.tm_mon = i;
90 break;
91 }
92 if (i == 12)
93 return FALSE;
94 pCurr += 4;
95
96 // Day of week
97 if (isdigit(*pCurr))
98 {
99 timestamp.tm_mday = *pCurr - '0';
100 }
101 else
102 {
103 if (*pCurr != ' ')
104 return FALSE; // Invalid day of month
105 timestamp.tm_mday = 0;
106 }
107 pCurr++;
108 if (isdigit(*pCurr))
109 {
110 timestamp.tm_mday = timestamp.tm_mday * 10 + (*pCurr - '0');
111 }
112 else
113 {
114 return FALSE; // Invalid day of month
115 }
116 pCurr++;
117 if (*pCurr != ' ')
118 return FALSE;
119 pCurr++;
120
121 // HH:MM:SS
122 memcpy(szBuffer, pCurr, 8);
123 szBuffer[8] = 0;
124 if (sscanf(szBuffer, "%02d:%02d:%02d", &timestamp.tm_hour,
125 &timestamp.tm_min, &timestamp.tm_sec) != 3)
126 return FALSE; // Invalid time format
127 pCurr += 8;
128
129 // Check for Cisco variant - HH:MM:SS.nnn
130 if (*pCurr == '.')
131 {
132 pCurr++;
133 if (isdigit(*pCurr))
134 pCurr++;
135 if (isdigit(*pCurr))
136 pCurr++;
137 if (isdigit(*pCurr))
138 pCurr++;
139 }
140
141 if (*pCurr != ' ')
142 return FALSE; // Space should follow timestamp
143 pCurr++;
144
145 // Convert to system time
146 *ptmTime = mktime(&timestamp);
147 if (*ptmTime == ((time_t)-1))
148 return FALSE;
149
150 // Adjust current position
151 *pnPos += (int)(pCurr - *ppStart);
152 *ppStart = pCurr;
153 return TRUE;
154 }
155
156 /**
157 * Parse syslog message
158 */
159 static BOOL ParseSyslogMessage(char *psMsg, int nMsgLen, NX_SYSLOG_RECORD *pRec)
160 {
161 int i, nLen, nPos = 0;
162 char *pCurr = psMsg;
163
164 memset(pRec, 0, sizeof(NX_SYSLOG_RECORD));
165
166 // Parse PRI part
167 if (*psMsg == '<')
168 {
169 int nPri = 0, nCount = 0;
170
171 for(pCurr++, nPos++; isdigit(*pCurr) && (nPos < nMsgLen); pCurr++, nPos++, nCount++)
172 nPri = nPri * 10 + (*pCurr - '0');
173 if (nPos >= nMsgLen)
174 return FALSE; // Unexpected end of message
175
176 if ((*pCurr == '>') && (nCount > 0) && (nCount <4))
177 {
178 pRec->nFacility = nPri / 8;
179 pRec->nSeverity = nPri % 8;
180 pCurr++;
181 nPos++;
182 }
183 else
184 {
185 return FALSE; // Invalid message
186 }
187 }
188 else
189 {
190 // Set default PRI of 13
191 pRec->nFacility = 1;
192 pRec->nSeverity = SYSLOG_SEVERITY_NOTICE;
193 }
194
195 // Parse HEADER part
196 if (ParseTimeStamp(&pCurr, nMsgLen, &nPos, &pRec->tmTimeStamp))
197 {
198 // Hostname
199 for(i = 0; (*pCurr >= 33) && (*pCurr <= 126) && (i < MAX_SYSLOG_HOSTNAME_LEN - 1) && (nPos < nMsgLen); i++, nPos++, pCurr++)
200 pRec->szHostName[i] = *pCurr;
201 if ((nPos >= nMsgLen) || (*pCurr != ' '))
202 {
203 // Not a valid hostname, assuming to be a part of message
204 pCurr -= i;
205 nPos -= i;
206 pRec->szHostName[0] = 0;
207 }
208 else
209 {
210 pCurr++;
211 nPos++;
212 }
213 }
214 else
215 {
216 pRec->tmTimeStamp = time(NULL);
217 }
218
219 // Parse MSG part
220 for(i = 0; isalnum(*pCurr) && (i < MAX_SYSLOG_TAG_LEN) && (nPos < nMsgLen); i++, nPos++, pCurr++)
221 pRec->szTag[i] = *pCurr;
222 if ((i == MAX_SYSLOG_TAG_LEN) || (nPos >= nMsgLen))
223 {
224 // Too long tag, assuming that it's a part of message
225 pRec->szTag[0] = 0;
226 }
227 pCurr -= i;
228 nPos -= i;
229 nLen = min(nMsgLen - nPos, MAX_LOG_MSG_LENGTH);
230 memcpy(pRec->szMessage, pCurr, nLen);
231
232 return TRUE;
233 }
234
235 /**
236 * Find node by host name
237 */
238 static Node *FindNodeByHostname(const char *hostName)
239 {
240 if (hostName[0] == 0)
241 return NULL;
242
243 Node *node = NULL;
244 UINT32 ipAddr = ntohl(ResolveHostNameA(hostName));
245 if ((ipAddr != INADDR_NONE) && (ipAddr != INADDR_ANY))
246 {
247 node = FindNodeByIP(0, ipAddr);
248 }
249
250 if (node == NULL)
251 {
252 #ifdef UNICODE
253 WCHAR wname[MAX_OBJECT_NAME];
254 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, hostName, -1, wname, MAX_OBJECT_NAME);
255 wname[MAX_OBJECT_NAME - 1] = 0;
256 node = (Node *)FindObjectByName(wname, OBJECT_NODE);
257 #else
258 node = (Node *)FindObjectByName(hostName, OBJECT_NODE);
259 #endif
260 }
261 return node;
262 }
263
264 /**
265 * Bind syslog message to NetXMS node object
266 * dwSourceIP is an IP address from which we receive message
267 */
268 static Node *BindMsgToNode(NX_SYSLOG_RECORD *pRec, UINT32 dwSourceIP)
269 {
270 Node *node = NULL;
271
272 if (s_nodeMatchingPolicy == SOURCE_IP_THEN_HOSTNAME)
273 {
274 node = FindNodeByIP(0, dwSourceIP);
275 if (node == NULL)
276 {
277 node = FindNodeByHostname(pRec->szHostName);
278 }
279 }
280 else
281 {
282 node = FindNodeByHostname(pRec->szHostName);
283 if (node == NULL)
284 {
285 node = FindNodeByIP(0, dwSourceIP);
286 }
287 }
288
289 if (node != NULL)
290 {
291 pRec->dwSourceObject = node->Id();
292 if (pRec->szHostName[0] == 0)
293 {
294 #ifdef UNICODE
295 WideCharToMultiByte(CP_ACP, WC_DEFAULTCHAR | WC_COMPOSITECHECK, node->Name(), -1, pRec->szHostName, MAX_SYSLOG_HOSTNAME_LEN, NULL, NULL);
296 pRec->szHostName[MAX_SYSLOG_HOSTNAME_LEN - 1] = 0;
297 #else
298 nx_strncpy(pRec->szHostName, node->Name(), MAX_SYSLOG_HOSTNAME_LEN);
299 #endif
300 }
301 }
302 else
303 {
304 if (pRec->szHostName[0] == 0)
305 IpToStrA(dwSourceIP, pRec->szHostName);
306 }
307
308 return node;
309 }
310
311 /**
312 * Handler for EnumerateSessions()
313 */
314 static void BroadcastSyslogMessage(ClientSession *pSession, void *pArg)
315 {
316 if (pSession->isAuthenticated())
317 pSession->onSyslogMessage((NX_SYSLOG_RECORD *)pArg);
318 }
319
320 /**
321 * Syslog writer thread
322 */
323 static THREAD_RESULT THREAD_CALL SyslogWriterThread(void *arg)
324 {
325 DbgPrintf(1, _T("Syslog writer thread started"));
326 while(true)
327 {
328 NX_SYSLOG_RECORD *r = (NX_SYSLOG_RECORD *)g_syslogWriteQueue.GetOrBlock();
329 if (r == INVALID_POINTER_VALUE)
330 break;
331
332 DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
333
334 DB_STATEMENT hStmt = DBPrepare(hdb, _T("INSERT INTO syslog (msg_id,msg_timestamp,facility,severity,source_object_id,hostname,msg_tag,msg_text) VALUES (?,?,?,?,?,?,?,?)"));
335 if (hStmt == NULL)
336 {
337 free(r);
338 continue;
339 }
340
341 int count = 0;
342 DBBegin(hdb);
343 while(true)
344 {
345 DBBind(hStmt, 1, DB_SQLTYPE_BIGINT, r->qwMsgId);
346 DBBind(hStmt, 2, DB_SQLTYPE_INTEGER, (INT32)r->tmTimeStamp);
347 DBBind(hStmt, 3, DB_SQLTYPE_INTEGER, r->nFacility);
348 DBBind(hStmt, 4, DB_SQLTYPE_INTEGER, r->nSeverity);
349 DBBind(hStmt, 5, DB_SQLTYPE_INTEGER, r->dwSourceObject);
350 #ifdef UNICODE
351 DBBind(hStmt, 6, DB_SQLTYPE_VARCHAR, WideStringFromMBString(r->szHostName), DB_BIND_DYNAMIC);
352 DBBind(hStmt, 7, DB_SQLTYPE_VARCHAR, WideStringFromMBString(r->szTag), DB_BIND_DYNAMIC);
353 DBBind(hStmt, 8, DB_SQLTYPE_VARCHAR, WideStringFromMBString(r->szMessage), DB_BIND_DYNAMIC);
354 #else
355 DBBind(hStmt, 6, DB_SQLTYPE_VARCHAR, r->szHostName, DB_BIND_STATIC);
356 DBBind(hStmt, 7, DB_SQLTYPE_VARCHAR, r->szTag, DB_BIND_STATIC);
357 DBBind(hStmt, 8, DB_SQLTYPE_VARCHAR, r->szMessage, DB_BIND_STATIC);
358 #endif
359
360 if (!DBExecute(hStmt))
361 {
362 free(r);
363 break;
364 }
365 free(r);
366 count++;
367 if (count == 1000)
368 break;
369 r = (NX_SYSLOG_RECORD *)g_syslogWriteQueue.Get();
370 if ((r == NULL) || (r == INVALID_POINTER_VALUE))
371 break;
372 }
373 DBCommit(hdb);
374 DBFreeStatement(hStmt);
375 DBConnectionPoolReleaseConnection(hdb);
376 if (r == INVALID_POINTER_VALUE)
377 break;
378 }
379 DbgPrintf(1, _T("Syslog writer thread stopped"));
380 return THREAD_OK;
381 }
382
383 /**
384 * Process syslog message
385 */
386 static void ProcessSyslogMessage(char *psMsg, int nMsgLen, UINT32 dwSourceIP)
387 {
388 NX_SYSLOG_RECORD record;
389
390 DbgPrintf(6, _T("ProcessSyslogMessage: Raw syslog message to process:\n%hs"), psMsg);
391 if (ParseSyslogMessage(psMsg, nMsgLen, &record))
392 {
393 record.qwMsgId = s_msgId++;
394 Node *node = BindMsgToNode(&record, dwSourceIP);
395
396 g_syslogWriteQueue.Put(nx_memdup(&record, sizeof(NX_SYSLOG_RECORD)));
397
398 // Send message to all connected clients
399 EnumerateClientSessions(BroadcastSyslogMessage, &record);
400
401 TCHAR ipAddr[32];
402 DbgPrintf(6, _T("Syslog message: ipAddr=%s objectId=%d tag=\"%hs\" msg=\"%hs\""),
403 IpToStr(dwSourceIP, ipAddr), record.dwSourceObject, record.szTag, record.szMessage);
404
405 MutexLock(s_parserLock);
406 if ((record.dwSourceObject != 0) && (s_parser != NULL) &&
407 ((node->Status() != STATUS_UNMANAGED) || (g_flags & AF_TRAPS_FROM_UNMANAGED_NODES)))
408 {
409 #ifdef UNICODE
410 WCHAR wtag[MAX_SYSLOG_TAG_LEN];
411 WCHAR wmsg[MAX_LOG_MSG_LENGTH];
412 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, record.szTag, -1, wtag, MAX_SYSLOG_TAG_LEN);
413 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, record.szMessage, -1, wmsg, MAX_LOG_MSG_LENGTH);
414 s_parser->matchEvent(wtag, record.nFacility, 1 << record.nSeverity, wmsg, record.dwSourceObject);
415 #else
416 s_parser->matchEvent(record.szTag, record.nFacility, 1 << record.nSeverity, record.szMessage, record.dwSourceObject);
417 #endif
418 }
419 MutexUnlock(s_parserLock);
420 }
421 else
422 {
423 DbgPrintf(6, _T("ProcessSyslogMessage: Cannot parse syslog message"));
424 }
425 }
426
427 /**
428 * Syslog processing thread
429 */
430 static THREAD_RESULT THREAD_CALL SyslogProcessingThread(void *pArg)
431 {
432 QUEUED_SYSLOG_MESSAGE *pMsg;
433
434 while(1)
435 {
436 pMsg = (QUEUED_SYSLOG_MESSAGE *)g_syslogProcessingQueue.GetOrBlock();
437 if (pMsg == INVALID_POINTER_VALUE)
438 break;
439
440 ProcessSyslogMessage(pMsg->psMsg, pMsg->nBytes, pMsg->dwSourceIP);
441 free(pMsg->psMsg);
442 free(pMsg);
443 }
444 return THREAD_OK;
445 }
446
447 /**
448 * Queue syslog message for processing
449 */
450 static void QueueSyslogMessage(char *psMsg, int nMsgLen, UINT32 dwSourceIP)
451 {
452 QUEUED_SYSLOG_MESSAGE *pMsg;
453
454 pMsg = (QUEUED_SYSLOG_MESSAGE *)malloc(sizeof(QUEUED_SYSLOG_MESSAGE));
455 pMsg->dwSourceIP = dwSourceIP;
456 pMsg->nBytes = nMsgLen;
457 pMsg->psMsg = (char *)nx_memdup(psMsg, nMsgLen + 1);
458 g_syslogProcessingQueue.Put(pMsg);
459 }
460
461 /**
462 * Callback for syslog parser
463 */
464 static void SyslogParserCallback(UINT32 eventCode, const TCHAR *eventName, const TCHAR *line,
465 const TCHAR *source, UINT32 facility, UINT32 severity,
466 int paramCount, TCHAR **params, UINT32 objectId, void *userArg)
467 {
468 char format[] = "ssssssssssssssssssssssssssssssss";
469 TCHAR *plist[32];
470 int i, count;
471
472 count = min(paramCount, 32);
473 format[count] = 0;
474 for(i = 0; i < count; i++)
475 plist[i] = params[i];
476 PostEvent(eventCode, objectId, format,
477 plist[0], plist[1], plist[2], plist[3],
478 plist[4], plist[5], plist[6], plist[7],
479 plist[8], plist[9], plist[10], plist[11],
480 plist[12], plist[13], plist[14], plist[15],
481 plist[16], plist[17], plist[18], plist[19],
482 plist[20], plist[21], plist[22], plist[23],
483 plist[24], plist[25], plist[26], plist[27],
484 plist[28], plist[29], plist[30], plist[31]);
485 }
486
487 /**
488 * Event name resolver
489 */
490 static bool EventNameResolver(const TCHAR *name, UINT32 *code)
491 {
492 EVENT_TEMPLATE *event;
493 bool success = false;
494
495 event = FindEventTemplateByName(name);
496 if (event != NULL)
497 {
498 *code = event->dwCode;
499 success = true;
500 }
501 return success;
502 }
503
504 /**
505 * Create syslog parser from config
506 */
507 static void CreateParserFromConfig()
508 {
509 char *xml;
510
511 MutexLock(s_parserLock);
512 delete_and_null(s_parser);
513 #ifdef UNICODE
514 WCHAR *wxml = ConfigReadCLOB(_T("SyslogParser"), _T("<parser></parser>"));
515 if (wxml != NULL)
516 {
517 xml = UTF8StringFromWideString(wxml);
518 free(wxml);
519 }
520 else
521 {
522 xml = NULL;
523 }
524 #else
525 xml = ConfigReadCLOB("SyslogParser", "<parser></parser>");
526 #endif
527 if (xml != NULL)
528 {
529 TCHAR parseError[256];
530 ObjectArray<LogParser> *parsers = LogParser::createFromXml(xml, -1, parseError, 256, EventNameResolver);
531 if ((parsers != NULL) && (parsers->size() > 0))
532 {
533 s_parser = parsers->get(0);
534 s_parser->setCallback(SyslogParserCallback);
535 DbgPrintf(3, _T("syslogd: parser successfully created from config"));
536 }
537 else
538 {
539 nxlog_write(MSG_SYSLOG_PARSER_INIT_FAILED, EVENTLOG_ERROR_TYPE, "s", parseError);
540 }
541 free(xml);
542 delete parsers;
543 }
544 MutexUnlock(s_parserLock);
545 }
546
547 /**
548 * Syslog messages receiver thread
549 */
550 THREAD_RESULT THREAD_CALL SyslogDaemon(void *pArg)
551 {
552 SOCKET hSocket;
553 struct sockaddr_in addr;
554 int nBytes, nPort, nRet;
555 socklen_t nAddrLen;
556 char sMsg[MAX_SYSLOG_MSG_LEN + 1];
557 DB_RESULT hResult;
558 fd_set rdfs;
559 struct timeval tv;
560
561 // Determine first available message id
562 hResult = DBSelect(g_hCoreDB, _T("SELECT max(msg_id) FROM syslog"));
563 if (hResult != NULL)
564 {
565 if (DBGetNumRows(hResult) > 0)
566 {
567 s_msgId = max(DBGetFieldUInt64(hResult, 0, 0) + 1, s_msgId);
568 }
569 DBFreeResult(hResult);
570 }
571
572 hSocket = socket(AF_INET, SOCK_DGRAM, 0);
573 if (hSocket == INVALID_SOCKET)
574 {
575 nxlog_write(MSG_SOCKET_FAILED, EVENTLOG_ERROR_TYPE, "s", _T("SyslogDaemon"));
576 return THREAD_OK;
577 }
578
579 SetSocketExclusiveAddrUse(hSocket);
580 SetSocketReuseFlag(hSocket);
581
582 // Get listen port number
583 nPort = ConfigReadInt(_T("SyslogListenPort"), 514);
584 if ((nPort < 1) || (nPort > 65535))
585 nPort = 514;
586
587 // Fill in local address structure
588 memset(&addr, 0, sizeof(struct sockaddr_in));
589 addr.sin_family = AF_INET;
590 addr.sin_addr.s_addr = ResolveHostName(g_szListenAddress);
591 addr.sin_port = htons((WORD)nPort);
592
593 // Bind socket
594 if (bind(hSocket, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) != 0)
595 {
596 nxlog_write(MSG_BIND_ERROR, EVENTLOG_ERROR_TYPE, "dse", nPort, _T("SyslogDaemon"), WSAGetLastError());
597 closesocket(hSocket);
598 return THREAD_OK;
599 }
600 nxlog_write(MSG_LISTENING_FOR_SYSLOG, EVENTLOG_INFORMATION_TYPE, "ad", ntohl(addr.sin_addr.s_addr), nPort);
601
602 // Create message parser
603 s_parserLock = MutexCreate();
604 CreateParserFromConfig();
605
606 // Start processing thread
607 THREAD hProcessingThread = ThreadCreateEx(SyslogProcessingThread, 0, NULL);
608 THREAD hWriterThread = ThreadCreateEx(SyslogWriterThread, 0, NULL);
609
610 DbgPrintf(1, _T("Syslog Daemon started"));
611
612 // Wait for packets
613 while(!IsShutdownInProgress())
614 {
615 FD_ZERO(&rdfs);
616 FD_SET(hSocket, &rdfs);
617 tv.tv_sec = 1;
618 tv.tv_usec = 0;
619 nRet = select((int)hSocket + 1, &rdfs, NULL, NULL, &tv);
620 if (nRet > 0)
621 {
622 nAddrLen = sizeof(struct sockaddr_in);
623 nBytes = recvfrom(hSocket, sMsg, MAX_SYSLOG_MSG_LEN, 0, (struct sockaddr *)&addr, &nAddrLen);
624 if (nBytes > 0)
625 {
626 sMsg[nBytes] = 0;
627 QueueSyslogMessage(sMsg, nBytes, ntohl(addr.sin_addr.s_addr));
628 }
629 else
630 {
631 // Sleep on error
632 ThreadSleepMs(100);
633 }
634 }
635 else if (nRet == -1)
636 {
637 // Sleep on error
638 ThreadSleepMs(100);
639 }
640 }
641
642 // Stop processing thread
643 g_syslogProcessingQueue.Put(INVALID_POINTER_VALUE);
644 ThreadJoin(hProcessingThread);
645
646 // Stop writer thread - it must be done after processing thread already finished
647 g_syslogWriteQueue.Put(INVALID_POINTER_VALUE);
648 ThreadJoin(hWriterThread);
649
650 delete s_parser;
651
652 DbgPrintf(1, _T("Syslog Daemon stopped"));
653 return THREAD_OK;
654 }
655
656 /**
657 * Create NXCP message from NX_SYSLOG_RECORD structure
658 */
659 void CreateMessageFromSyslogMsg(CSCPMessage *pMsg, NX_SYSLOG_RECORD *pRec)
660 {
661 UINT32 dwId = VID_SYSLOG_MSG_BASE;
662
663 pMsg->SetVariable(VID_NUM_RECORDS, (UINT32)1);
664 pMsg->SetVariable(dwId++, pRec->qwMsgId);
665 pMsg->SetVariable(dwId++, (UINT32)pRec->tmTimeStamp);
666 pMsg->SetVariable(dwId++, (WORD)pRec->nFacility);
667 pMsg->SetVariable(dwId++, (WORD)pRec->nSeverity);
668 pMsg->SetVariable(dwId++, pRec->dwSourceObject);
669 pMsg->SetVariableFromMBString(dwId++, pRec->szHostName);
670 pMsg->SetVariableFromMBString(dwId++, pRec->szTag);
671 pMsg->SetVariableFromMBString(dwId++, pRec->szMessage);
672 }
673
674 /**
675 * Reinitialize parser on configuration change
676 */
677 void ReinitializeSyslogParser()
678 {
679 if (s_parserLock == INVALID_MUTEX_HANDLE)
680 return; // Syslog daemon not initialized
681 CreateParserFromConfig();
682 }