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