- Script manager working
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 12 Jan 2006 10:32:39 +0000 (10:32 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 12 Jan 2006 10:32:39 +0000 (10:32 +0000)
- Autodiscovery filters implemented

18 files changed:
ChangeLog
doc/db_format_change.txt
include/nxclapi.h
sql/schema.in
sql/setup.in
src/console/win32/ScriptManager.cpp
src/console/win32/ScriptManager.h
src/console/win32/ScriptView.cpp
src/console/win32/ScriptView.h
src/console/win32/globals.h
src/console/win32/nxcon.clw
src/console/win32/nxcon.dsp
src/console/win32/nxcon.rc
src/console/win32/tools.cpp
src/libnxcl/script.cpp
src/server/core/np.cpp
src/server/core/poll.cpp
src/server/include/nms_core.h

index c69b3f8..057ed6e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,9 +2,11 @@
 * 0.2.9
 *
 
-- Added built-in scripting language
+- Added built-in scripting language (NXSL - NetXMS Scripting Language)
 - Implemented DCI transformations
+- Implemeted auto discovery filters (using NXSL)
 - Added startup scripts for Gentoo Linux
+- Windows console: agent configuration editor improved
 - Fixed issues: #68, #71
 
 
index 609110a..5160898 100644 (file)
                script_code SQL_TEXT not null,
                PRIMARY KEY(script_id)
        ) TABLE_TYPE;
+- Added configuration parameter "DefaultCommunityString"
+- Added configuration parameter "DiscoveryFilter"
+- Removed table "new_nodes"
+- Removed configuration parameter "NewNodePollingInterval"
 
 
 *************
index 775bbeb..8269200 100644 (file)
@@ -1459,7 +1459,7 @@ void LIBNXCL_EXPORTABLE NXCDestroyLPP(NXC_LPP *pPolicy);
 DWORD LIBNXCL_EXPORTABLE NXCGetScriptList(NXC_SESSION hSession, DWORD *pdwNumScrpts,
                                           NXC_SCRIPT_INFO **ppList);
 DWORD LIBNXCL_EXPORTABLE NXCGetScript(NXC_SESSION hSession, DWORD dwId, TCHAR **ppszCode);
-DWORD LIBNXCL_EXPORTABLE NXCUpdateScript(NXC_SESSION hSession, DWORD dwId,
+DWORD LIBNXCL_EXPORTABLE NXCUpdateScript(NXC_SESSION hSession, DWORD *pdwId,
                                          TCHAR *pszName, TCHAR *pszCode);
 
 #ifdef __cplusplus
index 008d7ad..81f9070 100644 (file)
@@ -95,19 +95,6 @@ CREATE TABLE user_profiles
 ) TABLE_TYPE;
 
 
-/*
-** Nodes to be added
-*/
-
-CREATE TABLE new_nodes
-(
-       id integer not null,
-       ip_addr varchar(15) not null,
-       ip_netmask varchar(15) not null,
-       discovery_flags integer not null
-) TABLE_TYPE;
-
-
 /*
 ** Common object properties
 */
index 8272bd3..eb2cc8a 100644 (file)
@@ -18,8 +18,6 @@ INSERT INTO config (var_name,var_value,is_visible,need_server_restart)
        VALUES ('EnableZoning','0',1,1);
 INSERT INTO config (var_name,var_value,is_visible,need_server_restart)
        VALUES ('SyncInterval','60',1,1);
-INSERT INTO config (var_name,var_value,is_visible,need_server_restart)
-       VALUES ('NewNodePollingInterval','60',1,1);
 INSERT INTO config (var_name,var_value,is_visible,need_server_restart)
        VALUES ('DiscoveryPollingInterval','900',1,1);
 INSERT INTO config (var_name,var_value,is_visible,need_server_restart)
@@ -118,6 +116,10 @@ INSERT INTO config (var_name,var_value,is_visible,need_server_restart)
        VALUES ('StatusThresholds','503C2814',1,1);
 INSERT INTO config (var_name,var_value,is_visible,need_server_restart)
        VALUES ('CapabilityExpirationTime','604800',1,0);  // In seconds
+INSERT INTO config (var_name,var_value,is_visible,need_server_restart)
+       VALUES ('DefaultCommunityString','public',1,0);
+INSERT INTO config (var_name,var_value,is_visible,need_server_restart)
+       VALUES ('DiscoveryFilter','none',1,0);
 
 
 /*
index be0dd38..d55e97a 100644 (file)
@@ -43,9 +43,13 @@ BEGIN_MESSAGE_MAP(CScriptManager, CMDIChildWnd)
        ON_COMMAND(ID_SCRIPT_VIEWASTREE, OnScriptViewastree)
        ON_UPDATE_COMMAND_UI(ID_SCRIPT_VIEWASTREE, OnUpdateScriptViewastree)
        ON_COMMAND(ID_SCRIPT_NEW, OnScriptNew)
+       ON_WM_CLOSE()
        //}}AFX_MSG_MAP
    ON_NOTIFY(TVN_SELCHANGING, AFX_IDW_PANE_FIRST, OnTreeViewSelChanging)
    ON_NOTIFY(TVN_SELCHANGED, AFX_IDW_PANE_FIRST, OnTreeViewSelChange)
+   ON_NOTIFY(LVN_ITEMCHANGING, AFX_IDW_PANE_FIRST, OnListViewItemChanging)
+   ON_NOTIFY(LVN_ITEMCHANGED, AFX_IDW_PANE_FIRST, OnListViewItemChange)
+   ON_NOTIFY(NM_DBLCLK, AFX_IDW_PANE_FIRST, OnViewDblClk)
 END_MESSAGE_MAP()
 
 /////////////////////////////////////////////////////////////////////////////
@@ -91,7 +95,7 @@ int CScriptManager::OnCreate(LPCREATESTRUCT lpCreateStruct)
    m_wndTreeCtrl.SetImageList(&m_imageList, TVSIL_NORMAL);
 
    // Create list control
-   m_wndListCtrl.Create(WS_CHILD | LVS_REPORT | LVS_NOCOLUMNHEADER | LVS_SHAREIMAGELISTS | LVS_SHOWSELALWAYS | LVS_SINGLESEL,
+   m_wndListCtrl.Create(WS_CHILD | LVS_REPORT | LVS_NOCOLUMNHEADER | LVS_SHAREIMAGELISTS | LVS_SHOWSELALWAYS | LVS_SINGLESEL | LVS_SORTASCENDING,
                         rect, &m_wndSplitter, m_wndSplitter.IdFromRowCol(0, 0));
    m_wndListCtrl.InsertColumn(0, _T("Script"));
    m_wndListCtrl.SetImageList(&m_imageList, LVSIL_SMALL);
@@ -101,11 +105,11 @@ int CScriptManager::OnCreate(LPCREATESTRUCT lpCreateStruct)
                           &m_wndSplitter, m_wndSplitter.IdFromRowCol(0, 1));
        
    // Finish splitter setup
-   m_wndSplitter.SetColumnInfo(0, 150, 150);
+   m_wndSplitter.SetColumnInfo(0, 200, 0);
    m_wndSplitter.InitComplete();
    m_wndSplitter.RecalcLayout();
 
-   SetMode(MODE_TREE);
+   SetMode(MODE_LIST);
 
    PostMessage(WM_COMMAND, ID_VIEW_REFRESH, 0);
 
@@ -167,7 +171,7 @@ void CScriptManager::OnViewRefresh()
    {
       for(i = 0; i < dwNumScripts; i++)
       {
-         InsertScript(pList[i].dwId, pList[i].szName);
+         InsertScript(pList[i].dwId, pList[i].szName, FALSE);
       }
       safe_free(pList);
    }
@@ -260,11 +264,44 @@ void CScriptManager::BuildScriptName(HTREEITEM hLast, CString &strName)
 
 void CScriptManager::SetMode(int nMode)
 {
+   DWORD dwId;
+   HTREEITEM hItem;
+   int iItem;
+
    if (m_nMode != nMode)
    {
       m_nMode = nMode;
       if (m_nMode == MODE_LIST)
       {
+         hItem = m_wndTreeCtrl.GetSelectedItem();
+         if (hItem != NULL)
+         {
+            dwId = m_wndTreeCtrl.GetItemData(hItem);
+            if (dwId != NULL)
+            {
+               LVFINDINFO lvfi;
+
+               lvfi.flags = LVFI_PARAM;
+               lvfi.lParam = dwId;
+               iItem = m_wndListCtrl.FindItem(&lvfi, -1);
+            }
+            else
+            {
+               iItem = -1;
+            }
+         }
+         else
+         {
+            iItem = -1;
+         }
+
+         SelectListViewItem(&m_wndListCtrl, iItem);
+         if (iItem == -1)
+         {
+            if (m_wndScriptView.ValidateClose())
+               m_wndScriptView.SetEmptyMode();
+         }
+
          m_wndListCtrl.ShowWindow(SW_SHOW);
          m_wndTreeCtrl.ShowWindow(SW_HIDE);
  
@@ -273,6 +310,24 @@ void CScriptManager::SetMode(int nMode)
       }
       else
       {
+         iItem = m_wndListCtrl.GetSelectionMark();
+         if (iItem != -1)
+         {
+            dwId = m_wndListCtrl.GetItemData(iItem);
+            hItem = FindTreeCtrlItemEx(m_wndTreeCtrl, TVI_ROOT, dwId);
+         }
+         else
+         {
+            hItem = NULL;
+         }
+
+         m_wndTreeCtrl.SelectItem(hItem);
+         if (hItem == NULL)
+         {
+            if (m_wndScriptView.ValidateClose())
+               m_wndScriptView.SetEmptyMode();
+         }
+
          m_wndTreeCtrl.ShowWindow(SW_SHOW);
          m_wndListCtrl.ShowWindow(SW_HIDE);
  
@@ -316,20 +371,32 @@ void CScriptManager::OnUpdateScriptViewastree(CCmdUI* pCmdUI)
 void CScriptManager::OnScriptNew() 
 {
    CInputBox dlg;
-   DWORD dwResult;
+   DWORD dwResult, dwId;
+   TCHAR szBuffer[MAX_DB_STRING];
 
-   if (m_wndScriptView.ValidateClose())
+   dlg.m_strTitle = _T("Create New Script");
+   dlg.m_strHeader = _T("Script name");
+   if (dlg.DoModal() == IDOK)
    {
-      dlg.m_strTitle = _T("Create New Script");
-      dlg.m_strHeader = _T("Scrip name");
-      if (dlg.DoModal() == IDOK)
+      // Ask to save currently open script if needed
+      if (m_wndScriptView.ValidateClose())
       {
+         m_wndScriptView.SetEmptyMode();
+         dwId = 0;
          dwResult = DoRequestArg4(NXCUpdateScript, g_hSession,
-                                  (void *)0, (void *)((LPCTSTR)dlg.m_strText),
+                                  &dwId, (void *)((LPCTSTR)dlg.m_strText),
                                   _T(""), _T("Updating script..."));
          if (dwResult == RCC_SUCCESS)
          {
-            InsertScript(0, (LPCTSTR)dlg.m_strText);
+            nx_strncpy(szBuffer, (LPCTSTR)dlg.m_strText, MAX_DB_STRING);
+            InsertScript(dwId, szBuffer, TRUE);
+            PostMessage(WM_COMMAND, ID_SCRIPT_EDIT, 0);
+         }
+         else
+         {
+            // Clear selection on failure
+            m_wndTreeCtrl.SelectItem(NULL);
+            SelectListViewItem(&m_wndListCtrl, -1);
          }
       }
    }
@@ -340,7 +407,7 @@ void CScriptManager::OnScriptNew()
 // Insert script into list/tree
 //
 
-void CScriptManager::InsertScript(DWORD dwId, TCHAR *pszName)
+void CScriptManager::InsertScript(DWORD dwId, LPTSTR pszName, BOOL bSelect)
 {
    TCHAR *pszCurr, *pszNext;
    HTREEITEM hItem, hNextItem;
@@ -361,8 +428,87 @@ void CScriptManager::InsertScript(DWORD dwId, TCHAR *pszName)
       {
          hNextItem = m_wndTreeCtrl.InsertItem(pszCurr, 1, 1, hItem);
          m_wndTreeCtrl.SetItemData(hNextItem, 0);
+         m_wndTreeCtrl.SortChildren(hItem);
       }
    }
-   hItem = m_wndTreeCtrl.InsertItem(pszCurr, 3, 3, hItem);
-   m_wndTreeCtrl.SetItemData(hItem, dwId);
+   hNextItem = m_wndTreeCtrl.InsertItem(pszCurr, 3, 3, hItem);
+   m_wndTreeCtrl.SetItemData(hNextItem, dwId);
+   m_wndTreeCtrl.SortChildren(hItem);
+
+   if (bSelect)
+   {
+      SelectListViewItem(&m_wndListCtrl, iItem);
+      m_wndTreeCtrl.SelectItem(hNextItem);
+   }
+}
+
+
+//
+// WM_NOTIFY::LVN_ITEMCHANGED message handler
+//
+
+void CScriptManager::OnListViewItemChange(LPNMLISTVIEW pItem, LRESULT *pResult)
+{
+   DWORD dwId;
+   TCHAR szName[MAX_DB_STRING];
+
+   if (pItem->iItem != -1)
+   {
+      if ((pItem->uChanged & LVIF_STATE) &&
+          (pItem->uNewState & LVIS_FOCUSED))
+      {
+         dwId = m_wndListCtrl.GetItemData(pItem->iItem);
+         if (dwId != 0)
+         {
+            m_wndListCtrl.GetItemText(pItem->iItem, 0, szName, MAX_DB_STRING);
+            m_wndScriptView.SetEditMode(dwId, szName);
+         }
+      }
+   }
+   *pResult = 0;
+}
+
+
+//
+// WM_NOTIFY::LVN_ITEMCHANGING message handler
+//
+
+void CScriptManager::OnListViewItemChanging(LPNMLISTVIEW pItem, LRESULT *pResult)
+{
+   DWORD dwId;
+
+   *pResult = 0;
+   if (pItem->uChanged & LVIF_STATE)
+   {
+      if ((pItem->uOldState & LVIS_FOCUSED) && (!(pItem->uNewState & LVIS_FOCUSED)))
+      {
+         dwId = m_wndListCtrl.GetItemData(pItem->iItem);
+         if (dwId != 0)
+         {
+            if (!m_wndScriptView.ValidateClose())
+               *pResult = 1;
+         }
+      }
+   }
+}
+
+
+//
+// Handler for double click in list or tree view
+//
+
+void CScriptManager::OnViewDblClk(LPNMHDR pHdr, LRESULT *pResult)
+{
+   m_wndScriptView.PostMessage(WM_COMMAND, ID_SCRIPT_EDIT, 0);
+}
+
+
+//
+// WM_CLOSE message handler
+//
+
+void CScriptManager::OnClose() 
+{
+   if (m_wndScriptView.ValidateClose())
+          CMDIChildWnd::OnClose();
 }
index 4ce06df..06b8c27 100644 (file)
@@ -35,7 +35,7 @@ public:
 
 // Implementation
 protected:
-       void InsertScript(DWORD dwId, TCHAR *pszName);
+       void InsertScript(DWORD dwId, LPTSTR pszName, BOOL bSelect);
        void SetMode(int nMode);
        int m_nMode;
        CSimpleListCtrl m_wndListCtrl;
@@ -59,9 +59,13 @@ protected:
        afx_msg void OnScriptViewastree();
        afx_msg void OnUpdateScriptViewastree(CCmdUI* pCmdUI);
        afx_msg void OnScriptNew();
+       afx_msg void OnClose();
        //}}AFX_MSG
    afx_msg void OnTreeViewSelChange(LPNMTREEVIEW lpnmt, LRESULT *pResult);
    afx_msg void OnTreeViewSelChanging(LPNMTREEVIEW lpnmt, LRESULT *pResult);
+   afx_msg void OnListViewItemChange(LPNMLISTVIEW pItem, LRESULT *pResult);
+   afx_msg void OnListViewItemChanging(LPNMLISTVIEW pItem, LRESULT *pResult);
+   afx_msg void OnViewDblClk(LPNMHDR pHdr, LRESULT *pResult);
        DECLARE_MESSAGE_MAP()
 };
 
index c90e196..d06351a 100644 (file)
@@ -16,9 +16,10 @@ static char THIS_FILE[] = __FILE__;
 // Operation modes
 //
 
-#define MODE_LIST    0
-#define MODE_VIEW    1
-#define MODE_EDIT    2
+#define MODE_INITIAL    -1
+#define MODE_LIST       0
+#define MODE_VIEW       1
+#define MODE_EDIT       2
 
 
 /////////////////////////////////////////////////////////////////////////////
@@ -26,6 +27,7 @@ static char THIS_FILE[] = __FILE__;
 
 CScriptView::CScriptView()
 {
+   m_nMode = MODE_INITIAL;
 }
 
 CScriptView::~CScriptView()
@@ -188,6 +190,20 @@ void CScriptView::SetEditMode(DWORD dwScriptId, LPCTSTR pszScriptName)
 }
 
 
+//
+// Switch script view to empty mode
+//
+
+void CScriptView::SetEmptyMode()
+{
+   m_nMode = MODE_INITIAL;
+   m_wndButton.ShowWindow(SW_HIDE);
+   m_wndEditor.ShowWindow(SW_HIDE);
+   m_wndStatusBar.ShowWindow(SW_HIDE);
+   m_wndListCtrl.ShowWindow(SW_HIDE);
+}
+
+
 //
 // WM_COMMAND::ID_SCRIPT_EDIT
 //
@@ -235,18 +251,20 @@ BOOL CScriptView::ValidateClose(void)
    BOOL bRet = FALSE;
    CString strText;
    DWORD dwResult;
+   TCHAR szMessage[1024];
 
    if ((m_nMode != MODE_EDIT) || (!m_wndEditor.GetModify()))
       return TRUE;
 
-   nRet = MessageBox(_T("Script is modified. Do you want to save changes?"),
-                     _T("Warning"), MB_YESNOCANCEL | MB_ICONEXCLAMATION);
+   _sntprintf(szMessage, 1024, _T("Script %s is modified. Do you want to save changes?"),
+              (LPCTSTR)m_strScriptName);
+   nRet = MessageBox(szMessage, _T("Warning"), MB_YESNOCANCEL | MB_ICONEXCLAMATION);
    switch(nRet)
    {
       case IDYES:
          m_wndEditor.GetText(strText);
          dwResult = DoRequestArg4(NXCUpdateScript, g_hSession,
-                                  (void *)m_dwScriptId, (void *)((LPCTSTR)m_strScriptName),
+                                  &m_dwScriptId, (void *)((LPCTSTR)m_strScriptName),
                                   (void *)((LPCTSTR)strText), _T("Updating script..."));
          if (dwResult == RCC_SUCCESS)
          {
index b13862b..b2f915e 100644 (file)
@@ -31,6 +31,7 @@ public:
 
 // Implementation
 public:
+       void SetEmptyMode(void);
        BOOL ValidateClose(void);
        void SetEditMode(DWORD dwScriptId, LPCTSTR pszScriptName);
        void SetListMode(CTreeCtrl &wndTreeCtrl, HTREEITEM hRoot);
index efacad3..f41440e 100644 (file)
@@ -288,6 +288,7 @@ void CopyMenuItems(CMenu *pDst, CMenu *pSrc);
 TCHAR **CopyStringList(TCHAR **ppList, DWORD dwSize);
 void DestroyStringList(TCHAR **ppList, DWORD dwSize);
 HTREEITEM FindTreeCtrlItem(CTreeCtrl &ctrl, HTREEITEM hRoot, TCHAR *pszText);
+HTREEITEM FindTreeCtrlItemEx(CTreeCtrl &ctrl, HTREEITEM hRoot, DWORD dwData);
 
 
 //
index 4489330..7900412 100644 (file)
@@ -16,9 +16,9 @@ Class7=CEventBrowser
 Class9=CMapView
 
 ResourceCount=136
-Resource1=IDD_SELECT_AGENT_PARAM (English (U.S.))
+Resource1=IDD_NEW_OBJECT_TOOL (English (U.S.))
 Resource2=IDD_OBJECT_NODE_GENERAL
-Resource3=IDD_OBJECT_VPNC_GENERAL (English (U.S.))
+Resource3=IDD_SAVE_AGENT_CFG (English (U.S.))
 Resource4=IDD_SELECT_OBJECT
 Resource5=IDD_SELECT_ACTION
 Class2=CChildView
@@ -32,9 +32,9 @@ Resource7=IDD_NEW_USER
 Class12=CObjectBrowser
 Resource8=IDD_CREATE_CONTAINER
 Class13=CObjectPropDlg
-Resource9=IDA_TRAP_EDITOR (English (U.S.))
-Resource10=IDD_CREATE_VPNC (English (U.S.))
-Resource11=IDD_THRESHOLD (English (U.S.))
+Resource9=IDA_PACKAGE_MGR (English (U.S.))
+Resource10=IDD_EDIT_IP_SUBNET (English (U.S.))
+Resource11=IDD_SELECT_OBJECT (English (U.S.))
 Resource12=IDR_CTRLPANEL (English (U.S.))
 Resource13=IDR_EVENTS (English (U.S.))
 Resource14=IDR_MAPFRAME (English (U.S.))
@@ -42,17 +42,17 @@ Resource15=IDR_OBJECTS (English (U.S.))
 Resource16=IDD_DUMMY (English (U.S.))
 Class14=CEventEditor
 Class15=CEditEventDlg
-Resource17=IDA_EVENT_EDITOR (English (U.S.))
+Resource17=IDA_TRAP_EDITOR (English (U.S.))
 Class16=CDebugFrame
-Resource18=IDD_OBJECT_PRESENTATION (English (U.S.))
+Resource18=IDD_EDIT_RULE_ALARM (English (U.S.))
 Resource19=IDD_OBJECT_PROPERTIES (English (U.S.))
 Resource20=IDD_SELECT_EVENT
 Class17=CObjectPreview
-Resource21=IDD_OBJECT_NODE_POLL (English (U.S.))
+Resource21=IDD_DESKTOP_SAVE_AS (English (U.S.))
 Class18=CToolBox
 Class19=CObjectInfoBox
 Class20=CObjectSearchBox
-Resource22=IDD_SELECT_ACTION (English (U.S.))
+Resource22=IDD_CREATE_NODE (English (U.S.))
 Class21=CEditBox
 Class22=COPGeneral
 Class23=CNodePropsGeneral
@@ -61,14 +61,14 @@ Class24=CObjectPropCaps
 Class25=CObjectPropSheet
 Resource24=IDA_MDI_DEFAULT
 Class26=CRequestProcessingDlg
-Resource25=IDD_REQUEST_PROCESSING (English (U.S.))
+Resource25=IDD_OBJECT_SECURITY (English (U.S.))
 Resource26=IDD_PROGRESS (English (U.S.))
 Resource27=IDD_EDIT_RULE_ALARM
-Resource28=IDD_DCI_COLLECTION (English (U.S.))
+Resource28=IDD_THRESHOLD (English (U.S.))
 Class27=CObjectPropsGeneral
-Resource29=IDD_GRAPH_PROP_SETTINGS (English (U.S.))
+Resource29=IDD_LASTVAL_PROP (English (U.S.))
 Class28=CObjectPropsSecurity
-Resource30=IDD_SAVE_AGENT_CFG (English (U.S.))
+Resource30=IDD_OBJECT_STATUS (English (U.S.))
 Resource31=IDD_SELECT_USER
 Resource32=IDD_OBJECT_SECURITY
 Class29=CUserSelectDlg
@@ -79,36 +79,36 @@ Class31=CNewUserDlg
 Resource35=IDD_THRESHOLD
 Resource36=IDA_EPP
 Class32=CUserPropDlg
-Resource37=IDD_EDIT_VARIABLE (English (U.S.))
+Resource37=IDD_OBJECT_VPNC_GENERAL (English (U.S.))
 Resource38=IDD_ABOUTBOX
 Class33=CGroupPropDlg
 Resource39=IDD_CP_GENERAL
 Resource40=IDA_TRAP_EDITOR
 Resource41=IDM_VIEW_SPECIFIC
-Resource42=IDD_LASTVAL_PROP (English (U.S.))
+Resource42=IDD_EDIT_VARIABLE (English (U.S.))
 Class34=CPasswordChangeDlg
 Class35=CNodeSummary
 Class36=CNetSummaryFrame
 Class37=CDataCollectionEditor
-Resource43=IDD_REMOVE_TEMPLATE
+Resource43=IDR_MAINFRAME (English (U.S.))
 Class38=CDCIPropPage
-Resource44=IDD_OBJECT_RELATIONS (English (U.S.))
+Resource44=IDD_GRAPH_PROP_SETTINGS (English (U.S.))
 Class39=CDCIDataView
-Resource45=IDA_ALARM_BROWSER (English (U.S.))
+Resource45=IDA_EVENT_EDITOR (English (U.S.))
 Class40=CGraph
 Class41=CGraphFrame
 Class42=CDCIThresholdsPage
-Resource46=IDA_AGENT_CFG_EDITOR (English (U.S.))
-Resource47=IDD_USER_PROPERTIES (English (U.S.))
+Resource46=IDA_OBJECT_TOOLS_EDITOR (English (U.S.))
+Resource47=IDD_SET_PASSWORD (English (U.S.))
 Resource48=IDM_CONTEXT
 Class43=CThresholdDlg
-Resource49=IDD_ACTION_PROPERTIES (English (U.S.))
+Resource49=IDD_CREATE_CONTAINER (English (U.S.))
 Resource50=IDD_EDIT_TRAP_ARG
 Class44=CMIBBrowserDlg
 Class45=CEventPolicyEditor
 Class46=CRuleList
 Class47=CRuleHeader
-Resource51=IDD_DATA_QUERY (English (U.S.))
+Resource51=IDD_EDIT_TRAP_ARG (English (U.S.))
 Resource52=IDD_CREATE_NODE
 Class48=CObjectSelDlg
 Resource53=IDD_OBJECT_CAPS
@@ -117,22 +117,22 @@ Class49=CRuleCommentDlg
 Resource55=IDD_DCI_COLLECTION
 Class50=CEventSelDlg
 Resource56=IDD_DATA_QUERY
-Resource57=IDD_ABOUTBOX (English (U.S.))
+Resource57=IDA_EPP (English (U.S.))
 Resource58=IDD_CREATE_TG
-Resource59=IDD_EDIT_RULE_ALARM (English (U.S.))
-Resource60=IDD_SELECT_EVENT (English (U.S.))
+Resource59=IDD_NEW_ACTION (English (U.S.))
+Resource60=IDD_EDIT_RULE_SEVERITY (English (U.S.))
 Class51=CObjectPropsPresentation
-Resource61=IDD_SELECT_INTERNAL_ITEM (English (U.S.))
+Resource61=IDD_INPUT_BOX (English (U.S.))
 Resource62=IDD_EDIT_RULE_COMMENT
 Class52=CRuleSeverityDlg
 Resource63=IDD_ACTION_PROPERTIES
 Class53=CRuleAlarmDlg
 Class54=CAlarmBrowser
-Resource64=IDD_DCI_DATA_EXPORT (English (U.S.))
+Resource64=IDD_CREATE_VPNC (English (U.S.))
 Resource65=IDD_DCI_TRANSFORM
-Resource66=IDD_GRAPH_PROP_DATA (English (U.S.))
-Resource67=IDD_SELECT_OBJECT (English (U.S.))
-Resource68=IDD_DCI_SCHEDULE (English (U.S.))
+Resource66=IDD_DCI_DATA_EXPORT (English (U.S.))
+Resource67=IDD_SELECT_EVENT (English (U.S.))
+Resource68=IDD_OBJTOOL_GENERAL (English (U.S.))
 Class55=CConsolePropsGeneral
 Class56=CActionEditor
 Resource69=IDA_ACTION_EDITOR
@@ -143,18 +143,18 @@ Class58=CEditActionDlg
 Resource72=IDA_NETMAP
 Class59=CActionSelDlg
 Resource73=IDD_MIB_BROWSER
-Resource74=IDD_GROUP_PROPERTIES (English (U.S.))
-Resource75=IDD_EDIT_IP_SUBNET (English (U.S.))
+Resource74=IDD_DCI_COLLECTION (English (U.S.))
+Resource75=IDD_DCI_SCHEDULE (English (U.S.))
 Resource76=IDD_USER_PROPERTIES
 Class60=CCreateObjectDlg
 Class61=CCreateContainerDlg
 Resource77=IDR_MAINFRAME
 Class62=CCreateNodeDlg
-Resource78=IDD_OBJECT_NETSRV_GENERAL (English (U.S.))
-Resource79=IDD_NEW_OBJECT_TOOL (English (U.S.))
-Resource80=IDA_SERVER_CFG_EDITOR (English (U.S.))
+Resource78=IDD_CHANGE_IP (English (U.S.))
+Resource79=IDD_OBJTOOL_OPTIONS (English (U.S.))
+Resource80=IDA_DC_EDITOR (English (U.S.))
 Class63=CDCITransformPage
-Resource81=IDD_DESKTOP_SAVE_AS (English (U.S.))
+Resource81=IDA_OBJECT_BROWSER (English (U.S.))
 Class64=CPollNodeDlg
 Resource82=IDD_POLL_NODE (English (U.S.))
 Class65=CNodePoller
@@ -171,7 +171,7 @@ Resource89=IDA_ALARM_BROWSER
 Class69=CDataQueryDlg
 Resource90=IDD_EDIT_RULE_SEVERITY
 Class70=CTrapEditDlg
-Resource91=IDD_OBJECT_SECURITY (English (U.S.))
+Resource91=IDD_NEW_USER (English (U.S.))
 Class71=CTrapParamDlg
 Resource92=IDD_EDIT_EVENT
 Resource93=IDD_CREATE_TEMPLATE
@@ -179,87 +179,87 @@ Class72=CGraphPropDlg
 Class73=CColorSelector
 Class74=CPackageMgr
 Resource94=IDD_GROUP_PROPERTIES
-Resource95=IDD_DCI_THRESHOLDS (English (U.S.))
-Resource96=IDD_NEW_USER (English (U.S.))
-Resource97=IDD_EDIT_RULE_SEVERITY (English (U.S.))
-Resource98=IDA_SCRIPT_MANAGER (English (U.S.))
-Resource99=IDD_EDIT_TRAP_ARG (English (U.S.))
-Resource100=IDA_LAST_VALUES (English (U.S.))
-Resource101=IDD_OBJECT_STATUS (English (U.S.))
-Resource102=IDA_NETMAP (English (U.S.))
-Resource103=IDA_OBJECT_TOOLS_EDITOR (English (U.S.))
-Resource104=IDD_OBJECT_NODE_GENERAL (English (U.S.))
-Resource105=IDD_DCI_TRANSFORM (English (U.S.))
-Resource106=IDD_EDIT_TRAP (English (U.S.))
-Resource107=IDD_OBJECT_GENERAL (English (U.S.))
+Resource95=IDD_MIB_BROWSER (English (U.S.))
+Resource96=IDD_GROUP_PROPERTIES (English (U.S.))
+Resource97=IDD_CP_GENERAL (English (U.S.))
+Resource98=IDD_EDIT_EVENT (English (U.S.))
+Resource99=IDD_SELECT_AGENT_PARAM (English (U.S.))
+Resource100=IDA_AGENT_CFG_EDITOR (English (U.S.))
+Resource101=IDD_CREATE_NETSRV (English (U.S.))
+Resource102=IDA_ACTION_EDITOR (English (U.S.))
+Resource103=IDD_ABOUTBOX (English (U.S.))
+Resource104=IDD_REQUEST_PROCESSING (English (U.S.))
+Resource105=IDD_CREATE_TEMPLATE (English (U.S.))
+Resource106=IDD_SELECT_INTERNAL_ITEM (English (U.S.))
+Resource107=IDD_SELECT_USER (English (U.S.))
 Class75=CInternalItemSelDlg
-Resource108=IDA_MDI_DEFAULT (English (U.S.))
+Resource108=IDD_OBJECT_NODE_GENERAL (English (U.S.))
 Class76=CAgentParamSelDlg
-Resource109=IDD_OBJTOOL_GENERAL (English (U.S.))
+Resource109=IDD_REMOVE_TEMPLATE
 Class77=CInputBox
-Resource110=IDD_CREATE_NETSRV (English (U.S.))
+Resource110=IDD_OBJECT_NODE_POLL (English (U.S.))
 Class78=CCreateNetSrvDlg
-Resource111=IDD_CP_GENERAL (English (U.S.))
+Resource111=IDD_ACTION_PROPERTIES (English (U.S.))
 Class79=CNetSrvPropsGeneral
 Resource112=IDD_LOGIN (English (U.S.))
 Class80=CNodePropsPolling
 Class81=CDeploymentView
 Class82=CLastValuesView
 Class83=CValueList
-Resource113=IDR_MAINFRAME (English (U.S.))
+Resource113=IDM_CONTEXT (English (U.S.))
 Class84=CObjectPropsRelations
-Resource114=IDA_PACKAGE_MGR (English (U.S.))
+Resource114=IDA_SERVER_CFG_EDITOR (English (U.S.))
 Class85=CSaveDesktopDlg
-Resource115=IDA_ACTION_EDITOR (English (U.S.))
+Resource115=IDA_GRAPH (English (U.S.))
 Class86=CGraphSettingsPage
-Resource116=IDA_EPP (English (U.S.))
+Resource116=IDA_NETMAP (English (U.S.))
 Class87=CGraphDataPage
-Resource117=IDD_CREATE_TG (English (U.S.))
+Resource117=IDD_DATA_QUERY (English (U.S.))
 Class88=CRemoveTemplateDlg
-Resource118=IDD_OBJECT_CAPS (English (U.S.))
+Resource118=IDD_OBJECT_GENERAL (English (U.S.))
 Class89=CAddrChangeDlg
-Resource119=IDD_CREATE_CONTAINER (English (U.S.))
+Resource119=IDD_DCI_TRANSFORM (English (U.S.))
 Class90=CLastValuesPropDlg
 Class91=CAgentCfgEditor
-Resource120=IDD_INPUT_BOX (English (U.S.))
+Resource120=IDD_OBJECT_NETSRV_GENERAL (English (U.S.))
 Class92=CDataExportDlg
 Class93=CServerCfgEditor
-Resource121=IDD_SET_PASSWORD (English (U.S.))
-Resource122=IDD_EDIT_RULE_COMMENT (English (U.S.))
+Resource121=IDD_DCI_THRESHOLDS (English (U.S.))
+Resource122=IDD_OBJECT_PRESENTATION (English (U.S.))
 Class94=CEditVariableDlg
-Resource123=IDD_CHANGE_IP
+Resource123=IDA_MDI_DEFAULT (English (U.S.))
 Class95=CCreateVPNConnDlg
-Resource124=IDA_GRAPH (English (U.S.))
+Resource124=IDA_LAST_VALUES (English (U.S.))
 Class96=CVPNCPropsGeneral
-Resource125=IDD_MIB_BROWSER (English (U.S.))
+Resource125=IDD_EDIT_RULE_COMMENT (English (U.S.))
 Class97=CEditSubnetDlg
-Resource126=IDD_SELECT_USER (English (U.S.))
-Resource127=IDD_EDIT_EVENT (English (U.S.))
+Resource126=IDD_USER_PROPERTIES (English (U.S.))
+Resource127=IDD_OBJECT_CAPS (English (U.S.))
 Class98=CModifiedAgentCfgDlg
 Class99=CSimpleSplitter
 Class100=CAdvSplitter
-Resource128=IDD_CREATE_TEMPLATE (English (U.S.))
+Resource128=IDD_EDIT_TRAP (English (U.S.))
 Class101=CTableView
 Class102=CWaitView
 Class103=CWebBrowser
 Class104=CSyslogBrowser
 Class105=CLPPList
-Resource129=IDM_CONTEXT (English (U.S.))
+Resource129=IDM_VIEW_SPECIFIC (English (U.S.))
 Class106=CDCISchedulePage
-Resource130=IDM_VIEW_SPECIFIC (English (U.S.))
+Resource130=IDD_GRAPH_PROP_DATA (English (U.S.))
 Class107=CObjectPropsStatus
 Class108=CObjectToolsEditor
-Resource131=IDA_DC_EDITOR (English (U.S.))
-Resource132=IDD_CREATE_NODE (English (U.S.))
+Resource131=IDA_SCRIPT_MANAGER (English (U.S.))
+Resource132=IDD_CREATE_TG (English (U.S.))
 Class109=CObjToolPropGeneral
-Resource133=IDD_NEW_ACTION (English (U.S.))
+Resource133=IDD_SELECT_ACTION (English (U.S.))
 Class110=CObjToolPropColumns
-Resource134=IDA_OBJECT_BROWSER (English (U.S.))
+Resource134=IDA_ALARM_BROWSER (English (U.S.))
 Class111=CNewObjectToolDlg
 Class112=CObjToolPropOptions
 Class113=CScriptManager
 Class114=CScriptView
-Resource135=IDD_OBJTOOL_OPTIONS (English (U.S.))
+Resource135=IDD_OBJECT_RELATIONS (English (U.S.))
 Resource136=IDD_OBJTOOL_COLUMNS
 
 [CLS:CConsoleApp]
@@ -3218,15 +3218,6 @@ Filter=D
 VirtualFilter=dWC
 LastObject=CRemoveTemplateDlg
 
-[DLG:IDD_CHANGE_IP]
-Type=1
-Class=CAddrChangeDlg
-ControlCount=4
-Control1=IDC_IP_ADDR,SysIPAddress32,1342242816
-Control2=IDOK,button,1342242817
-Control3=IDCANCEL,button,1342242816
-Control4=IDC_STATIC,static,1342308352
-
 [CLS:CAddrChangeDlg]
 Type=0
 HeaderFile=AddrChangeDlg.h
@@ -3720,6 +3711,17 @@ VirtualFilter=WC
 [ACL:IDA_SCRIPT_MANAGER (English (U.S.))]
 Type=1
 Class=?
-Command1=ID_EDIT_DELETE
-CommandCount=1
+Command1=ID_SCRIPT_VIEWASLIST
+Command2=ID_SCRIPT_VIEWASTREE
+Command3=ID_EDIT_DELETE
+CommandCount=3
+
+[DLG:IDD_CHANGE_IP (English (U.S.))]
+Type=1
+Class=CAddrChangeDlg
+ControlCount=4
+Control1=IDC_IP_ADDR,SysIPAddress32,1342242816
+Control2=IDOK,button,1342242817
+Control3=IDCANCEL,button,1342242816
+Control4=IDC_STATIC,static,1342308352
 
index 711d94c..121b480 100644 (file)
@@ -954,6 +954,10 @@ SOURCE=.\ServerCfgEditor.h
 # End Source File
 # Begin Source File
 
+SOURCE=..\nxuilib\SimpleListCtrl.h
+# End Source File
+# Begin Source File
+
 SOURCE=.\StdAfx.h
 # End Source File
 # Begin Source File
index c77b6a5..bff1d56 100644 (file)
@@ -497,8 +497,11 @@ BEGIN
         MENUITEM "&Edit\tCtrl+E",               ID_SCRIPT_EDIT
         MENUITEM "&Save\tCtrl+S",               ID_SCRIPT_SAVE
         MENUITEM SEPARATOR
-        MENUITEM "View as &list",               ID_SCRIPT_VIEWASLIST
-        MENUITEM "View as &tree",               ID_SCRIPT_VIEWASTREE
+        POPUP "&View"
+        BEGIN
+            MENUITEM "View as &list\tCtrl+Alt+L",   ID_SCRIPT_VIEWASLIST
+            MENUITEM "View as &tree\tCtrl+Alt+T",   ID_SCRIPT_VIEWASTREE
+        END
     END
 END
 
@@ -935,6 +938,8 @@ END
 
 IDA_SCRIPT_MANAGER ACCELERATORS DISCARDABLE 
 BEGIN
+    "L",            ID_SCRIPT_VIEWASLIST,   VIRTKEY, CONTROL, ALT, NOINVERT
+    "T",            ID_SCRIPT_VIEWASTREE,   VIRTKEY, CONTROL, ALT, NOINVERT
     VK_DELETE,      ID_EDIT_DELETE,         VIRTKEY, NOINVERT
 END
 
@@ -944,17 +949,17 @@ END
 // Dialog
 //
 
-IDD_ABOUTBOX DIALOG DISCARDABLE  0, 0, 235, 55
+IDD_ABOUTBOX DIALOG DISCARDABLE  0, 0, 274, 55
 STYLE DS_MODALFRAME | DS_3DLOOK | DS_CENTER | WS_POPUP | WS_CAPTION | 
     WS_SYSMENU
 CAPTION "About NetXMS Console"
 FONT 8, "MS Sans Serif"
 BEGIN
-    ICON            IDR_MAINFRAME,IDC_STATIC,11,12,20,20
+    ICON            IDR_MAINFRAME,IDC_STATIC,11,12,21,20
     LTEXT           "-version-",IDC_VERSION,40,10,119,8,SS_NOPREFIX
-    LTEXT           "Copyright (C) 2003, 2004 NetXMS Team",IDC_STATIC,40,25,
-                    132,8
-    DEFPUSHBUTTON   "OK",IDOK,178,7,50,14,WS_GROUP
+    LTEXT           "Copyright (C) 2003, 2004, 2005, 2006 NetXMS Team",
+                    IDC_STATIC,40,25,168,8
+    DEFPUSHBUTTON   "OK",IDOK,217,7,50,14,WS_GROUP
 END
 
 IDD_EDIT_EVENT DIALOG DISCARDABLE  0, 0, 270, 190
@@ -2212,6 +2217,18 @@ BEGIN
                     IDC_STATIC_SNMP_INDEX,13,99,160,8
 END
 
+IDD_CHANGE_IP DIALOG DISCARDABLE  0, 0, 172, 46
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Change IP Address"
+FONT 8, "MS Sans Serif"
+BEGIN
+    CONTROL         "IPAddress1",IDC_IP_ADDR,"SysIPAddress32",WS_TABSTOP,7,
+                    18,100,15
+    DEFPUSHBUTTON   "OK",IDOK,115,7,50,14
+    PUSHBUTTON      "Cancel",IDCANCEL,115,24,50,14
+    LTEXT           "Enter new IP address for node:",IDC_STATIC,7,7,98,8
+END
+
 
 #ifndef _MAC
 /////////////////////////////////////////////////////////////////////////////
@@ -2267,7 +2284,7 @@ BEGIN
     IDD_ABOUTBOX, DIALOG
     BEGIN
         LEFTMARGIN, 7
-        RIGHTMARGIN, 228
+        RIGHTMARGIN, 267
         TOPMARGIN, 7
         BOTTOMMARGIN, 48
     END
@@ -2711,6 +2728,14 @@ BEGIN
         TOPMARGIN, 7
         BOTTOMMARGIN, 147
     END
+
+    IDD_CHANGE_IP, DIALOG
+    BEGIN
+        LEFTMARGIN, 7
+        RIGHTMARGIN, 165
+        TOPMARGIN, 7
+        BOTTOMMARGIN, 39
+    END
 END
 #endif    // APSTUDIO_INVOKED
 
@@ -2901,18 +2926,6 @@ BEGIN
     ICON            IDI_SEVERITY_MINOR,IDC_STATIC,7,7,21,20
 END
 
-IDD_CHANGE_IP DIALOG DISCARDABLE  0, 0, 172, 46
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "Change IP Address"
-FONT 8, "MS Sans Serif"
-BEGIN
-    CONTROL         "IPAddress1",IDC_IP_ADDR,"SysIPAddress32",WS_TABSTOP,7,
-                    18,100,15
-    DEFPUSHBUTTON   "OK",IDOK,115,7,50,14
-    PUSHBUTTON      "Cancel",IDCANCEL,115,24,50,14
-    LTEXT           "Enter new IP address for node:",IDC_STATIC,7,7,98,8
-END
-
 IDD_OBJTOOL_COLUMNS DIALOGEX 0, 0, 257, 154
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION
 CAPTION "Columns"
@@ -2943,14 +2956,6 @@ BEGIN
         BOTTOMMARGIN, 79
     END
 
-    IDD_CHANGE_IP, DIALOG
-    BEGIN
-        LEFTMARGIN, 7
-        RIGHTMARGIN, 165
-        TOPMARGIN, 7
-        BOTTOMMARGIN, 39
-    END
-
     IDD_OBJTOOL_COLUMNS, DIALOG
     BEGIN
         LEFTMARGIN, 7
index dbe4502..81688ec 100644 (file)
@@ -83,8 +83,11 @@ void SelectListViewItem(CListCtrl *pListCtrl, int iItem)
       pListCtrl->SetItemState(i, 0, LVIS_SELECTED | LVIS_FOCUSED);
       i = pListCtrl->GetNextItem(i, LVIS_SELECTED);
    }
-   pListCtrl->SetItemState(iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
-   pListCtrl->SetSelectionMark(iItem);
+   if (iItem != -1)
+   {
+      pListCtrl->SetItemState(iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
+      pListCtrl->SetSelectionMark(iItem);
+   }
 }
 
 
@@ -691,3 +694,37 @@ HTREEITEM FindTreeCtrlItem(CTreeCtrl &ctrl, HTREEITEM hRoot, TCHAR *pszText)
    }
    return NULL;
 }
+
+
+//
+// Find item by LPARAM in tree control's subtree (all levels)
+//
+
+HTREEITEM FindTreeCtrlItemEx(CTreeCtrl &ctrl, HTREEITEM hRoot, DWORD dwData)
+{
+   HTREEITEM hItem, hResult;
+
+   if (hRoot != TVI_ROOT)
+   {
+      if (ctrl.GetItemData(hRoot) == dwData)
+         return hRoot;
+   }
+
+   hItem = ctrl.GetChildItem(hRoot);
+   while(hItem != NULL)
+   {
+      if (ctrl.ItemHasChildren(hItem))
+      {
+         hResult = FindTreeCtrlItemEx(ctrl, hItem, dwData);
+         if (hResult != NULL)
+            return hResult;
+      }
+      else
+      {
+         if (ctrl.GetItemData(hItem) == dwData)
+            return hItem;
+      }
+      hItem = ctrl.GetNextItem(hItem, TVGN_NEXT);
+   }
+   return NULL;
+}
index 7b8cf10..630dfda 100644 (file)
@@ -107,20 +107,32 @@ DWORD LIBNXCL_EXPORTABLE NXCGetScript(NXC_SESSION hSession, DWORD dwId, TCHAR **
 // Update script
 //
 
-DWORD LIBNXCL_EXPORTABLE NXCUpdateScript(NXC_SESSION hSession, DWORD dwId,
+DWORD LIBNXCL_EXPORTABLE NXCUpdateScript(NXC_SESSION hSession, DWORD *pdwId,
                                          TCHAR *pszName, TCHAR *pszCode)
 {
-   CSCPMessage msg;
-   DWORD dwRqId;
+   CSCPMessage msg, *pResponse;
+   DWORD dwRqId, dwResult;
 
    dwRqId = ((NXCL_Session *)hSession)->CreateRqId();
 
    msg.SetCode(CMD_UPDATE_SCRIPT);
    msg.SetId(dwRqId);
-   msg.SetVariable(VID_SCRIPT_ID, dwId);
+   msg.SetVariable(VID_SCRIPT_ID, *pdwId);
    msg.SetVariable(VID_NAME, pszName);
    msg.SetVariable(VID_SCRIPT_CODE, pszCode);
    ((NXCL_Session *)hSession)->SendMsg(&msg);
 
-   return ((NXCL_Session *)hSession)->WaitForRCC(dwRqId);
+   pResponse = ((NXCL_Session *)hSession)->WaitForMessage(CMD_REQUEST_COMPLETED, dwRqId);
+   if (pResponse != NULL)
+   {
+      dwResult = pResponse->GetVariableLong(VID_RCC);
+      if (dwResult == RCC_SUCCESS)
+         *pdwId = pResponse->GetVariableLong(VID_SCRIPT_ID);
+      delete pResponse;
+   }
+   else
+   {
+      dwResult = RCC_TIMEOUT;
+   }
+   return dwResult;
 }
index bbde1f9..cc8a3a4 100644 (file)
 #include "nxcore.h"
 
 
+//
+// Externals
+//
+
+extern Queue g_nodePollerQueue;
+
+
+//
+// Discovery class
+//
+
+class NXSL_DiscoveryClass : public NXSL_Class
+{
+public:
+   NXSL_DiscoveryClass();
+
+   virtual NXSL_Value *GetAttr(NXSL_Object *pObject, char *pszAttr);
+};
+
+
+//
+// Implementation of discovery class
+//
+
+NXSL_DiscoveryClass::NXSL_DiscoveryClass()
+                     :NXSL_Class()
+{
+   strcpy(m_szName, "NewNode");
+}
+
+NXSL_Value *NXSL_DiscoveryClass::GetAttr(NXSL_Object *pObject, char *pszAttr)
+{
+   DISCOVERY_FILTER_DATA *pData;
+   NXSL_Value *pValue = NULL;
+   char szBuffer[256];
+
+   pData = (DISCOVERY_FILTER_DATA *)pObject->Data();
+   if (!strcmp(pszAttr, "ipAddr"))
+   {
+      IpToStr(pData->dwIpAddr, szBuffer);
+      pValue = new NXSL_Value(szBuffer);
+   }
+   else if (!strcmp(pszAttr, "netMask"))
+   {
+      IpToStr(pData->dwNetMask, szBuffer);
+      pValue = new NXSL_Value(szBuffer);
+   }
+   else if (!strcmp(pszAttr, "subnet"))
+   {
+      IpToStr(pData->dwSubnetAddr, szBuffer);
+      pValue = new NXSL_Value(szBuffer);
+   }
+   else if (!strcmp(pszAttr, "isAgent"))
+   {
+      pValue = new NXSL_Value((LONG)((pData->dwFlags & NNF_IS_AGENT) ? 1 : 0));
+   }
+   else if (!strcmp(pszAttr, "isSNMP"))
+   {
+      pValue = new NXSL_Value((LONG)((pData->dwFlags & NNF_IS_SNMP) ? 1 : 0));
+   }
+   else if (!strcmp(pszAttr, "isBridge"))
+   {
+      pValue = new NXSL_Value((LONG)((pData->dwFlags & NNF_IS_BRIDGE) ? 1 : 0));
+   }
+   else if (!strcmp(pszAttr, "isRouter"))
+   {
+      pValue = new NXSL_Value((LONG)((pData->dwFlags & NNF_IS_ROUTER) ? 1 : 0));
+   }
+   else if (!strcmp(pszAttr, "isPrinter"))
+   {
+      pValue = new NXSL_Value((LONG)((pData->dwFlags & NNF_IS_PRINTER) ? 1 : 0));
+   }
+   else if (!strcmp(pszAttr, "snmpVersion"))
+   {
+      pValue = new NXSL_Value((LONG)pData->nSNMPVersion);
+   }
+   else if (!strcmp(pszAttr, "snmpOID"))
+   {
+      pValue = new NXSL_Value(pData->szObjectId);
+   }
+   else if (!strcmp(pszAttr, "agentVersion"))
+   {
+      pValue = new NXSL_Value(pData->szAgentVersion);
+   }
+   else if (!strcmp(pszAttr, "platformName"))
+   {
+      pValue = new NXSL_Value(pData->szPlatform);
+   }
+   return pValue;
+}
+
+
+//
+// Discovery class object
+//
+
+static NXSL_DiscoveryClass m_nxslDiscoveryClass;
+
+
 //
 // Poll new node for configuration
 // Returns pointer to new node object on success or NULL on failure
@@ -59,55 +158,144 @@ NetObj *PollNewNode(DWORD dwIpAddr, DWORD dwNetMask, DWORD dwFlags, TCHAR *pszNa
 
 
 //
-// Node poller thread (poll new nodes and put them into the database)
+// Check if newly discovered node should be added
 //
 
-THREAD_RESULT THREAD_CALL NodePoller(void *arg)
+static BOOL AcceptNewNode(DWORD dwIpAddr, DWORD dwNetMask)
 {
-   DB_RESULT hResult;
-   int iPollInterval;
-   DWORD dwWatchdogId;
+   DISCOVERY_FILTER_DATA data;
+   char szCommunityString[MAX_DB_STRING], szFilter[MAX_DB_STRING], szBuffer[256];
+   DWORD dwTemp;
+   AgentConnection *pAgentConn;
+   NXSL_Program *pScript;
+   NXSL_Value *pValue;
+   BOOL bResult = FALSE;
 
-   // Flush new nodes table
-   DBQuery(g_hCoreDB, "DELETE FROM new_nodes");
+   if ((FindNodeByIP(dwIpAddr) != NULL) ||
+       (FindSubnetByIP(dwIpAddr) != NULL))
+      return FALSE;  // Node already exist in database
 
-   // Read configuration and initialize
-   iPollInterval = ConfigReadInt("NewNodePollingInterval", 60);
-   dwWatchdogId = WatchdogAddThread("Node Poller", iPollInterval * 2 + 10);
-   DbgPrintf(AF_DEBUG_DISCOVERY, "Node poller started with poll interval %d seconds", iPollInterval);
+   // Read configuration
+   ConfigReadStr("DefaultCommunityString", szCommunityString, MAX_DB_STRING, "public");
+   ConfigReadStr("DiscoveryFilter", szFilter, MAX_DB_STRING, "");
+   StrStrip(szFilter);
 
-   while(!ShutdownInProgress())
+   // Run filter script
+   if ((szFilter[0] == 0) || (!_tcsicmp(szFilter, "none")))
+      return TRUE;   // No filtering
+
+   // Initialize new node data
+   memset(&data, 0, sizeof(DISCOVERY_FILTER_DATA));
+   data.dwIpAddr = dwIpAddr;
+   data.dwNetMask = dwNetMask;
+   data.dwSubnetAddr = dwIpAddr & dwNetMask;
+
+   // Check SNMP support
+   if (SnmpGet(SNMP_VERSION_2C, dwIpAddr, 161, szCommunityString,
+               ".1.3.6.1.2.1.1.2.0", NULL, 0, data.szObjectId, MAX_OID_LEN * 4,
+               FALSE, FALSE) == SNMP_ERR_SUCCESS)
+   {
+      data.dwFlags |= NNF_IS_SNMP;
+      data.nSNMPVersion = SNMP_VERSION_2C;
+   }
+   else
+   {
+      if (SnmpGet(SNMP_VERSION_1, dwIpAddr, 161, szCommunityString,
+                  ".1.3.6.1.2.1.1.2.0", NULL, 0, data.szObjectId, MAX_OID_LEN * 4,
+                  FALSE, FALSE) == SNMP_ERR_SUCCESS)
+      {
+         data.dwFlags |= NNF_IS_SNMP;
+         data.nSNMPVersion = SNMP_VERSION_1;
+      }
+   }
+
+   // Check NetXMS agent support
+   pAgentConn = new AgentConnection(htonl(dwIpAddr), AGENT_LISTEN_PORT,
+                                    AUTH_NONE, "");
+   if (pAgentConn->Connect(g_pServerKey))
+   {
+      data.dwFlags |= NNF_IS_AGENT;
+      pAgentConn->GetParameter("Agent.Version", MAX_AGENT_VERSION_LEN, data.szAgentVersion);
+      pAgentConn->GetParameter("System.PlatformName", MAX_PLATFORM_NAME_LEN, data.szPlatform);
+   }
+
+   // Check if node is a router
+   if (data.dwFlags & NNF_IS_SNMP)
+   {
+      if (SnmpGet(data.nSNMPVersion, dwIpAddr, 161, szCommunityString,
+                  ".1.3.6.1.2.1.4.1.0", NULL, 0, &dwTemp, sizeof(DWORD),
+                  FALSE, FALSE) == SNMP_ERR_SUCCESS)
+      {
+         if (dwTemp == 1)
+            data.dwFlags |= NNF_IS_ROUTER;
+      }
+   }
+   else if (data.dwFlags & NNF_IS_AGENT)
+   {
+      // Check IP forwarding status
+      if (pAgentConn->GetParameter("Net.IP.Forwarding", 16, szBuffer) == ERR_SUCCESS)
+      {
+         if (_tcstoul(szBuffer, NULL, 10) != 0)
+            data.dwFlags |= NNF_IS_ROUTER;
+      }
+   }
+
+   // Check if node is a bridge
+   if (data.dwFlags & NNF_IS_SNMP)
    {
-      if (SleepAndCheckForShutdown(iPollInterval))
-         break;      // Shutdown has arrived
-      WatchdogNotify(dwWatchdogId);
+      if (SnmpGet(data.nSNMPVersion, dwIpAddr, 161, szCommunityString,
+                  ".1.3.6.1.2.1.17.1.1.0", NULL, 0, szBuffer, 256,
+                  FALSE, FALSE) == SNMP_ERR_SUCCESS)
+      {
+         data.dwFlags |= NNF_IS_BRIDGE;
+      }
+   }
+
+   // Cleanup
+   delete pAgentConn;
 
-      hResult = DBSelect(g_hCoreDB, "SELECT id,ip_addr,ip_netmask,discovery_flags FROM new_nodes");
-      if (hResult != 0)
+   g_pScriptLibrary->Lock();
+   pScript = g_pScriptLibrary->FindScript(szFilter);
+   if (pScript != NULL)
+   {
+      DbgPrintf(AF_DEBUG_DISCOVERY, "Running filter script %s", szFilter);
+      pValue = new NXSL_Value(new NXSL_Object(&m_nxslDiscoveryClass, &data));
+      if (pScript->Run(NULL, 1, &pValue) == 0)
       {
-         int i, iNumRows;
-         DWORD dwId, dwIpAddr, dwNetMask, dwFlags;
-         char szQuery[256];
-
-         iNumRows = DBGetNumRows(hResult);
-         for(i = 0; i < iNumRows; i++)
-         {
-            WatchdogNotify(dwWatchdogId);
-
-            dwId = DBGetFieldULong(hResult, i, 0);
-            dwIpAddr = DBGetFieldIPAddr(hResult, i, 1);
-            dwNetMask = DBGetFieldIPAddr(hResult, i, 2);
-            dwFlags = DBGetFieldULong(hResult, i, 3);
-
-            PollNewNode(dwIpAddr, dwNetMask, dwFlags, NULL);
-
-            // Delete processed node
-            sprintf(szQuery, "DELETE FROM new_nodes WHERE id=%d", dwId);
-            DBQuery(g_hCoreDB, szQuery);
-         }
-         DBFreeResult(hResult);
+         bResult = (pScript->GetResult()->GetValueAsInt32() != 0) ? TRUE : FALSE;
+         DbgPrintf(AF_DEBUG_DISCOVERY, "Filter script result: %d", bResult);
       }
    }
+   else
+   {
+      DbgPrintf(AF_DEBUG_DISCOVERY, "Cannot find filter script %s", szFilter);
+   }
+   g_pScriptLibrary->Unlock();
+
+   return bResult;
+}
+
+
+//
+// Node poller thread (poll new nodes and put them into the database)
+//
+
+THREAD_RESULT THREAD_CALL NodePoller(void *arg)
+{
+   NEW_NODE *pInfo;
+
+   DbgPrintf(AF_DEBUG_DISCOVERY, "Node poller started");
+
+   while(!ShutdownInProgress())
+   {
+      pInfo = (NEW_NODE *)g_nodePollerQueue.GetOrBlock();
+      if (pInfo == INVALID_POINTER_VALUE)
+         break;   // Shutdown indicator received
+
+      if (AcceptNewNode(pInfo->dwIpAddr, pInfo->dwNetMask))
+         PollNewNode(pInfo->dwIpAddr, pInfo->dwNetMask, pInfo->dwFlags, NULL);
+      free(pInfo);
+   }
    DbgPrintf(AF_DEBUG_DISCOVERY, "Node poller thread terminated");
    return THREAD_OK;
 }
index 3630dc3..50020f1 100644 (file)
@@ -44,6 +44,7 @@ Queue g_statusPollQueue;
 Queue g_configPollQueue;
 Queue g_routePollQueue;
 Queue g_discoveryPollQueue;
+Queue g_nodePollerQueue;
 
 
 //
@@ -279,7 +280,7 @@ static THREAD_RESULT THREAD_CALL RoutePoller(void *arg)
 static THREAD_RESULT THREAD_CALL DiscoveryPoller(void *arg)
 {
    Node *pNode;
-   TCHAR szBuffer[MAX_OBJECT_NAME + 64], szIpAddr[16], szNetMask[16];
+   TCHAR szBuffer[MAX_OBJECT_NAME + 64], szIpAddr[16];
    ARP_CACHE *pArpCache;
 
    // Initialize state info
@@ -315,12 +316,13 @@ static THREAD_RESULT THREAD_CALL DiscoveryPoller(void *arg)
                   if (!IsBroadcastAddress(pArpCache->pEntries[j].dwIpAddr,
                                           pInterface->IpNetMask()))
                   {
-                     TCHAR szQuery[256];
+                     NEW_NODE *pInfo;
 
-                     _sntprintf(szQuery, 256, _T("INSERT INTO new_nodes (id,ip_addr,ip_netmask,discovery_flags) VALUES (%d,'%s','%s',%d)"),
-                                m_dwNewNodeId++, IpToStr(pArpCache->pEntries[j].dwIpAddr, szIpAddr),
-                                IpToStr(pInterface->IpNetMask(), szNetMask), DF_DEFAULT);
-                     DBQuery(g_hCoreDB, szQuery);
+                     pInfo = (NEW_NODE *)malloc(sizeof(NEW_NODE));
+                     pInfo->dwIpAddr = pArpCache->pEntries[j].dwIpAddr;
+                     pInfo->dwNetMask = pInterface->IpNetMask();
+                     pInfo->dwFlags = DF_DEFAULT;
+                     g_nodePollerQueue.Put(pInfo);
                   }
             }
          }
@@ -332,6 +334,8 @@ static THREAD_RESULT THREAD_CALL DiscoveryPoller(void *arg)
       pNode->SetDiscoveryPollTimeStamp();
       pNode->DecRefCount();
    }
+   g_nodePollerQueue.Clear();
+   g_nodePollerQueue.Put(INVALID_POINTER_VALUE);
    SetPollerState((int)arg, "finished");
    return THREAD_OK;
 }
index 3fde2c2..942f9fa 100644 (file)
@@ -232,6 +232,46 @@ typedef void * HSNMPSESSION;
 #include "nms_alarm.h"
 
 
+//
+// New node information
+//
+
+typedef struct
+{
+   DWORD dwIpAddr;
+   DWORD dwNetMask;
+   DWORD dwFlags;
+} NEW_NODE;
+
+
+//
+// New node flags
+//
+
+#define NNF_IS_SNMP     0x0001
+#define NNF_IS_AGENT    0x0002
+#define NNF_IS_ROUTER   0x0004
+#define NNF_IS_BRIDGE   0x0008
+#define NNF_IS_PRINTER  0x0010
+
+
+//
+// Node information for autodiscovery filter
+//
+
+typedef struct
+{
+   DWORD dwIpAddr;
+   DWORD dwNetMask;
+   DWORD dwSubnetAddr;
+   DWORD dwFlags;
+   int nSNMPVersion;
+   char szObjectId[MAX_OID_LEN * 4];    // SNMP OID
+   char szAgentVersion[MAX_AGENT_VERSION_LEN];
+   char szPlatform[MAX_PLATFORM_NAME_LEN];
+} DISCOVERY_FILTER_DATA;
+
+
 //
 // Data update structure for client sessions
 //