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