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