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