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