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