Allow selection of SNMP port during network disovery Feature #841
authorzev <zev@radensolutions.com>
Tue, 1 Sep 2015 17:46:37 +0000 (20:46 +0300)
committerzev <zev@radensolutions.com>
Tue, 1 Sep 2015 17:47:32 +0000 (20:47 +0300)
14 files changed:
include/netxmsdb.h
include/nxsnmp.h
sql/setup.in
src/java/netxms-eclipse/SNMP/src/org/netxms/ui/eclipse/snmp/views/SnmpCredentials.java
src/java/netxms-eclipse/SNMP/src/org/netxms/ui/eclipse/snmp/views/helpers/SnmpConfig.java
src/server/core/node.cpp
src/server/core/np.cpp
src/server/core/snmp.cpp
src/server/include/nms_core.h
src/server/include/nxsrvapi.h
src/server/tools/nxdbmgr/upgrade.cpp
src/snmp/libnxsnmp/transport.cpp
webui/webapp/SNMP/src/org/netxms/ui/eclipse/snmp/views/SnmpCredentials.java
webui/webapp/SNMP/src/org/netxms/ui/eclipse/snmp/views/helpers/SnmpConfig.java

index 073d634..07db10d 100644 (file)
@@ -23,6 +23,6 @@
 #ifndef _netxmsdb_h
 #define _netxmsdb_h
 
-#define DB_FORMAT_VERSION   364
+#define DB_FORMAT_VERSION   365
 
 #endif
index 7341ce2..964768f 100644 (file)
@@ -640,6 +640,8 @@ public:
       return InetAddress();
    }
 
+   virtual WORD getPort()=0;
+
    UINT32 doRequest(SNMP_PDU *request, SNMP_PDU **response, UINT32 timeout = INFINITE, int numRetries = 1);
 
        void setSecurityContext(SNMP_SecurityContext *ctx);
@@ -670,6 +672,7 @@ protected:
    size_t m_dwBytesInBuffer;
    size_t m_dwBufferPos;
    BYTE *m_pBuffer;
+   WORD m_port;
 
    size_t preParsePDU();
    int recvData(UINT32 dwTimeout, struct sockaddr *pSender, socklen_t *piAddrSize);
@@ -689,6 +692,7 @@ public:
    UINT32 createUDPTransport(const TCHAR *hostName, WORD port = SNMP_DEFAULT_PORT);
    UINT32 createUDPTransport(const InetAddress& hostAddr, WORD port = SNMP_DEFAULT_PORT);
        bool isConnected() { return m_connected; }
+   WORD getPort() { return m_port; }
 };
 
 /**
index 5da04b6..54961ff 100644 (file)
@@ -132,6 +132,7 @@ INSERT INTO config (var_name,var_value,is_visible,need_server_restart) VALUES ('
 INSERT INTO config (var_name,var_value,is_visible,need_server_restart) VALUES ('SMTPFromAddr','netxms@localhost',1,0);
 INSERT INTO config (var_name,var_value,is_visible,need_server_restart) VALUES ('SMTPFromName','NetXMS Server',1,0);
 INSERT INTO config (var_name,var_value,is_visible,need_server_restart) VALUES ('SMTPRetryCount','1',1,0);
+INSERT INTO config (var_name,var_value,is_visible,need_server_restart) VALUES ('SNMPPorts','162',1,1);
 INSERT INTO config (var_name,var_value,is_visible,need_server_restart) VALUES ('SMTPServer','localhost',1,0);
 INSERT INTO config (var_name,var_value,is_visible,need_server_restart) VALUES ('SNMPRequestTimeout','2000',1,1);
 INSERT INTO config (var_name,var_value,is_visible,need_server_restart) VALUES ('SNMPTrapLogRetentionTime','90',1,0);
index 3d08412..aad2fdc 100644 (file)
@@ -66,10 +66,11 @@ public class SnmpCredentials extends ViewPart implements ISaveablePart
        public static final String ID = "org.netxms.ui.eclipse.snmp.views.SnmpCredentials"; //$NON-NLS-1$
 
        private boolean modified = false;
-   private FormToolkit toolkit;
-   private ScrolledForm form;
+       private FormToolkit toolkit;
+       private ScrolledForm form;
        private TableViewer snmpCommunityList;
        private TableViewer snmpUsmCredList;
+       private TableViewer snmpPortList;
        private Action actionSave;
        private SnmpConfig config;
 
@@ -98,6 +99,7 @@ public class SnmpCredentials extends ViewPart implements ISaveablePart
                
                createSnmpCommunitySection();
                createSnmpUsmCredSection();
+               createSnmpPortList();
                
                createActions();
                contributeToActionBars();
@@ -295,6 +297,67 @@ public class SnmpCredentials extends ViewPart implements ISaveablePart
                        }
                });
        }
+       
+         /**
+    * Create "Port List" section
+    */
+   private void createSnmpPortList()
+   {
+      Section section = toolkit.createSection(form.getBody(), Section.DESCRIPTION | Section.TITLE_BAR);
+      section.setText("SNMP Ports");
+      section.setDescription("SNMP ports used in the network");
+      TableWrapData td = new TableWrapData();
+      td.align = TableWrapData.FILL;
+      td.grabHorizontal = true;
+      section.setLayoutData(td);
+      
+      Composite clientArea = toolkit.createComposite(section);
+      GridLayout layout = new GridLayout();
+      layout.numColumns = 2;
+      clientArea.setLayout(layout);
+      section.setClient(clientArea);
+      
+      snmpPortList = new TableViewer(clientArea, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
+      toolkit.adapt(snmpPortList.getTable());
+      GridData gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      gd.verticalAlignment = SWT.FILL;
+      gd.grabExcessVerticalSpace = true;
+      gd.verticalSpan = 2;
+      gd.heightHint = 150;
+      snmpPortList.getTable().setLayoutData(gd);
+      snmpPortList.setContentProvider(new ArrayContentProvider());
+      snmpPortList.setComparator(new StringComparator());
+
+      final ImageHyperlink linkAdd = toolkit.createImageHyperlink(clientArea, SWT.NONE);
+      linkAdd.setText(Messages.get().SnmpConfigurator_Add);
+      linkAdd.setImage(SharedIcons.IMG_ADD_OBJECT);
+      gd = new GridData();
+      gd.verticalAlignment = SWT.TOP;
+      linkAdd.setLayoutData(gd);
+      linkAdd.addHyperlinkListener(new HyperlinkAdapter() {
+         @Override
+         public void linkActivated(HyperlinkEvent e)
+         {
+            addSnmpPort();
+         }
+      });
+      
+      final ImageHyperlink linkRemove = toolkit.createImageHyperlink(clientArea, SWT.NONE);
+      linkRemove.setText(Messages.get().SnmpConfigurator_Remove);
+      linkRemove.setImage(SharedIcons.IMG_DELETE_OBJECT);
+      gd = new GridData();
+      gd.verticalAlignment = SWT.TOP;
+      linkRemove.setLayoutData(gd);
+      linkRemove.addHyperlinkListener(new HyperlinkAdapter() {
+         @Override
+         public void linkActivated(HyperlinkEvent e)
+         {
+            removeSnmpPort();
+         }
+      });
+   }
 
        /* (non-Javadoc)
         * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
@@ -314,6 +377,7 @@ public class SnmpCredentials extends ViewPart implements ISaveablePart
                
                snmpCommunityList.setInput(config.getCommunities().toArray());
                snmpUsmCredList.setInput(config.getUsmCredentials().toArray());
+      snmpPortList.setInput(config.getPorts().toArray());
 
                modified = false;
                firePropertyChange(PROP_DIRTY);
@@ -485,4 +549,42 @@ public class SnmpCredentials extends ViewPart implements ISaveablePart
                        setModified();
                }
        }
+       
+         /**
+    * Add SNMP USM credentials to the list
+    */
+   private void addSnmpPort()
+   {
+      InputDialog dlg = new InputDialog(getSite().getShell(), "Add SNMP Port", 
+            "Please enter SNMP Port", "", null); //$NON-NLS-1$
+      if (dlg.open() == Window.OK)
+      {
+         String value = dlg.getValue();
+         final List<String> list = config.getPorts();
+         if (!list.contains(value))
+         {
+            list.add(value);
+            snmpPortList.setInput(list.toArray());
+            setModified();
+         }
+      }
+   }
+   
+   /**
+    * Remove selected SNMP USM credentials
+    */
+   private void removeSnmpPort()
+   {
+      final List<String> list = config.getPorts();
+      IStructuredSelection selection = (IStructuredSelection)snmpPortList.getSelection();
+      if (selection.size() > 0)
+      {
+         for(Object o : selection.toList())
+         {
+            list.remove(o);
+         }
+         snmpPortList.setInput(list.toArray());
+         setModified();
+      }
+   }
 }
index 56ea4d7..54c6289 100644 (file)
@@ -1,9 +1,13 @@
 package org.netxms.ui.eclipse.snmp.views.helpers;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 import org.netxms.client.NXCException;
 import org.netxms.client.NXCSession;
+import org.netxms.client.server.ServerVariable;
 import org.netxms.client.snmp.SnmpUsmCredential;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 
@@ -11,6 +15,7 @@ public class SnmpConfig
 {
    private List<String> communities;
    private List<SnmpUsmCredential> usmCredentials;
+   private List<String> ports;
 
    /**
     * Create empty object
@@ -34,11 +39,38 @@ public class SnmpConfig
       
       config.communities = session.getSnmpCommunities();
       config.usmCredentials = session.getSnmpUsmCredentials();
-      
+      Map<String, ServerVariable> variables = session.getServerVariables();
+      ServerVariable v = variables.get("SNMPPorts");
+      config.ports = parsePorts(v != null ? v.getValue() : "" );
+
       return config;
    }
    
    /**
+    * 
+    * @param portList
+    */
+   public static List<String> parsePorts(String portList)
+   {
+      String[] arr = portList.split(",");
+      List<String> list = new ArrayList<String>(Arrays.asList(arr));
+      return list;      
+   }
+   
+   public String parsePorts() 
+   {
+      StringBuilder str = new StringBuilder();
+      for(int i = 0; i < ports.size(); i++)
+      {
+         str.append(ports.get(i));
+         if(i != ports.size() - 1)
+         {
+            str.append(",");            
+         }
+      }
+      return str.toString();
+   }
+   /**
     * Save SNMP configuration on server. This method calls communication
     * API directly, so it should not be called from UI thread.
     * 
@@ -51,6 +83,7 @@ public class SnmpConfig
       
       session.updateSnmpCommunities(communities);
       session.updateSnmpUsmCredentials(usmCredentials);
+      session.setServerVariable("SNMPPorts", parsePorts());
    }
    
    /**
@@ -68,6 +101,22 @@ public class SnmpConfig
    {
       this.communities = communities;
    }
+   
+   /**
+    * @return the ports
+    */
+   public List<String> getPorts()
+   {
+      return ports;
+   }
+   
+   /**
+    * @param communities the communities to set
+    */
+   public void setPorts(List<String> ports)
+   {
+      this.ports = ports;
+   }
 
    /**
     * @return the usmCredentials
index 8df0d43..8b2d479 100644 (file)
@@ -2218,13 +2218,6 @@ bool Node::confPollSnmp(UINT32 dwRqId)
 
    sendPollerMsg(dwRqId, _T("   Checking SNMP...\r\n"));
    DbgPrintf(5, _T("ConfPoll(%s): calling SnmpCheckCommSettings()"), m_name);
-       SNMP_Transport *pTransport = createSnmpTransport();
-       if (pTransport == NULL)
-       {
-               DbgPrintf(5, _T("ConfPoll(%s): unable to create SNMP transport"), m_name);
-               return false;
-       }
-
    StringList oids;
    const TCHAR *customOid = m_customAttributes.get(_T("snmp.testoid"));
    if (customOid != NULL)
@@ -2232,320 +2225,325 @@ bool Node::confPollSnmp(UINT32 dwRqId)
    oids.add(_T(".1.3.6.1.2.1.1.2.0"));
    oids.add(_T(".1.3.6.1.2.1.1.1.0"));
    AddDriverSpecificOids(&oids);
-   SNMP_SecurityContext *newCtx = SnmpCheckCommSettings(pTransport, &m_snmpVersion, m_snmpSecurity, &oids);
-       if (newCtx != NULL)
+   SNMP_Transport *pTransport = SnmpCheckCommSettings(getEffectiveSnmpProxy(), (getEffectiveSnmpProxy() == m_id) ? InetAddress::LOOPBACK : m_ipAddress, &m_snmpVersion, m_snmpPort, m_snmpSecurity, &oids);
+   if(pTransport == NULL)
    {
-      lockProperties();
-               delete m_snmpSecurity;
-               m_snmpSecurity = newCtx;
-      m_dwFlags |= NF_IS_SNMP;
-      if (m_dwDynamicFlags & NDF_SNMP_UNREACHABLE)
-      {
-         m_dwDynamicFlags &= ~NDF_SNMP_UNREACHABLE;
-         PostEvent(EVENT_SNMP_OK, m_id, NULL);
-         sendPollerMsg(dwRqId, POLLER_INFO _T("   Connectivity with SNMP agent restored\r\n"));
-      }
-               unlockProperties();
-      sendPollerMsg(dwRqId, _T("   SNMP agent is active (version %s)\r\n"),
-                       (m_snmpVersion == SNMP_VERSION_3) ? _T("3") : ((m_snmpVersion == SNMP_VERSION_2C) ? _T("2c") : _T("1")));
-
-               TCHAR szBuffer[4096];
-               if (SnmpGet(m_snmpVersion, pTransport, _T(".1.3.6.1.2.1.1.2.0"), NULL, 0, szBuffer, sizeof(szBuffer), SG_STRING_RESULT) != SNMP_ERR_SUCCESS)
-               {
-                       // Set snmp object ID to .0.0 if it cannot be read
-                       _tcscpy(szBuffer, _T(".0.0"));
-               }
-               lockProperties();
-               if (_tcscmp(m_szObjectId, szBuffer))
-               {
-                       nx_strncpy(m_szObjectId, szBuffer, MAX_OID_LEN * 4);
-                       hasChanges = true;
-               }
-               unlockProperties();
-
-               // Get system description
-               if (SnmpGet(m_snmpVersion, pTransport, _T(".1.3.6.1.2.1.1.1.0"), NULL, 0, szBuffer, sizeof(szBuffer), SG_STRING_RESULT) == SNMP_ERR_SUCCESS)
-               {
-                       TranslateStr(szBuffer, _T("\r\n"), _T(" "));
-                       TranslateStr(szBuffer, _T("\n"), _T(" "));
-                       TranslateStr(szBuffer, _T("\r"), _T(" "));
-                       lockProperties();
-         if ((m_sysDescription == NULL) || _tcscmp(m_sysDescription, szBuffer))
-         {
-                               safe_free(m_sysDescription);
-            m_sysDescription = _tcsdup(szBuffer);
-            hasChanges = true;
-            sendPollerMsg(dwRqId, _T("   System description changed to %s\r\n"), m_sysDescription);
-         }
-                       unlockProperties();
-               }
-
-               // Select device driver
-               NetworkDeviceDriver *driver = FindDriverForNode(this, pTransport);
-               DbgPrintf(5, _T("ConfPoll(%s): selected device driver %s"), m_name, driver->getName());
-               lockProperties();
-               if (driver != m_driver)
-               {
-                       m_driver = driver;
-                       sendPollerMsg(dwRqId, _T("   New network device driver selected: %s\r\n"), m_driver->getName());
-               }
-               unlockProperties();
+      DbgPrintf(5, _T("ConfPoll(%s): unable to create SNMP transport"), m_name);
+      return false;
+   }
 
-               // Allow driver to gather additional info
-               m_driver->analyzeDevice(pTransport, m_szObjectId, &m_customAttributes, &m_driverData);
+   lockProperties();
+   m_snmpPort = pTransport->getPort();
+   delete m_snmpSecurity;
+   m_snmpSecurity = new SNMP_SecurityContext(pTransport->getSecurityContext());
+   m_dwFlags |= NF_IS_SNMP;
+   if (m_dwDynamicFlags & NDF_SNMP_UNREACHABLE)
+   {
+      m_dwDynamicFlags &= ~NDF_SNMP_UNREACHABLE;
+      PostEvent(EVENT_SNMP_OK, m_id, NULL);
+      sendPollerMsg(dwRqId, POLLER_INFO _T("   Connectivity with SNMP agent restored\r\n"));
+   }
+   unlockProperties();
+   sendPollerMsg(dwRqId, _T("   SNMP agent is active (version %s)\r\n"),
+      (m_snmpVersion == SNMP_VERSION_3) ? _T("3") : ((m_snmpVersion == SNMP_VERSION_2C) ? _T("2c") : _T("1")));
 
-               // Get sysName
-               if (SnmpGet(m_snmpVersion, pTransport,
-                           _T(".1.3.6.1.2.1.1.5.0"), NULL, 0, szBuffer, sizeof(szBuffer), SG_STRING_RESULT) == SNMP_ERR_SUCCESS)
-               {
-                       lockProperties();
-                       if ((m_sysName == NULL) || _tcscmp(m_sysName, szBuffer))
-         {
-                               safe_free(m_sysName);
-            m_sysName = _tcsdup(szBuffer);
-            hasChanges = true;
-            sendPollerMsg(dwRqId, _T("   System name changed to %s\r\n"), m_sysName);
-         }
-                       unlockProperties();
-               }
+   TCHAR szBuffer[4096];
+   if (SnmpGet(m_snmpVersion, pTransport, _T(".1.3.6.1.2.1.1.2.0"), NULL, 0, szBuffer, sizeof(szBuffer), SG_STRING_RESULT) != SNMP_ERR_SUCCESS)
+   {
+      // Set snmp object ID to .0.0 if it cannot be read
+      _tcscpy(szBuffer, _T(".0.0"));
+   }
+   lockProperties();
+   if (_tcscmp(m_szObjectId, szBuffer))
+   {
+      nx_strncpy(m_szObjectId, szBuffer, MAX_OID_LEN * 4);
+      hasChanges = true;
+   }
+   unlockProperties();
 
-      // Check IP forwarding
-      if (checkSNMPIntegerValue(pTransport, _T(".1.3.6.1.2.1.4.1.0"), 1))
-      {
-                       lockProperties();
-         m_dwFlags |= NF_IS_ROUTER;
-                       unlockProperties();
-      }
-      else
+   // Get system description
+   if (SnmpGet(m_snmpVersion, pTransport, _T(".1.3.6.1.2.1.1.1.0"), NULL, 0, szBuffer, sizeof(szBuffer), SG_STRING_RESULT) == SNMP_ERR_SUCCESS)
+   {
+      TranslateStr(szBuffer, _T("\r\n"), _T(" "));
+      TranslateStr(szBuffer, _T("\n"), _T(" "));
+      TranslateStr(szBuffer, _T("\r"), _T(" "));
+      lockProperties();
+      if ((m_sysDescription == NULL) || _tcscmp(m_sysDescription, szBuffer))
       {
-                       lockProperties();
-         m_dwFlags &= ~NF_IS_ROUTER;
-                       unlockProperties();
+         safe_free(m_sysDescription);
+         m_sysDescription = _tcsdup(szBuffer);
+         hasChanges = true;
+         sendPollerMsg(dwRqId, _T("   System description changed to %s\r\n"), m_sysDescription);
       }
+      unlockProperties();
+   }
 
-               checkIfXTable(pTransport);
-               checkBridgeMib(pTransport);
+   // Select device driver
+   NetworkDeviceDriver *driver = FindDriverForNode(this, pTransport);
+   DbgPrintf(5, _T("ConfPoll(%s): selected device driver %s"), m_name, driver->getName());
+   lockProperties();
+   if (driver != m_driver)
+   {
+      m_driver = driver;
+      sendPollerMsg(dwRqId, _T("   New network device driver selected: %s\r\n"), m_driver->getName());
+   }
+   unlockProperties();
 
-      // Check for ENTITY-MIB support
-      if (SnmpGet(m_snmpVersion, pTransport, _T(".1.3.6.1.2.1.47.1.4.1.0"), NULL, 0, szBuffer, sizeof(szBuffer), SG_RAW_RESULT) == SNMP_ERR_SUCCESS)
-      {
-                       lockProperties();
-         m_dwFlags |= NF_HAS_ENTITY_MIB;
-                       unlockProperties();
+   // Allow driver to gather additional info
+   m_driver->analyzeDevice(pTransport, m_szObjectId, &m_customAttributes, &m_driverData);
 
-                       ComponentTree *components = BuildComponentTree(this, pTransport);
-                       lockProperties();
-                       if (m_components != NULL)
-                               m_components->decRefCount();
-                       m_components = components;
-                       unlockProperties();
-      }
-      else
+   // Get sysName
+   if (SnmpGet(m_snmpVersion, pTransport,
+               _T(".1.3.6.1.2.1.1.5.0"), NULL, 0, szBuffer, sizeof(szBuffer), SG_STRING_RESULT) == SNMP_ERR_SUCCESS)
+   {
+      lockProperties();
+      if ((m_sysName == NULL) || _tcscmp(m_sysName, szBuffer))
       {
-                       lockProperties();
-         m_dwFlags &= ~NF_HAS_ENTITY_MIB;
-                       if (m_components != NULL)
-                       {
-                               m_components->decRefCount();
-                               m_components = NULL;
-                       }
-                       unlockProperties();
+         safe_free(m_sysName);
+         m_sysName = _tcsdup(szBuffer);
+         hasChanges = true;
+         sendPollerMsg(dwRqId, _T("   System name changed to %s\r\n"), m_sysName);
       }
+      unlockProperties();
+   }
 
-      // Check for printer MIB support
-               int count = 0;
-               SnmpWalk(m_snmpVersion, pTransport, _T(".1.3.6.1.2.1.43.5.1.1.17"), CountingSnmpWalkerCallback, &count, FALSE);
-      if (count > 0)
-      {
-                       lockProperties();
-         m_dwFlags |= NF_IS_PRINTER;
-                       unlockProperties();
-      }
-      else
-      {
-                       lockProperties();
-         m_dwFlags &= ~NF_IS_PRINTER;
-                       unlockProperties();
-      }
+   // Check IP forwarding
+   if (checkSNMPIntegerValue(pTransport, _T(".1.3.6.1.2.1.4.1.0"), 1))
+   {
+      lockProperties();
+      m_dwFlags |= NF_IS_ROUTER;
+      unlockProperties();
+   }
+   else
+   {
+      lockProperties();
+      m_dwFlags &= ~NF_IS_ROUTER;
+      unlockProperties();
+   }
 
-      // Check for CDP (Cisco Discovery Protocol) support
-      if (checkSNMPIntegerValue(pTransport, _T(".1.3.6.1.4.1.9.9.23.1.3.1.0"), 1))
-      {
-                       lockProperties();
-         m_dwFlags |= NF_IS_CDP;
-                       unlockProperties();
-      }
-      else
-      {
-                       lockProperties();
-         m_dwFlags &= ~NF_IS_CDP;
-                       unlockProperties();
-      }
+   checkIfXTable(pTransport);
+   checkBridgeMib(pTransport);
 
-      // Check for NDP (Nortel Discovery Protocol) support
-      if (checkSNMPIntegerValue(pTransport, _T(".1.3.6.1.4.1.45.1.6.13.1.2.0"), 1))
-      {
-                       lockProperties();
-         m_dwFlags |= NF_IS_NDP;
-                       unlockProperties();
-      }
-      else
+   // Check for ENTITY-MIB support
+   if (SnmpGet(m_snmpVersion, pTransport, _T(".1.3.6.1.2.1.47.1.4.1.0"), NULL, 0, szBuffer, sizeof(szBuffer), SG_RAW_RESULT) == SNMP_ERR_SUCCESS)
+   {
+      lockProperties();
+      m_dwFlags |= NF_HAS_ENTITY_MIB;
+      unlockProperties();
+
+      ComponentTree *components = BuildComponentTree(this, pTransport);
+      lockProperties();
+      if (m_components != NULL)
+         m_components->decRefCount();
+      m_components = components;
+      unlockProperties();
+   }
+   else
+   {
+      lockProperties();
+      m_dwFlags &= ~NF_HAS_ENTITY_MIB;
+      if (m_components != NULL)
       {
-                       lockProperties();
-         m_dwFlags &= ~NF_IS_NDP;
-                       unlockProperties();
+         m_components->decRefCount();
+         m_components = NULL;
       }
+      unlockProperties();
+   }
 
-      // Check for LLDP (Link Layer Discovery Protocol) support
-               if (SnmpGet(m_snmpVersion, pTransport, _T(".1.0.8802.1.1.2.1.3.2.0"), NULL, 0, szBuffer, sizeof(szBuffer), 0) == SNMP_ERR_SUCCESS)
-               {
-                       lockProperties();
-                       m_dwFlags |= NF_IS_LLDP;
-                       unlockProperties();
+   // Check for printer MIB support
+   int count = 0;
+   SnmpWalk(m_snmpVersion, pTransport, _T(".1.3.6.1.2.1.43.5.1.1.17"), CountingSnmpWalkerCallback, &count, FALSE);
+   if (count > 0)
+   {
+      lockProperties();
+      m_dwFlags |= NF_IS_PRINTER;
+      unlockProperties();
+   }
+   else
+   {
+      lockProperties();
+      m_dwFlags &= ~NF_IS_PRINTER;
+      unlockProperties();
+   }
 
-         INT32 type;
-         BYTE data[256];
-         UINT32 dataLen;
-                       if ((SnmpGetEx(pTransport, _T(".1.0.8802.1.1.2.1.3.1.0"), NULL, 0, &type, sizeof(INT32), 0, NULL) == SNMP_ERR_SUCCESS) &&
-             (SnmpGetEx(pTransport, _T(".1.0.8802.1.1.2.1.3.2.0"), NULL, 0, data, 256, SG_RAW_RESULT, &dataLen) == SNMP_ERR_SUCCESS))
-                       {
-            BuildLldpId(type, data, dataLen, szBuffer, 1024);
-                               lockProperties();
-                               if ((m_lldpNodeId == NULL) || _tcscmp(m_lldpNodeId, szBuffer))
-                               {
-                                       safe_free(m_lldpNodeId);
-                                       m_lldpNodeId = _tcsdup(szBuffer);
-                                       hasChanges = true;
-                                       sendPollerMsg(dwRqId, _T("   LLDP node ID changed to %s\r\n"), m_lldpNodeId);
-                               }
-                               unlockProperties();
-                       }
+   // Check for CDP (Cisco Discovery Protocol) support
+   if (checkSNMPIntegerValue(pTransport, _T(".1.3.6.1.4.1.9.9.23.1.3.1.0"), 1))
+   {
+      lockProperties();
+      m_dwFlags |= NF_IS_CDP;
+      unlockProperties();
+   }
+   else
+   {
+      lockProperties();
+      m_dwFlags &= ~NF_IS_CDP;
+      unlockProperties();
+   }
 
-                       ObjectArray<LLDP_LOCAL_PORT_INFO> *lldpPorts = GetLLDPLocalPortInfo(pTransport);
-                       lockProperties();
-                       delete m_lldpLocalPortInfo;
-                       m_lldpLocalPortInfo = lldpPorts;
-                       unlockProperties();
-               }
-               else
-               {
-                       lockProperties();
-                       m_dwFlags &= ~NF_IS_LLDP;
-                       unlockProperties();
-               }
+   // Check for NDP (Nortel Discovery Protocol) support
+   if (checkSNMPIntegerValue(pTransport, _T(".1.3.6.1.4.1.45.1.6.13.1.2.0"), 1))
+   {
+      lockProperties();
+      m_dwFlags |= NF_IS_NDP;
+      unlockProperties();
+   }
+   else
+   {
+      lockProperties();
+      m_dwFlags &= ~NF_IS_NDP;
+      unlockProperties();
+   }
 
-      // Check for 802.1x support
-      if (checkSNMPIntegerValue(pTransport, _T(".1.0.8802.1.1.1.1.1.1.0"), 1))
-      {
-                       lockProperties();
-         m_dwFlags |= NF_IS_8021X;
-                       unlockProperties();
-      }
-      else
+   // Check for LLDP (Link Layer Discovery Protocol) support
+   if (SnmpGet(m_snmpVersion, pTransport, _T(".1.0.8802.1.1.2.1.3.2.0"), NULL, 0, szBuffer, sizeof(szBuffer), 0) == SNMP_ERR_SUCCESS)
+   {
+      lockProperties();
+      m_dwFlags |= NF_IS_LLDP;
+      unlockProperties();
+
+      INT32 type;
+      BYTE data[256];
+      UINT32 dataLen;
+      if ((SnmpGetEx(pTransport, _T(".1.0.8802.1.1.2.1.3.1.0"), NULL, 0, &type, sizeof(INT32), 0, NULL) == SNMP_ERR_SUCCESS) &&
+          (SnmpGetEx(pTransport, _T(".1.0.8802.1.1.2.1.3.2.0"), NULL, 0, data, 256, SG_RAW_RESULT, &dataLen) == SNMP_ERR_SUCCESS))
       {
-                       lockProperties();
-                       m_dwFlags &= ~NF_IS_8021X;
-                       unlockProperties();
+         BuildLldpId(type, data, dataLen, szBuffer, 1024);
+         lockProperties();
+         if ((m_lldpNodeId == NULL) || _tcscmp(m_lldpNodeId, szBuffer))
+         {
+            safe_free(m_lldpNodeId);
+            m_lldpNodeId = _tcsdup(szBuffer);
+            hasChanges = true;
+            sendPollerMsg(dwRqId, _T("   LLDP node ID changed to %s\r\n"), m_lldpNodeId);
+         }
+         unlockProperties();
       }
 
-      checkOSPFSupport(pTransport);
+      ObjectArray<LLDP_LOCAL_PORT_INFO> *lldpPorts = GetLLDPLocalPortInfo(pTransport);
+      lockProperties();
+      delete m_lldpLocalPortInfo;
+      m_lldpLocalPortInfo = lldpPorts;
+      unlockProperties();
+   }
+   else
+   {
+      lockProperties();
+      m_dwFlags &= ~NF_IS_LLDP;
+      unlockProperties();
+   }
 
-               // Get VRRP information
-               VrrpInfo *vrrpInfo = GetVRRPInfo(this);
-               if (vrrpInfo != NULL)
-               {
-                       lockProperties();
-                       m_dwFlags |= NF_IS_VRRP;
-                       delete m_vrrpInfo;
-                       m_vrrpInfo = vrrpInfo;
-                       unlockProperties();
-               }
-               else
-               {
-                       lockProperties();
-                       m_dwFlags &= ~NF_IS_VRRP;
-                       unlockProperties();
-               }
+   // Check for 802.1x support
+   if (checkSNMPIntegerValue(pTransport, _T(".1.0.8802.1.1.1.1.1.1.0"), 1))
+   {
+      lockProperties();
+      m_dwFlags |= NF_IS_8021X;
+      unlockProperties();
+   }
+   else
+   {
+      lockProperties();
+      m_dwFlags &= ~NF_IS_8021X;
+      unlockProperties();
+   }
 
-               // Get wireless controller data
-               if ((m_driver != NULL) && m_driver->isWirelessController(pTransport, &m_customAttributes, m_driverData))
-               {
-                       DbgPrintf(5, _T("ConfPoll(%s): node is wireless controller, reading access point information"), m_name);
-         sendPollerMsg(dwRqId, _T("   Reading wireless access point information\r\n"));
-                       lockProperties();
-                       m_dwFlags |= NF_IS_WIFI_CONTROLLER;
-                       unlockProperties();
+   checkOSPFSupport(pTransport);
 
-         int clusterMode = m_driver->getClusterMode(pTransport, &m_customAttributes, m_driverData);
+   // Get VRRP information
+   VrrpInfo *vrrpInfo = GetVRRPInfo(this);
+   if (vrrpInfo != NULL)
+   {
+      lockProperties();
+      m_dwFlags |= NF_IS_VRRP;
+      delete m_vrrpInfo;
+      m_vrrpInfo = vrrpInfo;
+      unlockProperties();
+   }
+   else
+   {
+      lockProperties();
+      m_dwFlags &= ~NF_IS_VRRP;
+      unlockProperties();
+   }
 
-                       ObjectArray<AccessPointInfo> *aps = m_driver->getAccessPoints(pTransport, &m_customAttributes, m_driverData);
-                       if (aps != NULL)
-                       {
-                               sendPollerMsg(dwRqId, POLLER_INFO _T("   %d wireless access points found\r\n"), aps->size());
-                               DbgPrintf(5, _T("ConfPoll(%s): got information about %d access points"), m_name, aps->size());
-                               int adopted = 0;
-                               for(int i = 0; i < aps->size(); i++)
-                               {
-                                       AccessPointInfo *info = aps->get(i);
-                                       if (info->getState() == AP_ADOPTED)
-                                       adopted++;
+   // Get wireless controller data
+   if ((m_driver != NULL) && m_driver->isWirelessController(pTransport, &m_customAttributes, m_driverData))
+   {
+      DbgPrintf(5, _T("ConfPoll(%s): node is wireless controller, reading access point information"), m_name);
+      sendPollerMsg(dwRqId, _T("   Reading wireless access point information\r\n"));
+      lockProperties();
+      m_dwFlags |= NF_IS_WIFI_CONTROLLER;
+      unlockProperties();
 
-               bool newAp = false;
-               AccessPoint *ap = (clusterMode == CLUSTER_MODE_STANDALONE) ? findAccessPointByMAC(info->getMacAddr()) : FindAccessPointByMAC(info->getMacAddr());
-                                       if (ap == NULL)
-                                       {
-                                               String name;
+      int clusterMode = m_driver->getClusterMode(pTransport, &m_customAttributes, m_driverData);
 
-                  if (info->getName() != NULL)
-                  {
-                     name = info->getName();
-                  }
-                  else
+      ObjectArray<AccessPointInfo> *aps = m_driver->getAccessPoints(pTransport, &m_customAttributes, m_driverData);
+      if (aps != NULL)
+      {
+         sendPollerMsg(dwRqId, POLLER_INFO _T("   %d wireless access points found\r\n"), aps->size());
+         DbgPrintf(5, _T("ConfPoll(%s): got information about %d access points"), m_name, aps->size());
+         int adopted = 0;
+         for(int i = 0; i < aps->size(); i++)
+         {
+            AccessPointInfo *info = aps->get(i);
+            if (info->getState() == AP_ADOPTED)
+               adopted++;
+
+            bool newAp = false;
+            AccessPoint *ap = (clusterMode == CLUSTER_MODE_STANDALONE) ? findAccessPointByMAC(info->getMacAddr()) : FindAccessPointByMAC(info->getMacAddr());
+            if (ap == NULL)
+            {
+               String name;
+
+               if (info->getName() != NULL)
+               {
+                  name = info->getName();
+               }
+               else
+               {
+                  for(int j = 0; j < info->getRadioInterfaces()->size(); j++)
                   {
-                                                  for(int j = 0; j < info->getRadioInterfaces()->size(); j++)
-                                                  {
-                                                          if (j > 0)
-                                                                  name += _T("/");
-                                                          name += info->getRadioInterfaces()->get(j)->name;
-                                                  }
+                     if (j > 0)
+                        name += _T("/");
+                     name += info->getRadioInterfaces()->get(j)->name;
                   }
-                  ap = new AccessPoint((const TCHAR *)name, info->getIndex(), info->getMacAddr());
-                                               NetObjInsert(ap, TRUE);
-                                               DbgPrintf(5, _T("ConfPoll(%s): created new access point object %s [%d]"), m_name, ap->getName(), ap->getId());
-                  newAp = true;
-                                       }
-                                       ap->attachToNode(m_id);
-               ap->setIpAddress(info->getIpAddr());
-                                       if ((info->getState() == AP_ADOPTED) || newAp)
-               {
-                                          ap->updateRadioInterfaces(info->getRadioInterfaces());
-                  ap->updateInfo(info->getVendor(), info->getModel(), info->getSerial());
                }
-                                       ap->unhide();
-               ap->updateState(info->getState());
-                               }
+               ap = new AccessPoint((const TCHAR *)name, info->getIndex(), info->getMacAddr());
+               NetObjInsert(ap, TRUE);
+               DbgPrintf(5, _T("ConfPoll(%s): created new access point object %s [%d]"), m_name, ap->getName(), ap->getId());
+               newAp = true;
+            }
+            ap->attachToNode(m_id);
+            ap->setIpAddress(info->getIpAddr());
+            if ((info->getState() == AP_ADOPTED) || newAp)
+            {
+               ap->updateRadioInterfaces(info->getRadioInterfaces());
+               ap->updateInfo(info->getVendor(), info->getModel(), info->getSerial());
+            }
+            ap->unhide();
+            ap->updateState(info->getState());
+         }
 
-                               lockProperties();
-                               m_adoptedApCount = adopted;
-                               m_totalApCount = aps->size();
-                               unlockProperties();
+         lockProperties();
+         m_adoptedApCount = adopted;
+         m_totalApCount = aps->size();
+         unlockProperties();
 
-                               delete aps;
-                       }
-                       else
-                       {
-                               DbgPrintf(5, _T("ConfPoll(%s): failed to read access point information"), m_name);
-                               sendPollerMsg(dwRqId, POLLER_ERROR _T("   Failed to read access point information\r\n"));
-                       }
-               }
-               else
-               {
-                       lockProperties();
-                       m_dwFlags &= ~NF_IS_WIFI_CONTROLLER;
-                       unlockProperties();
-               }
+         delete aps;
+      }
+      else
+      {
+         DbgPrintf(5, _T("ConfPoll(%s): failed to read access point information"), m_name);
+         sendPollerMsg(dwRqId, POLLER_ERROR _T("   Failed to read access point information\r\n"));
+      }
+   }
+   else
+   {
+      lockProperties();
+      m_dwFlags &= ~NF_IS_WIFI_CONTROLLER;
+      unlockProperties();
    }
-   else if (ConfigReadInt(_T("EnableCheckPointSNMP"), 0))
+
+   if (ConfigReadInt(_T("EnableCheckPointSNMP"), 0))
    {
       // Check for CheckPoint SNMP agent on port 161
       DbgPrintf(5, _T("ConfPoll(%s): checking for CheckPoint SNMP"), m_name);
@@ -2786,7 +2784,7 @@ bool Node::updateInterfaceConfiguration(UINT32 rqid, int maskBits)
                      pInterface->setSpeed(ifInfo->speed);
                   }
                   if ((ifInfo->ifTableSuffixLength != pInterface->getIfTableSuffixLen()) ||
-                      memcmp(ifInfo->ifTableSuffix, pInterface->getIfTableSuffix(), 
+                      memcmp(ifInfo->ifTableSuffix, pInterface->getIfTableSuffix(),
                          min(ifInfo->ifTableSuffixLength, pInterface->getIfTableSuffixLen())))
                   {
                      pInterface->setIfTableSuffix(ifInfo->ifTableSuffixLength, ifInfo->ifTableSuffix);
@@ -6920,7 +6918,7 @@ void Node::collectProxyInfo(ProxyInfo *info)
            (dco->getDataSource() == DS_SNMP_AGENT) &&
            (dco->getSourceNode() == 0) &&
            (dco->getAgentCacheMode() == AGENT_CACHE_ON)) ||
-          ((dco->getDataSource() == DS_NATIVE_AGENT) && 
+          ((dco->getDataSource() == DS_NATIVE_AGENT) &&
            (dco->getSourceNode() == info->proxyId)))
       {
          info->msg->setField(info->fieldId++, dco->getId());
index c54407b..d0bd1ab 100644 (file)
@@ -368,45 +368,22 @@ static bool HostIsReachable(const InetAddress& ipAddr, UINT32 zoneId, bool fullC
                return true;
 
        // *** SNMP ***
-       SNMP_Transport *pTransport = NULL;
-       if (snmpProxy != 0)
-       {
-               Node *proxyNode = (Node *)g_idxNodeById.get(snmpProxy);
-               if (proxyNode != NULL)
-               {
-                       AgentConnection *pConn;
-
-                       pConn = proxyNode->createAgentConnection();
-                       if (pConn != NULL)
-                       {
-                               pTransport = new SNMP_ProxyTransport(pConn, ipAddr, 161);
-                       }
-               }
-       }
-       else
-       {
-               pTransport = new SNMP_UDPTransport;
-               ((SNMP_UDPTransport *)pTransport)->createUDPTransport(ipAddr, 161);
-       }
+   INT16 version;
+   StringList oids;
+   oids.add(_T(".1.3.6.1.2.1.1.2.0"));
+   oids.add(_T(".1.3.6.1.2.1.1.1.0"));
+   AddDriverSpecificOids(&oids);
+   SNMP_Transport *pTransport = SnmpCheckCommSettings(snmpProxy, ipAddr, &version, 0, NULL, &oids);
+   //pass correct port
    if (pTransport != NULL)
    {
-          INT16 version;
-      StringList oids;
-      oids.add(_T(".1.3.6.1.2.1.1.2.0"));
-      oids.add(_T(".1.3.6.1.2.1.1.1.0"));
-      AddDriverSpecificOids(&oids);
-      SNMP_SecurityContext *ctx = SnmpCheckCommSettings(pTransport, &version, NULL, &oids);
-          if (ctx != NULL)
-          {
-                  delete ctx;
-                  if (transport != NULL)
-                  {
-                          pTransport->setSnmpVersion(version);
-                          *transport = pTransport;
-                          pTransport = NULL;   // prevent deletion
-                  }
-                  reachable = true;
-          }
+      if (transport != NULL)
+      {
+         pTransport->setSnmpVersion(version);
+         *transport = pTransport;
+         pTransport = NULL;    // prevent deletion
+      }
+      reachable = true;
           delete pTransport;
    }
 
index 70479f2..8895f43 100644 (file)
@@ -145,7 +145,7 @@ ROUTING_TABLE *SnmpGetRoutingTable(UINT32 dwVersion, SNMP_Transport *pTransport)
 /**
  * Check SNMP v3 connectivity
  */
-static SNMP_SecurityContext *SnmpCheckV3CommSettings(SNMP_Transport *pTransport, SNMP_SecurityContext *originalContext, StringList *testOids)
+bool SnmpCheckV3CommSettings(SNMP_Transport *pTransport, SNMP_SecurityContext *originalContext, StringList *testOids)
 {
        char buffer[1024];
 
@@ -160,7 +160,7 @@ static SNMP_SecurityContext *SnmpCheckV3CommSettings(SNMP_Transport *pTransport,
          if (SnmpGet(SNMP_VERSION_3, pTransport, testOids->get(i), NULL, 0, buffer, sizeof(buffer), 0) == SNMP_ERR_SUCCESS)
          {
                           DbgPrintf(5, _T("SnmpCheckV3CommSettings: success"));
-                          return new SNMP_SecurityContext(originalContext);
+                          return true;
          }
       }
        }
@@ -173,8 +173,9 @@ static SNMP_SecurityContext *SnmpCheckV3CommSettings(SNMP_Transport *pTransport,
                char name[MAX_DB_STRING], authPasswd[MAX_DB_STRING], privPasswd[MAX_DB_STRING];
                SNMP_SecurityContext *ctx;
                int i, count = DBGetNumRows(hResult);
+      bool found = false;
 
-               for(i = 0; i < count; i++)
+               for(i = 0; (i < count) && !found; i++)
                {
                        DBGetFieldA(hResult, i, 0, name, MAX_DB_STRING);
                        DBGetFieldA(hResult, i, 3, authPasswd, MAX_DB_STRING);
@@ -188,16 +189,17 @@ static SNMP_SecurityContext *SnmpCheckV3CommSettings(SNMP_Transport *pTransport,
             if (SnmpGet(SNMP_VERSION_3, pTransport, testOids->get(j), NULL, 0, buffer, sizeof(buffer), 0) == SNMP_ERR_SUCCESS)
             {
                                   DbgPrintf(5, _T("SnmpCheckV3CommSettings: success"));
-                                  goto stop_test;
+                                  found = true;
+                                  break;
             }
                        }
                }
-stop_test:
+
                DBFreeResult(hResult);
       DBConnectionPoolReleaseConnection(hdb);
 
                if (i < count)
-                       return new SNMP_SecurityContext(ctx);
+                       return true;
        }
        else
        {
@@ -206,7 +208,7 @@ stop_test:
        }
 
        DbgPrintf(5, _T("SnmpCheckV3CommSettings: failed"));
-       return NULL;
+       return false;
 }
 
 /**
@@ -214,80 +216,133 @@ stop_test:
  * On success, returns new security context object (dynamically created).
  * On failure, returns NULL
  */
-SNMP_SecurityContext *SnmpCheckCommSettings(SNMP_Transport *pTransport, INT16 *version, SNMP_SecurityContext *originalContext, StringList *testOids)
+SNMP_Transport *SnmpCheckCommSettings(UINT32 snmpProxy, const InetAddress& ipAddr, INT16 *version, UINT16 originalPort, SNMP_SecurityContext *originalContext, StringList *testOids)
 {
+   DbgPrintf(5, _T("SnmpCheckCommSettings: start."));
        int i, count, snmpVer = SNMP_VERSION_2C;
        TCHAR buffer[1024];
+   SNMP_Transport *pTransport;
+   //create transport checking ports
 
-       // Check for V3 USM
-       SNMP_SecurityContext *securityContext = SnmpCheckV3CommSettings(pTransport, originalContext, testOids);
-       if (securityContext != NULL)
-       {
-               *version = SNMP_VERSION_3;
-               return securityContext;
-       }
+   TCHAR tmp[MAX_CONFIG_VALUE];
+       ConfigReadStr(_T("SNMPPorts"), tmp, MAX_CONFIG_VALUE, _T("161"));
+   StringList *ports = new StringList(tmp, _T(","));
+   for(int j = -1;j < ports->size(); j++)
+   {
+      UINT16 port;
+      if(j == -1)
+      {
+         if(originalPort == 0)
+            continue;
+         port = originalPort;
+      }
+      else
+      {
+         port = (UINT16)_tcstoul(ports->get(j), NULL, 0);
+         if(port == originalPort)
+            continue;
+      }
+
+      AgentConnection *pConn = NULL;
+      if (snmpProxy != 0)
+      {
+         Node *proxyNode = (Node *)g_idxNodeById.get(snmpProxy);
+         if (proxyNode == NULL)
+         {
+            DbgPrintf(5, _T("SnmpCheckCommSettings: not possible to find proxy node."));
+            goto fail;
+         }
+         pConn = proxyNode->createAgentConnection();
+         if(pConn == NULL)
+         {
+            DbgPrintf(5, _T("SnmpCheckCommSettings: not possible to create proxy connection."));
+            goto fail;
+         }
+         pTransport = new SNMP_ProxyTransport(pConn, ipAddr, port);
+      }
+      else
+      {
+         pTransport = new SNMP_UDPTransport();
+         ((SNMP_UDPTransport *)pTransport)->createUDPTransport(ipAddr, port);
+      }
+
+
+      // Check for V3 USM
+      if (SnmpCheckV3CommSettings(pTransport, originalContext, testOids))
+      {
+         *version = SNMP_VERSION_3;
+         goto sucess;
+      }
 
 restart_check:
-       // Check current community first
-       if ((originalContext != NULL) && (originalContext->getSecurityModel() != SNMP_SECURITY_MODEL_USM))
-       {
-               DbgPrintf(5, _T("SnmpCheckCommSettings: trying version %d community '%hs'"), snmpVer, originalContext->getCommunity());
-               pTransport->setSecurityContext(new SNMP_SecurityContext(originalContext));
-      for(int i = 0; i < testOids->size(); i++)
+      // Check current community first
+      if ((originalContext != NULL) && (originalContext->getSecurityModel() != SNMP_SECURITY_MODEL_USM))
       {
-         if (SnmpGet(snmpVer, pTransport, testOids->get(i), NULL, 0, buffer, sizeof(buffer), 0) == SNMP_ERR_SUCCESS)
-                  {
-                          *version = snmpVer;
-                          return new SNMP_SecurityContext(originalContext);
-                  }
+         DbgPrintf(5, _T("SnmpCheckCommSettings: trying version %d community '%hs'"), snmpVer, originalContext->getCommunity());
+         pTransport->setSecurityContext(new SNMP_SecurityContext(originalContext));
+         for(int i = 0; i < testOids->size(); i++)
+         {
+            if (SnmpGet(snmpVer, pTransport, testOids->get(i), NULL, 0, buffer, sizeof(buffer), 0) == SNMP_ERR_SUCCESS)
+            {
+               *version = snmpVer;
+               goto sucess;
+            }
+         }
       }
-       }
 
-       // Check community from list
-   DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
-       DB_RESULT hResult = DBSelect(hdb, _T("SELECT community FROM snmp_communities"));
-       if (hResult != NULL)
-       {
-               char temp[256];
+      // Check community from list
+      DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
+      DB_RESULT hResult = DBSelect(hdb, _T("SELECT community FROM snmp_communities"));
+      if (hResult != NULL)
+      {
+         char temp[256];
 
-               count = DBGetNumRows(hResult);
-               for(i = 0; i < count; i++)
-               {
-                       DBGetFieldA(hResult, i, 0, temp, 256);
-         if ((originalContext == NULL) ||
-             (originalContext->getSecurityModel() == SNMP_SECURITY_MODEL_USM) ||
-             strcmp(temp, originalContext->getCommunity()))
+         count = DBGetNumRows(hResult);
+         for(i = 0; i < count; i++)
          {
-                          DbgPrintf(5, _T("SnmpCheckCommSettings: trying version %d community '%hs'"), snmpVer, temp);
-                          pTransport->setSecurityContext(new SNMP_SecurityContext(temp));
-            for(int j = 0; j < testOids->size(); j++)
+            DBGetFieldA(hResult, i, 0, temp, 256);
+            if ((originalContext == NULL) ||
+                (originalContext->getSecurityModel() == SNMP_SECURITY_MODEL_USM) ||
+                strcmp(temp, originalContext->getCommunity()))
             {
-               if (SnmpGet(snmpVer, pTransport, testOids->get(j), NULL, 0, buffer, sizeof(buffer), 0) == SNMP_ERR_SUCCESS)
-                   {
-                                  *version = snmpVer;
-                  goto stop_test;
+               DbgPrintf(5, _T("SnmpCheckCommSettings: trying version %d community '%hs'"), snmpVer, temp);
+               pTransport->setSecurityContext(new SNMP_SecurityContext(temp));
+               for(int j = 0; j < testOids->size(); j++)
+               {
+                  if (SnmpGet(snmpVer, pTransport, testOids->get(j), NULL, 0, buffer, sizeof(buffer), 0) == SNMP_ERR_SUCCESS)
+                  {
+                     *version = snmpVer;
+                     goto stop_test;
+                  }
                }
             }
          }
-               }
 stop_test:
-               DBFreeResult(hResult);
-      DBConnectionPoolReleaseConnection(hdb);
-               if (i < count)
-                       return new SNMP_SecurityContext(temp);
-       }
-       else
-       {
-      DBConnectionPoolReleaseConnection(hdb);
-               DbgPrintf(3, _T("SnmpCheckCommSettings: DBSelect() failed"));
-       }
-
-       if (snmpVer == SNMP_VERSION_2C)
-       {
-               snmpVer = SNMP_VERSION_1;
-               goto restart_check;
-       }
+         DBFreeResult(hResult);
+         DBConnectionPoolReleaseConnection(hdb);
+         if (i < count)
+         {
+            goto sucess;
+         }
+      }
+      else
+      {
+         DBConnectionPoolReleaseConnection(hdb);
+         DbgPrintf(3, _T("SnmpCheckCommSettings: DBSelect() failed"));
+      }
 
+      if (snmpVer == SNMP_VERSION_2C)
+      {
+         snmpVer = SNMP_VERSION_1;
+         goto restart_check;
+      }
+      delete pTransport;
+   }
+fail:
+   delete ports;
        DbgPrintf(5, _T("SnmpCheckCommSettings: failed"));
        return NULL;
+sucess:
+   delete ports;
+       return pTransport;
 }
index 62a9ee2..1125c0b 100644 (file)
@@ -907,7 +907,7 @@ void PerfDataStorageRequest(DCTable *dci, time_t timestamp, Table *value);
 
 void DecodeSQLStringAndSetVariable(NXCPMessage *pMsg, UINT32 dwVarId, TCHAR *pszStr);
 
-SNMP_SecurityContext *SnmpCheckCommSettings(SNMP_Transport *pTransport, INT16 *version, SNMP_SecurityContext *originalContext, StringList *customTestOids);
+SNMP_Transport *SnmpCheckCommSettings(UINT32 snmpProxy, const InetAddress& ipAddr, INT16 *version, UINT16 originalPort, SNMP_SecurityContext *originalContext, StringList *customTestOids);
 void StrToMac(const TCHAR *pszStr, BYTE *pBuffer);
 
 void InitLocalNetInfo();
index f9b75d3..2c720c2 100644 (file)
@@ -585,6 +585,7 @@ public:
                                SNMP_SecurityContext* (*contextFinder)(struct sockaddr *, socklen_t) = NULL);
    virtual int sendMessage(SNMP_PDU *pdu);
    virtual InetAddress getPeerIpAddress();
+   WORD getPort() { return m_port; }
 
    void setWaitForResponse(bool wait) { m_waitForResponse = wait; }
 };
index b7e4134..fb94c5c 100644 (file)
@@ -574,6 +574,17 @@ static bool ConvertObjectToolMacros(UINT32 id, const TCHAR *text, const TCHAR *c
 }
 
 /**
+ * Upgrade from V364 to V365
+ */
+static BOOL H_UpgradeFromV364(int currVersion, int newVersion)
+{
+   CHK_EXEC(CreateConfigParam(_T("SNMPPorts"), _T("161"), 0, 0));
+
+   CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='365' WHERE var_name='SchemaVersion'")));
+   return TRUE;
+}
+
+/**
  * Upgrade from V363 to V364
  */
 static BOOL H_UpgradeFromV363(int currVersion, int newVersion)
@@ -8924,6 +8935,7 @@ static struct
    { 361, 362, H_UpgradeFromV361 },
    { 362, 363, H_UpgradeFromV362 },
    { 363, 364, H_UpgradeFromV363 },
+   { 364, 365, H_UpgradeFromV364 },
    { 0, 0, NULL }
 };
 
index 1ce0415..fb4f6bb 100644 (file)
@@ -263,6 +263,7 @@ UINT32 SNMP_UDPTransport::createUDPTransport(const InetAddress& hostAddr, WORD p
    if (!hostAddr.isValid())
       return SNMP_ERR_HOSTNAME;
 
+   m_port=port;
    hostAddr.fillSockAddr(&m_peerAddr, port);
 
    UINT32 dwResult;
index 38daafa..c5cc52b 100644 (file)
@@ -68,10 +68,11 @@ public class SnmpCredentials extends ViewPart implements ISaveablePart
        public static final String ID = "org.netxms.ui.eclipse.snmp.views.SnmpCredentials"; //$NON-NLS-1$
 
        private boolean modified = false;
-    private FormToolkit toolkit;
-    private ScrolledForm form;
+       private FormToolkit toolkit;
+       private ScrolledForm form;
        private TableViewer snmpCommunityList;
        private TableViewer snmpUsmCredList;
+       private TableViewer snmpPortList;
        private Action actionSave;
        private SnmpConfig config;
 
@@ -100,6 +101,7 @@ public class SnmpCredentials extends ViewPart implements ISaveablePart
                
                createSnmpCommunitySection();
                createSnmpUsmCredSection();
+               createSnmpPortList();
                
                createActions();
                contributeToActionBars();
@@ -298,6 +300,67 @@ public class SnmpCredentials extends ViewPart implements ISaveablePart
                        }
                });
        }
+       
+         /**
+    * Create "Port List" section
+    */
+   private void createSnmpPortList()
+   {
+      Section section = toolkit.createSection(form.getBody(), Section.DESCRIPTION | Section.TITLE_BAR);
+      section.setText("SNMP Ports");
+      section.setDescription("SNMP ports used in the network");
+      TableWrapData td = new TableWrapData();
+      td.align = TableWrapData.FILL;
+      td.grabHorizontal = true;
+      section.setLayoutData(td);
+      
+      Composite clientArea = toolkit.createComposite(section);
+      GridLayout layout = new GridLayout();
+      layout.numColumns = 2;
+      clientArea.setLayout(layout);
+      section.setClient(clientArea);
+      
+      snmpPortList = new TableViewer(clientArea, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
+      toolkit.adapt(snmpPortList.getTable());
+      GridData gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      gd.verticalAlignment = SWT.FILL;
+      gd.grabExcessVerticalSpace = true;
+      gd.verticalSpan = 2;
+      gd.heightHint = 150;
+      snmpPortList.getTable().setLayoutData(gd);
+      snmpPortList.setContentProvider(new ArrayContentProvider());
+      snmpPortList.setComparator(new StringComparator());
+
+      final ImageHyperlink linkAdd = toolkit.createImageHyperlink(clientArea, SWT.NONE);
+      linkAdd.setText(Messages.get().SnmpConfigurator_Add);
+      linkAdd.setImage(SharedIcons.IMG_ADD_OBJECT);
+      gd = new GridData();
+      gd.verticalAlignment = SWT.TOP;
+      linkAdd.setLayoutData(gd);
+      linkAdd.addHyperlinkListener(new HyperlinkAdapter() {
+         @Override
+         public void linkActivated(HyperlinkEvent e)
+         {
+            addSnmpPort();
+         }
+      });
+      
+      final ImageHyperlink linkRemove = toolkit.createImageHyperlink(clientArea, SWT.NONE);
+      linkRemove.setText(Messages.get().SnmpConfigurator_Remove);
+      linkRemove.setImage(SharedIcons.IMG_DELETE_OBJECT);
+      gd = new GridData();
+      gd.verticalAlignment = SWT.TOP;
+      linkRemove.setLayoutData(gd);
+      linkRemove.addHyperlinkListener(new HyperlinkAdapter() {
+         @Override
+         public void linkActivated(HyperlinkEvent e)
+         {
+            removeSnmpPort();
+         }
+      });
+   }
 
        /* (non-Javadoc)
         * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
@@ -317,6 +380,7 @@ public class SnmpCredentials extends ViewPart implements ISaveablePart
                
                snmpCommunityList.setInput(config.getCommunities().toArray());
                snmpUsmCredList.setInput(config.getUsmCredentials().toArray());
+      snmpPortList.setInput(config.getPorts().toArray());
 
                modified = false;
                firePropertyChange(PROP_DIRTY);
@@ -488,4 +552,42 @@ public class SnmpCredentials extends ViewPart implements ISaveablePart
                        setModified();
                }
        }
+       
+         /**
+    * Add SNMP USM credentials to the list
+    */
+   private void addSnmpPort()
+   {
+      InputDialog dlg = new InputDialog(getSite().getShell(), "Add SNMP Port", 
+            "Please enter SNMP Port", "", null); //$NON-NLS-1$
+      if (dlg.open() == Window.OK)
+      {
+         String value = dlg.getValue();
+         final List<String> list = config.getPorts();
+         if (!list.contains(value))
+         {
+            list.add(value);
+            snmpPortList.setInput(list.toArray());
+            setModified();
+         }
+      }
+   }
+   
+   /**
+    * Remove selected SNMP USM credentials
+    */
+   private void removeSnmpPort()
+   {
+      final List<String> list = config.getPorts();
+      IStructuredSelection selection = (IStructuredSelection)snmpPortList.getSelection();
+      if (selection.size() > 0)
+      {
+         for(Object o : selection.toList())
+         {
+            list.remove(o);
+         }
+         snmpPortList.setInput(list.toArray());
+         setModified();
+      }
+   }
 }
index 8c9f23c..c6217ea 100644 (file)
@@ -1,9 +1,13 @@
 package org.netxms.ui.eclipse.snmp.views.helpers;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 import org.netxms.client.NXCException;
 import org.netxms.client.NXCSession;
+import org.netxms.client.server.ServerVariable;
 import org.netxms.client.snmp.SnmpUsmCredential;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 
@@ -11,6 +15,7 @@ public class SnmpConfig
 {
    private List<String> communities;
    private List<SnmpUsmCredential> usmCredentials;
+   private List<String> ports;
 
    /**
     * Create empty object
@@ -33,11 +38,38 @@ public class SnmpConfig
       
       config.communities = session.getSnmpCommunities();
       config.usmCredentials = session.getSnmpUsmCredentials();
-      
+      Map<String, ServerVariable> variables = session.getServerVariables();
+      ServerVariable v = variables.get("SNMPPorts");
+      config.ports = parsePorts(v != null ? v.getValue() : "" );
+
       return config;
    }
    
    /**
+    * 
+    * @param portList
+    */
+   public static List<String> parsePorts(String portList)
+   {
+      String[] arr = portList.split(",");
+      List<String> list = new ArrayList<String>(Arrays.asList(arr));
+      return list;      
+   }
+   
+   public String parsePorts() 
+   {
+      StringBuilder str = new StringBuilder();
+      for(int i = 0; i < ports.size(); i++)
+      {
+         str.append(ports.get(i));
+         if(i != ports.size() - 1)
+         {
+            str.append(",");            
+         }
+      }
+      return str.toString();
+   }
+   /**
     * Save SNMP configuration on server. This method calls communication
     * API directly, so it should not be called from UI thread.
     * 
@@ -50,6 +82,7 @@ public class SnmpConfig
       
       session.updateSnmpCommunities(communities);
       session.updateSnmpUsmCredentials(usmCredentials);
+      session.setServerVariable("SNMPPorts", parsePorts());
    }
    
    /**
@@ -67,6 +100,22 @@ public class SnmpConfig
    {
       this.communities = communities;
    }
+   
+   /**
+    * @return the ports
+    */
+   public List<String> getPorts()
+   {
+      return ports;
+   }
+   
+   /**
+    * @param communities the communities to set
+    */
+   public void setPorts(List<String> ports)
+   {
+      this.ports = ports;
+   }
 
    /**
     * @return the usmCredentials