96d6b20ab5cba2fbb507ade6e841cf9f44ea7e9b
2 ** nxdbmgr - NetXMS database manager
3 ** Copyright (C) 2004-2011 Victor Kirhenshtein
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 // Execute with error check
30 #define CHK_EXEC(x) if (!(x)) if (!g_bIgnoreErrors) return FALSE;
37 static BOOL
CreateTable(const TCHAR
*pszQuery
)
42 pszBuffer
= (TCHAR
*)malloc(_tcslen(pszQuery
) * sizeof(TCHAR
) + 256);
43 _tcscpy(pszBuffer
, pszQuery
);
44 TranslateStr(pszBuffer
, _T("$SQL:TEXT"), g_pszSqlType
[g_iSyntax
][SQL_TYPE_TEXT
]);
45 TranslateStr(pszBuffer
, _T("$SQL:TEXT4K"), g_pszSqlType
[g_iSyntax
][SQL_TYPE_TEXT4K
]);
46 TranslateStr(pszBuffer
, _T("$SQL:INT64"), g_pszSqlType
[g_iSyntax
][SQL_TYPE_INT64
]);
47 if (g_iSyntax
== DB_SYNTAX_MYSQL
)
48 _tcscat(pszBuffer
, g_pszTableSuffix
);
49 bResult
= SQLQuery(pszBuffer
);
56 // Create configuration parameter if it doesn't exist (unless bForceUpdate set to true)
59 static BOOL
CreateConfigParam(const TCHAR
*pszName
, const TCHAR
*pszValue
,
60 int iVisible
, int iNeedRestart
, BOOL bForceUpdate
= FALSE
)
62 TCHAR szQuery
[1024], *pszEscValue
;
64 BOOL bVarExist
= FALSE
, bResult
= TRUE
;
66 // Check for variable existence
67 _sntprintf(szQuery
, 1024, _T("SELECT var_value FROM config WHERE var_name='%s'"), pszName
);
68 hResult
= DBSelect(g_hCoreDB
, szQuery
);
71 if (DBGetNumRows(hResult
) > 0)
73 DBFreeResult(hResult
);
78 pszEscValue
= EncodeSQLString(pszValue
);
79 _sntprintf(szQuery
, 1024, _T("INSERT INTO config (var_name,var_value,is_visible,")
80 _T("need_server_restart) VALUES ('%s','%s',%d,%d)"),
81 pszName
, pszEscValue
, iVisible
, iNeedRestart
);
83 bResult
= SQLQuery(szQuery
);
85 else if (bForceUpdate
)
87 pszEscValue
= EncodeSQLString(pszValue
);
88 _sntprintf(szQuery
, 1024, _T("UPDATE config SET var_value='%s' WHERE var_name='%s'"),
89 pszEscValue
, pszName
);
91 bResult
= SQLQuery(szQuery
);
98 // Set primary key constraint
101 static BOOL
SetPrimaryKey(const TCHAR
*table
, const TCHAR
*key
)
105 if (g_iSyntax
== DB_SYNTAX_SQLITE
)
106 return TRUE
; // SQLite does not support adding constraints
108 _sntprintf(query
, 4096, _T("ALTER TABLE %s ADD PRIMARY KEY (%s)"), table
, key
);
109 return SQLQuery(query
);
114 // Drop primary key from table
117 static BOOL
DropPrimaryKey(const TCHAR
*table
)
125 case DB_SYNTAX_ORACLE
:
126 case DB_SYNTAX_MYSQL
:
127 _sntprintf(query
, 1024, _T("ALTER TABLE %s DROP PRIMARY KEY"), table
);
128 success
= SQLQuery(query
);
130 case DB_SYNTAX_PGSQL
:
131 _sntprintf(query
, 1024, _T("ALTER TABLE %s DROP CONSTRAINT %s_pkey"), table
, table
);
132 success
= SQLQuery(query
);
134 case DB_SYNTAX_MSSQL
:
136 _sntprintf(query
, 1024, _T("SELECT name FROM sysobjects WHERE xtype='PK' AND parent_obj=OBJECT_ID('%s')"), table
);
137 hResult
= SQLSelect(query
);
140 if (DBGetNumRows(hResult
) > 0)
144 DBGetField(hResult
, 0, 0, objName
, 512);
145 _sntprintf(query
, 1024, _T("ALTER TABLE %s DROP CONSTRAINT %s"), table
, objName
);
146 success
= SQLQuery(query
);
148 DBFreeResult(hResult
);
151 default: // Unsupported DB engine
160 // Convert strings from # encoded form to normal form
163 static BOOL
ConvertStrings(const TCHAR
*table
, const TCHAR
*idColumn
, const TCHAR
*column
)
168 BOOL success
= FALSE
;
170 query
= (TCHAR
*)malloc(queryLen
);
174 case DB_SYNTAX_MSSQL
:
175 _sntprintf(query
, queryLen
, _T("UPDATE %s SET %s='' WHERE CAST(%s AS nvarchar(4000))=N'#00'"), table
, column
, column
);
177 case DB_SYNTAX_ORACLE
:
178 _sntprintf(query
, queryLen
, _T("UPDATE %s SET %s='' WHERE to_char(%s)='#00'"), table
, column
, column
);
181 _sntprintf(query
, queryLen
, _T("UPDATE %s SET %s='' WHERE %s='#00'"), table
, column
, column
);
184 if (!SQLQuery(query
))
190 _sntprintf(query
, queryLen
, _T("SELECT %s,%s FROM %s WHERE %s LIKE '%%#%%'"), idColumn
, column
, table
, column
);
191 hResult
= SQLSelect(query
);
198 int count
= DBGetNumRows(hResult
);
199 for(int i
= 0; i
< count
; i
++)
201 INT64 id
= DBGetFieldInt64(hResult
, i
, 0);
202 TCHAR
*value
= DBGetField(hResult
, i
, 1, NULL
, 0);
203 if (_tcschr(value
, _T('#')) != NULL
)
205 DecodeSQLString(value
);
206 String newValue
= DBPrepareString(g_hCoreDB
, value
);
207 if ((int)newValue
.getSize() + 256 > queryLen
)
209 queryLen
= newValue
.getSize() + 256;
210 query
= (TCHAR
*)realloc(query
, queryLen
);
212 _sntprintf(query
, queryLen
, _T("UPDATE %s SET %s=%s WHERE %s=") INT64_FMT
, table
, column
,
213 (const TCHAR
*)newValue
, idColumn
, id
);
214 if (!SQLQuery(query
))
221 DBFreeResult(hResult
);
228 // Set column nullable (currently Oracle only implementation)
231 static BOOL
SetColumnNullable(const TCHAR
*table
, const TCHAR
*column
, const TCHAR
*type
)
233 TCHAR query
[1024] = _T("");
237 case DB_SYNTAX_ORACLE
:
238 _sntprintf(query
, 1024, _T("DECLARE already_null EXCEPTION; ")
239 _T("PRAGMA EXCEPTION_INIT(already_null, -1451); ")
240 _T("BEGIN EXECUTE IMMEDIATE 'ALTER TABLE %s MODIFY %s null'; ")
241 _T("EXCEPTION WHEN already_null THEN null; END;"), table
, column
);
247 return (query
[0] != 0) ?
SQLQuery(query
) : TRUE
;
252 // Upgrade from V222 to V223
255 static BOOL
H_UpgradeFromV222(int currVersion
, int newVersion
)
257 static TCHAR batch
[] =
258 _T("DROP TABLE oid_to_type\n")
259 _T("ALTER TABLE nodes DROP COLUMN node_type\n")
260 _T("ALTER TABLE nodes ADD primary_name varchar(255)\n")
261 _T("UPDATE nodes SET primary_name=primary_ip\n")
264 CHK_EXEC(SQLBatch(batch
));
266 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='223' WHERE var_name='SchemaVersion'")));
272 // Upgrade from V221 to V222
275 static BOOL
H_UpgradeFromV221(int currVersion
, int newVersion
)
277 static TCHAR batch
[] =
278 _T("ALTER TABLE object_properties ADD image varchar(36)\n")
279 _T("UPDATE object_properties SET image='00000000-0000-0000-0000-000000000000'\n")
282 CHK_EXEC(SQLBatch(batch
));
284 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='222' WHERE var_name='SchemaVersion'")));
290 // Upgrade from V220 to V221
293 static BOOL
H_UpgradeFromV220(int currVersion
, int newVersion
)
295 static TCHAR batch
[] =
296 _T("ALTER TABLE network_maps DROP COLUMN background\n")
297 _T("ALTER TABLE network_maps ADD background varchar(36)\n")
300 CHK_EXEC(SQLBatch(batch
));
302 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='221' WHERE var_name='SchemaVersion'")));
308 // Upgrade from V219 to V220
311 static BOOL
H_UpgradeFromV219(int currVersion
, int newVersion
)
313 static TCHAR batch
[] =
314 _T("ALTER TABLE interfaces ADD bridge_port integer\n")
315 _T("ALTER TABLE interfaces ADD phy_slot integer\n")
316 _T("ALTER TABLE interfaces ADD phy_port integer\n")
317 _T("ALTER TABLE interfaces ADD peer_node_id integer\n")
318 _T("ALTER TABLE interfaces ADD peer_if_id integer\n")
319 _T("UPDATE interfaces SET bridge_port=0,phy_slot=0,phy_port=0,peer_node_id=0,peer_if_id=0\n")
320 _T("ALTER TABLE nodes ADD snmp_sys_name varchar(127)\n")
321 _T("UPDATE nodes SET snmp_sys_name=''\n")
324 CHK_EXEC(SQLBatch(batch
));
326 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='220' WHERE var_name='SchemaVersion'")));
332 // Upgrade from V218 to V219
335 static BOOL
H_UpgradeFromV218(int currVersion
, int newVersion
)
337 CHK_EXEC(CreateTable(_T("CREATE TABLE images (")
338 _T(" guid varchar(36) not null,")
339 _T(" mimetype varchar(64) not null,")
340 _T(" name varchar(255) not null,")
341 _T(" category varchar(255) not null,")
342 _T(" protected integer default 0,")
344 _T(" PRIMARY KEY(guid),")
345 _T(" UNIQUE(name, category))")));
347 static TCHAR batch
[] =
348 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
349 _T("('1ddb76a3-a05f-4a42-acda-22021768feaf', 'image/png', 'ATM', 'Network Objects', 1)\n")
350 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
351 _T("('b314cf44-b2aa-478e-b23a-73bc5bb9a624', 'image/png', 'HSM', 'Network Objects', 1)\n")
352 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
353 _T("('904e7291-ee3f-41b7-8132-2bd29288ecc8', 'image/png', 'Node', 'Network Objects', 1)\n")
354 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
355 _T("('f5214d16-1ab1-4577-bb21-063cfd45d7af', 'image/png', 'Printer', 'Network Objects', 1)\n")
356 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
357 _T("('bacde727-b183-4e6c-8dca-ab024c88b999', 'image/png', 'Router', 'Network Objects', 1)\n")
358 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
359 _T("('ba6ab507-f62d-4b8f-824c-ca9d46f22375', 'image/png', 'Server', 'Network Objects', 1)\n")
360 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
361 _T("('092e4b35-4e7c-42df-b9b7-d5805bfac64e', 'image/png', 'Service', 'Network Objects', 1)\n")
362 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
363 _T("('f9105c54-8dcf-483a-b387-b4587dfd3cba', 'image/png', 'Switch', 'Network Objects', 1)\n")
364 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
365 _T("('7cd999e9-fbe0-45c3-a695-f84523b3a50c', 'image/png', 'Unknown', 'Network Objects', 1)\n")
368 CHK_EXEC(SQLBatch(batch
));
370 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='219' WHERE var_name='SchemaVersion'")));
376 // Upgrade from V217 to V218
379 static BOOL
H_UpgradeFromV217(int currVersion
, int newVersion
)
381 CHK_EXEC(SetColumnNullable(_T("snmp_communities"), _T("community"), _T("varchar(255)")));
382 CHK_EXEC(ConvertStrings(_T("snmp_communities"), _T("id"), _T("community")));
384 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='218' WHERE var_name='SchemaVersion'")));
390 // Upgrade from V216 to V217
393 static BOOL
H_UpgradeFromV216(int currVersion
, int newVersion
)
395 static TCHAR batch
[] =
396 _T("ALTER TABLE nodes ADD snmp_port integer\n")
397 _T("UPDATE nodes SET snmp_port=161\n")
398 _T("ALTER TABLE items ADD snmp_port integer\n")
399 _T("UPDATE items SET snmp_port=0\n")
402 CHK_EXEC(SQLBatch(batch
));
404 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("community"), _T("varchar(127)")));
405 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("community")));
407 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("usm_auth_password"), _T("varchar(127)")));
408 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("usm_auth_password")));
410 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("usm_priv_password"), _T("varchar(127)")));
411 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("usm_priv_password")));
413 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("snmp_oid"), _T("varchar(255)")));
414 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("snmp_oid")));
416 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("secret"), _T("varchar(64)")));
417 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("secret")));
419 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("agent_version"), _T("varchar(63)")));
420 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("agent_version")));
422 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("platform_name"), _T("varchar(63)")));
423 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("platform_name")));
425 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("uname"), _T("varchar(255)")));
426 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("uname")));
428 CHK_EXEC(SetColumnNullable(_T("items"), _T("name"), _T("varchar(255)")));
429 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("name")));
431 CHK_EXEC(SetColumnNullable(_T("items"), _T("description"), _T("varchar(255)")));
432 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("description")));
434 CHK_EXEC(SetColumnNullable(_T("items"), _T("transformation"), g_pszSqlType
[g_iSyntax
][SQL_TYPE_TEXT
]));
435 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("transformation")));
437 CHK_EXEC(SetColumnNullable(_T("items"), _T("instance"), _T("varchar(255)")));
438 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("instance")));
440 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='217' WHERE var_name='SchemaVersion'")));
446 // Upgrade from V215 to V216
449 static BOOL
H_UpgradeFromV215(int currVersion
, int newVersion
)
451 CHK_EXEC(SetColumnNullable(_T("ap_common"), _T("description"), g_pszSqlType
[g_iSyntax
][SQL_TYPE_TEXT
]));
452 CHK_EXEC(ConvertStrings(_T("ap_common"), _T("id"), _T("description")));
454 if (g_iSyntax
!= DB_SYNTAX_SQLITE
)
455 CHK_EXEC(SQLQuery(_T("ALTER TABLE ap_config_files DROP COLUMN file_name")));
457 CHK_EXEC(SetColumnNullable(_T("ap_config_files"), _T("file_content"), g_pszSqlType
[g_iSyntax
][SQL_TYPE_TEXT
]));
458 CHK_EXEC(ConvertStrings(_T("ap_config_files"), _T("policy_id"), _T("file_content")));
460 CHK_EXEC(SQLQuery(_T("ALTER TABLE object_properties ADD guid varchar(36)")));
462 // Generate GUIDs for all objects
463 DB_RESULT hResult
= SQLSelect(_T("SELECT object_id FROM object_properties"));
466 int count
= DBGetNumRows(hResult
);
467 for(int i
= 0; i
< count
; i
++)
470 TCHAR query
[256], buffer
[64];
473 _sntprintf(query
, 256, _T("UPDATE object_properties SET guid='%s' WHERE object_id=%d"),
474 uuid_to_string(guid
, buffer
), DBGetFieldULong(hResult
, i
, 0));
475 CHK_EXEC(SQLQuery(query
));
477 DBFreeResult(hResult
);
480 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='216' WHERE var_name='SchemaVersion'")));
486 // Upgrade from V214 to V215
489 static BOOL
H_UpgradeFromV214(int currVersion
, int newVersion
)
491 CHK_EXEC(CreateTable(_T("CREATE TABLE network_maps (")
492 _T("id integer not null,")
493 _T("map_type integer not null,")
494 _T("layout integer not null,")
495 _T("seed integer not null,")
496 _T("background integer not null,")
497 _T("PRIMARY KEY(id))")));
499 CHK_EXEC(CreateTable(_T("CREATE TABLE network_map_elements (")
500 _T("map_id integer not null,")
501 _T("element_id integer not null,")
502 _T("element_type integer not null,")
503 _T("element_data $SQL:TEXT not null,")
504 _T("PRIMARY KEY(map_id,element_id))")));
506 CHK_EXEC(CreateTable(_T("CREATE TABLE network_map_links (")
507 _T("map_id integer not null,")
508 _T("element1 integer not null,")
509 _T("element2 integer not null,")
510 _T("link_type integer not null,")
511 _T("link_name varchar(255) null,")
512 _T("connector_name1 varchar(255) null,")
513 _T("connector_name2 varchar(255) null,")
514 _T("PRIMARY KEY(map_id,element1,element2))")));
516 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='215' WHERE var_name='SchemaVersion'")));
522 // Upgrade from V213 to V214
525 static BOOL
H_UpgradeFromV213(int currVersion
, int newVersion
)
527 CHK_EXEC(SetColumnNullable(_T("script_library"), _T("script_code"), g_pszSqlType
[g_iSyntax
][SQL_TYPE_TEXT
]));
528 CHK_EXEC(ConvertStrings(_T("script_library"), _T("script_id"), _T("script_code")));
530 CHK_EXEC(SetColumnNullable(_T("raw_dci_values"), _T("raw_value"), _T("varchar(255)")));
531 CHK_EXEC(ConvertStrings(_T("raw_dci_values"), _T("item_id"), _T("raw_value")));
533 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='CREATE TABLE idata_%d (item_id integer not null,idata_timestamp integer not null,idata_value varchar(255) null)' WHERE var_name='IDataTableCreationCommand'")));
535 DB_RESULT hResult
= SQLSelect(_T("SELECT id FROM nodes"));
538 int count
= DBGetNumRows(hResult
);
539 for(int i
= 0; i
< count
; i
++)
543 DWORD nodeId
= DBGetFieldULong(hResult
, i
, 0);
544 _sntprintf(table
, 32, _T("idata_%d"), nodeId
);
545 CHK_EXEC(SetColumnNullable(table
, _T("idata_value"), _T("varchar(255)")));
547 DBFreeResult(hResult
);
550 // Convert values for string DCIs from # encoded to normal form
551 hResult
= SQLSelect(_T("SELECT node_id,item_id FROM items WHERE datatype=4"));
554 int count
= DBGetNumRows(hResult
);
555 for(int i
= 0; i
< count
; i
++)
559 DWORD nodeId
= DBGetFieldULong(hResult
, i
, 0);
560 DWORD dciId
= DBGetFieldULong(hResult
, i
, 1);
562 if (IsNodeExist(nodeId
))
564 _sntprintf(query
, 512, _T("SELECT idata_timestamp,idata_value FROM idata_%d WHERE item_id=%d AND idata_value LIKE '%%#%%'"), nodeId
, dciId
);
565 DB_RESULT hData
= SQLSelect(query
);
568 int valueCount
= DBGetNumRows(hData
);
569 for(int j
= 0; j
< valueCount
; j
++)
571 TCHAR buffer
[MAX_DB_STRING
];
573 LONG ts
= DBGetFieldLong(hData
, j
, 0);
574 DBGetField(hData
, j
, 1, buffer
, MAX_DB_STRING
);
575 DecodeSQLString(buffer
);
577 _sntprintf(query
, 512, _T("UPDATE idata_%d SET idata_value=%s WHERE item_id=%d AND idata_timestamp=%ld"),
578 nodeId
, (const TCHAR
*)DBPrepareString(g_hCoreDB
, buffer
), dciId
, (long)ts
);
579 CHK_EXEC(SQLQuery(query
));
585 DBFreeResult(hResult
);
588 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='214' WHERE var_name='SchemaVersion'")));
594 // Upgrade from V212 to V213
597 static BOOL
H_UpgradeFromV212(int currVersion
, int newVersion
)
599 CHK_EXEC(SetColumnNullable(_T("items"), _T("custom_units_name"), _T("varchar(63)")));
600 CHK_EXEC(SetColumnNullable(_T("items"), _T("perftab_settings"), g_pszSqlType
[g_iSyntax
][SQL_TYPE_TEXT
]));
602 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("custom_units_name")));
603 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("perftab_settings")));
605 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='213' WHERE var_name='SchemaVersion'")));
612 // Upgrade from V211 to V212
615 static BOOL
H_UpgradeFromV211(int currVersion
, int newVersion
)
617 CHK_EXEC(SetColumnNullable(_T("snmp_trap_cfg"), _T("snmp_oid"), _T("varchar(255)")));
618 CHK_EXEC(SetColumnNullable(_T("snmp_trap_cfg"), _T("user_tag"), _T("varchar(63)")));
619 CHK_EXEC(SetColumnNullable(_T("snmp_trap_cfg"), _T("description"), _T("varchar(255)")));
621 CHK_EXEC(ConvertStrings(_T("snmp_trap_cfg"), _T("trap_id"), _T("user_tag")));
622 CHK_EXEC(ConvertStrings(_T("snmp_trap_cfg"), _T("trap_id"), _T("description")));
624 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='212' WHERE var_name='SchemaVersion'")));
631 // Upgrade from V210 to V211
634 static BOOL
H_UpgradeFromV210(int currVersion
, int newVersion
)
636 static TCHAR batch
[] =
637 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
638 _T(" (53,'SYS_DCI_UNSUPPORTED',2,1,'Status of DCI %1 (%5: %2) changed to UNSUPPORTED',")
639 _T("'Generated when DCI status changed to UNSUPPORTED.#0D#0AParameters:#0D#0A")
640 _T(" 1) DCI ID#0D#0A 2) DCI Name#0D#0A 3) DCI Description#0D#0A 4) DCI Origin code#0D#0A 5) DCI Origin name')\n")
641 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
642 _T(" (54,'SYS_DCI_DISABLED',1,1,'Status of DCI %1 (%5: %2) changed to DISABLED',")
643 _T("'Generated when DCI status changed to DISABLED.#0D#0AParameters:#0D#0A")
644 _T(" 1) DCI ID#0D#0A 2) DCI Name#0D#0A 3) DCI Description#0D#0A 4) DCI Origin code#0D#0A 5) DCI Origin name')\n")
645 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
646 _T(" (55,'SYS_DCI_ACTIVE',0,1,'Status of DCI %1 (%5: %2) changed to ACTIVE',")
647 _T("'Generated when DCI status changed to ACTIVE.#0D#0AParameters:#0D#0A")
648 _T(" 1) DCI ID#0D#0A 2) DCI Name#0D#0A 3) DCI Description#0D#0A 4) DCI Origin code#0D#0A 5) DCI Origin name')\n")
651 CHK_EXEC(SQLBatch(batch
));
652 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='211' WHERE var_name='SchemaVersion'")));
659 // Upgrade from V209 to V210
662 static BOOL
H_UpgradeFromV209(int currVersion
, int newVersion
)
664 if (!SQLQuery(_T("DELETE FROM metadata WHERE var_name like 'IDataIndexCreationCommand_%'")))
665 if (!g_bIgnoreErrors
)
671 case DB_SYNTAX_PGSQL
:
672 query
= _T("INSERT INTO metadata (var_name,var_value) VALUES ('IDataIndexCreationCommand_0','CREATE INDEX idx_idata_%d_timestamp_id ON idata_%d(idata_timestamp,item_id)')");
674 case DB_SYNTAX_MSSQL
:
675 query
= _T("INSERT INTO metadata (var_name,var_value) VALUES ('IDataIndexCreationCommand_0','CREATE CLUSTERED INDEX idx_idata_%d_id_timestamp ON idata_%d(item_id,idata_timestamp)')");
678 query
= _T("INSERT INTO metadata (var_name,var_value) VALUES ('IDataIndexCreationCommand_0','CREATE INDEX idx_idata_%d_id_timestamp ON idata_%d(item_id,idata_timestamp)')");
682 if (!SQLQuery(query
))
683 if (!g_bIgnoreErrors
)
688 if (!SQLQuery(_T("UPDATE metadata SET var_value='210' WHERE var_name='SchemaVersion'")))
689 if (!g_bIgnoreErrors
)
697 // Upgrade from V208 to V209
700 static BOOL
H_UpgradeFromV208(int currVersion
, int newVersion
)
702 static TCHAR batch
[] =
703 _T("ALTER TABLE users ADD auth_failures integer\n")
704 _T("ALTER TABLE users ADD last_passwd_change integer\n")
705 _T("ALTER TABLE users ADD min_passwd_length integer\n")
706 _T("ALTER TABLE users ADD disabled_until integer\n")
707 _T("ALTER TABLE users ADD last_login integer\n")
708 _T("ALTER TABLE users ADD password_history $SQL:TEXT\n")
709 _T("UPDATE users SET auth_failures=0,last_passwd_change=0,min_passwd_length=-1,disabled_until=0,last_login=0\n")
712 if (!SQLBatch(batch
))
713 if (!g_bIgnoreErrors
)
716 if (!CreateConfigParam(_T("PasswordHistoryLength"), _T("0"), 1, 0))
717 if (!g_bIgnoreErrors
)
720 if (!CreateConfigParam(_T("IntruderLockoutThreshold"), _T("0"), 1, 0))
721 if (!g_bIgnoreErrors
)
724 if (!CreateConfigParam(_T("IntruderLockoutTime"), _T("30"), 1, 0))
725 if (!g_bIgnoreErrors
)
728 if (!CreateConfigParam(_T("MinPasswordLength"), _T("0"), 1, 0))
729 if (!g_bIgnoreErrors
)
732 if (!CreateConfigParam(_T("PasswordComplexity"), _T("0"), 1, 0))
733 if (!g_bIgnoreErrors
)
736 if (!CreateConfigParam(_T("PasswordExpiration"), _T("0"), 1, 0))
737 if (!g_bIgnoreErrors
)
740 if (!CreateConfigParam(_T("BlockInactiveUserAccounts"), _T("0"), 1, 0))
741 if (!g_bIgnoreErrors
)
744 if (!SQLQuery(_T("UPDATE metadata SET var_value='209' WHERE var_name='SchemaVersion'")))
745 if (!g_bIgnoreErrors
)
753 // Upgrade from V207 to V208
756 static BOOL
H_UpgradeFromV207(int currVersion
, int newVersion
)
758 if (!SQLQuery(_T("ALTER TABLE items ADD system_tag varchar(255)")))
759 if (!g_bIgnoreErrors
)
762 if (!SQLQuery(_T("UPDATE metadata SET var_value='208' WHERE var_name='SchemaVersion'")))
763 if (!g_bIgnoreErrors
)
771 // Upgrade from V206 to V207
774 static BOOL
H_UpgradeFromV206(int currVersion
, int newVersion
)
776 if (!CreateConfigParam(_T("RADIUSSecondaryServer"), _T("none"), 1, 0))
777 if (!g_bIgnoreErrors
)
780 if (!CreateConfigParam(_T("RADIUSSecondarySecret"), _T("netxms"), 1, 0))
781 if (!g_bIgnoreErrors
)
784 if (!CreateConfigParam(_T("RADIUSSecondaryPort"), _T("1645"), 1, 0))
785 if (!g_bIgnoreErrors
)
788 if (!CreateConfigParam(_T("ExternalAuditServer"), _T("none"), 1, 1))
789 if (!g_bIgnoreErrors
)
792 if (!CreateConfigParam(_T("ExternalAuditPort"), _T("514"), 1, 1))
793 if (!g_bIgnoreErrors
)
796 if (!CreateConfigParam(_T("ExternalAuditFacility"), _T("13"), 1, 1))
797 if (!g_bIgnoreErrors
)
800 if (!CreateConfigParam(_T("ExternalAuditSeverity"), _T("5"), 1, 1))
801 if (!g_bIgnoreErrors
)
804 if (!CreateConfigParam(_T("ExternalAuditTag"), _T("netxmsd-audit"), 1, 1))
805 if (!g_bIgnoreErrors
)
808 if (!SQLQuery(_T("UPDATE metadata SET var_value='207' WHERE var_name='SchemaVersion'")))
809 if (!g_bIgnoreErrors
)
817 // Upgrade from V205 to V206
820 static BOOL
H_UpgradeFromV205(int currVersion
, int newVersion
)
822 if (g_iSyntax
== DB_SYNTAX_ORACLE
)
824 static TCHAR oraBatch
[] =
825 _T("ALTER TABLE audit_log MODIFY message null\n")
826 _T("ALTER TABLE event_log MODIFY event_message null\n")
827 _T("ALTER TABLE event_log MODIFY user_tag null\n")
828 _T("ALTER TABLE syslog MODIFY hostname null\n")
829 _T("ALTER TABLE syslog MODIFY msg_tag null\n")
830 _T("ALTER TABLE syslog MODIFY msg_text null\n")
831 _T("ALTER TABLE snmp_trap_log MODIFY trap_varlist null\n")
834 if (!SQLBatch(oraBatch
))
835 if (!g_bIgnoreErrors
)
839 bool clearLogs
= GetYesNo(_T("This database upgrade requires log conversion. This can take significant amount of time ")
840 _T("(up to few hours for large databases). If preserving all log records is not very important, it is ")
841 _T("recommended to clear logs befor conversion. Clear logs?"));
845 if (!SQLQuery(_T("DELETE FROM audit_log")))
846 if (!g_bIgnoreErrors
)
849 if (!SQLQuery(_T("DELETE FROM event_log")))
850 if (!g_bIgnoreErrors
)
853 if (!SQLQuery(_T("DELETE FROM syslog")))
854 if (!g_bIgnoreErrors
)
857 if (!SQLQuery(_T("DELETE FROM snmp_trap_log")))
858 if (!g_bIgnoreErrors
)
864 if (!ConvertStrings(_T("event_log"), _T("event_id"), _T("event_message")))
865 if (!g_bIgnoreErrors
)
867 if (!ConvertStrings(_T("event_log"), _T("event_id"), _T("user_tag")))
868 if (!g_bIgnoreErrors
)
872 if (!ConvertStrings(_T("audit_log"), _T("record_id"), _T("message")))
873 if (!g_bIgnoreErrors
)
877 if (!ConvertStrings(_T("syslog"), _T("msg_id"), _T("msg_text")))
878 if (!g_bIgnoreErrors
)
881 // Convert SNMP trap log
882 if (!ConvertStrings(_T("snmp_trap_log"), _T("trap_id"), _T("trap_varlist")))
883 if (!g_bIgnoreErrors
)
887 if (!SQLQuery(_T("UPDATE metadata SET var_value='206' WHERE var_name='SchemaVersion'")))
888 if (!g_bIgnoreErrors
)
896 // Upgrade from V204 to V205
899 static BOOL
H_UpgradeFromV204(int currVersion
, int newVersion
)
901 if (!CreateTable(_T("CREATE TABLE usm_credentials (")
902 _T("id integer not null,")
903 _T("user_name varchar(255) not null,")
904 _T("auth_method integer not null,")
905 _T("priv_method integer not null,")
906 _T("auth_password varchar(255),")
907 _T("priv_password varchar(255),")
908 _T("PRIMARY KEY(id))")))
909 if (!g_bIgnoreErrors
)
912 if (!SQLQuery(_T("UPDATE metadata SET var_value='205' WHERE var_name='SchemaVersion'")))
913 if (!g_bIgnoreErrors
)
921 // Upgrade from V203 to V204
924 static BOOL
H_UpgradeFromV203(int currVersion
, int newVersion
)
926 static TCHAR batch
[] =
927 _T("ALTER TABLE object_properties ADD location_type integer\n")
928 _T("ALTER TABLE object_properties ADD latitude varchar(20)\n")
929 _T("ALTER TABLE object_properties ADD longitude varchar(20)\n")
930 _T("UPDATE object_properties SET location_type=0\n")
931 _T("ALTER TABLE object_properties DROP COLUMN image_id\n")
934 if (!SQLBatch(batch
))
935 if (!g_bIgnoreErrors
)
938 if (!CreateConfigParam(_T("ConnectionPoolBaseSize"), _T("5"), 1, 1))
939 if (!g_bIgnoreErrors
)
942 if (!CreateConfigParam(_T("ConnectionPoolMaxSize"), _T("20"), 1, 1))
943 if (!g_bIgnoreErrors
)
946 if (!CreateConfigParam(_T("ConnectionPoolCooldownTime"), _T("300"), 1, 1))
947 if (!g_bIgnoreErrors
)
950 if (g_iSyntax
== DB_SYNTAX_ORACLE
)
952 if (!SQLQuery(_T("ALTER TABLE object_properties MODIFY comments null\n")))
953 if (!g_bIgnoreErrors
)
957 if (!ConvertStrings(_T("object_properties"), _T("object_id"), _T("comments")))
958 if (!g_bIgnoreErrors
)
961 if (!SQLQuery(_T("UPDATE metadata SET var_value='204' WHERE var_name='SchemaVersion'")))
962 if (!g_bIgnoreErrors
)
970 // Upgrade from V202 to V203
973 static BOOL
H_UpgradeFromV202(int currVersion
, int newVersion
)
975 static TCHAR batch
[] =
976 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text)")
977 _T(" VALUES (20,'&Info->Topology table (LLDP)',2,'Topology Table',1,' ','Show topology table (LLDP)','#00')\n")
978 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
979 _T(" VALUES (20,0,'Chassis ID','.1.0.8802.1.1.2.1.4.1.1.5',0,0)\n")
980 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
981 _T(" VALUES (20,1,'Local port','.1.0.8802.1.1.2.1.4.1.1.2',5,0)\n")
982 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
983 _T(" VALUES (20,2,'System name','.1.0.8802.1.1.2.1.4.1.1.9',0,0)\n")
984 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
985 _T(" VALUES (20,3,'System description','.1.0.8802.1.1.2.1.4.1.1.10',0,0)\n")
986 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
987 _T(" VALUES (20,4,'Remote port ID','.1.0.8802.1.1.2.1.4.1.1.7',4,0)\n")
988 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
989 _T(" VALUES (20,5,'Remote port description','.1.0.8802.1.1.2.1.4.1.1.8',0,0)\n")
990 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (20,-2147483648)\n")
993 if (!SQLBatch(batch
))
994 if (!g_bIgnoreErrors
)
997 if (!SQLQuery(_T("UPDATE metadata SET var_value='203' WHERE var_name='SchemaVersion'")))
998 if (!g_bIgnoreErrors
)
1006 // Upgrade from V201 to V202
1009 static BOOL
H_UpgradeFromV201(int currVersion
, int newVersion
)
1011 if (g_iSyntax
== DB_SYNTAX_ORACLE
)
1013 static TCHAR oraBatch
[] =
1014 _T("ALTER TABLE alarms MODIFY message null\n")
1015 _T("ALTER TABLE alarms MODIFY alarm_key null\n")
1016 _T("ALTER TABLE alarms MODIFY hd_ref null\n")
1019 if (!SQLBatch(oraBatch
))
1020 if (!g_bIgnoreErrors
)
1024 if (!ConvertStrings(_T("alarms"), _T("alarm_id"), _T("message")))
1025 if (!g_bIgnoreErrors
)
1027 if (!ConvertStrings(_T("alarms"), _T("alarm_id"), _T("alarm_key")))
1028 if (!g_bIgnoreErrors
)
1030 if (!ConvertStrings(_T("alarms"), _T("alarm_id"), _T("hd_ref")))
1031 if (!g_bIgnoreErrors
)
1034 if (!SQLQuery(_T("UPDATE metadata SET var_value='202' WHERE var_name='SchemaVersion'")))
1035 if (!g_bIgnoreErrors
)
1043 // Upgrade from V200 to V201
1046 static BOOL
H_UpgradeFromV200(int currVersion
, int newVersion
)
1048 static TCHAR batch
[] =
1049 _T("ALTER TABLE nodes ADD usm_auth_password varchar(127)\n")
1050 _T("ALTER TABLE nodes ADD usm_priv_password varchar(127)\n")
1051 _T("ALTER TABLE nodes ADD usm_methods integer\n")
1052 _T("UPDATE nodes SET usm_auth_password='#00',usm_priv_password='#00',usm_methods=0\n")
1055 if (!SQLBatch(batch
))
1056 if (!g_bIgnoreErrors
)
1059 if (!SQLQuery(_T("UPDATE metadata SET var_value='201' WHERE var_name='SchemaVersion'")))
1060 if (!g_bIgnoreErrors
)
1068 // Upgrade from V92 to V200
1069 // or from V93 to V201
1070 // or from V94 to V202
1071 // or from V95 to V203
1072 // or from V96 to V204
1073 // or from V97 to V205
1074 // or from V98 to V206
1075 // or from V99 to V207
1078 static BOOL
H_UpgradeFromV9x(int currVersion
, int newVersion
)
1080 if (!CreateTable(_T("CREATE TABLE ap_common (")
1081 _T("id integer not null,")
1082 _T("policy_type integer not null,")
1083 _T("version integer not null,")
1084 _T("description $SQL:TEXT not null,")
1085 _T("PRIMARY KEY(id))")))
1086 if (!g_bIgnoreErrors
)
1089 if (!CreateTable(_T("CREATE TABLE ap_bindings (")
1090 _T("policy_id integer not null,")
1091 _T("node_id integer not null,")
1092 _T("PRIMARY KEY(policy_id,node_id))")))
1093 if (!g_bIgnoreErrors
)
1096 if (!CreateTable(_T("CREATE TABLE ap_config_files (")
1097 _T("policy_id integer not null,")
1098 _T("file_name varchar(63) not null,")
1099 _T("file_content $SQL:TEXT not null,")
1100 _T("PRIMARY KEY(policy_id))")))
1101 if (!g_bIgnoreErrors
)
1105 _sntprintf(query
, 256, _T("UPDATE metadata SET var_value='%d' WHERE var_name='SchemaVersion'"), newVersion
);
1106 if (!SQLQuery(query
))
1107 if (!g_bIgnoreErrors
)
1115 // Upgrade from V100 to V214
1116 // or from V101 to V214
1117 // or from V102 to V214
1118 // or from V103 to V214
1119 // or from V104 to V214
1122 static BOOL
H_UpgradeFromV10x(int currVersion
, int newVersion
)
1124 if (!H_UpgradeFromV9x(currVersion
, 207))
1127 // Now database at V207 level
1128 // V100 already has changes V209 -> V210, but missing V207 -> V209 and V210 -> V214 changes
1129 // V101 already has changes V209 -> V211, but missing V207 -> V209 and V211 -> V214 changes
1130 // V102 already has changes V209 -> V212, but missing V207 -> V209 and V212 -> V214 changes
1131 // V103 already has changes V209 -> V213, but missing V207 -> V209 and V213 -> V214 changes
1132 // V104 already has changes V209 -> V214, but missing V207 -> V209 changes
1134 if (!H_UpgradeFromV207(207, 208))
1137 if (!H_UpgradeFromV208(208, 209))
1140 if (currVersion
== 100)
1141 if (!H_UpgradeFromV210(210, 211))
1144 if (currVersion
< 102)
1145 if (!H_UpgradeFromV211(211, 212))
1148 if (currVersion
< 103)
1149 if (!H_UpgradeFromV212(212, 213))
1152 if (currVersion
< 104)
1153 if (!H_UpgradeFromV213(213, 214))
1156 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='214' WHERE var_name='SchemaVersion'")));
1162 // Upgrade from V105 to V217
1165 static BOOL
H_UpgradeFromV105(int currVersion
, int newVersion
)
1167 if (!H_UpgradeFromV10x(currVersion
, 214))
1170 // V105 already have V216 -> V217 changes, but missing V207 -> V209 and V214 -> V216 changes
1171 if (!H_UpgradeFromV214(214, 215))
1174 if (!H_UpgradeFromV215(215, 216))
1177 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='217' WHERE var_name='SchemaVersion'")));
1183 // Upgrade from V91 to V92
1186 static BOOL
H_UpgradeFromV91(int currVersion
, int newVersion
)
1188 static TCHAR batch
[] =
1189 _T("DROP TABLE images\n")
1190 _T("DROP TABLE default_images\n")
1193 if (!SQLBatch(batch
))
1194 if (!g_bIgnoreErrors
)
1197 if (!SQLQuery(_T("UPDATE metadata SET var_value='92' WHERE var_name='SchemaVersion'")))
1198 if (!g_bIgnoreErrors
)
1206 // Upgrade from V90 to V91
1209 static BOOL
H_UpgradeFromV90(int currVersion
, int newVersion
)
1211 if (!CreateTable(_T("CREATE TABLE userdb_custom_attributes (")
1212 _T("object_id integer not null,")
1213 _T("attr_name varchar(255) not null,")
1214 _T("attr_value $SQL:TEXT not null,")
1215 _T("PRIMARY KEY(object_id,attr_name))")))
1216 if (!g_bIgnoreErrors
)
1219 if (!SQLQuery(_T("UPDATE metadata SET var_value='91' WHERE var_name='SchemaVersion'")))
1220 if (!g_bIgnoreErrors
)
1228 // Upgrade from V89 to V90
1231 static BOOL
H_UpgradeFromV89(int currVersion
, int newVersion
)
1233 static TCHAR m_szBatch
[] =
1234 _T("ALTER TABLE items ADD base_units integer\n")
1235 _T("ALTER TABLE items ADD unit_multiplier integer\n")
1236 _T("ALTER TABLE items ADD custom_units_name varchar(63)\n")
1237 _T("ALTER TABLE items ADD perftab_settings $SQL:TEXT\n")
1238 _T("UPDATE items SET base_units=0,unit_multiplier=1,custom_units_name='#00',perftab_settings='#00'\n")
1241 if (!SQLBatch(m_szBatch
))
1242 if (!g_bIgnoreErrors
)
1245 if (!SQLQuery(_T("UPDATE metadata SET var_value='90' WHERE var_name='SchemaVersion'")))
1246 if (!g_bIgnoreErrors
)
1254 // Upgrade from V88 to V89
1257 static BOOL
H_UpgradeFromV88(int currVersion
, int newVersion
)
1259 static TCHAR m_szBatch
[] =
1260 _T("ALTER TABLE containers ADD enable_auto_bind integer\n")
1261 _T("ALTER TABLE containers ADD auto_bind_filter $SQL:TEXT\n")
1262 _T("UPDATE containers SET enable_auto_bind=0,auto_bind_filter='#00'\n")
1263 _T("ALTER TABLE cluster_resources ADD current_owner integer\n")
1264 _T("UPDATE cluster_resources SET current_owner=0\n")
1265 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (")
1266 _T("52,'SYS_DB_QUERY_FAILED',4,1,'Database query failed (Query: %1; Error: %2)',")
1267 _T("'Generated when SQL query to backend database failed.#0D#0A")
1268 _T("Parameters:#0D#0A 1) Query#0D#0A 2) Error message')\n")
1271 if (!SQLBatch(m_szBatch
))
1272 if (!g_bIgnoreErrors
)
1275 if (!SQLQuery(_T("UPDATE metadata SET var_value='89' WHERE var_name='SchemaVersion'")))
1276 if (!g_bIgnoreErrors
)
1284 // Upgrade from V87 to V88
1287 static BOOL
H_UpgradeFromV87(int currVersion
, int newVersion
)
1289 static TCHAR m_szBatch
[] =
1290 _T("ALTER TABLE templates ADD enable_auto_apply integer\n")
1291 _T("ALTER TABLE templates ADD apply_filter $SQL:TEXT\n")
1292 _T("UPDATE templates SET enable_auto_apply=0,apply_filter='#00'\n")
1295 if (!SQLBatch(m_szBatch
))
1296 if (!g_bIgnoreErrors
)
1299 if (!SQLQuery(_T("UPDATE metadata SET var_value='88' WHERE var_name='SchemaVersion'")))
1300 if (!g_bIgnoreErrors
)
1308 // Upgrade from V86 to V87
1311 static BOOL
MoveConfigToMetadata(const TCHAR
*cfgVar
, const TCHAR
*mdVar
)
1313 TCHAR query
[1024], buffer
[256];
1317 _sntprintf(query
, 1024, _T("SELECT var_value FROM config WHERE var_name='%s'"), cfgVar
);
1318 hResult
= SQLSelect(query
);
1319 if (hResult
!= NULL
)
1321 if (DBGetNumRows(hResult
) > 0)
1323 DBGetField(hResult
, 0, 0, buffer
, 256);
1324 DecodeSQLString(buffer
);
1325 _sntprintf(query
, 1024, _T("INSERT INTO metadata (var_name,var_value) VALUES ('%s','%s')"),
1327 DBFreeResult(hResult
);
1328 success
= SQLQuery(query
);
1331 _sntprintf(query
, 1024, _T("DELETE FROM config WHERE var_name='%s'"), cfgVar
);
1332 success
= SQLQuery(query
);
1337 success
= TRUE
; // Variable missing in 'config' table, nothing to move
1347 static BOOL
H_UpgradeFromV86(int currVersion
, int newVersion
)
1349 if (!CreateTable(_T("CREATE TABLE metadata (")
1350 _T("var_name varchar(63) not null,")
1351 _T("var_value varchar(255) not null,")
1352 _T("PRIMARY KEY(var_name))")))
1353 if (!g_bIgnoreErrors
)
1356 if (!MoveConfigToMetadata(_T("DBFormatVersion"), _T("SchemaVersion")))
1357 if (!g_bIgnoreErrors
)
1360 if (!MoveConfigToMetadata(_T("DBSyntax"), _T("Syntax")))
1361 if (!g_bIgnoreErrors
)
1364 if (!MoveConfigToMetadata(_T("IDataTableCreationCommand"), _T("IDataTableCreationCommand")))
1365 if (!g_bIgnoreErrors
)
1368 if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_0"), _T("IDataIndexCreationCommand_0")))
1369 if (!g_bIgnoreErrors
)
1372 if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_1"), _T("IDataIndexCreationCommand_1")))
1373 if (!g_bIgnoreErrors
)
1376 if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_2"), _T("IDataIndexCreationCommand_2")))
1377 if (!g_bIgnoreErrors
)
1380 if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_3"), _T("IDataIndexCreationCommand_3")))
1381 if (!g_bIgnoreErrors
)
1384 if (!SQLQuery(_T("UPDATE metadata SET var_value='87' WHERE var_name='SchemaVersion'")))
1385 if (!g_bIgnoreErrors
)
1393 // Upgrade from V85 to V86
1396 static BOOL
H_UpgradeFromV85(int currVersion
, int newVersion
)
1398 static TCHAR m_szBatch
[] =
1399 _T("DROP TABLE alarm_grops\n")
1400 _T("DROP TABLE alarm_group_map\n")
1401 _T("DROP TABLE alarm_change_log\n")
1402 _T("DROP TABLE lpp\n")
1403 _T("DROP TABLE lpp_associations\n")
1404 _T("DROP TABLE lpp_rulesets\n")
1405 _T("DROP TABLE lpp_rules\n")
1406 _T("DROP TABLE lpp_groups\n")
1409 if (!SQLBatch(m_szBatch
))
1410 if (!g_bIgnoreErrors
)
1413 if (!SQLQuery(_T("UPDATE config SET var_value='86' WHERE var_name='DBFormatVersion'")))
1414 if (!g_bIgnoreErrors
)
1422 // Upgrade from V84 to V85
1425 static BOOL
H_UpgradeFromV84(int currVersion
, int newVersion
)
1427 static TCHAR m_szBatch
[] =
1428 _T("ALTER TABLE nodes ADD use_ifxtable integer\n")
1429 _T("UPDATE nodes SET use_ifxtable=0\n")
1432 if (!SQLBatch(m_szBatch
))
1433 if (!g_bIgnoreErrors
)
1436 if (!CreateConfigParam(_T("UseIfXTable"), _T("1"), 1, 0))
1437 if (!g_bIgnoreErrors
)
1440 if (!CreateConfigParam(_T("SMTPRetryCount"), _T("1"), 1, 0))
1441 if (!g_bIgnoreErrors
)
1444 if (!SQLQuery(_T("UPDATE config SET var_value='85' WHERE var_name='DBFormatVersion'")))
1445 if (!g_bIgnoreErrors
)
1453 // Upgrade from V83 to V84
1456 static BOOL
H_UpgradeFromV83(int currVersion
, int newVersion
)
1458 if (!CreateConfigParam(_T("EnableAgentRegistration"), _T("1"), 1, 0))
1459 if (!g_bIgnoreErrors
)
1462 if (!CreateConfigParam(_T("AnonymousFileAccess"), _T("0"), 1, 0))
1463 if (!g_bIgnoreErrors
)
1466 if (!CreateConfigParam(_T("EnableISCListener"), _T("0"), 1, 1))
1467 if (!g_bIgnoreErrors
)
1470 if (!CreateConfigParam(_T("ReceiveForwardedEvents"), _T("0"), 1, 0))
1471 if (!g_bIgnoreErrors
)
1474 if (!SQLQuery(_T("UPDATE config SET var_value='84' WHERE var_name='DBFormatVersion'")))
1475 if (!g_bIgnoreErrors
)
1483 // Upgrade from V82 to V83
1486 static BOOL
H_UpgradeFromV82(int currVersion
, int newVersion
)
1488 // Fix incorrect alarm timeouts
1489 if (!SQLQuery(_T("UPDATE alarms SET timeout=0,timeout_event=43")))
1490 if (!g_bIgnoreErrors
)
1493 if (!SQLQuery(_T("UPDATE config SET var_value='83' WHERE var_name='DBFormatVersion'")))
1494 if (!g_bIgnoreErrors
)
1502 // Upgrade from V81 to V82
1505 static BOOL
H_UpgradeFromV81(int currVersion
, int newVersion
)
1507 if (!CreateTable(_T("CREATE TABLE config_clob (")
1508 _T("var_name varchar(63) not null,")
1509 _T("var_value $SQL:TEXT not null,")
1510 _T("PRIMARY KEY(var_name))")))
1511 if (!g_bIgnoreErrors
)
1514 if (!SQLQuery(_T("UPDATE config SET var_value='82' WHERE var_name='DBFormatVersion'")))
1515 if (!g_bIgnoreErrors
)
1523 // Upgrade from V80 to V81
1526 static BOOL
H_UpgradeFromV80(int currVersion
, int newVersion
)
1529 TCHAR query
[1024], buffer
[1024];
1532 // Update dci_schedules table
1533 hResult
= SQLSelect(_T("SELECT item_id,schedule FROM dci_schedules"));
1534 if (hResult
!= NULL
)
1536 if (!SQLQuery(_T("DROP TABLE dci_schedules")))
1537 if (!g_bIgnoreErrors
)
1540 if (!CreateTable(_T("CREATE TABLE dci_schedules (")
1541 _T("schedule_id integer not null,")
1542 _T("item_id integer not null,")
1543 _T("schedule varchar(255) not null,")
1544 _T("PRIMARY KEY(item_id,schedule_id))")))
1545 if (!g_bIgnoreErrors
)
1548 for(i
= 0; i
< DBGetNumRows(hResult
); i
++)
1550 _sntprintf(query
, 1024, _T("INSERT INTO dci_schedules (item_id,schedule_id,schedule) VALUES(%d,%d,'%s')"),
1551 DBGetFieldULong(hResult
, i
, 0), i
+ 1, DBGetField(hResult
, i
, 1, buffer
, 1024));
1552 if (!SQLQuery(query
))
1553 if (!g_bIgnoreErrors
)
1556 DBFreeResult(hResult
);
1560 if (!g_bIgnoreErrors
)
1564 // Update address_lists table
1565 hResult
= SQLSelect(_T("SELECT list_type,community_id,addr_type,addr1,addr2 FROM address_lists"));
1566 if (hResult
!= NULL
)
1568 if (!SQLQuery(_T("DROP TABLE address_lists")))
1569 if (!g_bIgnoreErrors
)
1572 if (!CreateTable(_T("CREATE TABLE address_lists (")
1573 _T("list_type integer not null,")
1574 _T("community_id integer not null,")
1575 _T("addr_type integer not null,")
1576 _T("addr1 varchar(15) not null,")
1577 _T("addr2 varchar(15) not null,")
1578 _T("PRIMARY KEY(list_type,community_id,addr_type,addr1,addr2))")))
1579 if (!g_bIgnoreErrors
)
1582 for(i
= 0; i
< DBGetNumRows(hResult
); i
++)
1584 _sntprintf(query
, 1024, _T("INSERT INTO address_lists (list_type,community_id,addr_type,addr1,addr2) VALUES(%d,%d,%d,'%s','%s')"),
1585 DBGetFieldULong(hResult
, i
, 0), DBGetFieldULong(hResult
, i
, 1),
1586 DBGetFieldULong(hResult
, i
, 2), DBGetField(hResult
, i
, 3, buffer
, 64),
1587 DBGetField(hResult
, i
, 4, &buffer
[128], 64));
1588 if (!SQLQuery(query
))
1589 if (!g_bIgnoreErrors
)
1593 DBFreeResult(hResult
);
1597 if (!g_bIgnoreErrors
)
1601 // Create new tables
1602 if (!CreateTable(_T("CREATE TABLE object_custom_attributes (")
1603 _T("object_id integer not null,")
1604 _T("attr_name varchar(127) not null,")
1605 _T("attr_value $SQL:TEXT not null,")
1606 _T("PRIMARY KEY(object_id,attr_name))")))
1607 if (!g_bIgnoreErrors
)
1610 if (!CreateTable(_T("CREATE TABLE web_maps (")
1611 _T("id integer not null,")
1612 _T("title varchar(63) not null,")
1613 _T("properties $SQL:TEXT not null,")
1614 _T("data $SQL:TEXT not null,")
1615 _T("PRIMARY KEY(id))")))
1616 if (!g_bIgnoreErrors
)
1619 if (!SQLQuery(_T("UPDATE config SET var_value='81' WHERE var_name='DBFormatVersion'")))
1620 if (!g_bIgnoreErrors
)
1628 // Upgrade from V79 to V80
1631 static BOOL
H_UpgradeFromV79(int currVersion
, int newVersion
)
1633 static TCHAR m_szBatch
[] =
1634 _T("ALTER TABLE nodes ADD uname varchar(255)\n")
1635 _T("UPDATE nodes SET uname='#00'\n")
1638 if (!SQLBatch(m_szBatch
))
1639 if (!g_bIgnoreErrors
)
1642 if (!SQLQuery(_T("UPDATE config SET var_value='80' WHERE var_name='DBFormatVersion'")))
1643 if (!g_bIgnoreErrors
)
1651 // Upgrade from V78 to V79
1654 static BOOL
H_UpgradeFromV78(int currVersion
, int newVersion
)
1656 static TCHAR m_szBatch
[] =
1657 _T("DELETE FROM config WHERE var_name='RetainCustomInterfaceNames'\n")
1658 _T("DROP TABLE modules\n")
1660 static TCHAR m_szMySQLBatch
[] =
1661 _T("ALTER TABLE users MODIFY COLUMN cert_mapping_data text not null\n")
1662 _T("ALTER TABLE user_profiles MODIFY COLUMN var_value text not null\n")
1663 _T("ALTER TABLE object_properties MODIFY COLUMN comments text not null\n")
1664 _T("ALTER TABLE network_services MODIFY COLUMN check_request text not null\n")
1665 _T("ALTER TABLE network_services MODIFY COLUMN check_responce text not null\n")
1666 _T("ALTER TABLE conditions MODIFY COLUMN script text not null\n")
1667 _T("ALTER TABLE container_categories MODIFY COLUMN description text not null\n")
1668 _T("ALTER TABLE items MODIFY COLUMN transformation text not null\n")
1669 _T("ALTER TABLE event_cfg MODIFY COLUMN description text not null\n")
1670 _T("ALTER TABLE actions MODIFY COLUMN action_data text not null\n")
1671 _T("ALTER TABLE event_policy MODIFY COLUMN comments text not null\n")
1672 _T("ALTER TABLE event_policy MODIFY COLUMN script text not null\n")
1673 _T("ALTER TABLE alarm_change_log MODIFY COLUMN info_text text not null\n")
1674 _T("ALTER TABLE alarm_notes MODIFY COLUMN note_text text not null\n")
1675 _T("ALTER TABLE object_tools MODIFY COLUMN tool_data text not null\n")
1676 _T("ALTER TABLE syslog MODIFY COLUMN msg_text text not null\n")
1677 _T("ALTER TABLE script_library MODIFY COLUMN script_code text not null\n")
1678 _T("ALTER TABLE snmp_trap_log MODIFY COLUMN trap_varlist text not null\n")
1679 _T("ALTER TABLE maps MODIFY COLUMN description text not null\n")
1680 _T("ALTER TABLE agent_configs MODIFY COLUMN config_file text not null\n")
1681 _T("ALTER TABLE agent_configs MODIFY COLUMN config_filter text not null\n")
1682 _T("ALTER TABLE graphs MODIFY COLUMN config text not null\n")
1683 _T("ALTER TABLE certificates MODIFY COLUMN cert_data text not null\n")
1684 _T("ALTER TABLE certificates MODIFY COLUMN subject text not null\n")
1685 _T("ALTER TABLE certificates MODIFY COLUMN comments text not null\n")
1686 _T("ALTER TABLE audit_log MODIFY COLUMN message text not null\n")
1687 _T("ALTER TABLE situations MODIFY COLUMN comments text not null\n")
1690 if (!SQLBatch(m_szBatch
))
1691 if (!g_bIgnoreErrors
)
1694 if (g_iSyntax
== DB_SYNTAX_MYSQL
)
1696 if (!SQLBatch(m_szMySQLBatch
))
1697 if (!g_bIgnoreErrors
)
1701 if (!SQLQuery(_T("UPDATE config SET var_value='79' WHERE var_name='DBFormatVersion'")))
1702 if (!g_bIgnoreErrors
)
1710 // Upgrade from V77 to V78
1713 static BOOL
H_UpgradeFromV77(int currVersion
, int newVersion
)
1715 if (!CreateTable(_T("CREATE TABLE trusted_nodes (")
1716 _T("source_object_id integer not null,")
1717 _T("target_node_id integer not null,")
1718 _T("PRIMARY KEY(source_object_id,target_node_id))")))
1719 if (!g_bIgnoreErrors
)
1722 if (!CreateConfigParam(_T("CheckTrustedNodes"), _T("1"), 1, 1))
1723 if (!g_bIgnoreErrors
)
1726 if (!SQLQuery(_T("UPDATE config SET var_value='78' WHERE var_name='DBFormatVersion'")))
1727 if (!g_bIgnoreErrors
)
1735 // Upgrade from V76 to V77
1738 static BOOL
H_UpgradeFromV76(int currVersion
, int newVersion
)
1745 hResult
= SQLSelect(_T("SELECT condition_id,dci_id,node_id,dci_func,num_polls FROM cond_dci_map ORDER BY condition_id"));
1746 if (hResult
== NULL
)
1747 if (!g_bIgnoreErrors
)
1750 if (!SQLQuery(_T("DROP TABLE cond_dci_map")))
1751 if (!g_bIgnoreErrors
)
1754 if (!CreateTable(_T("CREATE TABLE cond_dci_map (")
1755 _T("condition_id integer not null,")
1756 _T("sequence_number integer not null,")
1757 _T("dci_id integer not null,")
1758 _T("node_id integer not null,")
1759 _T("dci_func integer not null,")
1760 _T("num_polls integer not null,")
1761 _T("PRIMARY KEY(condition_id,sequence_number))")))
1762 if (!g_bIgnoreErrors
)
1765 count
= DBGetNumRows(hResult
);
1766 for(i
= 0, seq
= 0, lastId
= 0; i
< count
; i
++, seq
++)
1768 id
= DBGetFieldULong(hResult
, i
, 0);
1774 _sntprintf(query
, 1024, _T("INSERT INTO cond_dci_map (condition_id,sequence_number,dci_id,node_id,dci_func,num_polls) VALUES (%d,%d,%d,%d,%d,%d)"),
1775 id
, seq
, DBGetFieldULong(hResult
, i
, 1), DBGetFieldULong(hResult
, i
, 2),
1776 DBGetFieldULong(hResult
, i
, 3), DBGetFieldULong(hResult
, i
, 4));
1777 if (!SQLQuery(query
))
1778 if (!g_bIgnoreErrors
)
1782 DBFreeResult(hResult
);
1784 if (!SQLQuery(_T("UPDATE config SET var_value='77' WHERE var_name='DBFormatVersion'")))
1785 if (!g_bIgnoreErrors
)
1791 DBFreeResult(hResult
);
1797 // Upgrade from V75 to V76
1800 static BOOL
H_UpgradeFromV75(int currVersion
, int newVersion
)
1802 static TCHAR m_szBatch
[] =
1803 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (")
1804 _T("50,'SYS_NETWORK_CONN_LOST',4,1,'NetXMS server network connectivity lost',")
1805 _T("'Generated when system detects loss of network connectivity based on beacon ")
1806 _T("probing.#0D#0AParameters:#0D#0A 1) Number of beacons')\n")
1807 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (")
1808 _T("51,'SYS_NETWORK_CONN_RESTORED',0,1,'NetXMS server network connectivity restored',")
1809 _T("'Generated when system detects restoration of network connectivity based on ")
1810 _T("beacon probing.#0D#0AParameters:#0D#0A 1) Number of beacons')\n")
1813 if (!SQLBatch(m_szBatch
))
1814 if (!g_bIgnoreErrors
)
1817 if (!CreateConfigParam(_T("AgentCommandTimeout"), _T("2000"), 1, 1))
1818 if (!g_bIgnoreErrors
)
1821 if (!CreateConfigParam(_T("BeaconHosts"), _T(""), 1, 1))
1822 if (!g_bIgnoreErrors
)
1825 if (!CreateConfigParam(_T("BeaconTimeout"), _T("1000"), 1, 1))
1826 if (!g_bIgnoreErrors
)
1829 if (!CreateConfigParam(_T("BeaconPollingInterval"), _T("1000"), 1, 1))
1830 if (!g_bIgnoreErrors
)
1833 if (!SQLQuery(_T("UPDATE config SET var_value='76' WHERE var_name='DBFormatVersion'")))
1834 if (!g_bIgnoreErrors
)
1842 // Upgrade from V74 to V75
1845 static BOOL
H_UpgradeFromV74(int currVersion
, int newVersion
)
1847 static TCHAR m_szBatch
[] =
1848 _T("ALTER TABLE address_lists ADD community_id integer\n")
1849 _T("UPDATE address_lists SET community_id=0\n")
1852 if (!SQLBatch(m_szBatch
))
1853 if (!g_bIgnoreErrors
)
1856 if (!CreateTable(_T("CREATE TABLE snmp_communities (")
1857 _T("id integer not null,")
1858 _T("community varchar(255) not null,")
1859 _T("PRIMARY KEY(id))")))
1860 if (!g_bIgnoreErrors
)
1863 if (!CreateConfigParam(_T("UseInterfaceAliases"), _T("0"), 1, 0))
1864 if (!g_bIgnoreErrors
)
1867 if (!CreateConfigParam(_T("SyncNodeNamesWithDNS"), _T("0"), 1, 0))
1868 if (!g_bIgnoreErrors
)
1871 if (!SQLQuery(_T("UPDATE config SET var_value='75' WHERE var_name='DBFormatVersion'")))
1872 if (!g_bIgnoreErrors
)
1880 // Upgrade from V73 to V74
1883 static BOOL
H_UpgradeFromV73(int currVersion
, int newVersion
)
1885 static TCHAR m_szBatch
[] =
1886 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
1887 _T("VALUES (48,'SYS_EVENT_STORM_DETECTED',3,1,'Event storm detected (Events per second: %1)',")
1888 _T("'Generated when system detects an event storm.#0D#0AParameters:#0D#0A")
1889 _T(" 1) Events per second#0D#0A 2) Duration#0D#0A 3) Threshold')\n")
1890 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
1891 _T("VALUES (49,'SYS_EVENT_STORM_ENDED',0,1,'Event storm ended',")
1892 _T("'Generated when system clears event storm condition.#0D#0AParameters:#0D#0A")
1893 _T(" 1) Events per second#0D#0A 2) Duration#0D#0A 3) Threshold')\n")
1894 _T("DELETE FROM config WHERE var_name='NumberOfEventProcessors'\n")
1895 _T("DELETE FROM config WHERE var_name='EventStormThreshold'\n")
1898 if (!SQLBatch(m_szBatch
))
1899 if (!g_bIgnoreErrors
)
1902 if (!CreateConfigParam(_T("EnableEventStormDetection"), _T("0"), 1, 1))
1903 if (!g_bIgnoreErrors
)
1906 if (!CreateConfigParam(_T("EventStormEventsPerSecond"), _T("100"), 1, 1))
1907 if (!g_bIgnoreErrors
)
1910 if (!CreateConfigParam(_T("EventStormDuration"), _T("15"), 1, 1))
1911 if (!g_bIgnoreErrors
)
1914 if (!SQLQuery(_T("UPDATE config SET var_value='74' WHERE var_name='DBFormatVersion'")))
1915 if (!g_bIgnoreErrors
)
1923 // Upgrade from V72 to V73
1926 static BOOL
H_UpgradeFromV72(int currVersion
, int newVersion
)
1928 static TCHAR m_szBatch
[] =
1929 _T("ALTER TABLE event_policy ADD situation_id integer\n")
1930 _T("ALTER TABLE event_policy ADD situation_instance varchar(255)\n")
1931 _T("UPDATE event_policy SET situation_id=0,situation_instance='#00'\n")
1934 if (!SQLBatch(m_szBatch
))
1935 if (!g_bIgnoreErrors
)
1938 if (!CreateTable(_T("CREATE TABLE policy_situation_attr_list (")
1939 _T("rule_id integer not null,")
1940 _T("situation_id integer not null,")
1941 _T("attr_name varchar(255) not null,")
1942 _T("attr_value varchar(255) not null,")
1943 _T("PRIMARY KEY(rule_id,situation_id,attr_name))")))
1944 if (!g_bIgnoreErrors
)
1947 if (!CreateTable(_T("CREATE TABLE situations (")
1948 _T("id integer not null,")
1949 _T("name varchar(127) not null,")
1950 _T("comments $SQL:TEXT not null,")
1951 _T("PRIMARY KEY(id))")))
1952 if (!g_bIgnoreErrors
)
1955 if (!CreateConfigParam(_T("RetainCustomInterfaceNames"), _T("0"), 1, 0))
1956 if (!g_bIgnoreErrors
)
1959 if (!CreateConfigParam(_T("AllowDirectSMS"), _T("0"), 1, 0))
1960 if (!g_bIgnoreErrors
)
1963 if (!CreateConfigParam(_T("EventStormThreshold"), _T("0"), 1, 1))
1964 if (!g_bIgnoreErrors
)
1967 if (!SQLQuery(_T("UPDATE config SET var_value='73' WHERE var_name='DBFormatVersion'")))
1968 if (!g_bIgnoreErrors
)
1976 // Upgrade from V71 to V72
1979 static BOOL
H_UpgradeFromV71(int currVersion
, int newVersion
)
1981 static TCHAR m_szBatch
[] =
1982 _T("ALTER TABLE items ADD proxy_node integer\n")
1983 _T("UPDATE items SET proxy_node=0\n")
1986 if (!SQLBatch(m_szBatch
))
1987 if (!g_bIgnoreErrors
)
1990 if (!SQLQuery(_T("UPDATE config SET var_value='72' WHERE var_name='DBFormatVersion'")))
1991 if (!g_bIgnoreErrors
)
1999 // Upgrade from V70 to V71
2002 static BOOL
H_UpgradeFromV70(int currVersion
, int newVersion
)
2004 static TCHAR m_szBatch
[] =
2005 _T("ALTER TABLE nodes ADD required_polls integer\n")
2006 _T("UPDATE nodes SET required_polls=0\n")
2007 _T("ALTER TABLE interfaces ADD required_polls integer\n")
2008 _T("UPDATE interfaces SET required_polls=0\n")
2009 _T("ALTER TABLE network_services ADD required_polls integer\n")
2010 _T("UPDATE network_services SET required_polls=0\n")
2013 if (!SQLBatch(m_szBatch
))
2014 if (!g_bIgnoreErrors
)
2017 if (!CreateConfigParam(_T("PollCountForStatusChange"), _T("1"), 1, 1))
2018 if (!g_bIgnoreErrors
)
2021 if (!SQLQuery(_T("UPDATE config SET var_value='71' WHERE var_name='DBFormatVersion'")))
2022 if (!g_bIgnoreErrors
)
2030 // Upgrade from V69 to V70
2033 static BOOL
H_UpgradeFromV69(int currVersion
, int newVersion
)
2035 static TCHAR m_szBatch
[] =
2036 _T("ALTER TABLE snmp_trap_cfg ADD user_tag varchar(63)\n")
2037 _T("UPDATE snmp_trap_cfg SET user_tag='#00'\n")
2038 _T("ALTER TABLE event_log ADD user_tag varchar(63)\n")
2039 _T("UPDATE event_log SET user_tag='#00'\n")
2044 if (!SQLBatch(m_szBatch
))
2045 if (!g_bIgnoreErrors
)
2048 // Convert event log retention time from seconds to days
2049 n
= ConfigReadInt(_T("EventLogRetentionTime"), 5184000) / 86400;
2050 _sntprintf(buffer
, 64, _T("%d"), max(n
, 1));
2051 if (!CreateConfigParam(_T("EventLogRetentionTime"), buffer
, 1, 0, TRUE
))
2052 if (!g_bIgnoreErrors
)
2055 // Convert event log retention time from seconds to days
2056 n
= ConfigReadInt(_T("SyslogRetentionTime"), 5184000) / 86400;
2057 _sntprintf(buffer
, 64, _T("%d"), max(n
, 1));
2058 if (!CreateConfigParam(_T("SyslogRetentionTime"), buffer
, 1, 0, TRUE
))
2059 if (!g_bIgnoreErrors
)
2062 if (!SQLQuery(_T("UPDATE config SET var_value='70' WHERE var_name='DBFormatVersion'")))
2063 if (!g_bIgnoreErrors
)
2071 // Upgrade from V68 to V69
2074 static BOOL
H_UpgradeFromV68(int currVersion
, int newVersion
)
2076 if (!CreateTable(_T("CREATE TABLE audit_log (")
2077 _T("record_id integer not null,")
2078 _T("timestamp integer not null,")
2079 _T("subsystem varchar(32) not null,")
2080 _T("success integer not null,")
2081 _T("user_id integer not null,")
2082 _T("workstation varchar(63) not null,")
2083 _T("object_id integer not null,")
2084 _T("message $SQL:TEXT not null,")
2085 _T("PRIMARY KEY(record_id))")))
2086 if (!g_bIgnoreErrors
)
2089 if (!CreateConfigParam(_T("EnableAuditLog"), _T("1"), 1, 1))
2090 if (!g_bIgnoreErrors
)
2093 if (!CreateConfigParam(_T("AuditLogRetentionTime"), _T("90"), 1, 0))
2094 if (!g_bIgnoreErrors
)
2097 if (!SQLQuery(_T("UPDATE config SET var_value='69' WHERE var_name='DBFormatVersion'")))
2098 if (!g_bIgnoreErrors
)
2106 // Upgrade from V67 to V68
2109 static BOOL
H_UpgradeFromV67(int currVersion
, int newVersion
)
2111 static TCHAR m_szBatch
[] =
2112 _T("ALTER TABLE thresholds ADD repeat_interval integer\n")
2113 _T("UPDATE thresholds SET repeat_interval=-1\n")
2116 if (!SQLBatch(m_szBatch
))
2117 if (!g_bIgnoreErrors
)
2120 if (!CreateConfigParam(_T("ThresholdRepeatInterval"), _T("0"), 1, 1))
2121 if (!g_bIgnoreErrors
)
2124 if (!SQLQuery(_T("UPDATE config SET var_value='68' WHERE var_name='DBFormatVersion'")))
2125 if (!g_bIgnoreErrors
)
2133 // Upgrade from V66 to V67
2136 static BOOL
H_UpgradeFromV66(int currVersion
, int newVersion
)
2138 static TCHAR m_szBatch
[] =
2139 _T("ALTER TABLE subnets ADD synthetic_mask integer\n")
2140 _T("UPDATE subnets SET synthetic_mask=0\n")
2141 _T("ALTER TABLE interfaces ADD synthetic_mask integer\n")
2142 _T("UPDATE interfaces SET synthetic_mask=0\n")
2145 if (!SQLBatch(m_szBatch
))
2146 if (!g_bIgnoreErrors
)
2149 if (!SQLQuery(_T("UPDATE config SET var_value='67' WHERE var_name='DBFormatVersion'")))
2150 if (!g_bIgnoreErrors
)
2158 // Upgrade from V65 to V66
2161 static BOOL
H_UpgradeFromV65(int currVersion
, int newVersion
)
2163 static TCHAR m_szBatch
[] =
2164 _T("ALTER TABLE submap_links ADD port1 varchar(255)\n")
2165 _T("ALTER TABLE submap_links ADD port2 varchar(255)\n")
2166 _T("UPDATE submap_links SET port1='#00',port2='#00'\n")
2169 if (!SQLBatch(m_szBatch
))
2170 if (!g_bIgnoreErrors
)
2173 if (!SQLQuery(_T("UPDATE config SET var_value='66' WHERE var_name='DBFormatVersion'")))
2174 if (!g_bIgnoreErrors
)
2182 // Upgrade from V64 to V65
2185 static BOOL
H_UpgradeFromV64(int currVersion
, int newVersion
)
2187 static TCHAR m_szPGSQLBatch
[] =
2188 _T("ALTER TABLE nodes ADD new_community varchar(127)\n")
2189 _T("UPDATE nodes SET new_community=community\n")
2190 _T("ALTER TABLE nodes DROP COLUMN community\n")
2191 _T("ALTER TABLE nodes RENAME COLUMN new_community TO community\n")
2192 _T("ALTER TABLE nodes ALTER COLUMN community SET NOT NULL\n")
2197 case DB_SYNTAX_MYSQL
:
2198 case DB_SYNTAX_ORACLE
:
2199 if (!SQLQuery(_T("ALTER TABLE nodes MODIFY community varchar(127)")))
2200 if (!g_bIgnoreErrors
)
2203 case DB_SYNTAX_PGSQL
:
2205 ShowQuery(_T("ALTER TABLE nodes ALTER COLUMN community TYPE varchar(127)"));
2207 if (!DBQuery(g_hCoreDB
, _T("ALTER TABLE nodes ALTER COLUMN community TYPE varchar(127)")))
2209 // Assume that we are using PostgreSQL oldest than 8.x
2210 if (!SQLBatch(m_szPGSQLBatch
))
2211 if (!g_bIgnoreErrors
)
2215 case DB_SYNTAX_MSSQL
:
2216 if (!SQLQuery(_T("ALTER TABLE nodes ALTER COLUMN community varchar(127)")))
2217 if (!g_bIgnoreErrors
)
2220 case DB_SYNTAX_SQLITE
:
2221 _tprintf(_T("WARNING: Due to limitations of SQLite requested operation cannot be completed\nYou system will still be limited to use SNMP commonity strings not longer than 32 characters.\n"));
2224 _tprintf(_T("INTERNAL ERROR: Unknown database syntax %d\n"), g_iSyntax
);
2228 if (!SQLQuery(_T("UPDATE config SET var_value='65' WHERE var_name='DBFormatVersion'")))
2229 if (!g_bIgnoreErrors
)
2237 // Upgrade from V63 to V64
2240 static BOOL
H_UpgradeFromV63(int currVersion
, int newVersion
)
2242 static TCHAR m_szBatch
[] =
2243 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (15,'.1.3.6.1.4.1.45.3.29.*',3,0)\n")
2244 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (16,'.1.3.6.1.4.1.45.3.41.*',3,0)\n")
2245 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (17,'.1.3.6.1.4.1.45.3.45.*',3,0)\n")
2246 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (18,'.1.3.6.1.4.1.45.3.43.*',3,0)\n")
2247 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (19,'.1.3.6.1.4.1.45.3.57.*',3,0)\n")
2248 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (20,'.1.3.6.1.4.1.45.3.49.*',3,0)\n")
2249 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (21,'.1.3.6.1.4.1.45.3.54.*',3,0)\n")
2250 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (22,'.1.3.6.1.4.1.45.3.63.*',3,0)\n")
2251 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (23,'.1.3.6.1.4.1.45.3.64.*',3,0)\n")
2252 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (24,'.1.3.6.1.4.1.45.3.53.*',3,0)\n")
2253 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (25,'.1.3.6.1.4.1.45.3.59.*',3,0)\n")
2254 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (26,'.1.3.6.1.4.1.45.3.39.*',3,0)\n")
2255 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (27,'.1.3.6.1.4.1.45.3.65.*',3,0)\n")
2256 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (28,'.1.3.6.1.4.1.45.3.66.*',3,0)\n")
2257 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (29,'.1.3.6.1.4.1.45.3.44.*',4,0)\n")
2258 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (30,'.1.3.6.1.4.1.45.3.47.*',4,0)\n")
2259 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) VALUES (31,'.1.3.6.1.4.1.45.3.48.*',4,0)\n")
2262 if (!SQLBatch(m_szBatch
))
2263 if (!g_bIgnoreErrors
)
2266 if (!SQLQuery(_T("UPDATE config SET var_value='64' WHERE var_name='DBFormatVersion'")))
2267 if (!g_bIgnoreErrors
)
2275 // Upgrade from V62 to V63
2278 static BOOL
H_UpgradeFromV62(int currVersion
, int newVersion
)
2280 static TCHAR m_szBatch
[] =
2281 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
2282 _T("VALUES (45,'SYS_IF_UNKNOWN',1,1,")
2283 _T("'Interface \"%2\" changed state to UNKNOWN (IP Addr: %3/%4, IfIndex: %5)',")
2284 _T("'Generated when interface goes to unknown state.#0D#0A")
2285 _T("Please note that source of event is node, not an interface itself.#0D#0A")
2286 _T("Parameters:#0D#0A 1) Interface object ID#0D#0A 2) Interface name#0D#0A")
2287 _T(" 3) Interface IP address#0D#0A 4) Interface netmask#0D#0A")
2288 _T(" 5) Interface index')\n")
2289 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
2290 _T("VALUES (46,'SYS_IF_DISABLED',0,1,")
2291 _T("'Interface \"%2\" disabled (IP Addr: %3/%4, IfIndex: %5)',")
2292 _T("'Generated when interface administratively disabled.#0D#0A")
2293 _T("Please note that source of event is node, not an interface itself.#0D#0A")
2294 _T("Parameters:#0D#0A 1) Interface object ID#0D#0A 2) Interface name#0D#0A")
2295 _T(" 3) Interface IP address#0D#0A 4) Interface netmask#0D#0A")
2296 _T(" 5) Interface index')\n")
2297 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
2298 _T("VALUES (47,'SYS_IF_TESTING',0,1,")
2299 _T("'Interface \"%2\" is testing (IP Addr: %3/%4, IfIndex: %5)',")
2300 _T("'Generated when interface goes to testing state.#0D#0A")
2301 _T("Please note that source of event is node, not an interface itself.#0D#0A")
2302 _T("Parameters:#0D#0A 1) Interface object ID#0D#0A 2) Interface name#0D#0A")
2303 _T(" 3) Interface IP address#0D#0A 4) Interface netmask#0D#0A")
2304 _T(" 5) Interface index')\n")
2307 if (!SQLBatch(m_szBatch
))
2308 if (!g_bIgnoreErrors
)
2311 if (!SQLQuery(_T("UPDATE config SET var_value='63' WHERE var_name='DBFormatVersion'")))
2312 if (!g_bIgnoreErrors
)
2320 // Upgrade from V61 to V62
2323 static BOOL
H_UpgradeFromV61(int currVersion
, int newVersion
)
2325 static TCHAR m_szBatch
[] =
2326 _T("UPDATE event_policy SET alarm_key=alarm_ack_key WHERE alarm_severity=6\n")
2327 _T("ALTER TABLE event_policy DROP COLUMN alarm_ack_key\n")
2328 _T("ALTER TABLE event_policy ADD alarm_timeout integer\n")
2329 _T("ALTER TABLE event_policy ADD alarm_timeout_event integer\n")
2330 _T("UPDATE event_policy SET alarm_timeout=0,alarm_timeout_event=43\n")
2331 _T("ALTER TABLE alarms ADD timeout integer\n")
2332 _T("ALTER TABLE alarms ADD timeout_event integer\n")
2333 _T("UPDATE alarms SET timeout=0,timeout_event=43\n")
2334 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
2335 _T("VALUES (43,'SYS_ALARM_TIMEOUT',1,1,'Alarm timeout expired (ID: %1; Text: %2)',")
2336 _T("'Generated when alarm timeout expires.#0D#0AParameters:#0D#0A")
2337 _T(" 1) Alarm ID#0D#0A 2) Alarm message#0D#0A 3) Alarm key#0D#0A 4) Event code')\n")
2338 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
2339 _T("VALUES (44,'SYS_LOG_RECORD_MATCHED',1,1,")
2340 _T("'Log record matched (Policy: %1; File: %2; Record: %4)',")
2341 _T("'Default event for log record match.#0D#0AParameters:#0D#0A")
2342 _T(" 1) Policy name#0D#0A 2) Log file name#0D#0A 3) Matching regular expression#0D#0A")
2343 _T(" 4) Matched record#0D#0A 5 .. 9) Reserved#0D#0A")
2344 _T(" 10 .. 99) Substrings extracted by regular expression')\n")
2347 if (!SQLBatch(m_szBatch
))
2348 if (!g_bIgnoreErrors
)
2351 if (!CreateTable(_T("CREATE TABLE lpp_groups (")
2352 _T("lpp_group_id integer not null,")
2353 _T("lpp_group_name varchar(63) not null,")
2354 _T("parent_group integer not null,")
2355 _T("PRIMARY KEY(lpp_group_id))")))
2356 if (!g_bIgnoreErrors
)
2359 if (!CreateTable(_T("CREATE TABLE lpp (")
2360 _T("lpp_id integer not null,")
2361 _T("lpp_group_id integer not null,")
2362 _T("lpp_name varchar(63) not null,")
2363 _T("lpp_version integer not null,")
2364 _T("lpp_flags integer not null,")
2365 _T("PRIMARY KEY(lpp_id))")))
2366 if (!g_bIgnoreErrors
)
2369 if (!CreateTable(_T("CREATE TABLE lpp_associations (")
2370 _T("lpp_id integer not null,")
2371 _T("node_id integer not null,")
2372 _T("log_file varchar(255) not null)")))
2373 if (!g_bIgnoreErrors
)
2376 if (!CreateTable(_T("CREATE TABLE lpp_rulesets (")
2377 _T("ruleset_id integer not null,")
2378 _T("ruleset_name varchar(63),")
2379 _T("PRIMARY KEY(ruleset_id))")))
2380 if (!g_bIgnoreErrors
)
2383 if (!CreateTable(_T("CREATE TABLE lpp_rules (")
2384 _T("lpp_id integer not null,")
2385 _T("rule_number integer not null,")
2386 _T("ruleset_id integer not null,")
2387 _T("msg_id_start integer not null,")
2388 _T("msg_id_end integer not null,")
2389 _T("severity integer not null,")
2390 _T("source_name varchar(255) not null,")
2391 _T("msg_text_regexp varchar(255) not null,")
2392 _T("event_code integer not null,")
2393 _T("PRIMARY KEY(lpp_id,rule_number))")))
2394 if (!g_bIgnoreErrors
)
2397 if (!SQLQuery(_T("UPDATE config SET var_value='62' WHERE var_name='DBFormatVersion'")))
2398 if (!g_bIgnoreErrors
)
2406 // Upgrade from V60 to V61
2409 static BOOL
H_UpgradeFromV60(int currVersion
, int newVersion
)
2411 static TCHAR m_szBatch
[] =
2412 _T("DELETE FROM object_tools WHERE tool_id=14\n")
2413 _T("DELETE FROM object_tools_table_columns WHERE tool_id=14\n")
2414 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text) ")
2415 _T("VALUES (14,'&Info->Topology table (Nortel)',2,'Topology table',1,' ','Show topology table (Nortel protocol)','#00')\n")
2416 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2417 _T("VALUES (14,0,'Peer IP','.1.3.6.1.4.1.45.1.6.13.2.1.1.3',3,0)\n")
2418 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2419 _T("VALUES (14,1,'Peer MAC','.1.3.6.1.4.1.45.1.6.13.2.1.1.5',4,0)\n")
2420 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2421 _T("VALUES (14,2,'Slot','.1.3.6.1.4.1.45.1.6.13.2.1.1.1',1,0)\n")
2422 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2423 _T("VALUES (14,3,'Port','.1.3.6.1.4.1.45.1.6.13.2.1.1.2',1,0)\n")
2424 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text) ")
2425 _T("VALUES (17,'&Info->AR&P cache (SNMP)',2,'ARP Cache',1,' ','Show ARP cache','#00')\n")
2426 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2427 _T("VALUES (17,0,'IP Address','.1.3.6.1.2.1.4.22.1.3',3,0)\n")
2428 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2429 _T("VALUES (17,1,'MAC Address','.1.3.6.1.2.1.4.22.1.2',4,0)\n")
2430 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2431 _T("VALUES (17,2,'Interface','.1.3.6.1.2.1.4.22.1.1',5,0)\n")
2432 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text) ")
2433 _T("VALUES (18,'&Info->AR&P cache (Agent)',3,")
2434 _T("'ARP Cache#7FNet.ArpCache#7F(.*) (.*) (.*)',2,' ','Show ARP cache','#00')\n")
2435 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2436 _T("VALUES (18,0,'IP Address','.1.3.6.1.2.1.4.22.1.3',0,2)\n")
2437 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2438 _T("VALUES (18,1,'MAC Address','.1.3.6.1.2.1.4.22.1.2',0,1)\n")
2439 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2440 _T("VALUES (18,2,'Interface','.1.3.6.1.2.1.4.22.1.1',5,3)\n")
2441 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text) ")
2442 _T("VALUES (19,'&Info->&Routing table (SNMP)',2,'Routing Table',1,' ','Show IP routing table','#00')\n")
2443 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2444 _T("VALUES (19,0,'Destination','.1.3.6.1.2.1.4.21.1.1',3,0)\n")
2445 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2446 _T("VALUES (19,1,'Mask','.1.3.6.1.2.1.4.21.1.11',3,0)\n")
2447 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2448 _T("VALUES (19,2,'Next hop','.1.3.6.1.2.1.4.21.1.7',3,0)\n")
2449 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2450 _T("VALUES (19,3,'Metric','.1.3.6.1.2.1.4.21.1.3',1,0)\n")
2451 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2452 _T("VALUES (19,4,'Interface','.1.3.6.1.2.1.4.21.1.2',5,0)\n")
2453 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (17,-2147483648)\n")
2454 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (18,-2147483648)\n")
2455 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (19,-2147483648)\n")
2458 if (!SQLBatch(m_szBatch
))
2459 if (!g_bIgnoreErrors
)
2462 if (!CreateConfigParam(_T("TopologyExpirationTime"), _T("900"), 1, 0))
2463 if (!g_bIgnoreErrors
)
2466 if (!CreateConfigParam(_T("TopologyDiscoveryRadius"), _T("3"), 1, 0))
2467 if (!g_bIgnoreErrors
)
2470 if (!SQLQuery(_T("UPDATE config SET var_value='61' WHERE var_name='DBFormatVersion'")))
2471 if (!g_bIgnoreErrors
)
2479 // Upgrade from V59 to V60
2482 static BOOL
H_UpgradeFromV59(int currVersion
, int newVersion
)
2484 if (!CreateTable(_T("CREATE TABLE certificates (")
2485 _T("cert_id integer not null,")
2486 _T("cert_type integer not null,")
2487 _T("cert_data $SQL:TEXT not null,")
2488 _T("subject $SQL:TEXT not null,")
2489 _T("comments $SQL:TEXT not null,")
2490 _T("PRIMARY KEY(cert_id))")))
2491 if (!g_bIgnoreErrors
)
2494 if (!CreateConfigParam(_T("SNMPRequestTimeout"), _T("2000"), 1, 1))
2495 if (!g_bIgnoreErrors
)
2498 if (!SQLQuery(_T("UPDATE config SET var_value='60' WHERE var_name='DBFormatVersion'")))
2499 if (!g_bIgnoreErrors
)
2507 // Upgrade from V58 to V59
2510 static BOOL
H_UpgradeFromV58(int currVersion
, int newVersion
)
2512 static TCHAR m_szBatch
[] =
2513 _T("ALTER TABLE users ADD cert_mapping_method integer\n")
2514 _T("ALTER TABLE users ADD cert_mapping_data $SQL:TEXT\n")
2515 _T("UPDATE users SET cert_mapping_method=0\n")
2516 _T("UPDATE users SET cert_mapping_data='#00'\n")
2519 if (!SQLBatch(m_szBatch
))
2520 if (!g_bIgnoreErrors
)
2523 if (!CreateConfigParam(_T("InternalCA"), _T("0"), 1, 1))
2524 if (!g_bIgnoreErrors
)
2527 if (!SQLQuery(_T("UPDATE config SET var_value='59' WHERE var_name='DBFormatVersion'")))
2528 if (!g_bIgnoreErrors
)
2536 // Upgrade from V57 to V58
2539 static BOOL
H_UpgradeFromV57(int currVersion
, int newVersion
)
2541 static TCHAR m_szBatch
[] =
2542 _T("ALTER TABLE object_properties ADD is_system integer\n")
2543 _T("UPDATE object_properties SET is_system=0\n")
2546 if (!SQLBatch(m_szBatch
))
2547 if (!g_bIgnoreErrors
)
2550 if (!CreateTable(_T("CREATE TABLE graphs (")
2551 _T("graph_id integer not null,")
2552 _T("owner_id integer not null,")
2553 _T("name varchar(255) not null,")
2554 _T("config $SQL:TEXT not null,")
2555 _T("PRIMARY KEY(graph_id))")))
2556 if (!g_bIgnoreErrors
)
2559 if (!CreateTable(_T("CREATE TABLE graph_acl (")
2560 _T("graph_id integer not null,")
2561 _T("user_id integer not null,")
2562 _T("user_rights integer not null,")
2563 _T("PRIMARY KEY(graph_id,user_id))")))
2564 if (!g_bIgnoreErrors
)
2567 if (!SQLQuery(_T("UPDATE config SET var_value='58' WHERE var_name='DBFormatVersion'")))
2568 if (!g_bIgnoreErrors
)
2576 // Upgrade from V56 to V57
2579 static BOOL
H_UpgradeFromV56(int currVersion
, int newVersion
)
2581 static TCHAR m_szBatch
[] =
2582 _T("ALTER TABLE items ADD resource_id integer\n")
2583 _T("UPDATE items SET resource_id=0\n")
2584 _T("ALTER TABLE nodes ADD snmp_proxy integer\n")
2585 _T("UPDATE nodes SET snmp_proxy=0\n")
2588 if (!SQLBatch(m_szBatch
))
2589 if (!g_bIgnoreErrors
)
2592 if (!SQLQuery(_T("UPDATE config SET var_value='57' WHERE var_name='DBFormatVersion'")))
2593 if (!g_bIgnoreErrors
)
2601 // Upgrade from V55 to V56
2604 static BOOL
H_UpgradeFromV55(int currVersion
, int newVersion
)
2606 static TCHAR m_szBatch
[] =
2607 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
2608 _T(" (38,'SYS_CLUSTER_RESOURCE_MOVED',1,1,")
2609 _T("'Cluster resource \"%2\" moved from node %4 to node %6',")
2610 _T("'Generated when cluster resource moved between nodes.#0D#0A")
2611 _T("Parameters:#0D#0A 1) Resource ID#0D#0A")
2612 _T(" 2) Resource name#0D#0A 3) Previous owner node ID#0D#0A")
2613 _T(" 4) Previous owner node name#0D#0A 5) New owner node ID#0D#0A")
2614 _T(" 6) New owner node name')\n")
2615 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
2616 _T(" (39,'SYS_CLUSTER_RESOURCE_DOWN',3,1,")
2617 _T("'Cluster resource \"%2\" is down (last owner was %4)',")
2618 _T("'Generated when cluster resource goes down.#0D#0A")
2619 _T("Parameters:#0D#0A 1) Resource ID#0D#0A 2) Resource name#0D#0A")
2620 _T(" 3) Last owner node ID#0D#0A 4) Last owner node name')\n")
2621 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
2622 _T(" (40,'SYS_CLUSTER_RESOURCE_UP',0,1,")
2623 _T("'Cluster resource \"%2\" is up (new owner is %4)',")
2624 _T("'Generated when cluster resource goes up.#0D#0A")
2625 _T("Parameters:#0D#0A 1) Resource ID#0D#0A 2) Resource name#0D#0A")
2626 _T(" 3) New owner node ID#0D#0A 4) New owner node name')\n")
2627 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
2628 _T(" (41,'SYS_CLUSTER_DOWN',4,1,'Cluster is down',")
2629 _T("'Generated when cluster goes down.#0D#0AParameters:#0D#0A No message-specific parameters')\n")
2630 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
2631 _T(" (42,'SYS_CLUSTER_UP',0,1,'Cluster is up',")
2632 _T("'Generated when cluster goes up.#0D#0AParameters:#0D#0A No message-specific parameters')\n")
2635 if (!SQLBatch(m_szBatch
))
2636 if (!g_bIgnoreErrors
)
2639 if (!CreateTable(_T("CREATE TABLE cluster_resources (")
2640 _T("cluster_id integer not null,")
2641 _T("resource_id integer not null,")
2642 _T("resource_name varchar(255) not null,")
2643 _T("ip_addr varchar(15) not null,")
2644 _T("PRIMARY KEY(cluster_id,resource_id))")))
2645 if (!g_bIgnoreErrors
)
2648 if (!SQLQuery(_T("UPDATE config SET var_value='56' WHERE var_name='DBFormatVersion'")))
2649 if (!g_bIgnoreErrors
)
2657 // Upgrade from V54 to V55
2660 static BOOL
H_UpgradeFromV54(int currVersion
, int newVersion
)
2662 static TCHAR m_szBatch
[] =
2663 _T("ALTER TABLE containers DROP COLUMN description\n")
2664 _T("ALTER TABLE nodes DROP COLUMN description\n")
2665 _T("ALTER TABLE templates DROP COLUMN description\n")
2666 _T("ALTER TABLE zones DROP COLUMN description\n")
2667 _T("INSERT INTO images (image_id,name,file_name_png,file_hash_png,")
2668 _T("file_name_ico,file_hash_ico) VALUES (16,'Obj.Cluster',")
2669 _T("'cluster.png','<invalid_hash>','cluster.ico','<invalid_hash>')\n")
2670 _T("INSERT INTO default_images (object_class,image_id) VALUES (14,16)\n")
2671 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
2672 _T("VALUES (12,'.1.3.6.1.4.1.45.3.46.*',3,0)\n")
2673 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
2674 _T("VALUES (13,'.1.3.6.1.4.1.45.3.52.*',3,0)\n")
2677 if (!SQLBatch(m_szBatch
))
2678 if (!g_bIgnoreErrors
)
2681 if (!CreateTable(_T("CREATE TABLE clusters (")
2682 _T("id integer not null,")
2683 _T("cluster_type integer not null,")
2684 _T("PRIMARY KEY(id))")))
2685 if (!g_bIgnoreErrors
)
2688 if (!CreateTable(_T("CREATE TABLE cluster_members (")
2689 _T("cluster_id integer not null,")
2690 _T("node_id integer not null,")
2691 _T("PRIMARY KEY(cluster_id,node_id))")))
2692 if (!g_bIgnoreErrors
)
2695 if (!CreateTable(_T("CREATE TABLE cluster_sync_subnets (")
2696 _T("cluster_id integer not null,")
2697 _T("subnet_addr varchar(15) not null,")
2698 _T("subnet_mask varchar(15) not null,")
2699 _T("PRIMARY KEY(cluster_id,subnet_addr))")))
2700 if (!g_bIgnoreErrors
)
2703 if (!CreateConfigParam(_T("WindowsConsoleUpgradeURL"), _T("http://www.netxms.org/download/netxms-%version%.exe"), 1, 0))
2704 if (!g_bIgnoreErrors
)
2707 if (!SQLQuery(_T("UPDATE config SET var_value='55' WHERE var_name='DBFormatVersion'")))
2708 if (!g_bIgnoreErrors
)
2716 // Upgrade from V53 to V54
2719 static BOOL
H_UpgradeFromV53(int currVersion
, int newVersion
)
2721 static TCHAR m_szBatch
[] =
2722 _T("CREATE INDEX idx_address_lists_list_type ON address_lists(list_type)\n")
2723 _T("DELETE FROM config WHERE var_name='EnableAccessControl'\n")
2724 _T("DELETE FROM config WHERE var_name='EnableEventAccessControl'\n")
2727 if (!CreateTable(_T("CREATE TABLE address_lists (")
2728 _T("list_type integer not null,")
2729 _T("addr_type integer not null,")
2730 _T("addr1 varchar(15) not null,")
2731 _T("addr2 varchar(15) not null)")))
2732 if (!g_bIgnoreErrors
)
2735 if (!SQLBatch(m_szBatch
))
2736 if (!g_bIgnoreErrors
)
2739 if (!CreateConfigParam(_T("ActiveNetworkDiscovery"), _T("0"), 1, 1))
2740 if (!g_bIgnoreErrors
)
2743 if (!CreateConfigParam(_T("ActiveDiscoveryInterval"), _T("7200"), 1, 1))
2744 if (!g_bIgnoreErrors
)
2747 if (!CreateConfigParam(_T("DiscoveryFilterFlags"), _T("0"), 1, 0))
2748 if (!g_bIgnoreErrors
)
2751 if (!SQLQuery(_T("UPDATE config SET var_value='54' WHERE var_name='DBFormatVersion'")))
2752 if (!g_bIgnoreErrors
)
2760 // Upgrade from V52 to V53
2763 static BOOL
H_UpgradeFromV52(int currVersion
, int newVersion
)
2768 TCHAR szQuery
[1024];
2769 static const TCHAR
*pszNewIdx
[] =
2771 _T("CREATE INDEX idx_idata_%d_id_timestamp ON idata_%d(item_id,idata_timestamp)"), // MySQL
2772 _T("CREATE INDEX idx_idata_%d_timestamp_id ON idata_%d(idata_timestamp,item_id)"), // POstgreSQL
2773 _T("CREATE CLUSTERED INDEX idx_idata_%d_id_timestamp ON idata_%d(item_id,idata_timestamp)"), // MS SQL
2774 _T("CREATE INDEX idx_idata_%d_timestamp_id ON idata_%d(idata_timestamp,item_id)"), // Oracle
2775 _T("CREATE INDEX idx_idata_%d_timestamp_id ON idata_%d(idata_timestamp,item_id)") // SQLite
2778 hResult
= SQLSelect(_T("SELECT id FROM nodes"));
2779 if (hResult
== NULL
)
2782 _tprintf(_T("Reindexing database:\n"));
2783 nCount
= DBGetNumRows(hResult
);
2784 for(i
= 0; i
< nCount
; i
++)
2786 dwId
= DBGetFieldULong(hResult
, i
, 0);
2787 _tprintf(_T(" * idata_%d\n"), dwId
);
2790 _sntprintf(szQuery
, 1024, _T("DROP INDEX idx_idata_%d_timestamp"), dwId
);
2791 DBQuery(g_hCoreDB
, szQuery
);
2794 _sntprintf(szQuery
, 1024, pszNewIdx
[g_iSyntax
], dwId
, dwId
);
2798 DBFreeResult(hResult
);
2800 // Update index creation command
2801 DBQuery(g_hCoreDB
, _T("DELETE FROM config WHERE var_name='IDataIndexCreationCommand_1'"));
2802 if (!CreateConfigParam(_T("IDataIndexCreationCommand_1"), pszNewIdx
[g_iSyntax
], 0, 1))
2803 if (!g_bIgnoreErrors
)
2806 if (!SQLQuery(_T("UPDATE config SET var_value='53' WHERE var_name='DBFormatVersion'")))
2807 if (!g_bIgnoreErrors
)
2815 // Upgrade from V51 to V52
2818 static BOOL
H_UpgradeFromV51(int currVersion
, int newVersion
)
2820 static TCHAR m_szBatch
[] =
2821 _T("UPDATE object_tools SET tool_data='Configured ICMP targets#7FICMP.TargetList#7F^(.*) (.*) (.*) (.*) (.*)' WHERE tool_id=12\n")
2822 _T("UPDATE object_tools_table_columns SET col_number=4 WHERE col_number=3 AND tool_id=12\n")
2823 _T("UPDATE object_tools_table_columns SET col_number=3 WHERE col_number=2 AND tool_id=12\n")
2824 _T("UPDATE object_tools_table_columns SET col_substr=5 WHERE col_number=1 AND tool_id=12\n")
2825 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2826 _T("VALUES (12,2,'Packet size','',0,4)\n")
2827 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text) ")
2828 _T("VALUES (16,'&Info->Active &user sessions',3,")
2829 _T("'Active User Sessions#7FSystem.ActiveUserSessions#7F^\"(.*)\" \"(.*)\" \"(.*)\"',")
2830 _T("2,'','Show list of active user sessions','#00')\n")
2831 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2832 _T("VALUES (16,0,'User','',0,1)\n")
2833 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2834 _T("VALUES (16,1,'Terminal','',0,2)\n")
2835 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2836 _T("VALUES (16,2,'From','',0,3)\n")
2837 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (16,-2147483648)\n")
2840 if (!SQLBatch(m_szBatch
))
2841 if (!g_bIgnoreErrors
)
2844 if (!CreateConfigParam(_T("MailEncoding"), _T("iso-8859-1"), 1, 0))
2845 if (!g_bIgnoreErrors
)
2848 if (!SQLQuery(_T("UPDATE config SET var_value='52' WHERE var_name='DBFormatVersion'")))
2849 if (!g_bIgnoreErrors
)
2857 // Upgrade from V50 to V51
2860 static BOOL
H_UpgradeFromV50(int currVersion
, int newVersion
)
2862 static TCHAR m_szBatch
[] =
2863 _T("ALTER TABLE event_groups ADD range_start integer\n")
2864 _T("ALTER TABLE event_groups ADD range_END integer\n")
2865 _T("UPDATE event_groups SET range_start=0,range_end=0\n")
2868 if (!SQLBatch(m_szBatch
))
2869 if (!g_bIgnoreErrors
)
2872 if (!SQLQuery(_T("UPDATE config SET var_value='51' WHERE var_name='DBFormatVersion'")))
2873 if (!g_bIgnoreErrors
)
2881 // Upgrade from V49 to V50
2884 static BOOL
H_UpgradeFromV49(int currVersion
, int newVersion
)
2886 static TCHAR m_szBatch
[] =
2887 _T("ALTER TABLE object_tools ADD confirmation_text varchar(255)\n")
2888 _T("UPDATE object_tools SET confirmation_text='#00'\n")
2889 _T("UPDATE object_tools SET flags=10 WHERE tool_id=1 OR tool_id=2 OR tool_id=4\n")
2890 _T("UPDATE object_tools SET confirmation_text='Host #25OBJECT_NAME#25 (#25OBJECT_IP_ADDR#25) will be shut down. Are you sure?' WHERE tool_id=1\n")
2891 _T("UPDATE object_tools SET confirmation_text='Host #25OBJECT_NAME#25 (#25OBJECT_IP_ADDR#25) will be restarted. Are you sure?' WHERE tool_id=2\n")
2892 _T("UPDATE object_tools SET confirmation_text='NetXMS agent on host #25OBJECT_NAME#25 (#25OBJECT_IP_ADDR#25) will be restarted. Are you sure?' WHERE tool_id=4\n")
2895 if (!SQLBatch(m_szBatch
))
2896 if (!g_bIgnoreErrors
)
2899 if (!SQLQuery(_T("UPDATE config SET var_value='50' WHERE var_name='DBFormatVersion'")))
2900 if (!g_bIgnoreErrors
)
2908 // Upgrade from V48 to V49
2911 static BOOL
H_UpgradeFromV48(int currVersion
, int newVersion
)
2913 static TCHAR m_szBatch
[] =
2914 _T("ALTER TABLE items ADD all_thresholds integer\n")
2915 _T("UPDATE items SET all_thresholds=0\n")
2916 _T("ALTER TABLE thresholds ADD rearm_event_code integer\n")
2917 _T("UPDATE thresholds SET rearm_event_code=18\n")
2920 if (!SQLBatch(m_szBatch
))
2921 if (!g_bIgnoreErrors
)
2924 if (!SQLQuery(_T("UPDATE config SET var_value='49' WHERE var_name='DBFormatVersion'")))
2925 if (!g_bIgnoreErrors
)
2933 // Upgrade from V47 to V48
2936 static BOOL
H_UpgradeFromV47(int currVersion
, int newVersion
)
2938 static TCHAR m_szBatch
[] =
2939 _T("ALTER TABLE event_policy ADD script $SQL:TEXT\n")
2940 _T("UPDATE event_policy SET script='#00'\n")
2943 if (!SQLBatch(m_szBatch
))
2944 if (!g_bIgnoreErrors
)
2947 if (!CreateTable(_T("CREATE TABLE policy_time_range_list (")
2948 _T("rule_id integer not null,")
2949 _T("time_range_id integer not null,")
2950 _T("PRIMARY KEY(rule_id,time_range_id))")))
2951 if (!g_bIgnoreErrors
)
2954 if (!CreateTable(_T("CREATE TABLE time_ranges (")
2955 _T("time_range_id integer not null,")
2956 _T("wday_mask integer not null,")
2957 _T("mday_mask integer not null,")
2958 _T("month_mask integer not null,")
2959 _T("time_range varchar(255) not null,")
2960 _T("PRIMARY KEY(time_range_id))")))
2961 if (!g_bIgnoreErrors
)
2964 if (!SQLQuery(_T("UPDATE config SET var_value='48' WHERE var_name='DBFormatVersion'")))
2965 if (!g_bIgnoreErrors
)
2973 // Upgrade from V46 to V47
2976 static BOOL
H_UpgradeFromV46(int currVersion
, int newVersion
)
2978 static TCHAR m_szBatch
[] =
2979 _T("ALTER TABLE object_properties ADD comments $SQL:TEXT\n")
2980 _T("UPDATE object_properties SET comments='#00'\n")
2981 _T("ALTER TABLE nodes DROP COLUMN discovery_flags\n")
2982 _T("DROP TABLE alarm_notes\n")
2983 _T("ALTER TABLE alarms ADD alarm_state integer\n")
2984 _T("ALTER TABLE alarms ADD hd_state integer\n")
2985 _T("ALTER TABLE alarms ADD hd_ref varchar(63)\n")
2986 _T("ALTER TABLE alarms ADD creation_time integer\n")
2987 _T("ALTER TABLE alarms ADD last_change_time integer\n")
2988 _T("ALTER TABLE alarms ADD original_severity integer\n")
2989 _T("ALTER TABLE alarms ADD current_severity integer\n")
2990 _T("ALTER TABLE alarms ADD repeat_count integer\n")
2991 _T("ALTER TABLE alarms ADD term_by integer\n")
2992 _T("UPDATE alarms SET hd_state=0,hd_ref='#00',creation_time=alarm_timestamp,")
2993 _T("last_change_time=alarm_timestamp,original_severity=severity,")
2994 _T("current_severity=severity,repeat_count=1,term_by=ack_by\n")
2995 _T("UPDATE alarms SET alarm_state=0 WHERE is_ack=0\n")
2996 _T("UPDATE alarms SET alarm_state=2 WHERE is_ack<>0\n")
2997 _T("ALTER TABLE alarms DROP COLUMN severity\n")
2998 _T("ALTER TABLE alarms DROP COLUMN alarm_timestamp\n")
2999 _T("ALTER TABLE alarms DROP COLUMN is_ack\n")
3000 _T("ALTER TABLE thresholds ADD current_state integer\n")
3001 _T("UPDATE thresholds SET current_state=0\n")
3003 static TCHAR m_szBatch2
[] =
3004 _T("CREATE INDEX idx_alarm_notes_alarm_id ON alarm_notes(alarm_id)\n")
3005 _T("CREATE INDEX idx_alarm_change_log_alarm_id ON alarm_change_log(alarm_id)\n")
3008 if (!SQLBatch(m_szBatch
))
3009 if (!g_bIgnoreErrors
)
3012 if (!CreateTable(_T("CREATE TABLE alarm_notes ("
3013 _T("note_id integer not null,")
3014 _T("alarm_id integer not null,")
3015 _T("change_time integer not null,")
3016 _T("user_id integer not null,")
3017 _T("note_text $SQL:TEXT not null,")
3018 _T("PRIMARY KEY(note_id))"))))
3019 if (!g_bIgnoreErrors
)
3022 if (!CreateTable(_T("CREATE TABLE alarm_change_log ("
3023 _T("change_id $SQL:INT64 not null,")
3024 _T("change_time integer not null,")
3025 _T("alarm_id integer not null,")
3026 _T("opcode integer not null,")
3027 _T("user_id integer not null,")
3028 _T("info_text $SQL:TEXT not null,")
3029 _T("PRIMARY KEY(change_id))"))))
3030 if (!g_bIgnoreErrors
)
3033 if (!CreateTable(_T("CREATE TABLE alarm_grops ("
3034 _T("alarm_group_id integer not null,")
3035 _T("group_name varchar(255) not null,")
3036 _T("PRIMARY KEY(alarm_group_id))"))))
3037 if (!g_bIgnoreErrors
)
3040 if (!CreateTable(_T("CREATE TABLE alarm_group_map ("
3041 _T("alarm_group_id integer not null,")
3042 _T("alarm_id integer not null,")
3043 _T("PRIMARY KEY(alarm_group_id,alarm_id))"))))
3044 if (!g_bIgnoreErrors
)
3047 if (!SQLBatch(m_szBatch2
))
3048 if (!g_bIgnoreErrors
)
3051 if (!SQLQuery(_T("UPDATE config SET var_value='47' WHERE var_name='DBFormatVersion'")))
3052 if (!g_bIgnoreErrors
)
3060 // Upgrade from V45 to V46
3063 static BOOL
H_UpgradeFromV45(int currVersion
, int newVersion
)
3065 static TCHAR m_szBatch
[] =
3066 _T("UPDATE object_tools_table_columns SET col_format=5 WHERE tool_id=5 AND col_number=1\n")
3067 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
3068 _T("VALUES (2,'.1.3.6.1.4.1.45.3.26.*',3,0)\n")
3069 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
3070 _T("VALUES (3,'.1.3.6.1.4.1.45.3.30.*',3,0)\n")
3071 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
3072 _T("VALUES (4,'.1.3.6.1.4.1.45.3.31.*',3,0)\n")
3073 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
3074 _T("VALUES (5,'.1.3.6.1.4.1.45.3.32.*',3,0)\n")
3075 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
3076 _T("VALUES (6,'.1.3.6.1.4.1.45.3.33.*',3,0)\n")
3077 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
3078 _T("VALUES (7,'.1.3.6.1.4.1.45.3.34.*',3,0)\n")
3079 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
3080 _T("VALUES (8,'.1.3.6.1.4.1.45.3.35.*',3,0)\n")
3081 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
3082 _T("VALUES (9,'.1.3.6.1.4.1.45.3.36.*',3,0)\n")
3083 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
3084 _T("VALUES (10,'.1.3.6.1.4.1.45.3.40.*',3,0)\n")
3085 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
3086 _T("VALUES (11,'.1.3.6.1.4.1.45.3.61.*',3,0)\n")
3087 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description) ")
3088 _T("VALUES (14,'&Info->Topology table (Nortel)',2 ,'Topology table',1,'','Show topology table (Nortel protocol)')\n")
3089 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
3090 _T("VALUES (14,0,'Peer IP','.1.3.6.1.4.1.45.1.6.13.2.1.1.3',3 ,0)\n")
3091 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
3092 _T("VALUES (14,1,'Peer MAC','.1.3.6.1.4.1.45.1.6.13.2.1.1.5',4 ,0)\n")
3093 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
3094 _T("VALUES (14,2,'Port','.1.3.6.1.4.1.45.1.6.13.2.1.1.2',5 ,0)\n")
3095 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (14,-2147483648)\n")
3096 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description) ")
3097 _T("VALUES (15,'&Info->Topology table (CDP)',2 ,'Topology table',1,'','Show topology table (CDP)')\n")
3098 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
3099 _T("VALUES (15,0,'Device ID','.1.3.6.1.4.1.9.9.23.1.2.1.1.6',0 ,0)\n")
3100 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
3101 _T("VALUES (15,1,'IP Address','.1.3.6.1.4.1.9.9.23.1.2.1.1.4',3 ,0)\n")
3102 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
3103 _T("VALUES (15,2,'Platform','.1.3.6.1.4.1.9.9.23.1.2.1.1.8',0 ,0)\n")
3104 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
3105 _T("VALUES (15,3,'Version','.1.3.6.1.4.1.9.9.23.1.2.1.1.5',0 ,0)\n")
3106 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
3107 _T("VALUES (15,4,'Port','.1.3.6.1.4.1.9.9.23.1.2.1.1.7',0 ,0)\n")
3108 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (15,-2147483648)\n")
3111 if (!SQLBatch(m_szBatch
))
3112 if (!g_bIgnoreErrors
)
3115 if (!SQLQuery(_T("UPDATE config SET var_value='46' WHERE var_name='DBFormatVersion'")))
3116 if (!g_bIgnoreErrors
)
3124 // Upgrade from V44 to V45
3127 static BOOL
H_UpgradeFromV44(int currVersion
, int newVersion
)
3129 static TCHAR m_szBatch
[] =
3130 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
3131 _T("VALUES (36,'SYS_DB_CONN_LOST',4,1,")
3132 _T("'Lost connection with backend database engine',")
3133 _T("'Generated if connection with backend database engine is lost.#0D#0A")
3134 _T("Parameters:#0D#0A No message-specific parameters')\n")
3135 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
3136 _T("VALUES (37,'SYS_DB_CONN_RESTORED',0,1,")
3137 _T("'Connection with backend database engine restored',")
3138 _T("'Generated when connection with backend database engine restored.#0D#0A")
3139 _T("Parameters:#0D#0A No message-specific parameters')\n")
3142 if (!SQLBatch(m_szBatch
))
3143 if (!g_bIgnoreErrors
)
3146 if (!SQLQuery(_T("UPDATE config SET var_value='45' WHERE var_name='DBFormatVersion'")))
3147 if (!g_bIgnoreErrors
)
3155 // Upgrade from V43 to V44
3158 static BOOL
H_UpgradeFromV43(int currVersion
, int newVersion
)
3160 static TCHAR m_szBatch
[] =
3161 _T("DELETE FROM object_tools WHERE tool_id=8000\n")
3162 _T("DELETE FROM object_tools_table_columns WHERE tool_id=8000\n")
3163 _T("DELETE FROM object_tools_acl WHERE tool_id=8000\n")
3164 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,")
3165 _T("matching_oid,description) VALUES (13,'&Info->&Process list',3,")
3166 _T("'Process List#7FSystem.ProcessList#7F^([0-9]+) (.*)',2,'',")
3167 _T("'Show list of currently running processes')\n")
3168 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,")
3169 _T("col_oid,col_format,col_substr) VALUES (13,0,'PID','',0,1)\n")
3170 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,")
3171 _T("col_oid,col_format,col_substr) VALUES (13,1,'Name','',0,2)\n")
3172 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (13,-2147483648)\n")
3175 if (!CreateTable(_T("CREATE TABLE agent_configs ("
3176 _T("config_id integer not null,")
3177 _T("config_name varchar(255) not null,")
3178 _T("config_file $SQL:TEXT not null,")
3179 _T("config_filter $SQL:TEXT not null,")
3180 _T("sequence_number integer not null,")
3181 _T("PRIMARY KEY(config_id))"))))
3182 if (!g_bIgnoreErrors
)
3185 if (!SQLBatch(m_szBatch
))
3186 if (!g_bIgnoreErrors
)
3189 if (!CreateConfigParam(_T("DBLockPID"), _T("0"), 0, 0))
3190 if (!g_bIgnoreErrors
)
3193 if (!SQLQuery(_T("UPDATE config SET var_value='44' WHERE var_name='DBFormatVersion'")))
3194 if (!g_bIgnoreErrors
)
3202 // Upgrade from V42 to V43
3205 static BOOL
H_UpgradeFromV42(int currVersion
, int newVersion
)
3207 if (!CreateConfigParam(_T("RADIUSPort"), _T("1645"), 1, 0))
3208 if (!g_bIgnoreErrors
)
3211 if (!SQLQuery(_T("UPDATE config SET var_value='43' WHERE var_name='DBFormatVersion'")))
3212 if (!g_bIgnoreErrors
)
3220 // Upgrade from V41 to V42
3223 static BOOL
H_UpgradeFromV41(int currVersion
, int newVersion
)
3225 static TCHAR m_szBatch
[] =
3226 _T("INSERT INTO images (image_id,name,file_name_png,file_hash_png,")
3227 _T("file_name_ico,file_hash_ico) VALUES (15,'Obj.Condition',")
3228 _T("'condition.png','<invalid_hash>','condition.ico','<invalid_hash>')\n")
3229 _T("INSERT INTO default_images (object_class,image_id) VALUES (13, 15)\n")
3230 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
3231 _T("VALUES (1,'.1.3.6.1.4.1.3224.1.*',2,0)\n")
3232 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
3233 _T("VALUES (34,'SYS_CONDITION_ACTIVATED',2,1,'Condition \"%2\" activated',")
3234 _T("'Default event for condition activation.#0D#0AParameters:#0D#0A")
3235 _T(" 1) Condition object ID#0D#0A 2) Condition object name#0D#0A")
3236 _T(" 3) Previous condition status#0D#0A 4) Current condition status')\n")
3237 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
3238 _T("VALUES (35,'SYS_CONDITION_DEACTIVATED',0,1,'Condition \"%2\" deactivated',")
3239 _T("'Default event for condition deactivation.#0D#0AParameters:#0D#0A")
3240 _T(" 1) Condition object ID#0D#0A 2) Condition object name#0D#0A")
3241 _T(" 3) Previous condition status#0D#0A 4) Current condition status')\n")
3244 if (!CreateTable(_T("CREATE TABLE conditions ("
3245 _T("id integer not null,")
3246 _T("activation_event integer not null,")
3247 _T("deactivation_event integer not null,")
3248 _T("source_object integer not null,")
3249 _T("active_status integer not null,")
3250 _T("inactive_status integer not null,")
3251 _T("script $SQL:TEXT not null,")
3252 _T("PRIMARY KEY(id))"))))
3253 if (!g_bIgnoreErrors
)
3256 if (!CreateTable(_T("CREATE TABLE cond_dci_map ("
3257 _T("condition_id integer not null,")
3258 _T("dci_id integer not null,")
3259 _T("node_id integer not null,")
3260 _T("dci_func integer not null,")
3261 _T("num_polls integer not null,")
3262 _T("PRIMARY KEY(condition_id,dci_id))"))))
3263 if (!g_bIgnoreErrors
)
3266 if (!SQLBatch(m_szBatch
))
3267 if (!g_bIgnoreErrors
)
3270 if (!CreateConfigParam(_T("NumberOfConditionPollers"), _T("10"), 1, 1))
3271 if (!g_bIgnoreErrors
)
3274 if (!CreateConfigParam(_T("ConditionPollingInterval"), _T("60"), 1, 1))
3275 if (!g_bIgnoreErrors
)
3278 if (!SQLQuery(_T("UPDATE config SET var_value='42' WHERE var_name='DBFormatVersion'")))
3279 if (!g_bIgnoreErrors
)
3287 // Upgrade from V40 to V41
3290 static BOOL
H_UpgradeFromV40(int currVersion
, int newVersion
)
3292 static TCHAR m_szBatch
[] =
3293 _T("ALTER TABLE users ADD guid varchar(36)\n")
3294 _T("ALTER TABLE users ADD auth_method integer\n")
3295 _T("ALTER TABLE user_groups ADD guid varchar(36)\n")
3296 _T("UPDATE users SET auth_method=0\n")
3302 TCHAR szQuery
[256], szGUID
[64];
3304 if (!SQLBatch(m_szBatch
))
3305 if (!g_bIgnoreErrors
)
3308 // Generate GUIDs for users and groups
3309 _tprintf(_T("Generating GUIDs...\n"));