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