- Full syslog support
authorVictor Kirhenshtein <victor@netxms.org>
Sat, 1 Oct 2005 21:33:04 +0000 (21:33 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Sat, 1 Oct 2005 21:33:04 +0000 (21:33 +0000)
- Client library improved
- Various minor changes

26 files changed:
.gitattributes
include/nms_cscp.h
include/nxclapi.h
include/nxcscpapi.h
include/nxlog.h
src/agent/core/session.cpp
src/console/win32/AlarmBrowser.cpp
src/console/win32/Makefile.am
src/console/win32/SyslogBrowser.cpp [new file with mode: 0644]
src/console/win32/SyslogBrowser.h [new file with mode: 0644]
src/console/win32/globals.cpp
src/console/win32/globals.h
src/console/win32/nxcon.clw
src/console/win32/nxcon.cpp
src/console/win32/nxcon.dsp
src/console/win32/nxcon.h
src/console/win32/nxcon.rc
src/console/win32/resource.h
src/libnxcl/comm.cpp
src/libnxcl/events.cpp
src/libnxcl/libnxcl.h
src/libnxcl/objects.cpp
src/libnxcl/session.cpp
src/server/core/session.cpp
src/server/core/syslogd.cpp
src/server/include/nms_core.h

index be2db80..eb7fc4a 100644 (file)
@@ -563,6 +563,8 @@ src/console/win32/ServerCfgEditor.cpp -text
 src/console/win32/ServerCfgEditor.h -text
 src/console/win32/StdAfx.cpp -text
 src/console/win32/StdAfx.h -text
+src/console/win32/SyslogBrowser.cpp -text
+src/console/win32/SyslogBrowser.h -text
 src/console/win32/TableView.cpp -text
 src/console/win32/TableView.h -text
 src/console/win32/ThresholdDlg.cpp -text
index 64369e5..0b9ccf1 100644 (file)
@@ -217,8 +217,9 @@ typedef struct
 //
 
 #define MF_BINARY          0x0001
-#define MF_EOF             0x0002
+#define MF_END_OF_FILE     0x0002
 #define MF_DONT_ENCRYPT    0x0004
+#define MF_END_OF_SEQUENCE 0x0008
 
 
 //
@@ -544,6 +545,7 @@ typedef struct
 #define VID_LOG_NAME                ((DWORD)171)
 #define VID_OPERATION               ((DWORD)172)
 #define VID_MAX_RECORDS             ((DWORD)173)
+#define VID_NUM_RECORDS             ((DWORD)174)
 
 // Variable ranges for object's ACL
 #define VID_ACL_USER_BASE           ((DWORD)0x00001000)
@@ -616,6 +618,9 @@ typedef struct
 // Base value for log policy rules
 #define VID_LPP_RULE_BASE           ((DWORD)0x10000000)
 
+// Base value for syslog records
+#define VID_SYSLOG_MSG_BASE         ((DWORD)0x10000000)
+
 
 //
 // Inline functions
index 58fa188..6b792fb 100644 (file)
@@ -186,6 +186,7 @@ typedef void * NXC_SESSION;
 #define NXC_EVENT_OBJECT_CHANGED       4
 #define NXC_EVENT_NOTIFICATION         5
 #define NXC_EVENT_DEPLOYMENT_STATUS    6
+#define NXC_EVENT_NEW_SYSLOG_RECORD    7
 
 
 //
@@ -609,6 +610,23 @@ typedef void (* NXC_DEBUG_CALLBACK)(TCHAR *pMsg);
 
 
 //
+// Syslog record structure
+//
+
+typedef struct
+{
+   QWORD qwMsgId;
+   DWORD dwTimeStamp;
+   WORD wFacility;
+   WORD wSeverity;
+   DWORD dwSourceObject;
+   TCHAR szHost[MAX_SYSLOG_HOSTNAME_LEN];
+   TCHAR szTag[MAX_SYSLOG_TAG_LEN];
+   TCHAR *pszText;
+} NXC_SYSLOG_RECORD;
+
+
+//
 // Server's configuration variable
 //
 
@@ -1141,6 +1159,8 @@ int LIBNXCL_EXPORTABLE NXCGetEventSeverity(NXC_SESSION hSession, DWORD dwId);
 BOOL LIBNXCL_EXPORTABLE NXCGetEventText(NXC_SESSION hSession, DWORD dwId, TCHAR *pszBuffer, DWORD dwBufSize);
 DWORD LIBNXCL_EXPORTABLE NXCSendEvent(NXC_SESSION hSession, DWORD dwEventCode, DWORD dwObjectId, int iNumArgs, TCHAR **pArgList);
 
+DWORD LIBNXCL_EXPORTABLE NXCSyncSyslog(NXC_SESSION hSession, DWORD dwMaxRecords);
+
 DWORD LIBNXCL_EXPORTABLE NXCLoadUserDB(NXC_SESSION hSession);
 NXC_USER LIBNXCL_EXPORTABLE *NXCFindUserById(NXC_SESSION hSession, DWORD dwId);
 BOOL LIBNXCL_EXPORTABLE NXCGetUserDB(NXC_SESSION hSession, NXC_USER **ppUserList, DWORD *pdwNumUsers);
index 48953c7..c0b1294 100644 (file)
@@ -66,10 +66,10 @@ class LIBNXCSCP_EXPORTABLE CSCPMessage
 {
 private:
    WORD m_wCode;
+   WORD m_wFlags;
    DWORD m_dwId;
    DWORD m_dwNumVar;    // Number of variables
    CSCP_DF **m_ppVarList;   // List of variables
-   BOOL m_bDontEncrypt;
 
    void *Set(DWORD dwVarId, BYTE bType, void *pValue, DWORD dwSize = 0);
    void *Get(DWORD dwVarId, BYTE bType);
@@ -89,6 +89,7 @@ public:
    void SetId(DWORD dwId) { m_dwId = dwId; }
 
    BOOL IsVariableExist(DWORD dwVarId) { return (FindVariable(dwVarId) != INVALID_INDEX) ? TRUE : FALSE; }
+   BOOL IsEndOfSequence(void) { return (m_wFlags & MF_END_OF_SEQUENCE) ? TRUE : FALSE; }
 
    void SetVariable(DWORD dwVarId, WORD wValue) { Set(dwVarId, CSCP_DT_INT16, &wValue); }
    void SetVariable(DWORD dwVarId, DWORD dwValue) { Set(dwVarId, CSCP_DT_INTEGER, &dwValue); }
@@ -109,7 +110,8 @@ public:
 
    void DeleteAllVariables(void);
 
-   void DisableEncryption(void) { m_bDontEncrypt = TRUE; }
+   void DisableEncryption(void) { m_wFlags |= MF_DONT_ENCRYPT; }
+   void SetEndOfSequence(void) { m_wFlags |= MF_END_OF_SEQUENCE; }
 };
 
 
index 34db34d..1324d1a 100644 (file)
@@ -62,6 +62,7 @@
 
 typedef struct
 {
+   QWORD qwMsgId;       // NetXMS internal message ID
    DWORD dwTimeStamp;
    int nFacility;
    int nSeverity;
index dc481ee..9bbc1fc 100644 (file)
@@ -203,7 +203,7 @@ void CommSession::ReadThread(void)
             {
                if (write(m_hCurrFile, pRawMsg->df, pRawMsg->dwNumVars) == (int)pRawMsg->dwNumVars)
                {
-                  if (wFlags & MF_EOF)
+                  if (wFlags & MF_END_OF_FILE)
                   {
                      CSCPMessage msg;
 
index 21e7c60..97da154 100644 (file)
@@ -156,6 +156,7 @@ int CAlarmBrowser::OnCreate(LPCREATESTRUCT lpCreateStruct)
    RECT rect;
    int i;
    LVCOLUMN lvCol;
+   DWORD dwResult;
    static int widths[6] = { 50, 100, 150, 200, 250, -1 };
    static int icons[5] = { IDI_SEVERITY_NORMAL, IDI_SEVERITY_WARNING, IDI_SEVERITY_MINOR,
                            IDI_SEVERITY_MAJOR, IDI_SEVERITY_CRITICAL };
@@ -237,6 +238,10 @@ int CAlarmBrowser::OnCreate(LPCREATESTRUCT lpCreateStruct)
    }
 
    ((CConsoleApp *)AfxGetApp())->OnViewCreate(IDR_ALARMS, this);
+   dwResult = DoRequestArg2(NXCSubscribe, g_hSession, (void *)NXC_CHANNEL_ALARMS,
+                            _T("Subscribing to ALARMS channel..."));
+   if (dwResult != RCC_SUCCESS)
+      theApp.ErrorBox(dwResult, _T("Cannot subscribe to ALARMS channel: %s"));
 
    PostMessage(WM_COMMAND, ID_VIEW_REFRESH, 0);
        return 0;
@@ -249,6 +254,8 @@ int CAlarmBrowser::OnCreate(LPCREATESTRUCT lpCreateStruct)
 
 void CAlarmBrowser::OnDestroy() 
 {
+   DoRequestArg2(NXCUnsubscribe, g_hSession, (void *)NXC_CHANNEL_ALARMS,
+                 _T("Unsubscribing from ALARMS channel..."));
    ((CConsoleApp *)AfxGetApp())->OnViewDestroy(IDR_ALARMS, this);
        CMDIChildWnd::OnDestroy();
 }
index f67fd4d..e2c3ad8 100644 (file)
@@ -89,6 +89,7 @@ EXTRA_DIST = \
        RuleSeverityDlg.cpp RuleSeverityDlg.h \
        ServerCfgEditor.cpp ServerCfgEditor.h \
        StdAfx.cpp StdAfx.h \
+       SyslogBrowser.cpp SyslogBrowser.h \
        TableView.cpp TableView.h \
        ThresholdDlg.cpp ThresholdDlg.h \
        ToolBox.cpp ToolBox.h \
diff --git a/src/console/win32/SyslogBrowser.cpp b/src/console/win32/SyslogBrowser.cpp
new file mode 100644 (file)
index 0000000..eeebd45
--- /dev/null
@@ -0,0 +1,247 @@
+// SyslogBrowser.cpp : implementation file
+//
+
+#include "stdafx.h"
+#include "nxcon.h"
+#include "SyslogBrowser.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+// CSyslogBrowser
+
+IMPLEMENT_DYNCREATE(CSyslogBrowser, CMDIChildWnd)
+
+CSyslogBrowser::CSyslogBrowser()
+{
+   m_pImageList = NULL;
+   m_bIsBusy = FALSE;
+}
+
+CSyslogBrowser::~CSyslogBrowser()
+{
+   delete m_pImageList;
+}
+
+
+BEGIN_MESSAGE_MAP(CSyslogBrowser, CMDIChildWnd)
+       //{{AFX_MSG_MAP(CSyslogBrowser)
+       ON_WM_CREATE()
+       ON_WM_DESTROY()
+       ON_WM_SIZE()
+       ON_WM_SETFOCUS()
+       ON_COMMAND(ID_VIEW_REFRESH, OnViewRefresh)
+       //}}AFX_MSG_MAP
+   ON_MESSAGE(WM_GET_SAVE_INFO, OnGetSaveInfo)
+   ON_MESSAGE(WM_REQUEST_COMPLETED, OnRequestCompleted)
+   ON_MESSAGE(WM_SYSLOG_RECORD, OnSyslogRecord)
+END_MESSAGE_MAP()
+
+/////////////////////////////////////////////////////////////////////////////
+// CSyslogBrowser message handlers
+
+BOOL CSyslogBrowser::PreCreateWindow(CREATESTRUCT& cs) 
+{
+   if (cs.lpszClass == NULL)
+      cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW, 
+                                         NULL, 
+                                         GetSysColorBrush(COLOR_WINDOW), 
+                                         AfxGetApp()->LoadIcon(IDI_LOG));
+       return CMDIChildWnd::PreCreateWindow(cs);
+}
+
+
+//
+// WM_CREATE message handler
+//
+
+int CSyslogBrowser::OnCreate(LPCREATESTRUCT lpCreateStruct) 
+{
+   RECT rect;
+   DWORD dwResult;
+
+       if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
+               return -1;
+       
+   // Create list view control
+   GetClientRect(&rect);
+   m_wndListCtrl.Create(WS_CHILD | WS_VISIBLE | LVS_REPORT, rect, this, ID_LIST_VIEW);
+   m_wndListCtrl.SetExtendedStyle(LVS_EX_TRACKSELECT | LVS_EX_UNDERLINEHOT | 
+                                  LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
+   m_wndListCtrl.SetHoverTime(0x7FFFFFFF);
+
+   // Create image list
+   m_pImageList = CreateEventImageList();
+   m_wndListCtrl.SetImageList(m_pImageList, LVSIL_SMALL);
+
+   // Setup columns
+   m_wndListCtrl.InsertColumn(0, "Time", LVCFMT_LEFT, 135);
+   m_wndListCtrl.InsertColumn(1, "Severity", LVCFMT_LEFT, 80);
+   m_wndListCtrl.InsertColumn(2, "Facility", LVCFMT_LEFT, 80);
+   m_wndListCtrl.InsertColumn(3, "Hostname", LVCFMT_LEFT, 100);
+   m_wndListCtrl.InsertColumn(4, "Tag", LVCFMT_LEFT, 90);
+   m_wndListCtrl.InsertColumn(5, "Message", LVCFMT_LEFT, 500);
+       
+   // Create wait view
+   m_wndWaitView.Create(NULL, NULL, WS_CHILD, rect, this, ID_WAIT_VIEW);
+
+   ((CConsoleApp *)AfxGetApp())->OnViewCreate(IDR_SYSLOG_BROWSER, this);
+   dwResult = DoRequestArg2(NXCSubscribe, g_hSession,
+                            (void *)NXC_CHANNEL_SYSLOG,
+                            _T("Subscribing to SYSLOG channel..."));
+   if (dwResult != RCC_SUCCESS)
+      theApp.ErrorBox(dwResult, _T("Cannot subscribe to SYSLOG channel: %s"));
+
+   PostMessage(WM_COMMAND, ID_VIEW_REFRESH, 0);
+       return 0;
+}
+
+
+//
+// WM_DESTROY message handler
+//
+
+void CSyslogBrowser::OnDestroy() 
+{
+   DoRequestArg2(NXCUnsubscribe, g_hSession, (void *)NXC_CHANNEL_SYSLOG,
+                 _T("Unsubscribing from SYSLOG channel..."));
+   ((CConsoleApp *)AfxGetApp())->OnViewDestroy(IDR_SYSLOG_BROWSER, this);
+       CMDIChildWnd::OnDestroy();
+}
+
+
+//
+// WM_SIZE message handler
+//
+
+void CSyslogBrowser::OnSize(UINT nType, int cx, int cy) 
+{
+       CMDIChildWnd::OnSize(nType, cx, cy);
+       
+   m_wndListCtrl.SetWindowPos(NULL, 0, 0, cx, cy, SWP_NOZORDER);
+   m_wndWaitView.SetWindowPos(NULL, 0, 0, cx, cy, SWP_NOZORDER);
+}
+
+
+//
+// WM_SETFOCUS message handler
+//
+
+void CSyslogBrowser::OnSetFocus(CWnd* pOldWnd) 
+{
+       CMDIChildWnd::OnSetFocus(pOldWnd);
+       
+   if (m_bIsBusy)
+      m_wndWaitView.SetFocus();
+   else
+      m_wndListCtrl.SetFocus();
+}
+
+
+//
+// Message loading thread
+//
+
+static void LoadMessages(void *pArg)
+{
+   NXCSyncSyslog(g_hSession, g_dwMaxLogRecords);
+   PostMessage((HWND)pArg, WM_REQUEST_COMPLETED, 0, 0);
+}
+
+
+//
+// WM_COMMAND::ID_VIEW_REFRESH message handler
+//
+
+void CSyslogBrowser::OnViewRefresh() 
+{
+   if (!m_bIsBusy)
+   {
+      m_bIsBusy = TRUE;
+      m_wndWaitView.ShowWindow(SW_SHOW);
+      m_wndListCtrl.ShowWindow(SW_HIDE);
+      m_wndWaitView.Start();
+      m_wndListCtrl.DeleteAllItems();
+      _beginthread(LoadMessages, 0, m_hWnd);
+   }
+}
+
+
+//
+// WM_REQUEST_COMPLETED message handler
+//
+
+void CSyslogBrowser::OnRequestCompleted(void)
+{
+   if (m_bIsBusy)
+   {
+      m_bIsBusy = FALSE;
+      m_wndListCtrl.ShowWindow(SW_SHOW);
+      m_wndWaitView.ShowWindow(SW_HIDE);
+      m_wndWaitView.Stop();
+   }
+}
+
+
+//
+// Get save info for desktop saving
+//
+
+LRESULT CSyslogBrowser::OnGetSaveInfo(WPARAM wParam, WINDOW_SAVE_INFO *pInfo)
+{
+   pInfo->iWndClass = WNDC_SYSLOG_BROWSER;
+   GetWindowPlacement(&pInfo->placement);
+   pInfo->szParameters[0] = 0;
+   return 1;
+}
+
+
+//
+// WM_SYSLOG_RECORD message handler
+//
+
+void CSyslogBrowser::OnSyslogRecord(WPARAM wParam, NXC_SYSLOG_RECORD *pRec)
+{
+   AddRecord(pRec);
+   safe_free(pRec->pszText);
+   free(pRec);
+}
+
+
+//
+// Add new record to list
+//
+
+void CSyslogBrowser::AddRecord(NXC_SYSLOG_RECORD *pRec)
+{
+   int iIdx;
+   struct tm *ptm;
+   char szBuffer[64];
+   static int nImage[8] = { 4, 4, 3, 3, 2, 1, 0, 0 };
+
+   ptm = localtime((const time_t *)&pRec->dwTimeStamp);
+   strftime(szBuffer, 32, "%d-%b-%Y %H:%M:%S", ptm);
+   iIdx = m_wndListCtrl.InsertItem(0x7FFFFFFF, szBuffer, nImage[pRec->wSeverity]);
+   if (iIdx != -1)
+   {
+      m_wndListCtrl.SetItemText(iIdx, 1, g_szSyslogSeverity[pRec->wSeverity]);
+      if (pRec->wFacility <= 23)
+      {
+         m_wndListCtrl.SetItemText(iIdx, 2, g_szSyslogFacility[pRec->wFacility]);
+      }
+      else
+      {
+         _stprintf(szBuffer, _T("<%d>"), pRec->wFacility);
+         m_wndListCtrl.SetItemText(iIdx, 2, szBuffer);
+      }
+      m_wndListCtrl.SetItemText(iIdx, 3, pRec->szHost);
+      m_wndListCtrl.SetItemText(iIdx, 4, pRec->szTag);
+      m_wndListCtrl.SetItemText(iIdx, 5, pRec->pszText);
+
+      m_wndListCtrl.EnsureVisible(iIdx, FALSE);
+   }
+}
diff --git a/src/console/win32/SyslogBrowser.h b/src/console/win32/SyslogBrowser.h
new file mode 100644 (file)
index 0000000..f8995e7
--- /dev/null
@@ -0,0 +1,61 @@
+#if !defined(AFX_SYSLOGBROWSER_H__743A897E_9FF2_4815_BE2F_B66A2E6436B8__INCLUDED_)
+#define AFX_SYSLOGBROWSER_H__743A897E_9FF2_4815_BE2F_B66A2E6436B8__INCLUDED_
+
+#include "WaitView.h"  // Added by ClassView
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+// SyslogBrowser.h : header file
+//
+
+/////////////////////////////////////////////////////////////////////////////
+// CSyslogBrowser frame
+
+class CSyslogBrowser : public CMDIChildWnd
+{
+       DECLARE_DYNCREATE(CSyslogBrowser)
+protected:
+       CSyslogBrowser();           // protected constructor used by dynamic creation
+
+// Attributes
+public:
+
+// Operations
+public:
+
+// Overrides
+       // ClassWizard generated virtual function overrides
+       //{{AFX_VIRTUAL(CSyslogBrowser)
+       protected:
+       virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
+       //}}AFX_VIRTUAL
+
+// Implementation
+protected:
+       void AddRecord(NXC_SYSLOG_RECORD *pRec);
+       CImageList *m_pImageList;
+       BOOL m_bIsBusy;
+       CWaitView m_wndWaitView;
+       CListCtrl m_wndListCtrl;
+       virtual ~CSyslogBrowser();
+
+       // Generated message map functions
+       //{{AFX_MSG(CSyslogBrowser)
+       afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
+       afx_msg void OnDestroy();
+       afx_msg void OnSize(UINT nType, int cx, int cy);
+       afx_msg void OnSetFocus(CWnd* pOldWnd);
+       afx_msg void OnViewRefresh();
+       //}}AFX_MSG
+   afx_msg LRESULT OnGetSaveInfo(WPARAM wParam, WINDOW_SAVE_INFO *pInfo);
+   afx_msg void OnRequestCompleted(void);
+   afx_msg void OnSyslogRecord(WPARAM wParam, NXC_SYSLOG_RECORD *pRec);
+       DECLARE_MESSAGE_MAP()
+};
+
+/////////////////////////////////////////////////////////////////////////////
+
+//{{AFX_INSERT_LOCATION}}
+// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
+
+#endif // !defined(AFX_SYSLOGBROWSER_H__743A897E_9FF2_4815_BE2F_B66A2E6436B8__INCLUDED_)
index e15ea8e..87b1252 100644 (file)
@@ -93,6 +93,36 @@ TCHAR *g_szServiceType[] = { _T("User-defined"), _T("SSH"), _T("POP3"), _T("SMTP
 TCHAR *g_szDeploymentStatus[] = { _T("Pending"), _T("Uploading package"),
                                   _T("Installing"), _T("Completed"), _T("Failed"),
                                   _T("Initializing") };
+TCHAR *g_szSyslogSeverity[] = { _T("Emergency"), _T("Alert"), _T("Critical"),
+                                _T("Error"), _T("Warning"), _T("Notice"),
+                                _T("Informational"), _T("Debug") };
+TCHAR *g_szSyslogFacility[] =
+{
+   _T("Kernel"),
+   _T("User"),
+   _T("Mail"),
+   _T("System"),
+   _T("Auth"),
+   _T("Syslog"),
+   _T("Lpr"),
+   _T("News"),
+   _T("UUCP"),
+   _T("Cron"),
+   _T("Security"),
+   _T("FTP daemon"),
+   _T("NTP"),
+   _T("Log audit"),
+   _T("Log alert"),
+   _T("Clock daemon"),
+   _T("Local0"),
+   _T("Local1"),
+   _T("Local2"),
+   _T("Local3"),
+   _T("Local4"),
+   _T("Local5"),
+   _T("Local6"),
+   _T("Local7")
+};
 TCHAR *g_szInterfaceTypes[] = 
 {
    "Unknown",
index 969b1ed..a8c0d09 100644 (file)
@@ -61,6 +61,7 @@ extern CConsoleApp theApp;
 #define WNDC_ALARM_BROWSER    5
 #define WNDC_EVENT_BROWSER    6
 #define WNDC_OBJECT_BROWSER   7
+#define WNDC_SYSLOG_BROWSER   8
 
 
 //
@@ -107,6 +108,7 @@ extern CConsoleApp theApp;
 #define WM_GET_SAVE_INFO         (WM_USER + 14)
 #define WM_TABLE_DATA            (WM_USER + 15)
 #define WM_NETXMS_EVENT          (WM_USER + 16)
+#define WM_SYSLOG_RECORD         (WM_USER + 17)
 
 
 //
@@ -306,6 +308,8 @@ extern TCHAR *g_szStatusTextSmall[];
 extern TCHAR *g_szActionType[];
 extern TCHAR *g_szServiceType[];
 extern TCHAR *g_szDeploymentStatus[];
+extern TCHAR *g_szSyslogSeverity[];
+extern TCHAR *g_szSyslogFacility[];
 extern COLORREF g_statusColorTable[];
 extern char *g_szObjectClass[];
 extern char *g_szInterfaceTypes[];
index 81b1556..11da18a 100644 (file)
@@ -2,13 +2,13 @@
 
 [General Info]
 Version=1
-LastClass=CWebBrowser
+LastClass=CSyslogBrowser
 LastTemplate=CMDIChildWnd
 NewFileInclude1=#include "stdafx.h"
 NewFileInclude2=#include "nxcon.h"
 LastPage=0
 
-ClassCount=103
+ClassCount=104
 Class1=CConsoleApp
 Class3=CMainFrame
 Class4=CChildFrame
@@ -16,9 +16,9 @@ Class7=CEventBrowser
 Class9=CMapView
 
 ResourceCount=129
-Resource1=IDD_THRESHOLD (English (U.S.))
+Resource1=IDD_EDIT_RULE_ALARM (English (U.S.))
 Resource2=IDD_OBJECT_NODE_GENERAL
-Resource3=IDD_SELECT_AGENT_PARAM (English (U.S.))
+Resource3=IDD_GRAPH_PROP_SETTINGS (English (U.S.))
 Resource4=IDD_SELECT_OBJECT
 Resource5=IDD_SELECT_ACTION
 Class2=CChildView
@@ -32,9 +32,9 @@ Resource7=IDD_NEW_USER
 Class12=CObjectBrowser
 Resource8=IDD_CREATE_CONTAINER
 Class13=CObjectPropDlg
-Resource9=IDD_EDIT_TRAP (English (U.S.))
-Resource10=IDM_CONTEXT (English (U.S.))
-Resource11=IDA_ALARM_BROWSER (English (U.S.))
+Resource9=IDD_OBJECT_NODE_POLL (English (U.S.))
+Resource10=IDM_VIEW_SPECIFIC (English (U.S.))
+Resource11=IDA_LAST_VALUES (English (U.S.))
 Resource12=IDR_CTRLPANEL (English (U.S.))
 Resource13=IDR_EVENTS (English (U.S.))
 Resource14=IDR_MAPFRAME (English (U.S.))
@@ -42,17 +42,17 @@ Resource15=IDR_OBJECTS (English (U.S.))
 Resource16=IDD_DUMMY (English (U.S.))
 Class14=CEventEditor
 Class15=CEditEventDlg
-Resource17=IDD_SELECT_USER (English (U.S.))
+Resource17=IDD_THRESHOLD (English (U.S.))
 Class16=CDebugFrame
-Resource18=IDD_CHANGE_IP
+Resource18=IDA_EVENT_EDITOR (English (U.S.))
 Resource19=IDD_OBJECT_PROPERTIES (English (U.S.))
 Resource20=IDD_SELECT_EVENT
 Class17=CObjectPreview
-Resource21=IDD_EDIT_VARIABLE (English (U.S.))
+Resource21=IDA_MDI_DEFAULT (English (U.S.))
 Class18=CToolBox
 Class19=CObjectInfoBox
 Class20=CObjectSearchBox
-Resource22=IDA_ACTION_EDITOR (English (U.S.))
+Resource22=IDA_DC_EDITOR (English (U.S.))
 Class21=CEditBox
 Class22=COPGeneral
 Class23=CNodePropsGeneral
@@ -61,14 +61,14 @@ Class24=CObjectPropCaps
 Class25=CObjectPropSheet
 Resource24=IDA_MDI_DEFAULT
 Class26=CRequestProcessingDlg
-Resource25=IDD_EDIT_EVENT (English (U.S.))
+Resource25=IDD_NEW_USER (English (U.S.))
 Resource26=IDD_PROGRESS (English (U.S.))
 Resource27=IDD_EDIT_RULE_ALARM
-Resource28=IDA_LAST_VALUES (English (U.S.))
+Resource28=IDD_OBJECT_NODE_GENERAL (English (U.S.))
 Class27=CObjectPropsGeneral
-Resource29=IDD_SELECT_INTERNAL_ITEM (English (U.S.))
+Resource29=IDD_DESKTOP_SAVE_AS (English (U.S.))
 Class28=CObjectPropsSecurity
-Resource30=IDD_OBJECT_VPNC_GENERAL (English (U.S.))
+Resource30=IDA_EPP (English (U.S.))
 Resource31=IDD_SELECT_USER
 Resource32=IDD_OBJECT_SECURITY
 Class29=CUserSelectDlg
@@ -79,36 +79,36 @@ Class31=CNewUserDlg
 Resource35=IDD_THRESHOLD
 Resource36=IDA_EPP
 Class32=CUserPropDlg
-Resource37=IDD_DCI_COLLECTION (English (U.S.))
+Resource37=IDD_OBJECT_PRESENTATION (English (U.S.))
 Resource38=IDD_ABOUTBOX
 Class33=CGroupPropDlg
 Resource39=IDD_CP_GENERAL
 Resource40=IDA_TRAP_EDITOR
 Resource41=IDM_VIEW_SPECIFIC
-Resource42=IDA_DC_EDITOR (English (U.S.))
+Resource42=IDD_OBJECT_GENERAL (English (U.S.))
 Class34=CPasswordChangeDlg
 Class35=CNodeSummary
 Class36=CNetSummaryFrame
 Class37=CDataCollectionEditor
-Resource43=IDD_DCI_TRANSFORM (English (U.S.))
+Resource43=IDD_SELECT_AGENT_PARAM (English (U.S.))
 Class38=CDCIPropPage
-Resource44=IDD_OBJECT_CAPS (English (U.S.))
+Resource44=IDD_GROUP_PROPERTIES (English (U.S.))
 Class39=CDCIDataView
-Resource45=IDD_ACTION_PROPERTIES (English (U.S.))
+Resource45=IDD_DATA_QUERY (English (U.S.))
 Class40=CGraph
 Class41=CGraphFrame
 Class42=CDCIThresholdsPage
-Resource46=IDD_CP_GENERAL (English (U.S.))
-Resource47=IDD_GROUP_PROPERTIES (English (U.S.))
+Resource46=IDD_CREATE_TG (English (U.S.))
+Resource47=IDD_EDIT_RULE_COMMENT (English (U.S.))
 Resource48=IDM_CONTEXT
 Class43=CThresholdDlg
-Resource49=IDD_SELECT_ACTION (English (U.S.))
+Resource49=IDD_EDIT_TRAP (English (U.S.))
 Resource50=IDD_EDIT_TRAP_ARG
 Class44=CMIBBrowserDlg
 Class45=CEventPolicyEditor
 Class46=CRuleList
 Class47=CRuleHeader
-Resource51=IDD_EDIT_TRAP_ARG (English (U.S.))
+Resource51=IDD_OBJECT_RELATIONS (English (U.S.))
 Resource52=IDD_CREATE_NODE
 Class48=CObjectSelDlg
 Resource53=IDD_OBJECT_CAPS
@@ -117,22 +117,22 @@ Class49=CRuleCommentDlg
 Resource55=IDD_DCI_COLLECTION
 Class50=CEventSelDlg
 Resource56=IDD_DATA_QUERY
-Resource57=IDD_NEW_ACTION (English (U.S.))
+Resource57=IDD_CREATE_TEMPLATE (English (U.S.))
 Resource58=IDD_CREATE_TG
-Resource59=IDD_EDIT_RULE_COMMENT (English (U.S.))
-Resource60=IDD_EDIT_RULE_SEVERITY (English (U.S.))
+Resource59=IDD_ACTION_PROPERTIES (English (U.S.))
+Resource60=IDD_CREATE_NODE (English (U.S.))
 Class51=CObjectPropsPresentation
-Resource61=IDA_EVENT_EDITOR (English (U.S.))
+Resource61=IDA_AGENT_CFG_EDITOR (English (U.S.))
 Resource62=IDD_EDIT_RULE_COMMENT
 Class52=CRuleSeverityDlg
 Resource63=IDD_ACTION_PROPERTIES
 Class53=CRuleAlarmDlg
 Class54=CAlarmBrowser
-Resource64=IDD_NEW_USER (English (U.S.))
+Resource64=IDD_MIB_BROWSER (English (U.S.))
 Resource65=IDD_DCI_TRANSFORM
-Resource66=IDD_ABOUTBOX (English (U.S.))
-Resource67=IDD_CREATE_NETSRV (English (U.S.))
-Resource68=IDD_SET_PASSWORD (English (U.S.))
+Resource66=IDD_OBJECT_SECURITY (English (U.S.))
+Resource67=IDD_LASTVAL_PROP (English (U.S.))
+Resource68=IDD_SELECT_EVENT (English (U.S.))
 Class55=CConsolePropsGeneral
 Class56=CActionEditor
 Resource69=IDA_ACTION_EDITOR
@@ -143,18 +143,18 @@ Class58=CEditActionDlg
 Resource72=IDA_NETMAP
 Class59=CActionSelDlg
 Resource73=IDD_MIB_BROWSER
-Resource74=IDA_MDI_DEFAULT (English (U.S.))
-Resource75=IDA_PACKAGE_MGR (English (U.S.))
+Resource74=IDA_TRAP_EDITOR (English (U.S.))
+Resource75=IDD_EDIT_EVENT (English (U.S.))
 Resource76=IDD_USER_PROPERTIES
 Class60=CCreateObjectDlg
 Class61=CCreateContainerDlg
 Resource77=IDR_MAINFRAME
 Class62=CCreateNodeDlg
-Resource78=IDD_CREATE_NODE (English (U.S.))
-Resource79=IDD_SELECT_EVENT (English (U.S.))
-Resource80=IDD_OBJECT_GENERAL (English (U.S.))
+Resource78=IDD_SELECT_INTERNAL_ITEM (English (U.S.))
+Resource79=IDD_SELECT_ACTION (English (U.S.))
+Resource80=IDD_DCI_COLLECTION (English (U.S.))
 Class63=CDCITransformPage
-Resource81=IDD_INPUT_BOX (English (U.S.))
+Resource81=IDD_GRAPH_PROP_DATA (English (U.S.))
 Class64=CPollNodeDlg
 Resource82=IDD_POLL_NODE (English (U.S.))
 Class65=CNodePoller
@@ -179,69 +179,70 @@ Class72=CGraphPropDlg
 Class73=CColorSelector
 Class74=CPackageMgr
 Resource94=IDD_GROUP_PROPERTIES
-Resource95=IDD_MIB_BROWSER (English (U.S.))
-Resource96=IDD_OBJECT_NODE_GENERAL (English (U.S.))
-Resource97=IDD_OBJECT_NETSRV_GENERAL (English (U.S.))
-Resource98=IDD_CREATE_TEMPLATE (English (U.S.))
-Resource99=IDD_GRAPH_PROP_DATA (English (U.S.))
-Resource100=IDD_GRAPH_PROP_SETTINGS (English (U.S.))
-Resource101=IDD_CREATE_CONTAINER (English (U.S.))
-Resource102=IDD_USER_PROPERTIES (English (U.S.))
-Resource103=IDA_SERVER_CFG_EDITOR (English (U.S.))
-Resource104=IDD_CREATE_VPNC (English (U.S.))
-Resource105=IDA_NETMAP (English (U.S.))
-Resource106=IDD_DESKTOP_SAVE_AS (English (U.S.))
-Resource107=IDD_LOGIN (English (U.S.))
+Resource95=IDD_CP_GENERAL (English (U.S.))
+Resource96=IDD_USER_PROPERTIES (English (U.S.))
+Resource97=IDD_DCI_DATA_EXPORT (English (U.S.))
+Resource98=IDD_CREATE_NETSRV (English (U.S.))
+Resource99=IDD_REMOVE_TEMPLATE
+Resource100=IDD_EDIT_IP_SUBNET (English (U.S.))
+Resource101=IDD_EDIT_TRAP_ARG (English (U.S.))
+Resource102=IDD_SELECT_OBJECT (English (U.S.))
+Resource103=IDD_OBJECT_CAPS (English (U.S.))
+Resource104=IDA_OBJECT_BROWSER (English (U.S.))
+Resource105=IDA_SERVER_CFG_EDITOR (English (U.S.))
+Resource106=IDD_OBJECT_VPNC_GENERAL (English (U.S.))
+Resource107=IDD_SELECT_USER (English (U.S.))
 Class75=CInternalItemSelDlg
-Resource108=IDA_GRAPH (English (U.S.))
+Resource108=IDD_LOGIN (English (U.S.))
 Class76=CAgentParamSelDlg
-Resource109=IDA_EPP (English (U.S.))
+Resource109=IDA_PACKAGE_MGR (English (U.S.))
 Class77=CInputBox
-Resource110=IDA_OBJECT_BROWSER (English (U.S.))
+Resource110=IDA_GRAPH (English (U.S.))
 Class78=CCreateNetSrvDlg
-Resource111=IDM_VIEW_SPECIFIC (English (U.S.))
+Resource111=IDM_CONTEXT (English (U.S.))
 Class79=CNetSrvPropsGeneral
-Resource112=IDD_LASTVAL_PROP (English (U.S.))
+Resource112=IDD_CHANGE_IP
 Class80=CNodePropsPolling
 Class81=CDeploymentView
 Class82=CLastValuesView
 Class83=CValueList
-Resource113=IDD_REMOVE_TEMPLATE
+Resource113=IDA_NETMAP (English (U.S.))
 Class84=CObjectPropsRelations
-Resource114=IDA_TRAP_EDITOR (English (U.S.))
+Resource114=IDD_ABOUTBOX (English (U.S.))
 Class85=CSaveDesktopDlg
-Resource115=IDD_DCI_THRESHOLDS (English (U.S.))
+Resource115=IDD_EDIT_RULE_SEVERITY (English (U.S.))
 Class86=CGraphSettingsPage
-Resource116=IDD_DATA_QUERY (English (U.S.))
+Resource116=IDD_OBJECT_NETSRV_GENERAL (English (U.S.))
 Class87=CGraphDataPage
-Resource117=IDD_SELECT_OBJECT (English (U.S.))
+Resource117=IDD_NEW_ACTION (English (U.S.))
 Class88=CRemoveTemplateDlg
-Resource118=IDR_MAINFRAME (English (U.S.))
+Resource118=IDA_ACTION_EDITOR (English (U.S.))
 Class89=CAddrChangeDlg
-Resource119=IDD_OBJECT_SECURITY (English (U.S.))
+Resource119=IDD_DCI_THRESHOLDS (English (U.S.))
 Class90=CLastValuesPropDlg
 Class91=CAgentCfgEditor
-Resource120=IDD_REQUEST_PROCESSING (English (U.S.))
+Resource120=IDD_SET_PASSWORD (English (U.S.))
 Class92=CDataExportDlg
 Class93=CServerCfgEditor
-Resource121=IDD_EDIT_IP_SUBNET (English (U.S.))
-Resource122=IDD_OBJECT_RELATIONS (English (U.S.))
+Resource121=IDA_ALARM_BROWSER (English (U.S.))
+Resource122=IDD_CREATE_VPNC (English (U.S.))
 Class94=CEditVariableDlg
-Resource123=IDD_OBJECT_PRESENTATION (English (U.S.))
+Resource123=IDD_CREATE_CONTAINER (English (U.S.))
 Class95=CCreateVPNConnDlg
-Resource124=IDD_DCI_DATA_EXPORT (English (U.S.))
+Resource124=IDR_MAINFRAME (English (U.S.))
 Class96=CVPNCPropsGeneral
-Resource125=IDD_EDIT_RULE_ALARM (English (U.S.))
+Resource125=IDD_DCI_TRANSFORM (English (U.S.))
 Class97=CEditSubnetDlg
-Resource126=IDD_CREATE_TG (English (U.S.))
-Resource127=IDA_AGENT_CFG_EDITOR (English (U.S.))
+Resource126=IDD_INPUT_BOX (English (U.S.))
+Resource127=IDD_REQUEST_PROCESSING (English (U.S.))
 Class98=CModifiedAgentCfgDlg
 Class99=CSimpleSplitter
 Class100=CAdvSplitter
-Resource128=IDD_OBJECT_NODE_POLL (English (U.S.))
+Resource128=IDD_EDIT_VARIABLE (English (U.S.))
 Class101=CTableView
 Class102=CWaitView
 Class103=CWebBrowser
+Class104=CSyslogBrowser
 Resource129=IDD_SAVE_AGENT_CFG (English (U.S.))
 
 [CLS:CConsoleApp]
@@ -469,15 +470,16 @@ Command11=ID_VIEW_OBJECTBROWSER
 Command12=ID_VIEW_NETWORKSUMMARY
 Command13=ID_VIEW_ALARMS
 Command14=ID_VIEW_EVENTS
-Command15=ID_VIEW_CONTROLPANEL
-Command16=ID_VIEW_DEBUG
-Command17=ID_VIEW_TOOLBAR
-Command18=ID_VIEW_STATUS_BAR
-Command19=ID_VIEW_REFRESH
-Command20=ID_TOOLS_MIBBROWSER
-Command21=ID_TOOLS_ADDNODE
-Command22=ID_APP_ABOUT
-CommandCount=22
+Command15=ID_VIEW_SYSLOG
+Command16=ID_VIEW_CONTROLPANEL
+Command17=ID_VIEW_DEBUG
+Command18=ID_VIEW_TOOLBAR
+Command19=ID_VIEW_STATUS_BAR
+Command20=ID_VIEW_REFRESH
+Command21=ID_TOOLS_MIBBROWSER
+Command22=ID_TOOLS_ADDNODE
+Command23=ID_APP_ABOUT
+CommandCount=23
 
 [MNU:IDR_CTRLPANEL (English (U.S.))]
 Type=1
@@ -573,12 +575,13 @@ Command16=ID_PREV_PANE
 Command17=ID_VIEW_NETWORKSUMMARY
 Command18=ID_VIEW_ALARMS
 Command19=ID_VIEW_EVENTS
-Command20=ID_VIEW_CONTROLPANEL
-Command21=ID_EDIT_COPY
-Command22=ID_EDIT_PASTE
-Command23=ID_EDIT_CUT
-Command24=ID_EDIT_UNDO
-CommandCount=24
+Command20=ID_VIEW_SYSLOG
+Command21=ID_VIEW_CONTROLPANEL
+Command22=ID_EDIT_COPY
+Command23=ID_EDIT_PASTE
+Command24=ID_EDIT_CUT
+Command25=ID_EDIT_UNDO
+CommandCount=25
 
 [DLG:IDD_ABOUTBOX (English (U.S.))]
 Type=1
@@ -3503,3 +3506,11 @@ BaseClass=CMDIChildWnd
 Filter=M
 VirtualFilter=mfWC
 
+[CLS:CSyslogBrowser]
+Type=0
+HeaderFile=SyslogBrowser.h
+ImplementationFile=SyslogBrowser.cpp
+BaseClass=CMDIChildWnd
+Filter=M
+VirtualFilter=mfWC
+
index e6322ae..fc86a9d 100644 (file)
@@ -68,6 +68,7 @@ BEGIN_MESSAGE_MAP(CConsoleApp, CWinApp)
        ON_COMMAND(ID_CONTROLPANEL_SNMPTRAPS, OnControlpanelSnmptraps)
        ON_COMMAND(ID_CONTROLPANEL_AGENTPKG, OnControlpanelAgentpkg)
        ON_COMMAND(ID_CONTROLPANEL_SERVERCFG, OnControlpanelServercfg)
+       ON_COMMAND(ID_VIEW_SYSLOG, OnViewSyslog)
        //}}AFX_MSG_MAP
 END_MESSAGE_MAP()
 
@@ -83,6 +84,7 @@ CConsoleApp::CConsoleApp()
    m_bCtrlPanelActive = FALSE;
    m_bAlarmBrowserActive = FALSE;
    m_bEventBrowserActive = FALSE;
+   m_bSyslogBrowserActive = FALSE;
    m_bEventEditorActive = FALSE;
    m_bUserEditorActive = FALSE;
    m_bObjectBrowserActive = FALSE;
@@ -506,6 +508,11 @@ void CConsoleApp::OnViewCreate(DWORD dwView, CWnd *pWnd, DWORD dwArg)
          m_pwndEventBrowser = (CEventBrowser *)pWnd;
          m_hwndEventBrowser = pWnd->m_hWnd;
          break;
+      case IDR_SYSLOG_BROWSER:
+         m_bSyslogBrowserActive = TRUE;
+         m_pwndSyslogBrowser = (CSyslogBrowser *)pWnd;
+         m_hwndSyslogBrowser = pWnd->m_hWnd;
+         break;
       case IDR_OBJECTS:
          m_bObjectBrowserActive = TRUE;
          m_pwndObjectBrowser = (CObjectBrowser *)pWnd;
@@ -583,6 +590,10 @@ void CConsoleApp::OnViewDestroy(DWORD dwView, CWnd *pWnd, DWORD dwArg)
          m_bEventBrowserActive = FALSE;
          m_hwndEventBrowser = NULL;
          break;
+      case IDR_SYSLOG_BROWSER:
+         m_bSyslogBrowserActive = FALSE;
+         m_hwndSyslogBrowser = NULL;
+         break;
       case IDR_OBJECTS:
          m_bObjectBrowserActive = FALSE;
          break;
@@ -655,6 +666,30 @@ CMDIChildWnd *CConsoleApp::ShowEventBrowser(void)
 
 
 //
+// Show syslog browser window
+//
+
+CMDIChildWnd *CConsoleApp::ShowSyslogBrowser(void)
+{
+       CMainFrame *pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
+   CMDIChildWnd *pWnd;
+
+       // create a new MDI child window or open existing
+   if (m_bSyslogBrowserActive)
+   {
+      m_pwndSyslogBrowser->BringWindowToTop();
+      pWnd = m_pwndSyslogBrowser;
+   }
+   else
+   {
+          pWnd = pFrame->CreateNewChild(RUNTIME_CLASS(CSyslogBrowser), IDR_SYSLOG_BROWSER,
+                                    m_hMDIMenu, m_hMDIAccel);
+   }
+   return pWnd;
+}
+
+
+//
 // WM_COMMAND::ID_VIEW_EVENTS message handler
 //
 
@@ -665,6 +700,16 @@ void CConsoleApp::OnViewEvents()
 
 
 //
+// WM_COMMAND::ID_VIEW_SYSLOG message handler
+//
+
+void CConsoleApp::OnViewSyslog() 
+{
+   ShowSyslogBrowser();
+}
+
+
+//
 // WM_COMMAND::ID_VIEW_MAP message handler
 //
 
@@ -759,6 +804,20 @@ void CConsoleApp::EventHandler(DWORD dwEvent, DWORD dwCode, void *pArg)
                free(pData);
          }
          break;
+      case NXC_EVENT_NEW_SYSLOG_RECORD:
+         if (m_bSyslogBrowserActive)
+         {
+            NXC_SYSLOG_RECORD *pRec;
+
+            pRec = (NXC_SYSLOG_RECORD *)nx_memdup(pArg, sizeof(NXC_SYSLOG_RECORD));
+            pRec->pszText = _tcsdup(((NXC_SYSLOG_RECORD *)pArg)->pszText);
+            if (!PostMessage(m_hwndSyslogBrowser, WM_SYSLOG_RECORD, 0, (LPARAM)pRec))
+            {
+               safe_free(pRec->pszText);
+               free(pRec);
+            }
+         }
+         break;
       case NXC_EVENT_OBJECT_CHANGED:
          ((CMainFrame *)m_pMainWnd)->PostMessage(WM_OBJECT_CHANGE, dwCode, (LPARAM)pArg);
          break;
index 1946e2e..2e063d3 100644 (file)
@@ -446,6 +446,10 @@ SOURCE=.\StdAfx.cpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\SyslogBrowser.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\TableView.cpp
 # End Source File
 # Begin Source File
@@ -762,6 +766,10 @@ SOURCE=.\nxcon.h
 # End Source File
 # Begin Source File
 
+SOURCE=..\..\..\include\nxlog.h
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\..\include\nxsnmp.h
 # End Source File
 # Begin Source File
@@ -862,6 +870,10 @@ SOURCE=.\StdAfx.h
 # End Source File
 # Begin Source File
 
+SOURCE=.\SyslogBrowser.h
+# End Source File
+# Begin Source File
+
 SOURCE=.\TableView.h
 # End Source File
 # Begin Source File
index 82452ee..58e4ee8 100644 (file)
@@ -52,6 +52,7 @@ inline BOOL SafeFreeResource(HGLOBAL hRes)
 #include "TrapEditor.h"
 #include "PackageMgr.h"
 #include "ServerCfgEditor.h"
+#include "SyslogBrowser.h"
 
 
 //
@@ -115,10 +116,12 @@ protected:
        CMenu m_ctxMenu;
        DWORD m_dwClientState;
    HWND m_hwndEventBrowser;
+   HWND m_hwndSyslogBrowser;
    CActionEditor *m_pwndActionEditor;
    CTrapEditor *m_pwndTrapEditor;
        CAlarmBrowser *m_pwndAlarmBrowser;
        CEventBrowser *m_pwndEventBrowser;
+       CSyslogBrowser *m_pwndSyslogBrowser;
    CEventEditor *m_pwndEventEditor;
    CUserEditor *m_pwndUserEditor;
        CObjectBrowser *m_pwndObjectBrowser;
@@ -187,6 +190,7 @@ public:
        afx_msg void OnControlpanelSnmptraps();
        afx_msg void OnControlpanelAgentpkg();
        afx_msg void OnControlpanelServercfg();
+       afx_msg void OnViewSyslog();
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
 private:
@@ -194,6 +198,7 @@ private:
        BOOL m_bTrapEditorActive;
        BOOL m_bAlarmBrowserActive;
        BOOL m_bEventBrowserActive;
+       BOOL m_bSyslogBrowserActive;
        BOOL m_bEventEditorActive;
        BOOL m_bUserEditorActive;
        BOOL m_bObjectBrowserActive;
@@ -216,6 +221,7 @@ public:
        void UnbindObject(NXC_OBJECT *pObject);
        void BindObject(NXC_OBJECT *pObject);
        CMDIChildWnd *ShowEventBrowser(void);
+       CMDIChildWnd *ShowSyslogBrowser(void);
        CMDIChildWnd *ShowAlarmBrowser(TCHAR *pszParams = NULL);
        CMDIChildWnd *ShowNetworkSummary(void);
        void ApplyTemplate(NXC_OBJECT *pObject);
index 8adc880..bcd637d 100644 (file)
@@ -181,6 +181,7 @@ BEGIN
         MENUITEM "&Network Summary\tF7",        ID_VIEW_NETWORKSUMMARY
         MENUITEM "&Alarms\tF8",                 ID_VIEW_ALARMS
         MENUITEM "&Event Log\tCtrl+F8",         ID_VIEW_EVENTS
+        MENUITEM "S&yslog\tAlt+F8",             ID_VIEW_SYSLOG
         MENUITEM "&Control Panel\tF9",          ID_VIEW_CONTROLPANEL
         MENUITEM "&Debug\tCtrl+Shift+F12",      ID_VIEW_DEBUG
         MENUITEM SEPARATOR
@@ -756,6 +757,7 @@ BEGIN
     VK_F7,          ID_VIEW_NETWORKSUMMARY, VIRTKEY, NOINVERT
     VK_F8,          ID_VIEW_ALARMS,         VIRTKEY, NOINVERT
     VK_F8,          ID_VIEW_EVENTS,         VIRTKEY, CONTROL, NOINVERT
+    VK_F8,          ID_VIEW_SYSLOG,         VIRTKEY, ALT, NOINVERT
     VK_F9,          ID_VIEW_CONTROLPANEL,   VIRTKEY, NOINVERT
     VK_INSERT,      ID_EDIT_COPY,           VIRTKEY, CONTROL, NOINVERT
     VK_INSERT,      ID_EDIT_PASTE,          VIRTKEY, SHIFT, NOINVERT
@@ -2634,6 +2636,7 @@ END
 STRINGTABLE DISCARDABLE 
 BEGIN
     IDR_WEB_BROWSER         "\nWeb Browser\nWeb Browser"
+    IDR_SYSLOG_BROWSER      "\nSyslog\nSyslog"
     IDR_EVENT_EDITOR        "\nEvent Editor\nEvent Editor"
     IDR_USER_EDITOR         "\nUsers and Groups\nUsers and Groups"
     IDR_NETWORK_SUMMARY     "\nNetwork Summary\nNetwork Summary"
index 26c98cb..85cabfe 100644 (file)
 #define IDC_DISCARD                     1285
 #define IDC_SAVE                        1286
 #define IDR_WEB_BROWSER                 8100
+#define IDR_SYSLOG_BROWSER              8101
 #define IDR_EVENT_EDITOR                8105
 #define IDR_USER_EDITOR                 8106
 #define IDR_NETWORK_SUMMARY             8107
 #define ID_CONFIG_SAVEANDAPPLY          32952
 #define ID_ALARM_SHOWNODES              32953
 #define ID_ITEM_MOVETOTEMPLATE          32954
+#define ID_VIEW_SYSLOG                  32956
 #define IDS_GETFOLDERPATH_FAILED        61216
 #define IDS_WORKDIR_CREATION_FAILED     61217
 
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_3D_CONTROLS                     1
 #define _APS_NEXT_RESOURCE_VALUE        287
-#define _APS_NEXT_COMMAND_VALUE         32956
+#define _APS_NEXT_COMMAND_VALUE         32957
 #define _APS_NEXT_CONTROL_VALUE         1287
 #define _APS_NEXT_SYMED_VALUE           125
 #endif
index e6a6abe..c343e4f 100644 (file)
@@ -132,6 +132,9 @@ THREAD_RESULT THREAD_CALL NetReceiver(NXCL_Session *pSession)
             case CMD_EVENT_LIST_END:
                ProcessEvent(pSession, pMsg, NULL);
                break;
+            case CMD_SYSLOG_RECORDS:
+               ProcessSyslogRecords(pSession, pMsg);
+               break;
             case CMD_EVENT_DB_RECORD:
                ProcessEventDBRecord(pSession, pMsg);
                break;
index 08eee4e..94acf84 100644 (file)
@@ -104,6 +104,8 @@ DWORD LIBNXCL_EXPORTABLE NXCSyncEvents(NXC_SESSION hSession, DWORD dwMaxRecords)
    dwRetCode = ((NXCL_Session *)hSession)->WaitForRCC(dwRqId);
    if (dwRetCode == RCC_SUCCESS)
       dwRetCode = ((NXCL_Session *)hSession)->WaitForSync(INFINITE);
+   else
+      ((NXCL_Session *)hSession)->UnlockSyncOp();
 
    return dwRetCode;
 }
@@ -133,3 +135,64 @@ DWORD LIBNXCL_EXPORTABLE NXCSendEvent(NXC_SESSION hSession, DWORD dwEventCode,
 
    return ((NXCL_Session *)hSession)->WaitForRCC(dwRqId);
 }
+
+
+//
+// Process syslog records coming from server
+//
+
+void ProcessSyslogRecords(NXCL_Session *pSession, CSCPMessage *pMsg)
+{
+   DWORD i, dwNumRecords, dwId;
+   NXC_SYSLOG_RECORD rec;
+
+   dwNumRecords = pMsg->GetVariableLong(VID_NUM_RECORDS);
+   DebugPrintf(_T("ProcessSyslogRecords(): %d records in message"), dwNumRecords);
+   for(i = 0, dwId = VID_SYSLOG_MSG_BASE; i < dwNumRecords; i++)
+   {
+      rec.qwMsgId = pMsg->GetVariableInt64(dwId++);
+      rec.dwTimeStamp = pMsg->GetVariableLong(dwId++);
+      rec.wFacility = pMsg->GetVariableShort(dwId++);
+      rec.wSeverity = pMsg->GetVariableShort(dwId++);
+      rec.dwSourceObject = pMsg->GetVariableLong(dwId++);
+      pMsg->GetVariableStr(dwId++, rec.szHost, MAX_SYSLOG_HOSTNAME_LEN);
+      pMsg->GetVariableStr(dwId++, rec.szTag, MAX_SYSLOG_TAG_LEN);
+      rec.pszText = pMsg->GetVariableStr(dwId++);
+
+      // Call client's callback to handle new record
+      pSession->CallEventHandler(NXC_EVENT_NEW_SYSLOG_RECORD, 0, &rec);
+      free(rec.pszText);
+   }
+
+   // Notify requestor thread if all messages was received
+   if (pMsg->IsEndOfSequence())
+      pSession->CompleteSync(RCC_SUCCESS);
+}
+
+
+//
+// Synchronize syslog
+// This function is NOT REENTRANT
+//
+
+DWORD LIBNXCL_EXPORTABLE NXCSyncSyslog(NXC_SESSION hSession, DWORD dwMaxRecords)
+{
+   CSCPMessage msg;
+   DWORD dwRetCode, dwRqId;
+
+   dwRqId = ((NXCL_Session *)hSession)->CreateRqId();
+   ((NXCL_Session *)hSession)->PrepareForSync();
+
+   msg.SetCode(CMD_GET_SYSLOG);
+   msg.SetId(dwRqId);
+   msg.SetVariable(VID_MAX_RECORDS, dwMaxRecords);
+   ((NXCL_Session *)hSession)->SendMsg(&msg);
+
+   dwRetCode = ((NXCL_Session *)hSession)->WaitForRCC(dwRqId);
+   if (dwRetCode == RCC_SUCCESS)
+      dwRetCode = ((NXCL_Session *)hSession)->WaitForSync(INFINITE);
+   else
+      ((NXCL_Session *)hSession)->UnlockSyncOp();
+
+   return dwRetCode;
+}
index 1c4e1cc..d38a8e8 100644 (file)
@@ -98,6 +98,7 @@ private:
    DWORD m_dwNumObjects;
    INDEX *m_pIndexById;
    MUTEX m_mutexIndexAccess;
+   MUTEX m_mutexSyncOpAccess;
    SOCKET m_hSocket;
    CSCP_ENCRYPTION_CONTEXT *m_pCtx;
    MsgWaitQueue m_msgWaitQueue;
@@ -159,6 +160,7 @@ public:
    DWORD WaitForSync(DWORD dwTimeOut);
    void PrepareForSync(void);
    void CompleteSync(DWORD dwRetCode);
+   void UnlockSyncOp(void) { MutexUnlock(m_mutexSyncOpAccess); }
 
    DWORD OpenNodeDCIList(DWORD dwNodeId, NXC_DCI_LIST **ppItemList);
 
@@ -206,6 +208,7 @@ void UpdateUserFromMessage(CSCPMessage *pMsg, NXC_USER *pUser);
 
 void ProcessAlarmUpdate(NXCL_Session *pSession, CSCPMessage *pMsg);
 void ProcessEvent(NXCL_Session *pSession, CSCPMessage *pMsg, CSCP_MESSAGE *pRawMsg);
+void ProcessSyslogRecords(NXCL_Session *pSession, CSCPMessage *pMsg);
 void ProcessActionUpdate(NXCL_Session *pSession, CSCPMessage *pMsg);
 void ProcessEventDBRecord(NXCL_Session *pSession, CSCPMessage *pMsg);
 void ProcessUserDBUpdate(CSCPMessage *pMsg);
index 55f6ae5..8a23203 100644 (file)
@@ -384,6 +384,8 @@ DWORD NXCL_Session::SyncObjects(TCHAR *pszCacheFile)
    // If request was successful, wait for object list end or for disconnection
    if (dwRetCode == RCC_SUCCESS)
       dwRetCode = WaitForSync(INFINITE);
+   else
+      UnlockSyncOp();
 
    return dwRetCode;
 }
index 79f86a8..6201e45 100644 (file)
@@ -39,6 +39,7 @@ NXCL_Session::NXCL_Session()
    m_dwNumObjects = 0;
    m_pIndexById = NULL;
    m_mutexIndexAccess = MutexCreate();
+   m_mutexSyncOpAccess = MutexCreate();
    m_dwReceiverBufferSize = 4194304;     // 4MB
    m_hSocket = -1;
    m_pItemList = NULL;
@@ -75,6 +76,7 @@ NXCL_Session::~NXCL_Session()
       ThreadJoin(m_hRecvThread);
 
    MutexDestroy(m_mutexIndexAccess);
+   MutexDestroy(m_mutexSyncOpAccess);
 
    MutexLock(m_mutexEventAccess, INFINITE);
    MutexUnlock(m_mutexEventAccess);
@@ -224,6 +226,7 @@ DWORD NXCL_Session::WaitForSync(DWORD dwTimeOut)
    DWORD dwRetCode;
 
    dwRetCode = WaitForSingleObject(m_condSyncOp, dwTimeOut);
+   MutexUnlock(m_mutexSyncOpAccess);
    return (dwRetCode == WAIT_TIMEOUT) ? RCC_TIMEOUT : m_dwSyncExitCode;
 #else
    int iRetCode;
@@ -261,6 +264,7 @@ DWORD NXCL_Session::WaitForSync(DWORD dwTimeOut)
       dwResult = m_dwSyncExitCode;
    }
    pthread_mutex_unlock(&m_mutexSyncOp);
+   MutexUnlock(m_mutexSyncOpAccess);
    return dwResult;
 #endif
 }
@@ -272,6 +276,7 @@ DWORD NXCL_Session::WaitForSync(DWORD dwTimeOut)
 
 void NXCL_Session::PrepareForSync(void)
 {
+   MutexLock(m_mutexSyncOpAccess, INFINITE);
    m_dwSyncExitCode = RCC_SYSTEM_FAILURE;
 #ifdef _WIN32
    ResetEvent(m_condSyncOp);
@@ -415,6 +420,7 @@ DWORD NXCL_Session::OpenNodeDCIList(DWORD dwNodeId, NXC_DCI_LIST **ppItemList)
    }
    else
    {
+      UnlockSyncOp();
       free(m_pItemList);
    }
 
@@ -447,6 +453,8 @@ DWORD NXCL_Session::LoadEventDB(void)
    /* TODO: this probably should be recoded as loop with calls to WaitForMessage() */
    if (dwRetCode == RCC_SUCCESS)
       dwRetCode = WaitForSync(INFINITE);
+   else
+      UnlockSyncOp();
 
    MutexUnlock(m_mutexEventAccess);
    return dwRetCode;
@@ -770,6 +778,10 @@ DWORD NXCL_Session::LoadUserDB(void)
       if (dwRetCode == RCC_SUCCESS)
          m_dwFlags |= NXC_SF_USERDB_LOADED;
    }
+   else
+   {
+      UnlockSyncOp();
+   }
 
    return dwRetCode;
 }
@@ -795,8 +807,6 @@ DWORD NXCL_Session::SetSubscriptionStatus(DWORD dwChannels, int nOperation)
    DWORD dwRqId;
 
    dwRqId = CreateRqId();
-   PrepareForSync();
-   DestroyUserDB();
 
    msg.SetCode(CMD_CHANGE_SUBSCRIPTION);
    msg.SetId(dwRqId);
index 14858c7..6139ad9 100644 (file)
@@ -187,6 +187,7 @@ ClientSession::ClientSession(SOCKET hSocket, DWORD dwHostAddr)
    m_hProcessingThread = INVALID_THREAD_HANDLE;
    m_hUpdateThread = INVALID_THREAD_HANDLE;
    m_mutexSendEvents = MutexCreate();
+   m_mutexSendSyslog = MutexCreate();
    m_mutexSendObjects = MutexCreate();
    m_mutexSendAlarms = MutexCreate();
    m_mutexSendActions = MutexCreate();
@@ -220,6 +221,7 @@ ClientSession::~ClientSession()
    delete m_pUpdateQueue;
    safe_free(m_pMsgBuffer);
    MutexDestroy(m_mutexSendEvents);
+   MutexDestroy(m_mutexSendSyslog);
    MutexDestroy(m_mutexSendObjects);
    MutexDestroy(m_mutexSendAlarms);
    MutexDestroy(m_mutexSendActions);
@@ -340,7 +342,7 @@ void ClientSession::ReadThread(void)
                {
                   if (write(m_hCurrFile, pRawMsg->df, pRawMsg->dwNumVars) == (int)pRawMsg->dwNumVars)
                   {
-                     if (wFlags & MF_EOF)
+                     if (wFlags & MF_END_OF_FILE)
                      {
                         CSCPMessage msg;
 
@@ -521,45 +523,41 @@ void ClientSession::UpdateThread(void)
       switch(pUpdate->dwCategory)
       {
          case INFO_CAT_EVENT:
-            if (m_dwActiveChannels & NXC_CHANNEL_EVENTS)
-            {
-               MutexLock(m_mutexSendEvents, INFINITE);
-               m_pSendQueue->Put(CreateRawCSCPMessage(CMD_EVENT, 0, sizeof(NXC_EVENT), pUpdate->pData, NULL));
-               MutexUnlock(m_mutexSendEvents);
-            }
+            MutexLock(m_mutexSendEvents, INFINITE);
+            m_pSendQueue->Put(CreateRawCSCPMessage(CMD_EVENT, 0, sizeof(NXC_EVENT), pUpdate->pData, NULL));
+            MutexUnlock(m_mutexSendEvents);
+            free(pUpdate->pData);
+            break;
+         case INFO_CAT_SYSLOG_MSG:
+            MutexLock(m_mutexSendSyslog, INFINITE);
+            msg.SetCode(CMD_SYSLOG_RECORDS);
+            CreateMessageFromSyslogMsg(&msg, (NX_LOG_RECORD *)pUpdate->pData);
+            SendMessage(&msg);
+            MutexUnlock(m_mutexSendSyslog);
             free(pUpdate->pData);
             break;
          case INFO_CAT_OBJECT_CHANGE:
-            if (m_dwActiveChannels & NXC_CHANNEL_OBJECTS)
-            {
-               MutexLock(m_mutexSendObjects, INFINITE);
-               msg.SetCode(CMD_OBJECT_UPDATE);
-               msg.SetId(0);
-               ((NetObj *)pUpdate->pData)->CreateMessage(&msg);
-               SendMessage(&msg);
-               MutexUnlock(m_mutexSendObjects);
-               msg.DeleteAllVariables();
-            }
+            MutexLock(m_mutexSendObjects, INFINITE);
+            msg.SetCode(CMD_OBJECT_UPDATE);
+            ((NetObj *)pUpdate->pData)->CreateMessage(&msg);
+            SendMessage(&msg);
+            MutexUnlock(m_mutexSendObjects);
+            msg.DeleteAllVariables();
             ((NetObj *)pUpdate->pData)->DecRefCount();
             break;
          case INFO_CAT_ALARM:
-            if (m_dwActiveChannels & NXC_CHANNEL_ALARMS)
-            {
-               MutexLock(m_mutexSendAlarms, INFINITE);
-               msg.SetCode(CMD_ALARM_UPDATE);
-               msg.SetId(0);
-               msg.SetVariable(VID_NOTIFICATION_CODE, pUpdate->dwCode);
-               FillAlarmInfoMessage(&msg, (NXC_ALARM *)pUpdate->pData);
-               SendMessage(&msg);
-               MutexUnlock(m_mutexSendAlarms);
-               msg.DeleteAllVariables();
-            }
+            MutexLock(m_mutexSendAlarms, INFINITE);
+            msg.SetCode(CMD_ALARM_UPDATE);
+            msg.SetVariable(VID_NOTIFICATION_CODE, pUpdate->dwCode);
+            FillAlarmInfoMessage(&msg, (NXC_ALARM *)pUpdate->pData);
+            SendMessage(&msg);
+            MutexUnlock(m_mutexSendAlarms);
+            msg.DeleteAllVariables();
             free(pUpdate->pData);
             break;
          case INFO_CAT_ACTION:
             MutexLock(m_mutexSendActions, INFINITE);
             msg.SetCode(CMD_ACTION_DB_UPDATE);
-            msg.SetId(0);
             msg.SetVariable(VID_NOTIFICATION_CODE, pUpdate->dwCode);
             msg.SetVariable(VID_ACTION_ID, ((NXC_ACTION *)pUpdate->pData)->dwId);
             if (pUpdate->dwCode != NX_NOTIFY_ACTION_DELETED)
@@ -859,6 +857,9 @@ void ClientSession::ProcessingThread(void)
          case CMD_CHANGE_SUBSCRIPTION:
             ChangeSubscription(pMsg);
             break;
+         case CMD_GET_SYSLOG:
+            SendSyslog(pMsg);
+            break;
          default:
             // Pass message to loaded modules
             for(i = 0; i < g_dwNumModules; i++)
@@ -1382,7 +1383,7 @@ void ClientSession::SendAllEvents(CSCPMessage *pRequest)
                     _T("SELECT event_id,event_code,event_timestamp,event_source,")
                     _T("event_severity,event_message FROM event_log ")
                     _T("ORDER BY event_timestamp LIMIT %lu OFFSET %lu"),
-                    dwMaxRecords, dwNumRows - dwMaxRecords);
+                    dwMaxRecords, dwNumRows - min(dwNumRows, dwMaxRecords));
          break;
       case DB_SYNTAX_MSSQL:
          _sntprintf(szQuery, 1024,
@@ -1565,7 +1566,7 @@ void ClientSession::OnNewEvent(Event *pEvent)
 {
    UPDATE_INFO *pUpdate;
 
-   if (IsAuthenticated())
+   if (IsAuthenticated() && (m_dwActiveChannels & NXC_CHANNEL_EVENTS))
    {
       pUpdate = (UPDATE_INFO *)malloc(sizeof(UPDATE_INFO));
       pUpdate->dwCategory = INFO_CAT_EVENT;
@@ -1577,6 +1578,24 @@ void ClientSession::OnNewEvent(Event *pEvent)
 
 
 //
+// Handler for new syslog messages
+//
+
+void ClientSession::OnSyslogMessage(NX_LOG_RECORD *pRec)
+{
+   UPDATE_INFO *pUpdate;
+
+   if (IsAuthenticated() && (m_dwActiveChannels & NXC_CHANNEL_SYSLOG))
+   {
+      pUpdate = (UPDATE_INFO *)malloc(sizeof(UPDATE_INFO));
+      pUpdate->dwCategory = INFO_CAT_SYSLOG_MSG;
+      pUpdate->pData = nx_memdup(pRec, sizeof(NX_LOG_RECORD));
+      m_pUpdateQueue->Put(pUpdate);
+   }
+}
+
+
+//
 // Handler for object changes
 //
 
@@ -1584,7 +1603,7 @@ void ClientSession::OnObjectChange(NetObj *pObject)
 {
    UPDATE_INFO *pUpdate;
 
-   if (IsAuthenticated())
+   if (IsAuthenticated() && (m_dwActiveChannels & NXC_CHANNEL_OBJECTS))
       if (pObject->CheckAccessRights(m_dwUserId, OBJECT_ACCESS_READ))
       {
          pUpdate = (UPDATE_INFO *)malloc(sizeof(UPDATE_INFO));
@@ -3162,7 +3181,7 @@ void ClientSession::OnAlarmUpdate(DWORD dwCode, NXC_ALARM *pAlarm)
    UPDATE_INFO *pUpdate;
    NetObj *pObject;
 
-   if (IsAuthenticated())
+   if (IsAuthenticated() && (m_dwActiveChannels & NXC_CHANNEL_ALARMS))
    {
       pObject = FindObjectById(pAlarm->dwSourceObject);
       if (pObject != NULL)
@@ -5147,3 +5166,104 @@ void ClientSession::ChangeSubscription(CSCPMessage *pRequest)
    msg.SetVariable(VID_RCC, RCC_SUCCESS);
    SendMessage(&msg);
 }
+
+
+//
+// Get latest syslog records
+//
+
+void ClientSession::SendSyslog(CSCPMessage *pRequest)
+{
+   CSCPMessage msg;
+   DWORD dwRqId, dwMaxRecords, dwNumRows, dwId;
+   DB_RESULT hTempResult;
+   DB_ASYNC_RESULT hResult;
+   TCHAR szQuery[1024], szBuffer[1024];
+
+   dwRqId = pRequest->GetId();
+   dwMaxRecords = pRequest->GetVariableLong(VID_MAX_RECORDS);
+
+   // Send confirmation message
+   msg.SetCode(CMD_REQUEST_COMPLETED);
+   msg.SetId(dwRqId);
+   msg.SetVariable(VID_RCC, RCC_SUCCESS);
+   SendMessage(&msg);
+   msg.DeleteAllVariables();
+   msg.SetCode(CMD_SYSLOG_RECORDS);
+
+   MutexLock(m_mutexSendSyslog, INFINITE);
+
+   // Retrieve events from database
+   switch(g_dwDBSyntax)
+   {
+      case DB_SYNTAX_MYSQL:
+      case DB_SYNTAX_PGSQL:
+         hTempResult = DBSelect(g_hCoreDB, _T("SELECT count(*) FROM syslog"));
+         if (hTempResult != NULL)
+         {
+            if (DBGetNumRows(hTempResult) > 0)
+            {
+               dwNumRows = DBGetFieldULong(hTempResult, 0, 0);
+            }
+            else
+            {
+               dwNumRows = 0;
+            }
+            DBFreeResult(hTempResult);
+         }
+         _sntprintf(szQuery, 1024,
+                    _T("SELECT msg_id,msg_timestamp,facility,severity,")
+                    _T("source_object_id,hostname,msg_tag,msg_text FROM syslog ")
+                    _T("ORDER BY msg_timestamp LIMIT %lu OFFSET %lu"),
+                    dwMaxRecords, dwNumRows - min(dwNumRows, dwMaxRecords));
+         break;
+      case DB_SYNTAX_MSSQL:
+         _sntprintf(szQuery, 1024,
+                    _T("SELECT msg_id,msg_timestamp,facility,severity,")
+                    _T("source_object_id,hostname,msg_tag,msg_text ")
+                    _T("INTO temp_syslog_%ld FROM syslog ")
+                    _T("ORDER BY msg_timestamp DESC LIMIT %lu;"),
+                    _T("SELECT * FROM temp_syslog_%ld ORDER BY msg_timestamp;")
+                    _T("DROP TABLE temp_syslog_%ld"),
+                    m_dwIndex, dwMaxRecords, m_dwIndex, m_dwIndex);
+         break;
+      default:
+         szQuery[0] = 0;
+         break;
+   }
+   hResult = DBAsyncSelect(g_hCoreDB, szQuery);
+   if (hResult != NULL)
+   {
+      // Send events, one per message
+      for(dwId = VID_SYSLOG_MSG_BASE, dwNumRows = 0; DBFetch(hResult); dwNumRows++)
+      {
+         if (dwNumRows == 10)
+         {
+            msg.SetVariable(VID_NUM_RECORDS, dwNumRows);
+            SendMessage(&msg);
+            msg.DeleteAllVariables();
+            dwNumRows = 0;
+            dwId = VID_SYSLOG_MSG_BASE;
+         }
+         msg.SetVariable(dwId++, DBGetFieldAsyncUInt64(hResult, 0));
+         msg.SetVariable(dwId++, DBGetFieldAsyncULong(hResult, 1));
+         msg.SetVariable(dwId++, (WORD)DBGetFieldAsyncLong(hResult, 2));
+         msg.SetVariable(dwId++, (WORD)DBGetFieldAsyncLong(hResult, 3));
+         msg.SetVariable(dwId++, DBGetFieldAsyncULong(hResult, 4));
+         msg.SetVariable(dwId++, DBGetFieldAsync(hResult, 5, szBuffer, 1024));
+         msg.SetVariable(dwId++, DBGetFieldAsync(hResult, 6, szBuffer, 1024));
+         DBGetFieldAsync(hResult, 7, szBuffer, 1024);
+         DecodeSQLString(szBuffer);
+         msg.SetVariable(dwId++, szBuffer);
+      }
+      DBFreeAsyncResult(hResult);
+
+      // Send remaining records with End-Of-Sequence notification
+      msg.SetVariable(VID_NUM_RECORDS, dwNumRows);
+      msg.SetEndOfSequence();
+      SendMessage(&msg);
+      msg.DeleteAllVariables();
+   }
+
+   MutexUnlock(m_mutexSendSyslog);
+}
index f7f2ce4..05833a4 100644 (file)
@@ -231,6 +231,17 @@ static void BindMsgToNode(NX_LOG_RECORD *pRec, DWORD dwSourceIP)
 
 
 //
+// Handler for EnumerateSessions()
+//
+
+static void BroadcastSyslogMessage(ClientSession *pSession, void *pArg)
+{
+   if (pSession->IsAuthenticated())
+      pSession->OnSyslogMessage((NX_LOG_RECORD *)pArg);
+}
+
+
+//
 // Process syslog message
 //
 
@@ -241,17 +252,21 @@ static void ProcessSyslogMessage(char *psMsg, int nMsgLen, DWORD dwSourceIP)
 
    if (ParseSyslogMessage(psMsg, nMsgLen, &record))
    {
+      record.qwMsgId = m_qwMsgId++;
       BindMsgToNode(&record, dwSourceIP);
       pszEscMsg = EncodeSQLString(record.szMessage);
       _sntprintf(szQuery, 4096, 
                  _T("INSERT INTO syslog (msg_id,msg_timestamp,facility,severity,")
                  _T("source_object_id,hostname,msg_tag,msg_text) VALUES ")
                  _T("(" UINT64_FMT ",%ld,%d,%d,%ld,'%s','%s','%s')"),
-                 m_qwMsgId++, record.dwTimeStamp, record.nFacility,
+                 record.qwMsgId, record.dwTimeStamp, record.nFacility,
                  record.nSeverity, record.dwSourceObject,
                  record.szHostName, record.szTag, pszEscMsg);
       free(pszEscMsg);
       DBQuery(g_hCoreDB, szQuery);
+
+      // Send message to all connected clients
+      EnumerateClientSessions(BroadcastSyslogMessage, &record);
    }
 }
 
@@ -327,6 +342,26 @@ THREAD_RESULT THREAD_CALL SyslogDaemon(void *pArg)
       }
    }
 
-   DbgPrintf(AF_DEBUG_SNMP, _T("SNMP Trap Receiver terminated"));
+   DbgPrintf(AF_DEBUG_MISC, _T("Syslog Daemon stopped"));
    return THREAD_OK;
 }
+
+
+//
+// Create NXCP message from NX_LOG_RECORd structure
+//
+
+void CreateMessageFromSyslogMsg(CSCPMessage *pMsg, NX_LOG_RECORD *pRec)
+{
+   DWORD dwId = VID_SYSLOG_MSG_BASE;
+
+   pMsg->SetVariable(VID_NUM_RECORDS, (DWORD)1);
+   pMsg->SetVariable(dwId++, pRec->qwMsgId);
+   pMsg->SetVariable(dwId++, pRec->dwTimeStamp);
+   pMsg->SetVariable(dwId++, (WORD)pRec->nFacility);
+   pMsg->SetVariable(dwId++, (WORD)pRec->nSeverity);
+   pMsg->SetVariable(dwId++, pRec->dwSourceObject);
+   pMsg->SetVariable(dwId++, pRec->szHostName);
+   pMsg->SetVariable(dwId++, pRec->szTag);
+   pMsg->SetVariable(dwId++, pRec->szMessage);
+}
index 5cc7f1f..d267a06 100644 (file)
@@ -214,6 +214,7 @@ typedef void * HSNMPSESSION;
 #define INFO_CAT_OBJECT_CHANGE   2
 #define INFO_CAT_ALARM           3
 #define INFO_CAT_ACTION          4
+#define INFO_CAT_SYSLOG_MSG      5
 
 
 //
@@ -260,6 +261,7 @@ private:
    THREAD m_hProcessingThread;
    THREAD m_hUpdateThread;
    MUTEX m_mutexSendEvents;
+   MUTEX m_mutexSendSyslog;
    MUTEX m_mutexSendObjects;
    MUTEX m_mutexSendAlarms;
    MUTEX m_mutexSendActions;
@@ -374,6 +376,7 @@ private:
    void SendObjectTools(DWORD dwRqId);
    void ExecTableTool(CSCPMessage *pRequest);
    void ChangeSubscription(CSCPMessage *pRequest);
+   void SendSyslog(CSCPMessage *pRequest);
 
 public:
    ClientSession(SOCKET hSocket, DWORD dwHostAddr);
@@ -400,6 +403,7 @@ public:
    void Notify(DWORD dwCode, DWORD dwData = 0);
 
    void OnNewEvent(Event *pEvent);
+   void OnSyslogMessage(NX_LOG_RECORD *pRec);
    void OnObjectChange(NetObj *pObject);
    void OnUserDBUpdate(int iCode, DWORD dwUserId, NMS_USER *pUser, NMS_USER_GROUP *pGroup);
    void OnAlarmUpdate(DWORD dwCode, NXC_ALARM *pAlarm);
@@ -509,6 +513,8 @@ BOOL IsTableTool(DWORD dwToolId);
 BOOL CheckObjectToolAccess(DWORD dwToolId, DWORD dwUserId);
 DWORD ExecuteTableTool(DWORD dwToolId, Node *pNode, DWORD dwRqId, ClientSession *pSession);
 
+void CreateMessageFromSyslogMsg(CSCPMessage *pMsg, NX_LOG_RECORD *pRec);
+
 #ifdef _WIN32
 
 char NXCORE_EXPORTABLE *GetSystemErrorText(DWORD error);