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