added events on interface expected state change
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 2 Feb 2017 22:40:35 +0000 (00:40 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 2 Feb 2017 22:40:35 +0000 (00:40 +0200)
ChangeLog
include/netxmsdb.h
include/nxevent.h
sql/events.in
sql/policy.in
src/server/core/interface.cpp
src/server/include/nms_objects.h
src/server/tools/nxdbmgr/upgrade.cpp

index a085c78..45aa5d8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,7 @@
 - New attribute "mapImage" in NXSL class "NetObj"
 - New NXSL class "Container"
 - Container autobind mode and script can be set from NXSL
+- Events generated when interface expected state changed
 - Fixed issues: NX-60, NX-630, NX-916, NX-1151
 
 
index 9c6d83c..84c103e 100644 (file)
@@ -23,6 +23,6 @@
 #ifndef _netxmsdb_h
 #define _netxmsdb_h
 
-#define DB_FORMAT_VERSION   433
+#define DB_FORMAT_VERSION   434
 
 #endif
index fc83051..6e06d40 100644 (file)
 #define EVENT_LDAP_SYNC_ERROR              80
 #define EVENT_AGENT_LOG_PROBLEM            81
 #define EVENT_AGENT_LOCAL_DATABASE_PROBLEM 82
+#define EVENT_IF_EXPECTED_STATE_UP         83
+#define EVENT_IF_EXPECTED_STATE_DOWN       84
+#define EVENT_IF_EXPECTED_STATE_IGNORE     85
 
 #define EVENT_SNMP_UNMATCHED_TRAP          500
 #define EVENT_SNMP_COLD_START              501
index b12075f..78eb75e 100644 (file)
@@ -1147,3 +1147,36 @@ INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,descrip
                'Parameters:' CONCAT CRLF CONCAT
                THRESHOLD_EVENT_PARAMS
        );
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
+       (
+               EVENT_IF_EXPECTED_STATE_UP, 'SYS_IF_EXPECTED_STATE_UP', '4997c3f5-b332-4077-8e99-983142f0e193',
+               EVENT_SEVERITY_NORMAL, 1,
+               'Expected state for interface "%2" set to UP',
+               'Generated when interface expected state set to UP.' CONCAT CRLF CONCAT
+               'Please note that source of event is node, not an interface itself.' CONCAT CRLF CONCAT
+               'Parameters:' CONCAT CRLF CONCAT
+               '   1) Interface index' CONCAT CRLF CONCAT
+               '   2) Interface name'
+       );
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
+       (
+               EVENT_IF_EXPECTED_STATE_DOWN, 'SYS_IF_EXPECTED_STATE_DOWN', '75de536c-4861-4f19-ba56-c43d814431d7',
+               EVENT_SEVERITY_NORMAL, 1,
+               'Expected state for interface "%2" set to DOWN',
+               'Generated when interface expected state set to DOWN.' CONCAT CRLF CONCAT
+               'Please note that source of event is node, not an interface itself.' CONCAT CRLF CONCAT
+               'Parameters:' CONCAT CRLF CONCAT
+               '   1) Interface index' CONCAT CRLF CONCAT
+               '   2) Interface name'
+       );
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
+       (
+               EVENT_IF_EXPECTED_STATE_IGNORE, 'SYS_IF_EXPECTED_STATE_IGNORE', '0e488c0e-3340-4e02-ad96-b999b8392e55',
+               EVENT_SEVERITY_NORMAL, 1,
+               'Expected state for interface "%2" set to IGNORE',
+               'Generated when interface expected state set to IGNORE.' CONCAT CRLF CONCAT
+               'Please note that source of event is node, not an interface itself.' CONCAT CRLF CONCAT
+               'Parameters:' CONCAT CRLF CONCAT
+               '   1) Interface index' CONCAT CRLF CONCAT
+               '   2) Interface name'
+       );
index 8c144ac..3befebf 100644 (file)
@@ -29,7 +29,7 @@ INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_s
                '%m',6,'IF_DOWN_%i_%5','',0,EVENT_ALARM_TIMEOUT);
 
 INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event)
-       VALUES (6,'6f46d451-ee66-4563-8747-d129877df24d',7944,'Terminate interface down alarms when interface is deleted',
+       VALUES (6,'6f46d451-ee66-4563-8747-d129877df24d',7944,'Terminate interface down alarms when interface is deleted or it''s expected state changed',
                '%m',6,'IF_DOWN_%i_%1','',0,EVENT_ALARM_TIMEOUT);
 
 INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event)
@@ -41,7 +41,7 @@ INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_s
                '%m',6,'IF_UNEXP_UP_%i_%5','',0,EVENT_ALARM_TIMEOUT);
 
 INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event)
-       VALUES (9,'ecc3fb57-672d-489d-a0ef-4214ea896e0f',7944,'Terminate interface unexpectedly up alarms when interface is deleted',
+       VALUES (9,'ecc3fb57-672d-489d-a0ef-4214ea896e0f',7944,'Terminate interface unexpectedly up alarms when interface is deleted or it''s expected state changed',
                '%m',6,'IF_UNEXP_UP_%i_%1','',0,EVENT_ALARM_TIMEOUT);
 
 INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event)
@@ -149,9 +149,13 @@ INSERT INTO policy_event_list (rule_id,event_code) VALUES (3,EVENT_SERVICE_UP);
 INSERT INTO policy_event_list (rule_id,event_code) VALUES (4,EVENT_INTERFACE_DOWN);
 INSERT INTO policy_event_list (rule_id,event_code) VALUES (5,EVENT_INTERFACE_UP);
 INSERT INTO policy_event_list (rule_id,event_code) VALUES (6,EVENT_INTERFACE_DELETED);
+INSERT INTO policy_event_list (rule_id,event_code) VALUES (6,EVENT_IF_EXPECTED_STATE_DOWN);
+INSERT INTO policy_event_list (rule_id,event_code) VALUES (6,EVENT_IF_EXPECTED_STATE_IGNORE);
 INSERT INTO policy_event_list (rule_id,event_code) VALUES (7,EVENT_INTERFACE_UNEXPECTED_UP);
 INSERT INTO policy_event_list (rule_id,event_code) VALUES (8,EVENT_INTERFACE_EXPECTED_DOWN);
 INSERT INTO policy_event_list (rule_id,event_code) VALUES (9,EVENT_INTERFACE_DELETED);
+INSERT INTO policy_event_list (rule_id,event_code) VALUES (9,EVENT_IF_EXPECTED_STATE_UP);
+INSERT INTO policy_event_list (rule_id,event_code) VALUES (9,EVENT_IF_EXPECTED_STATE_IGNORE);
 INSERT INTO policy_event_list (rule_id,event_code) VALUES (10,EVENT_INCORRECT_NETMASK);
 INSERT INTO policy_event_list (rule_id,event_code) VALUES (11,EVENT_MAC_ADDR_CHANGED);
 INSERT INTO policy_event_list (rule_id,event_code) VALUES (12,EVENT_SCRIPT_ERROR);
index 0b68554..20c1c17 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ** NetXMS - Network Management System
-** Copyright (C) 2003-2016 Victor Kirhenshtein
+** Copyright (C) 2003-2017 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
@@ -1033,9 +1033,7 @@ UINT32 Interface::modifyFromMessageInternal(NXCPMessage *pRequest)
        // Expected interface state
        if (pRequest->isFieldExist(VID_EXPECTED_STATE))
        {
-      UINT32 expectedState = pRequest->getFieldAsUInt16(VID_EXPECTED_STATE);
-               m_flags &= ~IF_EXPECTED_STATE_MASK;
-               m_flags |= expectedState << 28;
+               setExpectedStateInternal(pRequest->getFieldAsInt16(VID_EXPECTED_STATE));
        }
 
        // Flags
@@ -1052,13 +1050,19 @@ UINT32 Interface::modifyFromMessageInternal(NXCPMessage *pRequest)
 /**
  * Set expected state for interface
  */
-void Interface::setExpectedState(int state)
+void Interface::setExpectedStateInternal(int state)
 {
-       lockProperties();
-       m_flags &= ~IF_EXPECTED_STATE_MASK;
-       m_flags |= (UINT32)state << 28;
-       setModified();
-       unlockProperties();
+   static UINT32 eventCode[] = { EVENT_IF_EXPECTED_STATE_UP, EVENT_IF_EXPECTED_STATE_DOWN, EVENT_IF_EXPECTED_STATE_IGNORE };
+
+       int curr = (m_flags & IF_EXPECTED_STATE_MASK) >> 28;
+       if (curr != state)
+       {
+      m_flags &= ~IF_EXPECTED_STATE_MASK;
+      m_flags |= (UINT32)state << 28;
+      setModified();
+      if (state != IF_EXPECTED_STATE_AUTO)
+         PostEvent(eventCode[state], getParentNodeId(), "ds", m_index, m_name);
+       }
 }
 
 /**
index c83bd2e..41e41f3 100644 (file)
@@ -823,6 +823,8 @@ protected:
        virtual void fillMessageInternal(NXCPMessage *pMsg);
    virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
 
+   void setExpectedStateInternal(int state);
+
 public:
    Interface();
    Interface(const InetAddressList& addrList, UINT32 zoneId, bool bSyntheticMask);
@@ -900,7 +902,7 @@ public:
    void statusPoll(ClientSession *session, UINT32 rqId, Queue *eventQueue, Cluster *cluster, SNMP_Transport *snmpTransport, UINT32 nodeIcmpProxy);
 
    UINT32 wakeUp();
-       void setExpectedState(int state);
+       void setExpectedState(int state) { lockProperties(); setExpectedStateInternal(state); unlockProperties(); }
    void setExcludeFromTopology(bool excluded);
        void updatePingData();
 };
index 2cc606b..8a006e5 100644 (file)
@@ -716,6 +716,27 @@ static int NextFreeEPPruleID()
 }
 
 /**
+ * Add event to EPP rule by rule GUID
+ */
+static bool AddEventToEPPRule(const TCHAR *guid, UINT32 eventCode)
+{
+   TCHAR query[256];
+   _sntprintf(query, 256, _T("SELECT rule_id FROM event_policy WHERE rule_guid='%s'"), guid);
+   DB_RESULT hResult = SQLSelect(query);
+   if (hResult == NULL)
+      return false;
+
+   bool success = true;
+   if (DBGetNumRows(hResult) > 0)
+   {
+      _sntprintf(query, 256, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), DBGetFieldLong(hResult, 0, 0), eventCode);
+      success = SQLQuery(query);
+   }
+   DBFreeResult(hResult);
+   return success;
+}
+
+/**
  * Set schema version
  */
 static bool SetSchemaVersion(int version)
@@ -725,7 +746,54 @@ static bool SetSchemaVersion(int version)
    return SQLQuery(query);
 }
 
-/*
+/**
+ * Upgrade from V433 to V434
+ */
+static BOOL H_UpgradeFromV433(int currVersion, int newVersion)
+{
+   CHK_EXEC(
+      CreateEventTemplate(EVENT_IF_EXPECTED_STATE_UP, _T("SYS_IF_EXPECTED_STATE_UP"),
+         SEVERITY_NORMAL, EF_LOG, _T("4997c3f5-b332-4077-8e99-983142f0e193"),
+         _T("Expected state for interface \"%2\" set to UP"),
+         _T("Generated when interface expected state set to UP.\r\n")
+         _T("Please note that source of event is node, not an interface itself.\r\n")
+         _T("Parameters:\r\n")
+         _T("    1) Interface index\r\n")
+         _T("    2) Interface name"))
+      );
+
+   CHK_EXEC(
+      CreateEventTemplate(EVENT_IF_EXPECTED_STATE_DOWN, _T("SYS_IF_EXPECTED_STATE_DOWN"),
+         SEVERITY_NORMAL, EF_LOG, _T("75de536c-4861-4f19-ba56-c43d814431d7"),
+         _T("Expected state for interface \"%2\" set to DOWN"),
+         _T("Generated when interface expected state set to DOWN.\r\n")
+         _T("Please note that source of event is node, not an interface itself.\r\n")
+         _T("Parameters:\r\n")
+         _T("    1) Interface index\r\n")
+         _T("    2) Interface name"))
+      );
+
+   CHK_EXEC(
+      CreateEventTemplate(EVENT_IF_EXPECTED_STATE_IGNORE, _T("SYS_IF_EXPECTED_STATE_IGNORE"),
+         SEVERITY_NORMAL, EF_LOG, _T("0e488c0e-3340-4e02-ad96-b999b8392e55"),
+         _T("Expected state for interface \"%2\" set to IGNORE"),
+         _T("Generated when interface expected state set to IGNORE.\r\n")
+         _T("Please note that source of event is node, not an interface itself.\r\n")
+         _T("Parameters:\r\n")
+         _T("    1) Interface index\r\n")
+         _T("    2) Interface name"))
+      );
+
+   CHK_EXEC(AddEventToEPPRule(_T("6f46d451-ee66-4563-8747-d129877df24d"), EVENT_IF_EXPECTED_STATE_DOWN));
+   CHK_EXEC(AddEventToEPPRule(_T("6f46d451-ee66-4563-8747-d129877df24d"), EVENT_IF_EXPECTED_STATE_IGNORE));
+   CHK_EXEC(AddEventToEPPRule(_T("ecc3fb57-672d-489d-a0ef-4214ea896e0f"), EVENT_IF_EXPECTED_STATE_UP));
+   CHK_EXEC(AddEventToEPPRule(_T("ecc3fb57-672d-489d-a0ef-4214ea896e0f"), EVENT_IF_EXPECTED_STATE_IGNORE));
+
+   CHK_EXEC(SetSchemaVersion(434));
+   return TRUE;
+}
+
+/**
  * Upgrade from V432 to V433
  */
 static BOOL H_UpgradeFromV432(int currVersion, int newVersion)
@@ -735,7 +803,7 @@ static BOOL H_UpgradeFromV432(int currVersion, int newVersion)
    return TRUE;
 }
 
-/*
+/**
  * Upgrade from V431 to V432
  */
 static BOOL H_UpgradeFromV431(int currVersion, int newVersion)
@@ -746,7 +814,7 @@ static BOOL H_UpgradeFromV431(int currVersion, int newVersion)
    return TRUE;
 }
 
-/*
+/**
  * Upgrade from V430 to V431
  */
 static BOOL H_UpgradeFromV430(int currVersion, int newVersion)
@@ -757,8 +825,8 @@ static BOOL H_UpgradeFromV430(int currVersion, int newVersion)
    return TRUE;
 }
 
-/*
- *  Upgrade from V429 to V430
+/**
+ * Upgrade from V429 to V430
  */
 static BOOL H_UpgradeFromV429(int currVersion, int newVersion)
 {
@@ -1077,7 +1145,7 @@ static BOOL H_UpgradeFromV428(int currVersion, int newVersion)
 }
 
 /**
- *  Upgrade from V427 to V428
+ * Upgrade from V427 to V428
  */
 static BOOL H_UpgradeFromV427(int currVersion, int newVersion)
 {
@@ -1088,7 +1156,7 @@ static BOOL H_UpgradeFromV427(int currVersion, int newVersion)
 }
 
 /**
- *  Upgrade from V426 to V427
+ * Upgrade from V426 to V427
  */
 static BOOL H_UpgradeFromV426(int currVersion, int newVersion)
 {
@@ -1099,7 +1167,7 @@ static BOOL H_UpgradeFromV426(int currVersion, int newVersion)
 }
 
 /**
- *  Upgrade from V425 to V426
+ * Upgrade from V425 to V426
  */
 static BOOL H_UpgradeFromV425(int currVersion, int newVersion)
 {
@@ -1111,7 +1179,7 @@ static BOOL H_UpgradeFromV425(int currVersion, int newVersion)
 }
 
 /**
- *  Upgrade from V424 to V425
+ * Upgrade from V424 to V425
  */
 static BOOL H_UpgradeFromV424(int currVersion, int newVersion)
 {
@@ -1121,7 +1189,7 @@ static BOOL H_UpgradeFromV424(int currVersion, int newVersion)
 }
 
 /**
- *  Upgrade from V423 to V424
+ * Upgrade from V423 to V424
  */
 static BOOL H_UpgradeFromV423(int currVersion, int newVersion)
 {
@@ -1131,7 +1199,7 @@ static BOOL H_UpgradeFromV423(int currVersion, int newVersion)
 }
 
 /**
- *  Upgrade from V422 to V423
+ * Upgrade from V422 to V423
  */
 static BOOL H_UpgradeFromV422(int currVersion, int newVersion)
 {
@@ -1152,7 +1220,7 @@ static BOOL H_UpgradeFromV421(int currVersion, int newVersion)
 }
 
 /**
- *  Upgrade from V420 to V421
+ * Upgrade from V420 to V421
  */
 static BOOL H_UpgradeFromV420(int currVersion, int newVersion)
 {
@@ -1197,7 +1265,7 @@ static BOOL H_UpgradeFromV420(int currVersion, int newVersion)
    return TRUE;
 }
 
-/*
+/**
  * Upgrade from V419 to V420
  */
 static BOOL H_UpgradeFromV419(int currVersion, int newVersion)
@@ -1220,7 +1288,7 @@ static BOOL H_UpgradeFromV418(int currVersion, int newVersion)
 }
 
 /**
- *  Upgrade from V417 to V418
+ * Upgrade from V417 to V418
  */
 static BOOL H_UpgradeFromV417(int currVersion, int newVersion)
 {
@@ -11302,6 +11370,7 @@ static struct
    { 430, 431, H_UpgradeFromV430 },
    { 431, 432, H_UpgradeFromV431 },
    { 432, 433, H_UpgradeFromV432 },
+   { 433, 434, H_UpgradeFromV433 },
    { 0, 0, NULL }
 };