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