network device database - initial implementation
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 25 Apr 2017 12:15:12 +0000 (15:15 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 25 Apr 2017 21:15:30 +0000 (00:15 +0300)
ChangeLog
include/netxmsdb.h
sql/dbinit.in
sql/devdb.in [new file with mode: 0644]
sql/schema.in
src/server/core/Makefile.am
src/server/core/devdb.cpp [new file with mode: 0644]
src/server/core/node.cpp
src/server/include/nms_core.h
src/server/tools/nxdbmgr/upgrade.cpp

index aa1c2d9..9ccbc80 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@
 - External tables in agent
 - Script source for table DCIs
 - Driver for IgniteNet devices
+- Network device database (allows some device specific information to be provided without drivers)
 - Management console:
        - Node's zone name shown in alarm browser and object overview when zoning is enabled
 - Fixed issues: NX-1222, NX-1239
index c7cd4a8..68147be 100644 (file)
@@ -23,6 +23,6 @@
 #ifndef _netxmsdb_h
 #define _netxmsdb_h
 
-#define DB_FORMAT_VERSION   446
+#define DB_FORMAT_VERSION   447
 
 #endif
index bc3cbe6..e1812e5 100644 (file)
@@ -34,6 +34,7 @@ BEGIN TRANSACTION;
 #include "images.in"
 #include "country_codes.in"
 #include "currency_codes.in"
+#include "devdb.in"
 #endif
 
 // End transaction
diff --git a/sql/devdb.in b/sql/devdb.in
new file mode 100644 (file)
index 0000000..c9b5671
--- /dev/null
@@ -0,0 +1,7 @@
+/*
+** Device database
+**
+** ex: syntax=sql
+*/
+
+INSERT INTO port_layouts (device_oid,numbering_scheme,row_count) VALUES ('.1.3.6.1','4','2');
index f61923b..9508813 100644 (file)
@@ -1646,9 +1646,9 @@ CREATE TABLE zmq_subscription
   PRIMARY KEY(object_id, subscription_type)
 ) TABLE_TYPE;
 
-/*
-** Currency codes
-*/
+/**
+ * Currency codes
+ */
 CREATE TABLE currency_codes
 (
        numeric_code char(3) not null,
@@ -1658,9 +1658,9 @@ CREATE TABLE currency_codes
        PRIMARY KEY(numeric_code)
 ) TABLE_TYPE;
 
-/*
-** Country codes
-*/
+/**
+ * Country codes
+ */
 CREATE TABLE country_codes
 (
        numeric_code char(3) not null,
@@ -1670,9 +1670,9 @@ CREATE TABLE country_codes
        PRIMARY KEY(numeric_code)
 ) TABLE_TYPE;
 
-/*
-** Config repositories
-*/
+/**
+ * Config repositories
+ */
 CREATE TABLE config_repositories
 (
        id integer not null,
@@ -1682,3 +1682,14 @@ CREATE TABLE config_repositories
        PRIMARY KEY(id)
 ) TABLE_TYPE;
 
+/**
+ * Network equipment port layouts
+ */
+CREATE TABLE port_layouts
+(
+   device_oid varchar(255) not null,
+   numbering_scheme char(1) not null,
+   row_count char(1) not null,
+   layout_data varchar(4000) null,
+   PRIMARY KEY(device_oid)
+) TABLE_TYPE;
index 51ad8fc..0ca53cf 100644 (file)
@@ -13,7 +13,7 @@ libnxcore_la_SOURCES =  accesspoint.cpp acl.cpp actions.cpp addrlist.cpp \
                        container.cpp correlate.cpp dashboard.cpp datacoll.cpp dbwrite.cpp \
                        dc_nxsl.cpp dcitem.cpp dcithreshold.cpp dcivalue.cpp \
                        dcobject.cpp dcst.cpp dctable.cpp dctarget.cpp \
-                       dctcolumn.cpp dctthreshold.cpp debug.cpp dfile_info.cpp \
+                       dctcolumn.cpp dctthreshold.cpp debug.cpp devdb.cpp dfile_info.cpp \
                        download_job.cpp ef.cpp email.cpp entirenet.cpp \
                        epp.cpp events.cpp evproc.cpp fdb.cpp \
                        filemonitoring.cpp graph.cpp hdlink.cpp hk.cpp id.cpp \
diff --git a/src/server/core/devdb.cpp b/src/server/core/devdb.cpp
new file mode 100644 (file)
index 0000000..5416ecc
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+** NetXMS - Network Management System
+** Copyright (C) 2003-2017 Raden Solutions
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: devdb.cpp
+**/
+
+#include "nxcore.h"
+
+/**
+ * Lookup device port layout in database
+ */
+bool LookupDevicePortLayout(const SNMP_ObjectId& objectId, NDD_MODULE_LAYOUT *layout)
+{
+   bool success = false;
+   DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
+   DB_STATEMENT hStmt = DBPrepare(hdb, _T("SELECT numbering_scheme,row_count,layout_data FROM port_layouts WHERE device_oid=?"));
+   if (hStmt != NULL)
+   {
+      DBBind(hStmt, 1, DB_SQLTYPE_VARCHAR, objectId.toString(), DB_BIND_TRANSIENT);
+      DB_RESULT hResult = DBSelectPrepared(hStmt);
+      if (hResult != NULL)
+      {
+         if (DBGetNumRows(hResult) > 0)
+         {
+            layout->numberingScheme = DBGetFieldLong(hResult, 0, 0);
+            layout->rows = DBGetFieldLong(hResult, 0, 1);
+            if (layout->numberingScheme == NDD_PN_CUSTOM)
+            {
+               // TODO: custom layout parsing
+            }
+            nxlog_debug(5, _T("Successful port layout lookup for device %s: scheme=%d rows=%d"),
+                     (const TCHAR *)objectId.toString(), layout->numberingScheme, layout->rows);
+            success = true;
+         }
+         DBFreeResult(hResult);
+      }
+      DBFreeStatement(hStmt);
+   }
+   DBConnectionPoolReleaseConnection(hdb);
+   return success;
+}
index c2fa685..e0051c9 100644 (file)
@@ -2733,6 +2733,11 @@ bool Node::confPollSnmp(UINT32 dwRqId)
    m_driver->analyzeDevice(pTransport, m_szObjectId, &m_customAttributes, &m_driverData);
    NDD_MODULE_LAYOUT layout;
    m_driver->getModuleLayout(pTransport, &m_customAttributes, m_driverData, 1, &layout); // TODO module set to 1
+   if (layout.numberingScheme == NDD_PN_UNKNOWN)
+   {
+      // Try to find port numbering information in database
+      LookupDevicePortLayout(SNMP_ObjectId::parse(m_szObjectId), &layout);
+   }
    m_portRowCount = layout.rows;
    m_portNumberingScheme = layout.numberingScheme;
 
index 5a104e2..6e2cf25 100644 (file)
@@ -1076,6 +1076,8 @@ NetworkDeviceDriver *FindDriverForNode(Node *node, SNMP_Transport *pTransport);
 NetworkDeviceDriver *FindDriverByName(const TCHAR *name);
 void AddDriverSpecificOids(StringList *list);
 
+bool LookupDevicePortLayout(const SNMP_ObjectId& objectId, NDD_MODULE_LAYOUT *layout);
+
 void CheckForMgmtNode();
 Node NXCORE_EXPORTABLE *PollNewNode(const InetAddress& ipAddr, UINT32 creationFlags, UINT16 agentPort,
                                     UINT16 snmpPort, const TCHAR *name, UINT32 agentProxyId, UINT32 snmpProxyId,
index 9961235..04f9925 100644 (file)
@@ -747,6 +747,23 @@ static bool SetSchemaVersion(int version)
 }
 
 /**
+ * Upgrade from V446 to V447
+ */
+static BOOL H_UpgradeFromV446(int currVersion, int newVersion)
+{
+   CHK_EXEC(CreateTable(
+      _T("CREATE TABLE port_layouts (")
+      _T("  device_oid varchar(255) not null,")
+      _T("  numbering_scheme char(1) not null,")
+      _T("  row_count char(1) not null,")
+      _T("  layout_data varchar(4000) null,")
+      _T("PRIMARY KEY(device_oid))")));
+
+   CHK_EXEC(SetSchemaVersion(447));
+   return TRUE;
+}
+
+/**
  * Upgrade from V445 to V446
  */
 static BOOL H_UpgradeFromV445(int currVersion, int newVersion)
@@ -786,7 +803,6 @@ static BOOL H_UpgradeFromV445(int currVersion, int newVersion)
       DBFreeResult(hResult);
    }
 
-
    CHK_EXEC(SetSchemaVersion(446));
    return TRUE;
 }
@@ -11660,6 +11676,7 @@ static struct
    { 443, 444, H_UpgradeFromV443 },
    { 444, 445, H_UpgradeFromV444 },
    { 445, 446, H_UpgradeFromV445 },
+   { 446, 447, H_UpgradeFromV446 },
    { 0, 0, NULL }
 };