events generated for table thresholds
authorVictor Kirhenshtein <victor@netxms.org>
Sat, 24 Aug 2013 21:49:01 +0000 (21:49 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Sat, 24 Aug 2013 21:49:01 +0000 (21:49 +0000)
include/netxmsdb.h
include/nxevent.h
sql/events.in
sql/policy.in
src/server/core/dcitem.cpp
src/server/core/dcithreshold.cpp
src/server/core/dctable.cpp
src/server/core/dctthreshold.cpp
src/server/core/events.cpp
src/server/include/nms_dcoll.h
src/server/tools/nxdbmgr/upgrade.cpp

index d33dfc9..6a64f25 100644 (file)
@@ -23,6 +23,6 @@
 #ifndef _netxmsdb_h
 #define _netxmsdb_h
 
-#define DB_FORMAT_VERSION   287
+#define DB_FORMAT_VERSION   288
 
 #endif
index d0176ca..8a40ce7 100644 (file)
 #define EVENT_TEMPLATE_AUTOAPPLY          66
 #define EVENT_TEMPLATE_AUTOREMOVE         67
 #define EVENT_NODE_UNREACHABLE            68
+#define EVENT_TABLE_THRESHOLD_ACTIVATED   69
+#define EVENT_TABLE_THRESHOLD_DEACTIVATED 70
 
 #define EVENT_SNMP_UNMATCHED_TRAP         500
 #define EVENT_SNMP_COLD_START             501
index f0f39ab..96172ec 100644 (file)
@@ -768,7 +768,32 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                'Parameters:' CONCAT CRLF CONCAT
                '   No event-specific parameters'
        );
-
+INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+       (
+               EVENT_TABLE_THRESHOLD_ACTIVATED, 'SYS_TABLE_THRESHOLD_ACTIVATED',
+               EVENT_SEVERITY_MINOR, 1,
+               'Threshold activated on table "%2" row %4 (%5)',
+               'Generated when table threshold is activated.' CONCAT CRLF CONCAT
+               'Parameters:' CONCAT CRLF CONCAT
+               '   1) Table DCI name' CONCAT CRLF CONCAT
+               '   2) Table DCI description' CONCAT CRLF CONCAT
+               '   3) Table DCI ID' CONCAT CRLF CONCAT
+               '   4) Table row' CONCAT CRLF CONCAT
+               '   5) Instance'
+       );
+INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+       (
+               EVENT_TABLE_THRESHOLD_DEACTIVATED, 'SYS_TABLE_THRESHOLD_DEACTIVATED',
+               EVENT_SEVERITY_NORMAL, 1,
+               'Threshold deactivated on table "%2" row %4 (%5)',
+               'Generated when table threshold is deactivated.' CONCAT CRLF CONCAT
+               'Parameters:' CONCAT CRLF CONCAT
+               '   1) Table DCI name' CONCAT CRLF CONCAT
+               '   2) Table DCI description' CONCAT CRLF CONCAT
+               '   3) Table DCI ID' CONCAT CRLF CONCAT
+               '   4) Table row' CONCAT CRLF CONCAT
+               '   5) Instance'
+       );
 
 /*
 ** SNMP traps
index 47768a9..a71bbc9 100644 (file)
@@ -9,7 +9,7 @@ INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,al
                '%m',5,'NODE_DOWN_%i','',0,EVENT_ALARM_TIMEOUT,0,'');
                
 INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance)
-       VALUES (1,7944,'Acknowlege node down alarms when node is up',
+       VALUES (1,7944,'Terminate node down alarms when node is up',
                '%m',6,'NODE_DOWN_%i','',0,EVENT_ALARM_TIMEOUT,0,'');
                
 INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance)
@@ -17,7 +17,7 @@ INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,al
                '%m',5,'SERVICE_DOWN_%i_%2','',0,EVENT_ALARM_TIMEOUT,0,'');
                
 INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance)
-       VALUES (3,7944,'Acknowlege network service down/unknown alarms when service is up',
+       VALUES (3,7944,'Terminate network service down/unknown alarms when service is up',
                '%m',6,'SERVICE_DOWN_%i_%2','',0,EVENT_ALARM_TIMEOUT,0,'');
                
 INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance)
@@ -25,7 +25,7 @@ INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,al
                '%m',5,'IF_DOWN_%i_%1','',0,EVENT_ALARM_TIMEOUT,0,'');
                
 INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance)
-       VALUES (5,7944,'Acknowlege interface down alarms when interface is up',
+       VALUES (5,7944,'Terminate interface down alarms when interface is up',
                '%m',6,'IF_DOWN_%i_%1','',0,EVENT_ALARM_TIMEOUT,0,'');
                
 INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance)
@@ -33,7 +33,7 @@ INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,al
                '%m',5,'IF_UNEXP_UP_%i_%1','',0,EVENT_ALARM_TIMEOUT,0,'');
                
 INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance)
-       VALUES (7,7944,'Acknowlege interface unexpectedly up alarms when interface goes down',
+       VALUES (7,7944,'Terminate interface unexpectedly up alarms when interface goes down',
                '%m',6,'IF_UNEXP_UP_%i_%1','',0,EVENT_ALARM_TIMEOUT,0,'');
                
 INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance)
@@ -53,7 +53,7 @@ INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,al
                '%m',4,'DB_CONN','',0,EVENT_ALARM_TIMEOUT,0,'');
                
 INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance)
-       VALUES (12,7944,'Acknowlege DB connection loss alarm when connection restored',
+       VALUES (12,7944,'Terminate DB connection loss alarm when connection restored',
                '%m',6,'DB_CONN','',0,EVENT_ALARM_TIMEOUT,0,'');
                
 INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance)
@@ -61,7 +61,7 @@ INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,al
                '%m',5,'DCI_STATUS_%i_%1','',0,EVENT_ALARM_TIMEOUT,0,'');
                
 INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance)
-       VALUES (14,7944,'Acknowlege DCI status alarms when DCI status returns to ACTIVE',
+       VALUES (14,7944,'Terminate DCI status alarms when DCI status returns to ACTIVE',
                '%m',6,'DCI_STATUS_%i_%1','',0,EVENT_ALARM_TIMEOUT,0,'');
 
 INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance)
@@ -69,9 +69,17 @@ INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,al
                '%m',5,'DC_THRESHOLD_%i_%5','',0,EVENT_ALARM_TIMEOUT,0,'');
                
 INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance)
-       VALUES (16,7944,'Acknowlege threshold violation alarm',
+       VALUES (16,7944,'Terminate threshold violation alarms',
                '%m',6,'DC_THRESHOLD_%i_%3','',0,EVENT_ALARM_TIMEOUT,0,'');
 
+INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance)
+       VALUES (17,7944,'Generate alarm on table threshold violation',
+               '%m',5,'DCTTHR_%i_%3_%5','',0,EVENT_ALARM_TIMEOUT,0,'');
+               
+INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance)
+       VALUES (18,7944,'Terminate table threshold violation alarms',
+               '%m',6,'DCTTHR_%i_%3_%5','',0,EVENT_ALARM_TIMEOUT,0,'');
+
 INSERT INTO policy_event_list (rule_id,event_code) VALUES (0,EVENT_NODE_DOWN);
 INSERT INTO policy_event_list (rule_id,event_code) VALUES (1,EVENT_NODE_UP);
 INSERT INTO policy_event_list (rule_id,event_code) VALUES (2,EVENT_SERVICE_DOWN);
@@ -91,3 +99,5 @@ INSERT INTO policy_event_list (rule_id,event_code) VALUES (13,EVENT_DCI_UNSUPPOR
 INSERT INTO policy_event_list (rule_id,event_code) VALUES (14,EVENT_DCI_ACTIVE);
 INSERT INTO policy_event_list (rule_id,event_code) VALUES (15,EVENT_THRESHOLD_REACHED);
 INSERT INTO policy_event_list (rule_id,event_code) VALUES (16,EVENT_THRESHOLD_REARMED);
+INSERT INTO policy_event_list (rule_id,event_code) VALUES (17,EVENT_TABLE_THRESHOLD_ACTIVATED);
+INSERT INTO policy_event_list (rule_id,event_code) VALUES (18,EVENT_TABLE_THRESHOLD_DEACTIVATED);
index a9a7797..caf619a 100644 (file)
@@ -423,8 +423,8 @@ BOOL DCItem::saveToDB(DB_HANDLE hdb)
  */
 void DCItem::checkThresholds(ItemValue &value)
 {
-       const TCHAR *paramNamesReach[] = { _T("dciName"), _T("dciDescription"), _T("thresholdValue"), _T("currentValue"), _T("dciId"), _T("instance"), _T("isRepeatedEvent") };
-       const TCHAR *paramNamesRearm[] = { _T("dciName"), _T("dciDescription"), _T("dciId"), _T("instance"), _T("thresholdValue"), _T("currentValue") };
+       static const TCHAR *paramNamesReach[] = { _T("dciName"), _T("dciDescription"), _T("thresholdValue"), _T("currentValue"), _T("dciId"), _T("instance"), _T("isRepeatedEvent") };
+       static const TCHAR *paramNamesRearm[] = { _T("dciName"), _T("dciDescription"), _T("dciId"), _T("instance"), _T("thresholdValue"), _T("currentValue") };
 
        if (m_thresholds == NULL)
                return;
@@ -436,49 +436,48 @@ void DCItem::checkThresholds(ItemValue &value)
 
    for(int i = 0; i < m_thresholds->size(); i++)
    {
-               Threshold *thr = m_thresholds->get(i);
-      int iResult = thr->check(value, m_ppValueCache, checkValue);
-      switch(iResult)
+               Threshold *t = m_thresholds->get(i);
+      ThresholdCheckResult result = t->check(value, m_ppValueCache, checkValue);
+      switch(result)
       {
-         case THRESHOLD_REACHED:
-            PostEventWithNames(thr->getEventCode(), m_pNode->Id(), "ssssisd",
-                                       paramNamesReach, m_szName, m_szDescription, thr->getStringValue(), 
+         case ACTIVATED:
+            PostEventWithNames(t->getEventCode(), m_pNode->Id(), "ssssisd",
+                                       paramNamesReach, m_szName, m_szDescription, t->getStringValue(), 
                (const TCHAR *)checkValue, m_dwId, m_instance, 0);
-                               evt = FindEventTemplateByCode(thr->getEventCode());
+                               evt = FindEventTemplateByCode(t->getEventCode());
                                if (evt != NULL)
-                                       thr->markLastEvent((int)evt->dwSeverity);
+                                       t->markLastEvent((int)evt->dwSeverity);
             if (!(m_flags & DCF_ALL_THRESHOLDS))
                i = m_thresholds->size();  // Stop processing
             break;
-         case THRESHOLD_REARMED:
-            PostEventWithNames(thr->getRearmEventCode(), m_pNode->Id(), "ssisss",
+         case DEACTIVATED:
+            PostEventWithNames(t->getRearmEventCode(), m_pNode->Id(), "ssisss",
                                        paramNamesRearm, m_szName, m_szDescription, m_dwId, m_instance, 
-                                       thr->getStringValue(), (const TCHAR *)checkValue);
+                                       t->getStringValue(), (const TCHAR *)checkValue);
             break;
-         case NO_ACTION:
-            if (thr->isReached())
+         case ALREADY_ACTIVE:
+                               // Check if we need to re-sent threshold violation event
+                               if (t->getRepeatInterval() == -1)
+                                       dwInterval = g_dwThresholdRepeatInterval;
+                               else
+                                       dwInterval = (UINT32)t->getRepeatInterval();
+                               if ((dwInterval != 0) && (t->getLastEventTimestamp() + (time_t)dwInterval < now))
+                               {
+                                       PostEventWithNames(t->getEventCode(), m_pNode->Id(), "ssssisd", 
+                                               paramNamesReach, m_szName, m_szDescription, t->getStringValue(), 
+                                               (const TCHAR *)checkValue, m_dwId, m_instance, 1);
+                                       evt = FindEventTemplateByCode(t->getEventCode());
+                                       if (evt != NULL)
+                                               t->markLastEvent((int)evt->dwSeverity);
+                               }
+
+                               if (!(m_flags & DCF_ALL_THRESHOLDS))
                                {
-                                       // Check if we need to re-sent threshold violation event
-                                       if (thr->getRepeatInterval() == -1)
-                                               dwInterval = g_dwThresholdRepeatInterval;
-                                       else
-                                               dwInterval = (UINT32)thr->getRepeatInterval();
-                                       if ((dwInterval != 0) && (thr->getLastEventTimestamp() + (time_t)dwInterval < now))
-                                       {
-                                               PostEventWithNames(thr->getEventCode(), m_pNode->Id(), "ssssisd", 
-                                                       paramNamesReach, m_szName, m_szDescription, thr->getStringValue(), 
-                                                       (const TCHAR *)checkValue, m_dwId, m_instance, 1);
-                                               evt = FindEventTemplateByCode(thr->getEventCode());
-                                               if (evt != NULL)
-                                                       thr->markLastEvent((int)evt->dwSeverity);
-                                       }
-
-                                       if (!(m_flags & DCF_ALL_THRESHOLDS))
-                                       {
-                                               i = m_thresholds->size();  // Threshold condition still true, stop processing
-                                       }
+                                       i = m_thresholds->size();  // Threshold condition still true, stop processing
                                }
             break;
+         default:
+            break;
       }
    }
 }
@@ -739,23 +738,25 @@ void DCItem::processNewError()
        for(int i = 0; i < getThresholdCount(); i++)
    {
                Threshold *thr = m_thresholds->get(i);
-      int iResult = thr->checkError(m_dwErrorCount);
-      switch(iResult)
+      ThresholdCheckResult result = thr->checkError(m_dwErrorCount);
+      switch(result)
       {
-         case THRESHOLD_REACHED:
+         case ACTIVATED:
             PostEvent(thr->getEventCode(), m_pNode->Id(), "ssssis", m_szName,
                       m_szDescription, _T(""), _T(""), m_dwId, m_instance);
             if (!(m_flags & DCF_ALL_THRESHOLDS))
                i = m_thresholds->size();  // Stop processing
             break;
-         case THRESHOLD_REARMED:
+         case DEACTIVATED:
             PostEvent(thr->getRearmEventCode(), m_pNode->Id(), "ssis", m_szName,
                       m_szDescription, m_dwId, m_instance);
             break;
-         case NO_ACTION:
-            if (thr->isReached() && !(m_flags & DCF_ALL_THRESHOLDS))
+         case ALREADY_ACTIVE:
+            if (!(m_flags & DCF_ALL_THRESHOLDS))
                i = m_thresholds->size();  // Threshold condition still true, stop processing
             break;
+         default:
+            break;
       }
    }
 
index c45eeb2..da95b95 100644 (file)
@@ -215,10 +215,10 @@ BOOL Threshold::saveToDB(DB_HANDLE hdb, UINT32 dwIndex)
  *    THRESHOLD_REARMED - when item's value doesn't match the threshold condition while previous check do
  *    NO_ACTION - when there are no changes in item's value match to threshold's condition
  */
-int Threshold::check(ItemValue &value, ItemValue **ppPrevValues, ItemValue &fvalue)
+ThresholdCheckResult Threshold::check(ItemValue &value, ItemValue **ppPrevValues, ItemValue &fvalue)
 {
    BOOL bMatch = FALSE;
-   int iResult, iDataType = m_dataType;
+   int iDataType = m_dataType;
 
    // Execute function on value
    switch(m_function)
@@ -414,20 +414,16 @@ int Threshold::check(ItemValue &value, ItemValue **ppPrevValues, ItemValue &fval
                }
        }
 
-   iResult = (bMatch & !m_isReached) ? THRESHOLD_REACHED :
-                ((!bMatch & m_isReached) ? THRESHOLD_REARMED : NO_ACTION);
+   ThresholdCheckResult result = (bMatch & !m_isReached) ? ACTIVATED : ((!bMatch & m_isReached) ? DEACTIVATED : (m_isReached ? ALREADY_ACTIVE : ALREADY_INACTIVE));
    m_isReached = bMatch;
-   if (iResult != NO_ACTION)
+   if (result == ACTIVATED || result == DEACTIVATED)
    {
-      TCHAR szQuery[256];
-
       // Update threshold status in database
-      _sntprintf(szQuery, 256,
-                 _T("UPDATE thresholds SET current_state=%d WHERE threshold_id=%d"),
-                 (int)m_isReached, (int)m_id);
+      TCHAR szQuery[256];
+      _sntprintf(szQuery, 256, _T("UPDATE thresholds SET current_state=%d WHERE threshold_id=%d"), (int)m_isReached, (int)m_id);
       QueueSQLRequest(szQuery);
    }
-   return iResult;
+   return result;
 }
 
 /**
@@ -450,36 +446,27 @@ void Threshold::markLastEvent(int severity)
  * Check for collection error thresholds
  * Return same values as Check()
  */
-int Threshold::checkError(UINT32 dwErrorCount)
+ThresholdCheckResult Threshold::checkError(UINT32 dwErrorCount)
 {
-   int nResult;
-   BOOL bMatch;
-
    if (m_function != F_ERROR)
-      return NO_ACTION;
+      return m_isReached ? ALREADY_ACTIVE : ALREADY_INACTIVE;
 
-   bMatch = ((UINT32)m_param1 <= dwErrorCount);
-   nResult = (bMatch & !m_isReached) ? THRESHOLD_REACHED :
-                ((!bMatch & m_isReached) ? THRESHOLD_REARMED : NO_ACTION);
+   BOOL bMatch = ((UINT32)m_param1 <= dwErrorCount);
+   ThresholdCheckResult result = (bMatch & !m_isReached) ? ACTIVATED : ((!bMatch & m_isReached) ? DEACTIVATED : (m_isReached ? ALREADY_ACTIVE : ALREADY_INACTIVE));
    m_isReached = bMatch;
-   if (nResult != NO_ACTION)
+   if (result == ACTIVATED || result == DEACTIVATED)
    {
-      TCHAR szQuery[256];
-
       // Update threshold status in database
-      _sntprintf(szQuery, 256,
-                 _T("UPDATE thresholds SET current_state=%d WHERE threshold_id=%d"),
-                 m_isReached, m_id);
+      TCHAR szQuery[256];
+      _sntprintf(szQuery, 256, _T("UPDATE thresholds SET current_state=%d WHERE threshold_id=%d"), m_isReached, m_id);
       QueueSQLRequest(szQuery);
    }
-   return nResult;
+   return result;
 }
 
-
-//
-// Fill DCI_THRESHOLD with object's data ready to send over the network
-//
-
+/**
+ * Fill DCI_THRESHOLD with object's data ready to send over the network
+ */
 void Threshold::createMessage(CSCPMessage *msg, UINT32 baseId)
 {
        UINT32 varId = baseId;
index 19f7b9e..e804d60 100644 (file)
@@ -437,11 +437,34 @@ void DCTable::transform(Table *value)
  */
 void DCTable::checkThresholds(Table *value)
 {
+       static const TCHAR *paramNames[] = { _T("dciName"), _T("dciDescription"), _T("dciId"), _T("row"), _T("instance") };
+
    lock();
-   for(int i = 0; i < m_thresholds->size(); i++)
+   for(int row = 0; row < value->getNumRows(); row++)
    {
-               DCTableThreshold *t = m_thresholds->get(i);
-      t->check(value, i);
+      TCHAR instance[MAX_RESULT_LENGTH];
+      value->buildInstanceString(row, instance, MAX_RESULT_LENGTH);
+      for(int i = 0; i < m_thresholds->size(); i++)
+      {
+                  DCTableThreshold *t = m_thresholds->get(i);
+         ThresholdCheckResult result = t->check(value, row, instance);
+         switch(result)
+         {
+            case ACTIVATED:
+               PostEventWithNames(t->getActivationEvent(), m_pNode->Id(), "ssids", paramNames, m_szName, m_szDescription, m_dwId, row, instance);
+               if (!(m_flags & DCF_ALL_THRESHOLDS))
+                  i = m_thresholds->size();  // Stop processing (for current row)
+               break;
+            case DEACTIVATED:
+               PostEventWithNames(t->getDeactivationEvent(), m_pNode->Id(), "ssids", paramNames, m_szName, m_szDescription, m_dwId, row, instance);
+               break;
+            case ALREADY_ACTIVE:
+                                  i = m_thresholds->size();  // Threshold condition still true, stop processing
+               break;
+            default:
+               break;
+         }
+      }
    }
    unlock();
 }
index 5bd19f7..a91357d 100644 (file)
@@ -307,8 +307,8 @@ DCTableThreshold::DCTableThreshold()
 {
    m_id = CreateUniqueId(IDG_THRESHOLD);
    m_groups = new ObjectArray<DCTableConditionGroup>(4, 4, true);
-   m_activationEvent = EVENT_THRESHOLD_REACHED;
-   m_deactivationEvent = EVENT_THRESHOLD_REARMED;
+   m_activationEvent = EVENT_TABLE_THRESHOLD_ACTIVATED;
+   m_deactivationEvent = EVENT_TABLE_THRESHOLD_DEACTIVATED;
    m_activeKeys = new StringSet;
 }
 
@@ -364,8 +364,8 @@ DCTableThreshold::DCTableThreshold(CSCPMessage *msg, UINT32 *baseId)
  */
 DCTableThreshold::DCTableThreshold(ConfigEntry *e)
 {
-   m_activationEvent = EventCodeFromName(e->getSubEntryValue(_T("activationEvent"), 0, _T("SYS_THRESHOLD_REACHED")));
-   m_deactivationEvent = EventCodeFromName(e->getSubEntryValue(_T("deactivationEvent"), 0, _T("SYS_THRESHOLD_REARMED")));
+   m_activationEvent = EventCodeFromName(e->getSubEntryValue(_T("activationEvent"), 0, _T("SYS_TABLE_THRESHOLD_ACTIVATED")));
+   m_deactivationEvent = EventCodeFromName(e->getSubEntryValue(_T("deactivationEvent"), 0, _T("SYS_TABLE_THRESHOLD_DEACTIVATED")));
 
        ConfigEntry *groupsRoot = e->findEntry(_T("groups"));
        if (groupsRoot != NULL)
@@ -496,21 +496,18 @@ UINT32 DCTableThreshold::fillMessage(CSCPMessage *msg, UINT32 baseId)
  *    THRESHOLD_REARMED - when value doesn't match the threshold condition while previous check do
  *    NO_ACTION - when there are no changes in value match to threshold's condition
  */
-int DCTableThreshold::check(Table *value, int row)
+ThresholdCheckResult DCTableThreshold::check(Table *value, int row, const TCHAR *instance)
 {
-   TCHAR instance[MAX_RESULT_LENGTH];
-   value->buildInstanceString(row, instance, MAX_RESULT_LENGTH);
-
    for(int i = 0; i < m_groups->size(); i++)
    {
       if (m_groups->get(i)->check(value, row))
       {
          if (m_activeKeys->exist(instance))
          {
-            return NO_ACTION;
+            return ALREADY_ACTIVE;
          }
          m_activeKeys->add(instance);
-         return THRESHOLD_REACHED;
+         return ACTIVATED;
       }
    }
 
@@ -518,9 +515,9 @@ int DCTableThreshold::check(Table *value, int row)
    if (m_activeKeys->exist(instance))
    {
       m_activeKeys->remove(instance);
-      return THRESHOLD_REARMED;
+      return DEACTIVATED;
    }
-   return NO_ACTION;
+   return ALREADY_INACTIVE;
 }
 
 /**
index 572c9e5..d33aa9c 100644 (file)
@@ -730,12 +730,10 @@ void DeleteEventTemplateFromList(UINT32 dwEventCode)
    RWLockUnlock(m_rwlockTemplateAccess);
 }
 
-
-//
-// Perform binary search on event template by id
-// Returns INULL if key not found or pointer to appropriate template
-//
-
+/**
+ * Perform binary search on event template by id
+ * Returns INULL if key not found or pointer to appropriate template
+ */
 static EVENT_TEMPLATE *FindEventTemplate(UINT32 dwCode)
 {
    UINT32 dwFirst, dwLast, dwMid;
@@ -763,25 +761,23 @@ static EVENT_TEMPLATE *FindEventTemplate(UINT32 dwCode)
    return NULL;
 }
 
-
-//
-// Post event to the queue.
-// Arguments:
-// dwEventCode - Event code
-// dwSourceId  - Event source object ID
-// szFormat    - Parameter format string, each parameter represented by one character.
-//    The following format characters can be used:
-//        s - String
-//        d - Decimal integer
-//        D - 64-bit decimal integer
-//        x - Hex integer
-//        a - IP address
-//        i - Object ID
-// names - names for parameters
-// PostEventEx will put events to specified queue, and PostEvent to system
-// event queue. Both functions uses RealPostEvent to do real job.
-//
-
+/**
+ * Post event to the queue.
+ * Arguments:
+ * dwEventCode - Event code
+ * dwSourceId  - Event source object ID
+ * szFormat    - Parameter format string, each parameter represented by one character.
+ *    The following format characters can be used:
+ *        s - String
+ *        d - Decimal integer
+ *        D - 64-bit decimal integer
+ *        x - Hex integer
+ *        a - IP address
+ *        i - Object ID
+ * names - names for parameters
+ * PostEventEx will put events to specified queue, and PostEvent to system
+ * event queue. Both functions uses RealPostEvent to do real job.
+ */
 static BOOL RealPostEvent(Queue *pQueue, UINT32 dwEventCode, UINT32 dwSourceId,
                           const TCHAR *pszUserTag, const char *pszFormat, const TCHAR **names, va_list args)
 {
index ce8810c..2716215 100644 (file)
 /**
  * Threshold check results
  */
-#define THRESHOLD_REACHED  0
-#define THRESHOLD_REARMED  1
-#define NO_ACTION          2
+enum ThresholdCheckResult
+{
+   ACTIVATED = 0,
+   DEACTIVATED = 1,
+   ALREADY_ACTIVE = 2,
+   ALREADY_INACTIVE = 3
+};
 
 /**
  * DCI value
@@ -137,8 +141,8 @@ public:
        void markLastEvent(int severity);
 
    BOOL saveToDB(DB_HANDLE hdb, UINT32 dwIndex);
-   int check(ItemValue &value, ItemValue **ppPrevValues, ItemValue &fvalue);
-   int checkError(UINT32 dwErrorCount);
+   ThresholdCheckResult check(ItemValue &value, ItemValue **ppPrevValues, ItemValue &fvalue);
+   ThresholdCheckResult checkError(UINT32 dwErrorCount);
 
    void createMessage(CSCPMessage *msg, UINT32 baseId);
    void updateFromMessage(CSCPMessage *msg, UINT32 baseId);
@@ -501,7 +505,7 @@ public:
    DCTableThreshold(ConfigEntry *e);
    ~DCTableThreshold();
 
-   int check(Table *value, int row);
+   ThresholdCheckResult check(Table *value, int row, const TCHAR *instance);
 
    bool saveToDatabase(DB_HANDLE hdb, UINT32 tableId, int seq);
 
@@ -510,6 +514,8 @@ public:
    void createNXMPRecord(String &str, int id);
 
    UINT32 getId() { return m_id; }
+   UINT32 getActivationEvent() { return m_activationEvent; }
+   UINT32 getDeactivationEvent() { return m_deactivationEvent; }
 };
 
 /**
index adae144..e50f7dc 100644 (file)
@@ -354,6 +354,35 @@ static BOOL RecreateTData(const TCHAR *className)
 }
 
 /**
+ * Upgrade from V287 to V288
+ */
+static BOOL H_UpgradeFromV287(int currVersion, int newVersion)
+{
+   CHK_EXEC(CreateEventTemplate(EVENT_TABLE_THRESHOLD_ACTIVATED, _T("SYS_TABLE_THRESHOLD_ACTIVATED"), EVENT_SEVERITY_MINOR, EF_LOG,
+      _T("Threshold activated on table \"%2\" row %4 (%5)"),
+      _T("Generated when table threshold is activated.\r\n")
+      _T("Parameters:\r\n")
+      _T("   1) Table DCI name\r\n")
+      _T("   2) Table DCI description\r\n")
+      _T("   3) Table DCI ID\r\n")
+      _T("   4) Table row\r\n")
+      _T("   5) Instance")));
+
+   CHK_EXEC(CreateEventTemplate(EVENT_TABLE_THRESHOLD_DEACTIVATED, _T("SYS_TABLE_THRESHOLD_DEACTIVATED"), EVENT_SEVERITY_NORMAL, EF_LOG,
+      _T("Threshold deactivated on table \"%2\" row %4 (%5)"),
+      _T("Generated when table threshold is deactivated.\r\n")
+      _T("Parameters:\r\n")
+      _T("   1) Table DCI name\r\n")
+      _T("   2) Table DCI description\r\n")
+      _T("   3) Table DCI ID\r\n")
+      _T("   4) Table row\r\n")
+      _T("   5) Instance")));
+
+   CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='288' WHERE var_name='SchemaVersion'")));
+   return TRUE;
+}
+
+/**
  * Upgrade from V286 to V287
  */
 static BOOL H_UpgradeFromV286(int currVersion, int newVersion)
@@ -7093,6 +7122,7 @@ static struct
    { 284, 285, H_UpgradeFromV284 },
    { 285, 286, H_UpgradeFromV285 },
    { 286, 287, H_UpgradeFromV286 },
+   { 287, 288, H_UpgradeFromV287 },
    { 0, 0, NULL }
 };