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