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