- Added support for SNMPv2c
authorVictor Kirhenshtein <victor@netxms.org>
Sat, 30 Oct 2004 11:37:34 +0000 (11:37 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Sat, 30 Oct 2004 11:37:34 +0000 (11:37 +0000)
- Started work on SNMP traps processing
- Status icons in Win32 console improved
- Full event template editing implemented
- Implemented status icons on top of object icon in object browser

42 files changed:
.gitattributes
include/nms_cscp.h
include/nxclapi.h
src/console/cmdline/nxcmd.dsp
src/console/win32/ControlPanel.cpp
src/console/win32/EditEventDlg.cpp
src/console/win32/EditEventDlg.h
src/console/win32/EventEditor.cpp
src/console/win32/EventEditor.h
src/console/win32/EventSelDlg.cpp
src/console/win32/MainFrm.cpp
src/console/win32/NodePropsGeneral.cpp
src/console/win32/NodePropsGeneral.h
src/console/win32/ObjectBrowser.cpp
src/console/win32/ObjectBrowser.h
src/console/win32/comm.cpp
src/console/win32/icons/ovl_status_major.ico
src/console/win32/icons/ovl_status_minor.ico
src/console/win32/icons/ovl_status_unmanaged.ico
src/console/win32/icons/ovl_status_warning.ico
src/console/win32/nxcon.clw
src/console/win32/nxcon.cpp
src/console/win32/nxcon.rc
src/console/win32/resource.h
src/libnxcl/comm.cpp
src/libnxcl/eventdb.cpp
src/libnxcl/libnxcl.h
src/libnxcl/main.cpp
src/libnxcl/objects.cpp
src/server/core/Makefile.am
src/server/core/admin.cpp
src/server/core/client.cpp
src/server/core/id.cpp
src/server/core/main.cpp
src/server/core/netxmsd.dsp
src/server/core/nms_core.h
src/server/core/node.cpp
src/server/core/nortel.cpp
src/server/core/session.cpp
src/server/core/snmp.cpp
src/server/core/snmptrap.cpp [new file with mode: 0644]
src/server/tools/nxdbmgr/nxdbmgr.cpp

index 010fed6..c554a1c 100644 (file)
@@ -475,6 +475,7 @@ src/server/core/objects.cpp -text
 src/server/core/rootobj.cpp -text
 src/server/core/session.cpp -text
 src/server/core/snmp.cpp -text
+src/server/core/snmptrap.cpp -text
 src/server/core/status.cpp -text
 src/server/core/subnet.cpp -text
 src/server/core/syncer.cpp -text
index 781b190..d2ef0b0 100644 (file)
@@ -186,11 +186,11 @@ typedef struct
 #define CMD_CLOSE_EPP               0x0015
 #define CMD_SAVE_EPP                0x0016
 #define CMD_EPP_RECORD              0x0017
-#define CMD_OPEN_EVENT_DB           0x0018
-#define CMD_CLOSE_EVENT_DB          0x0019
+#define CMD_LOCK_EVENT_DB           0x0018
+#define CMD_UNLOCK_EVENT_DB         0x0019
 #define CMD_SET_EVENT_INFO          0x001A
 #define CMD_EVENT_DB_RECORD         0x001B
-#define CMD_EVENT_DB_EOF            0x001C
+#define CMD_LOAD_EVENT_DB           0x001C
 #define CMD_REQUEST_COMPLETED       0x001D
 #define CMD_LOAD_USER_DB            0x001E
 #define CMD_USER_DATA               0x001F
@@ -255,6 +255,8 @@ typedef struct
 #define CMD_POLLING_INFO            0x005A
 #define CMD_COPY_DCI                0x005B
 #define CMD_WAKEUP_NODE             0x005C
+#define CMD_DELETE_EVENT_TEMPLATE   0x005D
+#define CMD_GENERATE_EVENT_ID       0x005E
 
 
 //
index 3a9a70f..39a4600 100644 (file)
@@ -231,6 +231,7 @@ typedef unsigned long HREQUEST;
 #define RCC_INVALID_EVENT_CODE      ((DWORD)25)
 #define RCC_NO_WOL_INTERFACES       ((DWORD)26)
 #define RCC_NO_MAC_ADDRESS          ((DWORD)27)
+#define RCC_NOT_IMPLEMENTED         ((DWORD)28)
 
 
 //
@@ -444,18 +445,6 @@ typedef struct
 
 
 //
-// Event name/code pair
-//
-
-typedef struct
-{
-   DWORD dwEventId;
-   DWORD dwSeverity;
-   TCHAR szName[MAX_EVENT_NAME];
-} NXC_EVENT_NAME;
-
-
-//
 // Image information
 //
 
@@ -559,6 +548,7 @@ typedef struct
          WORD wAgentPort;     // Listening TCP port for native agent
          WORD wAuthMethod;    // Native agent's authentication method
          TCHAR *pszDescription;
+         WORD wSNMPVersion;
       } node;
       struct
       {
@@ -591,12 +581,12 @@ typedef struct
    int iAgentPort;
    int iAuthType;
    TCHAR *pszSecret;
-   int iSnmpVersion;
    TCHAR *pszCommunity;
    BOOL bInheritRights;
    DWORD dwImage;
    DWORD dwAclSize;
    NXC_ACL_ENTRY *pAccessList;
+   WORD wSNMPVersion;
 } NXC_OBJECT_UPDATE;
 
 
@@ -853,14 +843,15 @@ DWORD LIBNXCL_EXPORTABLE NXCLoadCCList(NXC_CC_LIST **ppList);
 void LIBNXCL_EXPORTABLE NXCDestroyCCList(NXC_CC_LIST *pList);
 
 DWORD LIBNXCL_EXPORTABLE NXCSyncEvents(void);
-DWORD LIBNXCL_EXPORTABLE NXCOpenEventDB(void);
-DWORD LIBNXCL_EXPORTABLE NXCCloseEventDB(BOOL bSaveChanges);
+DWORD LIBNXCL_EXPORTABLE NXCLoadEventDB(void);
+DWORD LIBNXCL_EXPORTABLE NXCSetEventInfo(NXC_EVENT_TEMPLATE *pArg);
+DWORD LIBNXCL_EXPORTABLE NXCGenerateEventId(DWORD *pdwEventId);
+void LIBNXCL_EXPORTABLE NXCAddEventTemplate(NXC_EVENT_TEMPLATE *pEventTemplate);
+void LIBNXCL_EXPORTABLE NXCDeleteEDBRecord(DWORD dwEventId);
+DWORD LIBNXCL_EXPORTABLE NXCDeleteEventTemplate(DWORD dwEventId);
+DWORD LIBNXCL_EXPORTABLE NXCLockEventDB(void);
+DWORD LIBNXCL_EXPORTABLE NXCUnlockEventDB(void);
 BOOL LIBNXCL_EXPORTABLE NXCGetEventDB(NXC_EVENT_TEMPLATE ***pppTemplateList, DWORD *pdwNumRecords);
-void LIBNXCL_EXPORTABLE NXCModifyEventTemplate(NXC_EVENT_TEMPLATE *pEvent, DWORD dwMask, 
-                                       DWORD dwSeverity, DWORD dwFlags, const TCHAR *pszName,
-                                       const TCHAR *pszMessage, const TCHAR *pszDescription);
-DWORD LIBNXCL_EXPORTABLE NXCLoadEventNames(void);
-NXC_EVENT_NAME LIBNXCL_EXPORTABLE *NXCGetEventNamesList(DWORD *pdwNumEvents);
 const TCHAR LIBNXCL_EXPORTABLE *NXCGetEventName(DWORD dwId);
 int LIBNXCL_EXPORTABLE NXCGetEventSeverity(DWORD dwId);
 DWORD LIBNXCL_EXPORTABLE NXCSendEvent(DWORD dwEventCode, DWORD dwObjectId, int iNumArgs, TCHAR **pArgList);
index 4fd2efd..676c3df 100644 (file)
@@ -42,7 +42,7 @@ RSC=rc.exe
 # PROP Ignore_Export_Lib 0
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
 # ADD BASE RSC /l 0x409 /d "NDEBUG"
 # ADD RSC /l 0x409 /d "NDEBUG"
 BSC32=bscmake.exe
@@ -66,7 +66,7 @@ LINK32=link.exe
 # PROP Ignore_Export_Lib 0
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
 # ADD BASE RSC /l 0x409 /d "_DEBUG"
 # ADD RSC /l 0x409 /d "_DEBUG"
 BSC32=bscmake.exe
index 1ecb245..2655588 100644 (file)
@@ -72,7 +72,6 @@ int CControlPanel::OnCreate(LPCREATESTRUCT lpCreateStruct)
    m_pImageList->Add(AfxGetApp()->LoadIcon(IDI_USER_GROUP));
    m_pImageList->Add(AfxGetApp()->LoadIcon(IDI_LOG));
    m_pImageList->Add(AfxGetApp()->LoadIcon(IDI_EXEC));
-   m_pImageList->Add(AfxGetApp()->LoadIcon(IDI_DCT));
    m_wndListCtrl.SetImageList(m_pImageList, LVSIL_NORMAL);
 
    // Populate list with items
@@ -80,7 +79,6 @@ int CControlPanel::OnCreate(LPCREATESTRUCT lpCreateStruct)
    AddItem("Users", 1, ID_CONTROLPANEL_USERS);
    AddItem("Events", 2, ID_CONTROLPANEL_EVENTS);
    AddItem("Actions", 3, ID_CONTROLPANEL_ACTIONS);
-   AddItem("Data Collection Templates", 4, ID_CONTROLPANEL_DCT);
 
    theApp.OnViewCreate(IDR_CTRLPANEL, this);
        return 0;
index c093576..9d1a54e 100644 (file)
@@ -62,3 +62,16 @@ BOOL CEditEventDlg::OnInitDialog()
    
        return TRUE;
 }
+
+
+//
+// Handle "OK" button
+//
+
+void CEditEventDlg::OnOK() 
+{
+   m_dwSeverity = m_wndComboBox.GetCurSel();
+       
+       CDialog::OnOK();
+}
+
index 7e72f24..a920a16 100644 (file)
@@ -42,6 +42,7 @@ protected:
        // Generated message map functions
        //{{AFX_MSG(CEditEventDlg)
        virtual BOOL OnInitDialog();
+       virtual void OnOK();
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
 };
index 25c0d33..316ea73 100644 (file)
@@ -19,7 +19,6 @@ IMPLEMENT_DYNCREATE(CEventEditor, CMDIChildWnd)
 
 CEventEditor::CEventEditor()
 {
-   m_bModified = FALSE;
    m_pImageList = NULL;
 }
 
@@ -36,6 +35,12 @@ BEGIN_MESSAGE_MAP(CEventEditor, CMDIChildWnd)
        ON_WM_SIZE()
        ON_WM_SETFOCUS()
        ON_WM_CLOSE()
+       ON_WM_CONTEXTMENU()
+       ON_UPDATE_COMMAND_UI(ID_EVENT_EDIT, OnUpdateEventEdit)
+       ON_COMMAND(ID_EVENT_EDIT, OnEventEdit)
+       ON_UPDATE_COMMAND_UI(ID_EVENT_DELETE, OnUpdateEventDelete)
+       ON_COMMAND(ID_EVENT_NEW, OnEventNew)
+       ON_COMMAND(ID_EVENT_DELETE, OnEventDelete)
        //}}AFX_MSG_MAP
    ON_NOTIFY(NM_DBLCLK, IDC_LIST_VIEW, OnListViewDoubleClick)
 END_MESSAGE_MAP()
@@ -47,7 +52,7 @@ END_MESSAGE_MAP()
 int CEventEditor::OnCreate(LPCREATESTRUCT lpCreateStruct) 
 {
    RECT rect;
-   char szBuffer[32];
+   TCHAR szBuffer[32];
    DWORD i;
 
        if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
@@ -63,36 +68,25 @@ int CEventEditor::OnCreate(LPCREATESTRUCT lpCreateStruct)
    m_wndListCtrl.SetHoverTime(0x7FFFFFFF);
 
    // Setup columns
-   m_wndListCtrl.InsertColumn(0, "ID", LVCFMT_LEFT, 50);
-   m_wndListCtrl.InsertColumn(1, "Name", LVCFMT_LEFT, 120);
-   m_wndListCtrl.InsertColumn(2, "Severity", LVCFMT_LEFT, 70);
-   m_wndListCtrl.InsertColumn(3, "Flags", LVCFMT_LEFT, 40);
-   m_wndListCtrl.InsertColumn(4, "Message", LVCFMT_LEFT, 180);
-   m_wndListCtrl.InsertColumn(5, "Description", LVCFMT_LEFT, 300);
+   m_wndListCtrl.InsertColumn(0, _T("ID"), LVCFMT_LEFT, 60);
+   m_wndListCtrl.InsertColumn(1, _T("Name"), LVCFMT_LEFT, 190);
+   m_wndListCtrl.InsertColumn(2, _T("Severity"), LVCFMT_LEFT, 70);
+   m_wndListCtrl.InsertColumn(3, _T("Flags"), LVCFMT_LEFT, 40);
+   m_wndListCtrl.InsertColumn(4, _T("Message"), LVCFMT_LEFT, 300);
+   m_wndListCtrl.InsertColumn(5, _T("Description"), LVCFMT_LEFT, 300);
        
    // Create image list
-   m_pImageList = new CImageList;
-   m_pImageList->Create(16, 16, ILC_COLOR8 | ILC_MASK, 8, 8);
-   m_pImageList->Add(theApp.LoadIcon(IDI_SEVERITY_NORMAL));
-   m_pImageList->Add(theApp.LoadIcon(IDI_SEVERITY_WARNING));
-   m_pImageList->Add(theApp.LoadIcon(IDI_SEVERITY_MINOR));
-   m_pImageList->Add(theApp.LoadIcon(IDI_SEVERITY_MAJOR));
-   m_pImageList->Add(theApp.LoadIcon(IDI_SEVERITY_CRITICAL));
+   m_pImageList = CreateEventImageList();
    m_wndListCtrl.SetImageList(m_pImageList, LVSIL_SMALL);
 
    // Load event templates
    NXCGetEventDB(&m_ppEventTemplates, &m_dwNumTemplates);
    for(i = 0; i < m_dwNumTemplates; i++)
    {
-      sprintf(szBuffer, "%ld", m_ppEventTemplates[i]->dwCode);
+      _stprintf(szBuffer, _T("%ld"), m_ppEventTemplates[i]->dwCode);
       m_wndListCtrl.InsertItem(i, szBuffer, m_ppEventTemplates[i]->dwSeverity);
-      m_wndListCtrl.SetItemText(i, 1, m_ppEventTemplates[i]->szName);
-      m_wndListCtrl.SetItemText(i, 2, g_szStatusTextSmall[m_ppEventTemplates[i]->dwSeverity]);
-      sprintf(szBuffer, "%ld", m_ppEventTemplates[i]->dwFlags);
-      m_wndListCtrl.SetItemText(i, 3, szBuffer);
-      m_wndListCtrl.SetItemText(i, 4, m_ppEventTemplates[i]->pszMessage);
-      m_wndListCtrl.SetItemText(i, 5, m_ppEventTemplates[i]->pszDescription);
-      m_wndListCtrl.SetItemData(i, i);
+      m_wndListCtrl.SetItemData(i, m_ppEventTemplates[i]->dwCode);
+      UpdateItem(i, m_ppEventTemplates[i]);
    }
 
    return 0;
@@ -100,6 +94,24 @@ int CEventEditor::OnCreate(LPCREATESTRUCT lpCreateStruct)
 
 
 //
+// Update list view item
+//
+
+void CEventEditor::UpdateItem(int iItem, NXC_EVENT_TEMPLATE *pData)
+{
+   TCHAR szBuffer[32];
+
+   m_wndListCtrl.SetItem(iItem, 0, LVIF_IMAGE, NULL, pData->dwSeverity, 0, 0, 0);
+   m_wndListCtrl.SetItemText(iItem, 1, pData->szName);
+   m_wndListCtrl.SetItemText(iItem, 2, g_szStatusTextSmall[pData->dwSeverity]);
+   _stprintf(szBuffer, _T("%ld"), pData->dwFlags);
+   m_wndListCtrl.SetItemText(iItem, 3, szBuffer);
+   m_wndListCtrl.SetItemText(iItem, 4, pData->pszMessage);
+   m_wndListCtrl.SetItemText(iItem, 5, pData->pszDescription);
+}
+
+
+//
 // WM_DESTROY message handler
 //
 
@@ -137,31 +149,56 @@ void CEventEditor::OnListViewDoubleClick(NMITEMACTIVATE *pInfo, LRESULT *pResult
 // Edit currently selected event
 //
 
-void CEventEditor::EditEvent(int iItem)
+BOOL CEventEditor::EditEvent(int iItem)
 {
-   int iIdx;
-   DWORD dwFlags;
+   DWORD dwIndex, dwResult, dwId;
    CEditEventDlg dlgEditEvent;
+   BOOL bResult = FALSE;
 
-   iIdx = m_wndListCtrl.GetItemData(iItem);
-
-   dlgEditEvent.m_bWriteLog = m_ppEventTemplates[iIdx]->dwFlags & EF_LOG;
-   dlgEditEvent.m_dwEventId = m_ppEventTemplates[iIdx]->dwCode;
-   dlgEditEvent.m_strName = m_ppEventTemplates[iIdx]->szName;
-   dlgEditEvent.m_strMessage = m_ppEventTemplates[iIdx]->pszMessage;
-   dlgEditEvent.m_strDescription = m_ppEventTemplates[iIdx]->pszDescription;
-   dlgEditEvent.m_dwSeverity = m_ppEventTemplates[iIdx]->dwSeverity;
+   dwId = m_wndListCtrl.GetItemData(iItem);
+   for(dwIndex = 0; dwIndex < m_dwNumTemplates; dwIndex++)
+      if (m_ppEventTemplates[dwIndex]->dwCode == dwId)
+         break;
 
-   if (dlgEditEvent.DoModal() == IDOK)
+   if (dwIndex < m_dwNumTemplates)
    {
-      dwFlags = 0;
-      if (dlgEditEvent.m_bWriteLog)
-         dwFlags |= EF_LOG;
-      NXCModifyEventTemplate(m_ppEventTemplates[iIdx], EM_ALL, dlgEditEvent.m_dwSeverity,
-         dwFlags, (LPCTSTR)dlgEditEvent.m_strName, (LPCTSTR)dlgEditEvent.m_strMessage,
-         (LPCTSTR)dlgEditEvent.m_strDescription);
-      m_bModified = TRUE;
+      dlgEditEvent.m_bWriteLog = m_ppEventTemplates[dwIndex]->dwFlags & EF_LOG;
+      dlgEditEvent.m_dwEventId = m_ppEventTemplates[dwIndex]->dwCode;
+      dlgEditEvent.m_strName = m_ppEventTemplates[dwIndex]->szName;
+      dlgEditEvent.m_strMessage = m_ppEventTemplates[dwIndex]->pszMessage;
+      dlgEditEvent.m_strDescription = m_ppEventTemplates[dwIndex]->pszDescription;
+      dlgEditEvent.m_dwSeverity = m_ppEventTemplates[dwIndex]->dwSeverity;
+
+      if (dlgEditEvent.DoModal() == IDOK)
+      {
+         NXC_EVENT_TEMPLATE evt;
+
+         evt.dwCode = m_ppEventTemplates[dwIndex]->dwCode;
+         evt.dwFlags = dlgEditEvent.m_bWriteLog ? EF_LOG : 0;
+         evt.dwSeverity = dlgEditEvent.m_dwSeverity;
+         evt.pszDescription = _tcsdup((LPCTSTR)dlgEditEvent.m_strDescription);
+         evt.pszMessage = _tcsdup((LPCTSTR)dlgEditEvent.m_strMessage);
+         _tcsncpy(evt.szName, (LPCTSTR)dlgEditEvent.m_strName, MAX_EVENT_NAME);
+
+         dwResult = DoRequestArg1(NXCSetEventInfo, &evt, _T("Updating event configuration database..."));
+         if (dwResult == RCC_SUCCESS)
+         {
+            // Record was successfully updated on server, update local copy
+            safe_free(m_ppEventTemplates[dwIndex]->pszDescription);
+            safe_free(m_ppEventTemplates[dwIndex]->pszMessage);
+            memcpy(m_ppEventTemplates[dwIndex], &evt, sizeof(NXC_EVENT_TEMPLATE));
+            UpdateItem(iItem, m_ppEventTemplates[dwIndex]);
+            bResult = TRUE;
+         }
+         else
+         {
+            theApp.ErrorBox(dwResult, _T("Unable to update event configuration record: %s"));
+            safe_free(evt.pszDescription);
+            safe_free(evt.pszMessage);
+         }
+      }
    }
+   return bResult;
 }
 
 
@@ -182,40 +219,120 @@ void CEventEditor::OnSetFocus(CWnd* pOldWnd)
 
 void CEventEditor::OnClose() 
 {
-   static char szClosingMessage[] = "Closing event configuration database...";
-   int iAction;
    DWORD dwResult;
 
-   if (m_bModified)
+   dwResult = DoRequest(NXCUnlockEventDB, _T("Unlocking event configuration database..."));
+   if (dwResult != RCC_SUCCESS)
+      theApp.ErrorBox(dwResult, _T("Unable to unlock event configuration database: %s"));
+       CMDIChildWnd::OnClose();
+}
+
+
+//
+// PreCreateWindow()
+//
+
+BOOL CEventEditor::PreCreateWindow(CREATESTRUCT& cs) 
+{
+   if (cs.lpszClass == NULL)
+      cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW, NULL, NULL, 
+                                         AfxGetApp()->LoadIcon(IDI_LOG));
+       return CMDIChildWnd::PreCreateWindow(cs);
+}
+
+
+//
+// WM_CONTEXTMENU message handler
+//
+
+void CEventEditor::OnContextMenu(CWnd* pWnd, CPoint point) 
+{
+   CMenu *pMenu;
+
+   pMenu = theApp.GetContextMenu(10);
+   pMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this, NULL);
+}
+
+
+//
+// OnUpdate...() handlers
+//
+
+void CEventEditor::OnUpdateEventEdit(CCmdUI* pCmdUI) 
+{
+   pCmdUI->Enable(m_wndListCtrl.GetSelectedCount() == 1);
+}
+
+void CEventEditor::OnUpdateEventDelete(CCmdUI* pCmdUI) 
+{
+   pCmdUI->Enable(m_wndListCtrl.GetSelectedCount() > 0);
+}
+
+
+//
+// WM_COMMAND::ID_EVENT_EDIT message handler
+//
+
+void CEventEditor::OnEventEdit() 
+{
+   int iItem;
+
+   if (m_wndListCtrl.GetSelectedCount() == 1)
+   {
+      iItem = m_wndListCtrl.GetNextItem(-1, LVIS_FOCUSED);
+      if (iItem != -1)
+         EditEvent(iItem);
+   }
+}
+
+
+//
+// WM_COMMAND::ID_EVENT_NEW message handler
+//
+
+void CEventEditor::OnEventNew() 
+{
+   DWORD dwNewId, dwResult;
+   NXC_EVENT_TEMPLATE *pData;
+   TCHAR szBuffer[32];
+   int iItem;
+
+   dwResult = DoRequestArg1(NXCGenerateEventId, &dwNewId, _T("Generating ID for new event..."));
+   if (dwResult == RCC_SUCCESS)
    {
-      iAction = MessageBox("Event configuration database has been modified. "
-                           "Do you wish to save it?", "Event Editor", 
-                           MB_YESNOCANCEL | MB_ICONQUESTION);
-      switch(iAction)
+      // Create new item in list view
+      _stprintf(szBuffer, _T("%ld"), dwNewId);
+      iItem = m_wndListCtrl.InsertItem(0x7FFFFFFF, szBuffer, 0);
+      m_wndListCtrl.SetItemData(iItem, dwNewId);
+
+      // Create empty record in template list
+      pData = (NXC_EVENT_TEMPLATE *)malloc(sizeof(NXC_EVENT_TEMPLATE));
+      memset(pData, 0, sizeof(NXC_EVENT_TEMPLATE));
+      pData->dwCode = dwNewId;
+      NXCAddEventTemplate(pData);
+
+      // Pointers inside client library can change after adding new template, so we reget it
+      NXCGetEventDB(&m_ppEventTemplates, &m_dwNumTemplates);
+
+      // Edit new event
+      if (!EditEvent(iItem))
       {
-         case IDYES:
-            dwResult = DoRequestArg1(NXCCloseEventDB, (void *)TRUE, szClosingMessage);
-            if (dwResult == RCC_SUCCESS)
-            {
-                  CMDIChildWnd::OnClose();
-            }
-            else
-            {
-               theApp.ErrorBox(dwResult, "Error closing event configuration database:\n%s",
-                               "Event Editor");
-            }
-            break;
-         case IDNO:
-            dwResult = DoRequestArg1(NXCCloseEventDB, (void *)FALSE, szClosingMessage);
-          CMDIChildWnd::OnClose();
-            break;
-         case IDCANCEL:
-            break;
+         m_wndListCtrl.DeleteItem(iItem);
+         NXCDeleteEDBRecord(dwNewId);
+         NXCGetEventDB(&m_ppEventTemplates, &m_dwNumTemplates);
       }
    }
    else
    {
-      dwResult = DoRequestArg1(NXCCloseEventDB, (void *)FALSE, szClosingMessage);
-          CMDIChildWnd::OnClose();
+      theApp.ErrorBox(dwResult, _T("Unable to generate ID for new event: %s"));
    }
 }
+
+
+//
+// WM_COMMAND::ID_EVENT_DELETE message handler
+//
+
+void CEventEditor::OnEventDelete() 
+{
+}
index 3cfd640..cbb5ec8 100644 (file)
@@ -25,13 +25,15 @@ public:
 // Overrides
        // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(CEventEditor)
+       protected:
+       virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
        //}}AFX_VIRTUAL
 
 // Implementation
 protected:
+       void UpdateItem(int iItem, NXC_EVENT_TEMPLATE *pData);
        CImageList *m_pImageList;
-       BOOL m_bModified;
-       void EditEvent(int iItem);
+       BOOL EditEvent(int iItem);
        afx_msg void OnListViewDoubleClick(NMITEMACTIVATE *pInfo, LRESULT *pResult);
        DWORD m_dwNumTemplates;
        NXC_EVENT_TEMPLATE ** m_ppEventTemplates;
@@ -45,6 +47,12 @@ protected:
        afx_msg void OnSize(UINT nType, int cx, int cy);
        afx_msg void OnSetFocus(CWnd* pOldWnd);
        afx_msg void OnClose();
+       afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
+       afx_msg void OnUpdateEventEdit(CCmdUI* pCmdUI);
+       afx_msg void OnEventEdit();
+       afx_msg void OnUpdateEventDelete(CCmdUI* pCmdUI);
+       afx_msg void OnEventNew();
+       afx_msg void OnEventDelete();
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
 };
index d1b80bd..dbc9ee8 100644 (file)
@@ -56,7 +56,7 @@ END_MESSAGE_MAP()
 
 BOOL CEventSelDlg::OnInitDialog() 
 {
-   NXC_EVENT_NAME *pList;
+   NXC_EVENT_TEMPLATE **pList;
    DWORD i, dwListSize;
    char szBuffer[32];
    RECT rect;
@@ -69,7 +69,6 @@ BOOL CEventSelDlg::OnInitDialog()
    m_wndListCtrl.SetImageList(m_pImageList, LVSIL_SMALL);
 
    // Setup list control
-   //m_wndListCtrl.SetImageList(&m_imageList, LVSIL_SMALL);
    m_wndListCtrl.GetClientRect(&rect);
    m_wndListCtrl.InsertColumn(0, "ID", LVCFMT_LEFT, 70);
    m_wndListCtrl.InsertColumn(1, "Name", LVCFMT_LEFT, 
@@ -77,14 +76,14 @@ BOOL CEventSelDlg::OnInitDialog()
    m_wndListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT);
        
    // Fill in event list
-   pList = NXCGetEventNamesList(&dwListSize);
+   NXCGetEventDB(&pList, &dwListSize);
    if (pList != NULL)
       for(i = 0; i < dwListSize; i++)
       {
-         sprintf(szBuffer, "%u", pList[i].dwEventId);
-         iItem = m_wndListCtrl.InsertItem(0x7FFFFFFF, szBuffer, pList[i].dwSeverity);
-         m_wndListCtrl.SetItemText(iItem, 1, pList[i].szName);
-         m_wndListCtrl.SetItemData(iItem, pList[i].dwEventId);
+         sprintf(szBuffer, "%u", pList[i]->dwCode);
+         iItem = m_wndListCtrl.InsertItem(0x7FFFFFFF, szBuffer, pList[i]->dwSeverity);
+         m_wndListCtrl.SetItemText(iItem, 1, pList[i]->szName);
+         m_wndListCtrl.SetItemData(iItem, pList[i]->dwCode);
       }
 
        return TRUE;
index 8ece72e..35bfad2 100644 (file)
@@ -182,7 +182,7 @@ void CMainFrame::OnUserDBChange(WPARAM wParam, LPARAM lParam)
 
 void CMainFrame::OnUpdateEventList(void) 
 {
-   DoRequest(NXCLoadEventNames, "Loading event information...");
+   DoRequest(NXCLoadEventDB, "Reloading event information...");
 }
 
 
index f03f64d..e243f11 100644 (file)
@@ -34,8 +34,8 @@ CNodePropsGeneral::CNodePropsGeneral() : CPropertyPage(CNodePropsGeneral::IDD)
        m_strPrimaryIp = _T("");
        m_strSecret = _T("");
        m_strCommunity = _T("");
-       m_iSnmpVersion = -1;
        m_iAuthType = -1;
+       m_iSNMPVersion = -1;
        //}}AFX_DATA_INIT
 }
 
@@ -47,7 +47,6 @@ void CNodePropsGeneral::DoDataExchange(CDataExchange* pDX)
 {
        CPropertyPage::DoDataExchange(pDX);
        //{{AFX_DATA_MAP(CNodePropsGeneral)
-       DDX_Control(pDX, IDC_COMBO_SNMP_VERSION, m_wndSnmpVersionList);
        DDX_Control(pDX, IDC_COMBO_AUTH, m_wndAuthList);
        DDX_Text(pDX, IDC_EDIT_ID, m_dwObjectId);
        DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
@@ -60,8 +59,8 @@ void CNodePropsGeneral::DoDataExchange(CDataExchange* pDX)
        DDV_MaxChars(pDX, m_strSecret, 63);
        DDX_Text(pDX, IDC_EDIT_COMMUNITY, m_strCommunity);
        DDV_MaxChars(pDX, m_strCommunity, 63);
-       DDX_CBIndex(pDX, IDC_COMBO_SNMP_VERSION, m_iSnmpVersion);
        DDX_CBIndex(pDX, IDC_COMBO_AUTH, m_iAuthType);
+       DDX_Radio(pDX, IDC_RADIO_VERSION1, m_iSNMPVersion);
        //}}AFX_DATA_MAP
 }
 
@@ -73,6 +72,8 @@ BEGIN_MESSAGE_MAP(CNodePropsGeneral, CPropertyPage)
        ON_EN_CHANGE(IDC_EDIT_PORT, OnChangeEditPort)
        ON_EN_CHANGE(IDC_EDIT_COMMUNITY, OnChangeEditCommunity)
        ON_CBN_SELCHANGE(IDC_COMBO_AUTH, OnSelchangeComboAuth)
+       ON_BN_CLICKED(IDC_RADIO_VERSION_2C, OnRadioVersion2c)
+       ON_BN_CLICKED(IDC_RADIO_VERSION1, OnRadioVersion1)
        //}}AFX_MSG_MAP
 END_MESSAGE_MAP()
 
@@ -92,9 +93,6 @@ BOOL CNodePropsGeneral::OnInitDialog()
       m_wndAuthList.AddString(m_pszAuthStrings[i]);
    m_wndAuthList.SelectString(-1, m_pszAuthStrings[m_iAuthType]);
 
-   m_wndSnmpVersionList.AddString("SNMP Version 1");
-   m_wndSnmpVersionList.AddString("SNMP Version 2c");
-
    return TRUE;
 }
 
@@ -133,6 +131,18 @@ void CNodePropsGeneral::OnSelchangeComboAuth()
    SetModified();
 }
 
+void CNodePropsGeneral::OnRadioVersion2c() 
+{
+   m_pUpdate->dwFlags |= OBJ_UPDATE_SNMP_VERSION;
+   SetModified();
+}
+
+void CNodePropsGeneral::OnRadioVersion1() 
+{
+   m_pUpdate->dwFlags |= OBJ_UPDATE_SNMP_VERSION;
+   SetModified();
+}
+
 
 //
 // Handler for PSN_OK message
@@ -148,9 +158,9 @@ void CNodePropsGeneral::OnOK()
    // Set fields in update structure
    m_pUpdate->pszName = (char *)((LPCTSTR)m_strName);
    m_pUpdate->iAgentPort = m_iAgentPort;
-   m_pUpdate->iSnmpVersion = m_iSnmpVersion;
    m_pUpdate->pszCommunity = (char *)((LPCTSTR)m_strCommunity);
    m_pUpdate->pszSecret = (char *)((LPCTSTR)m_strSecret);
+   m_pUpdate->wSNMPVersion = (m_iSNMPVersion == 0) ? SNMP_VERSION_1 : SNMP_VERSION_2c;
 
    // Authentication type
    m_wndAuthList.GetWindowText(szBuffer, 255);
index c2fb3c8..fa47208 100644 (file)
@@ -22,7 +22,6 @@ public:
 // Dialog Data
        //{{AFX_DATA(CNodePropsGeneral)
        enum { IDD = IDD_OBJECT_NODE_GENERAL };
-       CComboBox       m_wndSnmpVersionList;
        CComboBox       m_wndAuthList;
        DWORD   m_dwObjectId;
        CString m_strName;
@@ -31,8 +30,8 @@ public:
        CString m_strPrimaryIp;
        CString m_strSecret;
        CString m_strCommunity;
-       int             m_iSnmpVersion;
        int             m_iAuthType;
+       int             m_iSNMPVersion;
        //}}AFX_DATA
 
 
@@ -55,6 +54,8 @@ protected:
        afx_msg void OnChangeEditPort();
        afx_msg void OnChangeEditCommunity();
        afx_msg void OnSelchangeComboAuth();
+       afx_msg void OnRadioVersion2c();
+       afx_msg void OnRadioVersion1();
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
 
index fbc74a2..d638a9f 100644 (file)
@@ -210,6 +210,7 @@ int CObjectBrowser::OnCreate(LPCREATESTRUCT lpCreateStruct)
    LVCOLUMN lvCol;
    BYTE *pwp;
    UINT iBytes;
+   int i;
 
        if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
                return -1;
@@ -258,6 +259,17 @@ int CObjectBrowser::OnCreate(LPCREATESTRUCT lpCreateStruct)
    m_iLastObjectImage = m_pImageList->GetImageCount();
    m_pImageList->Add(AfxGetApp()->LoadIcon(IDI_SORT_UP));
    m_pImageList->Add(AfxGetApp()->LoadIcon(IDI_SORT_DOWN));
+   m_iStatusImageBase = m_pImageList->GetImageCount();
+   m_pImageList->Add(theApp.LoadIcon(IDI_OVL_STATUS_WARNING));
+   m_pImageList->Add(theApp.LoadIcon(IDI_OVL_STATUS_MINOR));
+   m_pImageList->Add(theApp.LoadIcon(IDI_OVL_STATUS_MAJOR));
+   m_pImageList->Add(theApp.LoadIcon(IDI_OVL_STATUS_CRITICAL));
+   m_pImageList->Add(theApp.LoadIcon(IDI_OVL_STATUS_UNKNOWN));
+   m_pImageList->Add(theApp.LoadIcon(IDI_OVL_STATUS_UNMANAGED));
+   m_pImageList->Add(theApp.LoadIcon(IDI_OVL_STATUS_DISABLED));
+   m_pImageList->Add(theApp.LoadIcon(IDI_OVL_STATUS_TESTING));
+   for(i = STATUS_WARNING; i <= STATUS_TESTING; i++)
+      m_pImageList->SetOverlayImage(m_iStatusImageBase + i - 1, i);
    m_wndTreeCtrl.SetImageList(m_pImageList, TVSIL_NORMAL);
    m_wndListCtrl.SetImageList(m_pImageList, LVSIL_SMALL);
 
@@ -386,6 +398,7 @@ void CObjectBrowser::AddObjectToTree(NXC_OBJECT *pObject, HTREEITEM hParent)
    iImage = GetObjectImageIndex(pObject);
    hItem = m_wndTreeCtrl.InsertItem(szBuffer, iImage, iImage, hParent);
    m_wndTreeCtrl.SetItemData(hItem, pObject->dwId);
+   m_wndTreeCtrl.SetItemState(hItem, INDEXTOOVERLAYMASK(pObject->iStatus), TVIS_OVERLAYMASK);
 
    // Add to hash
    m_pTreeHash = (OBJ_TREE_HASH *)realloc(m_pTreeHash, sizeof(OBJ_TREE_HASH) * (m_dwTreeHashSize + 1));
@@ -658,11 +671,15 @@ restart_parent_check:;
                else  // Current tree item is still valid
                {
                   m_wndTreeCtrl.SetItemText(m_pTreeHash[i].hTreeItem, szBuffer);
+                  m_wndTreeCtrl.SetItemState(m_pTreeHash[i].hTreeItem,
+                                    INDEXTOOVERLAYMASK(pObject->iStatus), TVIS_OVERLAYMASK);
                }
             }
             else  // Current tree item has no parent
             {
                m_wndTreeCtrl.SetItemText(m_pTreeHash[i].hTreeItem, szBuffer);
+               m_wndTreeCtrl.SetItemState(m_pTreeHash[i].hTreeItem,
+                                       INDEXTOOVERLAYMASK(pObject->iStatus), TVIS_OVERLAYMASK);
             }
          }
 
@@ -1097,6 +1114,8 @@ void CObjectBrowser::UpdateObjectListEntry(int iItem, NXC_OBJECT *pObject)
    char szBuffer[64];
    int iPos;
 
+   m_wndListCtrl.SetItemState(iItem, INDEXTOOVERLAYMASK(pObject->iStatus), LVIS_OVERLAYMASK);
+
    m_wndListCtrl.SetItemText(iItem, 1, pObject->szName);
    m_wndListCtrl.SetItemText(iItem, 2, g_szObjectClass[pObject->iClass]);
    m_wndListCtrl.SetItemText(iItem, 3, g_szStatusTextSmall[pObject->iStatus]);
index 37476c1..19985f5 100644 (file)
@@ -94,6 +94,7 @@ public:
 
 // Implementation
 protected:
+       int m_iStatusImageBase;
        void ChangeMgmtStatus(BOOL bIsManaged);
        NXC_OBJECT * m_pCurrentObject;
        DWORD GetSelectedObject(void);
index a434ca0..2d8f50c 100644 (file)
@@ -135,7 +135,7 @@ static DWORD WINAPI LoginThread(void *pArg)
    if (dwResult == RCC_SUCCESS)
    {
       SetInfoText(hWnd, "Loading event information...");
-      dwResult = NXCLoadEventNames();
+      dwResult = NXCLoadEventDB();
    }
 
    // Synchronize images
index f1d1cec..0a5519d 100644 (file)
Binary files a/src/console/win32/icons/ovl_status_major.ico and b/src/console/win32/icons/ovl_status_major.ico differ
index a7e2673..4dd543e 100644 (file)
Binary files a/src/console/win32/icons/ovl_status_minor.ico and b/src/console/win32/icons/ovl_status_minor.ico differ
index 7071654..ca8fbf1 100644 (file)
Binary files a/src/console/win32/icons/ovl_status_unmanaged.ico and b/src/console/win32/icons/ovl_status_unmanaged.ico differ
index 0cfae8e..6d19704 100644 (file)
Binary files a/src/console/win32/icons/ovl_status_warning.ico and b/src/console/win32/icons/ovl_status_warning.ico differ
index ac74570..e3f3ba2 100644 (file)
@@ -2,7 +2,7 @@
 
 [General Info]
 Version=1
-LastClass=CDCIThresholdsPage
+LastClass=CNodePropsGeneral
 LastTemplate=CDialog
 NewFileInclude1=#include "stdafx.h"
 NewFileInclude2=#include "nxcon.h"
@@ -17,20 +17,20 @@ Class9=CMapView
 
 ResourceCount=87
 Resource1=IDD_THRESHOLD (English (U.S.))
-Resource2=IDD_THRESHOLD
+Resource2=IDD_DCI_TRANSFORM
 Resource3=IDM_VIEW_SPECIFIC (English (U.S.))
-Resource4=IDD_REQUEST_PROCESSING
-Resource5=IDD_OBJECT_NODE_GENERAL
+Resource4=IDD_NEW_USER
+Resource5=IDD_OBJECT_SECURITY
 Class2=CChildView
 Class5=CAboutDlg
 Class6=CControlPanel
 Class8=CMapFrame
 Class10=CLoginDialog
-Resource6=IDR_MAINFRAME
+Resource6=IDD_OBJECT_GENERAL
 Class11=CProgressDialog
-Resource7=IDD_NEW_USER
+Resource7=IDD_DCI_COLLECTION
 Class12=CObjectBrowser
-Resource8=IDD_EDIT_RULE_ALARM
+Resource8=IDD_SELECT_ACTION
 Class13=CObjectPropDlg
 Resource9=IDD_CP_GENERAL (English (U.S.))
 Resource10=IDA_OBJECT_BROWSER (English (U.S.))
@@ -46,7 +46,7 @@ Resource17=IDD_SET_PASSWORD (English (U.S.))
 Class16=CDebugFrame
 Resource18=IDD_OBJECT_SECURITY (English (U.S.))
 Resource19=IDD_OBJECT_PROPERTIES (English (U.S.))
-Resource20=IDD_DCI_TRANSFORM
+Resource20=IDA_OBJECT_BROWSER
 Class17=CObjectPreview
 Resource21=IDD_DCI_TRANSFORM (English (U.S.))
 Class18=CToolBox
@@ -59,32 +59,32 @@ Class23=CNodePropsGeneral
 Resource23=IDD_LOGIN (English (U.S.))
 Class24=CObjectPropCaps
 Class25=CObjectPropSheet
-Resource24=IDA_EVENT_EDITOR
+Resource24=IDD_OBJECT_NODE_GENERAL
 Class26=CRequestProcessingDlg
 Resource25=IDD_EDIT_EVENT (English (U.S.))
 Resource26=IDD_PROGRESS (English (U.S.))
-Resource27=IDA_EPP
+Resource27=IDD_CREATE_NODE
 Resource28=IDD_USER_PROPERTIES (English (U.S.))
 Class27=CObjectPropsGeneral
 Resource29=IDA_ALARM_BROWSER (English (U.S.))
 Class28=CObjectPropsSecurity
 Resource30=IDD_CREATE_NODE (English (U.S.))
-Resource31=IDD_MIB_BROWSER
-Resource32=IDD_SELECT_OBJECT
+Resource31=IDD_OBJECT_PRESENTATION
+Resource32=IDD_EDIT_RULE_SEVERITY
 Class29=CUserSelectDlg
-Resource33=IDD_CREATE_CONTAINER
+Resource33=IDR_MAINFRAME
 Class30=CUserEditor
 Resource34=IDD_DCI_PROPERTIES
 Class31=CNewUserDlg
-Resource35=IDD_USER_PROPERTIES
-Resource36=IDD_SELECT_EVENT
+Resource35=IDD_DCI_THRESHOLDS
+Resource36=IDD_CP_GENERAL
 Class32=CUserPropDlg
 Resource37=IDM_CONTEXT (English (U.S.))
-Resource38=IDD_OBJECT_PRESENTATION
+Resource38=IDD_NEW_ACTION
 Class33=CGroupPropDlg
-Resource39=IDD_DCI_COLLECTION
-Resource40=IDD_DCI_THRESHOLDS
-Resource41=IDA_OBJECT_BROWSER
+Resource39=IDD_SELECT_OBJECT
+Resource40=IDD_EDIT_RULE_COMMENT
+Resource41=IDD_CREATE_CONTAINER
 Resource42=IDD_SELECT_OBJECT (English (U.S.))
 Class34=CPasswordChangeDlg
 Class35=CNodeSummary
@@ -100,55 +100,55 @@ Class41=CGraphFrame
 Class42=CDCIThresholdsPage
 Resource46=IDA_MDI_DEFAULT (English (U.S.))
 Resource47=IDD_OBJECT_CAPS (English (U.S.))
-Resource48=IDD_SELECT_ACTION
+Resource48=IDD_CREATE_TG
 Class43=CThresholdDlg
 Resource49=IDD_SELECT_USER (English (U.S.))
-Resource50=IDD_CREATE_TG
+Resource50=IDA_EPP
 Class44=CMIBBrowserDlg
 Class45=CEventPolicyEditor
 Class46=CRuleList
 Class47=CRuleHeader
 Resource51=IDR_MAINFRAME (English (U.S.))
-Resource52=IDD_EDIT_RULE_SEVERITY
+Resource52=IDD_ACTION_PROPERTIES
 Class48=CObjectSelDlg
-Resource53=IDD_OBJECT_GENERAL
-Resource54=IDD_SET_PASSWORD
+Resource53=IDD_USER_PROPERTIES
+Resource54=IDD_MIB_BROWSER
 Class49=CRuleCommentDlg
-Resource55=IDD_CP_GENERAL
+Resource55=IDA_EVENT_EDITOR
 Class50=CEventSelDlg
-Resource56=IDD_EDIT_EVENT
+Resource56=IDA_ALARM_BROWSER
 Resource57=IDD_REQUEST_PROCESSING (English (U.S.))
-Resource58=IDA_MDI_DEFAULT
+Resource58=IDA_NETMAP
 Resource59=IDD_ABOUTBOX (English (U.S.))
 Resource60=IDD_MIB_BROWSER (English (U.S.))
 Class51=CObjectPropsPresentation
 Resource61=IDD_OBJECT_PRESENTATION (English (U.S.))
 Resource62=IDM_VIEW_SPECIFIC
 Class52=CRuleSeverityDlg
-Resource63=IDD_NEW_ACTION
+Resource63=IDD_ABOUTBOX
 Class53=CRuleAlarmDlg
 Class54=CAlarmBrowser
 Resource64=IDD_SELECT_EVENT (English (U.S.))
-Resource65=IDA_ALARM_BROWSER
+Resource65=IDD_LOGIN
 Resource66=IDD_NEW_ACTION (English (U.S.))
 Resource67=IDD_DCI_COLLECTION (English (U.S.))
 Resource68=IDD_NEW_USER (English (U.S.))
 Class55=CConsolePropsGeneral
 Class56=CActionEditor
-Resource69=IDD_ACTION_PROPERTIES
-Resource70=IDD_GROUP_PROPERTIES
+Resource69=IDD_SELECT_EVENT
+Resource70=IDD_THRESHOLD
 Class57=CNewActionDlg
-Resource71=IDD_OBJECT_CAPS
+Resource71=IDD_SELECT_USER
 Class58=CEditActionDlg
-Resource72=IDA_NETMAP
+Resource72=IDD_GROUP_PROPERTIES
 Class59=CActionSelDlg
-Resource73=IDD_OBJECT_SECURITY
+Resource73=IDD_EDIT_EVENT
 Resource74=IDD_EDIT_RULE_COMMENT (English (U.S.))
 Resource75=IDD_EDIT_RULE_ALARM (English (U.S.))
-Resource76=IDD_ABOUTBOX
+Resource76=IDM_CONTEXT
 Class60=CCreateObjectDlg
 Class61=CCreateContainerDlg
-Resource77=IDD_EDIT_RULE_COMMENT
+Resource77=IDD_EDIT_RULE_ALARM
 Class62=CCreateNodeDlg
 Resource78=IDA_EPP (English (U.S.))
 Resource79=IDD_CREATE_CONTAINER (English (U.S.))
@@ -158,12 +158,12 @@ Resource81=IDD_ACTION_PROPERTIES (English (U.S.))
 Class64=CPollNodeDlg
 Resource82=IDD_POLL_NODE (English (U.S.))
 Class65=CNodePoller
-Resource83=IDD_CREATE_NODE
-Resource84=IDD_LOGIN
+Resource83=IDA_MDI_DEFAULT
+Resource84=IDD_REQUEST_PROCESSING
 Class66=CCreateTemplateDlg
 Class67=CCreateTGDlg
-Resource85=IDD_SELECT_USER
-Resource86=IDM_CONTEXT
+Resource85=IDD_SET_PASSWORD
+Resource86=IDD_OBJECT_CAPS
 Resource87=IDD_CREATE_TEMPLATE
 
 [CLS:CConsoleApp]
@@ -556,7 +556,7 @@ Type=1
 Class=CEditEventDlg
 ControlCount=13
 Control1=IDC_EDIT_ID,edit,1350633600
-Control2=IDC_COMBO_SEVERITY,combobox,1344340227
+Control2=IDC_COMBO_SEVERITY,combobox,1344339971
 Control3=IDC_EDIT_NAME,edit,1350631552
 Control4=IDC_CHECK_LOG,button,1342242819
 Control5=IDC_EDIT_MESSAGE,edit,1350631552
@@ -638,28 +638,27 @@ Command54=ID_CONTROLPANEL_ACTIONS
 Command55=ID_CONTROLPANEL_EVENTS
 Command56=ID_CONTROLPANEL_EVENTPOLICY
 Command57=ID_CONTROLPANEL_USERS
-Command58=ID_CONTROLPANEL_DCT
-Command59=ID_OBJECT_OPEN
-Command60=ID_OBJECT_OPENPARENT
-Command61=ID_OBJECT_FIND
-Command62=ID_OBJECT_CREATE_NODE
-Command63=ID_OBJECT_CREATE_CONTAINER
-Command64=ID_OBJECT_CREATE_TEMPLATEGROUP
-Command65=ID_OBJECT_CREATE_TEMPLATE
-Command66=ID_OBJECT_BIND
-Command67=ID_OBJECT_RENAME
-Command68=ID_OBJECT_DELETE
-Command69=ID_OBJECT_MANAGE
-Command70=ID_OBJECT_UNMANAGE
-Command71=ID_OBJECT_POLL_STATUS
-Command72=ID_OBJECT_POLL_CONFIGURATION
-Command73=ID_OBJECT_WAKEUP
-Command74=ID_OBJECT_DATACOLLECTION
-Command75=ID_OBJECT_PROPERTIES
-Command76=ID_EVENT_NEW
-Command77=ID_EVENT_EDIT
-Command78=ID_EVENT_DELETE
-CommandCount=78
+Command58=ID_OBJECT_OPEN
+Command59=ID_OBJECT_OPENPARENT
+Command60=ID_OBJECT_FIND
+Command61=ID_OBJECT_CREATE_NODE
+Command62=ID_OBJECT_CREATE_CONTAINER
+Command63=ID_OBJECT_CREATE_TEMPLATEGROUP
+Command64=ID_OBJECT_CREATE_TEMPLATE
+Command65=ID_OBJECT_BIND
+Command66=ID_OBJECT_RENAME
+Command67=ID_OBJECT_DELETE
+Command68=ID_OBJECT_MANAGE
+Command69=ID_OBJECT_UNMANAGE
+Command70=ID_OBJECT_POLL_STATUS
+Command71=ID_OBJECT_POLL_CONFIGURATION
+Command72=ID_OBJECT_WAKEUP
+Command73=ID_OBJECT_DATACOLLECTION
+Command74=ID_OBJECT_PROPERTIES
+Command75=ID_EVENT_NEW
+Command76=ID_EVENT_EDIT
+Command77=ID_EVENT_DELETE
+CommandCount=77
 
 [ACL:IDA_MDI_DEFAULT]
 Type=1
@@ -835,25 +834,25 @@ LastObject=COPGeneral
 Type=1
 Class=CNodePropsGeneral
 ControlCount=22
-Control1=IDC_STATIC,static,1342308352
-Control2=IDC_EDIT_ID,edit,1350633600
-Control3=IDC_STATIC,static,1342308352
-Control4=IDC_STATIC,static,1342308352
-Control5=IDC_EDIT_NAME,edit,1350631552
-Control6=IDC_EDIT_PRIMARY_IP,edit,1350633600
-Control7=IDC_SELECT_IP,button,1342242816
-Control8=IDC_STATIC,static,1342308352
-Control9=IDC_EDIT_OID,edit,1350633600
+Control1=IDC_EDIT_NAME,edit,1350631552
+Control2=IDC_SELECT_IP,button,1342242816
+Control3=IDC_EDIT_OID,edit,1350633600
+Control4=IDC_COMBO_AUTH,combobox,1344340227
+Control5=IDC_EDIT_SECRET,edit,1350631552
+Control6=IDC_EDIT_PORT,edit,1350639744
+Control7=IDC_RADIO_VERSION1,button,1342308361
+Control8=IDC_RADIO_VERSION_2C,button,1342177289
+Control9=IDC_EDIT_COMMUNITY,edit,1350631552
 Control10=IDC_STATIC,static,1342308352
-Control11=IDC_COMBO_AUTH,combobox,1344340227
+Control11=IDC_EDIT_ID,edit,1350633600
 Control12=IDC_STATIC,static,1342308352
-Control13=IDC_EDIT_SECRET,edit,1350631552
-Control14=IDC_STATIC,static,1342308352
-Control15=IDC_EDIT_PORT,edit,1350639744
+Control13=IDC_STATIC,static,1342308352
+Control14=IDC_EDIT_PRIMARY_IP,edit,1350633600
+Control15=IDC_STATIC,static,1342308352
 Control16=IDC_STATIC,static,1342308352
-Control17=IDC_COMBO_SNMP_VERSION,combobox,1344340227
+Control17=IDC_STATIC,static,1342308352
 Control18=IDC_STATIC,static,1342308352
-Control19=IDC_EDIT_COMMUNITY,edit,1350631552
+Control19=IDC_STATIC,static,1342308352
 Control20=IDC_STATIC,button,1342177287
 Control21=IDC_STATIC,button,1342177287
 Control22=IDC_STATIC,button,1342177287
index 9f53482..a1485b7 100644 (file)
@@ -683,7 +683,7 @@ void CConsoleApp::OnControlpanelEvents()
    {
       DWORD dwResult;
 
-      dwResult = DoRequest(NXCOpenEventDB, "Opening event configuration database...");
+      dwResult = DoRequest(NXCLockEventDB, "Locking event configuration database...");
       if (dwResult == RCC_SUCCESS)
       {
              pFrame->CreateNewChild(
@@ -792,6 +792,7 @@ void CConsoleApp::ObjectProperties(DWORD dwObjectId)
          wndNodeGeneral.m_strCommunity = pObject->node.szCommunityString;
          wndNodeGeneral.m_iAuthType = pObject->node.wAuthMethod;
          wndNodeGeneral.m_strSecret = pObject->node.szSharedSecret;
+         wndNodeGeneral.m_iSNMPVersion = (pObject->node.wSNMPVersion == SNMP_VERSION_1) ? 0 : 1;
          wndPropSheet.AddPage(&wndNodeGeneral);
       }
       else
index 7cc0a2e..4f1c957 100644 (file)
@@ -298,7 +298,6 @@ BEGIN
         MENUITEM "&Events",                     ID_CONTROLPANEL_EVENTS
         MENUITEM "Event &Policy\tF4",           ID_CONTROLPANEL_EVENTPOLICY
         MENUITEM "&Users",                      ID_CONTROLPANEL_USERS
-        MENUITEM "Data Collection &Templates",  ID_CONTROLPANEL_DCT
     END
     POPUP "&Object (map)"
     BEGIN
@@ -654,7 +653,7 @@ FONT 8, "MS Sans Serif"
 BEGIN
     EDITTEXT        IDC_EDIT_ID,7,16,40,14,ES_AUTOHSCROLL | ES_READONLY
     COMBOBOX        IDC_COMBO_SEVERITY,175,18,88,180,CBS_DROPDOWNLIST | 
-                    CBS_SORT | WS_VSCROLL | WS_TABSTOP
+                    WS_VSCROLL | WS_TABSTOP
     EDITTEXT        IDC_EDIT_NAME,7,44,156,14,ES_AUTOHSCROLL
     CONTROL         "Write to event log",IDC_CHECK_LOG,"Button",
                     BS_AUTOCHECKBOX | WS_TABSTOP,175,46,88,10
@@ -676,28 +675,29 @@ STYLE DS_MODALFRAME | DS_3DLOOK | WS_POPUP | WS_CAPTION
 CAPTION "General"
 FONT 8, "MS Sans Serif"
 BEGIN
+    EDITTEXT        IDC_EDIT_NAME,51,33,107,14,ES_AUTOHSCROLL
+    PUSHBUTTON      "...",IDC_SELECT_IP,265,24,14,14
+    EDITTEXT        IDC_EDIT_OID,51,51,228,14,ES_AUTOHSCROLL | ES_READONLY
+    COMBOBOX        IDC_COMBO_AUTH,14,103,126,120,CBS_DROPDOWNLIST | 
+                    CBS_SORT | WS_VSCROLL | WS_TABSTOP
+    EDITTEXT        IDC_EDIT_SECRET,66,122,74,14,ES_AUTOHSCROLL
+    EDITTEXT        IDC_EDIT_PORT,66,140,74,14,ES_AUTOHSCROLL | ES_NUMBER
+    CONTROL         "Use version 1",IDC_RADIO_VERSION1,"Button",
+                    BS_AUTORADIOBUTTON | WS_GROUP,162,98,59,10
+    CONTROL         "Use version 2c",IDC_RADIO_VERSION_2C,"Button",
+                    BS_AUTORADIOBUTTON,162,111,63,10
+    EDITTEXT        IDC_EDIT_COMMUNITY,162,140,115,14,ES_AUTOHSCROLL
     LTEXT           "Object ID",IDC_STATIC,12,18,31,8
     EDITTEXT        IDC_EDIT_ID,51,15,38,14,ES_AUTOHSCROLL | ES_READONLY
     LTEXT           "Primary IP address",IDC_STATIC,168,15,59,8
     LTEXT           "Name",IDC_STATIC,12,36,20,8
-    EDITTEXT        IDC_EDIT_NAME,51,33,107,14,ES_AUTOHSCROLL
     EDITTEXT        IDC_EDIT_PRIMARY_IP,168,25,94,14,ES_AUTOHSCROLL | 
                     ES_READONLY
-    PUSHBUTTON      "...",IDC_SELECT_IP,265,24,14,14
     LTEXT           "SNMP OID",IDC_STATIC,12,54,36,8
-    EDITTEXT        IDC_EDIT_OID,51,51,228,14,ES_AUTOHSCROLL | ES_READONLY
     LTEXT           "Authentication method",IDC_STATIC,14,93,72,8
-    COMBOBOX        IDC_COMBO_AUTH,14,103,126,120,CBS_DROPDOWNLIST | 
-                    CBS_SORT | WS_VSCROLL | WS_TABSTOP
     LTEXT           "Shared secret",IDC_STATIC,14,125,45,8
-    EDITTEXT        IDC_EDIT_SECRET,66,122,74,14,ES_AUTOHSCROLL
     LTEXT           "Port number",IDC_STATIC,14,143,39,8
-    EDITTEXT        IDC_EDIT_PORT,66,140,74,14,ES_AUTOHSCROLL | ES_NUMBER
-    LTEXT           "Protocol version",IDC_STATIC,162,94,52,8
-    COMBOBOX        IDC_COMBO_SNMP_VERSION,162,104,115,90,CBS_DROPDOWNLIST | 
-                    CBS_SORT | WS_VSCROLL | WS_TABSTOP
-    LTEXT           "Community string",IDC_STATIC,162,124,54,8
-    EDITTEXT        IDC_EDIT_COMMUNITY,162,136,115,14,ES_AUTOHSCROLL
+    LTEXT           "Community string",IDC_STATIC,162,129,54,8
     GROUPBOX        "NetXMS Agent",IDC_STATIC,7,83,139,80
     GROUPBOX        "SNMP",IDC_STATIC,156,83,129,80
     GROUPBOX        "General",IDC_STATIC,7,7,278,70
index 9fc83da..897be23 100644 (file)
 #define IDC_BUTTON_RESOLVE              1173
 #define IDC_BUTTON_NONE                 1174
 #define IDC_EDIT_INSTANCE               1175
+#define IDC_RADIO_VERSION1              1176
+#define IDC_RADIO_VERSION_2C            1177
 #define ID_VIEW_CONTROLPANEL            32771
 #define ID_VIEW_EVENTS                  32774
 #define ID_VIEW_MAP                     32776
 #define _APS_3D_CONTROLS                     1
 #define _APS_NEXT_RESOURCE_VALUE        241
 #define _APS_NEXT_COMMAND_VALUE         32897
-#define _APS_NEXT_CONTROL_VALUE         1176
+#define _APS_NEXT_CONTROL_VALUE         1178
 #define _APS_NEXT_SYMED_VALUE           120
 #endif
 #endif
index 986e829..37c8334 100644 (file)
@@ -154,7 +154,6 @@ static THREAD_RESULT THREAD_CALL NetReceiver(void *pArg)
                ProcessEvent(pMsg, NULL);
                break;
             case CMD_EVENT_DB_RECORD:
-            case CMD_EVENT_DB_EOF:
                ProcessEventDBRecord(pMsg);
                break;
             case CMD_USER_DATA:
index a806260..7b0fb1d 100644 (file)
@@ -30,9 +30,7 @@
 
 static NXC_EVENT_TEMPLATE **m_ppEventTemplates = NULL;
 static DWORD m_dwNumTemplates = 0;
-static BOOL m_bEventDBOpened = FALSE;
-static NXC_EVENT_NAME *m_pEventNamesList = NULL;
-static DWORD m_dwNumEvents = 0;
+static MUTEX m_mutexEventAccess = INVALID_HANDLE_VALUE;
 
 
 //
@@ -56,6 +54,29 @@ static void DestroyEventDB(void)
 
 
 //
+// Initialize
+//
+
+void InitEventDB(void)
+{
+   m_mutexEventAccess = MutexCreate();
+}
+
+
+//
+// Cleanup
+//
+
+void ShutdownEventDB(void)
+{
+   MutexLock(m_mutexEventAccess, INFINITE);
+   MutexUnlock(m_mutexEventAccess);
+   MutexDestroy(m_mutexEventAccess);
+   DestroyEventDB();
+}
+
+
+//
 // Duplicate event template
 //
 
@@ -74,7 +95,7 @@ NXC_EVENT_TEMPLATE *DuplicateEventTemplate(NXC_EVENT_TEMPLATE *pSrc)
 // Add template to list
 //
 
-static void AddEventTemplate(NXC_EVENT_TEMPLATE *pEventTemplate)
+void LIBNXCL_EXPORTABLE NXCAddEventTemplate(NXC_EVENT_TEMPLATE *pEventTemplate)
 {
    m_ppEventTemplates = (NXC_EVENT_TEMPLATE **)realloc(m_ppEventTemplates, 
       sizeof(NXC_EVENT_TEMPLATE *) * (m_dwNumTemplates + 1));
@@ -84,40 +105,66 @@ static void AddEventTemplate(NXC_EVENT_TEMPLATE *pEventTemplate)
 
 
 //
+// Delete record from list
+//
+
+void LIBNXCL_EXPORTABLE NXCDeleteEDBRecord(DWORD dwEventId)
+{
+   DWORD i;
+
+   MutexLock(m_mutexEventAccess, INFINITE);
+   for(i = 0; i < m_dwNumTemplates; i++)
+      if (m_ppEventTemplates[i]->dwCode == dwEventId)
+      {
+         m_dwNumTemplates--;
+         safe_free(m_ppEventTemplates[i]->pszDescription);
+         safe_free(m_ppEventTemplates[i]->pszMessage);
+         free(m_ppEventTemplates[i]);
+         memmove(&m_ppEventTemplates[i], m_ppEventTemplates[i + 1], 
+                 sizeof(NXC_EVENT_TEMPLATE *) * (m_dwNumTemplates - i));
+         break;
+      }
+   MutexUnlock(m_mutexEventAccess);
+}
+
+
+//
 // Process record from network
 //
 
 void ProcessEventDBRecord(CSCPMessage *pMsg)
 {
    NXC_EVENT_TEMPLATE *pEventTemplate;
+   DWORD dwEventId;
 
-   switch(pMsg->GetCode())
+   if (pMsg->GetCode() == CMD_EVENT_DB_RECORD)
    {
-      case CMD_EVENT_DB_EOF:
-         CompleteSync(RCC_SUCCESS);
-         break;
-      case CMD_EVENT_DB_RECORD:
+      dwEventId = pMsg->GetVariableLong(VID_EVENT_ID);
+      if (dwEventId != 0)
+      {
          // Allocate new event template structure and fill it with values from message
          pEventTemplate = (NXC_EVENT_TEMPLATE *)malloc(sizeof(NXC_EVENT_TEMPLATE));
-         pEventTemplate->dwCode = pMsg->GetVariableLong(VID_EVENT_ID);
+         pEventTemplate->dwCode = dwEventId;
          pEventTemplate->dwSeverity = pMsg->GetVariableLong(VID_SEVERITY);
          pEventTemplate->dwFlags = pMsg->GetVariableLong(VID_FLAGS);
          pMsg->GetVariableStr(VID_NAME, pEventTemplate->szName, MAX_EVENT_NAME);
          pEventTemplate->pszMessage = pMsg->GetVariableStr(VID_MESSAGE, NULL, 0);
          pEventTemplate->pszDescription = pMsg->GetVariableStr(VID_DESCRIPTION, NULL, 0);
-         AddEventTemplate(pEventTemplate);
-         break;
-      default:
-         break;
+         NXCAddEventTemplate(pEventTemplate);
+      }
+      else
+      {
+         CompleteSync(RCC_SUCCESS);
+      }
    }
 }
 
 
 //
-// Open event configuration database
+// Load event configuration database
 //
 
-DWORD LIBNXCL_EXPORTABLE NXCOpenEventDB(void)
+DWORD LIBNXCL_EXPORTABLE NXCLoadEventDB(void)
 {
    CSCPMessage msg;
    DWORD dwRetCode;
@@ -126,20 +173,20 @@ DWORD LIBNXCL_EXPORTABLE NXCOpenEventDB(void)
    dwRqId = g_dwMsgId++;
    PrepareForSync();
 
-   msg.SetCode(CMD_OPEN_EVENT_DB);
+   DestroyEventDB();
+   MutexLock(m_mutexEventAccess, INFINITE);
+
+   msg.SetCode(CMD_LOAD_EVENT_DB);
    msg.SetId(dwRqId);
    SendMsg(&msg);
 
    dwRetCode = WaitForRCC(dwRqId);
 
+   /* TODO: this probably should be recoded as loop with calls to WaitForMessage() */
    if (dwRetCode == RCC_SUCCESS)
-   {
-      // Wait for object list end or for disconnection
       dwRetCode = WaitForSync(INFINITE);
-      if (dwRetCode == RCC_SUCCESS)
-         m_bEventDBOpened = TRUE;
-   }
 
+   MutexUnlock(m_mutexEventAccess);
    return dwRetCode;
 }
 
@@ -148,10 +195,9 @@ DWORD LIBNXCL_EXPORTABLE NXCOpenEventDB(void)
 // Set event information
 //
 
-static DWORD SetEventInfo(NXC_EVENT_TEMPLATE *pArg)
+DWORD LIBNXCL_EXPORTABLE NXCSetEventInfo(NXC_EVENT_TEMPLATE *pArg)
 {
    CSCPMessage msg;
-   DWORD dwRetCode = RCC_SUCCESS;
    DWORD dwRqId;
 
    dwRqId = g_dwMsgId++;
@@ -168,62 +214,60 @@ static DWORD SetEventInfo(NXC_EVENT_TEMPLATE *pArg)
    SendMsg(&msg);
    
    // Wait for reply
-   dwRetCode = WaitForRCC(dwRqId);
-   return dwRetCode;
+   return WaitForRCC(dwRqId);
 }
 
 
 //
-// Close event configuration database
+// Delete event template
 //
 
-DWORD LIBNXCL_EXPORTABLE NXCCloseEventDB(BOOL bSaveChanges)
+DWORD LIBNXCL_EXPORTABLE NXCDeleteEventTemplate(DWORD dwEventId)
 {
-   CSCPMessage msg, *pResponce;
-   DWORD dwRetCode = RCC_SUCCESS;
+   CSCPMessage msg;
    DWORD dwRqId;
 
-   // Go through event templates and save modified events
-   if (bSaveChanges)
+   dwRqId = g_dwMsgId++;
+
+   // Prepare message
+   msg.SetCode(CMD_DELETE_EVENT_TEMPLATE);
+   msg.SetId(dwRqId);
+   msg.SetVariable(VID_EVENT_ID, dwEventId);
+   SendMsg(&msg);
+   
+   // Wait for reply
+   return WaitForRCC(dwRqId);
+}
+
+
+//
+// Generate ID for new event
+//
+
+DWORD LIBNXCL_EXPORTABLE NXCGenerateEventId(DWORD *pdwEventId)
+{
+   CSCPMessage msg, *pResponce;
+   DWORD dwRqId, dwRetCode;
+
+   dwRqId = g_dwMsgId++;
+
+   // Prepare message
+   msg.SetCode(CMD_GENERATE_EVENT_ID);
+   msg.SetId(dwRqId);
+   SendMsg(&msg);
+   
+   // Wait for reply
+   pResponce = WaitForMessage(CMD_REQUEST_COMPLETED, dwRqId, g_dwCommandTimeout);
+   if (pResponce != NULL)
    {
-      DWORD i;
-
-      for(i = 0; i < m_dwNumTemplates; i++)
-         if (m_ppEventTemplates[i]->dwFlags & EF_MODIFIED)
-         {
-            m_ppEventTemplates[i]->dwFlags &= ~EF_MODIFIED;
-            dwRetCode = SetEventInfo(m_ppEventTemplates[i]);
-            if (dwRetCode != RCC_SUCCESS)
-            {
-               // Restore modified flag
-               m_ppEventTemplates[i]->dwFlags |= EF_MODIFIED;
-               break;
-            }
-         }
+      dwRetCode = pResponce->GetVariableLong(VID_RCC);
+      if (dwRetCode == RCC_SUCCESS)
+         *pdwEventId = pResponce->GetVariableLong(VID_EVENT_ID);
    }
-
-   // Close database
-   if (dwRetCode == RCC_SUCCESS)
+   else
    {
-      dwRqId = g_dwMsgId++;
-      msg.SetCode(CMD_CLOSE_EVENT_DB);
-      msg.SetId(dwRqId);
-      SendMsg(&msg);
-      pResponce = WaitForMessage(CMD_REQUEST_COMPLETED, dwRqId, g_dwCommandTimeout);
-      if (pResponce != NULL)
-      {
-         dwRetCode = pResponce->GetVariableLong(VID_RCC);
-         delete pResponce;
-      }
-      else
-      {
-         dwRetCode = RCC_TIMEOUT;
-      }
-
-      m_bEventDBOpened = FALSE;
-      DestroyEventDB();
+      dwRetCode = RCC_TIMEOUT;
    }
-
    return dwRetCode;
 }
 
@@ -234,121 +278,89 @@ DWORD LIBNXCL_EXPORTABLE NXCCloseEventDB(BOOL bSaveChanges)
 
 BOOL LIBNXCL_EXPORTABLE NXCGetEventDB(NXC_EVENT_TEMPLATE ***pppTemplateList, DWORD *pdwNumRecords)
 {
-   if (!m_bEventDBOpened)
-      return FALSE;
-
    *pppTemplateList = m_ppEventTemplates;
    *pdwNumRecords = m_dwNumTemplates;
    return TRUE;
 }
 
 
+
 //
-// Modify event template
+// Resolve event id to name
 //
 
-void LIBNXCL_EXPORTABLE NXCModifyEventTemplate(NXC_EVENT_TEMPLATE *pEvent, DWORD dwMask, 
-                                       DWORD dwSeverity, DWORD dwFlags, const TCHAR *pszName,
-                                       const TCHAR *pszMessage, const TCHAR *pszDescription)
+const TCHAR LIBNXCL_EXPORTABLE *NXCGetEventName(DWORD dwId)
 {
-   if (dwMask & EM_SEVERITY)
-      pEvent->dwSeverity = dwSeverity;
-   if (dwMask & EM_FLAGS)
-      pEvent->dwFlags = dwFlags & SERVER_FLAGS_BITS;
-   if ((dwMask & EM_NAME) && (pszName != NULL))
-      _tcsncpy(pEvent->szName, pszName, MAX_EVENT_NAME);
-   if ((dwMask & EM_MESSAGE) && (pszMessage != NULL))
-   {
-      if (pEvent->pszMessage != NULL)
-         free(pEvent->pszMessage);
-      pEvent->pszMessage = _tcsdup(pszMessage);
-   }
-   if ((dwMask & EM_DESCRIPTION) && (pszDescription != NULL))
-   {
-      if (pEvent->pszDescription != NULL)
-         free(pEvent->pszDescription);
-      pEvent->pszDescription = _tcsdup(pszDescription);
-   }
-   pEvent->dwFlags |= EF_MODIFIED;
+   DWORD i;
+
+   MutexLock(m_mutexEventAccess, INFINITE);
+   for(i = 0; i < m_dwNumTemplates; i++)
+      if (m_ppEventTemplates[i]->dwCode == dwId)
+      {
+         MutexUnlock(m_mutexEventAccess);
+         return m_ppEventTemplates[i]->szName;
+      }
+   MutexUnlock(m_mutexEventAccess);
+   return _T("<unknown>");
 }
 
 
 //
-// Load event name/id pairs
+// Get severity for given event id. Will return -1 for unknown id.
 //
 
-DWORD LIBNXCL_EXPORTABLE NXCLoadEventNames(void)
+int LIBNXCL_EXPORTABLE NXCGetEventSeverity(DWORD dwId)
 {
-   CSCPMessage msg, *pResponce;
-   DWORD i, dwRqId, dwRetCode;
+   DWORD i;
 
-   dwRqId = g_dwMsgId++;
-   msg.SetCode(CMD_GET_EVENT_NAMES);
-   msg.SetId(dwRqId);
-   SendMsg(&msg);
-   pResponce = WaitForMessage(CMD_EVENT_NAME_LIST, dwRqId, g_dwCommandTimeout);
-   if (pResponce != NULL)
-   {
-      dwRetCode = pResponce->GetVariableLong(VID_RCC);
-      if (dwRetCode == RCC_SUCCESS)
+   MutexLock(m_mutexEventAccess, INFINITE);
+   for(i = 0; i < m_dwNumTemplates; i++)
+      if (m_ppEventTemplates[i]->dwCode == dwId)
       {
-         safe_free(m_pEventNamesList);
-         m_dwNumEvents = pResponce->GetVariableLong(VID_NUM_EVENTS);
-         m_pEventNamesList = (NXC_EVENT_NAME *)malloc(sizeof(NXC_EVENT_NAME) * m_dwNumEvents);
-         pResponce->GetVariableBinary(VID_EVENT_NAME_TABLE, (BYTE *)m_pEventNamesList,
-                                      sizeof(NXC_EVENT_NAME) * m_dwNumEvents);
-         for(i = 0; i < m_dwNumEvents; i++)
-         {
-            m_pEventNamesList[i].dwEventId = ntohl(m_pEventNamesList[i].dwEventId);
-            m_pEventNamesList[i].dwSeverity = ntohl(m_pEventNamesList[i].dwSeverity);
-         }
+         MutexUnlock(m_mutexEventAccess);
+         return (int)(m_ppEventTemplates[i]->dwSeverity);
       }
-      delete pResponce;
-   }
-   else
-   {
-      dwRetCode = RCC_TIMEOUT;
-   }
-   return dwRetCode;
+   MutexUnlock(m_mutexEventAccess);
+   return -1;
 }
 
 
 //
-// Get pointer to event names list
+// Lock/unlock event DB
 //
 
-NXC_EVENT_NAME LIBNXCL_EXPORTABLE *NXCGetEventNamesList(DWORD *pdwNumEvents)
+static DWORD DoEventDBLock(BOOL bLock)
 {
-   *pdwNumEvents = m_dwNumEvents;
-   return m_pEventNamesList;
+   CSCPMessage msg;
+   DWORD dwRqId;
+
+   dwRqId = g_dwMsgId++;
+
+   // Prepare message
+   msg.SetCode(bLock ? CMD_LOCK_EVENT_DB : CMD_UNLOCK_EVENT_DB);
+   msg.SetId(dwRqId);
+   SendMsg(&msg);
+   
+   // Wait for reply
+   return WaitForRCC(dwRqId);
 }
 
 
 //
-// Resolve event id to name
+// Lock event DB
 //
 
-const TCHAR LIBNXCL_EXPORTABLE *NXCGetEventName(DWORD dwId)
+DWORD LIBNXCL_EXPORTABLE NXCLockEventDB(void)
 {
-   DWORD i;
-
-   for(i = 0; i < m_dwNumEvents; i++)
-      if (m_pEventNamesList[i].dwEventId == dwId)
-         return m_pEventNamesList[i].szName;
-   return _T("<unknown>");
+   return DoEventDBLock(TRUE);
 }
 
 
 //
-// Get severity for given event id. Will return -1 for unknown id.
+// Unlock event DB
 //
 
-int LIBNXCL_EXPORTABLE NXCGetEventSeverity(DWORD dwId)
+DWORD LIBNXCL_EXPORTABLE NXCUnlockEventDB(void)
 {
-   DWORD i;
-
-   for(i = 0; i < m_dwNumEvents; i++)
-      if (m_pEventNamesList[i].dwEventId == dwId)
-         return (int)(m_pEventNamesList[i].dwSeverity);
-   return -1;
+   return DoEventDBLock(FALSE);
 }
index e657b63..8c08bcb 100644 (file)
@@ -84,10 +84,13 @@ typedef struct
 void ObjectsInit(void);
 void DestroyAllObjects(void);
 
+void InitEventDB(void);
+void ShutdownEventDB(void);
+void ProcessEventDBRecord(CSCPMessage *pMsg);
+
 void ProcessAlarmUpdate(CSCPMessage *pMsg);
 void ProcessObjectUpdate(CSCPMessage *pMsg);
 void ProcessEvent(CSCPMessage *pMsg, CSCP_MESSAGE *pRawMsg);
-void ProcessEventDBRecord(CSCPMessage *pMsg);
 void ProcessActionUpdate(CSCPMessage *pMsg);
 
 void ProcessUserDBRecord(CSCPMessage *pMsg);
index 9e113ff..510cb7d 100644 (file)
@@ -42,6 +42,7 @@ BOOL LIBNXCL_EXPORTABLE NXCInitialize(void)
 {
    ObjectsInit();
    InitSyncStuff();
+   InitEventDB();
    return TRUE;
 }
 
@@ -53,6 +54,7 @@ BOOL LIBNXCL_EXPORTABLE NXCInitialize(void)
 void LIBNXCL_EXPORTABLE NXCShutdown(void)
 {
    SyncCleanup();
+   ShutdownEventDB();
 }
 
 
@@ -132,9 +134,10 @@ const TCHAR LIBNXCL_EXPORTABLE *NXCGetErrorText(DWORD dwError)
       _T("Copy operation failed for one or more DCI(s)"),
       _T("Invalid or unknown event code"),
       _T("No interfaces suitable for sending magic packet"),
-      _T("No MAC address on interface")
+      _T("No MAC address on interface"),
+      _T("Command not implemented")
    };
-   return ((dwError >= 0) && (dwError <= RCC_NO_MAC_ADDRESS)) ? pszErrorText[dwError] : _T("Unknown error code");
+   return ((dwError >= 0) && (dwError <= RCC_NOT_IMPLEMENTED)) ? pszErrorText[dwError] : _T("Unknown error code");
 }
 
 
index 9b1a4b9..8a18764 100644 (file)
@@ -234,6 +234,7 @@ static NXC_OBJECT *NewObjectFromMsg(CSCPMessage *pMsg)
          pMsg->GetVariableStr(VID_COMMUNITY_STRING, pObject->node.szCommunityString, MAX_COMMUNITY_LENGTH);
          pMsg->GetVariableStr(VID_SNMP_OID, pObject->node.szObjectId, MAX_OID_LENGTH);
          pObject->node.pszDescription = pMsg->GetVariableStr(VID_DESCRIPTION);
+         pObject->node.wSNMPVersion = pMsg->GetVariableShort(VID_SNMP_VERSION);
          break;
       case OBJECT_SUBNET:
          pObject->subnet.dwIpNetMask = pMsg->GetVariableLong(VID_IP_NETMASK);
@@ -485,6 +486,8 @@ DWORD LIBNXCL_EXPORTABLE NXCModifyObject(NXC_OBJECT_UPDATE *pUpdate)
       msg.SetVariable(VID_COMMUNITY_STRING, pUpdate->pszCommunity);
    if (pUpdate->dwFlags & OBJ_UPDATE_IMAGE)
       msg.SetVariable(VID_IMAGE_ID, pUpdate->dwImage);
+   if (pUpdate->dwFlags & OBJ_UPDATE_SNMP_VERSION)
+      msg.SetVariable(VID_SNMP_VERSION, pUpdate->wSNMPVersion);
    if (pUpdate->dwFlags & OBJ_UPDATE_DESCRIPTION)
       msg.SetVariable(VID_DESCRIPTION, pUpdate->pszDescription);
    if (pUpdate->dwFlags & OBJ_UPDATE_ACL)
index 83c85a0..e82a882 100644 (file)
@@ -1,7 +1,7 @@
 INCLUDES=-I@top_srcdir@/include -I@top_srcdir@/src/server/include
 
 bin_PROGRAMS = netxmsd
-netxmsd_SOURCES = acl.cpp actions.cpp admin.cpp alarm.cpp client.cpp config.cpp container.cpp datacoll.cpp dbwrite.cpp dcitem.cpp dcithreshold.cpp dcivalue.cpp debug.cpp discovery.cpp email.cpp entirenet.cpp epp.cpp events.cpp evproc.cpp hk.cpp id.cpp image.cpp interface.cpp locks.cpp main.cpp netinfo.cpp netobj.cpp node.cpp nortel.cpp np.cpp objects.cpp rootobj.cpp session.cpp snmp.cpp status.cpp subnet.cpp syncer.cpp template.cpp tools.cpp uniroot.cpp users.cpp watchdog.cpp winsrv.cpp
+netxmsd_SOURCES = acl.cpp actions.cpp admin.cpp alarm.cpp client.cpp config.cpp container.cpp datacoll.cpp dbwrite.cpp dcitem.cpp dcithreshold.cpp dcivalue.cpp debug.cpp discovery.cpp email.cpp entirenet.cpp epp.cpp events.cpp evproc.cpp hk.cpp id.cpp image.cpp interface.cpp locks.cpp main.cpp netinfo.cpp netobj.cpp node.cpp nortel.cpp np.cpp objects.cpp rootobj.cpp session.cpp snmp.cpp snmptrap.cpp status.cpp subnet.cpp syncer.cpp template.cpp tools.cpp uniroot.cpp users.cpp watchdog.cpp winsrv.cpp
 netxmsd_LDADD = @PTHREAD_LIBS@ ../../libnetxms/libnetxms.la ../../libnxcscp/libnxcscp.la ../libnxsrv/libnxsrv.la -lsnmp
 
 EXTRA_DIST = \
index f222925..c58c0c5 100644 (file)
@@ -203,7 +203,9 @@ THREAD_RESULT THREAD_CALL LocalAdminListener(void *pArg)
    if (bind(sock, (struct sockaddr *)&servAddr, sizeof(struct sockaddr_in)) != 0)
    {
       WriteLog(MSG_BIND_ERROR, EVENTLOG_ERROR_TYPE, "dse", LOCAL_ADMIN_PORT, "LocalAdminListener", WSAGetLastError());
-      exit(1);
+      closesocket(sock);
+      /* TODO: we should initiate shutdown from here */
+      return THREAD_OK;
    }
 
    // Set up queue
index e82667c..b4bda67 100644 (file)
@@ -110,7 +110,9 @@ THREAD_RESULT THREAD_CALL ClientListener(void *)
    if (bind(sock, (struct sockaddr *)&servAddr, sizeof(struct sockaddr_in)) != 0)
    {
       WriteLog(MSG_BIND_ERROR, EVENTLOG_ERROR_TYPE, "dse", wListenPort, "ClientListener", WSAGetLastError());
-      exit(1);
+      closesocket(sock);
+      /* TODO: we should initiate shutdown procedure here */
+      return THREAD_OK;
    }
 
    // Set up queue
index 119c9a8..56d51a9 100644 (file)
@@ -35,7 +35,8 @@
 //
 
 static MUTEX m_mutexTableAccess;
-static DWORD m_dwFreeIdTable[NUMBER_OF_GROUPS] = { 10, 1, 10000, 1, 1, 1000, 1, 0x80000000,
+static DWORD m_dwFreeIdTable[NUMBER_OF_GROUPS] = { 10, 1, FIRST_USER_EVENT_ID, 1, 1, 
+                                                   1000, 1, 0x80000000,
                                                    1, 1, 0x80000001, 1, 1 };
 static DWORD m_dwIdLimits[NUMBER_OF_GROUPS] = { 0xFFFFFFFE, 0xFFFFFFFE, 0x7FFFFFFF, 0x7FFFFFFF, 
                                                 0x7FFFFFFF, 0xFFFFFFFE, 0x7FFFFFFF, 0xFFFFFFFF,
@@ -46,7 +47,7 @@ static char *m_pszGroupNames[] =
 {
    "Network Objects",
    "Container Categories",
-   "User-defined Events",
+   "Events",
    "Data Collection Items",
    "<unused>",
    "Images",
@@ -134,7 +135,7 @@ BOOL InitIdTable(void)
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
-         m_dwFreeIdTable[IDG_EVENT] = max(10000, DBGetFieldULong(hResult, 0, 0) + 1);
+         m_dwFreeIdTable[IDG_EVENT] = max(m_dwFreeIdTable[IDG_EVENT], DBGetFieldULong(hResult, 0, 0) + 1);
       DBFreeResult(hResult);
    }
 
index f2fd69a..55154ab 100644 (file)
@@ -52,6 +52,7 @@ THREAD_RESULT THREAD_CALL EventProcessor(void *pArg);
 THREAD_RESULT THREAD_CALL WatchdogThread(void *pArg);
 THREAD_RESULT THREAD_CALL ClientListener(void *pArg);
 THREAD_RESULT THREAD_CALL LocalAdminListener(void *pArg);
+THREAD_RESULT THREAD_CALL SNMPTrapReceiver(void *pArg);
 
 
 //
@@ -287,6 +288,10 @@ BOOL Initialize(void)
    for(i = 0; i < iNumThreads; i++)
       ThreadCreate(EventProcessor, 0, (void *)(i + 1));
 
+   // Start SNMP trapper
+   if (ConfigReadInt("EnableSNMPTraps", 1))
+      ThreadCreate(SNMPTrapReceiver, 0, NULL);
+
    // Start database "lazy" write thread
    StartDBWriter();
 
index f4bbd17..cc66532 100644 (file)
@@ -232,6 +232,10 @@ SOURCE=.\snmp.cpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\snmptrap.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\status.cpp
 # End Source File
 # Begin Source File
index 61c9c65..1275c83 100644 (file)
@@ -257,8 +257,11 @@ private:
    void LockUserDB(DWORD dwRqId, BOOL bLock);
    void SetConfigVariable(CSCPMessage *pRequest);
    void SendEventDB(DWORD dwRqId);
-   void CloseEventDB(DWORD dwRqId);
+   void LockEventDB(DWORD dwRqId);
+   void UnlockEventDB(DWORD dwRqId);
    void SetEventInfo(CSCPMessage *pRequest);
+   void DeleteEventTemplate(CSCPMessage *pRequest);
+   void GenerateEventId(DWORD dwRqId);
    void ModifyObject(CSCPMessage *pRequest);
    void ChangeObjectMgmtStatus(CSCPMessage *pRequest);
    void OpenNodeDCIList(CSCPMessage *pRequest);
@@ -272,7 +275,6 @@ private:
    void ProcessEPPRecord(CSCPMessage *pRequest);
    void SendMIBList(DWORD dwRqId);
    void SendMIB(CSCPMessage *pRequest);
-   void SendEventNames(DWORD dwRqId);
    void CreateObject(CSCPMessage *pRequest);
    void ChangeObjectBinding(CSCPMessage *pRequest, BOOL bBind);
    void DeleteObject(CSCPMessage *pRequest);
@@ -340,11 +342,11 @@ void StartDBWriter(void);
 void StopDBWriter(void);
 
 void SnmpInit(void);
-BOOL SnmpGet(DWORD dwAddr, const char *szCommunity, const char *szOidStr,
+BOOL SnmpGet(DWORD dwVersion, DWORD dwAddr, const char *szCommunity, const char *szOidStr,
              const oid *oidBinary, size_t iOidLen, void *pValue,
              DWORD dwBufferSize, BOOL bVerbose, BOOL bStringResult);
-BOOL SnmpEnumerate(DWORD dwAddr, const char *szCommunity, const char *szRootOid,
-                   void (* pHandler)(DWORD, const char *, variable_list *, void *), 
+BOOL SnmpEnumerate(DWORD dwVersion, DWORD dwAddr, const char *szCommunity, const char *szRootOid,
+                   void (* pHandler)(DWORD, DWORD, const char *, variable_list *, void *), 
                    void *pUserArg, BOOL bVerbose);
 void OidToStr(oid *pOid, int iOidLen, char *szBuffer, DWORD dwBufferSize);
 void StrToMac(char *pszStr, BYTE *pBuffer);
@@ -353,9 +355,9 @@ DWORD OidToType(TCHAR *pszOid, DWORD *pdwFlags);
 void InitLocalNetInfo(void);
 
 ARP_CACHE *GetLocalArpCache(void);
-ARP_CACHE *SnmpGetArpCache(DWORD dwAddr, const char *szCommunity);
+ARP_CACHE *SnmpGetArpCache(DWORD dwVersion, DWORD dwAddr, const char *szCommunity);
 
-INTERFACE_LIST *SnmpGetInterfaceList(DWORD dwAddr, const char *szCommunity, DWORD dwNodeType);
+INTERFACE_LIST *SnmpGetInterfaceList(DWORD dwVersion, DWORD dwAddr, const char *szCommunity, DWORD dwNodeType);
 INTERFACE_LIST *GetLocalInterfaceList(void);
 void CleanInterfaceList(INTERFACE_LIST *pIfList);
 
@@ -393,7 +395,7 @@ void InitMailer(void);
 void ShutdownMailer(void);
 void PostMail(char *pszRcpt, char *pszSubject, char *pszText);
 
-void GetAccelarVLANIfList(DWORD dwIpAddr, const TCHAR *pszCommunity, INTERFACE_LIST *pIfList);
+void GetAccelarVLANIfList(DWORD dwVersion, DWORD dwIpAddr, const TCHAR *pszCommunity, INTERFACE_LIST *pIfList);
 
 #ifdef _WIN32
 
index 91e90c6..0857e5e 100644 (file)
@@ -327,13 +327,26 @@ BOOL Node::NewNodePoll(DWORD dwNetMask)
    PollerLock();
 
    // Determine node's capabilities
-   if (SnmpGet(m_dwIpAddr, m_szCommunityString, ".1.3.6.1.2.1.1.2.0", NULL, 0,
+   if (SnmpGet(SNMP_VERSION_2c, m_dwIpAddr, m_szCommunityString, ".1.3.6.1.2.1.1.2.0", NULL, 0,
                m_szObjectId, MAX_OID_LEN * 4, FALSE, FALSE))
    {
       DWORD dwNodeFlags;
 
       m_dwNodeType = OidToType(m_szObjectId, &dwNodeFlags);
       m_dwFlags |= NF_IS_SNMP | dwNodeFlags;
+      m_iSNMPVersion = SNMP_VERSION_2c;
+   }
+   else
+   {
+      if (SnmpGet(SNMP_VERSION_1, m_dwIpAddr, m_szCommunityString, ".1.3.6.1.2.1.1.2.0", NULL, 0,
+                  m_szObjectId, MAX_OID_LEN * 4, FALSE, FALSE))
+      {
+         DWORD dwNodeFlags;
+
+         m_dwNodeType = OidToType(m_szObjectId, &dwNodeFlags);
+         m_dwFlags |= NF_IS_SNMP | dwNodeFlags;
+         m_iSNMPVersion = SNMP_VERSION_1;
+      }
    }
 
    pAgentConn = new AgentConnection(htonl(m_dwIpAddr), m_wAgentPort, m_wAuthMethod,
@@ -356,7 +369,7 @@ BOOL Node::NewNodePoll(DWORD dwNetMask)
          CleanInterfaceList(pIfList);
       }
       if ((pIfList == NULL) && (m_dwFlags & NF_IS_SNMP))  // Use SNMP if we cannot get interfaces via agent
-         pIfList = SnmpGetInterfaceList(m_dwIpAddr, m_szCommunityString, m_dwNodeType);
+         pIfList = SnmpGetInterfaceList(m_iSNMPVersion, m_dwIpAddr, m_szCommunityString, m_dwNodeType);
 
       if (pIfList != NULL)
       {
@@ -412,7 +425,7 @@ ARP_CACHE *Node::GetArpCache(void)
    }
    else if (m_dwFlags & NF_IS_SNMP)
    {
-      pArpCache = SnmpGetArpCache(m_dwIpAddr, m_szCommunityString);
+      pArpCache = SnmpGetArpCache(m_iSNMPVersion, m_dwIpAddr, m_szCommunityString);
    }
 
    return pArpCache;
@@ -443,7 +456,7 @@ INTERFACE_LIST *Node::GetInterfaceList(void)
    }
    else if (m_dwFlags & NF_IS_SNMP)
    {
-      pIfList = SnmpGetInterfaceList(m_dwIpAddr, m_szCommunityString, m_dwNodeType);
+      pIfList = SnmpGetInterfaceList(m_iSNMPVersion, m_dwIpAddr, m_szCommunityString, m_dwNodeType);
    }
 
    return pIfList;
@@ -660,7 +673,7 @@ void Node::ConfigurationPoll(ClientSession *pSession, DWORD dwRqId)
 
    // Check node's capabilities
    SendPollerMsg(dwRqId, _T("Checking node's capabilities...\r\n"));
-   if (SnmpGet(m_dwIpAddr, m_szCommunityString, ".1.3.6.1.2.1.1.2.0", NULL, 0,
+   if (SnmpGet(m_iSNMPVersion, m_dwIpAddr, m_szCommunityString, ".1.3.6.1.2.1.1.2.0", NULL, 0,
                m_szObjectId, MAX_OID_LEN * 4, FALSE, FALSE))
    {
       DWORD dwNodeFlags, dwNodeType;
@@ -841,7 +854,7 @@ BOOL Node::ConnectToAgent(void)
 
 DWORD Node::GetItemFromSNMP(const char *szParam, DWORD dwBufSize, char *szBuffer)
 {
-   return SnmpGet(m_dwIpAddr, m_szCommunityString, szParam, NULL, 0,
+   return SnmpGet(m_iSNMPVersion, m_dwIpAddr, m_szCommunityString, szParam, NULL, 0,
                   szBuffer, dwBufSize, FALSE, TRUE) ? DCE_SUCCESS : DCE_COMM_ERROR;
 }
 
@@ -965,6 +978,7 @@ void Node::CreateMessage(CSCPMessage *pMsg)
    pMsg->SetVariable(VID_COMMUNITY_STRING, m_szCommunityString);
    pMsg->SetVariable(VID_SNMP_OID, m_szObjectId);
    pMsg->SetVariable(VID_NODE_TYPE, m_dwNodeType);
+   pMsg->SetVariable(VID_SNMP_VERSION, (WORD)m_iSNMPVersion);
 }
 
 
@@ -989,6 +1003,10 @@ DWORD Node::ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked)
    if (pRequest->IsVariableExist(VID_SHARED_SECRET))
       pRequest->GetVariableStr(VID_SHARED_SECRET, m_szSharedSecret, MAX_SECRET_LENGTH);
 
+   // Change SNMP protocol version
+   if (pRequest->IsVariableExist(VID_SNMP_VERSION))
+      m_iSNMPVersion = pRequest->GetVariableShort(VID_SNMP_VERSION);
+
    // Change SNMP community string
    if (pRequest->IsVariableExist(VID_COMMUNITY_STRING))
       pRequest->GetVariableStr(VID_COMMUNITY_STRING, m_szCommunityString, MAX_COMMUNITY_LENGTH);
index 08724aa..22a6782 100644 (file)
@@ -46,7 +46,7 @@ struct VLAN_LIST
 // Handler for VLAN enumeration on Passport
 //
 
-static void HandlerVlanList(DWORD dwAddr, const char *pszCommunity, variable_list *pVar, void *pArg)
+static void HandlerVlanList(DWORD dwVersion, DWORD dwAddr, const char *pszCommunity, variable_list *pVar, void *pArg)
 {
    oid oidName[MAX_OID_LEN];
    VLAN_LIST *pVlanList = (VLAN_LIST *)pArg;
@@ -62,19 +62,19 @@ static void HandlerVlanList(DWORD dwAddr, const char *pszCommunity, variable_lis
    // Get VLAN name
    memcpy(oidName, pVar->name, pVar->name_length * sizeof(oid));
    oidName[pVar->name_length - 2] = 2;
-   SnmpGet(dwAddr, pszCommunity, NULL, oidName, pVar->name_length, 
+   SnmpGet(dwVersion, dwAddr, pszCommunity, NULL, oidName, pVar->name_length, 
            pVlanList->pList[dwIndex].szName, MAX_OBJECT_NAME, FALSE, FALSE);
 
    // Get VLAN interface index
    oidName[pVar->name_length - 2] = 6;
-   SnmpGet(dwAddr, pszCommunity, NULL, oidName, pVar->name_length, 
+   SnmpGet(dwVersion, dwAddr, pszCommunity, NULL, oidName, pVar->name_length, 
            &pVlanList->pList[dwIndex].dwIfIndex, sizeof(DWORD), FALSE, FALSE);
 
    // Get VLAN MAC address
    oidName[pVar->name_length - 2] = 19;
    memset(pVlanList->pList[dwIndex].bMacAddr, 0, MAC_ADDR_LENGTH);
    memset(szBuffer, 0, MAC_ADDR_LENGTH);
-   SnmpGet(dwAddr, pszCommunity, NULL, oidName, pVar->name_length, 
+   SnmpGet(dwVersion, dwAddr, pszCommunity, NULL, oidName, pVar->name_length, 
            szBuffer, 256, FALSE, FALSE);
    memcpy(pVlanList->pList[dwIndex].bMacAddr, szBuffer, MAC_ADDR_LENGTH);
 }
@@ -84,7 +84,7 @@ static void HandlerVlanList(DWORD dwAddr, const char *pszCommunity, variable_lis
 // Handler for VLAN enumeration on Passport
 //
 
-static void HandlerPassportIfList(DWORD dwAddr, const char *pszCommunity, variable_list *pVar, void *pArg)
+static void HandlerPassportIfList(DWORD dwVersion, DWORD dwAddr, const char *pszCommunity, variable_list *pVar, void *pArg)
 {
    oid oidName[MAX_OID_LEN];
    INTERFACE_LIST *pIfList = (INTERFACE_LIST *)pArg;
@@ -113,12 +113,12 @@ static void HandlerPassportIfList(DWORD dwAddr, const char *pszCommunity, variab
       // Get IP address
       memcpy(oidName, pVar->name, pVar->name_length * sizeof(oid));
       oidName[pVar->name_length - 6] = 2;
-      SnmpGet(dwAddr, pszCommunity, NULL, oidName, pVar->name_length,
+      SnmpGet(dwVersion, dwAddr, pszCommunity, NULL, oidName, pVar->name_length,
               &pIfList->pInterfaces[iIndex].dwIpAddr, sizeof(DWORD), FALSE, FALSE);
 
       // Get netmask
       oidName[pVar->name_length - 6] = 3;
-      SnmpGet(dwAddr, pszCommunity, NULL, oidName, pVar->name_length,
+      SnmpGet(dwVersion, dwAddr, pszCommunity, NULL, oidName, pVar->name_length,
               &pIfList->pInterfaces[iIndex].dwIpNetMask, sizeof(DWORD), FALSE, FALSE);
    }
 }
@@ -128,18 +128,18 @@ static void HandlerPassportIfList(DWORD dwAddr, const char *pszCommunity, variab
 // Get list of VLAN interfaces from Nortel Passport 8000/Accelar switch
 //
 
-void GetAccelarVLANIfList(DWORD dwIpAddr, const TCHAR *pszCommunity, INTERFACE_LIST *pIfList)
+void GetAccelarVLANIfList(DWORD dwVersion, DWORD dwIpAddr, const TCHAR *pszCommunity, INTERFACE_LIST *pIfList)
 {
    VLAN_LIST vlanList;
 
    // Get VLAN list
    memset(&vlanList, 0, sizeof(VLAN_LIST));
-   SnmpEnumerate(dwIpAddr, pszCommunity, _T(".1.3.6.1.4.1.2272.1.3.2.1.1"), 
+   SnmpEnumerate(dwVersion, dwIpAddr, pszCommunity, _T(".1.3.6.1.4.1.2272.1.3.2.1.1"), 
                  HandlerVlanList, &vlanList, FALSE);
 
    // Get interfaces
    pIfList->pArg = &vlanList;
-   SnmpEnumerate(dwIpAddr, pszCommunity, _T(".1.3.6.1.4.1.2272.1.8.2.1.1"), 
+   SnmpEnumerate(dwVersion, dwIpAddr, pszCommunity, _T(".1.3.6.1.4.1.2272.1.8.2.1.1"), 
                  HandlerPassportIfList, pIfList, FALSE);
    safe_free(vlanList.pList);
 }
index 1866aaa..f8fda7e 100644 (file)
@@ -435,15 +435,24 @@ void ClientSession::ProcessingThread(void)
          case CMD_GET_CONFIG_VARLIST:
             SendAllConfigVars();
             break;
-         case CMD_OPEN_EVENT_DB:
+         case CMD_LOAD_EVENT_DB:
             SendEventDB(pMsg->GetId());
             break;
-         case CMD_CLOSE_EVENT_DB:
-            CloseEventDB(pMsg->GetId());
+         case CMD_LOCK_EVENT_DB:
+            LockEventDB(pMsg->GetId());
+            break;
+         case CMD_UNLOCK_EVENT_DB:
+            UnlockEventDB(pMsg->GetId());
             break;
          case CMD_SET_EVENT_INFO:
             SetEventInfo(pMsg);
             break;
+         case CMD_DELETE_EVENT_TEMPLATE:
+            DeleteEventTemplate(pMsg);
+            break;
+         case CMD_GENERATE_EVENT_ID:
+            GenerateEventId(pMsg->GetId());
+            break;
          case CMD_MODIFY_OBJECT:
             ModifyObject(pMsg);
             break;
@@ -515,9 +524,6 @@ void ClientSession::ProcessingThread(void)
          case CMD_UNBIND_OBJECT:
             ChangeObjectBinding(pMsg, FALSE);
             break;
-         case CMD_GET_EVENT_NAMES:
-            SendEventNames(pMsg->GetId());
-            break;
          case CMD_GET_IMAGE_LIST:
             SendImageCatalogue(this, pMsg->GetId(), pMsg->GetVariableShort(VID_IMAGE_FORMAT));
             break;
@@ -572,6 +578,14 @@ void ClientSession::ProcessingThread(void)
             OnWakeUpNode(pMsg);
             break;
          default:
+            {
+               CSCPMessage responce;
+
+               responce.SetId(pMsg->GetId());
+               responce.SetCode(CMD_REQUEST_COMPLETED);
+               responce.SetVariable(VID_RCC, RCC_NOT_IMPLEMENTED);
+               SendMessage(&responce);
+            }
             break;
       }
       delete pMsg;
@@ -640,17 +654,8 @@ void ClientSession::SendEventDB(DWORD dwRqId)
       msg.SetVariable(VID_RCC, RCC_ACCESS_DENIED);
       SendMessage(&msg);
    }
-   else if (!LockComponent(CID_EVENT_DB, m_dwIndex, m_szUserName, NULL, szBuffer))
-   {
-      msg.SetVariable(VID_RCC, RCC_COMPONENT_LOCKED);
-      msg.SetVariable(VID_LOCKED_BY, szBuffer);
-      SendMessage(&msg);
-   }
    else
    {
-      m_dwFlags |= CSF_EVENT_DB_LOCKED;
-      m_dwFlags &= ~CSF_EVENT_DB_MODIFIED;
-
       msg.SetVariable(VID_RCC, RCC_SUCCESS);
       SendMessage(&msg);
       msg.DeleteAllVariables();
@@ -684,17 +689,50 @@ void ClientSession::SendEventDB(DWORD dwRqId)
       }
 
       // Send end-of-list indicator
-      msg.SetCode(CMD_EVENT_DB_EOF);
+      msg.SetVariable(VID_EVENT_ID, (DWORD)0);
       SendMessage(&msg);
    }
 }
 
 
 //
+// Lock event configuration database
+//
+
+void ClientSession::LockEventDB(DWORD dwRqId)
+{
+   CSCPMessage msg;
+   char szBuffer[1024];
+
+   // Prepare responce message
+   msg.SetCode(CMD_REQUEST_COMPLETED);
+   msg.SetId(dwRqId);
+
+   if (!CheckSysAccessRights(SYSTEM_ACCESS_EDIT_EVENT_DB))
+   {
+      msg.SetVariable(VID_RCC, RCC_ACCESS_DENIED);
+   }
+   else if (!LockComponent(CID_EVENT_DB, m_dwIndex, m_szUserName, NULL, szBuffer))
+   {
+      msg.SetVariable(VID_RCC, RCC_COMPONENT_LOCKED);
+      msg.SetVariable(VID_LOCKED_BY, szBuffer);
+   }
+   else
+   {
+      m_dwFlags |= CSF_EVENT_DB_LOCKED;
+      m_dwFlags &= ~CSF_EVENT_DB_MODIFIED;
+
+      msg.SetVariable(VID_RCC, RCC_SUCCESS);
+   }
+   SendMessage(&msg);
+}
+
+
+//
 // Close event configuration database
 //
 
-void ClientSession::CloseEventDB(DWORD dwRqId)
+void ClientSession::UnlockEventDB(DWORD dwRqId)
 {
    CSCPMessage msg;
 
@@ -724,6 +762,192 @@ void ClientSession::CloseEventDB(DWORD dwRqId)
 
 
 //
+// Update event template
+//
+
+void ClientSession::SetEventInfo(CSCPMessage *pRequest)
+{
+   CSCPMessage msg;
+
+   // Prepare reply message
+   msg.SetCode(CMD_REQUEST_COMPLETED);
+   msg.SetId(pRequest->GetId());
+
+   // Check if we have event configuration database opened
+   if (!(m_dwFlags & CSF_EVENT_DB_LOCKED))
+   {
+      msg.SetVariable(VID_RCC, RCC_OUT_OF_STATE_REQUEST);
+   }
+   else
+   {
+      // Check access rights
+      if (CheckSysAccessRights(SYSTEM_ACCESS_EDIT_EVENT_DB))
+      {
+         char szQuery[4096], szName[MAX_EVENT_NAME];
+         DWORD dwEventId;
+         BOOL bEventExist = FALSE;
+         DB_RESULT hResult;
+
+         // Check if event with specific id exists
+         dwEventId = pRequest->GetVariableLong(VID_EVENT_ID);
+         sprintf(szQuery, "SELECT event_id FROM events WHERE event_id=%ld", dwEventId);
+         hResult = DBSelect(g_hCoreDB, szQuery);
+         if (hResult != NULL)
+         {
+            if (DBGetNumRows(hResult) > 0)
+               bEventExist = TRUE;
+            DBFreeResult(hResult);
+         }
+
+         // Check that we are not trying to create event below 100000
+         if (bEventExist || (dwEventId >= FIRST_USER_EVENT_ID))
+         {
+            // Prepare and execute SQL query
+            pRequest->GetVariableStr(VID_NAME, szName, MAX_EVENT_NAME);
+            if (IsValidObjectName(szName))
+            {
+               char szMessage[MAX_DB_STRING], *pszDescription, *pszEscMsg, *pszEscDescr;
+
+               pRequest->GetVariableStr(VID_MESSAGE, szMessage, MAX_DB_STRING);
+               pszEscMsg = EncodeSQLString(szMessage);
+
+               pszDescription = pRequest->GetVariableStr(VID_DESCRIPTION);
+               pszEscDescr = EncodeSQLString(pszDescription);
+               safe_free(pszDescription);
+
+               if (bEventExist)
+               {
+                  sprintf(szQuery, "UPDATE events SET name='%s',severity=%ld,flags=%ld,message='%s',description='%s' WHERE event_id=%ld",
+                          szName, pRequest->GetVariableLong(VID_SEVERITY), pRequest->GetVariableLong(VID_FLAGS),
+                          pszEscMsg, pszEscDescr, dwEventId);
+               }
+               else
+               {
+                  sprintf(szQuery, "INSERT INTO events (event_id,name,severity,flags,"
+                                   "message,description) VALUES (%ld,'%s',%ld,%ld,'%s','%s')",
+                          dwEventId, szName, pRequest->GetVariableLong(VID_SEVERITY),
+                          pRequest->GetVariableLong(VID_FLAGS), pszEscMsg, pszEscDescr);
+               }
+
+               free(pszEscMsg);
+               free(pszEscDescr);
+
+               if (DBQuery(g_hCoreDB, szQuery))
+               {
+                  msg.SetVariable(VID_RCC, RCC_SUCCESS);
+                  m_dwFlags |= CSF_EVENT_DB_MODIFIED;
+               }
+               else
+               {
+                  msg.SetVariable(VID_RCC, RCC_DB_FAILURE);
+               }
+            }
+            else
+            {
+               msg.SetVariable(VID_RCC, RCC_INVALID_OBJECT_NAME);
+            }
+         }
+         else
+         {
+            msg.SetVariable(VID_RCC, RCC_INVALID_EVENT_CODE);
+         }
+      }
+      else
+      {
+         msg.SetVariable(VID_RCC, RCC_ACCESS_DENIED);
+      }
+   }
+
+   // Send responce
+   SendMessage(&msg);
+}
+
+
+//
+// Delete event template
+//
+
+void ClientSession::DeleteEventTemplate(CSCPMessage *pRequest)
+{
+   CSCPMessage msg;
+   DWORD dwEventId;
+
+   // Prepare reply message
+   msg.SetCode(CMD_REQUEST_COMPLETED);
+   msg.SetId(pRequest->GetId());
+
+   // Check if we have event configuration database opened
+   if (!(m_dwFlags & CSF_EVENT_DB_LOCKED))
+   {
+      msg.SetVariable(VID_RCC, RCC_OUT_OF_STATE_REQUEST);
+   }
+   else
+   {
+      dwEventId = pRequest->GetVariableLong(VID_EVENT_ID);
+
+      // Check access rights
+      if (CheckSysAccessRights(SYSTEM_ACCESS_EDIT_EVENT_DB) && (dwEventId >= FIRST_USER_EVENT_ID))
+      {
+         TCHAR szQuery[256];
+
+         _stprintf(szQuery, _T("DELETE FROM events WHERE event_id=%ld"), dwEventId);
+         if (DBQuery(g_hCoreDB, szQuery))
+         {
+            msg.SetVariable(VID_RCC, RCC_SUCCESS);
+            m_dwFlags |= CSF_EVENT_DB_LOCKED;
+         }
+         else
+         {
+            msg.SetVariable(VID_RCC, RCC_DB_FAILURE);
+         }
+      }
+      else
+      {
+         msg.SetVariable(VID_RCC, RCC_ACCESS_DENIED);
+      }
+   }
+
+   // Send responce
+   SendMessage(&msg);
+}
+
+
+//
+// Generate ID for new event template
+//
+
+void ClientSession::GenerateEventId(DWORD dwRqId)
+{
+   CSCPMessage msg;
+
+   // Prepare reply message
+   msg.SetCode(CMD_REQUEST_COMPLETED);
+   msg.SetId(dwRqId);
+
+   // Check if we have event configuration database opened
+   if (!(m_dwFlags & CSF_EVENT_DB_LOCKED))
+   {
+      msg.SetVariable(VID_RCC, RCC_OUT_OF_STATE_REQUEST);
+   }
+   else
+   {
+      // Check access rights
+      if (CheckSysAccessRights(SYSTEM_ACCESS_EDIT_EVENT_DB))
+      {
+         msg.SetVariable(VID_EVENT_ID, CreateUniqueId(IDG_EVENT));
+      }
+      else
+      {
+         msg.SetVariable(VID_RCC, RCC_ACCESS_DENIED);
+      }
+   }
+
+   // Send responce
+   SendMessage(&msg);
+}
+
+
+//
 // Send all objects to client
 //
 
@@ -924,99 +1148,6 @@ void ClientSession::Notify(DWORD dwCode, DWORD dwData)
 
 
 //
-// Update event template
-//
-
-void ClientSession::SetEventInfo(CSCPMessage *pRequest)
-{
-   CSCPMessage msg;
-
-   // Prepare reply message
-   msg.SetCode(CMD_REQUEST_COMPLETED);
-   msg.SetId(pRequest->GetId());
-
-   // Check if we have event configuration database opened
-   if (!(m_dwFlags & CSF_EVENT_DB_LOCKED))
-   {
-      msg.SetVariable(VID_RCC, RCC_OUT_OF_STATE_REQUEST);
-   }
-   else
-   {
-      // Check access rights
-      if (CheckSysAccessRights(SYSTEM_ACCESS_EDIT_EVENT_DB))
-      {
-         char szQuery[4096], szName[MAX_EVENT_NAME];
-         DWORD dwEventId;
-         BOOL bEventExist = FALSE;
-         DB_RESULT hResult;
-
-         // Check if event with specific id exists
-         dwEventId = pRequest->GetVariableLong(VID_EVENT_ID);
-         sprintf(szQuery, "SELECT event_id FROM events WHERE event_id=%ld", dwEventId);
-         hResult = DBSelect(g_hCoreDB, szQuery);
-         if (hResult != NULL)
-         {
-            if (DBGetNumRows(hResult) > 0)
-               bEventExist = TRUE;
-            DBFreeResult(hResult);
-         }
-
-         // Prepare and execute SQL query
-         pRequest->GetVariableStr(VID_NAME, szName, MAX_EVENT_NAME);
-         if (IsValidObjectName(szName))
-         {
-            char szMessage[MAX_DB_STRING], *pszDescription, *pszEscMsg, *pszEscDescr;
-
-            pRequest->GetVariableStr(VID_MESSAGE, szMessage, MAX_DB_STRING);
-            pszEscMsg = EncodeSQLString(szMessage);
-
-            pszDescription = pRequest->GetVariableStr(VID_DESCRIPTION);
-            pszEscDescr = EncodeSQLString(pszDescription);
-            safe_free(pszDescription);
-
-            if (bEventExist)
-            {
-               sprintf(szQuery, "UPDATE events SET name='%s',severity=%ld,flags=%ld,message='%s',description='%s' WHERE event_id=%ld",
-                       szName, pRequest->GetVariableLong(VID_SEVERITY), pRequest->GetVariableLong(VID_FLAGS),
-                       pszEscMsg, pszEscDescr, dwEventId);
-            }
-            else
-            {
-               sprintf(szQuery, "INSERT INTO events SET event_id,name,severity,flags,message,description VALUES (%ld,'%s',%ld,%ld,'%s','%s')",
-                       dwEventId, szName, pRequest->GetVariableLong(VID_SEVERITY),
-                       pRequest->GetVariableLong(VID_FLAGS), pszEscMsg, pszEscDescr);
-            }
-
-            free(pszEscMsg);
-            free(pszEscDescr);
-
-            if (DBQuery(g_hCoreDB, szQuery))
-            {
-               msg.SetVariable(VID_RCC, RCC_SUCCESS);
-               m_dwFlags |= CSF_EVENT_DB_MODIFIED;
-            }
-            else
-            {
-               msg.SetVariable(VID_RCC, RCC_DB_FAILURE);
-            }
-         }
-         else
-         {
-            msg.SetVariable(VID_RCC, RCC_INVALID_OBJECT_NAME);
-         }
-      }
-      else
-      {
-         msg.SetVariable(VID_RCC, RCC_ACCESS_DENIED);
-      }
-   }
-
-   // Send responce
-   SendMessage(&msg);
-}
-
-
-//
 // Modify object
 //
 
@@ -2170,48 +2301,6 @@ void ClientSession::SendMIB(CSCPMessage *pRequest)
 
 
 //
-// Send list of event name/identifier pairs
-//
-
-void ClientSession::SendEventNames(DWORD dwRqId)
-{
-   CSCPMessage msg;
-   DB_RESULT hResult;
-
-   msg.SetCode(CMD_EVENT_NAME_LIST);
-   msg.SetId(dwRqId);
-   hResult = DBSelect(g_hCoreDB, "SELECT event_id,name,severity FROM events");
-   if (hResult != NULL)
-   {
-      DWORD i, dwNumEvents;
-      NXC_EVENT_NAME *pList;
-
-      dwNumEvents = DBGetNumRows(hResult);
-      msg.SetVariable(VID_NUM_EVENTS, dwNumEvents);
-      if (dwNumEvents > 0)
-      {
-         pList = (NXC_EVENT_NAME *)malloc(sizeof(NXC_EVENT_NAME) * dwNumEvents);
-         for(i = 0; i < dwNumEvents; i++)
-         {
-            pList[i].dwEventId = htonl(DBGetFieldULong(hResult, i, 0));
-            pList[i].dwSeverity = htonl(DBGetFieldLong(hResult, i, 2));
-            strcpy(pList[i].szName, DBGetField(hResult, i, 1));
-         }
-         msg.SetVariable(VID_EVENT_NAME_TABLE, (BYTE *)pList, sizeof(NXC_EVENT_NAME) * dwNumEvents);
-         free(pList);
-      }
-      DBFreeResult(hResult);
-      msg.SetVariable(VID_RCC, RCC_SUCCESS);
-   }
-   else
-   {
-      msg.SetVariable(VID_RCC, RCC_DB_FAILURE);
-   }
-   SendMessage(&msg);
-}
-
-
-//
 // Create new object
 //
 
index 4eb43c7..18a6942 100644 (file)
@@ -119,7 +119,7 @@ void OidToStr(oid *pOid, int iOidLen, char *szBuffer, DWORD dwBufferSize)
 // binary representation from oidBinary and iOidLen
 //
 
-BOOL SnmpGet(DWORD dwAddr, const char *szCommunity, const char *szOidStr,
+BOOL SnmpGet(DWORD dwVersion, DWORD dwAddr, const char *szCommunity, const char *szOidStr,
              const oid *oidBinary, size_t iOidLen, void *pValue,
              DWORD dwBufferSize, BOOL bVerbose, BOOL bStringResult)
 {
@@ -135,7 +135,7 @@ BOOL SnmpGet(DWORD dwAddr, const char *szCommunity, const char *szOidStr,
 
    // Open SNMP session
    snmp_sess_init(&session);
-   session.version = SNMP_VERSION_1;
+   session.version = dwVersion;
    session.peername = IpToStr(dwAddr, szNodeName);
    session.community = (unsigned char *)szCommunity;
    session.community_len = strlen((char *)session.community);
@@ -238,8 +238,9 @@ BOOL SnmpGet(DWORD dwAddr, const char *szCommunity, const char *szOidStr,
 // Enumerate multiple values by walking throgh MIB, starting at given root
 //
 
-BOOL SnmpEnumerate(DWORD dwAddr, const char *szCommunity, const char *szRootOid,
-                   void (* pHandler)(DWORD, const char *, variable_list *, void *), 
+BOOL SnmpEnumerate(DWORD dwVersion, DWORD dwAddr, const char *szCommunity, 
+                   const char *szRootOid,
+                   void (* pHandler)(DWORD, DWORD, const char *, variable_list *, void *), 
                    void *pUserArg, BOOL bVerbose)
 {
    struct snmp_session session;
@@ -254,7 +255,7 @@ BOOL SnmpEnumerate(DWORD dwAddr, const char *szCommunity, const char *szRootOid,
 
    // Open SNMP session
    snmp_sess_init(&session);
-   session.version = SNMP_VERSION_1;
+   session.version = dwVersion;
    session.peername = IpToStr(dwAddr, szNodeName);
    session.community = (unsigned char *)szCommunity;
    session.community_len = strlen((char *)session.community);
@@ -297,7 +298,7 @@ BOOL SnmpEnumerate(DWORD dwAddr, const char *szCommunity, const char *szRootOid,
             iNameLen = pVar->name_length;
 
             // Call user's callback function for processing
-            pHandler(dwAddr, szCommunity, pVar, pUserArg);
+            pHandler(dwVersion, dwAddr, szCommunity, pVar, pUserArg);
          }
       }
       else
@@ -334,7 +335,7 @@ BOOL SnmpEnumerate(DWORD dwAddr, const char *szCommunity, const char *szRootOid,
 // Handler for enumerating indexes
 //
 
-static void HandlerIndex(DWORD dwAddr, const char *szCommunity, variable_list *pVar,void *pArg)
+static void HandlerIndex(DWORD dwVersion, DWORD dwAddr, const char *szCommunity, variable_list *pVar,void *pArg)
 {
    if (((INTERFACE_LIST *)pArg)->iEnumPos < ((INTERFACE_LIST *)pArg)->iNumEntries)
       ((INTERFACE_LIST *)pArg)->pInterfaces[((INTERFACE_LIST *)pArg)->iEnumPos].dwIndex = *pVar->val.integer;
@@ -346,19 +347,19 @@ static void HandlerIndex(DWORD dwAddr, const char *szCommunity, variable_list *p
 // Handler for enumerating IP addresses
 //
 
-static void HandlerIpAddr(DWORD dwAddr, const char *szCommunity, variable_list *pVar, void *pArg)
+static void HandlerIpAddr(DWORD dwVersion, DWORD dwAddr, const char *szCommunity, variable_list *pVar, void *pArg)
 {
    DWORD dwIndex, dwNetMask;
    oid oidName[MAX_OID_LEN];
 
    memcpy(oidName, pVar->name, pVar->name_length * sizeof(oid));
    oidName[pVar->name_length - 5] = 3;  // Retrieve network mask for this IP
-   if (!SnmpGet(dwAddr, szCommunity, NULL, oidName, pVar->name_length,
+   if (!SnmpGet(dwVersion, dwAddr, szCommunity, NULL, oidName, pVar->name_length,
                 &dwNetMask, sizeof(DWORD), FALSE, FALSE))
       return;
 
    oidName[pVar->name_length - 5] = 2;  // Retrieve interface index for this IP
-   if (SnmpGet(dwAddr, szCommunity, NULL, oidName, pVar->name_length,
+   if (SnmpGet(dwVersion, dwAddr, szCommunity, NULL, oidName, pVar->name_length,
                &dwIndex, sizeof(DWORD), FALSE, FALSE))
    {
       int i;
@@ -396,14 +397,14 @@ static void HandlerIpAddr(DWORD dwAddr, const char *szCommunity, variable_list *
 // Get interface list via SNMP
 //
 
-INTERFACE_LIST *SnmpGetInterfaceList(DWORD dwAddr, const char *szCommunity, DWORD dwNodeType)
+INTERFACE_LIST *SnmpGetInterfaceList(DWORD dwVersion, DWORD dwAddr, const char *szCommunity, DWORD dwNodeType)
 {
    long i, iNumIf;
    char szOid[128], szBuffer[256];
    INTERFACE_LIST *pIfList = NULL;
 
    // Get number of interfaces
-   if (!SnmpGet(dwAddr, szCommunity, ".1.3.6.1.2.1.2.1.0", NULL, 0,
+   if (!SnmpGet(dwVersion, dwAddr, szCommunity, ".1.3.6.1.2.1.2.1.0", NULL, 0,
                 &iNumIf, sizeof(long), FALSE, FALSE))
       return NULL;
 
@@ -415,21 +416,21 @@ INTERFACE_LIST *SnmpGetInterfaceList(DWORD dwAddr, const char *szCommunity, DWOR
    memset(pIfList->pInterfaces, 0, sizeof(INTERFACE_INFO) * pIfList->iNumEntries);
 
    // Gather interface indexes
-   SnmpEnumerate(dwAddr, szCommunity, ".1.3.6.1.2.1.2.2.1.1", HandlerIndex, pIfList, FALSE);
+   SnmpEnumerate(dwVersion, dwAddr, szCommunity, ".1.3.6.1.2.1.2.2.1.1", HandlerIndex, pIfList, FALSE);
 
    // Enumerate interfaces
    for(i = 0; i < iNumIf; i++)
    {
       // Interface name
       sprintf(szOid, ".1.3.6.1.2.1.2.2.1.2.%d", pIfList->pInterfaces[i].dwIndex);
-      if (!SnmpGet(dwAddr, szCommunity, szOid, NULL, 0,
+      if (!SnmpGet(dwVersion, dwAddr, szCommunity, szOid, NULL, 0,
                    pIfList->pInterfaces[i].szName, MAX_OBJECT_NAME,
                    FALSE, FALSE))
          continue;
 
       // Interface type
       sprintf(szOid, ".1.3.6.1.2.1.2.2.1.3.%d", pIfList->pInterfaces[i].dwIndex);
-      if (!SnmpGet(dwAddr, szCommunity, szOid, NULL, 0,
+      if (!SnmpGet(dwVersion, dwAddr, szCommunity, szOid, NULL, 0,
                    &pIfList->pInterfaces[i].dwType, sizeof(DWORD),
                    FALSE, FALSE))
          continue;
@@ -437,18 +438,18 @@ INTERFACE_LIST *SnmpGetInterfaceList(DWORD dwAddr, const char *szCommunity, DWOR
       // MAC address
       sprintf(szOid, ".1.3.6.1.2.1.2.2.1.6.%d", pIfList->pInterfaces[i].dwIndex);
       memset(szBuffer, 0, MAC_ADDR_LENGTH);
-      if (!SnmpGet(dwAddr, szCommunity, szOid, NULL, 0,
+      if (!SnmpGet(dwVersion, dwAddr, szCommunity, szOid, NULL, 0,
                    szBuffer, 256, FALSE, TRUE))
          continue;
       memcpy(pIfList->pInterfaces[i].bMacAddr, szBuffer, MAC_ADDR_LENGTH);
    }
 
    // Interface IP address'es and netmasks
-   SnmpEnumerate(dwAddr, szCommunity, ".1.3.6.1.2.1.4.20.1.1", HandlerIpAddr, pIfList, FALSE);
+   SnmpEnumerate(dwVersion, dwAddr, szCommunity, ".1.3.6.1.2.1.4.20.1.1", HandlerIpAddr, pIfList, FALSE);
 
    // Handle special cases
    if (dwNodeType == NODE_TYPE_NORTEL_ACCELAR)
-      GetAccelarVLANIfList(dwAddr, szCommunity, pIfList);
+      GetAccelarVLANIfList(dwVersion, dwAddr, szCommunity, pIfList);
 
    CleanInterfaceList(pIfList);
 
@@ -460,7 +461,7 @@ INTERFACE_LIST *SnmpGetInterfaceList(DWORD dwAddr, const char *szCommunity, DWOR
 // Handler for ARP enumeration
 //
 
-static void HandlerArp(DWORD dwAddr, const char *szCommunity, variable_list *pVar,void *pArg)
+static void HandlerArp(DWORD dwVersion, DWORD dwAddr, const char *szCommunity, variable_list *pVar,void *pArg)
 {
    oid oidName[MAX_OID_LEN];
    BYTE bMac[64];
@@ -469,11 +470,11 @@ static void HandlerArp(DWORD dwAddr, const char *szCommunity, variable_list *pVa
    memcpy(oidName, pVar->name, pVar->name_length * sizeof(oid));
 
    oidName[pVar->name_length - 6] = 1;  // Retrieve interface index
-   SnmpGet(dwAddr, szCommunity, NULL, oidName, pVar->name_length, &dwIndex,
+   SnmpGet(dwVersion, dwAddr, szCommunity, NULL, oidName, pVar->name_length, &dwIndex,
            sizeof(DWORD), FALSE, FALSE);
 
    oidName[pVar->name_length - 6] = 2;  // Retrieve MAC address for this IP
-   if (SnmpGet(dwAddr, szCommunity, NULL, oidName, pVar->name_length, bMac,
+   if (SnmpGet(dwVersion, dwAddr, szCommunity, NULL, oidName, pVar->name_length, bMac,
                64, FALSE, FALSE))
    {
       ((ARP_CACHE *)pArg)->dwNumEntries++;
@@ -490,7 +491,7 @@ static void HandlerArp(DWORD dwAddr, const char *szCommunity, variable_list *pVa
 // Get ARP cache via SNMP
 //
 
-ARP_CACHE *SnmpGetArpCache(DWORD dwAddr, const char *szCommunity)
+ARP_CACHE *SnmpGetArpCache(DWORD dwVersion, DWORD dwAddr, const char *szCommunity)
 {
    ARP_CACHE *pArpCache;
 
@@ -501,7 +502,7 @@ ARP_CACHE *SnmpGetArpCache(DWORD dwAddr, const char *szCommunity)
    pArpCache->dwNumEntries = 0;
    pArpCache->pEntries = NULL;
 
-   if (!SnmpEnumerate(dwAddr, szCommunity, ".1.3.6.1.2.1.4.22.1.3", HandlerArp, pArpCache, FALSE))
+   if (!SnmpEnumerate(dwVersion, dwAddr, szCommunity, ".1.3.6.1.2.1.4.22.1.3", HandlerArp, pArpCache, FALSE))
    {
       DestroyArpCache(pArpCache);
       pArpCache = NULL;
diff --git a/src/server/core/snmptrap.cpp b/src/server/core/snmptrap.cpp
new file mode 100644 (file)
index 0000000..069c316
--- /dev/null
@@ -0,0 +1,85 @@
+/* 
+** NetXMS - Network Management System
+** Copyright (C) 2003, 2004 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** $module: snmptrap.cpp
+**
+**/
+
+#include "nms_core.h"
+
+
+//
+// Constants
+//
+
+#define MAX_PACKET_LENGTH     65536
+
+
+//
+// SNMP trap receiver thread
+//
+
+THREAD_RESULT THREAD_CALL SNMPTrapReceiver(void *pArg)
+{
+   SOCKET hSocket;
+   struct sockaddr_in addr;
+   int iAddrLen, iBytes;
+   BYTE *packet;
+
+   hSocket = socket(AF_INET, SOCK_DGRAM, 0);
+   if (hSocket == -1)
+   {
+      WriteLog(MSG_SOCKET_FAILED, EVENTLOG_ERROR_TYPE, "s", "SNMPTrapReceiver");
+      return THREAD_OK;
+   }
+
+   // Fill in local address structure
+   memset(&addr, 0, sizeof(struct sockaddr_in));
+   addr.sin_family = AF_INET;
+   addr.sin_addr.s_addr = htonl(INADDR_ANY);
+   addr.sin_port = htons(162);
+
+   // Bind socket
+   if (bind(hSocket, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) != 0)
+   {
+      WriteLog(MSG_BIND_ERROR, EVENTLOG_ERROR_TYPE, "dse", 162, "SNMPTrapReceiver", WSAGetLastError());
+      closesocket(hSocket);
+      return THREAD_OK;
+   }
+
+   packet = (BYTE *)malloc(MAX_PACKET_LENGTH);
+
+   // Wait for packets
+   while(!ShutdownInProgress())
+   {
+      iAddrLen = sizeof(struct sockaddr_in);
+      iBytes = recvfrom(hSocket, (char *)packet, MAX_PACKET_LENGTH, 0, (struct sockaddr *)&addr, &iAddrLen);
+      if (iBytes > 0)
+      {
+         printf("SNMP: %d bytes packet received\n", iBytes);
+      }
+      else
+      {
+         // Sleep on error
+         ThreadSleepMs(100);
+      }
+   }
+
+   free(packet);
+   return THREAD_OK;
+}
index 80e111d..a335559 100644 (file)
@@ -133,7 +133,7 @@ int main(int argc, char *argv[])
                         "   check        : Check database for errors\n"
                         "   upgrade      : Upgrade database to new version\n"
                         "Valid options are:\n"
-                        "   -c <config>  : Use alternate configuration file. Default is" DEFAULT_CONFIG_FILE "\n"
+                        "   -c <config>  : Use alternate configuration file. Default is " DEFAULT_CONFIG_FILE "\n"
                         "   -f           : Force repair - do not ask for confirmation.\n"
                         "   -h           : Display help and exit.\n"
                         "   -v           : Display version and exit.\n"