fixed bug in GetCurrentTimeMs
[public/netxms.git] / src / server / tools / nxdbmgr / upgrade.cpp
CommitLineData
5039dede
AK
1/*
2** nxdbmgr - NetXMS database manager
a8f60046 3** Copyright (C) 2004-2010 Victor Kirhenshtein
5039dede
AK
4**
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.
9**
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.
14**
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.
18**
19** File: upgrade.cpp
20**
21**/
22
23#include "nxdbmgr.h"
24
25
1024e962
VK
26//
27// Execute with error check
28//
29
30#define CHK_EXEC(x) if (!(x)) if (!g_bIgnoreErrors) return FALSE;
31
32
5039dede
AK
33//
34// Create table
35//
36
37static BOOL CreateTable(const TCHAR *pszQuery)
38{
39 TCHAR *pszBuffer;
40 BOOL bResult;
41
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]);
99d1de07 45 TranslateStr(pszBuffer, _T("$SQL:TEXT4K"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT4K]);
5039dede
AK
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);
50 free(pszBuffer);
51 return bResult;
52}
53
54
55//
56// Create configuration parameter if it doesn't exist (unless bForceUpdate set to true)
57//
58
59static BOOL CreateConfigParam(const TCHAR *pszName, const TCHAR *pszValue,
60 int iVisible, int iNeedRestart, BOOL bForceUpdate = FALSE)
61{
62 TCHAR szQuery[1024], *pszEscValue;
63 DB_RESULT hResult;
64 BOOL bVarExist = FALSE, bResult = TRUE;
65
66 // Check for variable existence
08b214c6 67 _sntprintf(szQuery, 1024, _T("SELECT var_value FROM config WHERE var_name='%s'"), pszName);
5039dede
AK
68 hResult = DBSelect(g_hCoreDB, szQuery);
69 if (hResult != 0)
70 {
71 if (DBGetNumRows(hResult) > 0)
72 bVarExist = TRUE;
73 DBFreeResult(hResult);
74 }
75
76 if (!bVarExist)
77 {
78 pszEscValue = EncodeSQLString(pszValue);
08b214c6
VK
79 _sntprintf(szQuery, 1024, _T("INSERT INTO config (var_name,var_value,is_visible,")
80 _T("need_server_restart) VALUES ('%s','%s',%d,%d)"),
5039dede
AK
81 pszName, pszEscValue, iVisible, iNeedRestart);
82 free(pszEscValue);
83 bResult = SQLQuery(szQuery);
84 }
85 else if (bForceUpdate)
86 {
87 pszEscValue = EncodeSQLString(pszValue);
08b214c6 88 _sntprintf(szQuery, 1024, _T("UPDATE config SET var_value='%s' WHERE var_name='%s'"),
5039dede
AK
89 pszEscValue, pszName);
90 free(pszEscValue);
91 bResult = SQLQuery(szQuery);
92 }
93 return bResult;
94}
95
96
97//
98// Set primary key constraint
99//
100
101static BOOL SetPrimaryKey(const TCHAR *table, const TCHAR *key)
102{
103 TCHAR query[4096];
104
105 if (g_iSyntax == DB_SYNTAX_SQLITE)
106 return TRUE; // SQLite does not support adding constraints
107
108 _sntprintf(query, 4096, _T("ALTER TABLE %s ADD PRIMARY KEY (%s)"), table, key);
109 return SQLQuery(query);
110}
111
112
9bfc9a6b
VK
113//
114// Drop primary key from table
115//
116
117static BOOL DropPrimaryKey(const TCHAR *table)
118{
119 TCHAR query[1024];
120 DB_RESULT hResult;
121 BOOL success;
122
123 switch(g_iSyntax)
124 {
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);
129 break;
130 case DB_SYNTAX_PGSQL:
131 _sntprintf(query, 1024, _T("ALTER TABLE %s DROP CONSTRAINT %s_pkey"), table, table);
132 success = SQLQuery(query);
133 break;
134 case DB_SYNTAX_MSSQL:
135 success = FALSE;
136 _sntprintf(query, 1024, _T("SELECT name FROM sysobjects WHERE xtype='PK' AND parent_obj=OBJECT_ID('%s')"), table);
137 hResult = SQLSelect(query);
138 if (hResult != NULL)
139 {
140 if (DBGetNumRows(hResult) > 0)
141 {
142 TCHAR objName[512];
143
144 DBGetField(hResult, 0, 0, objName, 512);
145 _sntprintf(query, 1024, _T("ALTER TABLE %s DROP CONSTRAINT %s"), table, objName);
146 success = SQLQuery(query);
147 }
148 DBFreeResult(hResult);
149 }
150 break;
151 default: // Unsupported DB engine
152 success = FALSE;
153 break;
154 }
155 return success;
156}
157
158
643c9dcb 159//
83f4afe0 160// Convert strings from # encoded form to normal form
643c9dcb
VK
161//
162
163static BOOL ConvertStrings(const TCHAR *table, const TCHAR *idColumn, const TCHAR *column)
164{
165 DB_RESULT hResult;
166 TCHAR *query;
167 int queryLen = 512;
168 BOOL success = FALSE;
169
170 query = (TCHAR *)malloc(queryLen);
fe12a1ea 171
a4743a0f
VK
172 switch(g_iSyntax)
173 {
174 case DB_SYNTAX_MSSQL:
9f6712bc 175 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE CAST(%s AS nvarchar(4000))=N'#00'"), table, column, column);
a4743a0f
VK
176 break;
177 case DB_SYNTAX_ORACLE:
178 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE to_char(%s)='#00'"), table, column, column);
179 break;
180 default:
181 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE %s='#00'"), table, column, column);
182 break;
183 }
fe12a1ea
VK
184 if (!SQLQuery(query))
185 {
186 free(query);
187 return FALSE;
188 }
189
190 _sntprintf(query, queryLen, _T("SELECT %s,%s FROM %s WHERE %s LIKE '%%#%%'"), idColumn, column, table, column);
643c9dcb
VK
191 hResult = SQLSelect(query);
192 if (hResult == NULL)
193 {
194 free(query);
195 return FALSE;
196 }
197
198 int count = DBGetNumRows(hResult);
199 for(int i = 0; i < count; i++)
200 {
201 INT64 id = DBGetFieldInt64(hResult, i, 0);
202 TCHAR *value = DBGetField(hResult, i, 1, NULL, 0);
035a4d73 203 if (_tcschr(value, _T('#')) != NULL)
643c9dcb 204 {
035a4d73
VK
205 DecodeSQLString(value);
206 String newValue = DBPrepareString(g_hCoreDB, value);
207 if ((int)newValue.getSize() + 256 > queryLen)
208 {
209 queryLen = newValue.getSize() + 256;
210 query = (TCHAR *)realloc(query, queryLen);
211 }
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))
215 goto cleanup;
643c9dcb 216 }
643c9dcb
VK
217 }
218 success = TRUE;
219
220cleanup:
221 DBFreeResult(hResult);
a4743a0f 222 free(query);
643c9dcb
VK
223 return success;
224}
225
226
1024e962
VK
227//
228// Set column nullable (currently Oracle only implementation)
229//
230
231static BOOL SetColumnNullable(const TCHAR *table, const TCHAR *column, const TCHAR *type)
232{
233 TCHAR query[1024] = _T("");
234
235 switch(g_iSyntax)
236 {
237 case DB_SYNTAX_ORACLE:
238 _sntprintf(query, 1024, _T("DECLARE already_null EXCEPTION; ")
239 _T("PRAGMA EXCEPTION_INIT(already_null, -1451); ")
f57209fd
VK
240 _T("BEGIN EXECUTE IMMEDIATE 'ALTER TABLE %s MODIFY %s null'; ")
241 _T("EXCEPTION WHEN already_null THEN null; END;"), table, column);
1024e962
VK
242 break;
243 default:
244 break;
245 }
246
247 return (query[0] != 0) ? SQLQuery(query) : TRUE;
248}
249
250
4fe87cdc
VK
251//
252// Upgrade from V217 to V218
253//
254
255static BOOL H_UpgradeFromV217(int currVersion, int newVersion)
256{
257 CHK_EXEC(SetColumnNullable(_T("snmp_communities"), _T("community"), _T("varchar(255)")));
258 CHK_EXEC(ConvertStrings(_T("snmp_communities"), _T("id"), _T("community")));
259
260 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='218' WHERE var_name='SchemaVersion'")));
261 return TRUE;
262}
263
264
65e2005b
VK
265//
266// Upgrade from V216 to V217
267//
268
269static BOOL H_UpgradeFromV216(int currVersion, int newVersion)
270{
271 static TCHAR batch[] =
272 _T("ALTER TABLE nodes ADD snmp_port integer\n")
8cad4ebb 273 _T("UPDATE nodes SET snmp_port=161\n")
65e2005b
VK
274 _T("ALTER TABLE items ADD snmp_port integer\n")
275 _T("UPDATE items SET snmp_port=0\n")
276 _T("<END>");
277
278 CHK_EXEC(SQLBatch(batch));
279
280 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("community"), _T("varchar(127)")));
281 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("community")));
282
283 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("usm_auth_password"), _T("varchar(127)")));
284 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("usm_auth_password")));
285
286 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("usm_priv_password"), _T("varchar(127)")));
287 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("usm_priv_password")));
288
289 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("snmp_oid"), _T("varchar(255)")));
290 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("snmp_oid")));
291
292 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("secret"), _T("varchar(64)")));
293 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("secret")));
294
295 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("agent_version"), _T("varchar(63)")));
296 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("agent_version")));
297
298 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("platform_name"), _T("varchar(63)")));
299 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("platform_name")));
300
301 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("uname"), _T("varchar(255)")));
302 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("uname")));
303
304 CHK_EXEC(SetColumnNullable(_T("items"), _T("name"), _T("varchar(255)")));
305 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("name")));
306
307 CHK_EXEC(SetColumnNullable(_T("items"), _T("description"), _T("varchar(255)")));
308 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("description")));
309
8cad4ebb 310 CHK_EXEC(SetColumnNullable(_T("items"), _T("transformation"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]));
65e2005b
VK
311 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("transformation")));
312
313 CHK_EXEC(SetColumnNullable(_T("items"), _T("instance"), _T("varchar(255)")));
314 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("instance")));
315
316 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='217' WHERE var_name='SchemaVersion'")));
317 return TRUE;
318}
319
320
3f7c0fe4
VK
321//
322// Upgrade from V215 to V216
323//
324
325static BOOL H_UpgradeFromV215(int currVersion, int newVersion)
326{
327 CHK_EXEC(SetColumnNullable(_T("ap_common"), _T("description"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]));
328 CHK_EXEC(ConvertStrings(_T("ap_common"), _T("id"), _T("description")));
329
a6c1f07f
VK
330 if (g_iSyntax != DB_SYNTAX_SQLITE)
331 CHK_EXEC(SQLQuery(_T("ALTER TABLE ap_config_files DROP COLUMN file_name")));
332
a30fa363
VK
333 CHK_EXEC(SetColumnNullable(_T("ap_config_files"), _T("file_content"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]));
334 CHK_EXEC(ConvertStrings(_T("ap_config_files"), _T("policy_id"), _T("file_content")));
335
3f7c0fe4
VK
336 CHK_EXEC(SQLQuery(_T("ALTER TABLE object_properties ADD guid varchar(36)")));
337
338 // Generate GUIDs for all objects
339 DB_RESULT hResult = SQLSelect(_T("SELECT object_id FROM object_properties"));
340 if (hResult != NULL)
341 {
342 int count = DBGetNumRows(hResult);
343 for(int i = 0; i < count; i++)
344 {
345 uuid_t guid;
346 TCHAR query[256], buffer[64];
347
348 uuid_generate(guid);
349 _sntprintf(query, 256, _T("UPDATE object_properties SET guid='%s' WHERE object_id=%d"),
350 uuid_to_string(guid, buffer), DBGetFieldULong(hResult, i, 0));
351 CHK_EXEC(SQLQuery(query));
352 }
353 DBFreeResult(hResult);
354 }
355
356 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='216' WHERE var_name='SchemaVersion'")));
357 return TRUE;
358}
359
360
021dcda7
VK
361//
362// Upgrade from V214 to V215
363//
364
365static BOOL H_UpgradeFromV214(int currVersion, int newVersion)
366{
367 CHK_EXEC(CreateTable(_T("CREATE TABLE network_maps (")
368 _T("id integer not null,")
369 _T("map_type integer not null,")
370 _T("layout integer not null,")
371 _T("seed integer not null,")
372 _T("background integer not null,")
373 _T("PRIMARY KEY(id))")));
374
375 CHK_EXEC(CreateTable(_T("CREATE TABLE network_map_elements (")
376 _T("map_id integer not null,")
377 _T("element_id integer not null,")
378 _T("element_type integer not null,")
379 _T("element_data $SQL:TEXT not null,")
380 _T("PRIMARY KEY(map_id,element_id))")));
381
cce8f214
VK
382 CHK_EXEC(CreateTable(_T("CREATE TABLE network_map_links (")
383 _T("map_id integer not null,")
384 _T("element1 integer not null,")
385 _T("element2 integer not null,")
386 _T("link_type integer not null,")
387 _T("link_name varchar(255) null,")
388 _T("connector_name1 varchar(255) null,")
389 _T("connector_name2 varchar(255) null,")
390 _T("PRIMARY KEY(map_id,element1,element2))")));
391
021dcda7
VK
392 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='215' WHERE var_name='SchemaVersion'")));
393 return TRUE;
394}
395
396
50da2d20
VK
397//
398// Upgrade from V213 to V214
399//
400
401static BOOL H_UpgradeFromV213(int currVersion, int newVersion)
402{
403 CHK_EXEC(SetColumnNullable(_T("script_library"), _T("script_code"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]));
404 CHK_EXEC(ConvertStrings(_T("script_library"), _T("script_id"), _T("script_code")));
405
406 CHK_EXEC(SetColumnNullable(_T("raw_dci_values"), _T("raw_value"), _T("varchar(255)")));
407 CHK_EXEC(ConvertStrings(_T("raw_dci_values"), _T("item_id"), _T("raw_value")));
408
409 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'")));
410
411 DB_RESULT hResult = SQLSelect(_T("SELECT id FROM nodes"));
412 if (hResult != NULL)
413 {
414 int count = DBGetNumRows(hResult);
415 for(int i = 0; i < count; i++)
416 {
417 TCHAR table[32];
418
419 DWORD nodeId = DBGetFieldULong(hResult, i, 0);
420 _sntprintf(table, 32, _T("idata_%d"), nodeId);
421 CHK_EXEC(SetColumnNullable(table, _T("idata_value"), _T("varchar(255)")));
422 }
423 DBFreeResult(hResult);
424 }
425
426 // Convert values for string DCIs from # encoded to normal form
427 hResult = SQLSelect(_T("SELECT node_id,item_id FROM items WHERE datatype=4"));
428 if (hResult != NULL)
429 {
430 int count = DBGetNumRows(hResult);
431 for(int i = 0; i < count; i++)
432 {
433 TCHAR query[512];
434
435 DWORD nodeId = DBGetFieldULong(hResult, i, 0);
436 DWORD dciId = DBGetFieldULong(hResult, i, 1);
437
035a4d73 438 if (IsNodeExist(nodeId))
50da2d20 439 {
3f7c0fe4 440 _sntprintf(query, 512, _T("SELECT idata_timestamp,idata_value FROM idata_%d WHERE item_id=%d AND idata_value LIKE '%%#%%'"), nodeId, dciId);
035a4d73
VK
441 DB_RESULT hData = SQLSelect(query);
442 if (hData != NULL)
50da2d20 443 {
035a4d73
VK
444 int valueCount = DBGetNumRows(hData);
445 for(int j = 0; j < valueCount; j++)
446 {
447 TCHAR buffer[MAX_DB_STRING];
448
449 LONG ts = DBGetFieldLong(hData, j, 0);
450 DBGetField(hData, j, 1, buffer, MAX_DB_STRING);
3f7c0fe4
VK
451 DecodeSQLString(buffer);
452
453 _sntprintf(query, 512, _T("UPDATE idata_%d SET idata_value=%s WHERE item_id=%d AND idata_timestamp=%ld"),
454 nodeId, (const TCHAR *)DBPrepareString(g_hCoreDB, buffer), dciId, (long)ts);
455 CHK_EXEC(SQLQuery(query));
035a4d73
VK
456 }
457 DBFreeResult(hData);
50da2d20 458 }
50da2d20
VK
459 }
460 }
461 DBFreeResult(hResult);
462 }
463
464 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='214' WHERE var_name='SchemaVersion'")));
50da2d20
VK
465 return TRUE;
466}
467
468
f57209fd
VK
469//
470// Upgrade from V212 to V213
471//
472
473static BOOL H_UpgradeFromV212(int currVersion, int newVersion)
474{
475 CHK_EXEC(SetColumnNullable(_T("items"), _T("custom_units_name"), _T("varchar(63)")));
476 CHK_EXEC(SetColumnNullable(_T("items"), _T("perftab_settings"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]));
477
478 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("custom_units_name")));
479 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("perftab_settings")));
480
481 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='213' WHERE var_name='SchemaVersion'")));
482
483 return TRUE;
484}
485
486
1024e962
VK
487//
488// Upgrade from V211 to V212
489//
490
491static BOOL H_UpgradeFromV211(int currVersion, int newVersion)
492{
1024e962
VK
493 CHK_EXEC(SetColumnNullable(_T("snmp_trap_cfg"), _T("snmp_oid"), _T("varchar(255)")));
494 CHK_EXEC(SetColumnNullable(_T("snmp_trap_cfg"), _T("user_tag"), _T("varchar(63)")));
495 CHK_EXEC(SetColumnNullable(_T("snmp_trap_cfg"), _T("description"), _T("varchar(255)")));
496
497 CHK_EXEC(ConvertStrings(_T("snmp_trap_cfg"), _T("trap_id"), _T("user_tag")));
498 CHK_EXEC(ConvertStrings(_T("snmp_trap_cfg"), _T("trap_id"), _T("description")));
499
500 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='212' WHERE var_name='SchemaVersion'")));
501
502 return TRUE;
503}
504
505
a8f60046
VK
506//
507// Upgrade from V210 to V211
508//
509
510static BOOL H_UpgradeFromV210(int currVersion, int newVersion)
511{
512 static TCHAR batch[] =
513 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
514 _T(" (53,'SYS_DCI_UNSUPPORTED',2,1,'Status of DCI %1 (%5: %2) changed to UNSUPPORTED',")
515 _T("'Generated when DCI status changed to UNSUPPORTED.#0D#0AParameters:#0D#0A")
516 _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")
517 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
518 _T(" (54,'SYS_DCI_DISABLED',1,1,'Status of DCI %1 (%5: %2) changed to DISABLED',")
519 _T("'Generated when DCI status changed to DISABLED.#0D#0AParameters:#0D#0A")
520 _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")
521 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
522 _T(" (55,'SYS_DCI_ACTIVE',0,1,'Status of DCI %1 (%5: %2) changed to ACTIVE',")
523 _T("'Generated when DCI status changed to ACTIVE.#0D#0AParameters:#0D#0A")
524 _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")
525 _T("<END>");
526
1024e962
VK
527 CHK_EXEC(SQLBatch(batch));
528 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='211' WHERE var_name='SchemaVersion'")));
a8f60046
VK
529
530 return TRUE;
531}
532
533
43c1be79
VK
534//
535// Upgrade from V209 to V210
536//
537
538static BOOL H_UpgradeFromV209(int currVersion, int newVersion)
539{
540 if (!SQLQuery(_T("DELETE FROM metadata WHERE var_name like 'IDataIndexCreationCommand_%'")))
541 if (!g_bIgnoreErrors)
542 return FALSE;
543
544 const TCHAR *query;
545 switch(g_iSyntax)
546 {
547 case DB_SYNTAX_PGSQL:
548 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)')");
549 break;
550 case DB_SYNTAX_MSSQL:
551 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)')");
552 break;
553 default:
554 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)')");
555 break;
556 }
557
558 if (!SQLQuery(query))
559 if (!g_bIgnoreErrors)
560 return FALSE;
561
562 ReindexIData();
563
564 if (!SQLQuery(_T("UPDATE metadata SET var_value='210' WHERE var_name='SchemaVersion'")))
565 if (!g_bIgnoreErrors)
566 return FALSE;
567
568 return TRUE;
569}
570
571
ab185583
VK
572//
573// Upgrade from V208 to V209
574//
575
576static BOOL H_UpgradeFromV208(int currVersion, int newVersion)
577{
578 static TCHAR batch[] =
579 _T("ALTER TABLE users ADD auth_failures integer\n")
580 _T("ALTER TABLE users ADD last_passwd_change integer\n")
581 _T("ALTER TABLE users ADD min_passwd_length integer\n")
582 _T("ALTER TABLE users ADD disabled_until integer\n")
583 _T("ALTER TABLE users ADD last_login integer\n")
584 _T("ALTER TABLE users ADD password_history $SQL:TEXT\n")
585 _T("UPDATE users SET auth_failures=0,last_passwd_change=0,min_passwd_length=-1,disabled_until=0,last_login=0\n")
586 _T("<END>");
587
588 if (!SQLBatch(batch))
589 if (!g_bIgnoreErrors)
590 return FALSE;
591
592 if (!CreateConfigParam(_T("PasswordHistoryLength"), _T("0"), 1, 0))
593 if (!g_bIgnoreErrors)
594 return FALSE;
595
0f1ddb74 596 if (!CreateConfigParam(_T("IntruderLockoutThreshold"), _T("0"), 1, 0))
ab185583
VK
597 if (!g_bIgnoreErrors)
598 return FALSE;
599
600 if (!CreateConfigParam(_T("IntruderLockoutTime"), _T("30"), 1, 0))
601 if (!g_bIgnoreErrors)
602 return FALSE;
603
604 if (!CreateConfigParam(_T("MinPasswordLength"), _T("0"), 1, 0))
605 if (!g_bIgnoreErrors)
606 return FALSE;
607
608 if (!CreateConfigParam(_T("PasswordComplexity"), _T("0"), 1, 0))
609 if (!g_bIgnoreErrors)
610 return FALSE;
611
612 if (!CreateConfigParam(_T("PasswordExpiration"), _T("0"), 1, 0))
613 if (!g_bIgnoreErrors)
614 return FALSE;
615
616 if (!CreateConfigParam(_T("BlockInactiveUserAccounts"), _T("0"), 1, 0))
617 if (!g_bIgnoreErrors)
618 return FALSE;
619
620 if (!SQLQuery(_T("UPDATE metadata SET var_value='209' WHERE var_name='SchemaVersion'")))
621 if (!g_bIgnoreErrors)
622 return FALSE;
623
624 return TRUE;
625}
626
627
80d3565a
VK
628//
629// Upgrade from V207 to V208
630//
631
632static BOOL H_UpgradeFromV207(int currVersion, int newVersion)
633{
634 if (!SQLQuery(_T("ALTER TABLE items ADD system_tag varchar(255)")))
635 if (!g_bIgnoreErrors)
636 return FALSE;
637
638 if (!SQLQuery(_T("UPDATE metadata SET var_value='208' WHERE var_name='SchemaVersion'")))
639 if (!g_bIgnoreErrors)
640 return FALSE;
641
642 return TRUE;
643}
644
645
5ab2f1ab
VK
646//
647// Upgrade from V206 to V207
648//
649
650static BOOL H_UpgradeFromV206(int currVersion, int newVersion)
651{
652 if (!CreateConfigParam(_T("RADIUSSecondaryServer"), _T("none"), 1, 0))
653 if (!g_bIgnoreErrors)
654 return FALSE;
655
656 if (!CreateConfigParam(_T("RADIUSSecondarySecret"), _T("netxms"), 1, 0))
657 if (!g_bIgnoreErrors)
658 return FALSE;
659
660 if (!CreateConfigParam(_T("RADIUSSecondaryPort"), _T("1645"), 1, 0))
661 if (!g_bIgnoreErrors)
662 return FALSE;
663
664 if (!CreateConfigParam(_T("ExternalAuditServer"), _T("none"), 1, 1))
665 if (!g_bIgnoreErrors)
666 return FALSE;
667
668 if (!CreateConfigParam(_T("ExternalAuditPort"), _T("514"), 1, 1))
669 if (!g_bIgnoreErrors)
670 return FALSE;
671
672 if (!CreateConfigParam(_T("ExternalAuditFacility"), _T("13"), 1, 1))
673 if (!g_bIgnoreErrors)
674 return FALSE;
675
676 if (!CreateConfigParam(_T("ExternalAuditSeverity"), _T("5"), 1, 1))
677 if (!g_bIgnoreErrors)
678 return FALSE;
679
680 if (!CreateConfigParam(_T("ExternalAuditTag"), _T("netxmsd-audit"), 1, 1))
681 if (!g_bIgnoreErrors)
682 return FALSE;
683
684 if (!SQLQuery(_T("UPDATE metadata SET var_value='207' WHERE var_name='SchemaVersion'")))
685 if (!g_bIgnoreErrors)
686 return FALSE;
687
688 return TRUE;
689}
690
691
ce7565e7
VK
692//
693// Upgrade from V205 to V206
694//
695
696static BOOL H_UpgradeFromV205(int currVersion, int newVersion)
697{
a4743a0f
VK
698 if (g_iSyntax == DB_SYNTAX_ORACLE)
699 {
700 static TCHAR oraBatch[] =
701 _T("ALTER TABLE audit_log MODIFY message null\n")
702 _T("ALTER TABLE event_log MODIFY event_message null\n")
703 _T("ALTER TABLE event_log MODIFY user_tag null\n")
704 _T("ALTER TABLE syslog MODIFY hostname null\n")
705 _T("ALTER TABLE syslog MODIFY msg_tag null\n")
706 _T("ALTER TABLE syslog MODIFY msg_text null\n")
707 _T("ALTER TABLE snmp_trap_log MODIFY trap_varlist null\n")
708 _T("<END>");
709
710 if (!SQLBatch(oraBatch))
711 if (!g_bIgnoreErrors)
712 return FALSE;
713 }
ce7565e7 714
a4743a0f
VK
715 bool clearLogs = GetYesNo(_T("This database upgrade requires log conversion. This can take significant amount of time ")
716 _T("(up to few hours for large databases). If preserving all log records is not very important, it is ")
717 _T("recommended to clear logs befor conversion. Clear logs?"));
ce7565e7 718
a4743a0f
VK
719 if (clearLogs)
720 {
721 if (!SQLQuery(_T("DELETE FROM audit_log")))
722 if (!g_bIgnoreErrors)
723 return FALSE;
ce7565e7 724
a4743a0f
VK
725 if (!SQLQuery(_T("DELETE FROM event_log")))
726 if (!g_bIgnoreErrors)
727 return FALSE;
728
729 if (!SQLQuery(_T("DELETE FROM syslog")))
730 if (!g_bIgnoreErrors)
731 return FALSE;
732
733 if (!SQLQuery(_T("DELETE FROM snmp_trap_log")))
734 if (!g_bIgnoreErrors)
735 return FALSE;
736 }
737 else
738 {
739 // Convert event log
08b214c6 740 if (!ConvertStrings(_T("event_log"), _T("event_id"), _T("event_message")))
a4743a0f
VK
741 if (!g_bIgnoreErrors)
742 return FALSE;
08b214c6 743 if (!ConvertStrings(_T("event_log"), _T("event_id"), _T("user_tag")))
a4743a0f
VK
744 if (!g_bIgnoreErrors)
745 return FALSE;
746
747 // Convert audit log
08b214c6 748 if (!ConvertStrings(_T("audit_log"), _T("record_id"), _T("message")))
a4743a0f
VK
749 if (!g_bIgnoreErrors)
750 return FALSE;
751
752 // Convert syslog
08b214c6 753 if (!ConvertStrings(_T("syslog"), _T("msg_id"), _T("msg_text")))
a4743a0f
VK
754 if (!g_bIgnoreErrors)
755 return FALSE;
756
757 // Convert SNMP trap log
08b214c6 758 if (!ConvertStrings(_T("snmp_trap_log"), _T("trap_id"), _T("trap_varlist")))
a4743a0f
VK
759 if (!g_bIgnoreErrors)
760 return FALSE;
761 }
ce7565e7
VK
762
763 if (!SQLQuery(_T("UPDATE metadata SET var_value='206' WHERE var_name='SchemaVersion'")))
764 if (!g_bIgnoreErrors)
765 return FALSE;
766
767 return TRUE;
768}
769
770
df8a4ca2
VK
771//
772// Upgrade from V204 to V205
773//
774
775static BOOL H_UpgradeFromV204(int currVersion, int newVersion)
776{
777 if (!CreateTable(_T("CREATE TABLE usm_credentials (")
778 _T("id integer not null,")
779 _T("user_name varchar(255) not null,")
780 _T("auth_method integer not null,")
781 _T("priv_method integer not null,")
782 _T("auth_password varchar(255),")
783 _T("priv_password varchar(255),")
784 _T("PRIMARY KEY(id))")))
785 if (!g_bIgnoreErrors)
786 return FALSE;
787
788 if (!SQLQuery(_T("UPDATE metadata SET var_value='205' WHERE var_name='SchemaVersion'")))
789 if (!g_bIgnoreErrors)
790 return FALSE;
791
792 return TRUE;
793}
794
795
e2babedf
VK
796//
797// Upgrade from V203 to V204
798//
799
800static BOOL H_UpgradeFromV203(int currVersion, int newVersion)
801{
802 static TCHAR batch[] =
803 _T("ALTER TABLE object_properties ADD location_type integer\n")
804 _T("ALTER TABLE object_properties ADD latitude varchar(20)\n")
805 _T("ALTER TABLE object_properties ADD longitude varchar(20)\n")
806 _T("UPDATE object_properties SET location_type=0\n")
807 _T("ALTER TABLE object_properties DROP COLUMN image_id\n")
808 _T("<END>");
809
810 if (!SQLBatch(batch))
811 if (!g_bIgnoreErrors)
812 return FALSE;
813
814 if (!CreateConfigParam(_T("ConnectionPoolBaseSize"), _T("5"), 1, 1))
815 if (!g_bIgnoreErrors)
816 return FALSE;
817
818 if (!CreateConfigParam(_T("ConnectionPoolMaxSize"), _T("20"), 1, 1))
819 if (!g_bIgnoreErrors)
820 return FALSE;
821
822 if (!CreateConfigParam(_T("ConnectionPoolCooldownTime"), _T("300"), 1, 1))
823 if (!g_bIgnoreErrors)
824 return FALSE;
825
a4743a0f
VK
826 if (g_iSyntax == DB_SYNTAX_ORACLE)
827 {
828 if (!SQLQuery(_T("ALTER TABLE object_properties MODIFY comments null\n")))
829 if (!g_bIgnoreErrors)
830 return FALSE;
831 }
832
08b214c6 833 if (!ConvertStrings(_T("object_properties"), _T("object_id"), _T("comments")))
e2babedf
VK
834 if (!g_bIgnoreErrors)
835 return FALSE;
836
837 if (!SQLQuery(_T("UPDATE metadata SET var_value='204' WHERE var_name='SchemaVersion'")))
838 if (!g_bIgnoreErrors)
839 return FALSE;
840
841 return TRUE;
842}
843
844
7cda0d53
VK
845//
846// Upgrade from V202 to V203
847//
848
849static BOOL H_UpgradeFromV202(int currVersion, int newVersion)
850{
851 static TCHAR batch[] =
852 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text)")
853 _T(" VALUES (20,'&Info->Topology table (LLDP)',2,'Topology Table',1,' ','Show topology table (LLDP)','#00')\n")
854 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
855 _T(" VALUES (20,0,'Chassis ID','.1.0.8802.1.1.2.1.4.1.1.5',0,0)\n")
856 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
857 _T(" VALUES (20,1,'Local port','.1.0.8802.1.1.2.1.4.1.1.2',5,0)\n")
858 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
859 _T(" VALUES (20,2,'System name','.1.0.8802.1.1.2.1.4.1.1.9',0,0)\n")
860 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
861 _T(" VALUES (20,3,'System description','.1.0.8802.1.1.2.1.4.1.1.10',0,0)\n")
862 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
863 _T(" VALUES (20,4,'Remote port ID','.1.0.8802.1.1.2.1.4.1.1.7',4,0)\n")
864 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
865 _T(" VALUES (20,5,'Remote port description','.1.0.8802.1.1.2.1.4.1.1.8',0,0)\n")
866 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (20,-2147483648)\n")
867 _T("<END>");
868
869 if (!SQLBatch(batch))
870 if (!g_bIgnoreErrors)
871 return FALSE;
872
873 if (!SQLQuery(_T("UPDATE metadata SET var_value='203' WHERE var_name='SchemaVersion'")))
874 if (!g_bIgnoreErrors)
875 return FALSE;
876
877 return TRUE;
878}
879
880
643c9dcb
VK
881//
882// Upgrade from V201 to V202
883//
884
885static BOOL H_UpgradeFromV201(int currVersion, int newVersion)
886{
a4743a0f
VK
887 if (g_iSyntax == DB_SYNTAX_ORACLE)
888 {
889 static TCHAR oraBatch[] =
890 _T("ALTER TABLE alarms MODIFY message null\n")
891 _T("ALTER TABLE alarms MODIFY alarm_key null\n")
892 _T("ALTER TABLE alarms MODIFY hd_ref null\n")
893 _T("<END>");
894
895 if (!SQLBatch(oraBatch))
896 if (!g_bIgnoreErrors)
897 return FALSE;
898 }
899
08b214c6 900 if (!ConvertStrings(_T("alarms"), _T("alarm_id"), _T("message")))
643c9dcb
VK
901 if (!g_bIgnoreErrors)
902 return FALSE;
08b214c6 903 if (!ConvertStrings(_T("alarms"), _T("alarm_id"), _T("alarm_key")))
643c9dcb
VK
904 if (!g_bIgnoreErrors)
905 return FALSE;
08b214c6 906 if (!ConvertStrings(_T("alarms"), _T("alarm_id"), _T("hd_ref")))
643c9dcb
VK
907 if (!g_bIgnoreErrors)
908 return FALSE;
909
910 if (!SQLQuery(_T("UPDATE metadata SET var_value='202' WHERE var_name='SchemaVersion'")))
911 if (!g_bIgnoreErrors)
912 return FALSE;
913
914 return TRUE;
915}
916
917
31cc1924
VK
918//
919// Upgrade from V200 to V201
920//
921
922static BOOL H_UpgradeFromV200(int currVersion, int newVersion)
923{
924 static TCHAR batch[] =
925 _T("ALTER TABLE nodes ADD usm_auth_password varchar(127)\n")
926 _T("ALTER TABLE nodes ADD usm_priv_password varchar(127)\n")
927 _T("ALTER TABLE nodes ADD usm_methods integer\n")
e8daf6d5 928 _T("UPDATE nodes SET usm_auth_password='#00',usm_priv_password='#00',usm_methods=0\n")
31cc1924
VK
929 _T("<END>");
930
931 if (!SQLBatch(batch))
932 if (!g_bIgnoreErrors)
933 return FALSE;
934
935 if (!SQLQuery(_T("UPDATE metadata SET var_value='201' WHERE var_name='SchemaVersion'")))
936 if (!g_bIgnoreErrors)
937 return FALSE;
938
939 return TRUE;
940}
941
942
45d84f8a
VK
943//
944// Upgrade from V92 to V200
31cc1924 945// or from V93 to V201
e2babedf
VK
946// or from V94 to V202
947// or from V95 to V203
ce7565e7
VK
948// or from V96 to V204
949// or from V97 to V205
950// or from V98 to V206
43c1be79 951// or from V99 to V207
45d84f8a
VK
952//
953
e2babedf 954static BOOL H_UpgradeFromV9x(int currVersion, int newVersion)
45d84f8a
VK
955{
956 if (!CreateTable(_T("CREATE TABLE ap_common (")
957 _T("id integer not null,")
958 _T("policy_type integer not null,")
959 _T("version integer not null,")
960 _T("description $SQL:TEXT not null,")
961 _T("PRIMARY KEY(id))")))
962 if (!g_bIgnoreErrors)
963 return FALSE;
964
965 if (!CreateTable(_T("CREATE TABLE ap_bindings (")
966 _T("policy_id integer not null,")
967 _T("node_id integer not null,")
968 _T("PRIMARY KEY(policy_id,node_id))")))
969 if (!g_bIgnoreErrors)
970 return FALSE;
971
972 if (!CreateTable(_T("CREATE TABLE ap_config_files (")
973 _T("policy_id integer not null,")
974 _T("file_name varchar(63) not null,")
975 _T("file_content $SQL:TEXT not null,")
976 _T("PRIMARY KEY(policy_id))")))
977 if (!g_bIgnoreErrors)
978 return FALSE;
979
31cc1924
VK
980 TCHAR query[256];
981 _sntprintf(query, 256, _T("UPDATE metadata SET var_value='%d' WHERE var_name='SchemaVersion'"), newVersion);
982 if (!SQLQuery(query))
45d84f8a
VK
983 if (!g_bIgnoreErrors)
984 return FALSE;
985
986 return TRUE;
987}
988
989
43c1be79 990//
50da2d20
VK
991// Upgrade from V100 to V214
992// or from V101 to V214
993// or from V102 to V214
994// or from V103 to V214
995// or from V104 to V214
43c1be79
VK
996//
997
a8f60046 998static BOOL H_UpgradeFromV10x(int currVersion, int newVersion)
43c1be79 999{
50da2d20 1000 if (!H_UpgradeFromV9x(currVersion, 207))
43c1be79
VK
1001 return FALSE;
1002
1003 // Now database at V207 level
50da2d20
VK
1004 // V100 already has changes V209 -> V210, but missing V207 -> V209 and V210 -> V214 changes
1005 // V101 already has changes V209 -> V211, but missing V207 -> V209 and V211 -> V214 changes
1006 // V102 already has changes V209 -> V212, but missing V207 -> V209 and V212 -> V214 changes
1007 // V103 already has changes V209 -> V213, but missing V207 -> V209 and V213 -> V214 changes
1008 // V104 already has changes V209 -> V214, but missing V207 -> V209 changes
43c1be79
VK
1009
1010 if (!H_UpgradeFromV207(207, 208))
1011 return FALSE;
1012
a6c1f07f 1013 if (!H_UpgradeFromV208(208, 209))
43c1be79
VK
1014 return FALSE;
1015
a8f60046 1016 if (currVersion == 100)
50da2d20
VK
1017 if (!H_UpgradeFromV210(210, 211))
1018 return FALSE;
a8f60046 1019
1024e962 1020 if (currVersion < 102)
50da2d20
VK
1021 if (!H_UpgradeFromV211(211, 212))
1022 return FALSE;
1024e962 1023
f57209fd 1024 if (currVersion < 103)
50da2d20
VK
1025 if (!H_UpgradeFromV212(212, 213))
1026 return FALSE;
1027
1028 if (currVersion < 104)
1029 if (!H_UpgradeFromV213(213, 214))
1030 return FALSE;
f57209fd 1031
65e2005b
VK
1032 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='214' WHERE var_name='SchemaVersion'")));
1033 return TRUE;
1034}
1035
1036
1037//
1038// Upgrade from V105 to V217
1039//
1040
1041static BOOL H_UpgradeFromV105(int currVersion, int newVersion)
1042{
1043 if (!H_UpgradeFromV10x(currVersion, 214))
1044 return FALSE;
1045
1046 // V105 already have V216 -> V217 changes, but missing V207 -> V209 and V214 -> V216 changes
1047 if (!H_UpgradeFromV214(214, 215))
1048 return FALSE;
1049
1050 if (!H_UpgradeFromV215(215, 216))
1051 return FALSE;
43c1be79 1052
65e2005b 1053 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='217' WHERE var_name='SchemaVersion'")));
43c1be79
VK
1054 return TRUE;
1055}
1056
1057
6e53f004
VK
1058//
1059// Upgrade from V91 to V92
1060//
1061
31cc1924 1062static BOOL H_UpgradeFromV91(int currVersion, int newVersion)
6e53f004
VK
1063{
1064 static TCHAR batch[] =
1065 _T("DROP TABLE images\n")
1066 _T("DROP TABLE default_images\n")
1067 _T("<END>");
1068
1069 if (!SQLBatch(batch))
1070 if (!g_bIgnoreErrors)
1071 return FALSE;
1072
1073 if (!SQLQuery(_T("UPDATE metadata SET var_value='92' WHERE var_name='SchemaVersion'")))
1074 if (!g_bIgnoreErrors)
1075 return FALSE;
1076
1077 return TRUE;
1078}
1079
1080
c45e0213
VK
1081//
1082// Upgrade from V90 to V91
1083//
1084
31cc1924 1085static BOOL H_UpgradeFromV90(int currVersion, int newVersion)
c45e0213
VK
1086{
1087 if (!CreateTable(_T("CREATE TABLE userdb_custom_attributes (")
1088 _T("object_id integer not null,")
1089 _T("attr_name varchar(255) not null,")
1090 _T("attr_value $SQL:TEXT not null,")
1091 _T("PRIMARY KEY(object_id,attr_name))")))
1092 if (!g_bIgnoreErrors)
1093 return FALSE;
1094
1095 if (!SQLQuery(_T("UPDATE metadata SET var_value='91' WHERE var_name='SchemaVersion'")))
1096 if (!g_bIgnoreErrors)
1097 return FALSE;
1098
1099 return TRUE;
1100}
1101
1102
4262c0dc
VK
1103//
1104// Upgrade from V89 to V90
1105//
1106
31cc1924 1107static BOOL H_UpgradeFromV89(int currVersion, int newVersion)
4262c0dc
VK
1108{
1109 static TCHAR m_szBatch[] =
1110 _T("ALTER TABLE items ADD base_units integer\n")
1111 _T("ALTER TABLE items ADD unit_multiplier integer\n")
1112 _T("ALTER TABLE items ADD custom_units_name varchar(63)\n")
1113 _T("ALTER TABLE items ADD perftab_settings $SQL:TEXT\n")
1114 _T("UPDATE items SET base_units=0,unit_multiplier=1,custom_units_name='#00',perftab_settings='#00'\n")
1115 _T("<END>");
1116
1117 if (!SQLBatch(m_szBatch))
1118 if (!g_bIgnoreErrors)
1119 return FALSE;
1120
1121 if (!SQLQuery(_T("UPDATE metadata SET var_value='90' WHERE var_name='SchemaVersion'")))
1122 if (!g_bIgnoreErrors)
1123 return FALSE;
1124
1125 return TRUE;
1126}
1127
1128
1129//
1130// Upgrade from V88 to V89
1131//
1132
31cc1924 1133static BOOL H_UpgradeFromV88(int currVersion, int newVersion)
4262c0dc
VK
1134{
1135 static TCHAR m_szBatch[] =
1136 _T("ALTER TABLE containers ADD enable_auto_bind integer\n")
1137 _T("ALTER TABLE containers ADD auto_bind_filter $SQL:TEXT\n")
1138 _T("UPDATE containers SET enable_auto_bind=0,auto_bind_filter='#00'\n")
1139 _T("ALTER TABLE cluster_resources ADD current_owner integer\n")
1140 _T("UPDATE cluster_resources SET current_owner=0\n")
1141 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (")
1142 _T("52,'SYS_DB_QUERY_FAILED',4,1,'Database query failed (Query: %1; Error: %2)',")
1143 _T("'Generated when SQL query to backend database failed.#0D#0A")
1144 _T("Parameters:#0D#0A 1) Query#0D#0A 2) Error message')\n")
1145 _T("<END>");
1146
1147 if (!SQLBatch(m_szBatch))
1148 if (!g_bIgnoreErrors)
1149 return FALSE;
1150
1151 if (!SQLQuery(_T("UPDATE metadata SET var_value='89' WHERE var_name='SchemaVersion'")))
1152 if (!g_bIgnoreErrors)
1153 return FALSE;
1154
1155 return TRUE;
1156}
1157
1158
1159//
1160// Upgrade from V87 to V88
1161//
1162
31cc1924 1163static BOOL H_UpgradeFromV87(int currVersion, int newVersion)
4262c0dc
VK
1164{
1165 static TCHAR m_szBatch[] =
1166 _T("ALTER TABLE templates ADD enable_auto_apply integer\n")
1167 _T("ALTER TABLE templates ADD apply_filter $SQL:TEXT\n")
1168 _T("UPDATE templates SET enable_auto_apply=0,apply_filter='#00'\n")
1169 _T("<END>");
1170
1171 if (!SQLBatch(m_szBatch))
1172 if (!g_bIgnoreErrors)
1173 return FALSE;
1174
1175 if (!SQLQuery(_T("UPDATE metadata SET var_value='88' WHERE var_name='SchemaVersion'")))
1176 if (!g_bIgnoreErrors)
1177 return FALSE;
1178
1179 return TRUE;
1180}
1181
1182
28f5b9a4
VK
1183//
1184// Upgrade from V86 to V87
1185//
1186
1187static BOOL MoveConfigToMetadata(const TCHAR *cfgVar, const TCHAR *mdVar)
1188{
1189 TCHAR query[1024], buffer[256];
1190 DB_RESULT hResult;
1191 BOOL success;
1192
1193 _sntprintf(query, 1024, _T("SELECT var_value FROM config WHERE var_name='%s'"), cfgVar);
1194 hResult = SQLSelect(query);
1195 if (hResult != NULL)
1196 {
1197 if (DBGetNumRows(hResult) > 0)
1198 {
1199 DBGetField(hResult, 0, 0, buffer, 256);
1200 DecodeSQLString(buffer);
1201 _sntprintf(query, 1024, _T("INSERT INTO metadata (var_name,var_value) VALUES ('%s','%s')"),
1202 mdVar, buffer);
1203 DBFreeResult(hResult);
1204 success = SQLQuery(query);
1205 if (success)
1206 {
1207 _sntprintf(query, 1024, _T("DELETE FROM config WHERE var_name='%s'"), cfgVar);
1208 success = SQLQuery(query);
1209 }
1210 }
1211 else
1212 {
1213 success = TRUE; // Variable missing in 'config' table, nothing to move
1214 }
1215 }
1216 else
1217 {
1218 success = FALSE;
1219 }
1220 return success;
1221}
1222
31cc1924 1223static BOOL H_UpgradeFromV86(int currVersion, int newVersion)
28f5b9a4
VK
1224{
1225 if (!CreateTable(_T("CREATE TABLE metadata (")
1226 _T("var_name varchar(63) not null,")
1227 _T("var_value varchar(255) not null,")
1228 _T("PRIMARY KEY(var_name))")))
1229 if (!g_bIgnoreErrors)
1230 return FALSE;
1231
1232 if (!MoveConfigToMetadata(_T("DBFormatVersion"), _T("SchemaVersion")))
1233 if (!g_bIgnoreErrors)
1234 return FALSE;
1235
1236 if (!MoveConfigToMetadata(_T("DBSyntax"), _T("Syntax")))
1237 if (!g_bIgnoreErrors)
1238 return FALSE;
1239
1240 if (!MoveConfigToMetadata(_T("IDataTableCreationCommand"), _T("IDataTableCreationCommand")))
1241 if (!g_bIgnoreErrors)
1242 return FALSE;
1243
1244 if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_0"), _T("IDataIndexCreationCommand_0")))
1245 if (!g_bIgnoreErrors)
1246 return FALSE;
1247
1248 if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_1"), _T("IDataIndexCreationCommand_1")))
1249 if (!g_bIgnoreErrors)
1250 return FALSE;
1251
1252 if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_2"), _T("IDataIndexCreationCommand_2")))
1253 if (!g_bIgnoreErrors)
1254 return FALSE;
1255
1256 if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_3"), _T("IDataIndexCreationCommand_3")))
1257 if (!g_bIgnoreErrors)
1258 return FALSE;
1259
1260 if (!SQLQuery(_T("UPDATE metadata SET var_value='87' WHERE var_name='SchemaVersion'")))
1261 if (!g_bIgnoreErrors)
1262 return FALSE;
1263
1264 return TRUE;
1265}
1266
1267
4c4c9b03
VK
1268//
1269// Upgrade from V85 to V86
1270//
1271
31cc1924 1272static BOOL H_UpgradeFromV85(int currVersion, int newVersion)
4c4c9b03
VK
1273{
1274 static TCHAR m_szBatch[] =
1275 _T("DROP TABLE alarm_grops\n")
1276 _T("DROP TABLE alarm_group_map\n")
47912c44
VK
1277 _T("DROP TABLE alarm_change_log\n")
1278 _T("DROP TABLE lpp\n")
1279 _T("DROP TABLE lpp_associations\n")
1280 _T("DROP TABLE lpp_rulesets\n")
1281 _T("DROP TABLE lpp_rules\n")
1282 _T("DROP TABLE lpp_groups\n")
4c4c9b03
VK
1283 _T("<END>");
1284
1285 if (!SQLBatch(m_szBatch))
1286 if (!g_bIgnoreErrors)
1287 return FALSE;
1288
1289 if (!SQLQuery(_T("UPDATE config SET var_value='86' WHERE var_name='DBFormatVersion'")))
1290 if (!g_bIgnoreErrors)
1291 return FALSE;
1292
1293 return TRUE;
1294}
1295
1296
5039dede
AK
1297//
1298// Upgrade from V84 to V85
1299//
1300
31cc1924 1301static BOOL H_UpgradeFromV84(int currVersion, int newVersion)
5039dede
AK
1302{
1303 static TCHAR m_szBatch[] =
1304 _T("ALTER TABLE nodes ADD use_ifxtable integer\n")
1305 _T("UPDATE nodes SET use_ifxtable=0\n")
1306 _T("<END>");
1307
1308 if (!SQLBatch(m_szBatch))
1309 if (!g_bIgnoreErrors)
1310 return FALSE;
1311
1312 if (!CreateConfigParam(_T("UseIfXTable"), _T("1"), 1, 0))
1313 if (!g_bIgnoreErrors)
1314 return FALSE;
1315
1316 if (!CreateConfigParam(_T("SMTPRetryCount"), _T("1"), 1, 0))
1317 if (!g_bIgnoreErrors)
1318 return FALSE;
1319
1320 if (!SQLQuery(_T("UPDATE config SET var_value='85' WHERE var_name='DBFormatVersion'")))
1321 if (!g_bIgnoreErrors)
1322 return FALSE;
1323
1324 return TRUE;
1325}
1326
1327
1328//
1329// Upgrade from V83 to V84
1330//
1331
31cc1924 1332static BOOL H_UpgradeFromV83(int currVersion, int newVersion)
5039dede
AK
1333{
1334 if (!CreateConfigParam(_T("EnableAgentRegistration"), _T("1"), 1, 0))
1335 if (!g_bIgnoreErrors)
1336 return FALSE;
1337
1338 if (!CreateConfigParam(_T("AnonymousFileAccess"), _T("0"), 1, 0))
1339 if (!g_bIgnoreErrors)
1340 return FALSE;
1341
1342 if (!CreateConfigParam(_T("EnableISCListener"), _T("0"), 1, 1))
1343 if (!g_bIgnoreErrors)
1344 return FALSE;
1345
1346 if (!CreateConfigParam(_T("ReceiveForwardedEvents"), _T("0"), 1, 0))
1347 if (!g_bIgnoreErrors)
1348 return FALSE;
1349
1350 if (!SQLQuery(_T("UPDATE config SET var_value='84' WHERE var_name='DBFormatVersion'")))
1351 if (!g_bIgnoreErrors)
1352 return FALSE;
1353
1354 return TRUE;
1355}
1356
1357
1358//
1359// Upgrade from V82 to V83
1360//
1361
31cc1924 1362static BOOL H_UpgradeFromV82(int currVersion, int newVersion)
5039dede
AK
1363{
1364 // Fix incorrect alarm timeouts
1365 if (!SQLQuery(_T("UPDATE alarms SET timeout=0,timeout_event=43")))
1366 if (!g_bIgnoreErrors)
1367 return FALSE;
1368
1369 if (!SQLQuery(_T("UPDATE config SET var_value='83' WHERE var_name='DBFormatVersion'")))
1370 if (!g_bIgnoreErrors)
1371 return FALSE;
1372
1373 return TRUE;
1374}
1375
1376
1377//
1378// Upgrade from V81 to V82
1379//
1380
31cc1924 1381static BOOL H_UpgradeFromV81(int currVersion, int newVersion)
5039dede
AK
1382{
1383 if (!CreateTable(_T("CREATE TABLE config_clob (")
1384 _T("var_name varchar(63) not null,")
1385 _T("var_value $SQL:TEXT not null,")
1386 _T("PRIMARY KEY(var_name))")))
1387 if (!g_bIgnoreErrors)
1388 return FALSE;
1389
1390 if (!SQLQuery(_T("UPDATE config SET var_value='82' WHERE var_name='DBFormatVersion'")))
1391 if (!g_bIgnoreErrors)
1392 return FALSE;
1393
1394 return TRUE;
1395}
1396
1397
1398//
1399// Upgrade from V80 to V81
1400//
1401
31cc1924 1402static BOOL H_UpgradeFromV80(int currVersion, int newVersion)
5039dede
AK
1403{
1404 DB_RESULT hResult;
1405 TCHAR query[1024], buffer[1024];
1406 int i;
1407
1408 // Update dci_schedules table
1409 hResult = SQLSelect(_T("SELECT item_id,schedule FROM dci_schedules"));
1410 if (hResult != NULL)
1411 {
1412 if (!SQLQuery(_T("DROP TABLE dci_schedules")))
1413 if (!g_bIgnoreErrors)
1414 return FALSE;
1415
1416 if (!CreateTable(_T("CREATE TABLE dci_schedules (")
1417 _T("schedule_id integer not null,")
1418 _T("item_id integer not null,")
1419 _T("schedule varchar(255) not null,")
1420 _T("PRIMARY KEY(item_id,schedule_id))")))
1421 if (!g_bIgnoreErrors)
1422 return FALSE;
1423
1424 for(i = 0; i < DBGetNumRows(hResult); i++)
1425 {
1426 _sntprintf(query, 1024, _T("INSERT INTO dci_schedules (item_id,schedule_id,schedule) VALUES(%d,%d,'%s')"),
1427 DBGetFieldULong(hResult, i, 0), i + 1, DBGetField(hResult, i, 1, buffer, 1024));
1428 if (!SQLQuery(query))
1429 if (!g_bIgnoreErrors)
1430 return FALSE;
1431 }
1432 DBFreeResult(hResult);
1433 }
1434 else
1435 {
1436 if (!g_bIgnoreErrors)
1437 return FALSE;
1438 }
1439
1440 // Update address_lists table
1441 hResult = SQLSelect(_T("SELECT list_type,community_id,addr_type,addr1,addr2 FROM address_lists"));
1442 if (hResult != NULL)
1443 {
1444 if (!SQLQuery(_T("DROP TABLE address_lists")))
1445 if (!g_bIgnoreErrors)
1446 return FALSE;
1447
1448 if (!CreateTable(_T("CREATE TABLE address_lists (")
1449 _T("list_type integer not null,")
1450 _T("community_id integer not null,")
1451 _T("addr_type integer not null,")
1452 _T("addr1 varchar(15) not null,")
1453 _T("addr2 varchar(15) not null,")
1454 _T("PRIMARY KEY(list_type,community_id,addr_type,addr1,addr2))")))
1455 if (!g_bIgnoreErrors)
1456 return FALSE;
1457
1458 for(i = 0; i < DBGetNumRows(hResult); i++)
1459 {
1460 _sntprintf(query, 1024, _T("INSERT INTO address_lists (list_type,community_id,addr_type,addr1,addr2) VALUES(%d,%d,%d,'%s','%s')"),
1461 DBGetFieldULong(hResult, i, 0), DBGetFieldULong(hResult, i, 1),
1462 DBGetFieldULong(hResult, i, 2), DBGetField(hResult, i, 3, buffer, 64),
1463 DBGetField(hResult, i, 4, &buffer[128], 64));
1464 if (!SQLQuery(query))
1465 if (!g_bIgnoreErrors)
1466 return FALSE;
1467 }
1468
1469 DBFreeResult(hResult);
1470 }
1471 else
1472 {
1473 if (!g_bIgnoreErrors)
1474 return FALSE;
1475 }
1476
1477 // Create new tables
1478 if (!CreateTable(_T("CREATE TABLE object_custom_attributes (")
1479 _T("object_id integer not null,")
1480 _T("attr_name varchar(127) not null,")
1481 _T("attr_value $SQL:TEXT not null,")
1482 _T("PRIMARY KEY(object_id,attr_name))")))
1483 if (!g_bIgnoreErrors)
1484 return FALSE;
1485
1486 if (!CreateTable(_T("CREATE TABLE web_maps (")
1487 _T("id integer not null,")
1488 _T("title varchar(63) not null,")
1489 _T("properties $SQL:TEXT not null,")
1490 _T("data $SQL:TEXT not null,")
1491 _T("PRIMARY KEY(id))")))
1492 if (!g_bIgnoreErrors)
1493 return FALSE;
1494
1495 if (!SQLQuery(_T("UPDATE config SET var_value='81' WHERE var_name='DBFormatVersion'")))
1496 if (!g_bIgnoreErrors)
1497 return FALSE;
1498
1499 return TRUE;
1500}
1501
1502
1503//
1504// Upgrade from V79 to V80
1505//
1506
31cc1924 1507static BOOL H_UpgradeFromV79(int currVersion, int newVersion)
5039dede
AK
1508{
1509 static TCHAR m_szBatch[] =
1510 _T("ALTER TABLE nodes ADD uname varchar(255)\n")
1511 _T("UPDATE nodes SET uname='#00'\n")
1512 _T("<END>");
1513
1514 if (!SQLBatch(m_szBatch))
1515 if (!g_bIgnoreErrors)
1516 return FALSE;
1517
1518 if (!SQLQuery(_T("UPDATE config SET var_value='80' WHERE var_name='DBFormatVersion'")))
1519 if (!g_bIgnoreErrors)
1520 return FALSE;
1521
1522 return TRUE;
1523}
1524
1525
1526//
1527// Upgrade from V78 to V79
1528//
1529
31cc1924 1530static BOOL H_UpgradeFromV78(int currVersion, int newVersion)
5039dede
AK
1531{
1532 static TCHAR m_szBatch[] =
1533 _T("DELETE FROM config WHERE var_name='RetainCustomInterfaceNames'\n")
1534 _T("DROP TABLE modules\n")
1535 _T("<END>");
1536 static TCHAR m_szMySQLBatch[] =
1537 _T("ALTER TABLE users MODIFY COLUMN cert_mapping_data text not null\n")
1538 _T("ALTER TABLE user_profiles MODIFY COLUMN var_value text not null\n")
1539 _T("ALTER TABLE object_properties MODIFY COLUMN comments text not null\n")
1540 _T("ALTER TABLE network_services MODIFY COLUMN check_request text not null\n")
1541 _T("ALTER TABLE network_services MODIFY COLUMN check_responce text not null\n")
1542 _T("ALTER TABLE conditions MODIFY COLUMN script text not null\n")
1543 _T("ALTER TABLE container_categories MODIFY COLUMN description text not null\n")
1544 _T("ALTER TABLE items MODIFY COLUMN transformation text not null\n")
1545 _T("ALTER TABLE event_cfg MODIFY COLUMN description text not null\n")
1546 _T("ALTER TABLE actions MODIFY COLUMN action_data text not null\n")
1547 _T("ALTER TABLE event_policy MODIFY COLUMN comments text not null\n")
1548 _T("ALTER TABLE event_policy MODIFY COLUMN script text not null\n")
1549 _T("ALTER TABLE alarm_change_log MODIFY COLUMN info_text text not null\n")
1550 _T("ALTER TABLE alarm_notes MODIFY COLUMN note_text text not null\n")
1551 _T("ALTER TABLE object_tools MODIFY COLUMN tool_data text not null\n")
1552 _T("ALTER TABLE syslog MODIFY COLUMN msg_text text not null\n")
1553 _T("ALTER TABLE script_library MODIFY COLUMN script_code text not null\n")
1554 _T("ALTER TABLE snmp_trap_log MODIFY COLUMN trap_varlist text not null\n")
1555 _T("ALTER TABLE maps MODIFY COLUMN description text not null\n")
1556 _T("ALTER TABLE agent_configs MODIFY COLUMN config_file text not null\n")
1557 _T("ALTER TABLE agent_configs MODIFY COLUMN config_filter text not null\n")
1558 _T("ALTER TABLE graphs MODIFY COLUMN config text not null\n")
1559 _T("ALTER TABLE certificates MODIFY COLUMN cert_data text not null\n")
1560 _T("ALTER TABLE certificates MODIFY COLUMN subject text not null\n")
1561 _T("ALTER TABLE certificates MODIFY COLUMN comments text not null\n")
1562 _T("ALTER TABLE audit_log MODIFY COLUMN message text not null\n")
1563 _T("ALTER TABLE situations MODIFY COLUMN comments text not null\n")
1564 _T("<END>");
1565
1566 if (!SQLBatch(m_szBatch))
1567 if (!g_bIgnoreErrors)
1568 return FALSE;
1569
1570 if (g_iSyntax == DB_SYNTAX_MYSQL)
1571 {
1572 if (!SQLBatch(m_szMySQLBatch))
1573 if (!g_bIgnoreErrors)
1574 return FALSE;
1575 }
1576
1577 if (!SQLQuery(_T("UPDATE config SET var_value='79' WHERE var_name='DBFormatVersion'")))
1578 if (!g_bIgnoreErrors)
1579 return FALSE;
1580
1581 return TRUE;
1582}
1583
1584
1585//
1586// Upgrade from V77 to V78
1587//
1588
31cc1924 1589static BOOL H_UpgradeFromV77(int currVersion, int newVersion)
5039dede
AK
1590{
1591 if (!CreateTable(_T("CREATE TABLE trusted_nodes (")
1592 _T("source_object_id integer not null,")
1593 _T("target_node_id integer not null,")
1594 _T("PRIMARY KEY(source_object_id,target_node_id))")))
1595 if (!g_bIgnoreErrors)
1596 return FALSE;
1597
1598 if (!CreateConfigParam(_T("CheckTrustedNodes"), _T("1"), 1, 1))
1599 if (!g_bIgnoreErrors)
1600 return FALSE;
1601
1602 if (!SQLQuery(_T("UPDATE config SET var_value='78' WHERE var_name='DBFormatVersion'")))
1603 if (!g_bIgnoreErrors)
1604 return FALSE;
1605
1606 return TRUE;
1607}
1608
1609
1610//
1611// Upgrade from V76 to V77
1612//
1613
31cc1924 1614static BOOL H_UpgradeFromV76(int currVersion, int newVersion)
5039dede
AK
1615{
1616 DB_RESULT hResult;
1617 int i, count, seq;
1618 DWORD id, lastId;
1619 TCHAR query[1024];
1620
1621 hResult = SQLSelect(_T("SELECT condition_id,dci_id,node_id,dci_func,num_polls FROM cond_dci_map ORDER BY condition_id"));
1622 if (hResult == NULL)
1623 if (!g_bIgnoreErrors)
1624 return FALSE;
1625
1626 if (!SQLQuery(_T("DROP TABLE cond_dci_map")))
1627 if (!g_bIgnoreErrors)
1628 goto error;
1629
1630 if (!CreateTable(_T("CREATE TABLE cond_dci_map (")
1631 _T("condition_id integer not null,")
1632 _T("sequence_number integer not null,")
1633 _T("dci_id integer not null,")
1634 _T("node_id integer not null,")
1635 _T("dci_func integer not null,")
1636 _T("num_polls integer not null,")
1637 _T("PRIMARY KEY(condition_id,sequence_number))")))
1638 if (!g_bIgnoreErrors)
1639 goto error;
1640
1641 count = DBGetNumRows(hResult);
1642 for(i = 0, seq = 0, lastId = 0; i < count; i++, seq++)
1643 {
1644 id = DBGetFieldULong(hResult, i, 0);
1645 if (id != lastId)
1646 {
1647 seq = 0;
1648 lastId = id;
1649 }
1650 _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)"),
1651 id, seq, DBGetFieldULong(hResult, i, 1), DBGetFieldULong(hResult, i, 2),
1652 DBGetFieldULong(hResult, i, 3), DBGetFieldULong(hResult, i, 4));
1653 if (!SQLQuery(query))
1654 if (!g_bIgnoreErrors)
1655 goto error;
1656 }
1657
1658 DBFreeResult(hResult);
1659
1660 if (!SQLQuery(_T("UPDATE config SET var_value='77' WHERE var_name='DBFormatVersion'")))
1661 if (!g_bIgnoreErrors)
1662 return FALSE;
1663
1664 return TRUE;
1665
1666error:
1667 DBFreeResult(hResult);
1668 return FALSE;
1669}
1670
1671
1672//
1673// Upgrade from V75 to V76
1674//
1675
31cc1924 1676static BOOL H_UpgradeFromV75(int currVersion, int newVersion)
5039dede
AK
1677{
1678 static TCHAR m_szBatch[] =
1679 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (")
1680 _T("50,'SYS_NETWORK_CONN_LOST',4,1,'NetXMS server network connectivity lost',")
1681 _T("'Generated when system detects loss of network connectivity based on beacon ")
1682 _T("probing.#0D#0AParameters:#0D#0A 1) Number of beacons')\n")
1683 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (")
1684 _T("51,'SYS_NETWORK_CONN_RESTORED',0,1,'NetXMS server network connectivity restored',")
1685 _T("'Generated when system detects restoration of network connectivity based on ")
1686 _T("beacon probing.#0D#0AParameters:#0D#0A 1) Number of beacons')\n")
1687 _T("<END>");
1688
1689 if (!SQLBatch(m_szBatch))
1690 if (!g_bIgnoreErrors)
1691 return FALSE;
1692
1693 if (!CreateConfigParam(_T("AgentCommandTimeout"), _T("2000"), 1, 1))
1694 if (!g_bIgnoreErrors)
1695 return FALSE;
1696
1697 if (!CreateConfigParam(_T("BeaconHosts"), _T(""), 1, 1))
1698 if (!g_bIgnoreErrors)
1699 return FALSE;
1700
1701 if (!CreateConfigParam(_T("BeaconTimeout"), _T("1000"), 1, 1))
1702 if (!g_bIgnoreErrors)
1703 return FALSE;
1704
1705 if (!CreateConfigParam(_T("BeaconPollingInterval"), _T("1000"), 1, 1))
1706 if (!g_bIgnoreErrors)
1707 return FALSE;
1708
1709 if (!SQLQuery(_T("UPDATE config SET var_value='76' WHERE var_name='DBFormatVersion'")))
1710 if (!g_bIgnoreErrors)
1711 return FALSE;
1712
1713 return TRUE;
1714}
1715
1716
1717//
1718// Upgrade from V74 to V75
1719//
1720
31cc1924 1721static BOOL H_UpgradeFromV74(int currVersion, int newVersion)
5039dede
AK
1722{
1723 static TCHAR m_szBatch[] =
1724 _T("ALTER TABLE address_lists ADD community_id integer\n")
1725 _T("UPDATE address_lists SET community_id=0\n")
1726 _T("<END>");
1727
1728 if (!SQLBatch(m_szBatch))
1729 if (!g_bIgnoreErrors)
1730 return FALSE;
1731
1732 if (!CreateTable(_T("CREATE TABLE snmp_communities (")
1733 _T("id integer not null,")
1734 _T("community varchar(255) not null,")
1735 _T("PRIMARY KEY(id))")))
1736 if (!g_bIgnoreErrors)
1737 return FALSE;
1738
1739 if (!CreateConfigParam(_T("UseInterfaceAliases"), _T("0"), 1, 0))
1740 if (!g_bIgnoreErrors)
1741 return FALSE;
1742
1743 if (!CreateConfigParam(_T("SyncNodeNamesWithDNS"), _T("0"), 1, 0))
1744 if (!g_bIgnoreErrors)
1745 return FALSE;
1746
1747 if (!SQLQuery(_T("UPDATE config SET var_value='75' WHERE var_name='DBFormatVersion'")))
1748 if (!g_bIgnoreErrors)
1749 return FALSE;
1750
1751 return TRUE;
1752}
1753
1754
1755//
1756// Upgrade from V73 to V74
1757//
1758
31cc1924 1759static BOOL H_UpgradeFromV73(int currVersion, int newVersion)
5039dede
AK
1760{
1761 static TCHAR m_szBatch[] =
1762 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
1763 _T("VALUES (48,'SYS_EVENT_STORM_DETECTED',3,1,'Event storm detected (Events per second: %1)',")
1764 _T("'Generated when system detects an event storm.#0D#0AParameters:#0D#0A")
1765 _T(" 1) Events per second#0D#0A 2) Duration#0D#0A 3) Threshold')\n")
1766 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
1767 _T("VALUES (49,'SYS_EVENT_STORM_ENDED',0,1,'Event storm ended',")
1768 _T("'Generated when system clears event storm condition.#0D#0AParameters:#0D#0A")
1769 _T(" 1) Events per second#0D#0A 2) Duration#0D#0A 3) Threshold')\n")
1770 _T("DELETE FROM config WHERE var_name='NumberOfEventProcessors'\n")
1771 _T("DELETE FROM config WHERE var_name='EventStormThreshold'\n")
1772 _T("<END>");
1773
1774 if (!SQLBatch(m_szBatch))
1775 if (!g_bIgnoreErrors)
1776 return FALSE;
1777
1778 if (!CreateConfigParam(_T("EnableEventStormDetection"), _T("0"), 1, 1))
1779 if (!g_bIgnoreErrors)
1780 return FALSE;
1781
1782 if (!CreateConfigParam(_T("EventStormEventsPerSecond"), _T("100"), 1, 1))
1783 if (!g_bIgnoreErrors)
1784 return FALSE;
1785
1786 if (!CreateConfigParam(_T("EventStormDuration"), _T("15"), 1, 1))
1787 if (!g_bIgnoreErrors)
1788 return FALSE;
1789
1790 if (!SQLQuery(_T("UPDATE config SET var_value='74' WHERE var_name='DBFormatVersion'")))
1791 if (!g_bIgnoreErrors)
1792 return FALSE;
1793
1794 return TRUE;
1795}
1796
1797
1798//
1799// Upgrade from V72 to V73
1800//
1801
31cc1924 1802static BOOL H_UpgradeFromV72(int currVersion, int newVersion)
5039dede
AK
1803{
1804 static TCHAR m_szBatch[] =
1805 _T("ALTER TABLE event_policy ADD situation_id integer\n")
1806 _T("ALTER TABLE event_policy ADD situation_instance varchar(255)\n")
1807 _T("UPDATE event_policy SET situation_id=0,situation_instance='#00'\n")
1808 _T("<END>");
1809
1810 if (!SQLBatch(m_szBatch))
1811 if (!g_bIgnoreErrors)
1812 return FALSE;
1813
1814 if (!CreateTable(_T("CREATE TABLE policy_situation_attr_list (")
1815 _T("rule_id integer not null,")
1816 _T("situation_id integer not null,")
1817 _T("attr_name varchar(255) not null,")
1818 _T("attr_value varchar(255) not null,")
1819 _T("PRIMARY KEY(rule_id,situation_id,attr_name))")))
1820 if (!g_bIgnoreErrors)
1821 return FALSE;
1822
1823 if (!CreateTable(_T("CREATE TABLE situations (")
1824 _T("id integer not null,")
1825 _T("name varchar(127) not null,")
1826 _T("comments $SQL:TEXT not null,")
1827 _T("PRIMARY KEY(id))")))
1828 if (!g_bIgnoreErrors)
1829 return FALSE;
1830
1831 if (!CreateConfigParam(_T("RetainCustomInterfaceNames"), _T("0"), 1, 0))
1832 if (!g_bIgnoreErrors)
1833 return FALSE;
1834
1835 if (!CreateConfigParam(_T("AllowDirectSMS"), _T("0"), 1, 0))
1836 if (!g_bIgnoreErrors)
1837 return FALSE;
1838
1839 if (!CreateConfigParam(_T("EventStormThreshold"), _T("0"), 1, 1))
1840 if (!g_bIgnoreErrors)
1841 return FALSE;
1842
1843 if (!SQLQuery(_T("UPDATE config SET var_value='73' WHERE var_name='DBFormatVersion'")))
1844 if (!g_bIgnoreErrors)
1845 return FALSE;
1846
1847 return TRUE;
1848}
1849
1850
1851//
1852// Upgrade from V71 to V72
1853//
1854
31cc1924 1855static BOOL H_UpgradeFromV71(int currVersion, int newVersion)
5039dede
AK
1856{
1857 static TCHAR m_szBatch[] =
1858 _T("ALTER TABLE items ADD proxy_node integer\n")
1859 _T("UPDATE items SET proxy_node=0\n")
1860 _T("<END>");
1861
1862 if (!SQLBatch(m_szBatch))
1863 if (!g_bIgnoreErrors)
1864 return FALSE;
1865
1866 if (!SQLQuery(_T("UPDATE config SET var_value='72' WHERE var_name='DBFormatVersion'")))
1867 if (!g_bIgnoreErrors)
1868 return FALSE;
1869
1870 return TRUE;
1871}
1872
1873
1874//
1875// Upgrade from V70 to V71
1876//
1877
31cc1924 1878static BOOL H_UpgradeFromV70(int currVersion, int newVersion)
5039dede
AK
1879{
1880 static TCHAR m_szBatch[] =
1881 _T("ALTER TABLE nodes ADD required_polls integer\n")
1882 _T("UPDATE nodes SET required_polls=0\n")
1883 _T("ALTER TABLE interfaces ADD required_polls integer\n")
1884 _T("UPDATE interfaces SET required_polls=0\n")
1885 _T("ALTER TABLE network_services ADD required_polls integer\n")
1886 _T("UPDATE network_services SET required_polls=0\n")
1887 _T("<END>");
1888
1889 if (!SQLBatch(m_szBatch))
1890 if (!g_bIgnoreErrors)
1891 return FALSE;
1892
1893 if (!CreateConfigParam(_T("PollCountForStatusChange"), _T("1"), 1, 1))
1894 if (!g_bIgnoreErrors)
1895 return FALSE;
1896
1897 if (!SQLQuery(_T("UPDATE config SET var_value='71' WHERE var_name='DBFormatVersion'")))
1898 if (!g_bIgnoreErrors)
1899 return FALSE;
1900
1901 return TRUE;
1902}
1903
1904
1905//
1906// Upgrade from V69 to V70
1907//
1908
31cc1924 1909static BOOL H_UpgradeFromV69(int currVersion, int newVersion)
5039dede
AK
1910{
1911 static TCHAR m_szBatch[] =
1912 _T("ALTER TABLE snmp_trap_cfg ADD user_tag varchar(63)\n")
1913 _T("UPDATE snmp_trap_cfg SET user_tag='#00'\n")
1914 _T("ALTER TABLE event_log ADD user_tag varchar(63)\n")
1915 _T("UPDATE event_log SET user_tag='#00'\n")
1916 _T("<END>");
1917 int n;
1918 TCHAR buffer[64];
1919
1920 if (!SQLBatch(m_szBatch))
1921 if (!g_bIgnoreErrors)
1922 return FALSE;
1923
1924 // Convert event log retention time from seconds to days
1925 n = ConfigReadInt(_T("EventLogRetentionTime"), 5184000) / 86400;
08b214c6 1926 _sntprintf(buffer, 64, _T("%d"), max(n, 1));
5039dede
AK
1927 if (!CreateConfigParam(_T("EventLogRetentionTime"), buffer, 1, 0, TRUE))
1928 if (!g_bIgnoreErrors)
1929 return FALSE;
1930
1931 // Convert event log retention time from seconds to days
1932 n = ConfigReadInt(_T("SyslogRetentionTime"), 5184000) / 86400;
08b214c6 1933 _sntprintf(buffer, 64, _T("%d"), max(n, 1));
5039dede
AK
1934 if (!CreateConfigParam(_T("SyslogRetentionTime"), buffer, 1, 0, TRUE))
1935 if (!g_bIgnoreErrors)
1936 return FALSE;
1937
1938 if (!SQLQuery(_T("UPDATE config SET var_value='70' WHERE var_name='DBFormatVersion'")))
1939 if (!g_bIgnoreErrors)
1940 return FALSE;
1941
1942 return TRUE;
1943}
1944
1945
1946//
1947// Upgrade from V68 to V69
1948//
1949
31cc1924 1950static BOOL H_UpgradeFromV68(int currVersion, int newVersion)
5039dede
AK
1951{
1952 if (!CreateTable(_T("CREATE TABLE audit_log (")
1953 _T("record_id integer not null,")
1954 _T("timestamp integer not null,")
1955 _T("subsystem varchar(32) not null,")
1956 _T("success integer not null,")
1957 _T("user_id integer not null,")
1958 _T("workstation varchar(63) not null,")
1959 _T("object_id integer not null,")
1960 _T("message $SQL:TEXT not null,")
1961 _T("PRIMARY KEY(record_id))")))
1962 if (!g_bIgnoreErrors)
1963 return FALSE;
1964
1965 if (!CreateConfigParam(_T("EnableAuditLog"), _T("1"), 1, 1))
1966 if (!g_bIgnoreErrors)
1967 return FALSE;
1968
1969 if (!CreateConfigParam(_T("AuditLogRetentionTime"), _T("90"), 1, 0))
1970 if (!g_bIgnoreErrors)
1971 return FALSE;
1972
1973 if (!SQLQuery(_T("UPDATE config SET var_value='69' WHERE var_name='DBFormatVersion'")))
1974 if (!g_bIgnoreErrors)
1975 return FALSE;
1976
1977 return TRUE;
1978}
1979
1980
1981//
1982// Upgrade from V67 to V68
1983//
1984
31cc1924 1985static BOOL H_UpgradeFromV67(int currVersion, int newVersion)
5039dede
AK
1986{
1987 static TCHAR m_szBatch[] =
1988 _T("ALTER TABLE thresholds ADD repeat_interval integer\n")
1989 _T("UPDATE thresholds SET repeat_interval=-1\n")
1990 _T("<END>");
1991
1992 if (!SQLBatch(m_szBatch))
1993 if (!g_bIgnoreErrors)
1994 return FALSE;
1995
1996 if (!CreateConfigParam(_T("ThresholdRepeatInterval"), _T("0"), 1, 1))
1997 if (!g_bIgnoreErrors)
1998 return FALSE;
1999
2000 if (!SQLQuery(_T("UPDATE config SET var_value='68' WHERE var_name='DBFormatVersion'")))
2001 if (!g_bIgnoreErrors)
2002 return FALSE;
2003
2004 return TRUE;
2005}
2006
2007
2008//
2009// Upgrade from V66 to V67
2010//
2011
31cc1924 2012static BOOL H_UpgradeFromV66(int currVersion, int newVersion)
5039dede
AK
2013{
2014 static TCHAR m_szBatch[] =
2015 _T("ALTER TABLE subnets ADD synthetic_mask integer\n")
2016 _T("UPDATE subnets SET synthetic_mask=0\n")
2017 _T("ALTER TABLE interfaces ADD synthetic_mask integer\n")
2018 _T("UPDATE interfaces SET synthetic_mask=0\n")
2019 _T("<END>");
2020
2021 if (!SQLBatch(m_szBatch))
2022 if (!g_bIgnoreErrors)
2023 return FALSE;
2024
2025 if (!SQLQuery(_T("UPDATE config SET var_value='67' WHERE var_name='DBFormatVersion'")))
2026 if (!g_bIgnoreErrors)
2027 return FALSE;
2028
2029 return TRUE;
2030}
2031
2032
2033//
2034// Upgrade from V65 to V66
2035//
2036
31cc1924 2037static BOOL H_UpgradeFromV65(int currVersion, int newVersion)
5039dede
AK
2038{
2039 static TCHAR m_szBatch[] =
2040 _T("ALTER TABLE submap_links ADD port1 varchar(255)\n")
2041 _T("ALTER TABLE submap_links ADD port2 varchar(255)\n")
2042 _T("UPDATE submap_links SET port1='#00',port2='#00'\n")
2043 _T("<END>");
2044
2045 if (!SQLBatch(m_szBatch))
2046 if (!g_bIgnoreErrors)
2047 return FALSE;
2048
2049 if (!SQLQuery(_T("UPDATE config SET var_value='66' WHERE var_name='DBFormatVersion'")))
2050 if (!g_bIgnoreErrors)
2051 return FALSE;
2052
2053 return TRUE;
2054}
2055
2056
2057//
2058// Upgrade from V64 to V65
2059//
2060
31cc1924 2061static BOOL H_UpgradeFromV64(int currVersion, int newVersion)
5039dede
AK
2062{
2063 static TCHAR m_szPGSQLBatch[] =
2064 _T("ALTER TABLE nodes ADD new_community varchar(127)\n")
2065 _T("UPDATE nodes SET new_community=community\n")
2066 _T("ALTER TABLE nodes DROP COLUMN community\n")
2067 _T("ALTER TABLE nodes RENAME COLUMN new_community TO community\n")
2068 _T("ALTER TABLE nodes ALTER COLUMN community SET NOT NULL\n")
2069 _T("<END>");
2070
2071 switch(g_iSyntax)
2072 {
2073 case DB_SYNTAX_MYSQL:
2074 case DB_SYNTAX_ORACLE:
2075 if (!SQLQuery(_T("ALTER TABLE nodes MODIFY community varchar(127)")))
2076 if (!g_bIgnoreErrors)
2077 return FALSE;
2078 break;
2079 case DB_SYNTAX_PGSQL:
2080 if (g_bTrace)
2081 ShowQuery(_T("ALTER TABLE nodes ALTER COLUMN community TYPE varchar(127)"));
2082
2083 if (!DBQuery(g_hCoreDB, _T("ALTER TABLE nodes ALTER COLUMN community TYPE varchar(127)")))
2084 {
2085 // Assume that we are using PostgreSQL oldest than 8.x
2086 if (!SQLBatch(m_szPGSQLBatch))
2087 if (!g_bIgnoreErrors)
2088 return FALSE;
2089 }
2090 break;
2091 case DB_SYNTAX_MSSQL:
2092 if (!SQLQuery(_T("ALTER TABLE nodes ALTER COLUMN community varchar(127)")))
2093 if (!g_bIgnoreErrors)
2094 return FALSE;
2095 break;
2096 case DB_SYNTAX_SQLITE:
2097 _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"));
2098 break;
2099 default:
2100 _tprintf(_T("INTERNAL ERROR: Unknown database syntax %d\n"), g_iSyntax);
2101 break;
2102 }
2103
2104 if (!SQLQuery(_T("UPDATE config SET var_value='65' WHERE var_name='DBFormatVersion'")))
2105 if (!g_bIgnoreErrors)
2106 return FALSE;
2107
2108 return TRUE;
2109}
2110
2111
2112//
2113// Upgrade from V63 to V64
2114//
2115
31cc1924 2116static BOOL H_UpgradeFromV63(int currVersion, int newVersion)
5039dede
AK
2117{
2118 static TCHAR m_szBatch[] =
2119 _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")
2120 _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")
2121 _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")
2122 _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")
2123 _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")
2124 _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")
2125 _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")
2126 _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")
2127 _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")
2128 _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")
2129 _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")
2130 _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")
2131 _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")
2132 _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")
2133 _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")
2134 _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")
2135 _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")
2136 _T("<END>");
2137
2138 if (!SQLBatch(m_szBatch))
2139 if (!g_bIgnoreErrors)
2140 return FALSE;
2141
2142 if (!SQLQuery(_T("UPDATE config SET var_value='64' WHERE var_name='DBFormatVersion'")))
2143 if (!g_bIgnoreErrors)
2144 return FALSE;
2145
2146 return TRUE;
2147}
2148
2149
2150//
2151// Upgrade from V62 to V63
2152//
2153
31cc1924 2154static BOOL H_UpgradeFromV62(int currVersion, int newVersion)
5039dede
AK
2155{
2156 static TCHAR m_szBatch[] =
2157 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
2158 _T("VALUES (45,'SYS_IF_UNKNOWN',1,1,")
2159 _T("'Interface \"%2\" changed state to UNKNOWN (IP Addr: %3/%4, IfIndex: %5)',")
2160 _T("'Generated when interface goes to unknown state.#0D#0A")
2161 _T("Please note that source of event is node, not an interface itself.#0D#0A")
2162 _T("Parameters:#0D#0A 1) Interface object ID#0D#0A 2) Interface name#0D#0A")
2163 _T(" 3) Interface IP address#0D#0A 4) Interface netmask#0D#0A")
2164 _T(" 5) Interface index')\n")
2165 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
2166 _T("VALUES (46,'SYS_IF_DISABLED',0,1,")
2167 _T("'Interface \"%2\" disabled (IP Addr: %3/%4, IfIndex: %5)',")
2168 _T("'Generated when interface administratively disabled.#0D#0A")
2169 _T("Please note that source of event is node, not an interface itself.#0D#0A")
2170 _T("Parameters:#0D#0A 1) Interface object ID#0D#0A 2) Interface name#0D#0A")
2171 _T(" 3) Interface IP address#0D#0A 4) Interface netmask#0D#0A")
2172 _T(" 5) Interface index')\n")
2173 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
2174 _T("VALUES (47,'SYS_IF_TESTING',0,1,")
2175 _T("'Interface \"%2\" is testing (IP Addr: %3/%4, IfIndex: %5)',")
2176 _T("'Generated when interface goes to testing state.#0D#0A")
2177 _T("Please note that source of event is node, not an interface itself.#0D#0A")
2178 _T("Parameters:#0D#0A 1) Interface object ID#0D#0A 2) Interface name#0D#0A")
2179 _T(" 3) Interface IP address#0D#0A 4) Interface netmask#0D#0A")
2180 _T(" 5) Interface index')\n")
2181 _T("<END>");
2182
2183 if (!SQLBatch(m_szBatch))
2184 if (!g_bIgnoreErrors)
2185 return FALSE;
2186
2187 if (!SQLQuery(_T("UPDATE config SET var_value='63' WHERE var_name='DBFormatVersion'")))
2188 if (!g_bIgnoreErrors)
2189 return FALSE;
2190
2191 return TRUE;
2192}
2193
2194
2195//
2196// Upgrade from V61 to V62
2197//
2198
31cc1924 2199static BOOL H_UpgradeFromV61(int currVersion, int newVersion)
5039dede
AK
2200{
2201 static TCHAR m_szBatch[] =
2202 _T("UPDATE event_policy SET alarm_key=alarm_ack_key WHERE alarm_severity=6\n")
2203 _T("ALTER TABLE event_policy DROP COLUMN alarm_ack_key\n")
2204 _T("ALTER TABLE event_policy ADD alarm_timeout integer\n")
2205 _T("ALTER TABLE event_policy ADD alarm_timeout_event integer\n")
2206 _T("UPDATE event_policy SET alarm_timeout=0,alarm_timeout_event=43\n")
2207 _T("ALTER TABLE alarms ADD timeout integer\n")
2208 _T("ALTER TABLE alarms ADD timeout_event integer\n")
2209 _T("UPDATE alarms SET timeout=0,timeout_event=43\n")
2210 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
2211 _T("VALUES (43,'SYS_ALARM_TIMEOUT',1,1,'Alarm timeout expired (ID: %1; Text: %2)',")
2212 _T("'Generated when alarm timeout expires.#0D#0AParameters:#0D#0A")
2213 _T(" 1) Alarm ID#0D#0A 2) Alarm message#0D#0A 3) Alarm key#0D#0A 4) Event code')\n")
2214 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
2215 _T("VALUES (44,'SYS_LOG_RECORD_MATCHED',1,1,")
2216 _T("'Log record matched (Policy: %1; File: %2; Record: %4)',")
2217 _T("'Default event for log record match.#0D#0AParameters:#0D#0A")
2218 _T(" 1) Policy name#0D#0A 2) Log file name#0D#0A 3) Matching regular expression#0D#0A")
2219 _T(" 4) Matched record#0D#0A 5 .. 9) Reserved#0D#0A")
2220 _T(" 10 .. 99) Substrings extracted by regular expression')\n")
2221 _T("<END>");
2222
2223 if (!SQLBatch(m_szBatch))
2224 if (!g_bIgnoreErrors)
2225 return FALSE;
2226
2227 if (!CreateTable(_T("CREATE TABLE lpp_groups (")
2228 _T("lpp_group_id integer not null,")
2229 _T("lpp_group_name varchar(63) not null,")
2230 _T("parent_group integer not null,")
2231 _T("PRIMARY KEY(lpp_group_id))")))
2232 if (!g_bIgnoreErrors)
2233 return FALSE;
2234
2235 if (!CreateTable(_T("CREATE TABLE lpp (")
2236 _T("lpp_id integer not null,")
2237 _T("lpp_group_id integer not null,")
2238 _T("lpp_name varchar(63) not null,")
2239 _T("lpp_version integer not null,")
2240 _T("lpp_flags integer not null,")
2241 _T("PRIMARY KEY(lpp_id))")))
2242 if (!g_bIgnoreErrors)
2243 return FALSE;
2244
2245 if (!CreateTable(_T("CREATE TABLE lpp_associations (")
2246 _T("lpp_id integer not null,")
2247 _T("node_id integer not null,")
2248 _T("log_file varchar(255) not null)")))
2249 if (!g_bIgnoreErrors)
2250 return FALSE;
2251
2252 if (!CreateTable(_T("CREATE TABLE lpp_rulesets (")
2253 _T("ruleset_id integer not null,")
2254 _T("ruleset_name varchar(63),")
2255 _T("PRIMARY KEY(ruleset_id))")))
2256 if (!g_bIgnoreErrors)
2257 return FALSE;
2258
2259 if (!CreateTable(_T("CREATE TABLE lpp_rules (")
2260 _T("lpp_id integer not null,")
2261 _T("rule_number integer not null,")
2262 _T("ruleset_id integer not null,")
2263 _T("msg_id_start integer not null,")
2264 _T("msg_id_end integer not null,")
2265 _T("severity integer not null,")
2266 _T("source_name varchar(255) not null,")
2267 _T("msg_text_regexp varchar(255) not null,")
2268 _T("event_code integer not null,")
2269 _T("PRIMARY KEY(lpp_id,rule_number))")))
2270 if (!g_bIgnoreErrors)
2271 return FALSE;
2272
2273 if (!SQLQuery(_T("UPDATE config SET var_value='62' WHERE var_name='DBFormatVersion'")))
2274 if (!g_bIgnoreErrors)
2275 return FALSE;
2276
2277 return TRUE;
2278}
2279
2280
2281//
2282// Upgrade from V60 to V61
2283//
2284
31cc1924 2285static BOOL H_UpgradeFromV60(int currVersion, int newVersion)
5039dede
AK
2286{
2287 static TCHAR m_szBatch[] =
2288 _T("DELETE FROM object_tools WHERE tool_id=14\n")
2289 _T("DELETE FROM object_tools_table_columns WHERE tool_id=14\n")
2290 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text) ")
2291 _T("VALUES (14,'&Info->Topology table (Nortel)',2,'Topology table',1,' ','Show topology table (Nortel protocol)','#00')\n")
2292 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2293 _T("VALUES (14,0,'Peer IP','.1.3.6.1.4.1.45.1.6.13.2.1.1.3',3,0)\n")
2294 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2295 _T("VALUES (14,1,'Peer MAC','.1.3.6.1.4.1.45.1.6.13.2.1.1.5',4,0)\n")
2296 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2297 _T("VALUES (14,2,'Slot','.1.3.6.1.4.1.45.1.6.13.2.1.1.1',1,0)\n")
2298 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2299 _T("VALUES (14,3,'Port','.1.3.6.1.4.1.45.1.6.13.2.1.1.2',1,0)\n")
2300 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text) ")
2301 _T("VALUES (17,'&Info->AR&P cache (SNMP)',2,'ARP Cache',1,' ','Show ARP cache','#00')\n")
2302 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2303 _T("VALUES (17,0,'IP Address','.1.3.6.1.2.1.4.22.1.3',3,0)\n")
2304 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2305 _T("VALUES (17,1,'MAC Address','.1.3.6.1.2.1.4.22.1.2',4,0)\n")
2306 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2307 _T("VALUES (17,2,'Interface','.1.3.6.1.2.1.4.22.1.1',5,0)\n")
2308 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text) ")
2309 _T("VALUES (18,'&Info->AR&P cache (Agent)',3,")
2310 _T("'ARP Cache#7FNet.ArpCache#7F(.*) (.*) (.*)',2,' ','Show ARP cache','#00')\n")
2311 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2312 _T("VALUES (18,0,'IP Address','.1.3.6.1.2.1.4.22.1.3',0,2)\n")
2313 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2314 _T("VALUES (18,1,'MAC Address','.1.3.6.1.2.1.4.22.1.2',0,1)\n")
2315 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2316 _T("VALUES (18,2,'Interface','.1.3.6.1.2.1.4.22.1.1',5,3)\n")
2317 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text) ")
2318 _T("VALUES (19,'&Info->&Routing table (SNMP)',2,'Routing Table',1,' ','Show IP routing table','#00')\n")
2319 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2320 _T("VALUES (19,0,'Destination','.1.3.6.1.2.1.4.21.1.1',3,0)\n")
2321 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2322 _T("VALUES (19,1,'Mask','.1.3.6.1.2.1.4.21.1.11',3,0)\n")
2323 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2324 _T("VALUES (19,2,'Next hop','.1.3.6.1.2.1.4.21.1.7',3,0)\n")
2325 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2326 _T("VALUES (19,3,'Metric','.1.3.6.1.2.1.4.21.1.3',1,0)\n")
2327 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2328 _T("VALUES (19,4,'Interface','.1.3.6.1.2.1.4.21.1.2',5,0)\n")
2329 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (17,-2147483648)\n")
2330 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (18,-2147483648)\n")
2331 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (19,-2147483648)\n")
2332 _T("<END>");
2333
2334 if (!SQLBatch(m_szBatch))
2335 if (!g_bIgnoreErrors)
2336 return FALSE;
2337
2338 if (!CreateConfigParam(_T("TopologyExpirationTime"), _T("900"), 1, 0))
2339 if (!g_bIgnoreErrors)
2340 return FALSE;
2341
2342 if (!CreateConfigParam(_T("TopologyDiscoveryRadius"), _T("3"), 1, 0))
2343 if (!g_bIgnoreErrors)
2344 return FALSE;
2345
2346 if (!SQLQuery(_T("UPDATE config SET var_value='61' WHERE var_name='DBFormatVersion'")))
2347 if (!g_bIgnoreErrors)
2348 return FALSE;
2349
2350 return TRUE;
2351}
2352
2353
2354//
2355// Upgrade from V59 to V60
2356//
2357
31cc1924 2358static BOOL H_UpgradeFromV59(int currVersion, int newVersion)
5039dede
AK
2359{
2360 if (!CreateTable(_T("CREATE TABLE certificates (")
2361 _T("cert_id integer not null,")
2362 _T("cert_type integer not null,")
2363 _T("cert_data $SQL:TEXT not null,")
2364 _T("subject $SQL:TEXT not null,")
2365 _T("comments $SQL:TEXT not null,")
2366 _T("PRIMARY KEY(cert_id))")))
2367 if (!g_bIgnoreErrors)
2368 return FALSE;
2369
2370 if (!CreateConfigParam(_T("SNMPRequestTimeout"), _T("2000"), 1, 1))
2371 if (!g_bIgnoreErrors)
2372 return FALSE;
2373
2374 if (!SQLQuery(_T("UPDATE config SET var_value='60' WHERE var_name='DBFormatVersion'")))
2375 if (!g_bIgnoreErrors)
2376 return FALSE;
2377
2378 return TRUE;
2379}
2380
2381
2382//
2383// Upgrade from V58 to V59
2384//
2385
31cc1924 2386static BOOL H_UpgradeFromV58(int currVersion, int newVersion)
5039dede
AK
2387{
2388 static TCHAR m_szBatch[] =
2389 _T("ALTER TABLE users ADD cert_mapping_method integer\n")
2390 _T("ALTER TABLE users ADD cert_mapping_data $SQL:TEXT\n")
2391 _T("UPDATE users SET cert_mapping_method=0\n")
2392 _T("UPDATE users SET cert_mapping_data='#00'\n")
2393 _T("<END>");
2394
2395 if (!SQLBatch(m_szBatch))
2396 if (!g_bIgnoreErrors)
2397 return FALSE;
2398
2399 if (!CreateConfigParam(_T("InternalCA"), _T("0"), 1, 1))
2400 if (!g_bIgnoreErrors)
2401 return FALSE;
2402
2403 if (!SQLQuery(_T("UPDATE config SET var_value='59' WHERE var_name='DBFormatVersion'")))
2404 if (!g_bIgnoreErrors)
2405 return FALSE;
2406
2407 return TRUE;
2408}
2409
2410
2411//
2412// Upgrade from V57 to V58
2413//
2414
31cc1924 2415static BOOL H_UpgradeFromV57(int currVersion, int newVersion)
5039dede
AK
2416{
2417 static TCHAR m_szBatch[] =
2418 _T("ALTER TABLE object_properties ADD is_system integer\n")
2419 _T("UPDATE object_properties SET is_system=0\n")
2420 _T("<END>");
2421
2422 if (!SQLBatch(m_szBatch))
2423 if (!g_bIgnoreErrors)
2424 return FALSE;
2425
2426 if (!CreateTable(_T("CREATE TABLE graphs (")
2427 _T("graph_id integer not null,")
2428 _T("owner_id integer not null,")
2429 _T("name varchar(255) not null,")
2430 _T("config $SQL:TEXT not null,")
2431 _T("PRIMARY KEY(graph_id))")))
2432 if (!g_bIgnoreErrors)
2433 return FALSE;
2434
2435 if (!CreateTable(_T("CREATE TABLE graph_acl (")
2436 _T("graph_id integer not null,")
2437 _T("user_id integer not null,")
2438 _T("user_rights integer not null,")
2439 _T("PRIMARY KEY(graph_id,user_id))")))
2440 if (!g_bIgnoreErrors)
2441 return FALSE;
2442
2443 if (!SQLQuery(_T("UPDATE config SET var_value='58' WHERE var_name='DBFormatVersion'")))
2444 if (!g_bIgnoreErrors)
2445 return FALSE;
2446
2447 return TRUE;
2448}
2449
2450
2451//
2452// Upgrade from V56 to V57
2453//
2454
31cc1924 2455static BOOL H_UpgradeFromV56(int currVersion, int newVersion)
5039dede
AK
2456{
2457 static TCHAR m_szBatch[] =
2458 _T("ALTER TABLE items ADD resource_id integer\n")
2459 _T("UPDATE items SET resource_id=0\n")
2460 _T("ALTER TABLE nodes ADD snmp_proxy integer\n")
2461 _T("UPDATE nodes SET snmp_proxy=0\n")
2462 _T("<END>");
2463
2464 if (!SQLBatch(m_szBatch))
2465 if (!g_bIgnoreErrors)
2466 return FALSE;
2467
2468 if (!SQLQuery(_T("UPDATE config SET var_value='57' WHERE var_name='DBFormatVersion'")))
2469 if (!g_bIgnoreErrors)
2470 return FALSE;
2471
2472 return TRUE;
2473}
2474
2475
2476//
2477// Upgrade from V55 to V56
2478//
2479
31cc1924 2480static BOOL H_UpgradeFromV55(int currVersion, int newVersion)
5039dede
AK
2481{
2482 static TCHAR m_szBatch[] =
2483 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
2484 _T(" (38,'SYS_CLUSTER_RESOURCE_MOVED',1,1,")
2485 _T("'Cluster resource \"%2\" moved from node %4 to node %6',")
2486 _T("'Generated when cluster resource moved between nodes.#0D#0A")
2487 _T("Parameters:#0D#0A 1) Resource ID#0D#0A")
2488 _T(" 2) Resource name#0D#0A 3) Previous owner node ID#0D#0A")
2489 _T(" 4) Previous owner node name#0D#0A 5) New owner node ID#0D#0A")
2490 _T(" 6) New owner node name')\n")
2491 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
2492 _T(" (39,'SYS_CLUSTER_RESOURCE_DOWN',3,1,")
2493 _T("'Cluster resource \"%2\" is down (last owner was %4)',")
2494 _T("'Generated when cluster resource goes down.#0D#0A")
2495 _T("Parameters:#0D#0A 1) Resource ID#0D#0A 2) Resource name#0D#0A")
2496 _T(" 3) Last owner node ID#0D#0A 4) Last owner node name')\n")
2497 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
2498 _T(" (40,'SYS_CLUSTER_RESOURCE_UP',0,1,")
2499 _T("'Cluster resource \"%2\" is up (new owner is %4)',")
2500 _T("'Generated when cluster resource goes up.#0D#0A")
2501 _T("Parameters:#0D#0A 1) Resource ID#0D#0A 2) Resource name#0D#0A")
2502 _T(" 3) New owner node ID#0D#0A 4) New owner node name')\n")
2503 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
2504 _T(" (41,'SYS_CLUSTER_DOWN',4,1,'Cluster is down',")
2505 _T("'Generated when cluster goes down.#0D#0AParameters:#0D#0A No message-specific parameters')\n")
2506 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
2507 _T(" (42,'SYS_CLUSTER_UP',0,1,'Cluster is up',")
2508 _T("'Generated when cluster goes up.#0D#0AParameters:#0D#0A No message-specific parameters')\n")
2509 _T("<END>");
2510
2511 if (!SQLBatch(m_szBatch))
2512 if (!g_bIgnoreErrors)
2513 return FALSE;
2514
2515 if (!CreateTable(_T("CREATE TABLE cluster_resources (")
2516 _T("cluster_id integer not null,")
2517 _T("resource_id integer not null,")
2518 _T("resource_name varchar(255) not null,")
2519 _T("ip_addr varchar(15) not null,")
2520 _T("PRIMARY KEY(cluster_id,resource_id))")))
2521 if (!g_bIgnoreErrors)
2522 return FALSE;
2523
2524 if (!SQLQuery(_T("UPDATE config SET var_value='56' WHERE var_name='DBFormatVersion'")))
2525 if (!g_bIgnoreErrors)
2526 return FALSE;
2527
2528 return TRUE;
2529}
2530
2531
2532//
2533// Upgrade from V54 to V55
2534//
2535
31cc1924 2536static BOOL H_UpgradeFromV54(int currVersion, int newVersion)
5039dede
AK
2537{
2538 static TCHAR m_szBatch[] =
2539 _T("ALTER TABLE containers DROP COLUMN description\n")
2540 _T("ALTER TABLE nodes DROP COLUMN description\n")
2541 _T("ALTER TABLE templates DROP COLUMN description\n")
2542 _T("ALTER TABLE zones DROP COLUMN description\n")
2543 _T("INSERT INTO images (image_id,name,file_name_png,file_hash_png,")
2544 _T("file_name_ico,file_hash_ico) VALUES (16,'Obj.Cluster',")
2545 _T("'cluster.png','<invalid_hash>','cluster.ico','<invalid_hash>')\n")
2546 _T("INSERT INTO default_images (object_class,image_id) VALUES (14,16)\n")
2547 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
2548 _T("VALUES (12,'.1.3.6.1.4.1.45.3.46.*',3,0)\n")
2549 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
2550 _T("VALUES (13,'.1.3.6.1.4.1.45.3.52.*',3,0)\n")
2551 _T("<END>");
2552
2553 if (!SQLBatch(m_szBatch))
2554 if (!g_bIgnoreErrors)
2555 return FALSE;
2556
2557 if (!CreateTable(_T("CREATE TABLE clusters (")
2558 _T("id integer not null,")
2559 _T("cluster_type integer not null,")
2560 _T("PRIMARY KEY(id))")))
2561 if (!g_bIgnoreErrors)
2562 return FALSE;
2563
2564 if (!CreateTable(_T("CREATE TABLE cluster_members (")
2565 _T("cluster_id integer not null,")
2566 _T("node_id integer not null,")
2567 _T("PRIMARY KEY(cluster_id,node_id))")))
2568 if (!g_bIgnoreErrors)
2569 return FALSE;
2570
2571 if (!CreateTable(_T("CREATE TABLE cluster_sync_subnets (")
2572 _T("cluster_id integer not null,")
2573 _T("subnet_addr varchar(15) not null,")
2574 _T("subnet_mask varchar(15) not null,")
2575 _T("PRIMARY KEY(cluster_id,subnet_addr))")))
2576 if (!g_bIgnoreErrors)
2577 return FALSE;
2578
2579 if (!CreateConfigParam(_T("WindowsConsoleUpgradeURL"), _T("http://www.netxms.org/download/netxms-%version%.exe"), 1, 0))
2580 if (!g_bIgnoreErrors)
2581 return FALSE;
2582
2583 if (!SQLQuery(_T("UPDATE config SET var_value='55' WHERE var_name='DBFormatVersion'")))
2584 if (!g_bIgnoreErrors)
2585 return FALSE;
2586
2587 return TRUE;
2588}
2589
2590
2591//
2592// Upgrade from V53 to V54
2593//
2594
31cc1924 2595static BOOL H_UpgradeFromV53(int currVersion, int newVersion)
5039dede
AK
2596{
2597 static TCHAR m_szBatch[] =
2598 _T("CREATE INDEX idx_address_lists_list_type ON address_lists(list_type)\n")
2599 _T("DELETE FROM config WHERE var_name='EnableAccessControl'\n")
2600 _T("DELETE FROM config WHERE var_name='EnableEventAccessControl'\n")
2601 _T("<END>");
2602
2603 if (!CreateTable(_T("CREATE TABLE address_lists (")
2604 _T("list_type integer not null,")
2605 _T("addr_type integer not null,")
2606 _T("addr1 varchar(15) not null,")
2607 _T("addr2 varchar(15) not null)")))
2608 if (!g_bIgnoreErrors)
2609 return FALSE;
2610
2611 if (!SQLBatch(m_szBatch))
2612 if (!g_bIgnoreErrors)
2613 return FALSE;
2614
2615 if (!CreateConfigParam(_T("ActiveNetworkDiscovery"), _T("0"), 1, 1))
2616 if (!g_bIgnoreErrors)
2617 return FALSE;
2618
2619 if (!CreateConfigParam(_T("ActiveDiscoveryInterval"), _T("7200"), 1, 1))
2620 if (!g_bIgnoreErrors)
2621 return FALSE;
2622
2623 if (!CreateConfigParam(_T("DiscoveryFilterFlags"), _T("0"), 1, 0))
2624 if (!g_bIgnoreErrors)
2625 return FALSE;
2626
2627 if (!SQLQuery(_T("UPDATE config SET var_value='54' WHERE var_name='DBFormatVersion'")))
2628 if (!g_bIgnoreErrors)
2629 return FALSE;
2630
2631 return TRUE;
2632}
2633
2634
2635//
2636// Upgrade from V52 to V53
2637//
2638
31cc1924 2639static BOOL H_UpgradeFromV52(int currVersion, int newVersion)
5039dede
AK
2640{
2641 DB_RESULT hResult;
2642 int i, nCount;
2643 DWORD dwId;
2644 TCHAR szQuery[1024];
2645 static const TCHAR *pszNewIdx[] =
2646 {
2647 _T("CREATE INDEX idx_idata_%d_id_timestamp ON idata_%d(item_id,idata_timestamp)"), // MySQL
2648 _T("CREATE INDEX idx_idata_%d_timestamp_id ON idata_%d(idata_timestamp,item_id)"), // POstgreSQL
2649 _T("CREATE CLUSTERED INDEX idx_idata_%d_id_timestamp ON idata_%d(item_id,idata_timestamp)"), // MS SQL
2650 _T("CREATE INDEX idx_idata_%d_timestamp_id ON idata_%d(idata_timestamp,item_id)"), // Oracle
2651 _T("CREATE INDEX idx_idata_%d_timestamp_id ON idata_%d(idata_timestamp,item_id)") // SQLite
2652 };
2653
2654 hResult = SQLSelect(_T("SELECT id FROM nodes"));
2655 if (hResult == NULL)
2656 return FALSE;
2657
2658 _tprintf(_T("Reindexing database:\n"));
2659 nCount = DBGetNumRows(hResult);
2660 for(i = 0; i < nCount; i++)
2661 {
2662 dwId = DBGetFieldULong(hResult, i, 0);
08b214c6 2663 _tprintf(_T(" * idata_%d\n"), dwId);
5039dede
AK
2664
2665 // Drop old indexes
08b214c6 2666 _sntprintf(szQuery, 1024, _T("DROP INDEX idx_idata_%d_timestamp"), dwId);
5039dede
AK
2667 DBQuery(g_hCoreDB, szQuery);
2668
2669 // Create new index
08b214c6 2670 _sntprintf(szQuery, 1024, pszNewIdx[g_iSyntax], dwId, dwId);
5039dede
AK
2671 SQLQuery(szQuery);
2672 }
2673
2674 DBFreeResult(hResult);
2675
2676 // Update index creation command
2677 DBQuery(g_hCoreDB, _T("DELETE FROM config WHERE var_name='IDataIndexCreationCommand_1'"));
2678 if (!CreateConfigParam(_T("IDataIndexCreationCommand_1"), pszNewIdx[g_iSyntax], 0, 1))
2679 if (!g_bIgnoreErrors)
2680 return FALSE;
2681
2682 if (!SQLQuery(_T("UPDATE config SET var_value='53' WHERE var_name='DBFormatVersion'")))
2683 if (!g_bIgnoreErrors)
2684 return FALSE;
2685
2686 return TRUE;
2687}
2688
2689
2690//
2691// Upgrade from V51 to V52
2692//
2693
31cc1924 2694static BOOL H_UpgradeFromV51(int currVersion, int newVersion)
5039dede
AK
2695{
2696 static TCHAR m_szBatch[] =
08b214c6
VK
2697 _T("UPDATE object_tools SET tool_data='Configured ICMP targets#7FICMP.TargetList#7F^(.*) (.*) (.*) (.*) (.*)' WHERE tool_id=12\n")
2698 _T("UPDATE object_tools_table_columns SET col_number=4 WHERE col_number=3 AND tool_id=12\n")
2699 _T("UPDATE object_tools_table_columns SET col_number=3 WHERE col_number=2 AND tool_id=12\n")
2700 _T("UPDATE object_tools_table_columns SET col_substr=5 WHERE col_number=1 AND tool_id=12\n")
2701 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2702 _T("VALUES (12,2,'Packet size','',0,4)\n")
2703 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text) ")
2704 _T("VALUES (16,'&Info->Active &user sessions',3,")
2705 _T("'Active User Sessions#7FSystem.ActiveUserSessions#7F^\"(.*)\" \"(.*)\" \"(.*)\"',")
2706 _T("2,'','Show list of active user sessions','#00')\n")
2707 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2708 _T("VALUES (16,0,'User','',0,1)\n")
2709 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2710 _T("VALUES (16,1,'Terminal','',0,2)\n")
2711 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2712 _T("VALUES (16,2,'From','',0,3)\n")
2713 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (16,-2147483648)\n")
2714 _T("<END>");
5039dede
AK
2715
2716 if (!SQLBatch(m_szBatch))
2717 if (!g_bIgnoreErrors)
2718 return FALSE;
2719
2720 if (!CreateConfigParam(_T("MailEncoding"), _T("iso-8859-1"), 1, 0))
2721 if (!g_bIgnoreErrors)
2722 return FALSE;
2723
2724 if (!SQLQuery(_T("UPDATE config SET var_value='52' WHERE var_name='DBFormatVersion'")))
2725 if (!g_bIgnoreErrors)
2726 return FALSE;
2727
2728 return TRUE;
2729}
2730
2731
2732//
2733// Upgrade from V50 to V51
2734//
2735
31cc1924 2736static BOOL H_UpgradeFromV50(int currVersion, int newVersion)
5039dede
AK
2737{
2738 static TCHAR m_szBatch[] =
08b214c6
VK
2739 _T("ALTER TABLE event_groups ADD range_start integer\n")
2740 _T("ALTER TABLE event_groups ADD range_END integer\n")
2741 _T("UPDATE event_groups SET range_start=0,range_end=0\n")
2742 _T("<END>");
5039dede
AK
2743
2744 if (!SQLBatch(m_szBatch))
2745 if (!g_bIgnoreErrors)
2746 return FALSE;
2747
2748 if (!SQLQuery(_T("UPDATE config SET var_value='51' WHERE var_name='DBFormatVersion'")))
2749 if (!g_bIgnoreErrors)
2750 return FALSE;
2751
2752 return TRUE;
2753}
2754
2755
2756//
2757// Upgrade from V49 to V50
2758//
2759
31cc1924 2760static BOOL H_UpgradeFromV49(int currVersion, int newVersion)
5039dede
AK
2761{
2762 static TCHAR m_szBatch[] =
08b214c6
VK
2763 _T("ALTER TABLE object_tools ADD confirmation_text varchar(255)\n")
2764 _T("UPDATE object_tools SET confirmation_text='#00'\n")
2765 _T("UPDATE object_tools SET flags=10 WHERE tool_id=1 OR tool_id=2 OR tool_id=4\n")
2766 _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")
2767 _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")
2768 _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")
2769 _T("<END>");
5039dede
AK
2770
2771 if (!SQLBatch(m_szBatch))
2772 if (!g_bIgnoreErrors)
2773 return FALSE;
2774
2775 if (!SQLQuery(_T("UPDATE config SET var_value='50' WHERE var_name='DBFormatVersion'")))
2776 if (!g_bIgnoreErrors)
2777 return FALSE;
2778
2779 return TRUE;
2780}
2781
2782
2783//
2784// Upgrade from V48 to V49
2785//
2786
31cc1924 2787static BOOL H_UpgradeFromV48(int currVersion, int newVersion)
5039dede
AK
2788{
2789 static TCHAR m_szBatch[] =
08b214c6
VK
2790 _T("ALTER TABLE items ADD all_thresholds integer\n")
2791 _T("UPDATE items SET all_thresholds=0\n")
2792 _T("ALTER TABLE thresholds ADD rearm_event_code integer\n")
2793 _T("UPDATE thresholds SET rearm_event_code=18\n")
2794 _T("<END>");
5039dede
AK
2795
2796 if (!SQLBatch(m_szBatch))
2797 if (!g_bIgnoreErrors)
2798 return FALSE;
2799
2800 if (!SQLQuery(_T("UPDATE config SET var_value='49' WHERE var_name='DBFormatVersion'")))
2801 if (!g_bIgnoreErrors)
2802 return FALSE;
2803
2804 return TRUE;
2805}
2806
2807
2808//
2809// Upgrade from V47 to V48
2810//
2811
31cc1924 2812static BOOL H_UpgradeFromV47(int currVersion, int newVersion)
5039dede
AK
2813{
2814 static TCHAR m_szBatch[] =
08b214c6
VK
2815 _T("ALTER TABLE event_policy ADD script $SQL:TEXT\n")
2816 _T("UPDATE event_policy SET script='#00'\n")
2817 _T("<END>");
5039dede
AK
2818
2819 if (!SQLBatch(m_szBatch))
2820 if (!g_bIgnoreErrors)
2821 return FALSE;
2822
2823 if (!CreateTable(_T("CREATE TABLE policy_time_range_list (")
2824 _T("rule_id integer not null,")
2825 _T("time_range_id integer not null,")
2826 _T("PRIMARY KEY(rule_id,time_range_id))")))
2827 if (!g_bIgnoreErrors)
2828 return FALSE;
2829
2830 if (!CreateTable(_T("CREATE TABLE time_ranges (")
2831 _T("time_range_id integer not null,")
2832 _T("wday_mask integer not null,")
2833 _T("mday_mask integer not null,")
2834 _T("month_mask integer not null,")
2835 _T("time_range varchar(255) not null,")
2836 _T("PRIMARY KEY(time_range_id))")))
2837 if (!g_bIgnoreErrors)
2838 return FALSE;
2839
2840 if (!SQLQuery(_T("UPDATE config SET var_value='48' WHERE var_name='DBFormatVersion'")))
2841 if (!g_bIgnoreErrors)
2842 return FALSE;
2843
2844 return TRUE;
2845}
2846
2847
2848//
2849// Upgrade from V46 to V47
2850//
2851
31cc1924 2852static BOOL H_UpgradeFromV46(int currVersion, int newVersion)
5039dede
AK
2853{
2854 static TCHAR m_szBatch[] =
08b214c6
VK
2855 _T("ALTER TABLE object_properties ADD comments $SQL:TEXT\n")
2856 _T("UPDATE object_properties SET comments='#00'\n")
2857 _T("ALTER TABLE nodes DROP COLUMN discovery_flags\n")
2858 _T("DROP TABLE alarm_notes\n")
2859 _T("ALTER TABLE alarms ADD alarm_state integer\n")
2860 _T("ALTER TABLE alarms ADD hd_state integer\n")
2861 _T("ALTER TABLE alarms ADD hd_ref varchar(63)\n")
2862 _T("ALTER TABLE alarms ADD creation_time integer\n")
2863 _T("ALTER TABLE alarms ADD last_change_time integer\n")
2864 _T("ALTER TABLE alarms ADD original_severity integer\n")
2865 _T("ALTER TABLE alarms ADD current_severity integer\n")
2866 _T("ALTER TABLE alarms ADD repeat_count integer\n")
2867 _T("ALTER TABLE alarms ADD term_by integer\n")
2868 _T("UPDATE alarms SET hd_state=0,hd_ref='#00',creation_time=alarm_timestamp,")
2869 _T("last_change_time=alarm_timestamp,original_severity=severity,")
2870 _T("current_severity=severity,repeat_count=1,term_by=ack_by\n")
2871 _T("UPDATE alarms SET alarm_state=0 WHERE is_ack=0\n")
2872 _T("UPDATE alarms SET alarm_state=2 WHERE is_ack<>0\n")
2873 _T("ALTER TABLE alarms DROP COLUMN severity\n")
2874 _T("ALTER TABLE alarms DROP COLUMN alarm_timestamp\n")
2875 _T("ALTER TABLE alarms DROP COLUMN is_ack\n")
2876 _T("ALTER TABLE thresholds ADD current_state integer\n")
2877 _T("UPDATE thresholds SET current_state=0\n")
2878 _T("<END>");
5039dede 2879 static TCHAR m_szBatch2[] =
08b214c6
VK
2880 _T("CREATE INDEX idx_alarm_notes_alarm_id ON alarm_notes(alarm_id)\n")
2881 _T("CREATE INDEX idx_alarm_change_log_alarm_id ON alarm_change_log(alarm_id)\n")
2882 _T("<END>");
5039dede
AK
2883
2884 if (!SQLBatch(m_szBatch))
2885 if (!g_bIgnoreErrors)
2886 return FALSE;
2887
2888 if (!CreateTable(_T("CREATE TABLE alarm_notes ("
08b214c6
VK
2889 _T("note_id integer not null,")
2890 _T("alarm_id integer not null,")
2891 _T("change_time integer not null,")
2892 _T("user_id integer not null,")
2893 _T("note_text $SQL:TEXT not null,")
2894 _T("PRIMARY KEY(note_id))"))))
5039dede
AK
2895 if (!g_bIgnoreErrors)
2896 return FALSE;
2897
2898 if (!CreateTable(_T("CREATE TABLE alarm_change_log ("
08b214c6
VK
2899 _T("change_id $SQL:INT64 not null,")
2900 _T("change_time integer not null,")
2901 _T("alarm_id integer not null,")
2902 _T("opcode integer not null,")
2903 _T("user_id integer not null,")
2904 _T("info_text $SQL:TEXT not null,")
2905 _T("PRIMARY KEY(change_id))"))))
5039dede
AK
2906 if (!g_bIgnoreErrors)
2907 return FALSE;
2908
2909 if (!CreateTable(_T("CREATE TABLE alarm_grops ("
08b214c6
VK
2910 _T("alarm_group_id integer not null,")
2911 _T("group_name varchar(255) not null,")
2912 _T("PRIMARY KEY(alarm_group_id))"))))
5039dede
AK
2913 if (!g_bIgnoreErrors)
2914 return FALSE;
2915
2916 if (!CreateTable(_T("CREATE TABLE alarm_group_map ("
08b214c6
VK
2917 _T("alarm_group_id integer not null,")
2918 _T("alarm_id integer not null,")
2919 _T("PRIMARY KEY(alarm_group_id,alarm_id))"))))
5039dede
AK
2920 if (!g_bIgnoreErrors)
2921 return FALSE;
2922
2923 if (!SQLBatch(m_szBatch2))
2924 if (!g_bIgnoreErrors)
2925 return FALSE;
2926
2927 if (!SQLQuery(_T("UPDATE config SET var_value='47' WHERE var_name='DBFormatVersion'")))
2928 if (!g_bIgnoreErrors)
2929 return FALSE;
2930
2931 return TRUE;
2932}
2933
2934
2935//
2936// Upgrade from V45 to V46
2937//
2938
31cc1924 2939static BOOL H_UpgradeFromV45(int currVersion, int newVersion)
5039dede
AK
2940{
2941 static TCHAR m_szBatch[] =
08b214c6
VK
2942 _T("UPDATE object_tools_table_columns SET col_format=5 WHERE tool_id=5 AND col_number=1\n")
2943 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
2944 _T("VALUES (2,'.1.3.6.1.4.1.45.3.26.*',3,0)\n")
2945 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
2946 _T("VALUES (3,'.1.3.6.1.4.1.45.3.30.*',3,0)\n")
2947 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
2948 _T("VALUES (4,'.1.3.6.1.4.1.45.3.31.*',3,0)\n")
2949 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
2950 _T("VALUES (5,'.1.3.6.1.4.1.45.3.32.*',3,0)\n")
2951 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
2952 _T("VALUES (6,'.1.3.6.1.4.1.45.3.33.*',3,0)\n")
2953 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
2954 _T("VALUES (7,'.1.3.6.1.4.1.45.3.34.*',3,0)\n")
2955 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
2956 _T("VALUES (8,'.1.3.6.1.4.1.45.3.35.*',3,0)\n")
2957 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
2958 _T("VALUES (9,'.1.3.6.1.4.1.45.3.36.*',3,0)\n")
2959 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
2960 _T("VALUES (10,'.1.3.6.1.4.1.45.3.40.*',3,0)\n")
2961 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
2962 _T("VALUES (11,'.1.3.6.1.4.1.45.3.61.*',3,0)\n")
2963 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description) ")
2964 _T("VALUES (14,'&Info->Topology table (Nortel)',2 ,'Topology table',1,'','Show topology table (Nortel protocol)')\n")
2965 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2966 _T("VALUES (14,0,'Peer IP','.1.3.6.1.4.1.45.1.6.13.2.1.1.3',3 ,0)\n")
2967 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2968 _T("VALUES (14,1,'Peer MAC','.1.3.6.1.4.1.45.1.6.13.2.1.1.5',4 ,0)\n")
2969 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2970 _T("VALUES (14,2,'Port','.1.3.6.1.4.1.45.1.6.13.2.1.1.2',5 ,0)\n")
2971 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (14,-2147483648)\n")
2972 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description) ")
2973 _T("VALUES (15,'&Info->Topology table (CDP)',2 ,'Topology table',1,'','Show topology table (CDP)')\n")
2974 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2975 _T("VALUES (15,0,'Device ID','.1.3.6.1.4.1.9.9.23.1.2.1.1.6',0 ,0)\n")
2976 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2977 _T("VALUES (15,1,'IP Address','.1.3.6.1.4.1.9.9.23.1.2.1.1.4',3 ,0)\n")
2978 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2979 _T("VALUES (15,2,'Platform','.1.3.6.1.4.1.9.9.23.1.2.1.1.8',0 ,0)\n")
2980 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2981 _T("VALUES (15,3,'Version','.1.3.6.1.4.1.9.9.23.1.2.1.1.5',0 ,0)\n")
2982 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
2983 _T("VALUES (15,4,'Port','.1.3.6.1.4.1.9.9.23.1.2.1.1.7',0 ,0)\n")
2984 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (15,-2147483648)\n")
2985 _T("<END>");
5039dede
AK
2986
2987 if (!SQLBatch(m_szBatch))
2988 if (!g_bIgnoreErrors)
2989 return FALSE;
2990
2991 if (!SQLQuery(_T("UPDATE config SET var_value='46' WHERE var_name='DBFormatVersion'")))
2992 if (!g_bIgnoreErrors)
2993 return FALSE;
2994
2995 return TRUE;
2996}
2997
2998
2999//
3000// Upgrade from V44 to V45
3001//
3002
31cc1924 3003static BOOL H_UpgradeFromV44(int currVersion, int newVersion)
5039dede
AK
3004{
3005 static TCHAR m_szBatch[] =
08b214c6
VK
3006 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
3007 _T("VALUES (36,'SYS_DB_CONN_LOST',4,1,")
3008 _T("'Lost connection with backend database engine',")
3009 _T("'Generated if connection with backend database engine is lost.#0D#0A")
3010 _T("Parameters:#0D#0A No message-specific parameters')\n")
3011 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
3012 _T("VALUES (37,'SYS_DB_CONN_RESTORED',0,1,")
3013 _T("'Connection with backend database engine restored',")
3014 _T("'Generated when connection with backend database engine restored.#0D#0A")
3015 _T("Parameters:#0D#0A No message-specific parameters')\n")
3016 _T("<END>");
5039dede
AK
3017
3018 if (!SQLBatch(m_szBatch))
3019 if (!g_bIgnoreErrors)
3020 return FALSE;
3021
3022 if (!SQLQuery(_T("UPDATE config SET var_value='45' WHERE var_name='DBFormatVersion'")))
3023 if (!g_bIgnoreErrors)
3024 return FALSE;
3025
3026 return TRUE;
3027}
3028
3029
3030//
3031// Upgrade from V43 to V44
3032//
3033
31cc1924 3034static BOOL H_UpgradeFromV43(int currVersion, int newVersion)
5039dede
AK
3035{
3036 static TCHAR m_szBatch[] =
08b214c6
VK
3037 _T("DELETE FROM object_tools WHERE tool_id=8000\n")
3038 _T("DELETE FROM object_tools_table_columns WHERE tool_id=8000\n")
3039 _T("DELETE FROM object_tools_acl WHERE tool_id=8000\n")
3040 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,")
3041 _T("matching_oid,description) VALUES (13,'&Info->&Process list',3,")
3042 _T("'Process List#7FSystem.ProcessList#7F^([0-9]+) (.*)',2,'',")
3043 _T("'Show list of currently running processes')\n")
3044 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,")
3045 _T("col_oid,col_format,col_substr) VALUES (13,0,'PID','',0,1)\n")
3046 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,")
3047 _T("col_oid,col_format,col_substr) VALUES (13,1,'Name','',0,2)\n")
3048 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (13,-2147483648)\n")
3049 _T("<END>");
5039dede
AK
3050
3051 if (!CreateTable(_T("CREATE TABLE agent_configs ("
08b214c6
VK
3052 _T("config_id integer not null,")
3053 _T("config_name varchar(255) not null,")
3054 _T("config_file $SQL:TEXT not null,")
3055 _T("config_filter $SQL:TEXT not null,")
3056 _T("sequence_number integer not null,")
3057 _T("PRIMARY KEY(config_id))"))))
5039dede
AK
3058 if (!g_bIgnoreErrors)
3059 return FALSE;
3060
3061 if (!SQLBatch(m_szBatch))
3062 if (!g_bIgnoreErrors)
3063 return FALSE;
3064
3065 if (!CreateConfigParam(_T("DBLockPID"), _T("0"), 0, 0))
3066 if (!g_bIgnoreErrors)
3067 return FALSE;
3068
3069 if (!SQLQuery(_T("UPDATE config SET var_value='44' WHERE var_name='DBFormatVersion'")))
3070 if (!g_bIgnoreErrors)
3071 return FALSE;
3072
3073 return TRUE;
3074}
3075
3076
3077//
3078// Upgrade from V42 to V43
3079//
3080
31cc1924 3081static BOOL H_UpgradeFromV42(int currVersion, int newVersion)
5039dede
AK
3082{
3083 if (!CreateConfigParam(_T("RADIUSPort"), _T("1645"), 1, 0))
3084 if (!g_bIgnoreErrors)
3085 return FALSE;
3086
3087 if (!SQLQuery(_T("UPDATE config SET var_value='43' WHERE var_name='DBFormatVersion'")))
3088 if (!g_bIgnoreErrors)
3089 return FALSE;
3090
3091 return TRUE;
3092}
3093
3094
3095//
3096// Upgrade from V41 to V42
3097//
3098
31cc1924 3099static BOOL H_UpgradeFromV41(int currVersion, int newVersion)
5039dede
AK
3100{
3101 static TCHAR m_szBatch[] =
08b214c6
VK
3102 _T("INSERT INTO images (image_id,name,file_name_png,file_hash_png,")
3103 _T("file_name_ico,file_hash_ico) VALUES (15,'Obj.Condition',")
3104 _T("'condition.png','<invalid_hash>','condition.ico','<invalid_hash>')\n")
3105 _T("INSERT INTO default_images (object_class,image_id) VALUES (13, 15)\n")
3106 _T("INSERT INTO oid_to_type (pair_id,snmp_oid,node_type,node_flags) ")
3107 _T("VALUES (1,'.1.3.6.1.4.1.3224.1.*',2,0)\n")
3108 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
3109 _T("VALUES (34,'SYS_CONDITION_ACTIVATED',2,1,'Condition \"%2\" activated',")
3110 _T("'Default event for condition activation.#0D#0AParameters:#0D#0A")
3111 _T(" 1) Condition object ID#0D#0A 2) Condition object name#0D#0A")
3112 _T(" 3) Previous condition status#0D#0A 4) Current condition status')\n")
3113 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
3114 _T("VALUES (35,'SYS_CONDITION_DEACTIVATED',0,1,'Condition \"%2\" deactivated',")
3115 _T("'Default event for condition deactivation.#0D#0AParameters:#0D#0A")
3116 _T(" 1) Condition object ID#0D#0A 2) Condition object name#0D#0A")
3117 _T(" 3) Previous condition status#0D#0A 4) Current condition status')\n")
3118 _T("<END>");
5039dede
AK
3119
3120 if (!CreateTable(_T("CREATE TABLE conditions ("
08b214c6
VK
3121 _T("id integer not null,")
3122 _T("activation_event integer not null,")
3123 _T("deactivation_event integer not null,")
3124 _T("source_object integer not null,")
3125 _T("active_status integer not null,")
3126 _T("inactive_status integer not null,")
3127 _T("script $SQL:TEXT not null,")
3128 _T("PRIMARY KEY(id))"))))
5039dede
AK
3129 if (!g_bIgnoreErrors)
3130 return FALSE;
3131
3132 if (!CreateTable(_T("CREATE TABLE cond_dci_map ("
08b214c6
VK
3133 _T("condition_id integer not null,")
3134 _T("dci_id integer not null,")
3135 _T("node_id integer not null,")
3136 _T("dci_func integer not null,")
3137 _T("num_polls integer not null,")
3138 _T("PRIMARY KEY(condition_id,dci_id))"))))
5039dede
AK
3139 if (!g_bIgnoreErrors)
3140 return FALSE;
3141
3142 if (!SQLBatch(m_szBatch))
3143 if (!g_bIgnoreErrors)
3144 return FALSE;
3145
3146 if (!CreateConfigParam(_T("NumberOfConditionPollers"), _T("10"), 1, 1))
3147 if (!g_bIgnoreErrors)
3148 return FALSE;
3149
3150 if (!CreateConfigParam(_T("ConditionPollingInterval"), _T("60"), 1, 1))
3151 if (!g_bIgnoreErrors)
3152 return FALSE;
3153
3154 if (!SQLQuery(_T("UPDATE config SET var_value='42' WHERE var_name='DBFormatVersion'")))
3155 if (!g_bIgnoreErrors)
3156 return FALSE;
3157
3158 return TRUE;
3159}
3160
3161
3162//
3163// Upgrade from V40 to V41
3164//
3165
31cc1924 3166static BOOL H_UpgradeFromV40(int currVersion, int newVersion)
5039dede
AK
3167{
3168 static TCHAR m_szBatch[] =
08b214c6
VK
3169 _T("ALTER TABLE users ADD guid varchar(36)\n")
3170 _T("ALTER TABLE users ADD auth_method integer\n")
3171 _T("ALTER TABLE user_groups ADD guid varchar(36)\n")
3172 _T("UPDATE users SET auth_method=0\n")
3173 _T("<END>");
5039dede
AK
3174 DB_RESULT hResult;
3175 int i, nCount;
3176 DWORD dwId;
3177 uuid_t guid;
3178 TCHAR szQuery[256], szGUID[64];
3179
3180 if (!SQLBatch(m_szBatch))
3181 if (!g_bIgnoreErrors)
3182 return FALSE;
3183
3184 // Generate GUIDs for users and groups
9f24efb3 3185 _tprintf(_T("Generating GUIDs...\n"));
5039dede
AK
3186
3187 hResult = SQLSelect(_T("SELECT id FROM users"));
3188 if (hResult != NULL)
3189 {
3190 nCount = DBGetNumRows(hResult);
3191 for(i = 0; i < nCount; i++)
3192 {
3193 dwId = DBGetFieldULong(hResult, i, 0);
3194 uuid_generate(guid);
3195 _sntprintf(szQuery, 256, _T("UPDATE users SET guid='%s' WHERE id=%d"),
3196 uuid_to_string(guid, szGUID), dwId);
3197 if (!SQLQuery(szQuery))
3198 if (!g_bIgnoreErrors)
3199 {
3200 DBFreeResult(hResult);
3201 return FALSE;
3202 }
3203 }
3204 DBFreeResult(hResult);
3205 }
3206
3207 hResult = SQLSelect(_T("SELECT id FROM user_groups"));
3208 if (hResult != NULL)
3209 {
3210 nCount = DBGetNumRows(hResult);
3211 for(i = 0; i < nCount; i++)
3212 {
3213 dwId = DBGetFieldULong(hResult, i, 0);
3214 uuid_generate(guid);
3215 _sntprintf(szQuery, 256, _T("UPDATE user_groups SET guid='%s' WHERE id=%d"),
3216 uuid_to_string(guid, szGUID), dwId);
3217 if (!SQLQuery(szQuery))
3218 if (!g_bIgnoreErrors)
3219 {
3220 DBFreeResult(hResult);
3221 return FALSE;
3222 }
3223 }
3224 DBFreeResult(hResult);
3225 }
3226
3227 if (!CreateConfigParam(_T("RADIUSServer"), _T("localhost"), 1, 0))
3228 if (!g_bIgnoreErrors)
3229 return FALSE;
3230
3231 if (!CreateConfigParam(_T("RADIUSSecret"), _T("netxms"), 1, 0))
3232 if (!g_bIgnoreErrors)
3233 return FALSE;
3234
3235 if (!CreateConfigParam(_T("RADIUSNumRetries"), _T("5"), 1, 0))
3236 if (!g_bIgnoreErrors)
3237 return FALSE;
3238
3239 if (!CreateConfigParam(_T("RADIUSTimeout"), _T("3"), 1, 0))
3240 if (!g_bIgnoreErrors)
3241 return FALSE;
3242
3243 if (!SQLQuery(_T("UPDATE config SET var_value='41' WHERE var_name='DBFormatVersion'")))
3244 if (!g_bIgnoreErrors)
3245 return FALSE;
3246
3247 return TRUE;
3248}
3249
3250
3251//
3252// Upgrade from V39 to V40
3253//
3254
31cc1924 3255static BOOL H_UpgradeFromV39(int currVersion, int newVersion)
5039dede
AK
3256{
3257 static TCHAR m_szBatch[] =
08b214c6
VK
3258 _T("ALTER TABLE users ADD grace_logins integer\n")
3259 _T("UPDATE users SET grace_logins=5\n")
3260 _T("<END>");
5039dede
AK
3261
3262 if (!SQLBatch(m_szBatch))
3263 if (!g_bIgnoreErrors)
3264 return FALSE;
3265
3266 if (!SQLQuery(_T("UPDATE config SET var_value='40' WHERE var_name='DBFormatVersion'")))
3267 if (!g_bIgnoreErrors)
3268 return FALSE;
3269
3270 return TRUE;
3271}
3272
3273
3274//
3275// Upgrade from V38 to V39
3276//
3277
31cc1924 3278static BOOL H_UpgradeFromV38(int currVersion, int newVersion)
5039dede
AK
3279{
3280 static TCHAR m_szBatch[] =
08b214c6
VK
3281 _T("INSERT INTO maps (map_id,map_name,description,root_object_id) ")
3282 _T("VALUES (1,'Default','Default network map',1)\n")
3283 _T("INSERT INTO map_access_lists (map_id,user_id,access_rights) VALUES (1,-2147483648,1)\n")
3284 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
3285 _T("VALUES (33,'SYS_SCRIPT_ERROR',2,1,")
3286 _T("'Script (%1) execution error: %2',")
3287 _T("'Generated when server encounters NXSL script execution error.#0D#0A")
3288 _T("Parameters:#0D#0A")
3289 _T(" 1) Script name#0D#0A")
3290 _T(" 2) Error text#0D#0A")
3291 _T(" 3) DCI ID if script is DCI transformation script, or 0 otherwise')\n")
3292 _T("<END>");
5039dede
AK
3293
3294 if (!CreateTable(_T("CREATE TABLE maps ("
08b214c6
VK
3295 _T("map_id integer not null,")
3296 _T("map_name varchar(255) not null,")
3297 _T("description $SQL:TEXT not null,")
3298 _T("root_object_id integer not null,")
3299 _T("PRIMARY KEY(map_id))"))))
5039dede
AK
3300 if (!g_bIgnoreErrors)
3301 return FALSE;
3302
3303 if (!CreateTable(_T("CREATE TABLE map_access_lists ("
08b214c6
VK
3304 _T("map_id integer not null,")
3305 _T("user_id integer not null,")
3306 _T("access_rights integer not null,")
3307 _T("PRIMARY KEY(map_id,user_id))"))))
5039dede
AK
3308 if (!g_bIgnoreErrors)
3309 return FALSE;
3310
3311 if (!CreateTable(_T("CREATE TABLE submaps ("
08b214c6
VK
3312 _T("map_id integer not null,")
3313 _T("submap_id integer not null,")
3314 _T("attributes integer not null,")
3315 _T("PRIMARY KEY(map_id,submap_id))"))))
5039dede
AK
3316 if (!g_bIgnoreErrors)
3317 return FALSE;
3318
3319 if (!CreateTable(_T("CREATE TABLE submap_object_positions ("
08b214c6
VK
3320 _T("map_id integer not null,")
3321 _T("submap_id integer not null,")
3322 _T("object_id integer not null,")
3323 _T("x integer not null,")
3324 _T("y integer not null,")
3325 _T("PRIMARY KEY(map_id,submap_id,object_id))"))))
5039dede
AK
3326 if (!g_bIgnoreErrors)
3327 return FALSE;
3328
3329 if (!CreateTable(_T("CREATE TABLE submap_links ("
08b214c6
VK
3330 _T("map_id integer not null,")
3331 _T("submap_id integer not null,")
3332 _T("object_id1 integer not null,")
3333 _T("object_id2 integer not null,")
3334 _T("link_type integer not null,")
3335 _T("PRIMARY KEY(map_id,submap_id,object_id1,object_id2))"))))
5039dede
AK
3336 if (!g_bIgnoreErrors)
3337 return FALSE;
3338
3339 if (!SQLBatch(m_szBatch))
3340 if (!g_bIgnoreErrors)
3341 return FALSE;
3342
3343 if (!CreateConfigParam(_T("LockTimeout"), _T("60000"), 1, 1))
3344 if (!g_bIgnoreErrors)
3345 return FALSE;
3346
3347 if (!CreateConfigParam(_T("DisableVacuum"), _T("0"), 1, 0))
3348 if (!g_bIgnoreErrors)
3349 return FALSE;
3350
3351 if (!SQLQuery(_T("UPDATE config SET var_value='39' WHERE var_name='DBFormatVersion'")))
3352 if (!g_bIgnoreErrors)
3353 return FALSE;
3354
3355 return TRUE;
3356}
3357
3358
3359//
3360// Upgrade from V37 to V38
3361//
3362
31cc1924 3363static BOOL H_UpgradeFromV37(int currVersion, int newVersion)
5039dede
AK
3364{
3365 static TCHAR m_szBatch[] =
08b214c6
VK
3366 _T("CREATE INDEX idx_event_log_event_timestamp ON event_log(event_timestamp)\n")
3367 _T("CREATE INDEX idx_syslog_msg_timestamp ON syslog(msg_timestamp)\n")
3368 _T("CREATE INDEX idx_snmp_trap_log_trap_timestamp ON snmp_trap_log(trap_timestamp)\n")
3369 _T("<END>");
5039dede
AK
3370
3371 if (!CreateTable(_T("CREATE TABLE snmp_trap_log ("
08b214c6
VK
3372 _T("trap_id $SQL:INT64 not null,")
3373 _T("trap_timestamp integer not null,")
3374 _T("ip_addr varchar(15) not null,")
3375 _T("object_id integer not null,")
3376 _T("trap_oid varchar(255) not null,")
3377 _T("trap_varlist $SQL:TEXT not null,")
3378 _T("PRIMARY KEY(trap_id))"))))
5039dede
AK
3379
3380 if (!g_bIgnoreErrors)
3381 return FALSE;
3382
3383 if (!SQLBatch(m_szBatch))
3384 if (!g_bIgnoreErrors)
3385 return FALSE;
3386
3387 if (!CreateConfigParam(_T("LogAllSNMPTraps"), _T("0"), 1, 1))
3388 if (!g_bIgnoreErrors)
3389 return FALSE;
3390
3391 if (!SQLQuery(_T("UPDATE config SET var_value='38' WHERE var_name='DBFormatVersion'")))
3392 if (!g_bIgnoreErrors)
3393 return FALSE;
3394
3395 return TRUE;
3396}
3397
3398
3399//
3400// Upgrade from V36 to V37
3401//
3402
31cc1924 3403static BOOL H_UpgradeFromV36(int currVersion, int newVersion)
5039dede
AK
3404{
3405 static TCHAR m_szBatch[] =
08b214c6
VK
3406 _T("DROP TABLE new_nodes\n")
3407 _T("DELETE FROM config WHERE var_name='NewNodePollingInterval'\n")
3408 _T("INSERT INTO script_library (script_id,script_name,script_code) ")
3409 _T("VALUES (1,'Filter::SNMP','sub main()#0D#0A{#0D#0A return $1->isSNMP;#0D#0A}#0D#0A')\n")
3410 _T("INSERT INTO script_library (script_id,script_name,script_code) ")
3411 _T("VALUES (2,'Filter::Agent','sub main()#0D#0A{#0D#0A return $1->isAgent;#0D#0A}#0D#0A')\n")
3412 _T("INSERT INTO script_library (script_id,script_name,script_code) ")
3413 _T("VALUES (3,'Filter::AgentOrSNMP','sub main()#0D#0A{#0D#0A return $1->isAgent || $1->isSNMP;#0D#0A}#0D#0A')\n")
3414 _T("INSERT INTO script_library (script_id,script_name,script_code) ")
3415 _T("VALUES (4,'DCI::SampleTransform','sub dci_transform()#0D#0A{#0D#0A return $1 + 1;#0D#0A}#0D#0A')\n")
3416 _T("<END>");
3417
3418 if (!CreateTable(_T("CREATE TABLE script_library (")
3419 _T("script_id integer not null,")
3420 _T("script_name varchar(63) not null,")
3421 _T("script_code $SQL:TEXT not null,")
3422 _T("PRIMARY KEY(script_id))")))
5039dede
AK
3423 if (!g_bIgnoreErrors)
3424 return FALSE;
3425
3426 if (!SQLBatch(m_szBatch))
3427 if (!g_bIgnoreErrors)
3428 return FALSE;
3429
3430 if (!CreateConfigParam(_T("DefaultCommunityString"), _T("public"), 1, 0))
3431 if (!g_bIgnoreErrors)
3432 return FALSE;
3433
3434 if (!CreateConfigParam(_T("DiscoveryFilter"), _T("none"), 1, 0))
3435 if (!g_bIgnoreErrors)
3436 return FALSE;
3437
3438 if (!SQLQuery(_T("UPDATE config SET var_value='37' WHERE var_name='DBFormatVersion'")))
3439 if (!g_bIgnoreErrors)
3440 return FALSE;
3441
3442 return TRUE;
3443}
3444
3445
3446//
3447// Upgrade from V35 to V36
3448//
3449
31cc1924 3450static BOOL H_UpgradeFromV35(int currVersion, int newVersion)
5039dede
AK
3451{
3452 static TCHAR m_szBatch[] =
08b214c6
VK
3453 _T("ALTER TABLE nodes ADD proxy_node integer\n")
3454 _T("UPDATE nodes SET proxy_node=0\n")
3455 _T("ALTER TABLE object_tools ADD matching_oid varchar(255)\n")
3456 _T("UPDATE object_tools SET matching_oid='#00'\n")
3457 _T("<END>");
5039dede
AK
3458
3459 if (!SQLBatch(m_szBatch))
3460 if (!g_bIgnoreErrors)
3461 return FALSE;
3462
3463 if (!CreateConfigParam(_T("CapabilityExpirationTime"), _T("604800"), 1, 0))
3464 if (!g_bIgnoreErrors)
3465 return FALSE;
3466
3467 if (!SQLQuery(_T("UPDATE config SET var_value='36' WHERE var_name='DBFormatVersion'")))
3468 if (!g_bIgnoreErrors)
3469 return FALSE;
3470
3471 return TRUE;
3472}
3473
3474
3475//
3476// Upgrade from V34 to V35
3477//
3478
31cc1924 3479static BOOL H_UpgradeFromV34(int currVersion, int newVersion)
5039dede
AK
3480{
3481 static TCHAR m_szBatch[] =
08b214c6
VK
3482 _T("ALTER TABLE object_properties DROP COLUMN status_alg\n")
3483 _T("ALTER TABLE object_properties ADD status_calc_alg integer\n")
3484 _T("ALTER TABLE object_properties ADD status_prop_alg integer\n")
3485 _T("ALTER TABLE object_properties ADD status_fixed_val integer\n")
3486 _T("ALTER TABLE object_properties ADD status_shift integer\n")
3487 _T("ALTER TABLE object_properties ADD status_translation varchar(8)\n")
3488 _T("ALTER TABLE object_properties ADD status_single_threshold integer\n")
3489 _T("ALTER TABLE object_properties ADD status_thresholds varchar(8)\n")
3490 _T("UPDATE object_properties SET status_calc_alg=0,status_prop_alg=0,")
3491 _T("status_fixed_val=0,status_shift=0,status_translation='01020304',")
3492 _T("status_single_threshold=75,status_thresholds='503C2814'\n")
3493 _T("DELETE FROM config WHERE var_name='StatusCalculationAlgorithm'\n")
3494 _T("<END>");
5039dede
AK
3495
3496 if (!SQLBatch(m_szBatch))
3497 if (!g_bIgnoreErrors)
3498 return FALSE;
3499
3500 if (!CreateConfigParam(_T("StatusCalculationAlgorithm"), _T("1"), 1, 1))
3501 if (!g_bIgnoreErrors)
3502 return FALSE;
3503
3504 if (!CreateConfigParam(_T("StatusPropagationAlgorithm"), _T("1"), 1, 1))
3505 if (!g_bIgnoreErrors)
3506 return FALSE;
3507
3508 if (!CreateConfigParam(_T("FixedStatusValue"), _T("0"), 1, 1))
3509 if (!g_bIgnoreErrors)
3510 return FALSE;
3511
3512 if (!CreateConfigParam(_T("StatusShift"), _T("0"), 1, 1))
3513 if (!g_bIgnoreErrors)
3514 return FALSE;
3515
3516 if (!CreateConfigParam(_T("StatusTranslation"), _T("01020304"), 1, 1))
3517 if (!g_bIgnoreErrors)
3518 return FALSE;
3519
3520 if (!CreateConfigParam(_T("StatusSingleThreshold"), _T("75"), 1, 1))
3521 if (!g_bIgnoreErrors)
3522 return FALSE;
3523
3524 if (!CreateConfigParam(_T("StatusThresholds"), _T("503C2814"), 1, 1))
3525 if (!g_bIgnoreErrors)
3526 return FALSE;
3527
3528 if (!SQLQuery(_T("UPDATE config SET var_value='35' WHERE var_name='DBFormatVersion'")))
3529 if (!g_bIgnoreErrors)
3530 return FALSE;
3531
3532 return TRUE;
3533}
3534
3535
3536//
3537// Upgrade from V33 to V34
3538//
3539
31cc1924 3540static BOOL H_UpgradeFromV33(int currVersion, int newVersion)
5039dede
AK
3541{
3542 static TCHAR m_szBatch[] =
08b214c6
VK
3543 _T("ALTER TABLE items ADD adv_schedule integer\n")
3544 _T("UPDATE items SET adv_schedule=0\n")
3545 _T("<END>");
5039dede
AK
3546
3547 if (!SQLBatch(m_szBatch))
3548 if (!g_bIgnoreErrors)
3549 return FALSE;
3550
3551 if (!CreateTable(_T("CREATE TABLE dci_schedules ("
08b214c6
VK
3552 _T("item_id integer not null,")
3553 _T("schedule varchar(255) not null)"))))
5039dede
AK
3554 if (!g_bIgnoreErrors)
3555 return FALSE;
3556
3557 if (!CreateTable(_T("CREATE TABLE syslog ("
08b214c6
VK
3558 _T("msg_id $SQL:INT64 not null,")
3559 _T("msg_timestamp integer not null,")
3560 _T("facility integer not null,")
3561 _T("severity integer not null,")
3562 _T("source_object_id integer not null,")
3563 _T("hostname varchar(127) not null,")
3564 _T("msg_tag varchar(32) not null,")
3565 _T("msg_text $SQL:TEXT not null,")
3566 _T("PRIMARY KEY(msg_id))"))))
5039dede
AK
3567 if (!g_bIgnoreErrors)
3568 return FALSE;
3569
3570 if (!CreateConfigParam(_T("IcmpPingSize"), _T("46"), 1, 1))
3571 if (!g_bIgnoreErrors)
3572 return FALSE;
3573
3574 if (!CreateConfigParam(_T("SMSDrvConfig"), _T(""), 1, 1))
3575 if (!g_bIgnoreErrors)
3576 return FALSE;
3577
3578 if (!CreateConfigParam(_T("EnableSyslogDaemon"), _T("0"), 1, 1))
3579 if (!g_bIgnoreErrors)
3580 return FALSE;
3581
3582 if (!CreateConfigParam(_T("SyslogListenPort"), _T("514"), 1, 1))
3583 if (!g_bIgnoreErrors)
3584 return FALSE;
3585
3586 if (!CreateConfigParam(_T("SyslogRetentionTime"), _T("5184000"), 1, 0))
3587 if (!g_bIgnoreErrors)
3588 return FALSE;
3589
3590 if (!SQLQuery(_T("UPDATE config SET var_value='34' WHERE var_name='DBFormatVersion'")))
3591 if (!g_bIgnoreErrors)
3592 return FALSE;
3593
3594 return TRUE;
3595}
3596
3597
3598//
3599// Upgrade from V32 to V33
3600//
3601
31cc1924 3602static BOOL H_UpgradeFromV32(int currVersion, int newVersion)
5039dede
AK
3603{
3604 static TCHAR m_szBatch[] =
08b214c6
VK
3605 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,description) ")
3606 _T("VALUES (5,'&Info->&Switch forwarding database (FDB)',2 ,'Forwarding database',0,'Show switch forwarding database')\n")
3607 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
3608 _T("VALUES (5,0,'MAC Address','.1.3.6.1.2.1.17.4.3.1.1',4 ,0)\n")
3609 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr) ")
3610 _T("VALUES (5,1,'Port','.1.3.6.1.2.1.17.4.3.1.2',1 ,0)\n")
3611 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,description) ")
3612 _T("VALUES (6,'&Connect->Open &web browser',4 ,'http://%OBJECT_IP_ADDR%',0,'Open embedded web browser to node')\n")
3613 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,description) ")
3614 _T("VALUES (7,'&Connect->Open &web browser (HTTPS)',4 ,'https://%OBJECT_IP_ADDR%',0,'Open embedded web browser to node using HTTPS')\n")
3615 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,description) ")
3616 _T("VALUES (8,'&Info->&Agent-&