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