Fixed upgrade procedure for fail_time_snmp and fail_time_snmp
[public/netxms.git] / src / server / tools / nxdbmgr / upgrade.cpp
1 /*
2 ** nxdbmgr - NetXMS database manager
3 ** Copyright (C) 2004-2017 Victor Kirhenshtein
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 **
19 ** File: upgrade.cpp
20 **
21 **/
22
23 #include "nxdbmgr.h"
24 #include <nxevent.h>
25
26 /**
27 * Externals
28 */
29 BOOL MigrateMaps();
30 bool ConvertTDataTables();
31
32 /**
33 * Pre-defined GUID mapping for GenerateGUID
34 */
35 struct GUID_MAPPING
36 {
37 UINT32 id;
38 const TCHAR *guid;
39 };
40
41 /**
42 * Generate GUIDs
43 */
44 static bool GenerateGUID(const TCHAR *table, const TCHAR *idColumn, const TCHAR *guidColumn, const GUID_MAPPING *mapping)
45 {
46 TCHAR query[256];
47 _sntprintf(query, 256, _T("SELECT %s FROM %s"), idColumn, table);
48 DB_RESULT hResult = SQLSelect(query);
49 if (hResult == NULL)
50 return false;
51
52 uuid_t guid;
53 TCHAR buffer[64];
54
55 int count = DBGetNumRows(hResult);
56 for(int i = 0; i < count; i++)
57 {
58 const TCHAR *guidText = NULL;
59 UINT32 id = DBGetFieldULong(hResult, i, 0);
60 if (mapping != NULL)
61 {
62 for(int j = 0; mapping[j].guid != NULL; j++)
63 if (mapping[j].id == id)
64 {
65 guidText = mapping[j].guid;
66 break;
67 }
68 }
69 if (guidText == NULL)
70 {
71 _uuid_generate(guid);
72 guidText = _uuid_to_string(guid, buffer);
73 }
74 _sntprintf(query, 256, _T("UPDATE %s SET %s='%s' WHERE %s=%d"), table, guidColumn, guidText, idColumn, id);
75 if (!SQLQuery(query))
76 {
77 DBFreeResult(hResult);
78 return false;
79 }
80 }
81 DBFreeResult(hResult);
82 return true;
83 }
84
85 /**
86 * Create table
87 */
88 static bool CreateTable(const TCHAR *pszQuery)
89 {
90 String query(pszQuery);
91
92 query.replace(_T("$SQL:TEXT"), g_pszSqlType[g_dbSyntax][SQL_TYPE_TEXT]);
93 query.replace(_T("$SQL:TXT4K"), g_pszSqlType[g_dbSyntax][SQL_TYPE_TEXT4K]);
94 query.replace(_T("$SQL:INT64"), g_pszSqlType[g_dbSyntax][SQL_TYPE_INT64]);
95 if (g_dbSyntax == DB_SYNTAX_MYSQL)
96 query += g_pszTableSuffix;
97 return SQLQuery(query);
98 }
99
100 /**
101 * Check if configuration variable exist
102 */
103 static bool IsConfigurationVariableExist(const TCHAR *name)
104 {
105 bool found = false;
106 TCHAR query[256];
107 _sntprintf(query, 256, _T("SELECT var_value FROM config WHERE var_name='%s'"), name);
108 DB_RESULT hResult = DBSelect(g_hCoreDB, query);
109 if (hResult != 0)
110 {
111 found = (DBGetNumRows(hResult) > 0);
112 DBFreeResult(hResult);
113 }
114 return found;
115 }
116
117 /**
118 * Create configuration parameter if it doesn't exist (unless forceUpdate set to true)
119 */
120 bool CreateConfigParam(const TCHAR *name, const TCHAR *value, const TCHAR *description, char dataType, bool isVisible, bool needRestart, bool isPublic, bool forceUpdate)
121 {
122 bool success = true;
123 TCHAR szQuery[3024];
124 if (!IsConfigurationVariableExist(name))
125 {
126 if (DBGetSchemaVersion(g_hCoreDB) >= 454)
127 _sntprintf(szQuery, 3024, _T("INSERT INTO config (var_name,var_value,default_value,is_visible,need_server_restart,is_public,data_type,description) VALUES (%s,%s,%s,%d,%d,'%c','%c',%s)"),
128 (const TCHAR *)DBPrepareString(g_hCoreDB, name, 63),
129 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000),
130 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000),
131 isVisible ? 1 : 0, needRestart ? 1 : 0,
132 isPublic ? _T('Y') : _T('N'), dataType, (const TCHAR *)DBPrepareString(g_hCoreDB, description, 255));
133 else
134 _sntprintf(szQuery, 3024, _T("INSERT INTO config (var_name,var_value,is_visible,need_server_restart,is_public,data_type,description) VALUES (%s,%s,%d,%d,'%c','%c',%s)"),
135 (const TCHAR *)DBPrepareString(g_hCoreDB, name, 63),
136 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000), isVisible ? 1 : 0, needRestart ? 1 : 0,
137 isPublic ? _T('Y') : _T('N'), dataType, (const TCHAR *)DBPrepareString(g_hCoreDB, description, 255));
138 success = SQLQuery(szQuery);
139 }
140 else if (forceUpdate)
141 {
142 _sntprintf(szQuery, 3024, _T("UPDATE config SET var_value=%s WHERE var_name=%s"),
143 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000), (const TCHAR *)DBPrepareString(g_hCoreDB, name, 63));
144 success = SQLQuery(szQuery);
145 }
146 return success;
147 }
148
149 /**
150 * Create configuration parameter if it doesn't exist (unless bForceUpdate set to true)
151 */
152 bool CreateConfigParam(const TCHAR *name, const TCHAR *value, bool isVisible, bool needRestart, bool forceUpdate)
153 {
154 bool success = true;
155 TCHAR szQuery[3024];
156 if (!IsConfigurationVariableExist(name))
157 {
158 if (DBGetSchemaVersion(g_hCoreDB) >= 454)
159 _sntprintf(szQuery, 3024, _T("INSERT INTO config (var_name,var_value,default_value,is_visible,need_server_restart) VALUES (%s,%s,%s,%d,%d)"),
160 (const TCHAR *)DBPrepareString(g_hCoreDB, name, 63),
161 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000),
162 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000),
163 isVisible ? 1 : 0, needRestart ? 1 : 0);
164 else
165 _sntprintf(szQuery, 3024, _T("INSERT INTO config (var_name,var_value,is_visible,need_server_restart) VALUES (%s,%s,%d,%d)"),
166 (const TCHAR *)DBPrepareString(g_hCoreDB, name, 63),
167 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000), isVisible ? 1 : 0, needRestart ? 1 : 0);
168 success = SQLQuery(szQuery);
169 }
170 else if (forceUpdate)
171 {
172 _sntprintf(szQuery, 3024, _T("UPDATE config SET var_value=%s WHERE var_name=%s"),
173 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000), (const TCHAR *)DBPrepareString(g_hCoreDB, name, 63));
174 success = SQLQuery(szQuery);
175 }
176 return success;
177 }
178
179 /**
180 * Convert strings from # encoded form to normal form
181 */
182 static BOOL ConvertStrings(const TCHAR *table, const TCHAR *idColumn, const TCHAR *idColumn2, const TCHAR *column, bool isStringId)
183 {
184 DB_RESULT hResult;
185 TCHAR *query;
186 size_t queryLen = 512;
187 BOOL success = FALSE;
188
189 query = (TCHAR *)malloc(queryLen * sizeof(TCHAR));
190
191 switch(g_dbSyntax)
192 {
193 case DB_SYNTAX_MSSQL:
194 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE CAST(%s AS nvarchar(4000))=N'#00'"), table, column, column);
195 break;
196 case DB_SYNTAX_ORACLE:
197 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE to_char(%s)='#00'"), table, column, column);
198 break;
199 default:
200 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE %s='#00'"), table, column, column);
201 break;
202 }
203 if (!SQLQuery(query))
204 {
205 free(query);
206 return FALSE;
207 }
208
209 _sntprintf(query, queryLen, _T("SELECT %s,%s%s%s FROM %s WHERE %s LIKE '%%#%%'"),
210 idColumn, column, (idColumn2 != NULL) ? _T(",") : _T(""), (idColumn2 != NULL) ? idColumn2 : _T(""), table, column);
211 hResult = SQLSelect(query);
212 if (hResult == NULL)
213 {
214 free(query);
215 return FALSE;
216 }
217
218 int count = DBGetNumRows(hResult);
219 for(int i = 0; i < count; i++)
220 {
221 TCHAR *value = DBGetField(hResult, i, 1, NULL, 0);
222 if (_tcschr(value, _T('#')) != NULL)
223 {
224 DecodeSQLString(value);
225 String newValue = DBPrepareString(g_hCoreDB, value);
226 if (newValue.length() + 256 > queryLen)
227 {
228 queryLen = newValue.length() + 256;
229 query = (TCHAR *)realloc(query, queryLen * sizeof(TCHAR));
230 }
231 if (isStringId)
232 {
233 TCHAR *id = DBGetField(hResult, i, 0, NULL, 0);
234 if (idColumn2 != NULL)
235 {
236 TCHAR *id2 = DBGetField(hResult, i, 2, NULL, 0);
237 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=%s AND %s=%s"),
238 table, column, (const TCHAR *)newValue,
239 idColumn, (const TCHAR *)DBPrepareString(g_hCoreDB, id),
240 idColumn2, (const TCHAR *)DBPrepareString(g_hCoreDB, id2));
241 }
242 else
243 {
244 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=%s"), table, column,
245 (const TCHAR *)newValue, idColumn, (const TCHAR *)DBPrepareString(g_hCoreDB, id));
246 }
247 free(id);
248 }
249 else
250 {
251 INT64 id = DBGetFieldInt64(hResult, i, 0);
252 if (idColumn2 != NULL)
253 {
254 INT64 id2 = DBGetFieldInt64(hResult, i, 2);
255 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=") INT64_FMT _T(" AND %s=") INT64_FMT,
256 table, column, (const TCHAR *)newValue, idColumn, id, idColumn2, id2);
257 }
258 else
259 {
260 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=") INT64_FMT, table, column,
261 (const TCHAR *)newValue, idColumn, id);
262 }
263 }
264 if (!SQLQuery(query))
265 goto cleanup;
266 }
267 }
268 success = TRUE;
269
270 cleanup:
271 DBFreeResult(hResult);
272 free(query);
273 return success;
274 }
275
276 static BOOL ConvertStrings(const TCHAR *table, const TCHAR *idColumn, const TCHAR *column)
277 {
278 return ConvertStrings(table, idColumn, NULL, column, false);
279 }
280
281 /**
282 * Create new event template
283 */
284 static BOOL CreateEventTemplate(int code, const TCHAR *name, int severity, int flags, const TCHAR *guid, const TCHAR *message, const TCHAR *description)
285 {
286 TCHAR query[4096];
287
288 if (guid != NULL)
289 {
290 _sntprintf(query, 4096, _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description,guid) VALUES (%d,'%s',%d,%d,%s,%s,'%s')"),
291 code, name, severity, flags, (const TCHAR *)DBPrepareString(g_hCoreDB, message),
292 (const TCHAR *)DBPrepareString(g_hCoreDB, description), guid);
293 }
294 else
295 {
296 _sntprintf(query, 4096, _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (%d,'%s',%d,%d,%s,%s)"),
297 code, name, severity, flags, (const TCHAR *)DBPrepareString(g_hCoreDB, message),
298 (const TCHAR *)DBPrepareString(g_hCoreDB, description));
299 }
300 return SQLQuery(query);
301 }
302
303 /**
304 * Re-create TDATA tables
305 */
306 static BOOL RecreateTData(const TCHAR *className, bool multipleTables, bool indexFix)
307 {
308 TCHAR query[1024];
309 _sntprintf(query, 256, _T("SELECT id FROM %s"), className);
310 DB_RESULT hResult = SQLSelect(query);
311 if (hResult != NULL)
312 {
313 int count = DBGetNumRows(hResult);
314 for(int i = 0; i < count; i++)
315 {
316 bool recreateTables = true;
317 DWORD id = DBGetFieldULong(hResult, i, 0);
318
319 if (indexFix)
320 {
321 _sntprintf(query, 256, _T("SELECT count(*) FROM dc_tables WHERE node_id=%d"), id);
322 DB_RESULT hResultCount = SQLSelect(query);
323 if (hResultCount != NULL)
324 {
325 recreateTables = (DBGetFieldLong(hResultCount, 0, 0) == 0);
326 DBFreeResult(hResultCount);
327 }
328
329 if (!recreateTables)
330 {
331 _sntprintf(query, 256, _T("CREATE INDEX idx_tdata_rec_%d_id ON tdata_records_%d(record_id)"), id, id);
332 if (!SQLQuery(query))
333 {
334 if (!g_bIgnoreErrors)
335 {
336 DBFreeResult(hResult);
337 return FALSE;
338 }
339 }
340 }
341 }
342
343 if (recreateTables)
344 {
345 if (multipleTables)
346 {
347 _sntprintf(query, 1024, _T("DROP TABLE tdata_rows_%d\nDROP TABLE tdata_records_%d\nDROP TABLE tdata_%d\n<END>"), id, id, id);
348 }
349 else
350 {
351 _sntprintf(query, 256, _T("DROP TABLE tdata_%d\n<END>"), id);
352 }
353 if (!SQLBatch(query))
354 {
355 if (!g_bIgnoreErrors)
356 {
357 DBFreeResult(hResult);
358 return FALSE;
359 }
360 }
361
362 if (!CreateTDataTable(id))
363 {
364 if (!g_bIgnoreErrors)
365 {
366 DBFreeResult(hResult);
367 return FALSE;
368 }
369 }
370 }
371 }
372 DBFreeResult(hResult);
373 }
374 else
375 {
376 if (!g_bIgnoreErrors)
377 return FALSE;
378 }
379 return TRUE;
380 }
381
382 /**
383 * Convert network masks from dotted decimal format to number of bits
384 */
385 static BOOL ConvertNetMasks(const TCHAR *table, const TCHAR *column, const TCHAR *idColumn, const TCHAR *idColumn2 = NULL, const TCHAR *condition = NULL)
386 {
387 TCHAR query[256];
388
389 if (idColumn2 != NULL)
390 _sntprintf(query, 256, _T("SELECT %s,%s,%s FROM %s"), idColumn, column, idColumn2, table);
391 else
392 _sntprintf(query, 256, _T("SELECT %s,%s FROM %s"), idColumn, column, table);
393 DB_RESULT hResult = SQLSelect(query);
394 if (hResult == NULL)
395 return FALSE;
396
397 bool success = DBDropColumn(g_hCoreDB, table, column);
398
399 if (success)
400 {
401 _sntprintf(query, 256, _T("ALTER TABLE %s ADD %s integer"), table, column);
402 success = SQLQuery(query);
403 }
404
405 if (success)
406 {
407 int count = DBGetNumRows(hResult);
408 for(int i = 0; (i < count) && success; i++)
409 {
410 if (idColumn2 != NULL)
411 {
412 TCHAR id2[256];
413 _sntprintf(query, 256, _T("UPDATE %s SET %s=%d WHERE %s=%d AND %s='%s'"),
414 table, column, BitsInMask(DBGetFieldIPAddr(hResult, i, 1)), idColumn, DBGetFieldLong(hResult, i, 0),
415 idColumn2, DBGetField(hResult, i, 2, id2, 256));
416 }
417 else
418 {
419 _sntprintf(query, 256, _T("UPDATE %s SET %s=%d WHERE %s=%d"),
420 table, column, BitsInMask(DBGetFieldIPAddr(hResult, i, 1)), idColumn, DBGetFieldLong(hResult, i, 0));
421 }
422 success = SQLQuery(query);
423 }
424 }
425
426 DBFreeResult(hResult);
427 return success;
428 }
429
430 /**
431 * Convert object tool macros to new format
432 */
433 static bool ConvertObjectToolMacros(UINT32 id, const TCHAR *text, const TCHAR *column)
434 {
435 if (_tcschr(text, _T('%')) == NULL)
436 return true; // nothing to convert
437
438 String s;
439 for(const TCHAR *p = text; *p != 0; p++)
440 {
441 if (*p == _T('%'))
442 {
443 TCHAR name[256];
444 int i = 0;
445 for(p++; (*p != _T('%')) && (*p != 0); p++)
446 {
447 if (i < 255)
448 name[i++] = *p;
449 }
450 if (*p == 0)
451 break; // malformed string
452 name[i] = 0;
453 if (!_tcscmp(name, _T("ALARM_ID")))
454 {
455 s.append(_T("%Y"));
456 }
457 else if (!_tcscmp(name, _T("ALARM_MESSAGE")))
458 {
459 s.append(_T("%A"));
460 }
461 else if (!_tcscmp(name, _T("ALARM_SEVERITY")))
462 {
463 s.append(_T("%s"));
464 }
465 else if (!_tcscmp(name, _T("ALARM_SEVERITY_TEXT")))
466 {
467 s.append(_T("%S"));
468 }
469 else if (!_tcscmp(name, _T("ALARM_STATE")))
470 {
471 s.append(_T("%y"));
472 }
473 else if (!_tcscmp(name, _T("OBJECT_ID")))
474 {
475 s.append(_T("%I"));
476 }
477 else if (!_tcscmp(name, _T("OBJECT_IP_ADDR")))
478 {
479 s.append(_T("%a"));
480 }
481 else if (!_tcscmp(name, _T("OBJECT_NAME")))
482 {
483 s.append(_T("%n"));
484 }
485 else if (!_tcscmp(name, _T("USERNAME")))
486 {
487 s.append(_T("%U"));
488 }
489 else
490 {
491 s.append(_T("%{"));
492 s.append(name);
493 s.append(_T('}'));
494 }
495 }
496 else
497 {
498 s.append(*p);
499 }
500 }
501
502 String query = _T("UPDATE object_tools SET ");
503 query.append(column);
504 query.append(_T('='));
505 query.append(DBPrepareString(g_hCoreDB, s));
506 query.append(_T(" WHERE tool_id="));
507 query.append(id);
508 return SQLQuery(query);
509 }
510
511 /**
512 * Create library script
513 */
514 static bool CreateLibraryScript(UINT32 id, const TCHAR *name, const TCHAR *code)
515 {
516 // Check if script exists
517 TCHAR query[256];
518 _sntprintf(query, 256, _T("SELECT script_id FROM script_library WHERE script_id=%d OR script_name=%s"),
519 id, (const TCHAR *)DBPrepareString(g_hCoreDB, name));
520 DB_RESULT hResult = SQLSelect(query);
521 if (hResult == NULL)
522 return false;
523 bool exist = (DBGetNumRows(hResult) > 0);
524 DBFreeResult(hResult);
525 if (exist)
526 return true;
527
528 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("INSERT INTO script_library (script_id,script_name,script_code) VALUES (?,?,?)"));
529 if (hStmt == NULL)
530 return false;
531
532 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, id);
533 DBBind(hStmt, 2, DB_SQLTYPE_VARCHAR, name, DB_BIND_STATIC);
534 DBBind(hStmt, 3, DB_SQLTYPE_TEXT, code, DB_BIND_STATIC);
535
536 bool success = SQLExecute(hStmt);
537 DBFreeStatement(hStmt);
538 return success;
539 }
540
541 /**
542 * Check if an event pair is handled by any EPP rules
543 */
544 static bool IsEventPairInUse(UINT32 code1, UINT32 code2)
545 {
546 TCHAR query[256];
547 _sntprintf(query, 256, _T("SELECT count(*) FROM policy_event_list WHERE event_code=%d OR event_code=%d"), code1, code2);
548 DB_RESULT hResult = SQLSelect(query);
549 if (hResult == NULL)
550 return false;
551 bool inUse = (DBGetFieldLong(hResult, 0, 0) > 0);
552 DBFreeResult(hResult);
553 return inUse;
554 }
555
556 /**
557 * Return the next free EPP rule ID
558 */
559 static int NextFreeEPPruleID()
560 {
561 int ruleId = 1;
562 DB_RESULT hResult = SQLSelect(_T("SELECT max(rule_id) FROM event_policy"));
563 if (hResult != NULL)
564 {
565 ruleId = DBGetFieldLong(hResult, 0, 0) + 1;
566 DBFreeResult(hResult);
567 }
568 return ruleId;
569 }
570
571 /**
572 * Add event to EPP rule by rule GUID
573 */
574 static bool AddEventToEPPRule(const TCHAR *guid, UINT32 eventCode)
575 {
576 TCHAR query[256];
577 _sntprintf(query, 256, _T("SELECT rule_id FROM event_policy WHERE rule_guid='%s'"), guid);
578 DB_RESULT hResult = SQLSelect(query);
579 if (hResult == NULL)
580 return false;
581
582 bool success = true;
583 if (DBGetNumRows(hResult) > 0)
584 {
585 _sntprintf(query, 256, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), DBGetFieldLong(hResult, 0, 0), eventCode);
586 success = SQLQuery(query);
587 }
588 DBFreeResult(hResult);
589 return success;
590 }
591
592 /**
593 * Set schema version
594 */
595 static bool SetSchemaVersion(int version)
596 {
597 TCHAR query[256];
598 _sntprintf(query, 256, _T("UPDATE metadata SET var_value='%d' WHERE var_name='SchemaVersion'"), version);
599 return SQLQuery(query);
600 }
601
602 BOOL moveFlagsFromOldTables(const TCHAR *tableName)
603 {
604 //_tprintf(_T("Move flags from %s\n"), tableName);
605 TCHAR query[256];
606 _sntprintf(query, 256, _T("SELECT id,flags FROM %s"), tableName);
607 DB_RESULT hResult = DBSelect(g_hCoreDB, query);
608 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("UPDATE object_properties SET flags=? WHERE object_id=?"));
609 if (hResult != NULL)
610 {
611 if (hStmt != NULL)
612 {
613 int nRows = DBGetNumRows(hResult);
614 for(int i = 0; i < nRows; i++)
615 {
616 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 1));
617 DBBind(hStmt, 2, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 0));
618
619 if (!SQLExecute(hStmt))
620 {
621 if (!g_bIgnoreErrors)
622 {
623 DBFreeStatement(hStmt);
624 DBFreeResult(hResult);
625 return FALSE;
626 }
627 }
628 }
629 DBFreeStatement(hStmt);
630 }
631 else if (!g_bIgnoreErrors)
632 {
633 return FALSE;
634 }
635 DBFreeResult(hResult);
636 }
637 else if (!g_bIgnoreErrors)
638 {
639 return FALSE;
640 }
641
642
643 CHK_EXEC(DBDropColumn(g_hCoreDB, tableName, _T("flags")));
644 return TRUE;
645 }
646
647 /**
648 * Upgrade from V504 to V505 included in stable as 460
649 */
650 static BOOL H_UpgradeFromV504(int currVersion, int newVersion)
651 {
652 static const TCHAR *batch =
653 _T("UPDATE nodes SET fail_time_snmp=0 WHERE fail_time_snmp IS NULL\n")
654 _T("UPDATE nodes SET fail_time_agent=0 WHERE fail_time_agent IS NULL\n")
655 _T("<END>");
656 CHK_EXEC(SQLBatch(batch));
657
658 DBSetNotNullConstraint(g_hCoreDB, _T("nodes"), _T("fail_time_snmp"));
659 DBSetNotNullConstraint(g_hCoreDB, _T("nodes"), _T("fail_time_agent"));
660
661 CHK_EXEC(SetSchemaVersion(505));
662 return TRUE;
663 }
664
665 /**
666 * Upgrade from V503 to V504 included in stable as 459
667 */
668 static BOOL H_UpgradeFromV503(int currVersion, int newVersion)
669 {
670 static const TCHAR *batch =
671 _T("ALTER TABLE nodes ADD fail_time_snmp integer\n")
672 _T("ALTER TABLE nodes ADD fail_time_agent integer\n")
673 _T("<END>");
674 CHK_EXEC(SQLBatch(batch));
675
676 CHK_EXEC(SetSchemaVersion(504));
677 return TRUE;
678 }
679
680 /**
681 * Move single flag
682 */
683 inline void MoveFlag(UINT32 oldVar, UINT32 *newVar, UINT32 oldFlag, UINT32 newFlag)
684 {
685 *newVar |= ((oldVar & oldFlag) != 0) ? newFlag : 0;
686 }
687
688 /**
689 * Move node flags
690 */
691 static void MoveNodeFlags(UINT32 oldFlag, UINT32 *flags)
692 {
693 MoveFlag(oldFlag, flags, 0x10000000, DCF_DISABLE_STATUS_POLL);
694 MoveFlag(oldFlag, flags, 0x20000000, DCF_DISABLE_CONF_POLL);
695 MoveFlag(oldFlag, flags, 0x80000000, DCF_DISABLE_DATA_COLLECT);
696 MoveFlag(oldFlag, flags, 0x00000080, NF_REMOTE_AGENT);
697 MoveFlag(oldFlag, flags, 0x00400000, NF_DISABLE_DISCOVERY_POLL);
698 MoveFlag(oldFlag, flags, 0x00800000, NF_DISABLE_TOPOLOGY_POLL);
699 MoveFlag(oldFlag, flags, 0x01000000, NF_DISABLE_SNMP);
700 MoveFlag(oldFlag, flags, 0x02000000, NF_DISABLE_NXCP);
701 MoveFlag(oldFlag, flags, 0x04000000, NF_DISABLE_ICMP);
702 MoveFlag(oldFlag, flags, 0x08000000, NF_FORCE_ENCRYPTION);
703 MoveFlag(oldFlag, flags, 0x40000000, NF_DISABLE_ROUTE_POLL);
704 }
705
706 /**
707 * Move node capabilities flags
708 */
709 static void MoveNodeCapabilities(UINT32 oldFlag, UINT32 *capabilities)
710 {
711 MoveFlag(oldFlag, capabilities, 0x00000001, NC_IS_SNMP);
712 MoveFlag(oldFlag, capabilities, 0x00000002, NC_IS_NATIVE_AGENT);
713 MoveFlag(oldFlag, capabilities, 0x00000004, NC_IS_BRIDGE);
714 MoveFlag(oldFlag, capabilities, 0x00000008, NC_IS_ROUTER);
715 MoveFlag(oldFlag, capabilities, 0x00000010, NC_IS_LOCAL_MGMT);
716 MoveFlag(oldFlag, capabilities, 0x00000020, NC_IS_PRINTER);
717 MoveFlag(oldFlag, capabilities, 0x00000040, NC_IS_OSPF);
718 MoveFlag(oldFlag, capabilities, 0x00000100, NC_IS_CPSNMP);
719 MoveFlag(oldFlag, capabilities, 0x00000200, NC_IS_CDP);
720 MoveFlag(oldFlag, capabilities, 0x00000400, NC_IS_NDP);
721 MoveFlag(oldFlag, capabilities, 0x00000800, NC_IS_LLDP);
722 MoveFlag(oldFlag, capabilities, 0x00001000, NC_IS_VRRP);
723 MoveFlag(oldFlag, capabilities, 0x00002000, NC_HAS_VLANS);
724 MoveFlag(oldFlag, capabilities, 0x00004000, NC_IS_8021X);
725 MoveFlag(oldFlag, capabilities, 0x00008000, NC_IS_STP);
726 MoveFlag(oldFlag, capabilities, 0x00010000, NC_HAS_ENTITY_MIB);
727 MoveFlag(oldFlag, capabilities, 0x00020000, NC_HAS_IFXTABLE);
728 MoveFlag(oldFlag, capabilities, 0x00040000, NC_HAS_AGENT_IFXCOUNTERS);
729 MoveFlag(oldFlag, capabilities, 0x00080000, NC_HAS_WINPDH);
730 MoveFlag(oldFlag, capabilities, 0x00100000, NC_IS_WIFI_CONTROLLER);
731 MoveFlag(oldFlag, capabilities, 0x00200000, NC_IS_SMCLP);
732 }
733
734 /**
735 * Move node state flags
736 */
737 static void MoveNodeState(UINT32 oldRuntime, UINT32 *state)
738 {
739 MoveFlag(oldRuntime, state, 0x000004, DCSF_UNREACHABLE);
740 MoveFlag(oldRuntime, state, 0x000008, NSF_AGENT_UNREACHABLE);
741 MoveFlag(oldRuntime, state, 0x000010, NSF_SNMP_UNREACHABLE);
742 MoveFlag(oldRuntime, state, 0x000200, NSF_CPSNMP_UNREACHABLE);
743 MoveFlag(oldRuntime, state, 0x008000, DCSF_NETWORK_PATH_PROBLEM);
744 MoveFlag(oldRuntime, state, 0x020000, NSF_CACHE_MODE_NOT_SUPPORTED);
745 }
746
747 /**
748 * Move sensor state flags
749 */
750 static void MoveSensorState(UINT32 oldFlag, UINT32 oldRuntime, UINT32 *status)
751 {
752 MoveFlag(oldFlag, status, 0x00000001, SSF_PROVISIONED);
753 MoveFlag(oldFlag, status, 0x00000002, SSF_REGISTERED);
754 MoveFlag(oldFlag, status, 0x00000004, SSF_ACTIVE);
755 MoveFlag(oldFlag, status, 0x00000008, SSF_CONF_UPDATE_PENDING);
756 MoveFlag(oldRuntime, status, 0x000004, DCSF_UNREACHABLE);
757 }
758
759 /**
760 * Upgrade from V502 to V503
761 */
762 static BOOL H_UpgradeFromV502(int currVersion, int newVersion)
763 {
764 static const TCHAR *batch =
765 _T("ALTER TABLE object_properties ADD flags integer null\n")
766 _T("ALTER TABLE object_properties ADD state integer null\n")
767 _T("ALTER TABLE nodes ADD capabilities integer null\n")
768 _T("UPDATE object_properties set flags=0,state=0\n")
769 _T("<END>");
770 CHK_EXEC(SQLBatch(batch));
771
772 //move flags from old tables to the new one
773 CHK_EXEC(moveFlagsFromOldTables(_T("interfaces")));
774 CHK_EXEC(moveFlagsFromOldTables(_T("templates")));
775 CHK_EXEC(moveFlagsFromOldTables(_T("chassis")));
776 CHK_EXEC(moveFlagsFromOldTables(_T("object_containers")));
777 CHK_EXEC(moveFlagsFromOldTables(_T("network_maps")));
778 //create special behavior for node and sensor, cluster
779 //node
780 DB_RESULT hResult = DBSelect(g_hCoreDB, _T("SELECT id,runtime_flags FROM nodes"));
781 DB_STATEMENT stmtNetObj = DBPrepare(g_hCoreDB, _T("UPDATE object_properties SET flags=?, state=? WHERE object_id=?"));
782 DB_STATEMENT stmtNode = DBPrepare(g_hCoreDB, _T("UPDATE nodes SET capabilities=? WHERE id=?"));
783 if (hResult != NULL)
784 {
785 if (stmtNetObj != NULL && stmtNode != NULL)
786 {
787 int nRows = DBGetNumRows(hResult);
788 for(int i = 0; i < nRows; i++)
789 {
790 UINT32 id = DBGetFieldULong(hResult, i, 0);
791 UINT32 oldFlags = 0;
792 UINT32 oldRuntime = DBGetFieldULong(hResult, i, 1);
793 UINT32 flags = 0;
794 UINT32 state = 0;
795 UINT32 capabilities = 0;
796 TCHAR query[256];
797 _sntprintf(query, 256, _T("SELECT node_flags FROM nodes WHERE id=%d"), id);
798 DB_RESULT flagResult = DBSelect(g_hCoreDB, query);
799 if(DBGetNumRows(flagResult) >= 1)
800 {
801 oldFlags = DBGetFieldULong(flagResult, i, 0);
802 }
803 else
804 {
805 if(!g_bIgnoreErrors)
806 {
807 DBFreeStatement(stmtNetObj);
808 DBFreeStatement(stmtNode);
809 DBFreeResult(hResult);
810 return FALSE;
811 }
812 }
813 MoveNodeFlags(oldFlags, &flags);
814 MoveNodeCapabilities(oldFlags, &capabilities);
815 MoveNodeState(oldRuntime, &state);
816
817 DBBind(stmtNetObj, 1, DB_SQLTYPE_INTEGER, flags);
818 DBBind(stmtNetObj, 2, DB_SQLTYPE_INTEGER, state);
819 DBBind(stmtNetObj, 3, DB_SQLTYPE_INTEGER, id);
820
821 DBBind(stmtNode, 1, DB_SQLTYPE_INTEGER, capabilities);
822 DBBind(stmtNode, 2, DB_SQLTYPE_INTEGER, id);
823
824 if (!(SQLExecute(stmtNetObj)))
825 {
826 if (!g_bIgnoreErrors)
827 {
828 DBFreeStatement(stmtNetObj);
829 DBFreeStatement(stmtNode);
830 DBFreeResult(hResult);
831 return FALSE;
832 }
833 }
834
835 if (!SQLExecute(stmtNode))
836 {
837 if (!g_bIgnoreErrors)
838 {
839 DBFreeStatement(stmtNetObj);
840 DBFreeStatement(stmtNode);
841 DBFreeResult(hResult);
842 return FALSE;
843 }
844 }
845 }
846 DBFreeStatement(stmtNetObj);
847 DBFreeStatement(stmtNode);
848 }
849 else
850 {
851 if(stmtNetObj != NULL)
852 DBFreeStatement(stmtNetObj);
853
854 if(stmtNode != NULL)
855 DBFreeStatement(stmtNode);
856 if (!g_bIgnoreErrors)
857 {
858 return FALSE;
859 }
860 }
861 DBFreeResult(hResult);
862 }
863 CHK_EXEC(DBDropColumn(g_hCoreDB, _T("nodes"), _T("runtime_flags")));
864 CHK_EXEC(DBDropColumn(g_hCoreDB, _T("nodes"), _T("node_flags")));
865
866 //sensor
867 hResult = DBSelect(g_hCoreDB, _T("SELECT id,runtime_flags,flags FROM sensors"));
868 DB_STATEMENT stmt = DBPrepare(g_hCoreDB, _T("UPDATE object_properties SET status=? WHERE object_id=?"));
869 if (hResult != NULL)
870 {
871 if (stmt != NULL)
872 {
873 int nRows = DBGetNumRows(hResult);
874 for(int i = 0; i < nRows; i++)
875 {
876 UINT32 status = 0;
877 MoveSensorState(DBGetFieldULong(hResult, i, 2), DBGetFieldULong(hResult, i, 1), &status);
878
879 DBBind(stmt, 1, DB_SQLTYPE_INTEGER, status);
880 DBBind(stmt, 2, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 0));
881
882 if (!(SQLExecute(stmt)))
883 {
884 if (!g_bIgnoreErrors)
885 {
886 DBFreeStatement(stmt);
887 DBFreeResult(hResult);
888 return FALSE;
889 }
890 }
891 }
892 DBFreeStatement(stmt);
893 }
894 else if (!g_bIgnoreErrors)
895 {
896 return FALSE;
897 }
898 DBFreeResult(hResult);
899 }
900 CHK_EXEC(DBDropColumn(g_hCoreDB, _T("sensors"), _T("runtime_flags")));
901 CHK_EXEC(DBDropColumn(g_hCoreDB, _T("sensors"), _T("flags")));
902
903 CHK_EXEC(SetSchemaVersion(503));
904 return TRUE;
905 }
906
907 /**
908 * Upgrade from V501 to V502
909 */
910 static BOOL H_UpgradeFromV501(int currVersion, int newVersion)
911 {
912 CHK_EXEC(DBDropColumn(g_hCoreDB, _T("event_groups"), _T("range_start")));
913 CHK_EXEC(DBDropColumn(g_hCoreDB, _T("event_groups"), _T("range_end")));
914
915 static const TCHAR *batch =
916 _T("ALTER TABLE event_groups ADD guid varchar(36) null\n")
917 _T("UPDATE event_groups SET guid='04b326c0-5cc0-411f-8587-2836cb87c920' WHERE id=-2147483647\n")
918 _T("UPDATE event_groups SET guid='b61859c6-1768-4a61-a0cf-eed07d688f66' WHERE id=-2147483646\n")
919 _T("<END>");
920 CHK_EXEC(SQLBatch(batch));
921 DBSetNotNullConstraint(g_hCoreDB, _T("event_groups"), _T("guid"));
922
923 CHK_EXEC(SetSchemaVersion(502));
924 return TRUE;
925 }
926
927 /**
928 * Upgrade from V500 to V501
929 */
930 static BOOL H_UpgradeFromV500(int currVersion, int newVersion)
931 {
932 static const TCHAR *batch =
933 _T("ALTER TABLE users ADD created integer null\n")
934 _T("ALTER TABLE user_groups ADD created integer null\n")
935 _T("UPDATE users SET created=0\n")
936 _T("UPDATE user_groups SET created=0\n")
937 _T("<END>");
938 CHK_EXEC(SQLBatch(batch));
939 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("users"), _T("created")));
940 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("user_groups"), _T("created")));
941
942 CHK_EXEC(SetSchemaVersion(501));
943 return TRUE;
944 }
945
946 /**
947 * Upgrade from V459 to V500
948 */
949 static BOOL H_UpgradeFromV459(int currVersion, int newVersion)
950 {
951 CHK_EXEC(CreateTable(
952 _T("CREATE TABLE sensors (")
953 _T(" id integer not null,")
954 _T(" proxy_node integer not null,")
955 _T(" flags integer not null,")
956 _T(" mac_address varchar(16) null,")
957 _T(" device_class integer not null,")
958 _T(" vendor varchar(128) null,")
959 _T(" communication_protocol integer not null,")
960 _T(" xml_config varchar(4000) null,")
961 _T(" xml_reg_config varchar(4000) null,")
962 _T(" serial_number varchar(256) null,")
963 _T(" device_address varchar(256) null,")
964 _T(" meta_type varchar(256) null,")
965 _T(" description varchar(512) null,")
966 _T(" last_connection_time integer not null,")
967 _T(" frame_count integer not null,")
968 _T(" signal_strenght integer not null,")
969 _T(" signal_noise integer not null,")
970 _T(" frequency integer not null,")
971 _T(" runtime_flags integer null,")
972 _T("PRIMARY KEY(id))")));
973
974 CHK_EXEC(SetSchemaVersion(500));
975 return TRUE;
976 }
977
978 /**
979 * Upgrade from V458 to V459
980 */
981 static BOOL H_UpgradeFromV458(int currVersion, int newVersion)
982 {
983 CHK_EXEC(SQLQuery(_T("ALTER TABLE dci_summary_tables ADD table_dci_name varchar(255)")));
984 CHK_EXEC(SetSchemaVersion(459));
985 return TRUE;
986 }
987
988 /**
989 * Upgrade from V457 to V458
990 */
991 static BOOL H_UpgradeFromV457(int currVersion, int newVersion)
992 {
993 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',need_server_restart=0 WHERE var_name='DeleteUnreachableNodesPeriod'")));
994 CHK_EXEC(CreateConfigParam(_T("LongRunningQueryThreshold"), _T("0"), _T("Threshold in milliseconds to report long running SQL queries (0 to disable)"), 'I', true, true, false, false));
995 CHK_EXEC(SetSchemaVersion(458));
996 return TRUE;
997 }
998
999 /**
1000 * Upgrade from V456 to V457
1001 */
1002 static BOOL H_UpgradeFromV456(int currVersion, int newVersion)
1003 {
1004 CHK_EXEC(SQLQuery(_T("DELETE FROM config WHERE var_name='EnableAdminInterface'")));
1005 CHK_EXEC(SetSchemaVersion(457));
1006 return TRUE;
1007 }
1008
1009 /**
1010 * Upgrade from V455 to V456
1011 */
1012 static BOOL H_UpgradeFromV455(int currVersion, int newVersion)
1013 {
1014 CHK_EXEC(
1015 CreateEventTemplate(EVENT_PACKAGE_INSTALLED, _T("SYS_PACKAGE_INSTALLED"),
1016 SEVERITY_NORMAL, EF_LOG, _T("92e5cf98-a415-4414-9ad8-d155dac77e96"),
1017 _T("Package %1 %2 installed"),
1018 _T("Generated when new software package is found.\r\n")
1019 _T("Parameters:\r\n")
1020 _T(" 1) Package name\r\n")
1021 _T(" 2) Package version"))
1022 );
1023
1024 CHK_EXEC(
1025 CreateEventTemplate(EVENT_PACKAGE_UPDATED, _T("SYS_PACKAGE_UPDATED"),
1026 SEVERITY_NORMAL, EF_LOG, _T("9d5878c1-525e-4cab-8f02-2a6c46d7fc36"),
1027 _T("Package %1 updated from %3 to %2"),
1028 _T("Generated when software package version change is detected.\r\n")
1029 _T("Parameters:\r\n")
1030 _T(" 1) Package name\r\n")
1031 _T(" 2) New package version\r\n")
1032 _T(" 3) Old package version"))
1033 );
1034
1035 CHK_EXEC(
1036 CreateEventTemplate(EVENT_PACKAGE_REMOVED, _T("SYS_PACKAGE_REMOVED"),
1037 SEVERITY_NORMAL, EF_LOG, _T("6ada4ea4-43e4-4444-9d19-ef7366110bb9"),
1038 _T("Package %1 %2 removed"),
1039 _T("Generated when software package removal is detected.\r\n")
1040 _T("Parameters:\r\n")
1041 _T(" 1) Package name\r\n")
1042 _T(" 2) Last known package version"))
1043 );
1044
1045 int ruleId = NextFreeEPPruleID();
1046 TCHAR query[1024];
1047 _sntprintf(query, 1024, _T("INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event) ")
1048 _T("VALUES (%d,'2bb3df47-482b-4e4b-9b49-8c72c6b33011',7944,'Generate alarm on software package changes','%%m',5,'SW_PKG_%%i_%%<name>','',0,%d)"),
1049 ruleId, EVENT_ALARM_TIMEOUT);
1050 CHK_EXEC(SQLQuery(query));
1051
1052 _sntprintf(query, 256, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_PACKAGE_INSTALLED);
1053 CHK_EXEC(SQLQuery(query));
1054 _sntprintf(query, 256, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_PACKAGE_UPDATED);
1055 CHK_EXEC(SQLQuery(query));
1056 _sntprintf(query, 256, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_PACKAGE_REMOVED);
1057 CHK_EXEC(SQLQuery(query));
1058
1059 CHK_EXEC(SetSchemaVersion(456));
1060 return TRUE;
1061 }
1062
1063 /**
1064 * Upgrade from V454 to V455
1065 */
1066 static BOOL H_UpgradeFromV454(int currVersion, int newVersion)
1067 {
1068 static const TCHAR *batch =
1069 _T("ALTER TABLE interfaces ADD parent_iface integer\n")
1070 _T("UPDATE interfaces SET parent_iface=0\n")
1071 _T("<END>");
1072 CHK_EXEC(SQLBatch(batch));
1073 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("interfaces"), _T("parent_iface")));
1074
1075 CHK_EXEC(SetSchemaVersion(455));
1076 return TRUE;
1077 }
1078
1079 /**
1080 * Upgrade from V453 to V454
1081 */
1082 static BOOL H_UpgradeFromV453(int currVersion, int newVersion)
1083 {
1084 static const TCHAR *batch =
1085 _T("ALTER TABLE config ADD default_value varchar(2000) null\n")
1086 _T("UPDATE config SET default_value='7200' WHERE var_name='ActiveDiscoveryInterval'\n")
1087 _T("UPDATE config SET default_value='0' WHERE var_name='ActiveNetworkDiscovery'\n")
1088 _T("UPDATE config SET default_value='4000' WHERE var_name='AgentCommandTimeout'\n")
1089 _T("UPDATE config SET default_value='netxms' WHERE var_name='AgentDefaultSharedSecret'\n")
1090 _T("UPDATE config SET default_value='600' WHERE var_name='AgentUpgradeWaitTime'\n")
1091 _T("UPDATE config SET default_value='180' WHERE var_name='AlarmHistoryRetentionTime'\n")
1092 _T("UPDATE config SET default_value='4096' WHERE var_name='AlarmListDisplayLimit'\n")
1093 _T("UPDATE config SET default_value='0 0 * * *' WHERE var_name='AlarmSummaryEmailSchedule'\n")
1094 _T("UPDATE config SET default_value='0' WHERE var_name='AllowDirectSMS'\n")
1095 _T("UPDATE config SET default_value='63' WHERE var_name='AllowedCiphers'\n")
1096 _T("UPDATE config SET default_value='1' WHERE var_name='AllowTrapVarbindsConversion'\n")
1097 _T("UPDATE config SET default_value='0' WHERE var_name='AnonymousFileAccess'\n")
1098 _T("UPDATE config SET default_value='1' WHERE var_name='ApplyDCIFromTemplateToDisabledDCI'\n")
1099 _T("UPDATE config SET default_value='90' WHERE var_name='AuditLogRetentionTime'\n")
1100 _T("UPDATE config SET default_value='1000' WHERE var_name='BeaconPollingInterval'\n")
1101 _T("UPDATE config SET default_value='1000' WHERE var_name='BeaconTimeout'\n")
1102 _T("UPDATE config SET default_value='0' WHERE var_name='BlockInactiveUserAccounts'\n")
1103 _T("UPDATE config SET default_value='604800' WHERE var_name='CapabilityExpirationTime'\n")
1104 _T("UPDATE config SET default_value='0' WHERE var_name='CaseInsensitiveLoginNames'\n")
1105 _T("UPDATE config SET default_value='0' WHERE var_name='CheckTrustedNodes'\n")
1106 _T("UPDATE config SET default_value='4701' WHERE var_name='ClientListenerPort'\n")
1107 _T("UPDATE config SET default_value='0' WHERE var_name='ClusterContainerAutoBind'\n")
1108 _T("UPDATE config SET default_value='0' WHERE var_name='ClusterTemplateAutoApply'\n")
1109 _T("UPDATE config SET default_value='60' WHERE var_name='ConditionPollingInterval'\n")
1110 _T("UPDATE config SET default_value='3600' WHERE var_name='ConfigurationPollingInterval'\n")
1111 _T("UPDATE config SET default_value='1' WHERE var_name='DashboardDataExportEnableInterpolation'\n")
1112 _T("UPDATE config SET default_value='10' WHERE var_name='DBConnectionPoolBaseSize'\n")
1113 _T("UPDATE config SET default_value='300' WHERE var_name='DBConnectionPoolCooldownTime'\n")
1114 _T("UPDATE config SET default_value='14400' WHERE var_name='DBConnectionPoolMaxLifetime'\n")
1115 _T("UPDATE config SET default_value='30' WHERE var_name='DBConnectionPoolMaxSize'\n")
1116 _T("UPDATE config SET default_value='0' WHERE var_name='DBLockPID'\n")
1117 _T("UPDATE config SET default_value='UNLOCKED' WHERE var_name='DBLockStatus'\n")
1118 _T("UPDATE config SET default_value='2' WHERE var_name='DefaultAgentCacheMode'\n")
1119 _T("UPDATE config SET default_value='1' WHERE var_name='DefaultAgentProtocolCompressionMode'\n")
1120 _T("UPDATE config SET default_value='dd.MM.yyyy' WHERE var_name='DefaultConsoleDateFormat'\n")
1121 _T("UPDATE config SET default_value='HH:mm' WHERE var_name='DefaultConsoleShortTimeFormat'\n")
1122 _T("UPDATE config SET default_value='HH:mm:ss' WHERE var_name='DefaultConsoleTimeFormat'\n")
1123 _T("UPDATE config SET default_value='60' WHERE var_name='DefaultDCIPollingInterval'\n")
1124 _T("UPDATE config SET default_value='30' WHERE var_name='DefaultDCIRetentionTime'\n")
1125 _T("UPDATE config SET default_value='1' WHERE var_name='DefaultEncryptionPolicy'\n")
1126 _T("UPDATE config SET default_value='1' WHERE var_name='DefaultInterfaceExpectedState'\n")
1127 _T("UPDATE config SET default_value='0xffffff' WHERE var_name='DefaultMapBackgroundColor'\n")
1128 _T("UPDATE config SET default_value='24' WHERE var_name='DefaultSubnetMaskIPv4'\n")
1129 _T("UPDATE config SET default_value='64' WHERE var_name='DefaultSubnetMaskIPv6'\n")
1130 _T("UPDATE config SET default_value='1' WHERE var_name='DeleteAlarmsOfDeletedObject'\n")
1131 _T("UPDATE config SET default_value='0' WHERE var_name='DeleteEmptySubnets'\n")
1132 _T("UPDATE config SET default_value='1' WHERE var_name='DeleteEventsOfDeletedObject'\n")
1133 _T("UPDATE config SET default_value='0' WHERE var_name='DeleteUnreachableNodesPeriod'\n")
1134 _T("UPDATE config SET default_value='none' WHERE var_name='DiscoveryFilter'\n")
1135 _T("UPDATE config SET default_value='0' WHERE var_name='DiscoveryFilterFlags'\n")
1136 _T("UPDATE config SET default_value='900' WHERE var_name='DiscoveryPollingInterval'\n")
1137 _T("UPDATE config SET default_value='1' WHERE var_name='EnableAdminInterface'\n")
1138 _T("UPDATE config SET default_value='1' WHERE var_name='EnableAgentRegistration'\n")
1139 _T("UPDATE config SET default_value='1' WHERE var_name='EnableAuditLog'\n")
1140 _T("UPDATE config SET default_value='0' WHERE var_name='EnableCheckPointSNMP'\n")
1141 _T("UPDATE config SET default_value='0' WHERE var_name='EnableReportingServer'\n")
1142 _T("UPDATE config SET default_value='0' WHERE var_name='EnableEventStormDetection'\n")
1143 _T("UPDATE config SET default_value='0' WHERE var_name='EnableISCListener'\n")
1144 _T("UPDATE config SET default_value='1' WHERE var_name='EnableNXSLContainerFunctions'\n")
1145 _T("UPDATE config SET default_value='0' WHERE var_name='EnableObjectTransactions'\n")
1146 _T("UPDATE config SET default_value='1' WHERE var_name='EnableSNMPTraps'\n")
1147 _T("UPDATE config SET default_value='0' WHERE var_name='EnableAlarmSummaryEmails'\n")
1148 _T("UPDATE config SET default_value='0' WHERE var_name='EnableSyslogReceiver'\n")
1149 _T("UPDATE config SET default_value='1' WHERE var_name='EnableTimedAlarmAck'\n")
1150 _T("UPDATE config SET default_value='0' WHERE var_name='EnableXMPPConnector'\n")
1151 _T("UPDATE config SET default_value='0' WHERE var_name='EnableZoning'\n")
1152 _T("UPDATE config SET default_value='0' WHERE var_name='EscapeLocalCommands'\n")
1153 _T("UPDATE config SET default_value='90' WHERE var_name='EventLogRetentionTime'\n")
1154 _T("UPDATE config SET default_value='15' WHERE var_name='EventStormDuration'\n")
1155 _T("UPDATE config SET default_value='100' WHERE var_name='EventStormEventsPerSecond'\n")
1156 _T("UPDATE config SET default_value='0' WHERE var_name='ExtendedLogQueryAccessControl'\n")
1157 _T("UPDATE config SET default_value='13' WHERE var_name='ExternalAuditFacility'\n")
1158 _T("UPDATE config SET default_value='514' WHERE var_name='ExternalAuditPort'\n")
1159 _T("UPDATE config SET default_value='none' WHERE var_name='ExternalAuditServer'\n")
1160 _T("UPDATE config SET default_value='5' WHERE var_name='ExternalAuditSeverity'\n")
1161 _T("UPDATE config SET default_value='netxmsd-audit' WHERE var_name='ExternalAuditTag'\n")
1162 _T("UPDATE config SET default_value='100' WHERE var_name='FirstFreeObjectId'\n")
1163 _T("UPDATE config SET default_value='0' WHERE var_name='FixedStatusValue'\n")
1164 _T("UPDATE config SET default_value='5' WHERE var_name='GraceLoginCount'\n")
1165 _T("UPDATE config SET default_value='none' WHERE var_name='HelpDeskLink'\n")
1166 _T("UPDATE config SET default_value='02:00' WHERE var_name='HousekeeperStartTime'\n")
1167 _T("UPDATE config SET default_value='46' WHERE var_name='IcmpPingSize'\n")
1168 _T("UPDATE config SET default_value='1500' WHERE var_name='IcmpPingTimeout'\n")
1169 _T("UPDATE config SET default_value='1' WHERE var_name='ImportConfigurationOnStartup'\n")
1170 _T("UPDATE config SET default_value='600' WHERE var_name='InstancePollingInterval'\n")
1171 _T("UPDATE config SET default_value='0' WHERE var_name='InternalCA'\n")
1172 _T("UPDATE config SET default_value='0' WHERE var_name='IntruderLockoutThreshold'\n")
1173 _T("UPDATE config SET default_value='30' WHERE var_name='IntruderLockoutTime'\n")
1174 _T("UPDATE config SET default_value='Task' WHERE var_name='JiraIssueType'\n")
1175 _T("UPDATE config SET default_value='netxms' WHERE var_name='JiraLogin'\n")
1176 _T("UPDATE config SET default_value='NETXMS' WHERE var_name='JiraProjectCode'\n")
1177 _T("UPDATE config SET default_value='http://localhost' WHERE var_name='JiraServerURL'\n")
1178 _T("UPDATE config SET default_value='90' WHERE var_name='JobHistoryRetentionTime'\n")
1179 _T("UPDATE config SET default_value='5' WHERE var_name='JobRetryCount'\n")
1180 _T("UPDATE config SET default_value='60' WHERE var_name='KeepAliveInterval'\n")
1181 _T("UPDATE config SET default_value='ldap://localhost:389' WHERE var_name='LdapConnectionString'\n")
1182 _T("UPDATE config SET default_value='displayName' WHERE var_name='LdapMappingFullName'\n")
1183 _T("UPDATE config SET default_value='1000' WHERE var_name='LdapPageSize'\n")
1184 _T("UPDATE config SET default_value='0' WHERE var_name='LdapSyncInterval'\n")
1185 _T("UPDATE config SET default_value='1' WHERE var_name='LdapUserDeleteAction'\n")
1186 _T("UPDATE config SET default_value='60000' WHERE var_name='LockTimeout'\n")
1187 _T("UPDATE config SET default_value='0' WHERE var_name='LogAllSNMPTraps'\n")
1188 _T("UPDATE config SET default_value='utf8' WHERE var_name='MailEncoding'\n")
1189 _T("UPDATE config SET default_value='0' WHERE var_name='MinPasswordLength'\n")
1190 _T("UPDATE config SET default_value='1000' WHERE var_name='MinViewRefreshInterval'\n")
1191 _T("UPDATE config SET default_value='4747' WHERE var_name='MobileDeviceListenerPort'\n")
1192 _T("UPDATE config SET default_value='25' WHERE var_name='NumberOfDataCollectors'\n")
1193 _T("UPDATE config SET default_value='10' WHERE var_name='NumberOfUpgradeThreads'\n")
1194 _T("UPDATE config SET default_value='86400' WHERE var_name='OfflineDataRelevanceTime'\n")
1195 _T("UPDATE config SET default_value='0' WHERE var_name='PasswordComplexity'\n")
1196 _T("UPDATE config SET default_value='0' WHERE var_name='PasswordExpiration'\n")
1197 _T("UPDATE config SET default_value='0' WHERE var_name='PasswordHistoryLength'\n")
1198 _T("UPDATE config SET default_value='1' WHERE var_name='PollCountForStatusChange'\n")
1199 _T("UPDATE config SET default_value='10' WHERE var_name='PollerThreadPoolBaseSize'\n")
1200 _T("UPDATE config SET default_value='250' WHERE var_name='PollerThreadPoolMaxSize'\n")
1201 _T("UPDATE config SET default_value='PAP' WHERE var_name='RADIUSAuthMethod'\n")
1202 _T("UPDATE config SET default_value='5' WHERE var_name='RADIUSNumRetries'\n")
1203 _T("UPDATE config SET default_value='1645' WHERE var_name='RADIUSPort'\n")
1204 _T("UPDATE config SET default_value='1645' WHERE var_name='RADIUSSecondaryPort'\n")
1205 _T("UPDATE config SET default_value='netxms' WHERE var_name='RADIUSSecondarySecret'\n")
1206 _T("UPDATE config SET default_value='none' WHERE var_name='RADIUSSecondaryServer'\n")
1207 _T("UPDATE config SET default_value='netxms' WHERE var_name='RADIUSSecret'\n")
1208 _T("UPDATE config SET default_value='none' WHERE var_name='RADIUSServer'\n")
1209 _T("UPDATE config SET default_value='3' WHERE var_name='RADIUSTimeout'\n")
1210 _T("UPDATE config SET default_value='0' WHERE var_name='ReceiveForwardedEvents'\n")
1211 _T("UPDATE config SET default_value='localhost' WHERE var_name='ReportingServerHostname'\n")
1212 _T("UPDATE config SET default_value='4710' WHERE var_name='ReportingServerPort'\n")
1213 _T("UPDATE config SET default_value='0' WHERE var_name='ResolveDNSToIPOnStatusPoll'\n")
1214 _T("UPDATE config SET default_value='1' WHERE var_name='ResolveNodeNames'\n")
1215 _T("UPDATE config SET default_value='300' WHERE var_name='RoutingTableUpdateInterval'\n")
1216 _T("UPDATE config SET default_value='0' WHERE var_name='RunNetworkDiscovery'\n")
1217 _T("UPDATE config SET default_value='60' WHERE var_name='ServerCommandOutputTimeout'\n")
1218 _T("UPDATE config SET default_value='<none>' WHERE var_name='SMSDriver'\n")
1219 _T("UPDATE config SET default_value='161' WHERE var_name='SNMPPorts'\n")
1220 _T("UPDATE config SET default_value='1500' WHERE var_name='SNMPRequestTimeout'\n")
1221 _T("UPDATE config SET default_value='90' WHERE var_name='SNMPTrapLogRetentionTime'\n")
1222 _T("UPDATE config SET default_value='162' WHERE var_name='SNMPTrapPort'\n")
1223 _T("UPDATE config SET default_value='netxms@localhost' WHERE var_name='SMTPFromAddr'\n")
1224 _T("UPDATE config SET default_value='NetXMS Server' WHERE var_name='SMTPFromName'\n")
1225 _T("UPDATE config SET default_value='25' WHERE var_name='SMTPPort'\n")
1226 _T("UPDATE config SET default_value='1' WHERE var_name='SMTPRetryCount'\n")
1227 _T("UPDATE config SET default_value='localhost' WHERE var_name='SMTPServer'\n")
1228 _T("UPDATE config SET default_value='1' WHERE var_name='StatusCalculationAlgorithm'\n")
1229 _T("UPDATE config SET default_value='60' WHERE var_name='StatusPollingInterval'\n")
1230 _T("UPDATE config SET default_value='1' WHERE var_name='StatusPropagationAlgorithm'\n")
1231 _T("UPDATE config SET default_value='0' WHERE var_name='StatusShift'\n")
1232 _T("UPDATE config SET default_value='75' WHERE var_name='StatusSingleThreshold'\n")
1233 _T("UPDATE config SET default_value='503C2814' WHERE var_name='StatusThresholds'\n")
1234 _T("UPDATE config SET default_value='01020304' WHERE var_name='StatusTranslation'\n")
1235 _T("UPDATE config SET default_value='0' WHERE var_name='StrictAlarmStatusFlow'\n")
1236 _T("UPDATE config SET default_value='60' WHERE var_name='SyncInterval'\n")
1237 _T("UPDATE config SET default_value='0' WHERE var_name='SyncNodeNamesWithDNS'\n")
1238 _T("UPDATE config SET default_value='0' WHERE var_name='SyslogIgnoreMessageTimestamp'\n")
1239 _T("UPDATE config SET default_value='514' WHERE var_name='SyslogListenPort'\n")
1240 _T("UPDATE config SET default_value='0' WHERE var_name='SyslogNodeMatchingPolicy'\n")
1241 _T("UPDATE config SET default_value='90' WHERE var_name='SyslogRetentionTime'\n")
1242 _T("UPDATE config SET default_value='0' WHERE var_name='ThresholdRepeatInterval'\n")
1243 _T("UPDATE config SET default_value='http://tile.openstreetmap.org/' WHERE var_name='TileServerURL'\n")
1244 _T("UPDATE config SET default_value='3' WHERE var_name='TopologyDiscoveryRadius'\n")
1245 _T("UPDATE config SET default_value='900' WHERE var_name='TopologyExpirationTime'\n")
1246 _T("UPDATE config SET default_value='1800' WHERE var_name='TopologyPollingInterval'\n")
1247 _T("UPDATE config SET default_value='0' WHERE var_name='TrapSourcesInAllZones'\n")
1248 _T("UPDATE config SET default_value='0' WHERE var_name='UseDNSNameForDiscoveredNodes'\n")
1249 _T("UPDATE config SET default_value='1' WHERE var_name='UseFQDNForNodeNames'\n")
1250 _T("UPDATE config SET default_value='1' WHERE var_name='UseIfXTable'\n")
1251 _T("UPDATE config SET default_value='0' WHERE var_name='UseInterfaceAliases'\n")
1252 _T("UPDATE config SET default_value='0' WHERE var_name='UseSNMPTrapsForDiscovery'\n")
1253 _T("UPDATE config SET default_value='0' WHERE var_name='UseSyslogForDiscovery'\n")
1254 _T("UPDATE config SET default_value='netxms@localhost' WHERE var_name='XMPPLogin'\n")
1255 _T("UPDATE config SET default_value='netxms' WHERE var_name='XMPPPassword'\n")
1256 _T("UPDATE config SET default_value='5222' WHERE var_name='XMPPPort'\n")
1257 _T("UPDATE config SET default_value='localhost' WHERE var_name='XMPPServer'\n")
1258 _T("<END>");
1259 CHK_EXEC(SQLBatch(batch));
1260
1261 CHK_EXEC(SetSchemaVersion(454));
1262 return TRUE;
1263 }
1264
1265 /**
1266 * Upgrade from V452 to V453
1267 */
1268 static BOOL H_UpgradeFromV452(int currVersion, int newVersion)
1269 {
1270 static const TCHAR *batch =
1271 _T("ALTER TABLE audit_log ADD value_diff $SQL:TEXT\n")
1272 _T("<END>");
1273 CHK_EXEC(SQLBatch(batch));
1274 CHK_EXEC(SetSchemaVersion(453));
1275 return TRUE;
1276 }
1277
1278 /**
1279 * Upgrade from V451 to V452
1280 */
1281 static BOOL H_UpgradeFromV451(int currVersion, int newVersion)
1282 {
1283 static const TCHAR *batch =
1284 _T("ALTER TABLE audit_log ADD old_value $SQL:TEXT\n")
1285 _T("ALTER TABLE audit_log ADD new_value $SQL:TEXT\n")
1286 _T("<END>");
1287 CHK_EXEC(SQLBatch(batch));
1288 CHK_EXEC(SetSchemaVersion(452));
1289 return TRUE;
1290 }
1291
1292 /**
1293 * Upgrade from V450 to V451
1294 */
1295 static BOOL H_UpgradeFromV450(int currVersion, int newVersion)
1296 {
1297 CHK_EXEC(CreateTable(
1298 _T("CREATE TABLE object_access_snapshot (")
1299 _T(" user_id integer not null,")
1300 _T(" object_id integer not null,")
1301 _T(" access_rights integer not null,")
1302 _T("PRIMARY KEY(user_id,object_id))")));
1303
1304 CHK_EXEC(SetSchemaVersion(451));
1305 return TRUE;
1306 }
1307
1308 /**
1309 * Upgrade from V449 to V450
1310 */
1311 static BOOL H_UpgradeFromV449(int currVersion, int newVersion)
1312 {
1313 static const TCHAR *batch =
1314 _T("ALTER TABLE dct_thresholds ADD sample_count integer\n")
1315 _T("UPDATE dct_thresholds SET sample_count=1\n")
1316 _T("<END>");
1317 CHK_EXEC(SQLBatch(batch));
1318 DBSetNotNullConstraint(g_hCoreDB, _T("dct_thresholds"), _T("sample_count"));
1319
1320 CHK_EXEC(CreateTable(
1321 _T("CREATE TABLE dct_threshold_instances (")
1322 _T(" threshold_id integer not null,")
1323 _T(" instance varchar(255) not null,")
1324 _T(" match_count integer not null,")
1325 _T(" is_active char(1) not null,")
1326 _T("PRIMARY KEY(threshold_id,instance))")));
1327
1328 CHK_EXEC(SetSchemaVersion(450));
1329 return TRUE;
1330 }
1331
1332 /**
1333 * Upgrade from V448 to V449
1334 */
1335 static BOOL H_UpgradeFromV448(int currVersion, int newVersion)
1336 {
1337 CHK_EXEC(CreateConfigParam(_T("SMTPPort"), _T("25"), _T("Port used by SMTP server"), 'I', true, false, false, false));
1338 CHK_EXEC(SetSchemaVersion(449));
1339 return TRUE;
1340 }
1341
1342 /**
1343 * Upgrade from V447 to V448
1344 */
1345 static BOOL H_UpgradeFromV447(int currVersion, int newVersion)
1346 {
1347 CHK_EXEC(SQLQuery(_T("ALTER TABLE nodes ADD lldp_id varchar(63)")));
1348 CHK_EXEC(SetSchemaVersion(448));
1349 return TRUE;
1350 }
1351
1352 /**
1353 * Upgrade from V446 to V447
1354 */
1355 static BOOL H_UpgradeFromV446(int currVersion, int newVersion)
1356 {
1357 CHK_EXEC(CreateTable(
1358 _T("CREATE TABLE port_layouts (")
1359 _T(" device_oid varchar(255) not null,")
1360 _T(" numbering_scheme char(1) not null,")
1361 _T(" row_count char(1) not null,")
1362 _T(" layout_data varchar(4000) null,")
1363 _T("PRIMARY KEY(device_oid))")));
1364
1365 CHK_EXEC(SetSchemaVersion(447));
1366 return TRUE;
1367 }
1368
1369 /**
1370 * Upgrade from V445 to V446
1371 */
1372 static BOOL H_UpgradeFromV445(int currVersion, int newVersion)
1373 {
1374 CHK_EXEC(CreateTable(
1375 _T("CREATE TABLE network_map_seed_nodes (")
1376 _T(" map_id integer not null,")
1377 _T(" seed_node_id integer not null,")
1378 _T("PRIMARY KEY(map_id,seed_node_id))")));
1379
1380 DB_RESULT hResult = DBSelect(g_hCoreDB, _T("SELECT id,seed FROM network_maps"));
1381 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("INSERT INTO network_map_seed_nodes (map_id,seed_node_id) VALUES (?,?)"));
1382 if (hResult != NULL)
1383 {
1384 if (hStmt != NULL)
1385 {
1386 int nRows = DBGetNumRows(hResult);
1387 for(int i = 0; i < nRows; i++)
1388 {
1389 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 0));
1390 DBBind(hStmt, 2, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 1));
1391
1392 if (!SQLExecute(hStmt))
1393 {
1394 if (!g_bIgnoreErrors)
1395 {
1396 DBFreeStatement(hStmt);
1397 DBFreeResult(hResult);
1398 return FALSE;
1399 }
1400 }
1401 }
1402
1403 CHK_EXEC(DBDropColumn(g_hCoreDB, _T("network_maps"), _T("seed")));
1404 DBFreeStatement(hStmt);
1405 }
1406 DBFreeResult(hResult);
1407 }
1408
1409 CHK_EXEC(SetSchemaVersion(446));
1410 return TRUE;
1411 }
1412
1413 /**
1414 * Upgrade from V444 to V445
1415 */
1416 static BOOL H_UpgradeFromV444(int currVersion, int newVersion)
1417 {
1418 CHK_EXEC(SQLQuery(_T("ALTER TABLE nodes ADD tunnel_id varchar(36) null")));
1419 CHK_EXEC(SetSchemaVersion(445));
1420 return TRUE;
1421 }
1422
1423 /**
1424 * Upgrade from V443 to V444
1425 */
1426 static BOOL H_UpgradeFromV443(int currVersion, int newVersion)
1427 {
1428 CHK_EXEC(CreateConfigParam(_T("GraceLoginCount"), _T("5"), _T("User's grace login count"), 'I', true, false, false, false));
1429 CHK_EXEC(SetSchemaVersion(444));
1430 return TRUE;
1431 }
1432
1433 /**
1434 * Upgrade from V442 to V443
1435 */
1436 static BOOL H_UpgradeFromV442(int currVersion, int newVersion)
1437 {
1438 static const TCHAR *batch =
1439 _T("ALTER TABLE dc_tables ADD instance varchar(255) null\n")
1440 _T("ALTER TABLE dc_tables ADD instd_method integer null\n")
1441 _T("UPDATE dc_tables SET instd_method=0\n")
1442 _T("ALTER TABLE dc_tables ADD instd_data varchar(255) null\n")
1443 _T("ALTER TABLE dc_tables ADD instd_filter $SQL:TEXT null\n")
1444 _T("<END>");
1445 CHK_EXEC(SQLBatch(batch));
1446 DBSetNotNullConstraint(g_hCoreDB, _T("dc_tables"), _T("instd_method"));
1447 CHK_EXEC(SetSchemaVersion(443));
1448 return TRUE;
1449 }
1450
1451 /**
1452 * Upgrade from V441 to V442
1453 */
1454 static BOOL H_UpgradeFromV441(int currVersion, int newVersion)
1455 {
1456 CHK_EXEC(CreateTable(
1457 _T("CREATE TABLE object_urls (")
1458 _T(" object_id integer not null,")
1459 _T(" url_id integer not null,")
1460 _T(" url varchar(2000) null,")
1461 _T(" description varchar(2000) null,")
1462 _T(" PRIMARY KEY(object_id,url_id))")));
1463 CHK_EXEC(SetSchemaVersion(442));
1464 return TRUE;
1465 }
1466
1467 /**
1468 * Upgrade from V440 to V441
1469 */
1470 static BOOL H_UpgradeFromV440(int currVersion, int newVersion)
1471 {
1472 CHK_EXEC(CreateConfigParam(_T("TopologyPollingInterval"), _T("1800"), _T("Interval in seconds between topology polls"), 'I', true, true, false, false));
1473 CHK_EXEC(SetSchemaVersion(441));
1474 return TRUE;
1475 }
1476
1477 /**
1478 * Upgrade from V439 to V440
1479 */
1480 static BOOL H_UpgradeFromV439(int currVersion, int newVersion)
1481 {
1482 static const TCHAR *batch =
1483 _T("UPDATE config SET description='Enable/disable automatic deletion of subnet objects without any nodes within.' WHERE var_name='DeleteEmptySubnets'\n")
1484 _T("UPDATE config SET description='Instance polling interval (in seconds).' WHERE var_name='InstancePollingInterval'\n")
1485 _T("<END>");
1486 CHK_EXEC(SQLBatch(batch));
1487 CHK_EXEC(SetSchemaVersion(440));
1488 return TRUE;
1489 }
1490
1491 /**
1492 * Upgrade from V438 to V439
1493 */
1494 static BOOL H_UpgradeFromV438(int currVersion, int newVersion)
1495 {
1496 static const TCHAR *batch =
1497 _T("UPDATE config SET data_type='S' WHERE var_name='LdapUserUniqueId'\n")
1498 _T("UPDATE config SET data_type='S' WHERE var_name='LdapGroupUniqueId'\n")
1499 _T("<END>");
1500 CHK_EXEC(SQLBatch(batch));
1501 CHK_EXEC(SetSchemaVersion(439));
1502 return TRUE;
1503 }
1504
1505 /**
1506 * Upgrade from V437 to V438
1507 */
1508 static BOOL H_UpgradeFromV437(int currVersion, int newVersion)
1509 {
1510 static const TCHAR *batch =
1511 _T("ALTER TABLE snmp_trap_cfg ADD guid varchar(36)\n")
1512 _T("UPDATE snmp_trap_cfg SET guid='5d01e7e5-edbb-46ce-b53c-f7f64d1bf8ff' WHERE trap_id=1\n")
1513 _T("UPDATE snmp_trap_cfg SET guid='c5464919-fd76-4624-9c21-b6ab73d9df80' WHERE trap_id=2\n")
1514 _T("UPDATE snmp_trap_cfg SET guid='44d3b32e-33c5-4a39-b2ad-990a1120155d' WHERE trap_id=3\n")
1515 _T("UPDATE snmp_trap_cfg SET guid='c9660f48-a4b3-41c8-b3f9-e9a6a8129db5' WHERE trap_id=4\n")
1516 _T("UPDATE snmp_trap_cfg SET guid='4b422ba6-4b45-4881-931a-ed38dc798f9f' WHERE trap_id=5\n")
1517 _T("UPDATE snmp_trap_cfg SET guid='bd8b6971-a3e4-4cad-9c70-3a33e61e0913' WHERE trap_id=6\n")
1518 _T("ALTER TABLE script_library ADD guid varchar(36)\n")
1519 _T("UPDATE script_library SET guid='3b7bddce-3505-42ff-ac60-6a48a64bd0ae' WHERE script_id=1\n")
1520 _T("UPDATE script_library SET guid='2fb9212b-97e6-40e7-b434-2df4f7e8f6aa' WHERE script_id=2\n")
1521 _T("UPDATE script_library SET guid='38696a00-c519-438c-8cbd-4b3a0cba4af1' WHERE script_id=3\n")
1522 _T("UPDATE script_library SET guid='efe50915-47b2-43d8-b4f4-2c09a44970c3' WHERE script_id=4\n")
1523 _T("UPDATE script_library SET guid='7837580c-4054-40f2-981f-7185797fe7d7' WHERE script_id=11\n")
1524 _T("UPDATE script_library SET guid='f7d1bc7e-4046-4ee4-adb2-718f7361984d' WHERE script_id=12\n")
1525 _T("UPDATE script_library SET guid='048fcf32-765b-4702-9c70-f012f62d5a90' WHERE script_id=13\n")
1526 _T("UPDATE script_library SET guid='d515c10f-a5c9-4f41-afcd-9ddc8845f288' WHERE script_id=14\n")
1527 _T("UPDATE script_library SET guid='7cd1c471-2f14-4fae-8743-8899fed64d18' WHERE script_id=15\n")
1528 _T("UPDATE script_library SET guid='befdb083-ac68-481d-a7b7-127e11c3fae0' WHERE script_id=16\n")
1529 _T("<END>");
1530 CHK_EXEC(SQLBatch(batch));
1531
1532 DB_RESULT hResult = DBSelect(g_hCoreDB, _T("SELECT trap_id FROM snmp_trap_cfg WHERE guid IS NULL"));
1533 if (hResult != NULL)
1534 {
1535 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("UPDATE snmp_trap_cfg SET guid=? WHERE trap_id=?"));
1536 if (hStmt != NULL)
1537 {
1538 int numRows = DBGetNumRows(hResult);
1539 for(int i = 0; i < numRows; i++)
1540 {
1541 uuid guid = uuid::generate();
1542 DBBind(hStmt, 1, DB_SQLTYPE_VARCHAR, guid);
1543 DBBind(hStmt, 2, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 0));
1544
1545 if (!SQLExecute(hStmt))
1546 {
1547 if (!g_bIgnoreErrors)
1548 {
1549 DBFreeStatement(hStmt);
1550 DBFreeResult(hResult);
1551 return FALSE;
1552 }
1553 }
1554 }
1555 DBFreeStatement(hStmt);
1556 }
1557 DBFreeResult(hResult);
1558 }
1559
1560 hResult = DBSelect(g_hCoreDB, _T("SELECT guid,script_id FROM script_library WHERE guid IS NULL"));
1561 if (hResult != NULL)
1562 {
1563 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("UPDATE script_library SET guid=? WHERE script_id=?"));
1564 if (hStmt != NULL)
1565 {
1566 int numRows = DBGetNumRows(hResult);
1567 for(int i = 0; i < numRows; i++)
1568 {
1569 uuid guid = uuid::generate();
1570 DBBind(hStmt, 1, DB_SQLTYPE_VARCHAR, guid);
1571 DBBind(hStmt, 2, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 1));
1572 if (!SQLExecute(hStmt))
1573 {
1574 if (!g_bIgnoreErrors)
1575 {
1576 DBFreeStatement(hStmt);
1577 DBFreeResult(hResult);
1578 return FALSE;
1579 }
1580 }
1581 }
1582 DBFreeStatement(hStmt);
1583 }
1584 DBFreeResult(hResult);
1585 }
1586
1587 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("snmp_trap_cfg"), _T("guid")));
1588 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("script_library"), _T("guid")));
1589 CHK_EXEC(SetSchemaVersion(438));
1590 return TRUE;
1591 }
1592
1593 /**
1594 * Upgrade from V436 to V437
1595 */
1596 static BOOL H_UpgradeFromV436(int currVersion, int newVersion)
1597 {
1598 CHK_EXEC(
1599 CreateEventTemplate(EVENT_ROUTING_LOOP_DETECTED, _T("SYS_ROUTING_LOOP_DETECTED"),
1600 SEVERITY_MAJOR, EF_LOG, _T("98276f42-dc85-41a5-b449-6ba83d1a71b7"),
1601 _T("Routing loop detected for destination %3 (selected route %6/%7 via %9)"),
1602 _T("Generated when server detects routing loop during network path trace.\r\n")
1603 _T("Source of the event is node which routes packet back to already passed hop.\r\n")
1604 _T("Parameters:\r\n")
1605 _T(" 1) Protocol (IPv4 or IPv6)\r\n")
1606 _T(" 2) Path trace destination node ID\r\n")
1607 _T(" 3) Path trace destination address\r\n")
1608 _T(" 4) Path trace source node ID\r\n")
1609 _T(" 5) Path trace source node address\r\n")
1610 _T(" 6) Routing prefix (subnet address)\r\n")
1611 _T(" 7) Routing prefix length (subnet mask length)\r\n")
1612 _T(" 8) Next hop node ID\r\n")
1613 _T(" 9) Next hop address"))
1614 );
1615 CHK_EXEC(SetSchemaVersion(437));
1616 return TRUE;
1617 }
1618
1619 /**
1620 * Upgrade from V435 to V436
1621 */
1622 static BOOL H_UpgradeFromV435(int currVersion, int newVersion)
1623 {
1624 static const TCHAR *batch =
1625 _T("ALTER TABLE nodes ADD agent_comp_mode char(1)\n")
1626 _T("UPDATE nodes SET agent_comp_mode='0'\n")
1627 _T("<END>");
1628 CHK_EXEC(SQLBatch(batch));
1629 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("nodes"), _T("agent_comp_mode")));
1630 CHK_EXEC(SetSchemaVersion(436));
1631 return TRUE;
1632 }
1633
1634 /**
1635 * Upgrade from V434 to V435
1636 */
1637 static BOOL H_UpgradeFromV434(int currVersion, int newVersion)
1638 {
1639 CHK_EXEC(CreateConfigParam(_T("DefaultAgentProtocolCompressionMode"), _T("1"), _T("Default agent protocol compression mode"), 'C', true, false, false, false));
1640 static const TCHAR *batch =
1641 _T("UPDATE config SET data_type='C',description='Default agent cache mode' WHERE var_name='DefaultAgentCacheMode'\n")
1642 _T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultAgentCacheMode','1','On')\n")
1643 _T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultAgentCacheMode','2','Off')\n")
1644 _T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultAgentProtocolCompressionMode','1','Enabled')\n")
1645 _T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultAgentProtocolCompressionMode','2','Disabled')\n")
1646 _T("<END>");
1647 CHK_EXEC(SQLBatch(batch));
1648 CHK_EXEC(SetSchemaVersion(435));
1649 return TRUE;
1650 }
1651
1652 /**
1653 * Upgrade from V433 to V434
1654 */
1655 static BOOL H_UpgradeFromV433(int currVersion, int newVersion)
1656 {
1657 CHK_EXEC(
1658 CreateEventTemplate(EVENT_IF_EXPECTED_STATE_UP, _T("SYS_IF_EXPECTED_STATE_UP"),
1659 SEVERITY_NORMAL, EF_LOG, _T("4997c3f5-b332-4077-8e99-983142f0e193"),
1660 _T("Expected state for interface \"%2\" set to UP"),
1661 _T("Generated when interface expected state set to UP.\r\n")
1662 _T("Please note that source of event is node, not an interface itself.\r\n")
1663 _T("Parameters:\r\n")
1664 _T(" 1) Interface index\r\n")
1665 _T(" 2) Interface name"))
1666 );
1667
1668 CHK_EXEC(
1669 CreateEventTemplate(EVENT_IF_EXPECTED_STATE_DOWN, _T("SYS_IF_EXPECTED_STATE_DOWN"),
1670 SEVERITY_NORMAL, EF_LOG, _T("75de536c-4861-4f19-ba56-c43d814431d7"),
1671 _T("Expected state for interface \"%2\" set to DOWN"),
1672 _T("Generated when interface expected state set to DOWN.\r\n")
1673 _T("Please note that source of event is node, not an interface itself.\r\n")
1674 _T("Parameters:\r\n")
1675 _T(" 1) Interface index\r\n")
1676 _T(" 2) Interface name"))
1677 );
1678
1679 CHK_EXEC(
1680 CreateEventTemplate(EVENT_IF_EXPECTED_STATE_IGNORE, _T("SYS_IF_EXPECTED_STATE_IGNORE"),
1681 SEVERITY_NORMAL, EF_LOG, _T("0e488c0e-3340-4e02-ad96-b999b8392e55"),
1682 _T("Expected state for interface \"%2\" set to IGNORE"),
1683 _T("Generated when interface expected state set to IGNORE.\r\n")
1684 _T("Please note that source of event is node, not an interface itself.\r\n")
1685 _T("Parameters:\r\n")
1686 _T(" 1) Interface index\r\n")
1687 _T(" 2) Interface name"))
1688 );
1689
1690 CHK_EXEC(AddEventToEPPRule(_T("6f46d451-ee66-4563-8747-d129877df24d"), EVENT_IF_EXPECTED_STATE_DOWN));
1691 CHK_EXEC(AddEventToEPPRule(_T("6f46d451-ee66-4563-8747-d129877df24d"), EVENT_IF_EXPECTED_STATE_IGNORE));
1692 CHK_EXEC(AddEventToEPPRule(_T("ecc3fb57-672d-489d-a0ef-4214ea896e0f"), EVENT_IF_EXPECTED_STATE_UP));
1693 CHK_EXEC(AddEventToEPPRule(_T("ecc3fb57-672d-489d-a0ef-4214ea896e0f"), EVENT_IF_EXPECTED_STATE_IGNORE));
1694
1695 CHK_EXEC(SetSchemaVersion(434));
1696 return TRUE;
1697 }
1698
1699 /**
1700 * Upgrade from V432 to V433
1701 */
1702 static BOOL H_UpgradeFromV432(int currVersion, int newVersion)
1703 {
1704 CHK_EXEC(CreateConfigParam(_T("UseSyslogForDiscovery"), _T("0"), _T("Use syslog messages for new node discovery."), 'B', true, false, false, false));
1705 CHK_EXEC(SetSchemaVersion(433));
1706 return TRUE;
1707 }
1708
1709 /**
1710 * Upgrade from V431 to V432
1711 */
1712 static BOOL H_UpgradeFromV431(int currVersion, int newVersion)
1713 {
1714 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_syslog_source ON syslog(source_object_id)")));
1715 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_snmp_trap_log_oid ON snmp_trap_log(object_id)")));
1716 CHK_EXEC(SetSchemaVersion(432));
1717 return TRUE;
1718 }
1719
1720 /**
1721 * Upgrade from V430 to V431
1722 */
1723 static BOOL H_UpgradeFromV430(int currVersion, int newVersion)
1724 {
1725 CHK_EXEC(SQLQuery(_T("DELETE FROM config_values WHERE var_name='SNMPPorts'")));
1726 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Comma separated list of UDP ports used by SNMP capable devices.' WHERE var_name='SNMPPorts'")));
1727 CHK_EXEC(SetSchemaVersion(431));
1728 return TRUE;
1729 }
1730
1731 /**
1732 * Upgrade from V429 to V430
1733 */
1734 static BOOL H_UpgradeFromV429(int currVersion, int newVersion)
1735 {
1736 CHK_EXEC(CreateTable(
1737 _T("CREATE TABLE policy_pstorage_actions (")
1738 _T("rule_id integer not null,")
1739 _T("ps_key varchar(255) not null,")
1740 _T("value varchar(2000) null,")
1741 _T("action integer not null,")
1742 _T("PRIMARY KEY(rule_id,ps_key,action))")));
1743
1744 CHK_EXEC(CreateTable(
1745 _T("CREATE TABLE persistent_storage (")
1746 _T("entry_key varchar(255) not null,")
1747 _T("value varchar(2000) null,")
1748 _T("PRIMARY KEY(entry_key))")));
1749
1750 //Move previous attrs form situations to pstorage
1751 DB_RESULT hResult = SQLSelect(_T("SELECT event_policy.rule_id,situations.name,event_policy.situation_instance,")
1752 _T("policy_situation_attr_list.attr_name,policy_situation_attr_list.attr_value ")
1753 _T("FROM event_policy,situations,policy_situation_attr_list ")
1754 _T("WHERE event_policy.rule_id=policy_situation_attr_list.rule_id ")
1755 _T("AND situations.id=policy_situation_attr_list.situation_id"));
1756 if (hResult != NULL)
1757 {
1758 int count = DBGetNumRows(hResult);
1759 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("INSERT INTO policy_pstorage_actions (rule_id,ps_key,value,action) VALUES (?,?,?,1)"));
1760 if (hStmt != NULL)
1761 {
1762 String key;
1763 for(int i = 0; i < count; i++)
1764 {
1765 TCHAR tmp[256];
1766 DBGetField(hResult, i, 1, tmp, 256);
1767 key.append(tmp);
1768 DBGetField(hResult, i, 2, tmp, 256);
1769 key.append(_T("."));
1770 key.append(tmp);
1771 DBGetField(hResult, i, 3, tmp, 256);
1772 key.append(_T("."));
1773 key.append(tmp);
1774 DBGetField(hResult, i, 4, tmp, 256);
1775
1776 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, DBGetFieldLong(hResult, i, 0));
1777 DBBind(hStmt, 2, DB_SQLTYPE_TEXT, key, DB_BIND_STATIC, 512);
1778 DBBind(hStmt, 3, DB_SQLTYPE_TEXT, tmp, DB_BIND_STATIC);
1779 if (!SQLExecute(hStmt))
1780 {
1781 if (!g_bIgnoreErrors)
1782 {
1783 DBFreeStatement(hStmt);
1784 DBFreeResult(hResult);
1785 return FALSE;
1786 }
1787 }
1788 key.clear();
1789 }
1790 DBFreeStatement(hStmt);
1791 }
1792 else if (!g_bIgnoreErrors)
1793 {
1794 DBFreeStatement(hStmt);
1795 DBFreeResult(hResult);
1796 return FALSE;
1797 }
1798 DBFreeResult(hResult);
1799 }
1800 else
1801 {
1802 if (!g_bIgnoreErrors)
1803 return false;
1804 }
1805
1806 CHK_EXEC(SQLQuery(_T("DROP TABLE situations")));
1807 CHK_EXEC(SQLQuery(_T("DROP TABLE policy_situation_attr_list")));
1808 CHK_EXEC(DBDropColumn(g_hCoreDB, _T("event_policy"), _T("situation_id")));
1809 CHK_EXEC(DBDropColumn(g_hCoreDB, _T("event_policy"), _T("situation_instance")));
1810 CHK_EXEC(SetSchemaVersion(430));
1811 return TRUE;
1812 }
1813
1814 /**
1815 * Upgrade from V428 to V429
1816 */
1817 static BOOL H_UpgradeFromV428(int currVersion, int newVersion)
1818 {
1819 CHK_EXEC(DBResizeColumn(g_hCoreDB, _T("config"), _T("description"), 450, true));
1820 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Interval in seconds between active network discovery polls.' WHERE var_name='ActiveDiscoveryInterval'")));
1821 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable active network discovery. This setting is change by Network Discovery GUI' WHERE var_name='ActiveNetworkDiscovery'")));
1822 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Timeout in milliseconds for commands sent to agent. If agent did not respond to command within given number of seconds, \ncommand considered as failed.' WHERE var_name='AgentCommandTimeout'")));
1823 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='String that will be used as a shared secret in case if agent will required authentication.' WHERE var_name='AgentDefaultSharedSecret'")));
1824 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Maximum wait time in seconds for agent restart after upgrade. If agent cannot be contacted after this time period, \nupgrade process is considered as failed.' WHERE var_name='AgentUpgradeWaitTime'")));
1825 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='A number of days the server keeps an alarm history in the database.' WHERE var_name='AlarmHistoryRetentionTime'")));
1826 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Maximum alarm count that will be displayed on Alarm Browser page. Alarms that exceed this count will not be shown.' WHERE var_name='AlarmListDisplayLimit'")));
1827 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='A semicolon separated list of alarm summary e-mail recipient addresses.' WHERE var_name='AlarmSummaryEmailRecipients'")));
1828 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Schedule for sending alarm summary e-mails in cron format' WHERE var_name='AlarmSummaryEmailSchedule'")));
1829 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Allow/disallow sending of SMS via NetXMS server using nxsms utility.' WHERE var_name='AllowDirectSMS'")));
1830 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='A bitmask for encryption algorithms allowed in the server(sum the values to allow multiple algorithms at once): \n\t*1 - AES256 \n\t*2 - Blowfish-256 \n\t*4 - IDEA \n\t*8 - 3DES\n\t*16 - AES128\n\t*32 - Blowfish-128' WHERE var_name='AllowedCiphers'")));
1831 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='AllowTrapVarbindsConversion'")));
1832 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='AnonymousFileAccess'")));
1833 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable applying all DCIs from a template to the node, including disabled ones.' WHERE var_name='ApplyDCIFromTemplateToDisabledDCI'")));
1834 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Retention time in days for the records in audit log. All records older than specified will be deleted by housekeeping process.' WHERE var_name='AuditLogRetentionTime'")));
1835 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Comma-separated list of hosts to be used as beacons for checking NetXMS server network connectivity. Either DNS names \nor IP addresses can be used. This list is pinged by NetXMS server and if none of the hosts have responded, server considers that connection \nwith network is lost and generates specific event.' WHERE var_name='BeaconHosts'")));
1836 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Interval in milliseconds between beacon hosts polls.' WHERE var_name='BeaconPollingInterval'")));
1837 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Timeout in milliseconds to consider beacon host unreachable.' WHERE var_name='BeaconTimeout'")));
1838 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='BlockInactiveUserAccounts'")));
1839 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='CapabilityExpirationTime'")));
1840 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable case insensitive login names' WHERE var_name='CaseInsensitiveLoginNames'")));
1841 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable trusted nodes check' WHERE var_name='CheckTrustedNodes'")));
1842 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='The server port for incoming client connections (such as management console).' WHERE var_name='ClientListenerPort'")));
1843 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable container auto binding for clusters.' WHERE var_name='ClusterContainerAutoBind'")));
1844 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable template auto apply for clusters.' WHERE var_name='ClusterTemplateAutoApply'")));
1845 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Interval in seconds between polling (re-evaluating) of condition objects.' WHERE var_name='ConditionPollingInterval'")));
1846 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Interval in seconds between configuration polls.' WHERE var_name='ConfigurationPollingInterval'")));
1847 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable data interpolation in dashboard data export.' WHERE var_name='DashboardDataExportEnableInterpolation'")));
1848 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='A number of connections to the database created on server startup.' WHERE var_name='DBConnectionPoolBaseSize'")));
1849 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='DBConnectionPoolCooldownTime'")));
1850 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='DBConnectionPoolMaxLifetime'")));
1851 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='A maximum number of connections in the connection pool.' WHERE var_name='DBConnectionPoolMaxSize'")));
1852 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='' WHERE var_name='DBLockInfo'")));
1853 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='DBLockPID'")));
1854 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='' WHERE var_name='DBLockStatus'")));
1855 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='DefaultAgentCacheMode'")));
1856 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Default date display format for GUI.' WHERE var_name='DefaultConsoleDateFormat'")));
1857 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Default short time display format for GUI.' WHERE var_name='DefaultConsoleShortTimeFormat'")));
1858 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Default long time display format for GUI.' WHERE var_name='DefaultConsoleTimeFormat'")));
1859 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Default polling interval for newly created DCI (in seconds).' WHERE var_name='DefaultDCIPollingInterval'")));
1860 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Default retention time for newly created DCI (in days).' WHERE var_name='DefaultDCIRetentionTime'")));
1861 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='C',description='Set the default encryption policy for communications with agents.' WHERE var_name='DefaultEncryptionPolicy'")));
1862 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='C',description='Default expected state for new interface objects.' WHERE var_name='DefaultInterfaceExpectedState'")));
1863 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='H',description='Default background color for new network map objects.' WHERE var_name='DefaultMapBackgroundColor'")));
1864 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Default mask for synthetic IPv4 subnets.' WHERE var_name='DefaultSubnetMaskIPv4'")));
1865 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Default mask for synthetic IPv6 subnets.' WHERE var_name='DefaultSubnetMaskIPv6'")));
1866 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable automatic alarm removal of an object when it is deleted' WHERE var_name='DeleteAlarmsOfDeletedObject'")));
1867 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable automatic deletion of subnet objects without any nodes within. When enabled, empty subnets will be deleted \nby housekeeping process.' WHERE var_name='DeleteEmptySubnets'")));
1868 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable automatic event removal of an object when it is deleted.' WHERE var_name='DeleteEventsOfDeletedObject'")));
1869 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Delete nodes which were unreachable for a number of days specified by this parameter.' WHERE var_name='DeleteUnreachableNodesPeriod'")));
1870 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='' WHERE var_name='DiscoveryFilter'")));
1871 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='DiscoveryFilterFlags'")));
1872 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Interval in seconds between passive network discovery polls.' WHERE var_name='DiscoveryPollingInterval'")));
1873 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='EnableAdminInterface'")));
1874 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable agent self-registration' WHERE var_name='EnableAgentRegistration'")));
1875 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable audit log.' WHERE var_name='EnableAuditLog'")));
1876 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='EnableCheckPointSNMP'")));
1877 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='EnableReportingServer'")));
1878 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='EnableEventStormDetection'")));
1879 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable Inter-Server Communications Listener.' WHERE var_name='EnableISCListener'")));
1880 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable server-side NXSL functions for container management (such as CreateContainer, RemoveContainer, BindObject, \nUnbindObject).' WHERE var_name='EnableNXSLContainerFunctions.'")));
1881 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='EnableObjectTransactions'")));
1882 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable SNMP trap processing.' WHERE var_name='EnableSNMPTraps'")));
1883 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable alarm summary e-mails.' WHERE var_name='EnableAlarmSummaryEmails'")));
1884 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable receiving of syslog messages.' WHERE var_name='EnableSyslogReceiver'")));
1885 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='EnableTimedAlarmAck'")));
1886 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable XMPP connector (required to enable XMPP message sending).' WHERE var_name='EnableXMPPConnector'")));
1887 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable zoning support' WHERE var_name='EnableZoning'")));
1888 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='EscapeLocalCommands'")));
1889 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='The retention time of event logs' WHERE var_name='EventLogRetentionTime'")));
1890 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='EventStormDuration'")));
1891 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Event storm events per second' WHERE var_name='EventStormEventsPerSecond'")));
1892 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable extended access control in log queries.' WHERE var_name='ExtendedLogQueryAccessControl'")));
1893 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Syslog facility to be used in audit log records sent to external server.' WHERE var_name='ExternalAuditFacility'")));
1894 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='UDP port of external syslog server to send audit records to.' WHERE var_name='ExternalAuditPort'")));
1895 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='External syslog server to send audit records to. If set to ‘’none’‘, external audit logging is disabled.' WHERE var_name='ExternalAuditServer'")));
1896 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Syslog severity to be used in audit log records sent to external server.' WHERE var_name='ExternalAuditSeverity'")));
1897 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Syslog tag to be used in audit log records sent to external server.' WHERE var_name='ExternalAuditTag'")));
1898 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='FirstFreeObjectId'")));
1899 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='FixedStatusValue'")));
1900 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='' WHERE var_name='HelpDeskLink'")));
1901 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Time when housekeeper starts. Housekeeper deletes old log lines, old DCI data, cleans removed objects and does VACUUM for \nPostgreSQL.' WHERE var_name='HousekeeperStartTime'")));
1902 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Size of ICMP packets (in bytes, excluding IP header size) used for status polls.' WHERE var_name='IcmpPingSize'")));
1903 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Timeout for ICMP ping used for status polls (in milliseconds).' WHERE var_name='IcmpPingTimeout'")));
1904 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Import configuration from local files on server startup.' WHERE var_name='ImportConfigurationOnStartup'")));
1905 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Instance polling interval (in milliseconds).' WHERE var_name='InstancePollingInterval'")));
1906 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable internal certificate authority.' WHERE var_name='InternalCA'")));
1907 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='IntruderLockoutThreshold'")));
1908 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='IntruderLockoutTime'")));
1909 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='' WHERE var_name='JiraIssueType'")));
1910 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Jira login name.' WHERE var_name='JiraLogin'")));
1911 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Jira password' WHERE var_name='JiraPassword'")));
1912 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Jira project code' WHERE var_name='JiraProjectCode'")));
1913 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='' WHERE var_name='JiraProjectComponent'")));
1914 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='The URL of the Jira server' WHERE var_name='JiraServerURL'")));
1915 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='JobHistoryRetentionTime'")));
1916 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Maximum mumber of job execution retrys.' WHERE var_name='JobRetryCount'")));
1917 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Interval in seconds between sending keep alive packets to connected clients.' WHERE var_name='KeepAliveInterval'")));
1918 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Specifies which object class represents group objects. If the found entry is not of user or group class, it will be ignored.' WHERE var_name='LdapGroupClass'")));
1919 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='LdapGroupUniqueId'")));
1920 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='The LdapConnectionString configuration parameter may be a comma- or whitespace-separated list of URIs containing only the \nschema, the host, and the port fields. Format: schema://host:port.' WHERE var_name='LdapConnectionString'")));
1921 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='The name of an attribute whose value will be used as a user`s description.' WHERE var_name='LdapMappingDescription'")));
1922 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='The name of an attribute whose value will be used as a user`s full name.' WHERE var_name='LdapMappingFullName'")));
1923 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='The name of an attribute whose value will be used as a user`s login name.' WHERE var_name='LdapMappingName'")));
1924 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='The maximum amount of records that can be returned in one search page.' WHERE var_name='LdapPageSize'")));
1925 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='The DN of the entry at which to start the search.' WHERE var_name='LdapSearchBase'")));
1926 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='A string representation of the filter to apply in the search.' WHERE var_name='LdapSearchFilter'")));
1927 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='The synchronization interval (in minutes) between the NetXMS server and the LDAP server. If the parameter is set to 0, no \nsynchronization will take place.' WHERE var_name='LdapSyncInterval'")));
1928 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='User login for LDAP synchronization.' WHERE var_name='LdapSyncUser'")));
1929 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='User password for LDAP synchronization.' WHERE var_name='LdapSyncUserPassword'")));
1930 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='The object class which represents user objects. If the found entry is not of user or group class, it will be ignored.' WHERE var_name='LdapUserClass'")));
1931 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='C',description='This parameter specifies what should be done while synchronizing with a deleted user/group from LDAP.' WHERE var_name='LdapUserDeleteAction'")));
1932 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='LdapUserUniqueId'")));
1933 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='LockTimeout'")));
1934 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Log all SNMP traps.' WHERE var_name='LogAllSNMPTraps'")));
1935 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Encoding for e-mails generated by NetXMS server.' WHERE var_name='MailEncoding'")));
1936 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Message to be shown when a user logs into the console.' WHERE var_name='MessageOfTheDay'")));
1937 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Default minimum password length for a NetXMS user. The default applied only if per-user setting is not defined.' WHERE var_name='MinPasswordLength'")));
1938 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='MinViewRefreshInterval'")));
1939 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='MobileDeviceListenerPort'")));
1940 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='The number of threads used for data collection.' WHERE var_name='NumberOfDataCollectors'")));
1941 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='The number of threads used to perform agent upgrades (i.e. maximum number of parallel upgrades).' WHERE var_name='NumberOfUpgradeThreads'")));
1942 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Time period in seconds within which received offline data still relevant for threshold validation.' WHERE var_name='OfflineDataRelevanceTime'")));
1943 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Set of flags to enforce password complexity.' WHERE var_name='PasswordComplexity'")));
1944 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Password expiration time in days. If set to 0, password expiration is disabled.' WHERE var_name='PasswordExpiration'")));
1945 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Number of previous passwords to keep. Users are not allowed to set password if it matches one from previous passwords list.' WHERE var_name='PasswordHistoryLength'")));
1946 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='The number of consecutive unsuccessful polls required to declare interface as down.' WHERE var_name='PollCountForStatusChange'")));
1947 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='The base thread pool size.' WHERE var_name='PollerThreadPoolBaseSize'")));
1948 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Maximum thread pool size.' WHERE var_name='PollerThreadPoolMaxSize'")));
1949 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='RADIUS authentication method to be used (PAP, CHAP, MS-CHAPv1, MS-CHAPv2).' WHERE var_name='RADIUSAuthMethod'")));
1950 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='The number of retries for RADIUS authentication.' WHERE var_name='RADIUSNumRetries'")));
1951 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Port number used for connection to primary RADIUS server.' WHERE var_name='RADIUSPort'")));
1952 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Port number used for connection to secondary RADIUS server.' WHERE var_name='RADIUSSecondaryPort'")));
1953 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Shared secret used for communication with secondary RADIUS server.' WHERE var_name='RADIUSSecondarySecret'")));
1954 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Host name or IP address of secondary RADIUS server.' WHERE var_name='RADIUSSecondaryServer'")));
1955 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Shared secret used for communication with primary RADIUS server.' WHERE var_name='RADIUSSecret'")));
1956 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Host name or IP address of primary RADIUS server.' WHERE var_name='RADIUSServer'")));
1957 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Timeout in seconds for requests to RADIUS server.' WHERE var_name='RADIUSTimeout'")));
1958 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable reception of events forwarded by another NetXMS server. Please note that for external event reception ISC listener \nshould be enabled as well.' WHERE var_name='ReceiveForwardedEvents'")));
1959 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='The hostname of the reporting server.' WHERE var_name='ReportingServerHostname'")));
1960 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='The port of the reporting server.' WHERE var_name='ReportingServerPort'")));
1961 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Resolve DNS to IP on status poll.' WHERE var_name='ResolveDNSToIPOnStatusPoll'")));
1962 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='ResolveNodeNames'")));
1963 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Interval in seconds between reading routing table from node.' WHERE var_name='RoutingTableUpdateInterval'")));
1964 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable automatic network discovery process. *This setting is changed by Network Discovery in the GUI*.' WHERE var_name='RunNetworkDiscovery'")));
1965 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='H',description='Identification color for this server' WHERE var_name='ServerColor'")));
1966 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='ServerCommandOutputTimeout'")));
1967 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Name of this server' WHERE var_name='ServerName'")));
1968 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Mobile phone driver to be used for sending SMS.' WHERE var_name='SMSDriver'")));
1969 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='SMS driver parameters. For ‘’generic’’ driver, it should be the name of COM port device.' WHERE var_name='SMSDrvConfig'")));
1970 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='The address used for sending mail from.' WHERE var_name='SMTPFromAddr'")));
1971 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='The name used as the sender.' WHERE var_name='SMTPFromName'")));
1972 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Number of retries for sending mail.' WHERE var_name='SMTPRetryCount'")));
1973 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='TCP port for SMTP server.' WHERE var_name='SNMPPorts'")));
1974 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='An SMTP server used for sending mail.' WHERE var_name='SMTPServer'")));
1975 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Timeout in milliseconds for SNMP requests sent by NetXMS server.' WHERE var_name='SNMPRequestTimeout'")));
1976 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='The time how long SNMP trap logs are retained.' WHERE var_name='SNMPTrapLogRetentionTime'")));
1977 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Port used for SNMP traps.' WHERE var_name='SNMPTrapPort'")));
1978 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='StatusCalculationAlgorithm'")));
1979 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Interval in seconds between status polls.' WHERE var_name='StatusPollingInterval'")));
1980 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='C',description='Algorithm for status propagation (how object’s status affects its child object statuses).' WHERE var_name='StatusPropagationAlgorithm'")));
1981 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='StatusShift'")));
1982 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='StatusSingleThreshold'")));
1983 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='' WHERE var_name='StatusThresholds'")));
1984 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='' WHERE var_name='StatusTranslation'")));
1985 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable strict alarm status flow (alarm can be terminated only after it has been resolved).' WHERE var_name='StrictAlarmStatusFlow'")));
1986 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Interval in seconds between writing object changes to the database.' WHERE var_name='SyncInterval'")));
1987 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable synchronization of node names with DNS on each configuration poll.' WHERE var_name='SyncNodeNamesWithDNS'")));
1988 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Ignore timestamp received in syslog messages and always use server time.' WHERE var_name='SyslogIgnoreMessageTimestamp'")));
1989 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='UDP port used by built-in syslog server.' WHERE var_name='SyslogListenPort'")));
1990 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='C',description='Node matching policy for built-in syslog daemon.' WHERE var_name='SyslogNodeMatchingPolicy'")));
1991 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Retention time in days for records in syslog. All records older than specified will be deleted by housekeeping process.' WHERE var_name='SyslogRetentionTime'")));
1992 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='System-wide interval in seconds for resending threshold violation events. Value of 0 disables event resending.' WHERE var_name='ThresholdRepeatInterval'")));
1993 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='The URL for the Tile server.' WHERE var_name='TileServerURL'")));
1994 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='TopologyDiscoveryRadius'")));
1995 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='TopologyExpirationTime'")));
1996 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Search all zones to match trap/syslog source address to node.' WHERE var_name='TrapSourcesInAllZones'")));
1997 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable the use of DNS name instead of IP address as primary name for newly discovered nodes.' WHERE var_name='UseDNSNameForDiscoveredNodes'")));
1998 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable the use of fully qualified domain names as primary names for newly discovered nodes.' WHERE var_name='UseFQDNForNodeNames'")));
1999 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable the use of SNMP ifXTable instead of ifTable for interface configuration polling.' WHERE var_name='UseIfXTable'")));
2000 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='C',description='Control usage of interface aliases (or descriptions).' WHERE var_name='UseInterfaceAliases'")));
2001 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Use SNMP trap information for new node discovery.' WHERE var_name='UseSNMPTrapsForDiscovery'")));
2002 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Login name that will be used to authentication on XMPP server.' WHERE var_name='XMPPLogin'")));
2003 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Password that will be used to authentication on XMPP server.' WHERE var_name='XMPPPassword'")));
2004 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='XMPP connection port.' WHERE var_name='XMPPPort'")));
2005 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='XMPP connection server.' WHERE var_name='XMPPServer'")));
2006
2007 CHK_EXEC(CreateTable(
2008 _T("CREATE TABLE config_values (")
2009 _T("var_name varchar(63) not null,")
2010 _T("var_value varchar(15) not null,")
2011 _T("var_description varchar(255) null,")
2012 _T("PRIMARY KEY(var_name,var_value))")));
2013
2014 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('ClientListenerPort','65535')")));
2015 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('ExternalAuditPort','65535')")));
2016 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('MobileDeviceListenerPort','65535')")));
2017 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('RADIUSPort','65535')")));
2018 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('RADIUSSecondaryPort','65535')")));
2019 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('ReportingServerPort','65535')")));
2020 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('SNMPPorts','65535')")));
2021 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('SNMPTrapPort','65535')")));
2022 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('SyslogListenPort','65535')")));
2023 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('XMPPPort','65535')")));
2024 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('AllowedCiphers','63')")));
2025 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultInterfaceExpectedState','0','UP')")));
2026 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultInterfaceExpectedState','1','DOWN')")));
2027 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultInterfaceExpectedState','2','IGNORE')")));
2028 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultEncryptionPolicy','0','Disabled')")));
2029 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultEncryptionPolicy','1','Allowed')")));
2030 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultEncryptionPolicy','2','Preferred')")));
2031 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultEncryptionPolicy','3','Required')")));
2032 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('StatusPropagationAlgorithm','0','Default')")));
2033 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('StatusPropagationAlgorithm','1','Unchanged')")));
2034 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('StatusPropagationAlgorithm','2','Fixed')")));
2035 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('StatusPropagationAlgorithm','3','Relative')")));
2036 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('StatusPropagationAlgorithm','4','Translated')")));
2037 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('UseInterfaceAliases','0','Don`t use aliases')")));
2038 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('UseInterfaceAliases','1','Use aliases when possible')")));
2039 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('UseInterfaceAliases','2','Concatenate alias and name')")));
2040 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('UseInterfaceAliases','3','Concatenate name and alias')")));
2041 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('SyslogNodeMatchingPolicy','0','IP, then hostname')")));
2042 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('SyslogNodeMatchingPolicy','1','Hostname, then IP')")));
2043 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('LdapUserDeleteAction','0','Delete user')")));
2044 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('LdapUserDeleteAction','1','Disable user')")));
2045
2046 CHK_EXEC(SetSchemaVersion(429));
2047 return TRUE;
2048 }
2049
2050 /**
2051 * Upgrade from V427 to V428
2052 */
2053 static BOOL H_UpgradeFromV427(int currVersion, int newVersion)
2054 {
2055 CHK_EXEC(CreateConfigParam(_T("ClusterContainerAutoBind"), _T("0"), _T("Enable/disable container auto binding for clusters"), 'B', true, false, false, false));
2056 CHK_EXEC(CreateConfigParam(_T("ClusterTemplateAutoApply"), _T("0"), _T("Enable/disable template auto apply for clusters"), 'B', true, false, false, false));
2057 CHK_EXEC(SetSchemaVersion(428));
2058 return TRUE;
2059 }
2060
2061 /**
2062 * Upgrade from V426 to V427
2063 */
2064 static BOOL H_UpgradeFromV426(int currVersion, int newVersion)
2065 {
2066 CHK_EXEC(SQLQuery(_T("ALTER TABLE nodes ADD port_rows integer")));
2067 CHK_EXEC(SQLQuery(_T("ALTER TABLE nodes ADD port_numbering_scheme integer")));
2068 CHK_EXEC(SetSchemaVersion(427));
2069 return TRUE;
2070 }
2071
2072 /**
2073 * Upgrade from V425 to V426
2074 */
2075 static BOOL H_UpgradeFromV425(int currVersion, int newVersion)
2076 {
2077 CHK_EXEC(CreateConfigParam(_T("EnableAlarmSummaryEmails"), _T(""), _T("Enable alarm summary e-mails"), 'I', true, false, false, false));
2078 CHK_EXEC(CreateConfigParam(_T("AlarmSummaryEmailSchedule"), _T(""), _T("Schedule for sending alarm summary e-mails in cron format"), 'S', true, false, false, false));
2079 CHK_EXEC(CreateConfigParam(_T("AlarmSummaryEmailRecipients"), _T(""), _T("A semicolon separated list of alarm summary e-mail recipient addresses"), 'S', true, false, false, false));
2080 CHK_EXEC(SetSchemaVersion(426));
2081 return TRUE;
2082 }
2083
2084 /**
2085 * Upgrade from V424 to V425
2086 */
2087 static BOOL H_UpgradeFromV424(int currVersion, int newVersion)
2088 {
2089 CHK_EXEC(SQLQuery(_T("ALTER TABLE scheduled_tasks ADD comments varchar(255)")));
2090 CHK_EXEC(SetSchemaVersion(425));
2091 return TRUE;
2092 }
2093
2094 /**
2095 * Upgrade from V423 to V424
2096 */
2097 static BOOL H_UpgradeFromV423(int currVersion, int newVersion)
2098 {
2099 CHK_EXEC(CreateConfigParam(_T("MessageOfTheDay"), _T(""), _T("Message to be shown when a user logs into the console"), 'S', true, false, false, false));
2100 CHK_EXEC(SetSchemaVersion(424));
2101 return TRUE;
2102 }
2103
2104 /**
2105 * Upgrade from V422 to V423
2106 */
2107 static BOOL H_UpgradeFromV422(int currVersion, int newVersion)
2108 {
2109 CHK_EXEC(CreateConfigParam(_T("RADIUSAuthMethod"), _T("PAP"), _T("RADIUS authentication method to be used (PAP, CHAP, MS-CHAPv1, MS-CHAPv2)"), 'S', true, false, false, false));
2110 CHK_EXEC(SetSchemaVersion(423));
2111 return TRUE;
2112 }
2113
2114 /**
2115 * Upgrade from V421 to V422
2116 */
2117 static BOOL H_UpgradeFromV421(int currVersion, int newVersion)
2118 {
2119 CHK_EXEC(CreateConfigParam(_T("ServerColor"), _T(""), _T("Identification color for this server"), 'S', true, false, false, false));
2120 CHK_EXEC(CreateConfigParam(_T("ServerName"), _T(""), _T("Name of this server"), 'S', true, false, false, false));
2121 CHK_EXEC(SetSchemaVersion(422));
2122 return TRUE;
2123 }
2124
2125 /**
2126 * Upgrade from V420 to V421
2127 */
2128 static BOOL H_UpgradeFromV420(int currVersion, int newVersion)
2129 {
2130 DB_RESULT hResult = SQLSelect(_T("SELECT access_rights,user_id,object_id FROM acl"));
2131 if (hResult != NULL)
2132 {
2133 UINT32 rights;
2134 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("UPDATE acl SET access_rights=? WHERE user_id=? AND object_id=?"));
2135 if (hStmt != NULL)
2136 {
2137 for(int i = 0; i < DBGetNumRows(hResult); i++)
2138 {
2139 rights = DBGetFieldULong(hResult, i, 0);
2140 if ((rights & 0x2) == 0x2)
2141 {
2142 rights = rights | 0x8000; // Add Manage maintenance access right to all users which have Modify object access right
2143 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, rights);
2144 DBBind(hStmt, 2, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 1));
2145 DBBind(hStmt, 3, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 2));
2146 SQLExecute(hStmt);
2147 }
2148 }
2149 DBFreeStatement(hStmt);
2150 }
2151 else
2152 {
2153 if (!g_bIgnoreErrors)
2154 {
2155 DBFreeResult(hResult);
2156 return FALSE;
2157 }
2158 }
2159 DBFreeResult(hResult);
2160 }
2161 else
2162 {
2163 if (!g_bIgnoreErrors)
2164 return FALSE;
2165 }
2166
2167 CHK_EXEC(SetSchemaVersion(421));
2168 return TRUE;
2169 }
2170
2171 /**
2172 * Upgrade from V419 to V420
2173 */
2174 static BOOL H_UpgradeFromV419(int currVersion, int newVersion)
2175 {
2176 CHK_EXEC(CreateConfigParam(_T("EnableReportingServer"), _T("0"), 1, 1));
2177 CHK_EXEC(CreateConfigParam(_T("ReportingServerHostname"), _T("localhost"), 1, 1));
2178 CHK_EXEC(CreateConfigParam(_T("ReportingServerPort"), _T("4710"), 1, 1));
2179 CHK_EXEC(SetSchemaVersion(420));
2180 return TRUE;
2181 }
2182
2183 /**
2184 * Upgrade from V418 to V419
2185 */
2186 static BOOL H_UpgradeFromV418(int currVersion, int newVersion)
2187 {
2188 CHK_EXEC(SQLQuery(_T("ALTER TABLE items ADD npe_name varchar(15)")));
2189 CHK_EXEC(SetSchemaVersion(419));
2190 return TRUE;
2191 }
2192
2193 /**
2194 * Upgrade from V417 to V418
2195 */
2196 static BOOL H_UpgradeFromV417(int currVersion, int newVersion)
2197 {
2198 // Update in object tools objectToolFilter objectMenuFilter
2199 // move object tool flags to filter structure
2200 DB_RESULT hResult = SQLSelect(_T("SELECT tool_id,flags,tool_filter FROM object_tools"));
2201 if (hResult != NULL)
2202 {
2203 int count = DBGetNumRows(hResult);
2204 for(int i = 0; i < count; i++)
2205 {
2206 int filteringFlag = 0;
2207 int objectToolFlag = DBGetFieldLong(hResult, i, 1);
2208
2209 // Separate and reorder flags for filter and for object tools
2210 for(int j = 1; j < 5; j = j << 1) //REQUIRES_SNMP 0x01, REQUIRES_AGENT 0x02, REQUIRES_OID_MATCH 0x04
2211 {
2212 if ((objectToolFlag & j) != 0)
2213 {
2214 objectToolFlag = objectToolFlag & ~j;
2215 filteringFlag = filteringFlag | j;
2216 }
2217 }
2218
2219 if ((objectToolFlag & 0x08) != 0) //ASK_CONFIRMATION
2220 {
2221 objectToolFlag = objectToolFlag & ~0x08;
2222 objectToolFlag = objectToolFlag | 0x01;
2223 }
2224
2225 if ((objectToolFlag & 0x10) != 0) //GENERATES_OUTPUT
2226 {
2227 objectToolFlag = objectToolFlag & ~0x10;
2228 objectToolFlag = objectToolFlag | 0x02;
2229 }
2230
2231 if ((objectToolFlag & 0x20) != 0) //DISABLED
2232 {
2233 objectToolFlag = objectToolFlag & ~0x20;
2234 objectToolFlag = objectToolFlag | 0x04;
2235 }
2236
2237 if ((objectToolFlag & 0x40) != 0) //SHOW_IN_COMMANDS
2238 {
2239 objectToolFlag = objectToolFlag & ~0x40;
2240 objectToolFlag = objectToolFlag | 0x08;
2241 }
2242
2243 if ((objectToolFlag & 0x80) != 0) //REQUIRES_NODE_OS_MATCH
2244 {
2245 objectToolFlag = objectToolFlag & ~0x80;
2246 filteringFlag = filteringFlag | 0x08;
2247 }
2248
2249 if ((objectToolFlag & 0x100) != 0) //REQUIRES_TEMPLATE_MATCH
2250 {
2251 objectToolFlag = objectToolFlag & ~0x100;
2252 filteringFlag = filteringFlag | 0x10;
2253 }
2254
2255 if ((objectToolFlag & 0x10000) != 0) //SNMP_INDEXED_BY_VALUE
2256 {
2257 objectToolFlag = objectToolFlag & ~0x10000;
2258 objectToolFlag = objectToolFlag | 0x10;
2259 }
2260
2261 if ((objectToolFlag & 0x20000) != 0) //REQUIRES_WORKSTATION_OS_MATCH
2262 {
2263 objectToolFlag = objectToolFlag & ~0x20000;
2264 filteringFlag = filteringFlag | 0x20;
2265 }
2266
2267 // Add filter flags to XML
2268 TCHAR *xml = DBGetField(hResult, i, 2, NULL, 0);
2269 size_t len = (xml != NULL) ? _tcslen(xml) + 1024 : 1024;
2270 TCHAR *tmp = (TCHAR *)malloc(len * sizeof(TCHAR));
2271 TCHAR *ptr = (xml != NULL) ? _tcsrchr(xml, '<') : NULL;
2272 if (ptr != NULL)
2273 {
2274 *ptr = 0;
2275 _sntprintf(tmp, len, _T("%s<flags>%d</flags></objectMenuFilter>"), xml, filteringFlag);
2276 _tcsncpy(tmp, _T("<objectMenuFilter"), 17); //Change main tag name
2277 }
2278 else
2279 {
2280 _sntprintf(tmp, len, _T("<objectMenuFilter><flags>%d</flags></objectMenuFilter>"), filteringFlag);
2281 }
2282
2283 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("UPDATE object_tools SET flags=?,tool_filter=? WHERE tool_id=?"));
2284 if (hStmt != NULL)
2285 {
2286 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, objectToolFlag);
2287 DBBind(hStmt, 2, DB_SQLTYPE_TEXT, tmp, DB_BIND_DYNAMIC);
2288 DBBind(hStmt, 3, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 0));
2289 if (!SQLExecute(hStmt))
2290 {
2291 if (!g_bIgnoreErrors)
2292 {
2293 free(xml);
2294 DBFreeStatement(hStmt);
2295 DBFreeResult(hResult);
2296 return FALSE;
2297 }
2298 }
2299 }
2300 else
2301 {
2302 free(tmp);
2303 if (!g_bIgnoreErrors)
2304 {
2305 free(xml);
2306 DBFreeResult(hResult);
2307 return FALSE;
2308 }
2309 }
2310 free(xml);
2311 }
2312 DBFreeResult(hResult);
2313 }
2314 else
2315 {
2316 if (!g_bIgnoreErrors)
2317 return false;
2318 }
2319
2320 CHK_EXEC(SetSchemaVersion(418));
2321 return TRUE;
2322 }
2323
2324 /**
2325 * Upgrade from V416 to V417
2326 */
2327 static BOOL H_UpgradeFromV416(int currVersion, int newVersion)
2328 {
2329 CHK_EXEC(CreateConfigParam(_T("JiraIssueType"), _T("Task"), true, false));
2330 CHK_EXEC(CreateConfigParam(_T("JiraLogin"), _T("netxms"), true, true));
2331 CHK_EXEC(CreateConfigParam(_T("JiraPassword"), _T(""), true, true));
2332 CHK_EXEC(CreateConfigParam(_T("JiraProjectCode"), _T("NETXMS"), true, false));
2333 CHK_EXEC(CreateConfigParam(_T("JiraProjectComponent"), _T(""), true, false));
2334 CHK_EXEC(CreateConfigParam(_T("JiraServerURL"), _T("http://localhost"), true, true));
2335
2336 CHK_EXEC(SetSchemaVersion(417));
2337 return TRUE;
2338 }
2339
2340 /**
2341 * Upgrade from V415 to V416
2342 */
2343 static BOOL H_UpgradeFromV415(int currVersion, int newVersion)
2344 {
2345 CHK_EXEC(CreateTable(
2346 _T("CREATE TABLE alarm_categories (")
2347 _T("id integer not null,")
2348 _T("name varchar(63) null,")
2349 _T("descr varchar(255) null,")
2350 _T("PRIMARY KEY(id))")));
2351 CHK_EXEC(CreateTable(
2352 _T("CREATE TABLE alarm_category_acl (")
2353 _T("category_id integer not null,")
2354 _T("user_id integer not null,")
2355 _T("PRIMARY KEY(category_id,user_id))")));
2356 CHK_EXEC(CreateTable(
2357 _T("CREATE TABLE alarm_category_map (")
2358 _T("alarm_id integer not null,")
2359 _T("category_id integer not null,")
2360 _T("PRIMARY KEY(alarm_id,category_id))")));
2361
2362 CHK_EXEC(SQLQuery(
2363 _T("ALTER TABLE alarms ADD alarm_category_ids varchar(255)")));
2364
2365 // Add view all alarms system access to user group - Everyone
2366 DB_RESULT hResult = SQLSelect(_T("SELECT system_access FROM user_groups WHERE name='Everyone'"));
2367 if (hResult != NULL)
2368 {
2369 UINT64 sysAccess = DBGetFieldUInt64(hResult, 0, 0);
2370 sysAccess = sysAccess | SYSTEM_ACCESS_VIEW_ALL_ALARMS;
2371
2372 TCHAR query[MAX_DB_STRING];
2373 _sntprintf(query, MAX_DB_STRING, _T("UPDATE user_groups SET system_access=%ld WHERE name='Everyone'"), sysAccess);
2374 CHK_EXEC(SQLQuery(query));
2375
2376 DBFreeResult(hResult);
2377 }
2378 else
2379 {
2380 if (!g_bIgnoreErrors)
2381 return false;
2382 }
2383
2384 CHK_EXEC(SetSchemaVersion(416));
2385 return TRUE;
2386 }
2387
2388 /**
2389 * Upgrade from V414 to V415
2390 */
2391 static BOOL H_UpgradeFromV414(int currVersion, int newVersion)
2392 {
2393 CHK_EXEC(DBRemoveNotNullConstraint(g_hCoreDB, _T("dci_summary_tables"), _T("menu_path")));
2394 CHK_EXEC(SetSchemaVersion(415));
2395 return TRUE;
2396 }
2397
2398 /**
2399 * Upgrade from V413 to V414
2400 */
2401 static BOOL H_UpgradeFromV413(int currVersion, int newVersion)
2402 {
2403 CHK_EXEC(SQLQuery(_T("UPDATE config SET var_name='EnableSyslogReceiver' WHERE var_name='EnableSyslogDaemon'")));
2404 CHK_EXEC(SetSchemaVersion(414));
2405 return TRUE;
2406 }
2407
2408 /**
2409 * Upgrade from V412 to V413
2410 */
2411 static BOOL H_UpgradeFromV412(int currVersion, int newVersion)
2412 {
2413 CHK_EXEC(SQLQuery(_T("UPDATE users SET name='system',description='Built-in system account',full_name='',flags=12 WHERE id=0")));
2414
2415 TCHAR password[128];
2416 DB_RESULT hResult = SQLSelect(_T("SELECT password FROM users WHERE id=0"));
2417 if (hResult != NULL)
2418 {
2419 if (DBGetNumRows(hResult) > 0)
2420 DBGetField(hResult, 0, 0, password, 128);
2421 else
2422 _tcscpy(password, _T("3A445C0072CD69D9030CC6644020E5C4576051B1")); // Use default password "netxms"
2423 DBFreeResult(hResult);
2424 }
2425 else
2426 {
2427 if (!g_bIgnoreErrors)
2428 return false;
2429 }
2430
2431 UINT32 userId = 1;
2432 hResult = SQLSelect(_T("SELECT max(id) FROM users"));
2433 if (hResult != NULL)
2434 {
2435 if (DBGetNumRows(hResult) > 0)
2436 userId = DBGetFieldULong(hResult, 0, 0) + 1;
2437 DBFreeResult(hResult);
2438 }
2439 else
2440 {
2441 if (!g_bIgnoreErrors)
2442 return false;
2443 }
2444
2445 uuid guid = uuid::generate();
2446 TCHAR query[1024];
2447 _sntprintf(query, 1024,
2448 _T("INSERT INTO users (id,name,password,system_access,flags,full_name,")
2449 _T(" description,grace_logins,auth_method,guid,")
2450 _T(" cert_mapping_method,cert_mapping_data,")
2451 _T(" auth_failures,last_passwd_change,min_passwd_length,")
2452 _T(" disabled_until,last_login) VALUES (%d,'admin','%s',274877906943,0,")
2453 _T(" '','Default administrator account',5,0,'%s',0,'',0,0,0,0,0)"),
2454 userId, password, (const TCHAR *)guid.toString());
2455 CHK_EXEC(SQLQuery(query));
2456
2457 for(int i = 1; i < 10; i++)
2458 {
2459 _sntprintf(query, 256, _T("INSERT INTO acl (object_id,user_id,access_rights) VALUES (%d,%d,32767)"), i, userId);
2460 CHK_EXEC(SQLQuery(query));
2461 }
2462
2463 //Add adming to Admin group if exists
2464 UINT32 groupId = 0;
2465 hResult = SQLSelect(_T("SELECT id FROM user_groups WHERE name='Admins'"));
2466 if (hResult != NULL)
2467 {
2468 if (DBGetNumRows(hResult) > 0)
2469 groupId = DBGetFieldULong(hResult, 0, 0);
2470 DBFreeResult(hResult);
2471 }
2472 else
2473 {
2474 if (!g_bIgnoreErrors)
2475 return false;
2476 }
2477 if(groupId != 0)
2478 {
2479 _sntprintf(query, 256, _T("INSERT INTO user_group_members (group_id,user_id) VALUES (%d,%d)"), groupId, userId);
2480 CHK_EXEC(SQLQuery(query));
2481 }
2482
2483 //Update non object ACL
2484 _sntprintf(query, 256, _T("UPDATE object_tools_acl SET user_id=%d WHERE user_id=0"), userId);
2485 CHK_EXEC(SQLQuery(query));
2486
2487 _sntprintf(query, 256, _T("UPDATE graph_acl SET user_id=%d WHERE user_id=0"), userId);
2488 CHK_EXEC(SQLQuery(query));
2489
2490 _sntprintf(query, 256, _T("UPDATE graphs SET owner_id=%d WHERE owner_id=0"), userId);
2491 CHK_EXEC(SQLQuery(query));
2492
2493
2494 CHK_EXEC(SetSchemaVersion(413));
2495 return TRUE;
2496 }
2497
2498 /**
2499 * Upgrade from V411 to V412
2500 */
2501 static BOOL H_UpgradeFromV411(int currVersion, int newVersion)
2502 {
2503 DB_RESULT hResult = SQLSelect(_T("SELECT id,zone_guid,agent_proxy,snmp_proxy,icmp_proxy,ssh_proxy FROM zones"));
2504 if (hResult != NULL)
2505 {
2506 CHK_EXEC(SQLQuery(_T("DROP TABLE zones")));
2507 CHK_EXEC(CreateTable(
2508 _T("CREATE TABLE zones (")
2509 _T("id integer not null,")
2510 _T("zone_guid integer not null,")
2511 _T("proxy_node integer not null,")
2512 _T("PRIMARY KEY(id))")));
2513 int count = DBGetNumRows(hResult);
2514 if (count > 0)
2515 {
2516 TCHAR query[256];
2517 for(int i = 0; i < count; i++)
2518 {
2519 UINT32 proxy = 0;
2520 for(int j = 2; (j < 6) && (proxy == 0); j++)
2521 proxy = DBGetFieldULong(hResult, i, j);
2522 _sntprintf(query, 256, _T("INSERT INTO zones (id,zone_guid,proxy_node) VALUES (%d,%d,%d)"),
2523 DBGetFieldLong(hResult, i, 0), DBGetFieldLong(hResult, i, 1), (int)proxy);
2524 CHK_EXEC(SQLQuery(query));
2525 }
2526 }
2527 DBFreeResult(hResult);
2528 }
2529 else
2530 {
2531 if (!g_bIgnoreErrors)
2532 return false;
2533 }
2534 CHK_EXEC(SetSchemaVersion(412));
2535 return TRUE;
2536 }
2537
2538 /**
2539 * Upgrade from V410 to V411
2540 */
2541 static BOOL H_UpgradeFromV410(int currVersion, int newVersion)
2542 {
2543 //check if tdata upgrade was already done, then just delete "TdataTableUpdated" metadata parameter
2544 if (!MetaDataReadInt(_T("TdataTableUpdated"), 0))
2545 {
2546 StringMap savedMetadata;
2547 DB_RESULT hResult = SQLSelect(_T("SELECT var_name,var_value FROM metadata WHERE var_name LIKE 'TDataTableCreationCommand_%' OR var_name LIKE 'TDataIndexCreationCommand_%'"));
2548 if (hResult != NULL)
2549 {
2550 int count = DBGetNumRows(hResult);
2551 for(int i = 0; i < count; i++)
2552 {
2553 savedMetadata.setPreallocated(DBGetField(hResult, i, 0, NULL, 0), DBGetField(hResult, i, 1, NULL, 0));
2554 }
2555 DBFreeResult(hResult);
2556 }
2557 else if (!g_bIgnoreErrors)
2558 {
2559 return false;
2560 }
2561
2562 static const TCHAR *batch =
2563 _T("DELETE FROM metadata WHERE var_name LIKE 'TDataTableCreationCommand_%' OR var_name LIKE 'TDataIndexCreationCommand_%'\n")
2564 _T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataTableCreationCommand_0','CREATE TABLE tdata_%d (item_id integer not null,tdata_timestamp integer not null,tdata_value $SQL:TEXT null)')\n")
2565 _T("<END>");
2566 CHK_EXEC(SQLBatch(batch));
2567
2568 if (g_dbSyntax == DB_SYNTAX_MSSQL)
2569 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataIndexCreationCommand_0','CREATE CLUSTERED INDEX idx_tdata_%d ON tdata_%d(item_id,tdata_timestamp)')")));
2570 else
2571 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataIndexCreationCommand_0','CREATE INDEX idx_tdata_%d ON tdata_%d(item_id,tdata_timestamp)')")));
2572
2573 // table conversion will require multiple commits
2574 DBCommit(g_hCoreDB);
2575 if (!ConvertTDataTables())
2576 {
2577 if (!g_bIgnoreErrors)
2578 {
2579 // Restore metadata
2580 SQLQuery(_T("DELETE FROM metadata WHERE var_name LIKE 'TDataTableCreationCommand_%' OR var_name LIKE 'TDataIndexCreationCommand_%'"));
2581 StringList *keys = savedMetadata.keys();
2582 for(int i = 0; i < keys->size(); i++)
2583 {
2584 TCHAR query[4096];
2585 _sntprintf(query, 4096, _T("INSERT INTO metadata (var_name,var_value) VALUES (%s,%s)"),
2586 (const TCHAR *)DBPrepareString(g_hCoreDB, keys->get(i)),
2587 (const TCHAR *)DBPrepareString(g_hCoreDB, savedMetadata.get(keys->get(i))));
2588 SQLQuery(query);
2589 }
2590 return false;
2591 }
2592 }
2593
2594 DBBegin(g_hCoreDB);
2595 }
2596 else
2597 {
2598 CHK_EXEC(SQLQuery(_T("DELETE FROM metadata WHERE var_name='TdataTableUpdated'")));
2599 }
2600 CHK_EXEC(SetSchemaVersion(411));
2601 return TRUE;
2602 }
2603
2604 /**
2605 * Upgrade from V409 to V410
2606 */
2607 static BOOL H_UpgradeFromV409(int currVersion, int newVersion)
2608 {
2609 static const TCHAR *batch =
2610 _T("ALTER TABLE zones ADD ssh_proxy integer\n")
2611 _T("UPDATE zones SET ssh_proxy=0\n")
2612 _T("ALTER TABLE nodes ADD ssh_login varchar(63)\n")
2613 _T("ALTER TABLE nodes ADD ssh_password varchar(63)\n")
2614 _T("ALTER TABLE nodes ADD ssh_proxy integer\n")
2615 _T("UPDATE nodes SET ssh_proxy=0\n")
2616 _T("<END>");
2617 CHK_EXEC(SQLBatch(batch));
2618
2619 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("nodes"), _T("ssh_proxy")));
2620 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("zones"), _T("ssh_proxy")));
2621
2622 CHK_EXEC(SetSchemaVersion(410));
2623 return TRUE;
2624 }
2625
2626 /**
2627 * Upgrade from V408 to V409
2628 */
2629 static BOOL H_UpgradeFromV408(int currVersion, int newVersion)
2630 {
2631 static const TCHAR *batch =
2632 _T("ALTER TABLE nodes ADD node_type integer\n")
2633 _T("ALTER TABLE nodes ADD node_subtype varchar(127)\n")
2634 _T("UPDATE nodes SET node_type=0\n")
2635 _T("<END>");
2636 CHK_EXEC(SQLBatch(batch));
2637
2638 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("nodes"), _T("node_type")));
2639
2640 CHK_EXEC(SetSchemaVersion(409));
2641 return TRUE;
2642 }
2643
2644 /**
2645 * Upgrade from V407 to V408
2646 */
2647 static BOOL H_UpgradeFromV407(int currVersion, int newVersion)
2648 {
2649 CHK_EXEC(CreateTable(
2650 _T("CREATE TABLE chassis (")
2651 _T(" id integer not null,")
2652 _T(" flags integer not null,")
2653 _T(" controller_id integer not null,")
2654 _T(" rack_id integer not null,")
2655 _T(" rack_image varchar(36) null,")
2656 _T(" rack_position integer not null,")
2657 _T(" rack_height integer not null,")
2658 _T(" PRIMARY KEY(id))")
2659 ));
2660
2661 static const TCHAR *batch =
2662 _T("ALTER TABLE nodes ADD chassis_id integer\n")
2663 _T("UPDATE nodes SET chassis_id=0\n")
2664 _T("<END>");
2665 CHK_EXEC(SQLBatch(batch));
2666
2667 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("nodes"), _T("chassis_id")));
2668
2669 CHK_EXEC(SetSchemaVersion(408));
2670 return TRUE;
2671 }
2672
2673 /**
2674 * Upgrade from V406 to V407
2675 */
2676 static BOOL H_UpgradeFromV406(int currVersion, int newVersion)
2677 {
2678 DBResizeColumn(g_hCoreDB, _T("user_groups"), _T("ldap_unique_id"), 64, true);
2679 CHK_EXEC(SetSchemaVersion(407));
2680 return TRUE;
2681 }
2682
2683 /**
2684 * Upgrade from V405 to V406
2685 */
2686 static BOOL H_UpgradeFromV405(int currVersion, int newVersion)
2687 {
2688 static const TCHAR *batch =
2689 _T("ALTER TABLE nodes ADD syslog_msg_count $SQL:INT64\n")
2690 _T("ALTER TABLE nodes ADD snmp_trap_count $SQL:INT64\n")
2691 _T("UPDATE nodes SET syslog_msg_count=0,snmp_trap_count=0\n")
2692 _T("<END>");
2693 CHK_EXEC(SQLBatch(batch));
2694 CHK_EXEC(SetSchemaVersion(406));
2695 return TRUE;
2696 }
2697
2698 /**
2699 * Upgrade from V404 to V405
2700 */
2701 static BOOL H_UpgradeFromV404(int currVersion, int newVersion)
2702 {
2703 CHK_EXEC(CreateEventTemplate(EVENT_AGENT_LOG_PROBLEM, _T("SYS_AGENT_LOG_PROBLEM"),
2704 SEVERITY_MAJOR, EF_LOG, _T("262057ca-357a-4a4d-9b78-42ae96e490a1"),
2705 _T("Problem with agent log: %2"),
2706 _T("Generated on status poll if agent reports problem with log file.\r\n")
2707 _T("Parameters:\r\n")
2708 _T(" 1) Status code\r\n")
2709 _T(" 2) Description")));
2710 CHK_EXEC(CreateEventTemplate(EVENT_AGENT_LOCAL_DATABASE_PROBLEM, _T("SYS_AGENT_LOCAL_DATABASE_PROBLEM"),
2711 SEVERITY_MAJOR, EF_LOG, _T("d02b63f1-1151-429e-adb9-1dfbb3a31b32"),
2712 _T("Problem with agent local database: %2"),
2713 _T("Generated on status poll if agent reports local database problem.\r\n")
2714 _T("Parameters:\r\n")
2715 _T(" 1) Status code\r\n")
2716 _T(" 2) Description")));
2717
2718 int ruleId = NextFreeEPPruleID();
2719 TCHAR query[1024];
2720 _sntprintf(query, 1024, _T("INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) ")
2721 _T("VALUES (%d,'19bd89ba-8bb2-4915-8546-a1ecc650dedd',7944,'Generate an alarm when there is problem with agent log','%%m',5,'SYS_AGENT_LOG_PROBLEM_%%i','',0,%d,0,'')"),
2722 ruleId, EVENT_ALARM_TIMEOUT);
2723 CHK_EXEC(SQLQuery(query));
2724 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_AGENT_LOG_PROBLEM);
2725 CHK_EXEC(SQLQuery(query));
2726
2727 ruleId = NextFreeEPPruleID();
2728 _sntprintf(query, 1024, _T("INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) ")
2729 _T("VALUES (%d,'cff7fe6b-2ad1-4c18-8a8f-4d397d44fe04',7944,'Generate an alarm when there is problem with agent local database','%%m',5,'SYS_AGENT_LOCAL_DATABASE_PROBLEM_%%i','',0,%d,0,'')"),
2730 ruleId, EVENT_ALARM_TIMEOUT);
2731 CHK_EXEC(SQLQuery(query));
2732 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_AGENT_LOCAL_DATABASE_PROBLEM);
2733 CHK_EXEC(SQLQuery(query));
2734
2735 CHK_EXEC(SetSchemaVersion(405));
2736 return TRUE;
2737 }
2738
2739 /**
2740 * Upgrade from V403 to V404
2741 */
2742 static BOOL H_UpgradeFromV403(int currVersion, int newVersion)
2743 {
2744 CHK_EXEC(CreateConfigParam(_T("SyslogIgnoreMessageTimestamp"), _T("0"),
2745 _T("Ignore timestamp received in syslog messages and always use server time"),
2746 'B', true, false, false, false));
2747 CHK_EXEC(SetSchemaVersion(404));
2748 return TRUE;
2749 }
2750
2751 /**
2752 * Upgrade from V402 to V403
2753 */
2754 static BOOL H_UpgradeFromV402(int currVersion, int newVersion)
2755 {
2756 CHK_EXEC(SQLQuery(_T("DROP TABLE policy_time_range_list")));
2757 CHK_EXEC(SQLQuery(_T("DROP TABLE time_ranges")));
2758 CHK_EXEC(SetSchemaVersion(403));
2759 return TRUE;
2760 }
2761
2762 /**
2763 * Upgrade from V401 to V402
2764 */
2765 static BOOL H_UpgradeFromV401(int currVersion, int newVersion)
2766 {
2767 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_event_log_source ON event_log(event_source)")));
2768 CHK_EXEC(SetSchemaVersion(402));
2769 return TRUE;
2770 }
2771
2772 /**
2773 * Upgrade from V400 to V401
2774 */
2775 static BOOL H_UpgradeFromV400(int currVersion, int newVersion)
2776 {
2777 CHK_EXEC(CreateEventTemplate(EVENT_LDAP_SYNC_ERROR, _T("SYS_LDAP_SYNC_ERROR"),
2778 SEVERITY_MAJOR, EF_LOG, _T("f7e8508d-1503-4736-854b-1e5b8b0ad1f2"),
2779 _T("LDAP sync error: %5"),
2780 _T("Generated when LDAP synchronization error occurs.\r\n")
2781 _T("Parameters:\r\n")
2782 _T(" 1) User ID\r\n")
2783 _T(" 2) User GUID\r\n")
2784 _T(" 3) User LDAP DN\r\n")
2785 _T(" 4) User name\r\n")
2786 _T(" 5) Problem description")));
2787
2788 int ruleId = NextFreeEPPruleID();
2789 TCHAR query[1024];
2790 _sntprintf(query, 1024, _T("INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) VALUES (%d,'417648af-5361-49a5-9471-6ef31e857b2d',7944,'Generate an alarm when error occurred during LDAP synchronization','%%m',5,'SYS_LDAP_SYNC_ERROR_%%2','',0,%d,0,'')"), ruleId, EVENT_ALARM_TIMEOUT);
2791 CHK_EXEC(SQLQuery(query));
2792 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_LDAP_SYNC_ERROR);
2793 CHK_EXEC(SQLQuery(query));
2794
2795 CHK_EXEC(SQLQuery(_T("ALTER TABLE users ADD ldap_unique_id varchar(64)")));
2796 CHK_EXEC(SQLQuery(_T("ALTER TABLE user_groups ADD ldap_unique_id varchar(64)")));
2797 CHK_EXEC(CreateConfigParam(_T("LdapUserUniqueId"), _T(""), true, false, false));
2798 CHK_EXEC(CreateConfigParam(_T("LdapGroupUniqueId"), _T(""), true, false, false));
2799
2800 CHK_EXEC(SetSchemaVersion(401));
2801 return TRUE;
2802 }
2803
2804 /**
2805 * Upgrade from V399 to V400
2806 */
2807 static BOOL H_UpgradeFromV399(int currVersion, int newVersion)
2808 {
2809 CHK_EXEC(CreateConfigParam(_T("JobRetryCount"), _T("5"), _T("Maximum mumber of job execution retrys"), 'I', true, false, false, false));
2810 CHK_EXEC(SetSchemaVersion(400));
2811 return TRUE;
2812 }
2813
2814 /**
2815 * Upgrade from V398 to V399
2816 */
2817 static BOOL H_UpgradeFromV398(int currVersion, int newVersion)
2818 {
2819 CHK_EXEC(CreateTable(
2820 _T("CREATE TABLE config_repositories (")
2821 _T(" id integer not null,")
2822 _T(" url varchar(1023) not null,")
2823 _T(" auth_token varchar(63) null,")
2824 _T(" description varchar(1023) null,")
2825 _T(" PRIMARY KEY(id))")
2826 ));
2827
2828 CHK_EXEC(SetSchemaVersion(399));
2829 return TRUE;
2830 }
2831
2832 /**
2833 * Upgrade from V397 to V398
2834 */
2835 static BOOL H_UpgradeFromV397(int currVersion, int newVersion)
2836 {
2837 CHK_EXEC(CreateTable(
2838 _T("CREATE TABLE currency_codes (")
2839 _T(" numeric_code char(3) not null,")
2840 _T(" alpha_code char(3) not null,")
2841 _T(" description varchar(127) not null,")
2842 _T(" exponent integer not null,")
2843 _T(" PRIMARY KEY(numeric_code))")
2844 ));
2845
2846 CHK_EXEC(CreateTable(
2847 _T("CREATE TABLE country_codes (")
2848 _T(" numeric_code char(3) not null,")
2849 _T(" alpha_code char(2) not null,")
2850 _T(" alpha3_code char(3) not null,")
2851 _T(" name varchar(127) not null,")
2852 _T(" PRIMARY KEY(numeric_code))")
2853 ));
2854
2855 static const TCHAR *batch1 =
2856 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('008', 'ALL', 'Lek', 2)\n")
2857 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('012', 'DZD', 'Algerian Dinar', 2)\n")
2858 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('031', 'AZM', 'Azerbaijanian Manat', 0)\n")
2859 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('032', 'ARS', 'Argentine Peso', 2)\n")
2860 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('036', 'AUD', 'Australian Dollar', 2)\n")
2861 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('044', 'BSD', 'Bahamian Dollar', 2)\n")
2862 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('048', 'BHD', 'Bahraini Dinar', 3)\n")
2863 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('050', 'BDT', 'Taka', 2)\n")
2864 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('051', 'AMD', 'Armenian Dram', 2)\n")
2865 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('052', 'BBD', 'Barbados Dollar', 2)\n")
2866 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('060', 'BMD', 'Bermudian Dollar', 2)\n")
2867 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('064', 'BTN', 'Ngultrum', 2)\n")
2868 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('068', 'BOB', 'Boliviano', 2)\n")
2869 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('072', 'BWP', 'Pula', 2)\n")
2870 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('084', 'BZD', 'Belize Dollar', 2)\n")
2871 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('090', 'SBD', 'Solomon Islands Dollar', 2)\n")
2872 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('096', 'BND', 'Brunei Dollar', 2)\n")
2873 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('100', 'BGL', 'Lev', 0)\n")
2874 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('104', 'MMK', 'Kyat', 2)\n")
2875 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('108', 'BIF', 'Burundi Franc', 0)\n")
2876 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('116', 'KHR', 'Riel', 2)\n")
2877 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('124', 'CAD', 'Canadian Dollar', 2)\n")
2878 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('132', 'CVE', 'Cape Verde Escudo', 2)\n")
2879 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('136', 'KYD', 'Cayman Islands Dollar', 2)\n")
2880 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('144', 'LKR', 'Sri Lanka Rupee', 2)\n")
2881 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('152', 'CLP', 'Chilean Peso', 0)\n")
2882 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('156', 'CNY', 'Yuan Renminbi', 2)\n")
2883 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('170', 'COP', 'Colombian Peso', 2)\n")
2884 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('174', 'KMF', 'Comoro Franc', 0)\n")
2885 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('188', 'CRC', 'Costa Rican Colon', 2)\n")
2886 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('191', 'HRK', 'Croatian Kuna', 2)\n")
2887 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('192', 'CUP', 'Cuban Peso', 2)\n")
2888 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('196', 'CYP', 'Cyprus Pound', 0)\n")
2889 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('203', 'CZK', 'Czech Koruna', 2)\n")
2890 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('208', 'DKK', 'Danish Krone', 2)\n")
2891 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('214', 'DOP', 'Dominican Peso', 2)\n")
2892 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('222', 'SVC', 'El Salvador Colon', 2)\n")
2893 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('230', 'ETB', 'Ethiopian Birr', 2)\n")
2894 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('232', 'ERN', 'Nakfa', 2)\n")
2895 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('233', 'EEK', 'Estonian Kroon', 0)\n")
2896 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('238', 'FKP', 'Falkland Islands Pound', 2)\n")
2897 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('242', 'FJD', 'Fiji Dollar', 2)\n")
2898 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('262', 'DJF', 'Djibouti Franc', 0)\n")
2899 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('270', 'GMD', 'Dalasi', 2)\n")
2900 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('288', 'GHC', 'Cedi', 0)\n")
2901 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('292', 'GIP', 'Gibraltar Pound', 2)\n")
2902 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('320', 'GTQ', 'Quetzal', 2)\n")
2903 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('324', 'GNF', 'Guinea Franc', 0)\n")
2904 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('328', 'GYD', 'Guyana Dollar', 2)\n")
2905 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('332', 'HTG', 'Gourde', 2)\n")
2906 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('340', 'HNL', 'Lempira', 2)\n")
2907 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('344', 'HKD', 'Hong Kong Dollar', 2)\n")
2908 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('348', 'HUF', 'Forint', 2)\n")
2909 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('352', 'ISK', 'Iceland Krona', 0)\n")
2910 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('356', 'INR', 'Indian Rupee', 2)\n")
2911 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('360', 'IDR', 'Rupiah', 2)\n")
2912 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('364', 'IRR', 'Iranian Rial', 2)\n")
2913 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('368', 'IQD', 'Iraqi Dinar', 3)\n")
2914 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('376', 'ILS', 'New Israeli Sheqel', 2)\n")
2915 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('388', 'JMD', 'Jamaican Dollar', 2)\n")
2916 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('392', 'JPY', 'Yen', 0)\n")
2917 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('398', 'KZT', 'Tenge', 2)\n")
2918 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('400', 'JOD', 'Jordanian Dinar', 3)\n")
2919 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('404', 'KES', 'Kenyan Shilling', 2)\n")
2920 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('408', 'KPW', 'North Korean Won', 2)\n")
2921 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('410', 'KRW', 'Won', 0)\n")
2922 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('414', 'KWD', 'Kuwaiti Dinar', 3)\n")
2923 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('417', 'KGS', 'Som', 2)\n")
2924 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('418', 'LAK', 'Kip', 2)\n")
2925 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('422', 'LBP', 'Lebanese Pound', 2)\n")
2926 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('426', 'LSL', 'Lesotho Loti', 2)\n")
2927 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('428', 'LVL', 'Latvian Lats', 2)\n")
2928 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('430', 'LRD', 'Liberian Dollar', 2)\n")
2929 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('434', 'LYD', 'Lybian Dinar', 3)\n")
2930 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('440', 'LTL', 'Lithuanian Litas', 2)\n")
2931 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('446', 'MOP', 'Pataca', 2)\n")
2932 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('450', 'MGF', 'Malagasy Franc', 0)\n")
2933 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('454', 'MWK', 'Kwacha', 2)\n")
2934 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('458', 'MYR', 'Malaysian Ringgit', 2)\n")
2935 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('462', 'MVR', 'Rufiyaa', 2)\n")
2936 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('470', 'MTL', 'Maltese Lira', 0)\n")
2937 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('478', 'MRO', 'Ouguiya', 2)\n")
2938 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('480', 'MUR', 'Mauritius Rupee', 2)\n")
2939 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('484', 'MXN', 'Mexican Peso', 2)\n")
2940 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('496', 'MNT', 'Tugrik', 2)\n")
2941 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('498', 'MDL', 'Moldovan Leu', 2)\n")