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