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