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