new internal parameters to access counters for received SNMP traps and syslog messages
authorVictor Kirhenshtein <victor@netxms.org>
Fri, 1 Jul 2016 15:07:42 +0000 (18:07 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Fri, 1 Jul 2016 15:07:42 +0000 (18:07 +0300)
ChangeLog
include/netxmsdb.h
sql/schema.in
src/java/netxms-eclipse/DataCollection/src/org/netxms/ui/eclipse/datacollection/dialogs/SelectInternalParamDlg.java
src/server/core/netobj.cpp
src/server/core/node.cpp
src/server/core/snmptrap.cpp
src/server/core/syslogd.cpp
src/server/include/nms_objects.h
src/server/tools/nxdbmgr/upgrade.cpp
webui/webapp/DataCollection/src/org/netxms/ui/eclipse/datacollection/dialogs/SelectInternalParamDlg.java

index 594eb16..5a0572d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,7 @@
 - Fixed memory leak in postgreSQL database driver
 - New attributes "source" and "sourceId" in NXSL class "Event"
 - New method toJson() in NXSL class "Event"
+- New internal parameters: Server.ReceivedSNMPTraps, Server.ReceivedSyslogMessages, ReceivedSNMPTraps, ReceivedSyslogMessages
 - Management console
        - New editors for Agent Config Policy and Log Parser Policy. 
        - DCI summary tables with empty menu path not shown in object context menu
index a559432..e60fbfe 100644 (file)
@@ -23,6 +23,6 @@
 #ifndef _netxmsdb_h
 #define _netxmsdb_h
 
-#define DB_FORMAT_VERSION   405
+#define DB_FORMAT_VERSION   406
 
 #endif
index 986b507..0fcfdac 100644 (file)
@@ -414,6 +414,8 @@ CREATE TABLE nodes
   rack_id integer not null,
   agent_cache_mode char(1) not null,
   last_agent_comm_time integer not null,
+  syslog_msg_count SQL_INT64 not null,
+  snmp_trap_count SQL_INT64 not null,
   PRIMARY KEY(id)
 ) TABLE_TYPE;
 
@@ -457,6 +459,8 @@ COMMENT_COLUMN(nodes.rack_height, '')
 COMMENT_COLUMN(nodes.rack_id, '')
 COMMENT_COLUMN(nodes.agent_cache_mode, '')
 COMMENT_COLUMN(nodes.last_agent_comm_time, '')
+COMMENT_COLUMN(nodes.syslog_msg_count, 'Total number of received syslog messages')
+COMMENT_COLUMN(nodes.snmp_trap_count, 'Total number of received SNMP traps')
 
 /*
 ** Clusters information
index 971b91b..d2db9d3 100644 (file)
@@ -56,6 +56,8 @@ public class SelectInternalParamDlg extends AbstractSelectParamDlg
                {
                        list.add(new AgentParameter("Net.IP.NextHop(*)", Messages.get().SelectInternalParamDlg_DCI_NextHop, DataCollectionItem.DT_STRING)); //$NON-NLS-1$
          list.add(new AgentParameter("NetSvc.ResponseTime(*)", "Network service {instance} response time", DataCollectionItem.DT_UINT)); //$NON-NLS-1$
+         list.add(new AgentParameter("ReceivedSNMPTraps", "Total SNMP traps received", DataCollectionItem.DT_UINT64)); //$NON-NLS-1$
+         list.add(new AgentParameter("ReceivedSyslogMessages", "Total syslog messages received", DataCollectionItem.DT_UINT64)); //$NON-NLS-1$
                }
                
                if ((object instanceof Template) || ((object instanceof AbstractNode) && ((AbstractNode)object).hasAgent()))
@@ -81,6 +83,8 @@ public class SelectInternalParamDlg extends AbstractSelectParamDlg
          list.add(new AgentParameter("Server.DBWriter.Requests.IData", "DB writer requests (DCI data)", DataCollectionItem.DT_UINT64)); //$NON-NLS-1$
          list.add(new AgentParameter("Server.DBWriter.Requests.Other", "DB writer requests (other queries)", DataCollectionItem.DT_UINT64)); //$NON-NLS-1$
          list.add(new AgentParameter("Server.DBWriter.Requests.RawData", "DB writer requests (raw DCI data)", DataCollectionItem.DT_UINT64)); //$NON-NLS-1$
+         list.add(new AgentParameter("Server.ReceivedSNMPTraps", "SNMP traps received since server start", DataCollectionItem.DT_UINT64)); //$NON-NLS-1$
+         list.add(new AgentParameter("Server.ReceivedSyslogMessages", "Syslog messages received since server start", DataCollectionItem.DT_UINT64)); //$NON-NLS-1$
          list.add(new AgentParameter("Server.ThreadPool.ActiveRequests(*)", "Thread pool {instance}: active requests", DataCollectionItem.DT_INT)); //$NON-NLS-1$
          list.add(new AgentParameter("Server.ThreadPool.CurrSize(*)", "Thread pool {instance}: current size", DataCollectionItem.DT_INT)); //$NON-NLS-1$
          list.add(new AgentParameter("Server.ThreadPool.Load(*)", "Thread pool {instance}: current load", DataCollectionItem.DT_INT)); //$NON-NLS-1$
index ed103b1..07bd52b 100644 (file)
@@ -1073,7 +1073,7 @@ static void BroadcastObjectChange(ClientSession *pSession, void *pArg)
  * Mark object as modified and put on client's notification queue
  * We assume that object is locked at the time of function call
  */
-void NetObj::setModified()
+void NetObj::setModified(bool notify)
 {
    if (g_bModificationsLocked)
       return;
@@ -1082,7 +1082,7 @@ void NetObj::setModified()
    m_dwTimeStamp = (UINT32)time(NULL);
 
    // Send event to all connected clients
-   if (!m_isHidden && !m_isSystem)
+   if (notify && !m_isHidden && !m_isSystem)
       EnumerateClientSessions(BroadcastObjectChange, this);
 }
 
index 23b1dce..0dd3b87 100644 (file)
 
 #include "nxcore.h"
 
+/**
+ * Externals
+ */
+extern UINT64 g_syslogMessagesReceived;
+extern UINT64 g_snmpTrapsReceived;
+
 /**
  * Node class default constructor
  */
@@ -106,6 +112,8 @@ Node::Node() : DataCollectionTarget()
        m_rackId = 0;
        m_rackPosition = 0;
        m_rackHeight = 1;
+       m_syslogMessageCount = 0;
+       m_snmpTrapCount = 0;
 }
 
 /**
@@ -195,6 +203,8 @@ Node::Node(const InetAddress& addr, UINT32 dwFlags, UINT32 agentProxy, UINT32 sn
    m_rackId = 0;
    m_rackPosition = 0;
    m_rackHeight = 1;
+   m_syslogMessageCount = 0;
+   m_snmpTrapCount = 0;
 }
 
 /**
@@ -268,7 +278,7 @@ bool Node::loadFromDatabase(DB_HANDLE hdb, UINT32 dwId)
       _T("runtime_flags,down_since,boot_time,driver_name,icmp_proxy,")
       _T("agent_cache_mode,snmp_sys_contact,snmp_sys_location,")
       _T("rack_id,rack_image,rack_position,rack_height,")
-      _T("last_agent_comm_time FROM nodes WHERE id=?"));
+      _T("last_agent_comm_time,syslog_msg_count,snmp_trap_count FROM nodes WHERE id=?"));
        if (hStmt == NULL)
                return false;
 
@@ -351,6 +361,8 @@ bool Node::loadFromDatabase(DB_HANDLE hdb, UINT32 dwId)
    m_rackPosition = (INT16)DBGetFieldLong(hResult, 0, 35);
    m_rackHeight = (INT16)DBGetFieldLong(hResult, 0, 36);
    m_lastAgentCommTime = DBGetFieldLong(hResult, 0, 37);
+   m_syslogMessageCount = DBGetFieldInt64(hResult, 0, 38);
+   m_snmpTrapCount = DBGetFieldInt64(hResult, 0, 39);
 
    DBFreeResult(hResult);
        DBFreeStatement(hStmt);
@@ -445,7 +457,8 @@ BOOL Node::saveToDatabase(DB_HANDLE hdb)
                        _T("platform_name=?,poller_node_id=?,zone_guid=?,proxy_node=?,snmp_proxy=?,icmp_proxy=?,required_polls=?,")
                        _T("use_ifxtable=?,usm_auth_password=?,usm_priv_password=?,usm_methods=?,snmp_sys_name=?,bridge_base_addr=?,")
                        _T("runtime_flags=?,down_since=?,driver_name=?,rack_image=?,rack_position=?,rack_height=?,rack_id=?,boot_time=?,")
-         _T("agent_cache_mode=?,snmp_sys_contact=?,snmp_sys_location=?,last_agent_comm_time=? WHERE id=?"));
+         _T("agent_cache_mode=?,snmp_sys_contact=?,snmp_sys_location=?,last_agent_comm_time=?,")
+         _T("syslog_msg_count=?,snmp_trap_count=? WHERE id=?"));
        }
    else
        {
@@ -454,8 +467,8 @@ BOOL Node::saveToDatabase(DB_HANDLE hdb)
                  _T("agent_port,auth_method,secret,snmp_oid,uname,agent_version,platform_name,poller_node_id,zone_guid,")
                  _T("proxy_node,snmp_proxy,icmp_proxy,required_polls,use_ifxtable,usm_auth_password,usm_priv_password,usm_methods,")
                  _T("snmp_sys_name,bridge_base_addr,runtime_flags,down_since,driver_name,rack_image,rack_position,rack_height,rack_id,boot_time,")
-        _T("agent_cache_mode,snmp_sys_contact,snmp_sys_location,last_agent_comm_time,id) ")
-                 _T("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"));
+        _T("agent_cache_mode,snmp_sys_contact,snmp_sys_location,last_agent_comm_time,syslog_msg_count,snmp_trap_count,id) ")
+                 _T("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"));
        }
        if (hStmt == NULL)
        {
@@ -512,7 +525,9 @@ BOOL Node::saveToDatabase(DB_HANDLE hdb)
    DBBind(hStmt, 36, DB_SQLTYPE_VARCHAR, m_sysContact, DB_BIND_STATIC);
    DBBind(hStmt, 37, DB_SQLTYPE_VARCHAR, m_sysLocation, DB_BIND_STATIC);
        DBBind(hStmt, 38, DB_SQLTYPE_INTEGER, (LONG)m_lastAgentCommTime);
-       DBBind(hStmt, 39, DB_SQLTYPE_INTEGER, m_id);
+   DBBind(hStmt, 39, DB_SQLTYPE_BIGINT, m_syslogMessageCount);
+   DBBind(hStmt, 40, DB_SQLTYPE_BIGINT, m_snmpTrapCount);
+       DBBind(hStmt, 41, DB_SQLTYPE_INTEGER, m_id);
 
        BOOL bResult = DBExecute(hStmt);
        DBFreeStatement(hStmt);
@@ -4362,6 +4377,18 @@ UINT32 Node::getInternalItem(const TCHAR *param, size_t bufSize, TCHAR *buffer)
          rc = DCE_NOT_SUPPORTED;
       }
    }
+   else if (!_tcsicmp(param, _T("ReceivedSNMPTraps")))
+   {
+      lockProperties();
+      _sntprintf(buffer, bufSize, INT64_FMT, m_snmpTrapCount);
+      unlockProperties();
+   }
+   else if (!_tcsicmp(param, _T("ReceivedSyslogMessages")))
+   {
+      lockProperties();
+      _sntprintf(buffer, bufSize, INT64_FMT, m_syslogMessageCount);
+      unlockProperties();
+   }
    else if (!_tcsicmp(param, _T("WirelessController.AdoptedAPCount")))
    {
       if (m_dwFlags & NF_IS_WIFI_CONTROLLER)
@@ -4471,6 +4498,14 @@ UINT32 Node::getInternalItem(const TCHAR *param, size_t bufSize, TCHAR *buffer)
       {
          _sntprintf(buffer, bufSize, UINT64_FMT, g_rawDataWriteRequests);
       }
+      else if (!_tcsicmp(param, _T("Server.ReceivedSNMPTraps")))
+      {
+         _sntprintf(buffer, bufSize, UINT64_FMT, g_snmpTrapsReceived);
+      }
+      else if (!_tcsicmp(param, _T("Server.ReceivedSyslogMessages")))
+      {
+         _sntprintf(buffer, bufSize, UINT64_FMT, g_syslogMessagesReceived);
+      }
       else if (MatchString(_T("Server.ThreadPool.ActiveRequests(*)"), param, FALSE))
       {
          rc = GetThreadPoolStat(THREAD_POOL_REQUESTS, param, buffer);
@@ -7654,3 +7689,25 @@ NXSL_Value *Node::createNXSLObject()
 {
    return new NXSL_Value(new NXSL_Object(&g_nxslNodeClass, this));
 }
+
+/**
+ * Increase number of received syslog messages
+ */
+void Node::incSyslogMessageCount()
+{
+   lockProperties();
+   m_syslogMessageCount++;
+   setModified(false);
+   unlockProperties();
+}
+
+/**
+ * Increase number of received SNMP traps
+ */
+void Node::incSnmpTrapCount()
+{
+   lockProperties();
+   m_snmpTrapCount++;
+   setModified(false);
+   unlockProperties();
+}
index 7431587..1e2530e 100644 (file)
  */
 extern Queue g_nodePollerQueue;
 
+/**
+ * Total number of received SNMP traps
+ */
+UINT64 g_snmpTrapsReceived = 0;
+
 /**
  * Max SNMP packet length
  */
@@ -264,6 +269,8 @@ void ProcessTrap(SNMP_PDU *pdu, const InetAddress& srcAddr, int srcPort, SNMP_Tr
 
    DbgPrintf(4, _T("Received SNMP %s %s from %s"), isInformRq ? _T("INFORM-REQUEST") : _T("TRAP"),
              pdu->getTrapId()->toString(&szBuffer[96], 4000), srcAddr.toString(szBuffer));
+   g_snmpTrapsReceived++;
+
        if (isInformRq)
        {
                SNMP_PDU *response = new SNMP_PDU(SNMP_RESPONSE, pdu->getRequestId(), pdu->getVersion());
@@ -330,6 +337,7 @@ void ProcessTrap(SNMP_PDU *pdu, const InetAddress& srcAddr, int srcPort, SNMP_Tr
    if (pNode != NULL)
    {
       DbgPrintf(4, _T("ProcessTrap: trap matched to node %s [%d]"), pNode->getName(), pNode->getId());
+      pNode->incSnmpTrapCount();
       if ((pNode->getStatus() != STATUS_UNMANAGED) || (g_flags & AF_TRAPS_FROM_UNMANAGED_NODES))
       {
          UINT32 i;
index 0f8b43b..7d0f224 100644 (file)
@@ -57,6 +57,11 @@ public:
 Queue g_syslogProcessingQueue(1000, 100);
 Queue g_syslogWriteQueue(1000, 100);
 
+/**
+ * Total number of received syslog messages
+ */
+UINT64 g_syslogMessagesReceived = 0;
+
 /**
  * Node matching policy
  */
@@ -310,6 +315,7 @@ static Node *BindMsgToNode(NX_SYSLOG_RECORD *pRec, const InetAddress& sourceAddr
 
        if (node != NULL)
    {
+          node->incSyslogMessageCount();
       pRec->dwSourceObject = node->getId();
       if (pRec->szHostName[0] == 0)
                {
@@ -415,6 +421,8 @@ static void ProcessSyslogMessage(char *psMsg, int nMsgLen, const InetAddress& so
        DbgPrintf(6, _T("ProcessSyslogMessage: Raw syslog message to process:\n%hs"), psMsg);
    if (ParseSyslogMessage(psMsg, nMsgLen, &record))
    {
+      g_syslogMessagesReceived++;
+
       record.qwMsgId = s_msgId++;
       Node *node = BindMsgToNode(&record, sourceAddr);
 
index 8830189..b0e11d8 100644 (file)
@@ -502,7 +502,7 @@ protected:
    }
    void unlockChildList() { RWLockUnlock(m_rwlockChildList); }
 
-   void setModified();                  // Used to mark object as modified
+   void setModified(bool notify = true);                  // Used to mark object as modified
 
    bool loadACLFromDB(DB_HANDLE hdb);
    bool saveACLToDB(DB_HANDLE hdb);
@@ -1288,6 +1288,8 @@ protected:
        INT16 m_rackPosition;
        UINT32 m_rackId;
        uuid m_rackImage;
+       INT64 m_syslogMessageCount;
+       INT64 m_snmpTrapCount;
 
    void pollerLock() { MutexLock(m_hPollerMutex); }
    void pollerUnlock() { MutexUnlock(m_hPollerMutex); }
@@ -1552,6 +1554,9 @@ public:
 
        DriverData *getDriverData() { return m_driverData; }
        void setDriverData(DriverData *data) { m_driverData = data; }
+
+       void incSyslogMessageCount();
+       void incSnmpTrapCount();
 };
 
 /**
index 10c1103..30b8e03 100644 (file)
@@ -673,6 +673,21 @@ static int NextFreeEPPruleID()
        return ruleId;
 }
 
+/**
+ * Upgrade from V405 to V406
+ */
+static BOOL H_UpgradeFromV405(int currVersion, int newVersion)
+{
+   static const TCHAR *batch =
+      _T("ALTER TABLE nodes ADD syslog_msg_count $SQL:INT64\n")
+      _T("ALTER TABLE nodes ADD snmp_trap_count $SQL:INT64\n")
+      _T("UPDATE nodes SET syslog_msg_count=0,snmp_trap_count=0\n")
+      _T("<END>");
+   CHK_EXEC(SQLBatch(batch));
+   CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='406' WHERE var_name='SchemaVersion'")));
+   return TRUE;
+}
+
 /**
  * Upgrade from V404 to V405
  */
@@ -10234,6 +10249,7 @@ static struct
    { 402, 403, H_UpgradeFromV402 },
    { 403, 404, H_UpgradeFromV403 },
    { 404, 405, H_UpgradeFromV404 },
+   { 405, 406, H_UpgradeFromV405 },
    { 0, 0, NULL }
 };
 
index 971b91b..d2db9d3 100644 (file)
@@ -56,6 +56,8 @@ public class SelectInternalParamDlg extends AbstractSelectParamDlg
                {
                        list.add(new AgentParameter("Net.IP.NextHop(*)", Messages.get().SelectInternalParamDlg_DCI_NextHop, DataCollectionItem.DT_STRING)); //$NON-NLS-1$
          list.add(new AgentParameter("NetSvc.ResponseTime(*)", "Network service {instance} response time", DataCollectionItem.DT_UINT)); //$NON-NLS-1$
+         list.add(new AgentParameter("ReceivedSNMPTraps", "Total SNMP traps received", DataCollectionItem.DT_UINT64)); //$NON-NLS-1$
+         list.add(new AgentParameter("ReceivedSyslogMessages", "Total syslog messages received", DataCollectionItem.DT_UINT64)); //$NON-NLS-1$
                }
                
                if ((object instanceof Template) || ((object instanceof AbstractNode) && ((AbstractNode)object).hasAgent()))
@@ -81,6 +83,8 @@ public class SelectInternalParamDlg extends AbstractSelectParamDlg
          list.add(new AgentParameter("Server.DBWriter.Requests.IData", "DB writer requests (DCI data)", DataCollectionItem.DT_UINT64)); //$NON-NLS-1$
          list.add(new AgentParameter("Server.DBWriter.Requests.Other", "DB writer requests (other queries)", DataCollectionItem.DT_UINT64)); //$NON-NLS-1$
          list.add(new AgentParameter("Server.DBWriter.Requests.RawData", "DB writer requests (raw DCI data)", DataCollectionItem.DT_UINT64)); //$NON-NLS-1$
+         list.add(new AgentParameter("Server.ReceivedSNMPTraps", "SNMP traps received since server start", DataCollectionItem.DT_UINT64)); //$NON-NLS-1$
+         list.add(new AgentParameter("Server.ReceivedSyslogMessages", "Syslog messages received since server start", DataCollectionItem.DT_UINT64)); //$NON-NLS-1$
          list.add(new AgentParameter("Server.ThreadPool.ActiveRequests(*)", "Thread pool {instance}: active requests", DataCollectionItem.DT_INT)); //$NON-NLS-1$
          list.add(new AgentParameter("Server.ThreadPool.CurrSize(*)", "Thread pool {instance}: current size", DataCollectionItem.DT_INT)); //$NON-NLS-1$
          list.add(new AgentParameter("Server.ThreadPool.Load(*)", "Thread pool {instance}: current load", DataCollectionItem.DT_INT)); //$NON-NLS-1$