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