GUID added to event templates; server side event template related code refactored
authorVictor Kirhenshtein <victor@netxms.org>
Sun, 24 Apr 2016 13:40:56 +0000 (16:40 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Sun, 24 Apr 2016 13:40:56 +0000 (16:40 +0300)
14 files changed:
include/netxmsdb.h
include/nms_util.h
sql/events.in
sql/schema.in
src/server/core/dcitem.cpp
src/server/core/ef.cpp
src/server/core/epp.cpp
src/server/core/events.cpp
src/server/core/import.cpp
src/server/core/session.cpp
src/server/core/syslogd.cpp
src/server/include/nms_events.h
src/server/tools/nxdbmgr/upgrade.cpp
tools/generate_guids.pl [new file with mode: 0755]

index 4095bdd..0422899 100644 (file)
@@ -23,6 +23,6 @@
 #ifndef _netxmsdb_h
 #define _netxmsdb_h
 
-#define DB_FORMAT_VERSION   396
+#define DB_FORMAT_VERSION   397
 
 #endif
index 2e67186..a65ce07 100644 (file)
@@ -819,6 +819,25 @@ public:
    Iterator<V> *iterator() { return new Iterator<V>(new HashMapIterator(this)); }
 };
 
+/**
+ * Hash map template for holding reference counting objects as values
+ */
+template <class K, class V> class RefCountHashMap : public HashMapBase
+{
+private:
+   static void destructor(void *object) { ((V*)object)->decRefCount(); }
+
+public:
+   RefCountHashMap(bool objectOwner = false) : HashMapBase(objectOwner, sizeof(K)) { m_objectDestructor = destructor; }
+
+   V *get(const K& key) { V *v = (V*)_get(&key); v->incRefCount(); return v; }
+   void set(const K& key, V *value) { value->incRefCount(); _set(&key, (void *)value); }
+   void remove(const K& key) { _remove(&key); }
+   bool contains(const K& key) { return _contains(&key); }
+
+   Iterator<V> *iterator() { return new Iterator<V>(new HashMapIterator(this)); }
+};
+
 /**
  * Byte stream
  */
index 70ce79b..bb7a906 100644 (file)
 ** System events
 */
 
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_NODE_ADDED, 'SYS_NODE_ADDED',
+               EVENT_NODE_ADDED, 'SYS_NODE_ADDED', '8d34acfd-dad6-4f6e-b6a8-1189683591ef',
                EVENT_SEVERITY_NORMAL, 1,
                'Node added',
                'Generated when new node object added to the database.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   1) "Discovered" flag - set to 1 if this node was added by network discovery process'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_SUBNET_ADDED, 'SYS_SUBNET_ADDED',
+               EVENT_SUBNET_ADDED, 'SYS_SUBNET_ADDED', '75fc3f8b-768f-46b4-bf44-72949436a679',
                EVENT_SEVERITY_NORMAL, 0,
                'Subnet %2 added',
                'Generated when new subnet object added to the database.' CONCAT CRLF CONCAT
@@ -39,9 +39,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   3) IP address' CONCAT CRLF CONCAT
                '   4) Network mask'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_INTERFACE_ADDED, 'SYS_IF_ADDED',
+               EVENT_INTERFACE_ADDED, 'SYS_IF_ADDED', '33cb8f9c-9427-459c-8a71-45c73f5cc183',
                EVENT_SEVERITY_NORMAL, 1,
                'Interface "%2" added (IP Addr: %3/%4, IfIndex: %5)',
                'Generated when new interface object added to the database.' CONCAT CRLF CONCAT
@@ -53,9 +53,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   4) Interface netmask' CONCAT CRLF CONCAT
                '   5) Interface index'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_INTERFACE_UP, 'SYS_IF_UP',
+               EVENT_INTERFACE_UP, 'SYS_IF_UP', '09ee209a-0e75-434f-b8c8-399d93305d7b',
                EVENT_SEVERITY_NORMAL, 1,
                'Interface "%2" changed state to UP (IP Addr: %3/%4, IfIndex: %5)',
                'Generated when interface goes up.' CONCAT CRLF CONCAT
@@ -67,9 +67,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   4) Interface netmask' CONCAT CRLF CONCAT
                '   5) Interface index'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_INTERFACE_DOWN, 'SYS_IF_DOWN',
+               EVENT_INTERFACE_DOWN, 'SYS_IF_DOWN', 'd9a6d46d-97f8-48eb-a86a-2c0f6b150d0d',
                EVENT_SEVERITY_MINOR, 1,
                'Interface "%2" changed state to DOWN (IP Addr: %3/%4, IfIndex: %5)',
                'Generated when interface goes down.' CONCAT CRLF CONCAT
@@ -81,9 +81,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   4) Interface netmask' CONCAT CRLF CONCAT
                '   5) Interface index'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_INTERFACE_UNKNOWN, 'SYS_IF_UNKNOWN',
+               EVENT_INTERFACE_UNKNOWN, 'SYS_IF_UNKNOWN', 'ecb47be1-f911-4c1f-9b00-d0d21694071d',
                EVENT_SEVERITY_WARNING, 1,
                'Interface "%2" changed state to UNKNOWN (IP Addr: %3/%4, IfIndex: %5)',
                'Generated when interface goes to unknown state.' CONCAT CRLF CONCAT
@@ -95,9 +95,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   4) Interface netmask' CONCAT CRLF CONCAT
                '   5) Interface index'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_INTERFACE_DISABLED, 'SYS_IF_DISABLED',
+               EVENT_INTERFACE_DISABLED, 'SYS_IF_DISABLED', '2f3123a2-425f-47db-9c6b-9bc05a7fba2d',
                EVENT_SEVERITY_NORMAL, 1,
                'Interface "%2" disabled (IP Addr: %3/%4, IfIndex: %5)',
                'Generated when interface administratively disabled.' CONCAT CRLF CONCAT
@@ -109,9 +109,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   4) Interface netmask' CONCAT CRLF CONCAT
                '   5) Interface index'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_INTERFACE_TESTING, 'SYS_IF_TESTING',
+               EVENT_INTERFACE_TESTING, 'SYS_IF_TESTING', 'eb500e5c-3560-4394-8f5f-80aa67036f13',
                EVENT_SEVERITY_NORMAL, 1,
                'Interface "%2" is testing (IP Addr: %3/%4, IfIndex: %5)',
                'Generated when interface goes to testing state.' CONCAT CRLF CONCAT
@@ -123,9 +123,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   4) Interface netmask' CONCAT CRLF CONCAT
                '   5) Interface index'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_INTERFACE_UNEXPECTED_UP, 'SYS_IF_UNEXPECTED_UP',
+               EVENT_INTERFACE_UNEXPECTED_UP, 'SYS_IF_UNEXPECTED_UP', 'ff21a165-9253-4ecc-929a-ffd1e388d504',
                EVENT_SEVERITY_MAJOR, 1,
                'Interface "%2" unexpectedly changed state to UP (IP Addr: %3/%4, IfIndex: %5)',
                'Generated when interface goes up but it''s expected state set to DOWN.' CONCAT CRLF CONCAT
@@ -137,9 +137,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   4) Interface netmask' CONCAT CRLF CONCAT
                '   5) Interface index'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_INTERFACE_EXPECTED_DOWN, 'SYS_IF_EXPECTED_DOWN',
+               EVENT_INTERFACE_EXPECTED_DOWN, 'SYS_IF_EXPECTED_DOWN', '911358f4-d2a1-4465-94d7-ce4bc5c38860',
                EVENT_SEVERITY_NORMAL, 1,
                'Interface "%2" with expected state DOWN changed state to DOWN (IP Addr: %3/%4, IfIndex: %5)',
                'Generated when interface goes down and it''s expected state is DOWN.' CONCAT CRLF CONCAT
@@ -151,72 +151,72 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   4) Interface netmask' CONCAT CRLF CONCAT
                '   5) Interface index'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_NODE_NORMAL, 'SYS_NODE_NORMAL',
+               EVENT_NODE_NORMAL, 'SYS_NODE_NORMAL', '03bc11c0-ec20-43be-be45-e60846f744dc',
                EVENT_SEVERITY_NORMAL, 1,
                'Node status changed to NORMAL',
                'Generated when node status changed to normal.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   1) Previous node status'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_NODE_WARNING, 'SYS_NODE_WARNING',
+               EVENT_NODE_WARNING, 'SYS_NODE_WARNING', '1c80deab-aafb-43a7-93a7-1330dd563b47',
                EVENT_SEVERITY_WARNING, 1,
                'Node status changed to WARNING',
                'Generated when node status changed to "Warning".' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   1) Previous node status'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_NODE_MINOR, 'SYS_NODE_MINOR',
+               EVENT_NODE_MINOR, 'SYS_NODE_MINOR', '84eaea00-4ed7-41eb-9079-b783e5c60651',
                EVENT_SEVERITY_MINOR, 1,
                'Node status changed to MINOR',
                'Generated when node status changed to "Minor Problem" (informational).' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   1) Previous node status'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_NODE_MAJOR, 'SYS_NODE_MAJOR',
+               EVENT_NODE_MAJOR, 'SYS_NODE_MAJOR', '27035c88-c27a-4c16-97b3-4658d34a5f63',
                EVENT_SEVERITY_MAJOR, 1,
                'Node status changed to MAJOR',
                'Generated when node status changed to "Major Problem".' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   1) Previous node status'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_NODE_CRITICAL, 'SYS_NODE_CRITICAL',
+               EVENT_NODE_CRITICAL, 'SYS_NODE_CRITICAL', '8f2e98f8-1cd4-4e12-b41f-48b5c60ebe8e',
                EVENT_SEVERITY_CRITICAL, 1,
                'Node status changed to CRITICAL',
                'Generated when node status changed to critical.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   1) Previous node status'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_NODE_UNKNOWN, 'SYS_NODE_UNKNOWN',
+               EVENT_NODE_UNKNOWN, 'SYS_NODE_UNKNOWN', '6933cce0-fe1f-4123-817f-af1fb9f0eab4',
                EVENT_SEVERITY_NORMAL, 1,
                'Node status changed to UNKNOWN',
                'Generated when node status changed to unknown.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   1) Previous node status'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_NODE_UNMANAGED, 'SYS_NODE_UNMANAGED',
+               EVENT_NODE_UNMANAGED, 'SYS_NODE_UNMANAGED', 'a8356ba7-51b7-4487-b74e-d12132db233c',
                EVENT_SEVERITY_NORMAL, 1,
                'Node status changed to UNMANAGED',
                'Generated when node status changed to unmanaged.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   1) Previous node status'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_NODE_FLAGS_CHANGED, 'SYS_NODE_CAP_CHANGED',
+               EVENT_NODE_FLAGS_CHANGED, 'SYS_NODE_CAP_CHANGED', 'b04e39f5-d3a7-4d9a-b594-37132f5eaf34',
                EVENT_SEVERITY_NORMAL, 0,
                'Node capabilities changed (Old: %1; New: %2)',
                'Generated when node capabilities changed.' CONCAT CRLF CONCAT
@@ -224,27 +224,27 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   1) Old capabilities' CONCAT CRLF CONCAT
                '   2) New capabilities'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_SNMP_FAIL, 'SYS_SNMP_UNREACHABLE',
+               EVENT_SNMP_FAIL, 'SYS_SNMP_UNREACHABLE', 'd2fc3b0c-1215-4a92-b8f3-47df5d753602',
                EVENT_SEVERITY_MAJOR, 1,
                'SNMP agent is not responding',
                'Generated when node''s SNMP agent is not responding.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   No message-specific parameters'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_AGENT_FAIL, 'SYS_AGENT_UNREACHABLE',
+               EVENT_AGENT_FAIL, 'SYS_AGENT_UNREACHABLE', 'ba484457-3594-418e-a72a-65336055d025',
                EVENT_SEVERITY_MAJOR, 1,
                'Native agent is not responding',
                'Generated when node''s native agent is not responding.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   No message-specific parameters'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_INTERFACE_DELETED, 'SYS_IF_DELETED',
+               EVENT_INTERFACE_DELETED, 'SYS_IF_DELETED', 'ad7e9856-e361-4095-9361-ccc462d93624',
                EVENT_SEVERITY_NORMAL, 1,
                'Interface "%2" deleted (IP Addr: %3/%4, IfIndex: %1)',
                'Generated when interface object deleted from the database.' CONCAT CRLF CONCAT
@@ -255,18 +255,18 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   3) Interface IP address' CONCAT CRLF CONCAT
                '   4) Interface netmask'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_THRESHOLD_REACHED, 'SYS_THRESHOLD_REACHED',
+               EVENT_THRESHOLD_REACHED, 'SYS_THRESHOLD_REACHED', '05161c3d-7ceb-406f-af0a-af5c77f324a5',
                EVENT_SEVERITY_WARNING, 1,
                'Threshold reached for data collection item "%2" (Parameter: %1; Threshold value: %3; Actual value: %4)',
                'Generated when threshold value reached for specific data collection item.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                THRESHOLD_EVENT_PARAMS
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_THRESHOLD_REARMED, 'SYS_THRESHOLD_REARMED',
+               EVENT_THRESHOLD_REARMED, 'SYS_THRESHOLD_REARMED', '25eef3a7-6158-4c5e-b4e3-8a7aa7ade73c',
                EVENT_SEVERITY_NORMAL, 1,
                'Threshold rearmed for data collection item %2 (Parameter: %1)',
                'Generated when threshold check is rearmed for specific data collection item.' CONCAT CRLF CONCAT
@@ -278,9 +278,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   5) Threshold value' CONCAT CRLF CONCAT
                '   6) Actual value'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_SUBNET_DELETED, 'SYS_SUBNET_DELETED',
+               EVENT_SUBNET_DELETED, 'SYS_SUBNET_DELETED', 'af188eb3-e84f-4fd9-aecf-f1ba934a9f1a',
                EVENT_SEVERITY_NORMAL, 0,
                'Subnet %2 deleted',
                'Generated when subnet object deleted from the database.' CONCAT CRLF CONCAT
@@ -290,27 +290,27 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   3) IP address' CONCAT CRLF CONCAT
                '   4) Network mask'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_THREAD_HANGS, 'SYS_THREAD_HANG',
+               EVENT_THREAD_HANGS, 'SYS_THREAD_HANG', 'df247d13-a63a-43fe-bb02-cb41718ee387',
                EVENT_SEVERITY_CRITICAL, 1,
                'Thread "%1" is not responding',
                'Generated when one of the system threads hangs or stops unexpectedly.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   1) Thread name'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_THREAD_RUNNING, 'SYS_THREAD_RUNNING',
+               EVENT_THREAD_RUNNING, 'SYS_THREAD_RUNNING', '5589f6ce-7133-44db-8e7a-e1452d636a9a',
                EVENT_SEVERITY_NORMAL, 1,
                'Thread "%1" was returned to running state',
                'Generated when one of the system threads which previously hangs or stops unexpectedly was returned to running state.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   1) Thread name'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_SMTP_FAILURE, 'SYS_SMTP_FAILURE',
+               EVENT_SMTP_FAILURE, 'SYS_SMTP_FAILURE', '1e376009-0d26-4b86-87a2-f4715a02fb38',
                EVENT_SEVERITY_WARNING, 1,
                'Unable to send e-mail to <%3>: %2',
                'Generated when server is unable to send e-mail.' CONCAT CRLF CONCAT
@@ -320,9 +320,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   3) Recipient address' CONCAT CRLF CONCAT
                '   4) Mail subject'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_MAC_ADDR_CHANGED, 'SYS_MAC_ADDR_CHANGED',
+               EVENT_MAC_ADDR_CHANGED, 'SYS_MAC_ADDR_CHANGED', '61916ef0-1eee-4df7-a95b-150928d47962',
                EVENT_SEVERITY_WARNING, 1,
                'MAC address for interface %3 changed from %4 to %5',
                'Generated when server detects change of interface''s MAC address.' CONCAT CRLF CONCAT
@@ -333,9 +333,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   4) Old MAC address' CONCAT CRLF CONCAT
                '   5) New MAC address'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_INCORRECT_NETMASK, 'SYS_INCORRECT_NETMASK',
+               EVENT_INCORRECT_NETMASK, 'SYS_INCORRECT_NETMASK', '86c08c55-416e-4ac4-bf2b-302b5fddbd68',
                EVENT_SEVERITY_MINOR, 1,
                'Invalid network mask /%4 on interface "%3", should be /%5',
                'Generated when server detects invalid network mask on an interface.' CONCAT CRLF CONCAT
@@ -346,27 +346,27 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   4) Actual network mask on interface' CONCAT CRLF CONCAT
                '   5) Correct network mask'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_NODE_DOWN, 'SYS_NODE_DOWN',
+               EVENT_NODE_DOWN, 'SYS_NODE_DOWN', 'ce34f0d0-5b21-48c2-8788-8ed5ee547023',
                EVENT_SEVERITY_CRITICAL, 1,
                'Node down',
                'Generated when node is not responding to management server.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   1) Previous state (1 if node was marked as UNREACHABLE, 0 if it was marked as DOWN)'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_NODE_UP, 'SYS_NODE_UP',
+               EVENT_NODE_UP, 'SYS_NODE_UP', '05f180b6-62e7-4bc4-8a8d-34540214254b',
                EVENT_SEVERITY_NORMAL, 1,
                'Node up',
                'Generated when communication with the node re-established.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   No event-specific parameters'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_SERVICE_DOWN, 'SYS_SERVICE_DOWN',
+               EVENT_SERVICE_DOWN, 'SYS_SERVICE_DOWN', '89caacb5-d2cf-493b-862f-cddbfecac5b6',
                EVENT_SEVERITY_MAJOR, 1,
                'Network service "%1" is not responding',
                'Generated when network service is not responding to management server as expected.' CONCAT CRLF CONCAT
@@ -375,9 +375,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   2) Service object ID' CONCAT CRLF CONCAT
                '   3) Service type'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_SERVICE_UP, 'SYS_SERVICE_UP',
+               EVENT_SERVICE_UP, 'SYS_SERVICE_UP', 'ab35e7c7-2428-44db-ad43-57fe551bb8cc',
                EVENT_SEVERITY_NORMAL, 1,
                'Network service "%1" returned to operational state',
                'Generated when network service responds as expected after failure.' CONCAT CRLF CONCAT
@@ -386,9 +386,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   2) Service object ID' CONCAT CRLF CONCAT
                '   3) Service type'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_SERVICE_UNKNOWN, 'SYS_SERVICE_UNKNOWN',
+               EVENT_SERVICE_UNKNOWN, 'SYS_SERVICE_UNKNOWN', 'd891adae-49fe-4442-a8f3-0ca37ca8820a',
                EVENT_SEVERITY_WARNING, 1,
                'Status of network service "%1" is unknown',
                'Generated when management server is unable to determine state of the network service due to agent or server-to-agent communication failure.' CONCAT CRLF CONCAT
@@ -397,36 +397,36 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   2) Service object ID' CONCAT CRLF CONCAT
                '   3) Service type'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_SMS_FAILURE, 'SYS_SMS_FAILURE',
+               EVENT_SMS_FAILURE, 'SYS_SMS_FAILURE', 'c349bf75-458a-4d43-9c27-f71ea4bb06e2',
                EVENT_SEVERITY_WARNING, 1,
                'Unable to send SMS to phone %1',
                'Generated when server is unable to send SMS.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   1) Phone number'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_SNMP_OK, 'SYS_SNMP_OK',
+               EVENT_SNMP_OK, 'SYS_SNMP_OK', 'a821086b-1595-40db-9148-8d770d30a54b',
                EVENT_SEVERITY_NORMAL, 1,
                'Connectivity with SNMP agent restored',
                'Generated when connectivity with node''s SNMP agent restored.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   No message-specific parameters'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_AGENT_OK, 'SYS_AGENT_OK',
+               EVENT_AGENT_OK, 'SYS_AGENT_OK', '9c15299a-f2e3-4440-84c5-b17dea87ae2a',
                EVENT_SEVERITY_NORMAL, 1,
                'Connectivity with native agent restored',
                'Generated when connectivity with node''s native agent restored.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   No message-specific parameters'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_SCRIPT_ERROR, 'SYS_SCRIPT_ERROR',
+               EVENT_SCRIPT_ERROR, 'SYS_SCRIPT_ERROR', '2cc78efe-357a-4278-932f-91e36754c775',
                EVENT_SEVERITY_MINOR, 1,
                'Script (%1) execution error: %2',
                'Generated when server encounters NXSL script execution error.' CONCAT CRLF CONCAT
@@ -435,9 +435,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   2) Error text' CONCAT CRLF CONCAT
                '   3) DCI ID if script is DCI transformation script, or 0 otherwise'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_CONDITION_ACTIVATED, 'SYS_CONDITION_ACTIVATED',
+               EVENT_CONDITION_ACTIVATED, 'SYS_CONDITION_ACTIVATED', '16a86780-b73a-4601-929c-0c503bd06401',
                EVENT_SEVERITY_MINOR, 1,
                'Condition "%2" activated',
                'Default event for condition activation.' CONCAT CRLF CONCAT
@@ -447,9 +447,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   3) Previous condition status' CONCAT CRLF CONCAT
                '   4) Current condition status'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_CONDITION_DEACTIVATED, 'SYS_CONDITION_DEACTIVATED',
+               EVENT_CONDITION_DEACTIVATED, 'SYS_CONDITION_DEACTIVATED', '926d15d2-9761-4bb6-a1ce-64175303796f',
                EVENT_SEVERITY_NORMAL, 1,
                'Condition "%2" deactivated',
                'Default event for condition deactivation.' CONCAT CRLF CONCAT
@@ -459,27 +459,27 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   3) Previous condition status' CONCAT CRLF CONCAT
                '   4) Current condition status'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_DB_CONNECTION_LOST, 'SYS_DB_CONN_LOST',
+               EVENT_DB_CONNECTION_LOST, 'SYS_DB_CONN_LOST', '0311e9c8-8dcf-4a5b-9036-8cff034409ff',
                EVENT_SEVERITY_CRITICAL, 1,
                'Lost connection with backend database engine',
                'Generated if connection with backend database engine is lost.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   No message-specific parameters'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_DB_CONNECTION_RESTORED, 'SYS_DB_CONN_RESTORED',
+               EVENT_DB_CONNECTION_RESTORED, 'SYS_DB_CONN_RESTORED', 'd36259a7-5f6b-4e3c-bb6f-17d1f8ac950d',
                EVENT_SEVERITY_NORMAL, 1,
                'Connection with backend database engine restored',
                'Generated when connection with backend database engine restored.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   No message-specific parameters'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_CLUSTER_RESOURCE_MOVED, 'SYS_CLUSTER_RESOURCE_MOVED',
+               EVENT_CLUSTER_RESOURCE_MOVED, 'SYS_CLUSTER_RESOURCE_MOVED', '44abe5f3-a7c9-4fbd-8d10-53be172eae83',
                EVENT_SEVERITY_WARNING, 1,
                'Cluster resource "%2" moved from node %4 to node %6',
                'Generated when cluster resource moved between nodes.' CONCAT CRLF CONCAT
@@ -491,9 +491,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   5) New owner node ID' CONCAT CRLF CONCAT
                '   6) New owner node name'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_CLUSTER_RESOURCE_DOWN, 'SYS_CLUSTER_RESOURCE_DOWN',
+               EVENT_CLUSTER_RESOURCE_DOWN, 'SYS_CLUSTER_RESOURCE_DOWN', 'c3b1d4b5-2e41-4a2f-b379-9d74ebba3a25',
                EVENT_SEVERITY_MAJOR, 1,
                'Cluster resource "%2" is down (last owner was %4)',
                'Generated when cluster resource goes down.' CONCAT CRLF CONCAT
@@ -503,9 +503,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   3) Last owner node ID' CONCAT CRLF CONCAT
                '   4) Last owner node name'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_CLUSTER_RESOURCE_UP, 'SYS_CLUSTER_RESOURCE_UP',
+               EVENT_CLUSTER_RESOURCE_UP, 'SYS_CLUSTER_RESOURCE_UP', 'ef6fff96-0cbb-4030-aeba-2473a80c6568',
                EVENT_SEVERITY_NORMAL, 1,
                'Cluster resource "%2" is up (new owner is %4)',
                'Generated when cluster resource goes up.' CONCAT CRLF CONCAT
@@ -515,27 +515,27 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   3) New owner node ID' CONCAT CRLF CONCAT
                '   4) New owner node name'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_CLUSTER_DOWN, 'SYS_CLUSTER_DOWN',
+               EVENT_CLUSTER_DOWN, 'SYS_CLUSTER_DOWN', '8f14d0f7-08d4-4422-92f4-469e5eef93ef',
                EVENT_SEVERITY_CRITICAL, 1,
                'Cluster is down',
                'Generated when cluster goes down.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   No message-specific parameters'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_CLUSTER_UP, 'SYS_CLUSTER_UP',
+               EVENT_CLUSTER_UP, 'SYS_CLUSTER_UP', '4a9cdb65-aa44-42f2-99b0-1e302aec10f6',
                EVENT_SEVERITY_NORMAL, 1,
                'Cluster is up',
                'Generated when cluster goes up.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   No message-specific parameters'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_ALARM_TIMEOUT, 'SYS_ALARM_TIMEOUT',
+               EVENT_ALARM_TIMEOUT, 'SYS_ALARM_TIMEOUT', '4ae4f601-327b-4ef8-9740-8600a1ba2acd',
                EVENT_SEVERITY_WARNING, 1,
                'Alarm timeout expired (ID: %1; Text: %2)',
                'Generated when alarm timeout expires.' CONCAT CRLF CONCAT
@@ -545,9 +545,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   3) Alarm key' CONCAT CRLF CONCAT
                '   4) Original event code'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_LOG_RECORD_MATCHED, 'SYS_LOG_RECORD_MATCHED',
+               EVENT_LOG_RECORD_MATCHED, 'SYS_LOG_RECORD_MATCHED', 'd9326159-5c60-410f-990e-fae88df7fdd4',
                EVENT_SEVERITY_WARNING, 1,
                'Log record matched (Policy: %1; File: %2; Record: %4)',
                'Default event for log record match.' CONCAT CRLF CONCAT
@@ -559,9 +559,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   5 .. 9) Reserved' CONCAT CRLF CONCAT
                '   10 .. 99) Substrings extracted by regular expression'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_EVENT_STORM_DETECTED, 'SYS_EVENT_STORM_DETECTED',
+               EVENT_EVENT_STORM_DETECTED, 'SYS_EVENT_STORM_DETECTED', 'c98d8575-d134-4044-ba67-75c5f5d0f6e0',
                EVENT_SEVERITY_MAJOR, 1,
                'Event storm detected (Events per second: %1)',
                'Generated when system detects an event storm.' CONCAT CRLF CONCAT
@@ -570,9 +570,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   2) Duration' CONCAT CRLF CONCAT
                '   3) Threshold'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_EVENT_STORM_ENDED, 'SYS_EVENT_STORM_ENDED',
+               EVENT_EVENT_STORM_ENDED, 'SYS_EVENT_STORM_ENDED', 'dfd5e3ba-3182-4deb-bc32-9e6b8c1c6546',
                EVENT_SEVERITY_NORMAL, 1,
                'Event storm ended',
                'Generated when system clears event storm condition.' CONCAT CRLF CONCAT
@@ -581,27 +581,27 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   2) Duration' CONCAT CRLF CONCAT
                '   3) Threshold'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_NETWORK_CONNECTION_LOST, 'SYS_NETWORK_CONN_LOST',
+               EVENT_NETWORK_CONNECTION_LOST, 'SYS_NETWORK_CONN_LOST', '3cb0921a-87a1-46e4-8be1-82ad2dda0015',
                EVENT_SEVERITY_CRITICAL, 1,
                'NetXMS server network connectivity lost',
                'Generated when system detects loss of network connectivity based on beacon probing.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   1) Number of beacons'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_NETWORK_CONNECTION_RESTORED, 'SYS_NETWORK_CONN_RESTORED',
+               EVENT_NETWORK_CONNECTION_RESTORED, 'SYS_NETWORK_CONN_RESTORED', '1c61b3e0-389a-47ac-8469-932a907392bc',
                EVENT_SEVERITY_NORMAL, 1,
                'NetXMS server network connectivity restored',
                'Generated when system detects restoration of network connectivity based on beacon probing.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   1) Number of beacons'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_DB_QUERY_FAILED, 'SYS_DB_QUERY_FAILED',
+               EVENT_DB_QUERY_FAILED, 'SYS_DB_QUERY_FAILED', '5f35d646-63b6-4dcd-b94a-e2ccd060686a',
                EVENT_SEVERITY_CRITICAL, 1,
                'Database query failed (Query: %1; Error: %2)',
                'Generated when SQL query to backend database failed.' CONCAT CRLF CONCAT
@@ -609,9 +609,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   1) Query' CONCAT CRLF CONCAT
                '   2) Error message'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_DCI_UNSUPPORTED, 'SYS_DCI_UNSUPPORTED',
+               EVENT_DCI_UNSUPPORTED, 'SYS_DCI_UNSUPPORTED', '28367b5b-1541-4526-8cbe-91a17ed31ba4',
                EVENT_SEVERITY_MINOR, 1,
                'Status of DCI %1 (%5: %2) changed to UNSUPPORTED',
                'Generated when DCI status changed to UNSUPPORTED.' CONCAT CRLF CONCAT
@@ -622,9 +622,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   4) DCI Origin code' CONCAT CRLF CONCAT
                '   5) DCI Origin name'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_DCI_DISABLED, 'SYS_DCI_DISABLED',
+               EVENT_DCI_DISABLED, 'SYS_DCI_DISABLED', '50196042-0619-4420-9471-16b7c25c0213',
                EVENT_SEVERITY_WARNING, 1,
                'Status of DCI %1 (%5: %2) changed to DISABLED',
                'Generated when DCI status changed to DISABLED.' CONCAT CRLF CONCAT
@@ -635,9 +635,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   4) DCI Origin code' CONCAT CRLF CONCAT
                '   5) DCI Origin name'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_DCI_ACTIVE, 'SYS_DCI_ACTIVE',
+               EVENT_DCI_ACTIVE, 'SYS_DCI_ACTIVE', '740b6810-b355-46f4-a921-65118504af18',
                EVENT_SEVERITY_NORMAL, 1,
                'Status of DCI %1 (%5: %2) changed to ACTIVE',
                'Generated when DCI status changed to ACTIVE.' CONCAT CRLF CONCAT
@@ -648,9 +648,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   4) DCI Origin code' CONCAT CRLF CONCAT
                '   5) DCI Origin name'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_IP_ADDRESS_CHANGED, 'SYS_IP_ADDRESS_CHANGED',
+               EVENT_IP_ADDRESS_CHANGED, 'SYS_IP_ADDRESS_CHANGED', '517b6d2a-f5c6-46aa-969d-48e62e05e3bf',
                EVENT_SEVERITY_WARNING, 1,
                'Primary IP address changed from %2 to %1',
                'Generated when primary IP address changed (usually because of primary name change or DNS change).' CONCAT CRLF CONCAT
@@ -659,9 +659,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   2) Old IP address' CONCAT CRLF CONCAT
                '   3) Primary host name'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_8021X_PAE_STATE_CHANGED, 'SYS_8021X_PAE_STATE_CHANGED',
+               EVENT_8021X_PAE_STATE_CHANGED, 'SYS_8021X_PAE_STATE_CHANGED', '3c69667b-04dd-434a-a5b7-cf322abcb9c9',
                EVENT_SEVERITY_NORMAL, 1,
                'Port %6 PAE state changed from %4 to %2',
                'Generated when switch port PAE state changed.' CONCAT CRLF CONCAT
@@ -673,9 +673,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   5) Interface index' CONCAT CRLF CONCAT
                '   6) Interface name'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_8021X_BACKEND_STATE_CHANGED, 'SYS_8021X_BACKEND_STATE_CHANGED',
+               EVENT_8021X_BACKEND_STATE_CHANGED, 'SYS_8021X_BACKEND_STATE_CHANGED', 'e7cddb93-e42d-479d-9c5b-d68d4be71319',
                EVENT_SEVERITY_NORMAL, 1,
                'Port %6 backend authentication state changed from %4 to %2',
                'Generated when switch port backend authentication state changed.' CONCAT CRLF CONCAT
@@ -687,9 +687,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   5) Interface index' CONCAT CRLF CONCAT
                '   6) Interface name'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_8021X_PAE_FORCE_UNAUTH, 'SYS_8021X_PAE_FORCE_UNAUTH',
+               EVENT_8021X_PAE_FORCE_UNAUTH, 'SYS_8021X_PAE_FORCE_UNAUTH', '16a59549-2b06-4938-9e79-1c3d9445d65c',
                EVENT_SEVERITY_MAJOR, 1,
                'Port %2 switched to force unauthorize state',
                'Generated when switch port PAE state changed to FORCE UNAUTHORIZE.' CONCAT CRLF CONCAT
@@ -697,9 +697,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   1) Interface index' CONCAT CRLF CONCAT
                '   2) Interface name'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_8021X_AUTH_FAILED, 'SYS_8021X_AUTH_FAILED',
+               EVENT_8021X_AUTH_FAILED, 'SYS_8021X_AUTH_FAILED', '8ac56c8e-150b-40d1-998a-c63e7d6596b8',
                EVENT_SEVERITY_MAJOR, 1,
                '802.1x authentication failed on port %2',
                'Generated when switch port backend authentication state changed to FAIL.' CONCAT CRLF CONCAT
@@ -707,9 +707,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   1) Interface index' CONCAT CRLF CONCAT
                '   2) Interface name'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_8021X_AUTH_TIMEOUT, 'SYS_8021X_AUTH_TIMEOUT',
+               EVENT_8021X_AUTH_TIMEOUT, 'SYS_8021X_AUTH_TIMEOUT', '609a2198-2ea4-4d07-8100-587d550a5670',
                EVENT_SEVERITY_MAJOR, 1,
                '802.1x authentication time out on port %2',
                'Generated when switch port backend authentication state changed to TIMEOUT.' CONCAT CRLF CONCAT
@@ -717,9 +717,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   1) Interface index' CONCAT CRLF CONCAT
                '   2) Interface name'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_CONTAINER_AUTOBIND, 'SYS_CONTAINER_AUTOBIND',
+               EVENT_CONTAINER_AUTOBIND, 'SYS_CONTAINER_AUTOBIND', '611133e2-1f76-446f-b278-9d500a823611',
                EVENT_SEVERITY_NORMAL, 1,
                'Node %2 automatically bound to container %4',
                'Generated when node bound to container object by autobind rule.' CONCAT CRLF CONCAT
@@ -729,9 +729,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   3) Container ID' CONCAT CRLF CONCAT
                '   4) Container name'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_CONTAINER_AUTOUNBIND, 'SYS_CONTAINER_AUTOUNBIND',
+               EVENT_CONTAINER_AUTOUNBIND, 'SYS_CONTAINER_AUTOUNBIND', 'e57603be-0d81-41aa-b07c-12d08640561c',
                EVENT_SEVERITY_NORMAL, 1,
                'Node %2 automatically unbound from container %4',
                'Generated when node unbound from container object by autobind rule.' CONCAT CRLF CONCAT
@@ -741,9 +741,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   3) Container ID' CONCAT CRLF CONCAT
                '   4) Container name'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_TEMPLATE_AUTOAPPLY, 'SYS_TEMPLATE_AUTOAPPLY',
+               EVENT_TEMPLATE_AUTOAPPLY, 'SYS_TEMPLATE_AUTOAPPLY', 'bf084945-f928-4428-8c6c-d2965addc832',
                EVENT_SEVERITY_NORMAL, 1,
                'Template %4 automatically applied to node %2',
                'Generated when template applied to node by autoapply rule.' CONCAT CRLF CONCAT
@@ -753,9 +753,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   3) Template ID' CONCAT CRLF CONCAT
                '   4) Template name'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_TEMPLATE_AUTOREMOVE, 'SYS_TEMPLATE_AUTOREMOVE',
+               EVENT_TEMPLATE_AUTOREMOVE, 'SYS_TEMPLATE_AUTOREMOVE', '8f7a4b4a-d0a2-4404-9b66-fdbc029f42cf',
                EVENT_SEVERITY_NORMAL, 1,
                'Template %4 automatically removed from node %2',
                'Generated when template removed from node by autoapply rule.' CONCAT CRLF CONCAT
@@ -765,18 +765,18 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   3) Template ID' CONCAT CRLF CONCAT
                '   4) Template name'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_NODE_UNREACHABLE, 'SYS_NODE_UNREACHABLE',
+               EVENT_NODE_UNREACHABLE, 'SYS_NODE_UNREACHABLE', '47bba2ce-c795-4e56-ad44-cbf05741e1ff',
                EVENT_SEVERITY_CRITICAL, 1,
                'Node unreachable because of network failure',
                'Generated when node is unreachable by management server because of network failure.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   No event-specific parameters'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_TABLE_THRESHOLD_ACTIVATED, 'SYS_TABLE_THRESHOLD_ACTIVATED',
+               EVENT_TABLE_THRESHOLD_ACTIVATED, 'SYS_TABLE_THRESHOLD_ACTIVATED', 'c08a1cfe-3128-40c2-99cc-378e7ef91f79',
                EVENT_SEVERITY_MINOR, 1,
                'Threshold activated on table "%2" row %4 (%5)',
                'Generated when table threshold is activated.' CONCAT CRLF CONCAT
@@ -787,9 +787,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   4) Table row' CONCAT CRLF CONCAT
                '   5) Instance'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_TABLE_THRESHOLD_DEACTIVATED, 'SYS_TABLE_THRESHOLD_DEACTIVATED',
+               EVENT_TABLE_THRESHOLD_DEACTIVATED, 'SYS_TABLE_THRESHOLD_DEACTIVATED', '479085e7-e1d1-4f2a-9d96-1d522f51b26a',
                EVENT_SEVERITY_NORMAL, 1,
                'Threshold deactivated on table "%2" row %4 (%5)',
                'Generated when table threshold is deactivated.' CONCAT CRLF CONCAT
@@ -800,9 +800,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   4) Table row' CONCAT CRLF CONCAT
                '   5) Instance'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_IF_PEER_CHANGED, 'SYS_IF_PEER_CHANGED',
+               EVENT_IF_PEER_CHANGED, 'SYS_IF_PEER_CHANGED', 'a3a5c1df-9d96-4e98-9e06-b3157dbf39f0',
                EVENT_SEVERITY_NORMAL, 1,
                'New peer for interface %3 is %7 interface %10 (%12)',
                'Generated when peer information for interface changes.' CONCAT CRLF CONCAT
@@ -821,9 +821,9 @@ 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
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_AP_ADOPTED, 'SYS_AP_ADOPTED',
+               EVENT_AP_ADOPTED, 'SYS_AP_ADOPTED', '5aaee261-0c5d-44e0-b2f0-223bbba5297d',
                EVENT_SEVERITY_NORMAL, 1,
                'Access point %2 changed state to ADOPTED',
                'Generated when access point state changes to ADOPTED.' CONCAT CRLF CONCAT
@@ -836,9 +836,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '    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
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_AP_UNADOPTED, 'SYS_AP_UNADOPTED',
+               EVENT_AP_UNADOPTED, 'SYS_AP_UNADOPTED', '846a3581-aad1-4e17-9c55-9bd2e6b1247b',
                EVENT_SEVERITY_MAJOR, 1,
                'Access point %2 changed state to UNADOPTED',
                'Generated when access point state changes to UNADOPTED.' CONCAT CRLF CONCAT
@@ -851,9 +851,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '    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
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_AP_DOWN, 'SYS_AP_DOWN',
+               EVENT_AP_DOWN, 'SYS_AP_DOWN', '2c8c6208-d3ab-4b8c-926a-872f4d8abcee',
                EVENT_SEVERITY_CRITICAL, 1,
                'Access point %2 changed state to DOWN',
                'Generated when access point state changes to DOWN.' CONCAT CRLF CONCAT
@@ -867,9 +867,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '    7) Access point serial number'
        );
 
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
    (
-      EVENT_IF_MASK_CHANGED, 'SYS_IF_MASK_CHANGED',
+      EVENT_IF_MASK_CHANGED, 'SYS_IF_MASK_CHANGED', 'f800e593-057e-4aec-9e47-be0f7718c5c4',
       EVENT_SEVERITY_NORMAL, 1,
       'Interface "%2" changed mask from /%6 to /%4 (IP Addr: %3/%4, IfIndex: %5)',
       'Generated when when network mask on interface is corrected.' CONCAT CRLF CONCAT
@@ -882,9 +882,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
       '   6) Interface old mask'
    );
 
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
    (
-      EVENT_IF_IPADDR_ADDED, 'SYS_IF_IPADDR_ADDED',
+      EVENT_IF_IPADDR_ADDED, 'SYS_IF_IPADDR_ADDED', '475bdca6-543e-410b-9aff-c217599e0fe6',
       EVENT_SEVERITY_NORMAL, 1,
       'IP address %3/%4 added to interface "%2"',
       'Generated when IP address added to interface.' CONCAT CRLF CONCAT
@@ -896,9 +896,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
       '   5) Interface index'
    );
    
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
    (
-      EVENT_IF_IPADDR_DELETED, 'SYS_IF_IPADDR_DELETED',
+      EVENT_IF_IPADDR_DELETED, 'SYS_IF_IPADDR_DELETED', 'ef477387-eb50-4a1a-bf90-717502b9873c',
       EVENT_SEVERITY_NORMAL, 1,
       'IP address %3/%4 deleted from interface "%2"',
       'Generated when IP address deleted from interface.' CONCAT CRLF CONCAT
@@ -909,16 +909,16 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
       '   4) Network mask' CONCAT CRLF CONCAT
       '   5) Interface index'
    );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
    (
-      EVENT_MAINTENANCE_MODE_ENTERED, 'SYS_MAINTENANCE_MODE_ENTERED',
+      EVENT_MAINTENANCE_MODE_ENTERED, 'SYS_MAINTENANCE_MODE_ENTERED', '5f6c8b1c-f162-413e-8028-80e7ad2c362d',
       EVENT_SEVERITY_NORMAL, 1,
       'Entered maintenance mode',
       'Generated when node, cluster, or mobile device entered maintenance mode.'
    );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
    (
-      EVENT_MAINTENANCE_MODE_LEFT, 'SYS_MAINTENANCE_MODE_LEFT',
+      EVENT_MAINTENANCE_MODE_LEFT, 'SYS_MAINTENANCE_MODE_LEFT', 'cab06848-a622-430d-8b4c-addeea732657',
       EVENT_SEVERITY_NORMAL, 1,
       'Left maintenance mode',
       'Generated when node, cluster, or mobile device left maintenance mode.'
@@ -928,9 +928,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
 ** SNMP traps
 */
 
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_SNMP_UNMATCHED_TRAP, 'SNMP_UNMATCHED_TRAP',
+               EVENT_SNMP_UNMATCHED_TRAP, 'SNMP_UNMATCHED_TRAP', 'fc3613f7-d151-4221-9acd-d28b6f804335',
                EVENT_SEVERITY_NORMAL, 1,
                'SNMP trap received: %1 (Parameters: %2)',
                'Generated when system receives an SNMP trap without match in trap configuration table' CONCAT CRLF CONCAT
@@ -938,27 +938,27 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   1) SNMP trap OID' CONCAT CRLF CONCAT
                '   2) Trap parameters'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_SNMP_COLD_START, 'SNMP_COLD_START',
+               EVENT_SNMP_COLD_START, 'SNMP_COLD_START', '39920e99-97bd-4d61-a462-43f89ba6fbdf',
                EVENT_SEVERITY_NORMAL, 1,
                'System was cold-started',
                'Generated when system receives a coldStart SNMP trap' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   1) SNMP trap OID'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_SNMP_WARM_START, 'SNMP_WARM_START',
+               EVENT_SNMP_WARM_START, 'SNMP_WARM_START', '0aa888c1-eba6-4fe7-a37a-b85f2b373bdc',
                EVENT_SEVERITY_NORMAL, 1,
                'System was warm-started',
                'Generated when system receives a warmStart SNMP trap' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   1) SNMP trap OID'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_SNMP_LINK_DOWN, 'SNMP_LINK_DOWN',
+               EVENT_SNMP_LINK_DOWN, 'SNMP_LINK_DOWN', 'b71338cc-137d-473c-a0f1-6b131086af56',
                EVENT_SEVERITY_MAJOR, 1,
                'Link is down (interface index %2)',
                'Generated when system receives a linkDown SNMP trap' CONCAT CRLF CONCAT
@@ -966,9 +966,9 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   1) SNMP trap OID' CONCAT CRLF CONCAT
                '   2) Interface index'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_SNMP_LINK_UP, 'SNMP_LINK_UP',
+               EVENT_SNMP_LINK_UP, 'SNMP_LINK_UP', '03da14a7-e39c-4a46-a7cb-4bf77ec7936c',
                EVENT_SEVERITY_NORMAL, 1,
                'Link is up (interface index %2)',
                'Generated when system receives a linkUp SNMP trap' CONCAT CRLF CONCAT
@@ -976,18 +976,18 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
                '   1) SNMP trap OID' CONCAT CRLF CONCAT
                '   2) Interface index'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_SNMP_AUTH_FAILURE, 'SNMP_AUTH_FAILURE',
+               EVENT_SNMP_AUTH_FAILURE, 'SNMP_AUTH_FAILURE', '37020cb0-dde7-487b-9cfb-0d5ee771aa13',
                EVENT_SEVERITY_WARNING, 1,
                'SNMP authentication failure',
                'Generated when system receives an authenticationFailure SNMP trap' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                '   1) SNMP trap OID'
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               EVENT_SNMP_EGP_NL, 'SNMP_EGP_NEIGHBOR_LOSS',
+               EVENT_SNMP_EGP_NL, 'SNMP_EGP_NEIGHBOR_LOSS', 'aecf5fa4-390c-4125-be10-df8b0e669fe1',
                EVENT_SEVERITY_WARNING, 1,
                'EGP neighbor loss',
                'Generated when system receives an egpNeighborLoss SNMP trap' CONCAT CRLF CONCAT
@@ -1001,108 +1001,108 @@ INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description)
 ** These events can occupy ID space 4000 ... 4999
 */
 
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               4000, 'DC_HIGH_CPU_UTIL',
+               4000, 'DC_HIGH_CPU_UTIL', 'a1063661-6992-4536-bb11-38e40d72537f',
                EVENT_SEVERITY_MINOR, 1,
                'CPU utilization exceeds allowed maximum of %3 (Current: %4)',
                'Custom data collection threshold event.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                THRESHOLD_EVENT_PARAMS
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               4001, 'DC_HIGH_PROCLOAD',
+               4001, 'DC_HIGH_PROCLOAD', '6b438fb0-0bfa-4832-b020-8432a2a417d3',
                EVENT_SEVERITY_MINOR, 1,
                'Processor load average exceeds allowed maximum of %3 (Current: %4)',
                'Custom data collection threshold event.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                THRESHOLD_EVENT_PARAMS
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               4002, 'DC_HOST_RESTARTED',
+               4002, 'DC_HOST_RESTARTED', 'e0d27cf7-017d-4a73-ba53-bb6a4adcb9ee',
                EVENT_SEVERITY_NORMAL, 1,
                'Host was restarted within last 5 minutes',
                'Custom data collection threshold event.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                THRESHOLD_EVENT_PARAMS
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               4003, 'DC_AGENT_RESTARTED',
+               4003, 'DC_AGENT_RESTARTED', '191fc8fb-d10f-46c4-b100-1167074622e8',
                EVENT_SEVERITY_NORMAL, 1,
                'NetXMS agent was restarted within last 5 minutes',
                'Custom data collection threshold event.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                THRESHOLD_EVENT_PARAMS
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               4004, 'DC_SERVICE_NOT_RUNNING',
+               4004, 'DC_SERVICE_NOT_RUNNING', '69f9fb0b-c7cf-47dd-b1df-bfc2c5639678',
                EVENT_SEVERITY_MAJOR, 1,
                'Service "%6" is not running',
                'Custom data collection threshold event.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                THRESHOLD_EVENT_PARAMS
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               4005, 'DC_MAILBOX_TOO_LARGE',
+               4005, 'DC_MAILBOX_TOO_LARGE', '4d448490-88af-450a-a138-b127b89a0f06',
                EVENT_SEVERITY_WARNING, 1,
                'Mailbox "%6" exceeds size limit (allowed size: %3; actual size: %4)',
                'Custom data collection threshold event.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                THRESHOLD_EVENT_PARAMS
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               4006, 'DC_AGENT_VERSION_CHANGE',
+               4006, 'DC_AGENT_VERSION_CHANGE', 'e3c5d5e0-37c7-4b84-842e-22ad64a18692',
                EVENT_SEVERITY_NORMAL, 1,
                'NetXMS agent version was changed from %3 to %4',
                'Custom data collection threshold event.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                THRESHOLD_EVENT_PARAMS
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               4007, 'DC_HOSTNAME_CHANGE',
+               4007, 'DC_HOSTNAME_CHANGE', 'd9f6d75c-5924-4e91-94e1-e43e6adc72c7',
                EVENT_SEVERITY_WARNING, 1,
                'Host name was changed from %3 to %4',
                'Custom data collection threshold event.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                THRESHOLD_EVENT_PARAMS
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               4008, 'DC_FILE_CHANGE',
+               4008, 'DC_FILE_CHANGE', '9da39f09-b5d1-4b04-9b46-e4fb7e5751da',
                EVENT_SEVERITY_WARNING, 1,
                'File "%6" was changed',
                'Custom data collection threshold event.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                THRESHOLD_EVENT_PARAMS
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               4009, 'DC_HDD_TEMP_WARNING',
+               4009, 'DC_HDD_TEMP_WARNING', 'fe37a161-9411-4869-8b3c-81041694609a',
                EVENT_SEVERITY_WARNING, 1,
                'Temperature of hard disk %6 is above warning level of %3 (current: %4)',
                'Custom data collection threshold event.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                THRESHOLD_EVENT_PARAMS
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               4010, 'DC_HDD_TEMP_MAJOR',
+               4010, 'DC_HDD_TEMP_MAJOR', '8af75da6-69f6-4723-902f-d43b44d5fced',
                EVENT_SEVERITY_MAJOR, 1,
                'Temperature of hard disk %6 is above %3 (current: %4)',
                'Custom data collection threshold event.' CONCAT CRLF CONCAT
                'Parameters:' CONCAT CRLF CONCAT
                THRESHOLD_EVENT_PARAMS
        );
-INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES
+INSERT INTO event_cfg (event_code,event_name,guid,severity,flags,message,description) VALUES
        (
-               4011, 'DC_HDD_TEMP_CRITICAL',
+               4011, 'DC_HDD_TEMP_CRITICAL', 'ed2a5b3c-02a0-4d81-94c9-7dc6396d6256',
                EVENT_SEVERITY_CRITICAL, 1,
                'Temperature of hard disk %6 is above critical level of %3 (current: %4)',
                'Custom data collection threshold event.' CONCAT CRLF CONCAT
index 3c6f081..642bfbe 100644 (file)
@@ -1082,6 +1082,7 @@ CREATE TABLE event_cfg
 (
   event_code integer not null,
   event_name varchar(63) not null,  // Short event name
+  guid varchar(36) not null,
   severity integer not null,
   flags integer not null,
   message varchar(2000) null,   /* Message template */
@@ -1089,13 +1090,14 @@ CREATE TABLE event_cfg
   PRIMARY KEY(event_code)
 ) TABLE_TYPE;
 
-COMMENT_TABLE(event_cfg, '')
-COMMENT_COLUMN(event_cfg.event_code, '')
-COMMENT_COLUMN(event_cfg.event_name, '')
-COMMENT_COLUMN(event_cfg.severity, '')
-COMMENT_COLUMN(event_cfg.flags, '')
-COMMENT_COLUMN(event_cfg.message, '')
-COMMENT_COLUMN(event_cfg.description, '')
+COMMENT_TABLE(event_cfg, 'Event templates')
+COMMENT_COLUMN(event_cfg.event_code, 'Event code (unique within system)')
+COMMENT_COLUMN(event_cfg.event_name, 'Event name')
+COMMENT_COLUMN(event_cfg.guid, 'Event template GUID')
+COMMENT_COLUMN(event_cfg.severity, 'Severity')
+COMMENT_COLUMN(event_cfg.flags, 'Flags')
+COMMENT_COLUMN(event_cfg.message, 'Message template')
+COMMENT_COLUMN(event_cfg.description, 'Event description')
 
 /*
 ** Event log
index 249647e..083b10d 100644 (file)
@@ -475,9 +475,12 @@ void DCItem::checkThresholds(ItemValue &value)
                PostDciEventWithNames(t->getEventCode(), m_owner->getId(), m_id, "ssssisd",
                                           s_paramNamesReach, m_name, m_description, t->getStringValue(),
                   (const TCHAR *)checkValue, m_id, m_instance, 0);
-                                  EVENT_TEMPLATE *evt = FindEventTemplateByCode(t->getEventCode());
+                                  EventTemplate *evt = FindEventTemplateByCode(t->getEventCode());
                                   if (evt != NULL)
-                                          t->markLastEvent((int)evt->dwSeverity);
+                                  {
+                                          t->markLastEvent(evt->getSeverity());
+                                          evt->decRefCount();
+                                  }
                if (!(m_flags & DCF_ALL_THRESHOLDS))
                   i = m_thresholds->size();  // Stop processing
             }
@@ -497,9 +500,12 @@ void DCItem::checkThresholds(ItemValue &value)
                                           PostDciEventWithNames(t->getEventCode(), m_owner->getId(), m_id, "ssssisd",
                                                   s_paramNamesReach, m_name, m_description, t->getStringValue(),
                                                   (const TCHAR *)checkValue, m_id, m_instance, 1);
-                                          EVENT_TEMPLATE *evt = FindEventTemplateByCode(t->getEventCode());
+                                          EventTemplate *evt = FindEventTemplateByCode(t->getEventCode());
                                           if (evt != NULL)
-                                                  t->markLastEvent((int)evt->dwSeverity);
+                                          {
+                                                  t->markLastEvent(evt->getSeverity());
+                                                  evt->decRefCount();
+                                          }
                                   }
             }
                                if (!(m_flags & DCF_ALL_THRESHOLDS))
@@ -797,9 +803,12 @@ void DCItem::processNewError(bool noInstance)
                PostDciEventWithNames(t->getEventCode(), m_owner->getId(), m_id, "ssssisd",
                                           s_paramNamesReach, m_name, m_description, _T(""), _T(""),
                   m_id, m_instance, 0);
-                                  EVENT_TEMPLATE *evt = FindEventTemplateByCode(t->getEventCode());
+               EventTemplate *evt = FindEventTemplateByCode(t->getEventCode());
                                   if (evt != NULL)
-                                          t->markLastEvent((int)evt->dwSeverity);
+                                  {
+                                          t->markLastEvent(evt->getSeverity());
+                                          evt->decRefCount();
+                                  }
                if (!(m_flags & DCF_ALL_THRESHOLDS))
                {
                   i = m_thresholds->size();  // Stop processing
@@ -820,9 +829,12 @@ void DCItem::processNewError(bool noInstance)
                                           PostDciEventWithNames(t->getEventCode(), m_owner->getId(), m_id, "ssssisd",
                                                   s_paramNamesReach, m_name, m_description, _T(""), _T(""),
                                                   m_id, m_instance, 1);
-                                          EVENT_TEMPLATE *evt = FindEventTemplateByCode(t->getEventCode());
+                                          EventTemplate *evt = FindEventTemplateByCode(t->getEventCode());
                                           if (evt != NULL)
-                                                  t->markLastEvent((int)evt->dwSeverity);
+                                          {
+                                                  t->markLastEvent(evt->getSeverity());
+                                                  evt->decRefCount();
+                                          }
                                   }
             }
                                if (!(m_flags & DCF_ALL_THRESHOLDS))
index 1e15c56..a3a4305 100644 (file)
@@ -1,6 +1,6 @@
 /* 
 ** NetXMS - Network Management System
-** Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Victor Kirhenshtein
+** Copyright (C) 2003-2016 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
@@ -64,14 +64,13 @@ BOOL EF_ProcessMessage(ISCSession *session, NXCPMessage *request, NXCPMessage *r
                        name = request->getFieldAsString(VID_EVENT_NAME);
                        if (name != NULL)
                        {
-                               EVENT_TEMPLATE *pt;
-
                                DbgPrintf(5, _T("Event specified by name (%s)"), name);
-                               pt = FindEventTemplateByName(name);
+                               EventTemplate *pt = FindEventTemplateByName(name);
                                if (pt != NULL)
                                {
-                                       code = pt->dwCode;
+                                       code = pt->getCode();
                                        DbgPrintf(5, _T("Event name %s resolved to event code %d"), name, code);
+                                       pt->decRefCount();
                                }
                                else
                                {
index 8332706..f891ba7 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ** NetXMS - Network Management System
-** Copyright (C) 2003-2014 Victor Kirhenshtein
+** Copyright (C) 2003-2016 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
@@ -71,10 +71,11 @@ EPRule::EPRule(ConfigEntry *config)
       m_pdwEventList = (UINT32 *)malloc(sizeof(UINT32) * events->size());
       for(int i = 0; i < events->size(); i++)
       {
-         EVENT_TEMPLATE *e = FindEventTemplateByName(events->get(i)->getSubEntryValue(_T("name"), 0, _T("<unknown>")));
+         EventTemplate *e = FindEventTemplateByName(events->get(i)->getSubEntryValue(_T("name"), 0, _T("<unknown>")));
          if (e != NULL)
          {
-            m_pdwEventList[m_dwNumEvents++] = e->dwCode;
+            m_pdwEventList[m_dwNumEvents++] = e->getCode();
+            e->decRefCount();
          }
       }
    }
index 121f728..1f77bb4 100644 (file)
@@ -1,6 +1,6 @@
 /* 
 ** NetXMS - Network Management System
-** Copyright (C) 2003-2015 Victor Kirhenshtein
+** Copyright (C) 2003-2016 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
@@ -31,10 +31,31 @@ EventPolicy *g_pEventPolicy = NULL;
 /**
  * Static data
  */
-static UINT32 m_dwNumTemplates = 0;
-static EVENT_TEMPLATE *m_pEventTemplates = NULL;
+static RefCountHashMap<UINT32, EventTemplate> m_eventTemplates(true);
 static RWLOCK m_rwlockTemplateAccess;
 
+/**
+ * Create event template from DB record
+ */
+EventTemplate::EventTemplate(DB_RESULT hResult, int row)
+{
+   m_code = DBGetFieldULong(hResult, row, 0);
+   m_severity = DBGetFieldLong(hResult, row, 1);
+   m_flags = DBGetFieldLong(hResult, row, 2);
+   m_messageTemplate = DBGetField(hResult, row, 3, NULL, 0);
+   m_description = DBGetField(hResult, row, 4, NULL, 0);
+   DBGetField(hResult, row, 5, m_name, MAX_EVENT_NAME);
+}
+
+/**
+ * Event template destructor
+ */
+EventTemplate::~EventTemplate()
+{
+   free(m_messageTemplate);
+   free(m_description);
+}
+
 /**
  * Default constructor for event
  */
@@ -85,15 +106,15 @@ Event::Event(const Event *src)
 /**
  * Construct event from template
  */
-Event::Event(EVENT_TEMPLATE *pTemplate, UINT32 sourceId, UINT32 dciId, const TCHAR *userTag, const char *szFormat, const TCHAR **names, va_list args)
+Event::Event(const EventTemplate *eventTemplate, UINT32 sourceId, UINT32 dciId, const TCHAR *userTag, const char *szFormat, const TCHAR **names, va_list args)
 {
-       _tcscpy(m_name, pTemplate->szName);
+       _tcscpy(m_name, eventTemplate->getName());
    m_timeStamp = time(NULL);
    m_id = CreateUniqueEventId();
    m_rootId = 0;
-   m_code = pTemplate->dwCode;
-   m_severity = pTemplate->dwSeverity;
-   m_flags = pTemplate->dwFlags;
+   m_code = eventTemplate->getCode();
+   m_severity = eventTemplate->getSeverity();
+   m_flags = eventTemplate->getFlags();
    m_sourceId = sourceId;
    m_dciId = dciId;
    m_messageText = NULL;
@@ -185,7 +206,7 @@ Event::Event(EVENT_TEMPLATE *pTemplate, UINT32 sourceId, UINT32 dciId, const TCH
       }
    }
 
-   m_messageTemplate = _tcsdup(pTemplate->pszMessageTemplate);
+   m_messageTemplate = _tcsdup(eventTemplate->getMessageTemplate());
 }
 
 /**
@@ -685,19 +706,15 @@ static bool LoadEvents()
 {
    bool success = false;
    DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
-   DB_RESULT hResult = DBSelect(hdb, _T("SELECT event_code,severity,flags,message,description,event_name FROM event_cfg ORDER BY event_code"));
+   DB_RESULT hResult = DBSelect(hdb, _T("SELECT event_code,severity,flags,message,description,event_name FROM event_cfg"));
    if (hResult != NULL)
    {
-      m_dwNumTemplates = DBGetNumRows(hResult);
-      m_pEventTemplates = (EVENT_TEMPLATE *)malloc(sizeof(EVENT_TEMPLATE) * m_dwNumTemplates);
-      for(UINT32 i = 0; i < m_dwNumTemplates; i++)
+      int count = DBGetNumRows(hResult);
+      for(int i = 0; i < count; i++)
       {
-         m_pEventTemplates[i].dwCode = DBGetFieldULong(hResult, i, 0);
-         m_pEventTemplates[i].dwSeverity = DBGetFieldLong(hResult, i, 1);
-         m_pEventTemplates[i].dwFlags = DBGetFieldLong(hResult, i, 2);
-         m_pEventTemplates[i].pszMessageTemplate = DBGetField(hResult, i, 3, NULL, 0);
-         m_pEventTemplates[i].pszDescription = DBGetField(hResult, i, 4, NULL, 0);
-         DBGetField(hResult, i, 5, m_pEventTemplates[i].szName, MAX_EVENT_NAME);
+         EventTemplate *t = new EventTemplate(hResult, i);
+         m_eventTemplates.set(t->getCode(), t);
+         t->decRefCount();
       }
 
       DBFreeResult(hResult);
@@ -750,20 +767,6 @@ void ShutdownEventSubsystem()
 {
    delete g_pEventQueue;
    delete g_pEventPolicy;
-
-   if (m_pEventTemplates != NULL)
-   {
-      UINT32 i;
-      for(i = 0; i < m_dwNumTemplates; i++)
-      {
-         safe_free(m_pEventTemplates[i].pszDescription);
-         safe_free(m_pEventTemplates[i].pszMessageTemplate);
-      }
-      free(m_pEventTemplates);
-   }
-   m_dwNumTemplates = 0;
-   m_pEventTemplates = NULL;
-
    RWLockDestroy(m_rwlockTemplateAccess);
 }
 
@@ -772,20 +775,8 @@ void ShutdownEventSubsystem()
  */
 void ReloadEvents()
 {
-   UINT32 i;
-
    RWLockWriteLock(m_rwlockTemplateAccess, INFINITE);
-   if (m_pEventTemplates != NULL)
-   {
-      for(i = 0; i < m_dwNumTemplates; i++)
-      {
-         safe_free(m_pEventTemplates[i].pszDescription);
-         safe_free(m_pEventTemplates[i].pszMessageTemplate);
-      }
-      free(m_pEventTemplates);
-   }
-   m_dwNumTemplates = 0;
-   m_pEventTemplates = NULL;
+   m_eventTemplates.clear();
    LoadEvents();
    RWLockUnlock(m_rwlockTemplateAccess);
 }
@@ -795,55 +786,11 @@ void ReloadEvents()
  */
 void DeleteEventTemplateFromList(UINT32 eventCode)
 {
-   UINT32 i;
-
    RWLockWriteLock(m_rwlockTemplateAccess, INFINITE);
-   for(i = 0; i < m_dwNumTemplates; i++)
-   {
-      if (m_pEventTemplates[i].dwCode == eventCode)
-      {
-         m_dwNumTemplates--;
-         safe_free(m_pEventTemplates[i].pszDescription);
-         safe_free(m_pEventTemplates[i].pszMessageTemplate);
-         memmove(&m_pEventTemplates[i], &m_pEventTemplates[i + 1],
-                 sizeof(EVENT_TEMPLATE) * (m_dwNumTemplates - i));
-         break;
-      }
-   }
+   m_eventTemplates.remove(eventCode);
    RWLockUnlock(m_rwlockTemplateAccess);
 }
 
-/**
- * Perform binary search on event template by id
- * Returns INULL if key not found or pointer to appropriate template
- */
-static EVENT_TEMPLATE *FindEventTemplate(UINT32 eventCode)
-{
-   UINT32 dwFirst, dwLast, dwMid;
-
-   dwFirst = 0;
-   dwLast = m_dwNumTemplates - 1;
-
-   if ((eventCode < m_pEventTemplates[0].dwCode) || (eventCode > m_pEventTemplates[dwLast].dwCode))
-      return NULL;
-
-   while(dwFirst < dwLast)
-   {
-      dwMid = (dwFirst + dwLast) / 2;
-      if (eventCode == m_pEventTemplates[dwMid].dwCode)
-         return &m_pEventTemplates[dwMid];
-      if (eventCode < m_pEventTemplates[dwMid].dwCode)
-         dwLast = dwMid - 1;
-      else
-         dwFirst = dwMid + 1;
-   }
-
-   if (eventCode == m_pEventTemplates[dwLast].dwCode)
-      return &m_pEventTemplates[dwLast];
-
-   return NULL;
-}
-
 /**
  * Post event to given event queue.
  *
@@ -869,27 +816,24 @@ static EVENT_TEMPLATE *FindEventTemplate(UINT32 eventCode)
 static bool RealPostEvent(Queue *queue, UINT64 *eventId, UINT32 eventCode, UINT32 sourceId, UINT32 dciId,
                           const TCHAR *userTag, const char *format, const TCHAR **names, va_list args)
 {
-   EVENT_TEMPLATE *eventTemplate = NULL;
+   EventTemplate *eventTemplate = NULL;
    bool success = false;
 
    RWLockReadLock(m_rwlockTemplateAccess, INFINITE);
 
-   // Find event template
-   if (m_dwNumTemplates > 0)    // Is there any templates?
+   eventTemplate = m_eventTemplates.get(eventCode);
+   if (eventTemplate != NULL)
    {
-      eventTemplate = FindEventTemplate(eventCode);
-      if (eventTemplate != NULL)
-      {
-         // Template found, create new event
-         Event *evt = new Event(eventTemplate, sourceId, dciId, userTag, format, names, args);
-         if (eventId != NULL)
-            *eventId = evt->getId();
+      // Template found, create new event
+      Event *evt = new Event(eventTemplate, sourceId, dciId, userTag, format, names, args);
+      if (eventId != NULL)
+         *eventId = evt->getId();
 
-         // Add new event to queue
-         queue->put(evt);
+      // Add new event to queue
+      queue->put(evt);
 
-         success = true;
-      }
+      eventTemplate->decRefCount();
+      success = true;
    }
 
    RWLockUnlock(m_rwlockTemplateAccess);
@@ -1212,29 +1156,28 @@ void NXCORE_EXPORTABLE ResendEvents(Queue *queue)
  */
 void CreateNXMPEventRecord(String &str, UINT32 eventCode)
 {
-   EVENT_TEMPLATE *p;
    String strText, strDescr;
 
    RWLockReadLock(m_rwlockTemplateAccess, INFINITE);
 
    // Find event template
-   if (m_dwNumTemplates > 0)    // Is there any templates?
+   EventTemplate *p = m_eventTemplates.get(eventCode);
+   if (p != NULL)
    {
-      p = FindEventTemplate(eventCode);
-      if (p != NULL)
-      {
-         str.appendFormattedString(_T("\t\t<event id=\"%d\">\n")
-                                              _T("\t\t\t<name>%s</name>\n")
-                                _T("\t\t\t<code>%d</code>\n")
-                                _T("\t\t\t<severity>%d</severity>\n")
-                                _T("\t\t\t<flags>%d</flags>\n")
-                                _T("\t\t\t<message>%s</message>\n")
-                                _T("\t\t\t<description>%s</description>\n")
-                                _T("\t\t</event>\n"),
-                                                                                 p->dwCode, (const TCHAR *)EscapeStringForXML2(p->szName), p->dwCode, p->dwSeverity,
-                                p->dwFlags, (const TCHAR *)EscapeStringForXML2(p->pszMessageTemplate),
-                                                                                 (const TCHAR *)EscapeStringForXML2(p->pszDescription));
-      }
+      str.appendFormattedString(_T("\t\t<event id=\"%d\">\n")
+                             _T("\t\t\t<name>%s</name>\n")
+                             _T("\t\t\t<code>%d</code>\n")
+                             _T("\t\t\t<guid>%d</guid>\n")
+                             _T("\t\t\t<severity>%d</severity>\n")
+                             _T("\t\t\t<flags>%d</flags>\n")
+                             _T("\t\t\t<message>%s</message>\n")
+                             _T("\t\t\t<description>%s</description>\n")
+                             _T("\t\t</event>\n"),
+                             p->getCode(), (const TCHAR *)EscapeStringForXML2(p->getName()),
+                             (const TCHAR *)p->getGuid().toString(), p->getCode(), p->getSeverity(),
+                             p->getFlags(), (const TCHAR *)EscapeStringForXML2(p->getMessageTemplate()),
+                             (const TCHAR *)EscapeStringForXML2(p->getDescription()));
+      p->decRefCount();
    }
 
    RWLockUnlock(m_rwlockTemplateAccess);
@@ -1243,30 +1186,22 @@ void CreateNXMPEventRecord(String &str, UINT32 eventCode)
 /**
  * Resolve event name
  */
-BOOL EventNameFromCode(UINT32 eventCode, TCHAR *pszBuffer)
+bool EventNameFromCode(UINT32 eventCode, TCHAR *buffer)
 {
-   EVENT_TEMPLATE *p;
-   BOOL bRet = FALSE;
+   bool bRet = false;
 
    RWLockReadLock(m_rwlockTemplateAccess, INFINITE);
 
-   // Find event template
-   if (m_dwNumTemplates > 0)    // Is there any templates?
+   EventTemplate *p = m_eventTemplates.get(eventCode);
+   if (p != NULL)
    {
-      p = FindEventTemplate(eventCode);
-      if (p != NULL)
-      {
-         _tcscpy(pszBuffer, p->szName);
-         bRet = TRUE;
-      }
-      else
-      {
-         _tcscpy(pszBuffer, _T("UNKNOWN_EVENT"));
-      }
+      _tcscpy(buffer, p->getName());
+      p->decRefCount();
+      bRet = true;
    }
    else
    {
-      _tcscpy(pszBuffer, _T("UNKNOWN_EVENT"));
+      _tcscpy(buffer, _T("UNKNOWN_EVENT"));
    }
 
    RWLockUnlock(m_rwlockTemplateAccess);
@@ -1276,12 +1211,10 @@ BOOL EventNameFromCode(UINT32 eventCode, TCHAR *pszBuffer)
 /**
  * Find event template by code - suitable for external call
  */
-EVENT_TEMPLATE *FindEventTemplateByCode(UINT32 eventCode)
+EventTemplate *FindEventTemplateByCode(UINT32 eventCode)
 {
-   EVENT_TEMPLATE *p = NULL;
-
    RWLockReadLock(m_rwlockTemplateAccess, INFINITE);
-   p = FindEventTemplate(eventCode);
+   EventTemplate *p = m_eventTemplates.get(eventCode);
    RWLockUnlock(m_rwlockTemplateAccess);
    return p;
 }
@@ -1289,22 +1222,26 @@ EVENT_TEMPLATE *FindEventTemplateByCode(UINT32 eventCode)
 /**
  * Find event template by name - suitable for external call
  */
-EVENT_TEMPLATE *FindEventTemplateByName(const TCHAR *name)
+EventTemplate *FindEventTemplateByName(const TCHAR *name)
 {
-   EVENT_TEMPLATE *p = NULL;
+   EventTemplate *result = NULL;
    UINT32 i;
 
    RWLockReadLock(m_rwlockTemplateAccess, INFINITE);
-   for(i = 0; i < m_dwNumTemplates; i++)
+   Iterator<EventTemplate> *it = m_eventTemplates.iterator();
+   while(it->hasNext())
    {
-      if (!_tcscmp(m_pEventTemplates[i].szName, name))
+      EventTemplate *t = it->next();
+      if (!_tcscmp(t->getName(), name))
       {
-         p = &m_pEventTemplates[i];
+         result = t;
+         result->incRefCount();
          break;
       }
    }
+   delete it;
    RWLockUnlock(m_rwlockTemplateAccess);
-   return p;
+   return result;
 }
 
 /**
@@ -1313,8 +1250,12 @@ EVENT_TEMPLATE *FindEventTemplateByName(const TCHAR *name)
  */
 UINT32 NXCORE_EXPORTABLE EventCodeFromName(const TCHAR *name, UINT32 defaultValue)
 {
-       EVENT_TEMPLATE *p = FindEventTemplateByName(name);
-       return (p != NULL) ? p->dwCode : defaultValue;
+       EventTemplate *p = FindEventTemplateByName(name);
+       if (p == NULL)
+          return defaultValue;
+       UINT32 code = p->getCode();
+       p->decRefCount();
+       return code;
 }
 
 /**
index 4ab441b..a699244 100644 (file)
@@ -1,6 +1,6 @@
 /* 
 ** NetXMS - Network Management System
-** Copyright (C) 2003-2015 Victor Kirhenshtein
+** Copyright (C) 2003-2016 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
@@ -154,9 +154,10 @@ bool ValidateConfig(Config *config, UINT32 flags, TCHAR *errorText, int errorTex
                                ConfigEntry *e = event->findEntry(_T("name"));
                                if (e != NULL)
                                {
-                                       EVENT_TEMPLATE *pEvent = FindEventTemplateByName(e->getValue());
+                                  EventTemplate *pEvent = FindEventTemplateByName(e->getValue());
                                        if (pEvent != NULL)
                                        {
+                                          pEvent->decRefCount();
                                                if (!(flags & CFG_IMPORT_REPLACE_EVENT_BY_NAME))
                                                {
                                                        _sntprintf(errorText, errorTextLen, _T("Event with name %s already exist"), e->getValue());
@@ -172,15 +173,17 @@ bool ValidateConfig(Config *config, UINT32 flags, TCHAR *errorText, int errorTex
                        }
                        else
                        {
-                               EVENT_TEMPLATE *pEvent = FindEventTemplateByCode(code);
+                          EventTemplate *pEvent = FindEventTemplateByCode(code);
                                if (pEvent != NULL)
                                {
                                        if (!(flags & CFG_IMPORT_REPLACE_EVENT_BY_CODE))
                                        {
                                                _sntprintf(errorText, errorTextLen, _T("Event with code %d already exist (existing event name: %s; new event name: %s)"),
-                                                          pEvent->dwCode, pEvent->szName, event->getSubEntryValue(_T("name"), 0, _T("<unnamed>")));
+                                                          pEvent->getCode(), pEvent->getName(), event->getSubEntryValue(_T("name"), 0, _T("<unnamed>")));
+                                               pEvent->decRefCount();
                                                goto stop_processing;
                                        }
+               pEvent->decRefCount();
                                }
                        }
                }
@@ -257,10 +260,10 @@ static UINT32 ImportEvent(ConfigEntry *event)
    else
    {
       _sntprintf(query, 8192, _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,")
-                              _T("message,description) VALUES (%d,%s,%d,%d,%s,%s)"),
+                              _T("message,description,guid) VALUES (%d,%s,%d,%d,%s,%s,'%s')"),
                  code, (const TCHAR *)DBPrepareString(hdb, name), event->getSubEntryValueAsInt(_T("severity")),
                                          event->getSubEntryValueAsInt(_T("flags")), (const TCHAR *)DBPrepareString(hdb, msg),
-                                         (const TCHAR *)DBPrepareString(hdb, descr));
+                                         (const TCHAR *)DBPrepareString(hdb, descr), (const TCHAR *)uuid::generate().toString());
    }
        UINT32 rcc = DBQuery(hdb, query) ? RCC_SUCCESS : RCC_DB_FAILURE;
 
@@ -273,18 +276,18 @@ static UINT32 ImportEvent(ConfigEntry *event)
  */
 static UINT32 ImportTrap(ConfigEntry *trap)
 {
-       NXC_TRAP_CFG_ENTRY tc;
-       EVENT_TEMPLATE *event;
-
-       event = FindEventTemplateByName(trap->getSubEntryValue(_T("event"), 0, _T("")));
+       EventTemplate *event = FindEventTemplateByName(trap->getSubEntryValue(_T("event"), 0, _T("")));
        if (event == NULL)
                return RCC_INTERNAL_ERROR;
 
+   NXC_TRAP_CFG_ENTRY tc;
        memset(&tc, 0, sizeof(NXC_TRAP_CFG_ENTRY));
-       tc.dwEventCode = event->dwCode;
+       tc.dwEventCode = event->getCode();
        nx_strncpy(tc.szDescription, trap->getSubEntryValue(_T("description"), 0, _T("")), MAX_DB_STRING);
        nx_strncpy(tc.szUserTag, trap->getSubEntryValue(_T("userTag"), 0, _T("")), MAX_USERTAG_LENGTH);
 
+       event->decRefCount();
+
        UINT32 oid[256];
        tc.dwOidLen = (UINT32)SNMPParseOID(trap->getSubEntryValue(_T("oid"), 0, _T("")), oid, 256);
        tc.pdwObjectId = oid;
index e8a440e..38f7d3f 100644 (file)
@@ -2074,7 +2074,7 @@ void ClientSession::modifyEventTemplate(NXCPMessage *pRequest)
             }
             else
             {
-               hStmt = DBPrepare(hdb, _T("INSERT INTO event_cfg (event_name,severity,flags,message,description,event_code) VALUES (?,?,?,?,?,?)"));
+               hStmt = DBPrepare(hdb, _T("INSERT INTO event_cfg (event_name,severity,flags,message,description,event_code,guid) VALUES (?,?,?,?,?,?,?)"));
             }
 
             if (hStmt != NULL)
@@ -2085,6 +2085,10 @@ void ClientSession::modifyEventTemplate(NXCPMessage *pRequest)
                DBBind(hStmt, 4, DB_SQLTYPE_VARCHAR, pRequest->getFieldAsString(VID_MESSAGE), DB_BIND_DYNAMIC, MAX_EVENT_MSG_LENGTH - 1);
                DBBind(hStmt, 5, DB_SQLTYPE_TEXT, pRequest->getFieldAsString(VID_DESCRIPTION), DB_BIND_DYNAMIC);
                DBBind(hStmt, 6, DB_SQLTYPE_INTEGER, dwEventCode);
+               if (!bEventExist)
+               {
+                  DBBind(hStmt, 7, DB_SQLTYPE_VARCHAR, uuid::generate());
+               }
 
                if (DBExecute(hStmt))
                {
index 1c71fcd..4a257d0 100644 (file)
@@ -499,13 +499,12 @@ static void SyslogParserCallback(UINT32 eventCode, const TCHAR *eventName, const
  */
 static bool EventNameResolver(const TCHAR *name, UINT32 *code)
 {
-       EVENT_TEMPLATE *event;
        bool success = false;
-
-       event = FindEventTemplateByName(name);
+       EventTemplate *event = FindEventTemplateByName(name);
        if (event != NULL)
        {
-               *code = event->dwCode;
+               *code = event->getCode();
+               event->decRefCount();
                success = true;
        }
        return success;
index 1089468..201465d 100644 (file)
 /**
  * Event template
  */
-struct EVENT_TEMPLATE
+class EventTemplate : public RefCountObject
 {
-   UINT32 dwCode;
-   UINT32 dwSeverity;
-   UINT32 dwFlags;
-   TCHAR *pszMessageTemplate;
-   TCHAR *pszDescription;
-   TCHAR szName[MAX_EVENT_NAME];
+private:
+   UINT32 m_code;
+   int m_severity;
+   uuid m_guid;
+   TCHAR m_name[MAX_EVENT_NAME];
+   UINT32 m_flags;
+   TCHAR *m_messageTemplate;
+   TCHAR *m_description;
+
+protected:
+   virtual ~EventTemplate();
+
+public:
+   EventTemplate(DB_RESULT hResult, int row);
+
+   UINT32 getCode() const { return m_code; }
+   int getSeverity() const { return m_severity; }
+   const uuid& getGuid() const { return m_guid; }
+   const TCHAR *getName() const { return m_name; }
+   UINT32 getFlags() const { return m_flags; }
+   const TCHAR *getMessageTemplate() const { return m_messageTemplate; }
+   const TCHAR *getDescription() const { return m_description; }
 };
 
 /**
@@ -71,7 +87,7 @@ private:
 public:
    Event();
    Event(const Event *src);
-   Event(EVENT_TEMPLATE *pTemplate, UINT32 sourceId, UINT32 dciId, const TCHAR *userTag, const char *format, const TCHAR **names, va_list args);
+   Event(const EventTemplate *eventTemplate, UINT32 sourceId, UINT32 dciId, const TCHAR *userTag, const char *format, const TCHAR **names, va_list args);
    ~Event();
 
    UINT64 getId() const { return m_id; }
@@ -211,10 +227,10 @@ void DeleteEventTemplateFromList(UINT32 eventCode);
 void CorrelateEvent(Event *pEvent);
 void CreateNXMPEventRecord(String &str, UINT32 eventCode);
 
-BOOL EventNameFromCode(UINT32 eventCode, TCHAR *pszBuffer);
+bool EventNameFromCode(UINT32 eventCode, TCHAR *buffer);
 UINT32 NXCORE_EXPORTABLE EventCodeFromName(const TCHAR *name, UINT32 defaultValue = 0);
-EVENT_TEMPLATE *FindEventTemplateByCode(UINT32 eventCode);
-EVENT_TEMPLATE *FindEventTemplateByName(const TCHAR *pszName);
+EventTemplate *FindEventTemplateByCode(UINT32 eventCode);
+EventTemplate *FindEventTemplateByName(const TCHAR *pszName);
 
 bool NXCORE_EXPORTABLE PostEvent(UINT32 eventCode, UINT32 sourceId, const char *format, ...);
 bool NXCORE_EXPORTABLE PostDciEvent(UINT32 eventCode, UINT32 sourceId, UINT32 dciId, const char *format, ...);
index 606cdc7..f695fcc 100644 (file)
  */
 BOOL MigrateMaps();
 
+/**
+ * Pre-defined GUID mapping for GenerateGUID
+ */
+struct GUID_MAPPING
+{
+   UINT32 id;
+   const TCHAR *guid;
+};
+
 /**
  * Generate GUIDs
  */
-static bool GenerateGUID(const TCHAR *table, const TCHAR *idColumn, const TCHAR *guidColumn)
+static bool GenerateGUID(const TCHAR *table, const TCHAR *idColumn, const TCHAR *guidColumn, const GUID_MAPPING *mapping)
 {
    TCHAR query[256];
    _sntprintf(query, 256, _T("SELECT %s FROM %s"), idColumn, table);
@@ -39,15 +48,29 @@ static bool GenerateGUID(const TCHAR *table, const TCHAR *idColumn, const TCHAR
        if (hResult == NULL)
       return false;
 
+   uuid_t guid;
+   TCHAR buffer[64];
+
        int count = DBGetNumRows(hResult);
        for(int i = 0; i < count; i++)
        {
-               uuid_t guid;
-               TCHAR buffer[64];
-
-               _uuid_generate(guid);
-               _sntprintf(query, 256, _T("UPDATE %s SET %s='%s' WHERE %s=%d"),
-                          table, guidColumn, _uuid_to_string(guid, buffer), idColumn, DBGetFieldULong(hResult, i, 0));
+               const TCHAR *guidText = NULL;
+               UINT32 id = DBGetFieldULong(hResult, i, 0);
+               if (mapping != NULL)
+               {
+                  for(int j = 0; mapping[j].guid != NULL; j++)
+                     if (mapping[j].id == id)
+                     {
+                        guidText = mapping[j].guid;
+                        break;
+                     }
+               }
+               if (guidText == NULL)
+               {
+                  _uuid_generate(guid);
+                  guidText = _uuid_to_string(guid, buffer);
+               }
+               _sntprintf(query, 256, _T("UPDATE %s SET %s='%s' WHERE %s=%d"), table, guidColumn, guidText, idColumn, id);
                if (!SQLQuery(query))
       {
        DBFreeResult(hResult);
@@ -641,6 +664,102 @@ static int NextFreeEPPruleID()
        return ruleId;
 }
 
+/**
+ * Upgrade from V396 to V397
+ */
+static BOOL H_UpgradeFromV396(int currVersion, int newVersion)
+{
+   static GUID_MAPPING eventGuidMapping[] = {
+      { EVENT_NODE_ADDED, _T("8d34acfd-dad6-4f6e-b6a8-1189683591ef") },
+      { EVENT_SUBNET_ADDED, _T("75fc3f8b-768f-46b4-bf44-72949436a679") },
+      { EVENT_INTERFACE_ADDED, _T("33cb8f9c-9427-459c-8a71-45c73f5cc183") },
+      { EVENT_INTERFACE_UP, _T("09ee209a-0e75-434f-b8c8-399d93305d7b") },
+      { EVENT_INTERFACE_DOWN, _T("d9a6d46d-97f8-48eb-a86a-2c0f6b150d0d") },
+      { EVENT_INTERFACE_UNKNOWN, _T("ecb47be1-f911-4c1f-9b00-d0d21694071d") },
+      { EVENT_INTERFACE_DISABLED, _T("2f3123a2-425f-47db-9c6b-9bc05a7fba2d") },
+      { EVENT_INTERFACE_TESTING, _T("eb500e5c-3560-4394-8f5f-80aa67036f13") },
+      { EVENT_INTERFACE_UNEXPECTED_UP, _T("ff21a165-9253-4ecc-929a-ffd1e388d504") },
+      { EVENT_INTERFACE_EXPECTED_DOWN, _T("911358f4-d2a1-4465-94d7-ce4bc5c38860") },
+      { EVENT_NODE_NORMAL, _T("03bc11c0-ec20-43be-be45-e60846f744dc") },
+      { EVENT_NODE_WARNING, _T("1c80deab-aafb-43a7-93a7-1330dd563b47") },
+      { EVENT_NODE_MINOR, _T("84eaea00-4ed7-41eb-9079-b783e5c60651") },
+      { EVENT_NODE_MAJOR, _T("27035c88-c27a-4c16-97b3-4658d34a5f63") },
+      { EVENT_NODE_CRITICAL, _T("8f2e98f8-1cd4-4e12-b41f-48b5c60ebe8e") },
+      { EVENT_NODE_UNKNOWN, _T("6933cce0-fe1f-4123-817f-af1fb9f0eab4") },
+      { EVENT_NODE_UNMANAGED, _T("a8356ba7-51b7-4487-b74e-d12132db233c") },
+      { EVENT_NODE_FLAGS_CHANGED, _T("b04e39f5-d3a7-4d9a-b594-37132f5eaf34") },
+      { EVENT_SNMP_FAIL, _T("d2fc3b0c-1215-4a92-b8f3-47df5d753602") },
+      { EVENT_AGENT_FAIL, _T("ba484457-3594-418e-a72a-65336055d025") },
+      { EVENT_INTERFACE_DELETED, _T("ad7e9856-e361-4095-9361-ccc462d93624") },
+      { EVENT_THRESHOLD_REACHED, _T("05161c3d-7ceb-406f-af0a-af5c77f324a5") },
+      { EVENT_THRESHOLD_REARMED, _T("25eef3a7-6158-4c5e-b4e3-8a7aa7ade73c") },
+      { EVENT_SUBNET_DELETED, _T("af188eb3-e84f-4fd9-aecf-f1ba934a9f1a") },
+      { EVENT_THREAD_HANGS, _T("df247d13-a63a-43fe-bb02-cb41718ee387") },
+      { EVENT_THREAD_RUNNING, _T("5589f6ce-7133-44db-8e7a-e1452d636a9a") },
+      { EVENT_SMTP_FAILURE, _T("1e376009-0d26-4b86-87a2-f4715a02fb38") },
+      { EVENT_MAC_ADDR_CHANGED, _T("61916ef0-1eee-4df7-a95b-150928d47962") },
+      { EVENT_INCORRECT_NETMASK, _T("86c08c55-416e-4ac4-bf2b-302b5fddbd68") },
+      { EVENT_NODE_DOWN, _T("ce34f0d0-5b21-48c2-8788-8ed5ee547023") },
+      { EVENT_NODE_UP, _T("05f180b6-62e7-4bc4-8a8d-34540214254b") },
+      { EVENT_SERVICE_DOWN, _T("89caacb5-d2cf-493b-862f-cddbfecac5b6") },
+      { EVENT_SERVICE_UP, _T("ab35e7c7-2428-44db-ad43-57fe551bb8cc") },
+      { EVENT_SERVICE_UNKNOWN, _T("d891adae-49fe-4442-a8f3-0ca37ca8820a") },
+      { EVENT_SMS_FAILURE, _T("c349bf75-458a-4d43-9c27-f71ea4bb06e2") },
+      { EVENT_SNMP_OK, _T("a821086b-1595-40db-9148-8d770d30a54b") },
+      { EVENT_AGENT_OK, _T("9c15299a-f2e3-4440-84c5-b17dea87ae2a") },
+      { EVENT_SCRIPT_ERROR, _T("2cc78efe-357a-4278-932f-91e36754c775") },
+      { EVENT_CONDITION_ACTIVATED, _T("16a86780-b73a-4601-929c-0c503bd06401") },
+      { EVENT_CONDITION_DEACTIVATED, _T("926d15d2-9761-4bb6-a1ce-64175303796f") },
+      { EVENT_DB_CONNECTION_LOST, _T("0311e9c8-8dcf-4a5b-9036-8cff034409ff") },
+      { EVENT_DB_CONNECTION_RESTORED, _T("d36259a7-5f6b-4e3c-bb6f-17d1f8ac950d") },
+      { EVENT_CLUSTER_RESOURCE_MOVED, _T("44abe5f3-a7c9-4fbd-8d10-53be172eae83") },
+      { EVENT_CLUSTER_RESOURCE_DOWN, _T("c3b1d4b5-2e41-4a2f-b379-9d74ebba3a25") },
+      { EVENT_CLUSTER_RESOURCE_UP, _T("ef6fff96-0cbb-4030-aeba-2473a80c6568") },
+      { EVENT_CLUSTER_DOWN, _T("8f14d0f7-08d4-4422-92f4-469e5eef93ef") },
+      { EVENT_CLUSTER_UP, _T("4a9cdb65-aa44-42f2-99b0-1e302aec10f6") },
+      { EVENT_ALARM_TIMEOUT, _T("4ae4f601-327b-4ef8-9740-8600a1ba2acd") },
+      { EVENT_LOG_RECORD_MATCHED, _T("d9326159-5c60-410f-990e-fae88df7fdd4") },
+      { EVENT_EVENT_STORM_DETECTED, _T("c98d8575-d134-4044-ba67-75c5f5d0f6e0") },
+      { EVENT_EVENT_STORM_ENDED, _T("dfd5e3ba-3182-4deb-bc32-9e6b8c1c6546") },
+      { EVENT_NETWORK_CONNECTION_LOST, _T("3cb0921a-87a1-46e4-8be1-82ad2dda0015") },
+      { EVENT_NETWORK_CONNECTION_RESTORED, _T("1c61b3e0-389a-47ac-8469-932a907392bc") },
+      { EVENT_DB_QUERY_FAILED, _T("5f35d646-63b6-4dcd-b94a-e2ccd060686a") },
+      { EVENT_DCI_UNSUPPORTED, _T("28367b5b-1541-4526-8cbe-91a17ed31ba4") },
+      { EVENT_DCI_DISABLED, _T("50196042-0619-4420-9471-16b7c25c0213") },
+      { EVENT_DCI_ACTIVE, _T("740b6810-b355-46f4-a921-65118504af18") },
+      { EVENT_IP_ADDRESS_CHANGED, _T("517b6d2a-f5c6-46aa-969d-48e62e05e3bf") },
+      { EVENT_CONTAINER_AUTOBIND, _T("611133e2-1f76-446f-b278-9d500a823611") },
+      { EVENT_CONTAINER_AUTOUNBIND, _T("e57603be-0d81-41aa-b07c-12d08640561c") },
+      { EVENT_TEMPLATE_AUTOAPPLY, _T("bf084945-f928-4428-8c6c-d2965addc832") },
+      { EVENT_TEMPLATE_AUTOREMOVE, _T("8f7a4b4a-d0a2-4404-9b66-fdbc029f42cf") },
+      { EVENT_NODE_UNREACHABLE, _T("47bba2ce-c795-4e56-ad44-cbf05741e1ff") },
+      { EVENT_TABLE_THRESHOLD_ACTIVATED, _T("c08a1cfe-3128-40c2-99cc-378e7ef91f79") },
+      { EVENT_TABLE_THRESHOLD_DEACTIVATED, _T("479085e7-e1d1-4f2a-9d96-1d522f51b26a") },
+      { EVENT_IF_PEER_CHANGED, _T("a3a5c1df-9d96-4e98-9e06-b3157dbf39f0") },
+      { EVENT_AP_ADOPTED, _T("5aaee261-0c5d-44e0-b2f0-223bbba5297d") },
+      { EVENT_AP_UNADOPTED, _T("846a3581-aad1-4e17-9c55-9bd2e6b1247b") },
+      { EVENT_AP_DOWN, _T("2c8c6208-d3ab-4b8c-926a-872f4d8abcee") },
+      { EVENT_IF_MASK_CHANGED, _T("f800e593-057e-4aec-9e47-be0f7718c5c4") },
+      { EVENT_IF_IPADDR_ADDED, _T("475bdca6-543e-410b-9aff-c217599e0fe6") },
+      { EVENT_IF_IPADDR_DELETED, _T("ef477387-eb50-4a1a-bf90-717502b9873c") },
+      { EVENT_MAINTENANCE_MODE_ENTERED, _T("5f6c8b1c-f162-413e-8028-80e7ad2c362d") },
+      { EVENT_MAINTENANCE_MODE_LEFT, _T("cab06848-a622-430d-8b4c-addeea732657") },
+      { EVENT_SNMP_UNMATCHED_TRAP, _T("fc3613f7-d151-4221-9acd-d28b6f804335") },
+      { EVENT_SNMP_COLD_START, _T("39920e99-97bd-4d61-a462-43f89ba6fbdf") },
+      { EVENT_SNMP_WARM_START, _T("0aa888c1-eba6-4fe7-a37a-b85f2b373bdc") },
+      { EVENT_SNMP_LINK_DOWN, _T("b71338cc-137d-473c-a0f1-6b131086af56") },
+      { EVENT_SNMP_LINK_UP, _T("03da14a7-e39c-4a46-a7cb-4bf77ec7936c") },
+      { EVENT_SNMP_AUTH_FAILURE, _T("37020cb0-dde7-487b-9cfb-0d5ee771aa13") },
+      { EVENT_SNMP_EGP_NL, _T("aecf5fa4-390c-4125-be10-df8b0e669fe1") },
+      { 0, NULL }
+   };
+
+   CHK_EXEC(SQLQuery(_T("ALTER TABLE event_cfg ADD guid varchar(36)")));
+   CHK_EXEC(GenerateGUID(_T("event_cfg"), _T("event_code"), _T("guid"), eventGuidMapping));
+   CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='397' WHERE var_name='SchemaVersion'")));
+   return TRUE;
+}
+
 /**
  * Upgrade from V395 to V396
  */
@@ -964,8 +1083,8 @@ static BOOL H_UpgradeFromV380(int currVersion, int newVersion)
       _T("ALTER TABLE dc_tables ADD guid varchar(36)\n")
       _T("<END>");
    CHK_EXEC(SQLBatch(batch));
-   CHK_EXEC(GenerateGUID(_T("items"), _T("item_id"), _T("guid")));
-   CHK_EXEC(GenerateGUID(_T("dc_tables"), _T("item_id"), _T("guid")));
+   CHK_EXEC(GenerateGUID(_T("items"), _T("item_id"), _T("guid"), NULL));
+   CHK_EXEC(GenerateGUID(_T("dc_tables"), _T("item_id"), _T("guid"), NULL));
    CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='381' WHERE var_name='SchemaVersion'")));
    return TRUE;
 }
@@ -1444,7 +1563,7 @@ static BOOL H_UpgradeFromV353(int currVersion, int newVersion)
 static BOOL H_UpgradeFromV352(int currVersion, int newVersion)
 {
        CHK_EXEC(SQLQuery(_T("ALTER TABLE dci_summary_tables ADD guid varchar(36)")));
-   CHK_EXEC(GenerateGUID(_T("dci_summary_tables"), _T("id"), _T("guid")));
+   CHK_EXEC(GenerateGUID(_T("dci_summary_tables"), _T("id"), _T("guid"), NULL));
    CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='353' WHERE var_name='SchemaVersion'")));
    return TRUE;
 }
@@ -1455,7 +1574,7 @@ static BOOL H_UpgradeFromV352(int currVersion, int newVersion)
 static BOOL H_UpgradeFromV351(int currVersion, int newVersion)
 {
        CHK_EXEC(SQLQuery(_T("ALTER TABLE object_tools ADD guid varchar(36)")));
-   CHK_EXEC(GenerateGUID(_T("object_tools"), _T("tool_id"), _T("guid")));
+   CHK_EXEC(GenerateGUID(_T("object_tools"), _T("tool_id"), _T("guid"), NULL));
    CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='352' WHERE var_name='SchemaVersion'")));
    return TRUE;
 }
@@ -2700,7 +2819,7 @@ static BOOL H_UpgradeFromV292(int currVersion, int newVersion)
 static BOOL H_UpgradeFromV291(int currVersion, int newVersion)
 {
        CHK_EXEC(SQLQuery(_T("ALTER TABLE event_policy ADD rule_guid varchar(36)")));
-   CHK_EXEC(GenerateGUID(_T("event_policy"), _T("rule_id"), _T("rule_guid")));
+   CHK_EXEC(GenerateGUID(_T("event_policy"), _T("rule_id"), _T("rule_guid"), NULL));
    CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='292' WHERE var_name='SchemaVersion'")));
    return TRUE;
 }
@@ -9498,6 +9617,7 @@ static struct
    { 393, 394, H_UpgradeFromV393 },
    { 394, 395, H_UpgradeFromV394 },
    { 395, 396, H_UpgradeFromV395 },
+   { 396, 397, H_UpgradeFromV396 },
    { 0, 0, NULL }
 };
 
diff --git a/tools/generate_guids.pl b/tools/generate_guids.pl
new file mode 100755 (executable)
index 0000000..10d4ec1
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+use Data::UUID;
+
+while(<STDIN>)
+{
+   chomp;
+   $line = $_;
+
+   if ($line =~ /^(.*)____guid____(.*)$/)
+   {
+      $gen = Data::UUID->new;
+      $guid = $gen->create();
+      print $1 . $gen->to_string($guid) . $2 . "\n";
+   }
+   else
+   {
+      print $line . "\n";
+   }
+}