unadopted access points created under wireless switch; events for AP state change...
authorVictor Kirhenshtein <victor@netxms.org>
Sat, 10 May 2014 15:41:17 +0000 (18:41 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Sat, 10 May 2014 15:41:17 +0000 (18:41 +0300)
12 files changed:
include/netxmsdb.h
include/nxevent.h
sql/events.in
sql/schema.in
src/java/netxms-client/src/main/java/org/netxms/client/constants/AccessPointState.java [new file with mode: 0644]
src/java/netxms-client/src/main/java/org/netxms/client/objects/AccessPoint.java
src/java/netxms-eclipse/ObjectView/src/org/netxms/ui/eclipse/objectview/objecttabs/elements/GeneralInfo.java
src/server/core/accesspoint.cpp
src/server/core/node.cpp
src/server/include/nms_objects.h
src/server/tools/nxdbmgr/upgrade.cpp
webui/webapp/ObjectView/src/org/netxms/ui/eclipse/objectview/objecttabs/elements/GeneralInfo.java

index 3155932..3535821 100644 (file)
@@ -23,6 +23,6 @@
 #ifndef _netxmsdb_h
 #define _netxmsdb_h
 
-#define DB_FORMAT_VERSION   315
+#define DB_FORMAT_VERSION   316
 
 #endif
index 2ee47f2..6d2dfe8 100644 (file)
 #define EVENT_TABLE_THRESHOLD_ACTIVATED   69
 #define EVENT_TABLE_THRESHOLD_DEACTIVATED 70
 #define EVENT_IF_PEER_CHANGED             71
+#define EVENT_AP_ADOPTED                  72
+#define EVENT_AP_UNADOPTED                73
 
 #define EVENT_SNMP_UNMATCHED_TRAP         500
 #define EVENT_SNMP_COLD_START             501
index 37600c7..8655884 100644 (file)
@@ -821,6 +821,36 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   12) Peer interface MAC address' CONCAT CRLF CONCAT
       '   13) Discovery protocol'
        );
+INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+       (
+               EVENT_AP_ADOPTED, 'SYS_AP_ADOPTED',
+               EVENT_SEVERITY_NORMAL, 1,
+               'Access point %2 changed state to ADOPTED',
+               'Generated when access point state changes to ADOPTED.' CONCAT CRLF CONCAT
+               'Parameters:' CONCAT CRLF CONCAT
+               '    1) Access point object ID' CONCAT CRLF CONCAT
+               '    2) Access point name' CONCAT CRLF CONCAT
+               '    3) Access point MAC address' CONCAT CRLF CONCAT
+               '    4) Access point IP address' CONCAT CRLF CONCAT
+               '    5) Access point vendor name' CONCAT CRLF CONCAT
+               '    6) Access point model' CONCAT CRLF CONCAT
+               '    7) Access point serial number'
+       );
+INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+       (
+               EVENT_AP_ADOPTED, 'SYS_AP_UNADOPTED',
+               EVENT_SEVERITY_MAJOR, 1,
+               'Access point %2 changed state to UNADOPTED',
+               'Generated when access point state changes to UNADOPTED.' CONCAT CRLF CONCAT
+               'Parameters:' CONCAT CRLF CONCAT
+               '    1) Access point object ID' CONCAT CRLF CONCAT
+               '    2) Access point name' CONCAT CRLF CONCAT
+               '    3) Access point MAC address' CONCAT CRLF CONCAT
+               '    4) Access point IP address' CONCAT CRLF CONCAT
+               '    5) Access point vendor name' CONCAT CRLF CONCAT
+               '    6) Access point model' CONCAT CRLF CONCAT
+               '    7) Access point serial number'
+       );
 
 /*
 ** SNMP traps
index d4bbb54..724e05a 100644 (file)
@@ -185,11 +185,9 @@ CREATE TABLE zones
        PRIMARY KEY(id)
 ) TABLE_TYPE;
 
-
 /*
 ** Mobile device objects
 */
-
 CREATE TABLE mobile_devices
 (
        id integer not null,
@@ -204,11 +202,9 @@ CREATE TABLE mobile_devices
        PRIMARY KEY(id)
 ) TABLE_TYPE;
 
-
 /*
 ** Access point objects
 */
-
 CREATE TABLE access_points
 (
        id integer not null,
@@ -217,14 +213,13 @@ CREATE TABLE access_points
        vendor varchar(64) null,
        model varchar(128) null,
        serial_number varchar(64) null,
+   ap_state integer not null,
        PRIMARY KEY(id)
 ) TABLE_TYPE;
 
-
 /*
 ** Rack objects
 */
-
 CREATE TABLE racks
 (
        id integer not null,
@@ -232,11 +227,9 @@ CREATE TABLE racks
        PRIMARY KEY(id)
 ) TABLE_TYPE;
 
-
 /*
 ** Nodes information
 */
-
 CREATE TABLE nodes
 (
        id integer not null,
diff --git a/src/java/netxms-client/src/main/java/org/netxms/client/constants/AccessPointState.java b/src/java/netxms-client/src/main/java/org/netxms/client/constants/AccessPointState.java
new file mode 100644 (file)
index 0000000..b0c744a
--- /dev/null
@@ -0,0 +1,74 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2014 Victor Kirhenshtein
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.netxms.client.constants;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.netxms.base.Logger;
+
+/**
+ * Access point state
+ */
+public enum AccessPointState
+{
+   ADOPTED(0),
+   UNADOPTED(1);
+
+   private int value;
+   private static Map<Integer, AccessPointState> lookupTable = new HashMap<Integer, AccessPointState>();
+
+   static
+   {
+      for(AccessPointState element : AccessPointState.values())
+      {
+         lookupTable.put(element.value, element);
+      }
+   }
+
+   /**
+    * @param value
+    */
+   private AccessPointState(int value)
+   {
+      this.value = value;
+   }
+
+   /**
+    * @return
+    */
+   public int getValue()
+   {
+      return value;
+   }
+
+   /**
+    * @param value
+    * @return
+    */
+   public static AccessPointState getByValue(int value)
+   {
+      final AccessPointState element = lookupTable.get(value);
+      if (element == null)
+      {
+         Logger.warning(AccessPointState.class.getName(), "Unknown element " + value);
+         return ADOPTED; // fallback
+      }
+      return element;
+   }
+}
index d70c14b..ce324a0 100644 (file)
@@ -7,6 +7,7 @@ import org.netxms.base.NXCPCodes;
 import org.netxms.base.NXCPMessage;
 import org.netxms.client.MacAddress;
 import org.netxms.client.NXCSession;
+import org.netxms.client.constants.AccessPointState;
 import org.netxms.client.topology.RadioInterface;
 
 /**
@@ -16,6 +17,7 @@ public class AccessPoint extends GenericObject
 {
        private long nodeId;
        private MacAddress macAddress;
+   private AccessPointState state;
        private String vendor;
        private String model;
        private String serialNumber;
@@ -30,6 +32,7 @@ public class AccessPoint extends GenericObject
                super(msg, session);
                nodeId = msg.getVariableAsInt64(NXCPCodes.VID_NODE_ID);
                macAddress = new MacAddress(msg.getVariableAsBinary(NXCPCodes.VID_MAC_ADDR));
+               state = AccessPointState.getByValue(msg.getVariableAsInteger(NXCPCodes.VID_STATE));
                vendor = msg.getVariableAsString(NXCPCodes.VID_VENDOR);
                model = msg.getVariableAsString(NXCPCodes.VID_MODEL);
                serialNumber = msg.getVariableAsString(NXCPCodes.VID_SERIAL_NUMBER);
@@ -109,4 +112,12 @@ public class AccessPoint extends GenericObject
        {
                return radios;
        }
+
+   /**
+    * @return the state
+    */
+   public AccessPointState getState()
+   {
+      return state;
+   }
 }
index dc2d27f..8bf99c4 100644 (file)
@@ -128,6 +128,7 @@ public class GeneralInfo extends TableElement
                                break;
                        case AbstractObject.OBJECT_ACCESSPOINT:
                                AccessPoint ap = (AccessPoint)object;
+            addPair("State", ap.getState().toString());
                                addPair(Messages.get().GeneralInfo_Vendor, ap.getVendor());
                                addPair(Messages.get().GeneralInfo_Model, ap.getModel());
                                addPair(Messages.get().GeneralInfo_Serial, ap.getSerialNumber());
index 4ef9b17..abdf54e 100644 (file)
@@ -32,6 +32,7 @@ AccessPoint::AccessPoint() : DataCollectionTarget()
        m_model = NULL;
        m_serialNumber = NULL;
        m_radioInterfaces = NULL;
+   m_state = AP_ADOPTED;
 }
 
 /**
@@ -45,6 +46,7 @@ AccessPoint::AccessPoint(const TCHAR *name, BYTE *macAddr) : DataCollectionTarge
        m_model = NULL;
        m_serialNumber = NULL;
        m_radioInterfaces = NULL;
+   m_state = AP_ADOPTED;
        m_isHidden = true;
 }
 
@@ -73,7 +75,7 @@ BOOL AccessPoint::CreateFromDB(UINT32 dwId)
    }
 
        TCHAR query[256];
-       _sntprintf(query, 256, _T("SELECT mac_address,vendor,model,serial_number,node_id FROM access_points WHERE id=%d"), (int)m_dwId);
+       _sntprintf(query, 256, _T("SELECT mac_address,vendor,model,serial_number,node_id,ap_state FROM access_points WHERE id=%d"), (int)m_dwId);
        DB_RESULT hResult = DBSelect(g_hCoreDB, query);
        if (hResult == NULL)
                return FALSE;
@@ -83,6 +85,7 @@ BOOL AccessPoint::CreateFromDB(UINT32 dwId)
        m_model = DBGetField(hResult, 0, 2, NULL, 0);
        m_serialNumber = DBGetField(hResult, 0, 3, NULL, 0);
        UINT32 nodeId = DBGetFieldULong(hResult, 0, 4);
+   m_state = (DBGetFieldLong(hResult, 0, 5) == AP_ADOPTED) ? AP_ADOPTED : AP_UNADOPTED;
        DBFreeResult(hResult);
 
    // Load DCI and access list
@@ -133,9 +136,9 @@ BOOL AccessPoint::SaveToDB(DB_HANDLE hdb)
    BOOL bResult;
        DB_STATEMENT hStmt;
    if (IsDatabaseRecordExist(hdb, _T("access_points"), _T("id"), m_dwId))
-               hStmt = DBPrepare(hdb, _T("UPDATE access_points SET mac_address=?,vendor=?,model=?,serial_number=?,node_id=? WHERE id=?"));
+               hStmt = DBPrepare(hdb, _T("UPDATE access_points SET mac_address=?,vendor=?,model=?,serial_number=?,node_id=?,ap_state=? WHERE id=?"));
        else
-               hStmt = DBPrepare(hdb, _T("INSERT INTO access_points (mac_address,vendor,model,serial_number,node_id,id) VALUES (?,?,?,?,?,?)"));
+               hStmt = DBPrepare(hdb, _T("INSERT INTO access_points (mac_address,vendor,model,serial_number,node_id,ap_state,id) VALUES (?,?,?,?,?,?,?)"));
        if (hStmt != NULL)
        {
                TCHAR macStr[16];
@@ -144,7 +147,8 @@ BOOL AccessPoint::SaveToDB(DB_HANDLE hdb)
                DBBind(hStmt, 3, DB_SQLTYPE_VARCHAR, CHECK_NULL_EX(m_model), DB_BIND_STATIC);
                DBBind(hStmt, 4, DB_SQLTYPE_VARCHAR, CHECK_NULL_EX(m_serialNumber), DB_BIND_STATIC);
                DBBind(hStmt, 5, DB_SQLTYPE_INTEGER, m_nodeId);
-               DBBind(hStmt, 6, DB_SQLTYPE_INTEGER, m_dwId);
+               DBBind(hStmt, 6, DB_SQLTYPE_INTEGER, (INT32)m_state);
+               DBBind(hStmt, 7, DB_SQLTYPE_INTEGER, m_dwId);
 
                bResult = DBExecute(hStmt);
 
@@ -197,6 +201,7 @@ void AccessPoint::CreateMessage(CSCPMessage *msg)
        msg->SetVariable(VID_VENDOR, CHECK_NULL_EX(m_vendor));
        msg->SetVariable(VID_MODEL, CHECK_NULL_EX(m_model));
        msg->SetVariable(VID_SERIAL_NUMBER, CHECK_NULL_EX(m_serialNumber));
+   msg->SetVariable(VID_STATE, (UINT16)m_state);
 
    if (m_radioInterfaces != NULL)
    {
@@ -342,3 +347,23 @@ void AccessPoint::updateInfo(const TCHAR *vendor, const TCHAR *model, const TCHA
        Modify();
        UnlockData();
 }
+
+/**
+ * Update access point state
+ */
+void AccessPoint::updateState(AccessPointState state)
+{
+   if (state == m_state)
+      return;
+
+       LockData();
+   m_state = state;
+   if (m_iStatus != STATUS_UNMANAGED)
+      m_iStatus = (state == AP_ADOPTED) ? STATUS_NORMAL : STATUS_MAJOR;
+   Modify();
+       UnlockData();
+
+   static const TCHAR *names[] = { _T("id"), _T("name"), _T("macAddr"), _T("ipAddr"), _T("vendor"), _T("model"), _T("serialNumber") };
+   PostEventWithNames((state == AP_ADOPTED) ? EVENT_AP_ADOPTED : EVENT_AP_UNADOPTED, m_nodeId, "ishasss", names,
+      m_dwId, m_szName, m_macAddr, m_dwIpAddr, CHECK_NULL_EX(m_vendor), CHECK_NULL_EX(m_model), CHECK_NULL_EX(m_serialNumber));
+}
index 963f56b..99b74fa 100644 (file)
@@ -1312,7 +1312,6 @@ restart_agent_check:
                }
        }
 
-
    // Get uptime and update boot time
    if (!(m_dwDynamicFlags & NDF_UNREACHABLE))
    {
@@ -2314,10 +2313,9 @@ bool Node::confPollSnmp(UINT32 dwRqId)
                                for(int i = 0; i < aps->size(); i++)
                                {
                                        AccessPointInfo *info = aps->get(i);
-                                       if (info->getState() != AP_ADOPTED)
-                                               continue;
+                                       if (info->getState() == AP_ADOPTED)
+                                       adopted++;
 
-                                       adopted++;
                                        AccessPoint *ap = FindAccessPointByMAC(info->getMacAddr());
                                        if (ap == NULL)
                                        {
@@ -2341,9 +2339,13 @@ bool Node::confPollSnmp(UINT32 dwRqId)
                                                DbgPrintf(5, _T("ConfPoll(%s): created new access point object %s [%d]"), m_szName, ap->Name(), ap->Id());
                                        }
                                        ap->attachToNode(m_dwId);
-                                       ap->updateRadioInterfaces(info->getRadioInterfaces());
-                                       ap->updateInfo(NULL, info->getModel(), info->getSerial());
+                                       if (info->getState() == AP_ADOPTED)
+               {
+                                          ap->updateRadioInterfaces(info->getRadioInterfaces());
+                                          ap->updateInfo(NULL, info->getModel(), info->getSerial());
+               }
                                        ap->unhide();
+               ap->updateState(info->getState());
                                }
 
                                LockData();
index 83fa716..55ac070 100644 (file)
@@ -844,6 +844,7 @@ protected:
        TCHAR *m_model;
        TCHAR *m_serialNumber;
        ObjectArray<RadioInterfaceInfo> *m_radioInterfaces;
+   AccessPointState m_state;
 
 public:
    AccessPoint();
@@ -862,10 +863,12 @@ public:
        BYTE *getMacAddr() { return m_macAddr; }
        bool isMyRadio(int rfIndex);
        void getRadioName(int rfIndex, TCHAR *buffer, size_t bufSize);
+   AccessPointState getState() { return m_state; }
 
        void attachToNode(UINT32 nodeId);
        void updateRadioInterfaces(ObjectArray<RadioInterfaceInfo> *ri);
        void updateInfo(const TCHAR *vendor, const TCHAR *model, const TCHAR *serialNumber);
+   void updateState(AccessPointState state);
 };
 
 /**
index 15d7c15..287d442 100644 (file)
@@ -360,6 +360,45 @@ static BOOL RecreateTData(const TCHAR *className, bool multipleTables)
 }
 
 /**
+ * Upgrade from V315 to V316
+ */
+static BOOL H_UpgradeFromV315(int currVersion, int newVersion)
+{
+   static TCHAR batch[] =
+      _T("ALTER TABLE access_points ADD ap_state integer\n")
+      _T("UPDATE access_points SET ap_state=0\n")
+      _T("<END>");
+   CHK_EXEC(SQLBatch(batch));
+
+   CHK_EXEC(CreateEventTemplate(EVENT_AP_ADOPTED, _T("SYS_AP_ADOPTED"), SEVERITY_NORMAL, EF_LOG,
+      _T("Access point %2 changed state to ADOPTED"),
+               _T("Generated when access point state changes to ADOPTED.\r\n")
+               _T("Parameters:\r\n")
+               _T("    1) Access point object ID\r\n")
+               _T("    2) Access point name\r\n")
+               _T("    3) Access point MAC address\r\n")
+               _T("    4) Access point IP address\r\n")
+               _T("    5) Access point vendor name\r\n")
+               _T("    6) Access point model\r\n")
+               _T("    7) Access point serial number")));
+
+   CHK_EXEC(CreateEventTemplate(EVENT_AP_UNADOPTED, _T("SYS_AP_UNADOPTED"), SEVERITY_MAJOR, EF_LOG,
+      _T("Access point %2 changed state to UNADOPTED"),
+               _T("Generated when access point state changes to UNADOPTED.\r\n")
+               _T("Parameters:\r\n")
+               _T("    1) Access point object ID\r\n")
+               _T("    2) Access point name\r\n")
+               _T("    3) Access point MAC address\r\n")
+               _T("    4) Access point IP address\r\n")
+               _T("    5) Access point vendor name\r\n")
+               _T("    6) Access point model\r\n")
+               _T("    7) Access point serial number")));
+
+   CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='316' WHERE var_name='SchemaVersion'")));
+   return TRUE;
+}
+
+/**
  * Upgrade from V314 to V315
  */
 static BOOL H_UpgradeFromV314(int currVersion, int newVersion)
@@ -7624,6 +7663,7 @@ static struct
    { 312, 313, H_UpgradeFromV312 },
    { 313, 314, H_UpgradeFromV313 },
    { 314, 315, H_UpgradeFromV314 },
+   { 315, 316, H_UpgradeFromV315 },
    { 0, 0, NULL }
 };
 
index dc2d27f..8bf99c4 100644 (file)
@@ -128,6 +128,7 @@ public class GeneralInfo extends TableElement
                                break;
                        case AbstractObject.OBJECT_ACCESSPOINT:
                                AccessPoint ap = (AccessPoint)object;
+            addPair("State", ap.getState().toString());
                                addPair(Messages.get().GeneralInfo_Vendor, ap.getVendor());
                                addPair(Messages.get().GeneralInfo_Model, ap.getModel());
                                addPair(Messages.get().GeneralInfo_Serial, ap.getSerialNumber());