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