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