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