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