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