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