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