added option to read interfaces from all zones
[public/netxms.git] / src / server / tools / nxdbmgr / upgrade.cpp
CommitLineData
5039dede
AK
1/*
2** nxdbmgr - NetXMS database manager
c29fb885 3** Copyright (C) 2004-2012 Victor Kirhenshtein
5039dede
AK
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
7a41a06e
VK
26//
27// Externals
28//
29
30BOOL MigrateMaps();
31
ae2a3458 32
5039dede
AK
33//
34// Create table
35//
36
37static BOOL CreateTable(const TCHAR *pszQuery)
38{
5039dede 39 BOOL bResult;
7618e362 40 String query(pszQuery);
5039dede 41
7618e362 42 query.translate(_T("$SQL:TEXT"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]);
e4acd770 43 query.translate(_T("$SQL:TXT4K"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT4K]);
7618e362 44 query.translate(_T("$SQL:INT64"), g_pszSqlType[g_iSyntax][SQL_TYPE_INT64]);
5039dede 45 if (g_iSyntax == DB_SYNTAX_MYSQL)
7618e362
VK
46 query += g_pszTableSuffix;
47 bResult = SQLQuery(query);
5039dede
AK
48 return bResult;
49}
50
51
52//
53// Create configuration parameter if it doesn't exist (unless bForceUpdate set to true)
54//
55
a43a5e7d
VK
56BOOL CreateConfigParam(const TCHAR *pszName, const TCHAR *pszValue,
57 int iVisible, int iNeedRestart, BOOL bForceUpdate)
5039dede
AK
58{
59 TCHAR szQuery[1024], *pszEscValue;
60 DB_RESULT hResult;
61 BOOL bVarExist = FALSE, bResult = TRUE;
62
63 // Check for variable existence
08b214c6 64 _sntprintf(szQuery, 1024, _T("SELECT var_value FROM config WHERE var_name='%s'"), pszName);
5039dede
AK
65 hResult = DBSelect(g_hCoreDB, szQuery);
66 if (hResult != 0)
67 {
68 if (DBGetNumRows(hResult) > 0)
69 bVarExist = TRUE;
70 DBFreeResult(hResult);
71 }
72
73 if (!bVarExist)
74 {
75 pszEscValue = EncodeSQLString(pszValue);
08b214c6
VK
76 _sntprintf(szQuery, 1024, _T("INSERT INTO config (var_name,var_value,is_visible,")
77 _T("need_server_restart) VALUES ('%s','%s',%d,%d)"),
5039dede
AK
78 pszName, pszEscValue, iVisible, iNeedRestart);
79 free(pszEscValue);
80 bResult = SQLQuery(szQuery);
81 }
82 else if (bForceUpdate)
83 {
84 pszEscValue = EncodeSQLString(pszValue);
08b214c6 85 _sntprintf(szQuery, 1024, _T("UPDATE config SET var_value='%s' WHERE var_name='%s'"),
5039dede
AK
86 pszEscValue, pszName);
87 free(pszEscValue);
88 bResult = SQLQuery(szQuery);
89 }
90 return bResult;
91}
92
93
94//
95// Set primary key constraint
96//
97
98static BOOL SetPrimaryKey(const TCHAR *table, const TCHAR *key)
99{
100 TCHAR query[4096];
101
102 if (g_iSyntax == DB_SYNTAX_SQLITE)
103 return TRUE; // SQLite does not support adding constraints
104
105 _sntprintf(query, 4096, _T("ALTER TABLE %s ADD PRIMARY KEY (%s)"), table, key);
106 return SQLQuery(query);
107}
108
109
9bfc9a6b
VK
110//
111// Drop primary key from table
112//
113
114static BOOL DropPrimaryKey(const TCHAR *table)
115{
116 TCHAR query[1024];
117 DB_RESULT hResult;
118 BOOL success;
119
120 switch(g_iSyntax)
121 {
122 case DB_SYNTAX_ORACLE:
123 case DB_SYNTAX_MYSQL:
124 _sntprintf(query, 1024, _T("ALTER TABLE %s DROP PRIMARY KEY"), table);
125 success = SQLQuery(query);
126 break;
127 case DB_SYNTAX_PGSQL:
128 _sntprintf(query, 1024, _T("ALTER TABLE %s DROP CONSTRAINT %s_pkey"), table, table);
129 success = SQLQuery(query);
130 break;
131 case DB_SYNTAX_MSSQL:
132 success = FALSE;
133 _sntprintf(query, 1024, _T("SELECT name FROM sysobjects WHERE xtype='PK' AND parent_obj=OBJECT_ID('%s')"), table);
134 hResult = SQLSelect(query);
135 if (hResult != NULL)
136 {
137 if (DBGetNumRows(hResult) > 0)
138 {
139 TCHAR objName[512];
140
141 DBGetField(hResult, 0, 0, objName, 512);
142 _sntprintf(query, 1024, _T("ALTER TABLE %s DROP CONSTRAINT %s"), table, objName);
143 success = SQLQuery(query);
144 }
145 DBFreeResult(hResult);
146 }
147 break;
148 default: // Unsupported DB engine
149 success = FALSE;
150 break;
151 }
152 return success;
153}
154
1b94acbf 155
643c9dcb 156//
83f4afe0 157// Convert strings from # encoded form to normal form
643c9dcb
VK
158//
159
98cd01bb 160static BOOL ConvertStrings(const TCHAR *table, const TCHAR *idColumn, const TCHAR *idColumn2, const TCHAR *column)
643c9dcb
VK
161{
162 DB_RESULT hResult;
163 TCHAR *query;
164 int queryLen = 512;
165 BOOL success = FALSE;
166
c29fb885 167 query = (TCHAR *)malloc(queryLen * sizeof(TCHAR));
fe12a1ea 168
a4743a0f
VK
169 switch(g_iSyntax)
170 {
171 case DB_SYNTAX_MSSQL:
9f6712bc 172 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE CAST(%s AS nvarchar(4000))=N'#00'"), table, column, column);
a4743a0f
VK
173 break;
174 case DB_SYNTAX_ORACLE:
175 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE to_char(%s)='#00'"), table, column, column);
176 break;
177 default:
178 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE %s='#00'"), table, column, column);
179 break;
180 }
fe12a1ea
VK
181 if (!SQLQuery(query))
182 {
183 free(query);
184 return FALSE;
185 }
186
98cd01bb
VK
187 _sntprintf(query, queryLen, _T("SELECT %s,%s%s%s FROM %s WHERE %s LIKE '%%#%%'"),
188 idColumn, column, (idColumn2 != NULL) ? _T(",") : _T(""), (idColumn2 != NULL) ? idColumn2 : _T(""), table, column);
643c9dcb
VK
189 hResult = SQLSelect(query);
190 if (hResult == NULL)
191 {
192 free(query);
193 return FALSE;
194 }
195
196 int count = DBGetNumRows(hResult);
197 for(int i = 0; i < count; i++)
198 {
643c9dcb 199 TCHAR *value = DBGetField(hResult, i, 1, NULL, 0);
035a4d73 200 if (_tcschr(value, _T('#')) != NULL)
643c9dcb 201 {
035a4d73
VK
202 DecodeSQLString(value);
203 String newValue = DBPrepareString(g_hCoreDB, value);
204 if ((int)newValue.getSize() + 256 > queryLen)
205 {
206 queryLen = newValue.getSize() + 256;
c29fb885 207 query = (TCHAR *)realloc(query, queryLen * sizeof(TCHAR));
035a4d73 208 }
98cd01bb
VK
209 INT64 id = DBGetFieldInt64(hResult, i, 0);
210 if (idColumn2 != NULL)
211 {
212 INT64 id2 = DBGetFieldInt64(hResult, i, 2);
213 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=") INT64_FMT _T(" AND %s=") INT64_FMT,
214 table, column, (const TCHAR *)newValue, idColumn, id, idColumn2, id2);
215 }
216 else
217 {
218 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=") INT64_FMT, table, column,
219 (const TCHAR *)newValue, idColumn, id);
220 }
035a4d73
VK
221 if (!SQLQuery(query))
222 goto cleanup;
643c9dcb 223 }
643c9dcb
VK
224 }
225 success = TRUE;
226
227cleanup:
228 DBFreeResult(hResult);
a4743a0f 229 free(query);
643c9dcb
VK
230 return success;
231}
232
98cd01bb
VK
233static BOOL ConvertStrings(const TCHAR *table, const TCHAR *idColumn, const TCHAR *column)
234{
235 return ConvertStrings(table, idColumn, NULL, column);
236}
237
643c9dcb 238
1024e962
VK
239//
240// Set column nullable (currently Oracle only implementation)
241//
242
243static BOOL SetColumnNullable(const TCHAR *table, const TCHAR *column, const TCHAR *type)
244{
245 TCHAR query[1024] = _T("");
246
247 switch(g_iSyntax)
248 {
249 case DB_SYNTAX_ORACLE:
250 _sntprintf(query, 1024, _T("DECLARE already_null EXCEPTION; ")
251 _T("PRAGMA EXCEPTION_INIT(already_null, -1451); ")
f57209fd
VK
252 _T("BEGIN EXECUTE IMMEDIATE 'ALTER TABLE %s MODIFY %s null'; ")
253 _T("EXCEPTION WHEN already_null THEN null; END;"), table, column);
1024e962
VK
254 break;
255 default:
256 break;
257 }
258
259 return (query[0] != 0) ? SQLQuery(query) : TRUE;
260}
261
262
aa16f82b
VK
263//
264// Create new event template
265//
266
267static BOOL CreateEventTemplate(int code, const TCHAR *name, int severity, int flags, const TCHAR *message, const TCHAR *description)
268{
269 TCHAR query[4096], *escMessage, *escDescription;
270
271 escMessage = EncodeSQLString(message);
272 escDescription = EncodeSQLString(description);
273 _sntprintf(query, 4096, _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (%d,'%s',%d,%d,'%s','%s')"),
274 code, name, severity, flags, escMessage, escDescription);
275 free(escMessage);
276 free(escDescription);
277 return SQLQuery(query);
278}
279
a203ea53
AK
280//
281// Upgrade from V259 to V260
282//
283
284static BOOL H_UpgradeFromV259(int currVersion, int newVersion)
285{
286 CreateConfigParam(_T("UseFQDNForNodeNames"), _T("1"), 1, 1);
287 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='260' WHERE var_name='SchemaVersion'")));
288 return TRUE;
289}
290
5da6ca46
VK
291//
292// Upgrade from V258 to V259
293//
294
295static BOOL H_UpgradeFromV258(int currVersion, int newVersion)
296{
297 // have to made these columns nullable again because
298 // because they was forgotten as NOT NULL in schema.in
299 // and so some databases can still have them as NOT NULL
300 CHK_EXEC(SetColumnNullable(_T("templates"), _T("apply_filter"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]));
301 CHK_EXEC(SetColumnNullable(_T("containers"), _T("auto_bind_filter"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]));
302
303 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='259' WHERE var_name='SchemaVersion'")));
304 return TRUE;
305}
306
307
dd42ad0a
AK
308//
309// Upgrade from V257 to V258
310//
311
312static BOOL H_UpgradeFromV257(int currVersion, int newVersion)
313{
314 static TCHAR batch[] =
315 _T("ALTER TABLE nodes ADD down_since integer\n")
316 _T("UPDATE nodes SET down_since=0\n")
317 _T("<END>");
318
319 CHK_EXEC(SQLBatch(batch));
320
321 CreateConfigParam(_T("DeleteUnreachableNodesPeriod"), _T("0"), 1, 1);
322
323 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='258' WHERE var_name='SchemaVersion'")));
324 return TRUE;
325}
aa16f82b 326
e4acd770
VK
327//
328// Upgrade from V256 to V257
329//
330
331static BOOL H_UpgradeFromV256(int currVersion, int newVersion)
332{
333 static TCHAR batch[] =
334 _T("ALTER TABLE network_maps ADD bg_color integer\n")
335 _T("ALTER TABLE network_maps ADD link_routing integer\n")
336 _T("UPDATE network_maps SET bg_color=16777215,link_routing=1\n")
337 _T("ALTER TABLE network_map_links ADD routing integer\n")
338 _T("ALTER TABLE network_map_links ADD bend_points $SQL:TXT4K\n")
339 _T("UPDATE network_map_links SET routing=0\n")
340 _T("<END>");
341
342 CHK_EXEC(SQLBatch(batch));
343
344 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='257' WHERE var_name='SchemaVersion'")));
345 return TRUE;
346}
347
348
aabe5b72
VK
349//
350// Upgrade from V255 to V256
351//
352
353static BOOL H_UpgradeFromV255(int currVersion, int newVersion)
354{
355 CreateConfigParam(_T("DefaultConsoleDateFormat"), _T("dd.MM.yyyy"), 1, 0);
356 CreateConfigParam(_T("DefaultConsoleTimeFormat"), _T("HH:mm:ss"), 1, 0);
357
358 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='256' WHERE var_name='SchemaVersion'")));
359 return TRUE;
360}
361
362
5f6bc78c
VK
363//
364// Upgrade from V254 to V255
365//
366
367static BOOL H_UpgradeFromV254(int currVersion, int newVersion)
368{
369 static TCHAR batch[] =
370 _T("ALTER TABLE alarms ADD resolved_by integer\n")
371 _T("UPDATE alarms SET resolved_by=0\n")
372 _T("UPDATE alarms SET alarm_state=3 WHERE alarm_state=2\n")
373 _T("<END>");
374
375 CHK_EXEC(SQLBatch(batch));
376
3e9e0cc5 377 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='255' WHERE var_name='SchemaVersion'")));
5f6bc78c
VK
378 return TRUE;
379}
40647141
VK
380
381
382//
383// Upgrade from V253 to V254
384//
385
386static BOOL H_UpgradeFromV253(int currVersion, int newVersion)
387{
388 static TCHAR batch[] =
389 _T("ALTER TABLE network_maps ADD flags integer\n")
390 _T("ALTER TABLE network_maps ADD link_color integer\n")
391 _T("UPDATE network_maps SET flags=1,link_color=-1\n")
392 _T("ALTER TABLE network_map_links ADD color integer\n")
393 _T("ALTER TABLE network_map_links ADD status_object integer\n")
394 _T("UPDATE network_map_links SET color=-1,status_object=0\n")
395 _T("<END>");
396
397 CHK_EXEC(SQLBatch(batch));
398
399 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='254' WHERE var_name='SchemaVersion'")));
400 return TRUE;
401}
402
403
feab3324
VK
404//
405// Upgrade from V252 to V253
406//
407
408static BOOL H_UpgradeFromV252(int currVersion, int newVersion)
409{
242e9c7f
VK
410 CHK_EXEC(SetColumnNullable(_T("templates"), _T("apply_filter"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]));
411 CHK_EXEC(ConvertStrings(_T("templates"), _T("id"), _T("apply_filter")));
412
413 CHK_EXEC(SetColumnNullable(_T("containers"), _T("auto_bind_filter"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]));
414 CHK_EXEC(ConvertStrings(_T("containers"), _T("id"), _T("auto_bind_filter")));
415
feab3324
VK
416 static TCHAR batch[] =
417 _T("ALTER TABLE templates ADD flags integer\n")
2984ac95
VK
418 _T("UPDATE templates SET flags=0 WHERE enable_auto_apply=0\n")
419 _T("UPDATE templates SET flags=3 WHERE enable_auto_apply<>0\n")
feab3324
VK
420 _T("ALTER TABLE templates DROP COLUMN enable_auto_apply\n")
421 _T("ALTER TABLE containers ADD flags integer\n")
2984ac95
VK
422 _T("UPDATE containers SET flags=0 WHERE enable_auto_bind=0\n")
423 _T("UPDATE containers SET flags=3 WHERE enable_auto_bind<>0\n")
feab3324
VK
424 _T("ALTER TABLE containers DROP COLUMN enable_auto_bind\n")
425 _T("<END>");
feab3324
VK
426 CHK_EXEC(SQLBatch(batch));
427
428 CHK_EXEC(CreateEventTemplate(EVENT_CONTAINER_AUTOBIND, _T("SYS_CONTAINER_AUTOBIND"), EVENT_SEVERITY_NORMAL, 1,
429 _T("Node %2 automatically bound to container %4"),
430 _T("Generated when node bound to container object by autobind rule.\r\n")
431 _T("Parameters:#\r\n")
432 _T(" 1) Node ID\r\n")
433 _T(" 2) Node name\r\n")
434 _T(" 3) Container ID\r\n")
435 _T(" 4) Container name")
436 ));
437
438 CHK_EXEC(CreateEventTemplate(EVENT_CONTAINER_AUTOUNBIND, _T("SYS_CONTAINER_AUTOUNBIND"), EVENT_SEVERITY_NORMAL, 1,
439 _T("Node %2 automatically unbound from container %4"),
440 _T("Generated when node unbound from container object by autobind rule.\r\n")
441 _T("Parameters:#\r\n")
442 _T(" 1) Node ID\r\n")
443 _T(" 2) Node name\r\n")
444 _T(" 3) Container ID\r\n")
445 _T(" 4) Container name")
446 ));
447
448 CHK_EXEC(CreateEventTemplate(EVENT_TEMPLATE_AUTOAPPLY, _T("SYS_TEMPLATE_AUTOAPPLY"), EVENT_SEVERITY_NORMAL, 1,
449 _T("Template %4 automatically applied to node %2"),
450 _T("Generated when template applied to node by autoapply rule.\r\n")
451 _T("Parameters:#\r\n")
452 _T(" 1) Node ID\r\n")
453 _T(" 2) Node name\r\n")
454 _T(" 3) Template ID\r\n")
455 _T(" 4) Template name")
456 ));
457
458 CHK_EXEC(CreateEventTemplate(EVENT_TEMPLATE_AUTOREMOVE, _T("SYS_TEMPLATE_AUTOREMOVE"), EVENT_SEVERITY_NORMAL, 1,
459 _T("Template %4 automatically removed from node %2"),
460 _T("Generated when template removed from node by autoapply rule.\r\n")
461 _T("Parameters:#\r\n")
462 _T(" 1) Node ID\r\n")
463 _T(" 2) Node name\r\n")
464 _T(" 3) Template ID\r\n")
465 _T(" 4) Template name")
466 ));
467
65790062
VK
468 TCHAR buffer[64];
469 _sntprintf(buffer, 64, _T("%d"), ConfigReadInt(_T("AllowedCiphers"), 15) + 16);
470 CreateConfigParam(_T("AllowedCiphers"), buffer, 1, 1, TRUE);
471
feab3324
VK
472 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='253' WHERE var_name='SchemaVersion'")));
473 return TRUE;
474}
475
476
1e6b68a6
VK
477//
478// Upgrade from V251 to V252
479//
480
481static BOOL H_UpgradeFromV251(int currVersion, int newVersion)
482{
483 static TCHAR batch[] =
484 _T("ALTER TABLE interfaces ADD admin_state integer\n")
485 _T("ALTER TABLE interfaces ADD oper_state integer\n")
486 _T("UPDATE interfaces SET admin_state=0,oper_state=0\n")
487 _T("<END>");
488
489 CHK_EXEC(SQLBatch(batch));
490
491 CHK_EXEC(CreateEventTemplate(EVENT_INTERFACE_UNEXPECTED_UP, _T("SYS_IF_UNEXPECTED_UP"), EVENT_SEVERITY_MAJOR, 1,
492 _T("Interface \"%2\" unexpectedly changed state to UP (IP Addr: %3/%4, IfIndex: %5)"),
493 _T("Generated when interface goes up but it's expected state set to DOWN.\r\n")
494 _T("Please note that source of event is node, not an interface itself.\r\n")
495 _T("Parameters:#\r\n")
496 _T(" 1) Interface object ID\r\n")
497 _T(" 2) Interface name\r\n")
498 _T(" 3) Interface IP address\r\n")
499 _T(" 4) Interface netmask\r\n")
500 _T(" 5) Interface index")
501 ));
502
503 CHK_EXEC(CreateEventTemplate(EVENT_INTERFACE_EXPECTED_DOWN, _T("SYS_IF_EXPECTED_DOWN"), EVENT_SEVERITY_NORMAL, 1,
504 _T("Interface \"%2\" with expected state DOWN changed state to DOWN (IP Addr: %3/%4, IfIndex: %5)"),
505 _T("Generated when interface goes down and it's expected state is DOWN.\r\n")
506 _T("Please note that source of event is node, not an interface itself.\r\n")
507 _T("Parameters:#\r\n")
508 _T(" 1) Interface object ID\r\n")
509 _T(" 2) Interface name\r\n")
510 _T(" 3) Interface IP address\r\n")
511 _T(" 4) Interface netmask\r\n")
512 _T(" 5) Interface index")
513 ));
514
515 // Create rule pair in event processing policy
516 int ruleId = 0;
517 DB_RESULT hResult = SQLSelect(_T("SELECT max(rule_id) FROM event_policy"));
518 if (hResult != NULL)
519 {
520 ruleId = DBGetFieldLong(hResult, 0, 0) + 1;
521 DBFreeResult(hResult);
522 }
523
524 TCHAR query[1024];
525 _sntprintf(query, 1024,
526 _T("INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,")
527 _T("script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) VALUES ")
528 _T("(%d,7944,'Show alarm when interface is unexpectedly up','%%m',5,'IF_UNEXP_UP_%%i_%%1',")
529 _T("'#00',0,%d,0,'#00')"), ruleId, EVENT_ALARM_TIMEOUT);
530 CHK_EXEC(SQLQuery(query));
531 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_INTERFACE_UNEXPECTED_UP);
532 CHK_EXEC(SQLQuery(query));
533 ruleId++;
534
535 _sntprintf(query, 1024,
536 _T("INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,")
537 _T("script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) VALUES ")
538 _T("(%d,7944,'Acknowlege interface unexpectedly up alarms when interface goes down','%%m',")
539 _T("6,'IF_UNEXP_UP_%%i_%%1','#00',0,%d,0,'#00')"), ruleId, EVENT_ALARM_TIMEOUT);
540 CHK_EXEC(SQLQuery(query));
541 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_INTERFACE_EXPECTED_DOWN);
542 CHK_EXEC(SQLQuery(query));
543
544 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='252' WHERE var_name='SchemaVersion'")));
545 return TRUE;
546}
547
548
711e5e9a
VK
549//
550// Upgrade from V250 to V251
551//
552
553static BOOL H_UpgradeFromV250(int currVersion, int newVersion)
554{
555 static TCHAR batch[] =
556 _T("ALTER TABLE thresholds ADD current_severity integer\n")
557 _T("ALTER TABLE thresholds ADD last_event_timestamp integer\n")
558 _T("UPDATE thresholds SET current_severity=0,last_event_timestamp=0\n")
559 _T("<END>");
560
561 CHK_EXEC(SQLBatch(batch));
562
563 CHK_EXEC(SetColumnNullable(_T("thresholds"), _T("fire_value"), _T("varchar(255)")));
564 CHK_EXEC(SetColumnNullable(_T("thresholds"), _T("rearm_value"), _T("varchar(255)")));
565 CHK_EXEC(ConvertStrings(_T("thresholds"), _T("threshold_id"), _T("fire_value")));
566 CHK_EXEC(ConvertStrings(_T("thresholds"), _T("threshold_id"), _T("rearm_value")));
567
568 CHK_EXEC(CreateConfigParam(_T("EnableNXSLContainerFunctions"), _T("1"), 1, 1));
569 CHK_EXEC(CreateConfigParam(_T("UseDNSNameForDiscoveredNodes"), _T("0"), 1, 0));
570 CHK_EXEC(CreateConfigParam(_T("AllowTrapVarbindsConversion"), _T("1"), 1, 1));
571
572 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='251' WHERE var_name='SchemaVersion'")));
573 return TRUE;
574}
575
576
ae2a3458
VK
577//
578// Upgrade from V249 to V250
579//
580
581static BOOL H_UpgradeFromV249(int currVersion, int newVersion)
582{
583 CHK_EXEC(CreateTable(_T("CREATE TABLE licenses (")
584 _T("id integer not null,")
585 _T("content $SQL:TEXT null,")
586 _T("PRIMARY KEY(id))")));
587
588 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='250' WHERE var_name='SchemaVersion'")));
589 return TRUE;
590}
591
592
d6124fa0
VK
593//
594// Upgrade from V248 to V249
595//
596
597#define TDATA_CREATE_QUERY _T("CREATE TABLE tdata_%d (item_id integer not null,tdata_timestamp integer not null,tdata_row integer not null,tdata_column integer not null,tdata_value varchar(255) null)")
598#define TDATA_INDEX_MSSQL _T("CREATE CLUSTERED INDEX idx_tdata_%d_id_timestamp ON tdata_%d(item_id,tdata_timestamp)")
599#define TDATA_INDEX_PGSQL _T("CREATE INDEX idx_tdata_%d_timestamp_id ON tdata_%d(tdata_timestamp,item_id)")
600#define TDATA_INDEX_DEFAULT _T("CREATE INDEX idx_tdata_%d_id_timestamp ON tdata_%d(item_id,tdata_timestamp)")
601
602static BOOL CreateTData(DWORD nodeId)
603{
604 TCHAR query[256];
605
606 _sntprintf(query, 256, TDATA_CREATE_QUERY, (int)nodeId);
607 CHK_EXEC(SQLQuery(query));
608
609 switch(g_iSyntax)
610 {
611 case DB_SYNTAX_MSSQL:
612 _sntprintf(query, 256, TDATA_INDEX_MSSQL, (int)nodeId, (int)nodeId);
613 break;
614 case DB_SYNTAX_PGSQL:
615 _sntprintf(query, 256, TDATA_INDEX_PGSQL, (int)nodeId, (int)nodeId);
616 break;
617 default:
618 _sntprintf(query, 256, TDATA_INDEX_DEFAULT, (int)nodeId, (int)nodeId);
619 break;
620 }
621 CHK_EXEC(SQLQuery(query));
622
623 return TRUE;
624}
625
626static BOOL H_UpgradeFromV248(int currVersion, int newVersion)
627{
628 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataTableCreationCommand','") TDATA_CREATE_QUERY _T("')")));
629
630 switch(g_iSyntax)
631 {
632 case DB_SYNTAX_MSSQL:
633 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataIndexCreationCommand_0','") TDATA_INDEX_MSSQL _T("')")));
634 break;
635 case DB_SYNTAX_PGSQL:
636 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataIndexCreationCommand_0','") TDATA_INDEX_PGSQL _T("')")));
637 break;
638 default:
639 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataIndexCreationCommand_0','") TDATA_INDEX_DEFAULT _T("')")));
640 break;
641 }
642
643 CHK_EXEC(CreateTable(_T("CREATE TABLE dct_column_names (")
644 _T("column_id integer not null,")
645 _T("column_name varchar(63) not null,")
646 _T("PRIMARY KEY(column_id))")));
647
648 DB_RESULT hResult = SQLSelect(_T("SELECT id FROM nodes"));
649 if (hResult != NULL)
650 {
651 int count = DBGetNumRows(hResult);
652 for(int i = 0 ; i < count; i++)
653 {
654 if (!CreateTData(DBGetFieldULong(hResult, i, 0)))
655 {
656 if (!g_bIgnoreErrors)
657 {
658 DBFreeResult(hResult);
659 return FALSE;
660 }
661 }
662 }
663 DBFreeResult(hResult);
664 }
665 else
666 {
667 if (!g_bIgnoreErrors)
668 return FALSE;
669 }
670
671 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='249' WHERE var_name='SchemaVersion'")));
672 return TRUE;
673}
674
675
cc8ce218
VK
676//
677// Upgrade from V247 to V248
678//
679
680static BOOL H_UpgradeFromV247(int currVersion, int newVersion)
681{
682 CHK_EXEC(CreateTable(_T("CREATE TABLE dc_tables (")
683 _T("item_id integer not null,")
684 _T("node_id integer not null,")
685 _T("template_id integer not null,")
686 _T("template_item_id integer not null,")
687 _T("name varchar(255) null,")
688 _T("instance_column varchar(63) null,")
689 _T("description varchar(255) null,")
690 _T("flags integer not null,")
691 _T("source integer not null,")
692 _T("snmp_port integer not null,")
693 _T("polling_interval integer not null,")
694 _T("retention_time integer not null,")
695 _T("status integer not null,")
696 _T("system_tag varchar(255) null,")
697 _T("resource_id integer not null,")
698 _T("proxy_node integer not null,")
699 _T("perftab_settings $SQL:TEXT null,")
700 _T("PRIMARY KEY(item_id))")));
701
702 CHK_EXEC(CreateTable(_T("CREATE TABLE dc_table_columns (")
703 _T("table_id integer not null,")
704 _T("column_name varchar(63) not null,")
705 _T("snmp_oid varchar(1023) null,")
706 _T("data_type integer not null,")
707 _T("transformation_script $SQL:TEXT null,")
708 _T("PRIMARY KEY(table_id,column_name))")));
709
710 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='248' WHERE var_name='SchemaVersion'")));
711 return TRUE;
712}
713
714
ff392ecf
VK
715//
716// Upgrade from V246 to V247
717//
718
719static BOOL H_UpgradeFromV246(int currVersion, int newVersion)
720{
721 static TCHAR insertQuery[] = _T("INSERT INTO object_custom_attributes (object_id,attr_name,attr_value) VALUES (?,?,?)");
722
723 CHK_EXEC(SetColumnNullable(_T("object_custom_attributes"), _T("attr_value"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]));
724
725 // Convert strings in object_custom_attributes table
726 DB_RESULT hResult = SQLSelect(_T("SELECT object_id,attr_name,attr_value FROM object_custom_attributes"));
727 if (hResult != NULL)
728 {
729 if (SQLQuery(_T("DELETE FROM object_custom_attributes")))
730 {
731 TCHAR errorText[DBDRV_MAX_ERROR_TEXT];
732 DB_STATEMENT hStmt = DBPrepareEx(g_hCoreDB, insertQuery, errorText);
733 if (hStmt != NULL)
734 {
735 TCHAR name[128], *value;
736 int count = DBGetNumRows(hResult);
737 for(int i = 0; i < count; i++)
738 {
739 DWORD id = DBGetFieldULong(hResult, i, 0);
740 DBGetField(hResult, i, 1, name, 128);
741 DecodeSQLString(name);
742 value = DBGetField(hResult, i, 2, NULL, 0);
743 DecodeSQLString(value);
744
745 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, id);
746 DBBind(hStmt, 2, DB_SQLTYPE_VARCHAR, name, DB_BIND_STATIC);
747 DBBind(hStmt, 3, DB_SQLTYPE_VARCHAR, value, DB_BIND_DYNAMIC);
748 if (g_bTrace)
749 ShowQuery(insertQuery);
750 if (!DBExecuteEx(hStmt, errorText))
751 {
752 WriteToTerminalEx(_T("SQL query failed (%s):\n\x1b[33;1m%s\x1b[0m\n"), errorText, insertQuery);
753 if (!g_bIgnoreErrors)
754 {
755 DBFreeStatement(hStmt);
756 DBFreeResult(hResult);
757 return FALSE;
758 }
759 }
760 }
761 DBFreeStatement(hStmt);
762 }
763 else
764 {
765 WriteToTerminalEx(_T("SQL query failed (%s):\n\x1b[33;1m%s\x1b[0m\n"), errorText, insertQuery);
766 if (!g_bIgnoreErrors)
767 {
768 DBFreeResult(hResult);
769 return FALSE;
770 }
771 }
772 }
773 else
774 {
775 if (!g_bIgnoreErrors)
776 {
777 DBFreeResult(hResult);
778 return FALSE;
779 }
780 }
781
782 DBFreeResult(hResult);
783 }
784 else
785 {
786 if (!g_bIgnoreErrors)
787 return FALSE;
788 }
789
790 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_ocattr_oid ON object_custom_attributes(object_id)")));
791 CHK_EXEC(CreateConfigParam(_T("AlarmHistoryRetentionTime"), _T("180"), 1, 0));
792
793 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='247' WHERE var_name='SchemaVersion'")));
794 return TRUE;
795}
796
797
98cd01bb
VK
798//
799// Upgrade from V245 to V246
800//
801
802static BOOL H_UpgradeFromV245(int currVersion, int newVersion)
803{
804 static TCHAR batch[] =
805 _T("ALTER TABLE snmp_trap_pmap ADD flags integer\n")
806 _T("UPDATE snmp_trap_pmap SET flags=0\n")
807 _T("<END>");
808
809 CHK_EXEC(SQLBatch(batch));
810
811 CHK_EXEC(SetColumnNullable(_T("snmp_trap_pmap"), _T("description"), _T("varchar(255)")));
812 CHK_EXEC(ConvertStrings(_T("snmp_trap_pmap"), _T("trap_id"), _T("parameter"), _T("description")));
813
814 CHK_EXEC(SetColumnNullable(_T("cluster_resources"), _T("resource_name"), _T("varchar(255)")));
815 CHK_EXEC(ConvertStrings(_T("cluster_resources"), _T("cluster_id"), _T("resource_id"), _T("resource_name")));
816
817 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='246' WHERE var_name='SchemaVersion'")));
818 return TRUE;
819}
820
821
4866d57b
VK
822//
823// Upgrade from V244 to V245
824//
825
826static BOOL H_UpgradeFromV244(int currVersion, int newVersion)
827{
828 static TCHAR batch[] =
829 _T("ALTER TABLE nodes ADD runtime_flags integer\n")
830 _T("UPDATE nodes SET runtime_flags=0\n")
831 _T("<END>");
832
833 CHK_EXEC(SQLBatch(batch));
834
835 CHK_EXEC(SetColumnNullable(_T("actions"), _T("rcpt_addr"), _T("varchar(255)")));
836 CHK_EXEC(SetColumnNullable(_T("actions"), _T("email_subject"), _T("varchar(255)")));
837 CHK_EXEC(SetColumnNullable(_T("actions"), _T("action_data"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]));
838
839 CHK_EXEC(ConvertStrings(_T("actions"), _T("action_id"), _T("rcpt_addr")));
840 CHK_EXEC(ConvertStrings(_T("actions"), _T("action_id"), _T("email_subject")));
841 CHK_EXEC(ConvertStrings(_T("actions"), _T("action_id"), _T("action_data")));
842
843 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='245' WHERE var_name='SchemaVersion'")));
844 return TRUE;
845}
846
847
aa16f82b
VK
848//
849// Upgrade from V243 to V244
850//
851
852static BOOL H_UpgradeFromV243(int currVersion, int newVersion)
853{
854 static TCHAR batch[] =
855 _T("ALTER TABLE interfaces ADD dot1x_pae_state integer\n")
856 _T("ALTER TABLE interfaces ADD dot1x_backend_state integer\n")
857 _T("UPDATE interfaces SET dot1x_pae_state=0,dot1x_backend_state=0\n")
858 _T("<END>");
859
860 CHK_EXEC(SQLBatch(batch));
861
862 CHK_EXEC(CreateEventTemplate(EVENT_8021X_PAE_STATE_CHANGED, _T("SYS_8021X_PAE_STATE_CHANGED"),
863 EVENT_SEVERITY_NORMAL, 1, _T("Port %6 PAE state changed from %4 to %2"),
864 _T("Generated when switch port PAE state changed.\r\nParameters:\r\n")
865 _T(" 1) New PAE state code\r\n")
866 _T(" 2) New PAE state as text\r\n")
867 _T(" 3) Old PAE state code\r\n")
868 _T(" 4) Old PAE state as text\r\n")
869 _T(" 5) Interface index\r\n")
870 _T(" 6) Interface name")));
871
872 CHK_EXEC(CreateEventTemplate(EVENT_8021X_BACKEND_STATE_CHANGED, _T("SYS_8021X_BACKEND_STATE_CHANGED"),
873 EVENT_SEVERITY_NORMAL, 1, _T("Port %6 backend authentication state changed from %4 to %2"),
874 _T("Generated when switch port backend authentication state changed.\r\nParameters:\r\n")
875 _T(" 1) New backend state code\r\n")
876 _T(" 2) New backend state as text\r\n")
877 _T(" 3) Old backend state code\r\n")
878 _T(" 4) Old backend state as text\r\n")
879 _T(" 5) Interface index\r\n")
880 _T(" 6) Interface name")));
881
882 CHK_EXEC(CreateEventTemplate(EVENT_8021X_PAE_FORCE_UNAUTH, _T("SYS_8021X_PAE_FORCE_UNAUTH"),
883 EVENT_SEVERITY_MAJOR, 1, _T("Port %2 switched to force unauthorize state"),
884 _T("Generated when switch port PAE state changed to FORCE UNAUTHORIZE.\r\nParameters:\r\n")
885 _T(" 1) Interface index\r\n")
886 _T(" 2) Interface name")));
887
888 CHK_EXEC(CreateEventTemplate(EVENT_8021X_AUTH_FAILED, _T("SYS_8021X_AUTH_FAILED"),
889 EVENT_SEVERITY_MAJOR, 1, _T("802.1x authentication failed on port %2"),
890 _T("Generated when switch port backend authentication state changed to FAIL.\r\nParameters:\r\n")
891 _T(" 1) Interface index\r\n")
892 _T(" 2) Interface name")));
893
894 CHK_EXEC(CreateEventTemplate(EVENT_8021X_AUTH_TIMEOUT, _T("SYS_8021X_AUTH_TIMEOUT"),
895 EVENT_SEVERITY_MAJOR, 1, _T("802.1x authentication time out on port %2"),
896 _T("Generated when switch port backend authentication state changed to TIMEOUT.\r\nParameters:\r\n")
897 _T(" 1) Interface index\r\n")
898 _T(" 2) Interface name")));
899
900 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='244' WHERE var_name='SchemaVersion'")));
901 return TRUE;
902}
903
904
e320f8ce
VK
905//
906// Upgrade from V242 to V243
907//
908
909static BOOL H_UpgradeFromV242(int currVersion, int newVersion)
910{
911 static TCHAR batch[] =
242e9c7f
VK
912 _T("ALTER TABLE items ADD snmp_raw_value_type integer\n")
913 _T("UPDATE items SET snmp_raw_value_type=0\n")
e320f8ce
VK
914 _T("ALTER TABLE items ADD flags integer\n")
915 _T("UPDATE items SET flags=adv_schedule+(all_thresholds*2)\n")
916 _T("ALTER TABLE items DROP COLUMN adv_schedule\n")
917 _T("ALTER TABLE items DROP COLUMN all_thresholds\n")
e320f8ce
VK
918 _T("<END>");
919
920 CHK_EXEC(SQLBatch(batch));
921 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='243' WHERE var_name='SchemaVersion'")));
922 return TRUE;
923}
924
925
f5e80875
VK
926//
927// Upgrade from V241 to V242
928//
929
930static BOOL H_UpgradeFromV241(int currVersion, int newVersion)
931{
932 static TCHAR batch[] =
933 _T("DROP TABLE business_service_templates\n")
934 _T("ALTER TABLE dashboards ADD options integer\n")
935 _T("UPDATE dashboards SET options=0\n")
936 _T("<END>");
937
938 CHK_EXEC(SQLBatch(batch));
939 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='242' WHERE var_name='SchemaVersion'")));
940 return TRUE;
941}
942
943
6ff21d27
VK
944//
945// Upgrade from V240 to V241
946//
947
948static BOOL H_UpgradeFromV240(int currVersion, int newVersion)
949{
950 static TCHAR batch[] =
951 _T("ALTER TABLE slm_checks ADD template_id integer\n")
952 _T("ALTER TABLE slm_checks ADD current_ticket integer\n")
953 _T("UPDATE slm_checks SET template_id=0,current_ticket=0\n")
954 _T("<END>");
955
956 CHK_EXEC(SQLBatch(batch));
957 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='241' WHERE var_name='SchemaVersion'")));
958 return TRUE;
959}
960
961
5fe19f9e
VK
962//
963// Upgrade from V239 to V240
964//
965
966static BOOL H_UpgradeFromV239(int currVersion, int newVersion)
967{
968 CHK_EXEC(SQLQuery(_T("ALTER TABLE raw_dci_values ADD transformed_value varchar(255)")));
969 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='240' WHERE var_name='SchemaVersion'")));
970 return TRUE;
971}
972
973
5a7d6a10
VK
974//
975// Upgrade from V238 to V239
976//
977
978static BOOL H_UpgradeFromV238(int currVersion, int newVersion)
979{
980 CHK_EXEC(SQLQuery(
981 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES ")
982 _T("(56,'SYS_IP_ADDRESS_CHANGED',1,1,'Primary IP address changed from %2 to %1',")
983 _T("'Generated when primary IP address changed (usually because of primary name change or DNS change).#0D#0A")
984 _T("Parameters:#0D#0A 1) New IP address#0D#0A 2) Old IP address#0D#0A 3) Primary host name')")));
985
986 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='239' WHERE var_name='SchemaVersion'")));
987 return TRUE;
988}
989
990
34ccf87f
VK
991//
992// Upgrade from V232 to V238
993//
994
995static BOOL H_UpgradeFromV232toV238(int currVersion, int newVersion)
996{
997 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_checks (")
998 _T("id integer not null,")
999 _T("type integer not null,")
1000 _T("content $SQL:TEXT null,")
1001 _T("threshold_id integer not null,")
1002 _T("reason varchar(255) null,")
1003 _T("is_template integer not null,")
1004 _T("PRIMARY KEY(id))")));
1005
1006 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_tickets (")
1007 _T("ticket_id integer not null,")
1008 _T("service_id integer not null,")
1009 _T("check_id integer not null,")
1010 _T("create_timestamp integer not null,")
1011 _T("close_timestamp integer not null,")
1012 _T("reason varchar(255) null,")
1013 _T("PRIMARY KEY(ticket_id))")));
1014
1015 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_service_history (")
1016 _T("record_id integer not null,")
1017 _T("service_id integer not null,")
1018 _T("change_timestamp integer not null,")
1019 _T("new_status integer not null,")
1020 _T("PRIMARY KEY(record_id))")));
1021
1022 CHK_EXEC(CreateTable(_T("CREATE TABLE report_results (")
1023 _T("report_id integer not null,")
1024 _T("generated integer not null,")
1025 _T("job_id integer not null,")
1026 _T("PRIMARY KEY(report_id,job_id))")));
1027
1028 CHK_EXEC(CreateTable(_T("CREATE TABLE reports (")
1029 _T("id integer not null,")
1030 _T("definition $SQL:TEXT null,")
1031 _T("PRIMARY KEY(id))")));
1032
1033 CHK_EXEC(CreateTable(_T("CREATE TABLE job_history (")
1034 _T("id integer not null,")
1035 _T("time_created integer not null,")
1036 _T("time_started integer not null,")
1037 _T("time_finished integer not null,")
1038 _T("job_type varchar(127) null,")
1039 _T("description varchar(255) null,")
1040 _T("additional_info varchar(255) null,")
1041 _T("node_id integer not null,")
1042 _T("user_id integer not null,")
1043 _T("status integer not null,")
1044 _T("failure_message varchar(255) null,")
1045 _T("PRIMARY KEY(id))")));
1046
1047 CHK_EXEC(CreateTable(_T("CREATE TABLE business_services (")
1048 _T("service_id integer not null,")
1049 _T("PRIMARY KEY(service_id))")));
1050
1051 CHK_EXEC(CreateTable(_T("CREATE TABLE business_service_templates (")
1052 _T("service_id integer not null,")
1053 _T("template_id integer not null,")
1054 _T("PRIMARY KEY(service_id,template_id))")));
1055
1056 CHK_EXEC(CreateTable(_T("CREATE TABLE node_links (")
1057 _T("nodelink_id integer not null,")
1058 _T("node_id integer not null,")
1059 _T("PRIMARY KEY(nodelink_id))")));
1060
1061 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_agreements (")
1062 _T("agreement_id integer not null,")
1063 _T("service_id integer not null,")
1064 _T("org_id integer not null,")
1065 _T("uptime varchar(63) not null,")
1066 _T("period integer not null,")
1067 _T("start_date integer not null,")
1068 _T("notes varchar(255),")
1069 _T("PRIMARY KEY(agreement_id))")));
1070
1071 CHK_EXEC(CreateTable(_T("CREATE TABLE organizations (")
1072 _T("id integer not null,")
1073 _T("parent_id integer not null,")
1074 _T("org_type integer not null,")
1075 _T("name varchar(63) not null,")
1076 _T("description varchar(255),")
1077 _T("manager integer not null,")
1078 _T("PRIMARY KEY(id))")));
1079
1080 CHK_EXEC(CreateTable(_T("CREATE TABLE persons (")
1081 _T("id integer not null,")
1082 _T("org_id integer not null,")
1083 _T("first_name varchar(63),")
1084 _T("last_name varchar(63),")
1085 _T("title varchar(255),")
1086 _T("status integer not null,")
1087 _T("PRIMARY KEY(id))")));
1088
1089 CHK_EXEC(CreateConfigParam(_T("JobHistoryRetentionTime"), _T("90"), 1, 0));
1090
1091 CHK_EXEC(SQLQuery(_T("UPDATE event_cfg SET description=")
1092 _T("'Generated when threshold check is rearmed for specific data collection item.#0D#0A")
1093 _T("Parameters:#0D#0A")
1094 _T(" 1) Parameter name#0D#0A")
1095 _T(" 2) Item description#0D#0A")
1096 _T(" 3) Data collection item ID#0D#0A")
1097 _T(" 4) Instance#0D#0A")
1098 _T(" 5) Threshold value#0D#0A")
1099 _T(" 6) Actual value' WHERE event_code=18")));
1100
1101 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='238' WHERE var_name='SchemaVersion'")));
1102 return TRUE;
1103}
1104
1105
9c529287
VK
1106//
1107// Upgrade from V237 to V238
1108//
1109
1110static BOOL H_UpgradeFromV237(int currVersion, int newVersion)
1111{
1112 static TCHAR batch[] =
1113 _T("DROP TABLE slm_check_templates\n")
1114 _T("DROP TABLE node_link_checks\n")
1115 _T("DROP TABLE slm_checks\n")
1116 _T("DROP TABLE slm_tickets\n")
1117 _T("<END>");
1118
1119 CHK_EXEC(SQLBatch(batch));
1120
1121 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_checks (")
1122 _T("id integer not null,")
1123 _T("type integer not null,")
1124 _T("content $SQL:TEXT null,")
1125 _T("threshold_id integer not null,")
1126 _T("reason varchar(255) null,")
1127 _T("is_template integer not null,")
1128 _T("PRIMARY KEY(id))")));
1129
1130 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_tickets (")
1131 _T("ticket_id integer not null,")
1132 _T("service_id integer not null,")
1133 _T("check_id integer not null,")
1134 _T("create_timestamp integer not null,")
1135 _T("close_timestamp integer not null,")
1136 _T("reason varchar(255) null,")
1137 _T("PRIMARY KEY(ticket_id))")));
1138
1139 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_service_history (")
1140 _T("record_id integer not null,")
1141 _T("service_id integer not null,")
1142 _T("change_timestamp integer not null,")
1143 _T("new_status integer not null,")
1144 _T("PRIMARY KEY(record_id))")));
1145
1146 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='238' WHERE var_name='SchemaVersion'")));
1147 return TRUE;
1148}
1149
1150
f5c9fdc5
VK
1151//
1152// Upgrade from V236 to V237
1153//
1154
1155static BOOL H_UpgradeFromV236(int currVersion, int newVersion)
1156{
1157 static TCHAR batch[] =
1158 _T("ALTER TABLE business_services DROP COLUMN name\n")
1159 _T("ALTER TABLE business_services DROP COLUMN parent_id\n")
1160 _T("ALTER TABLE business_services DROP COLUMN status\n")
1161 _T("ALTER TABLE slm_checks DROP COLUMN name\n")
1162 _T("<END>");
1163
1164 CHK_EXEC(SQLBatch(batch));
1165
1166 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='237' WHERE var_name='SchemaVersion'")));
1167 return TRUE;
1168}
1169
1170
5418326b
AK
1171//
1172// Upgrade from V235 to V236
1173//
1174
1175static BOOL H_UpgradeFromV235(int currVersion, int newVersion)
1176{
1177 CHK_EXEC(CreateTable(_T("CREATE TABLE report_results (")
1178 _T("report_id integer not null,")
1179 _T("generated integer not null,")
1180 _T("job_id integer not null,")
1181 _T("PRIMARY KEY(report_id,job_id))")));
1182
1183 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='236' WHERE var_name='SchemaVersion'")));
1184 return TRUE;
1185}
1186
1187
845b8121
VK
1188//
1189// Upgrade from V234 to V235
1190//
1191
1192static BOOL H_UpgradeFromV234(int currVersion, int newVersion)
1193{
1194 CHK_EXEC(CreateTable(_T("CREATE TABLE reports (")
1195 _T("id integer not null,")
1196 _T("definition $SQL:TEXT null,")
1197 _T("PRIMARY KEY(id))")));
1198
845b8121
VK
1199 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='235' WHERE var_name='SchemaVersion'")));
1200 return TRUE;
1201}
1202
1203
878b4261
VK
1204//
1205// Upgrade from V233 to V234
1206//
1207
1208static BOOL H_UpgradeFromV233(int currVersion, int newVersion)
1209{
1210 CHK_EXEC(CreateTable(_T("CREATE TABLE job_history (")
1211 _T("id integer not null,")
1212 _T("time_created integer not null,")
1213 _T("time_started integer not null,")
1214 _T("time_finished integer not null,")
1215 _T("job_type varchar(127) null,")
1216 _T("description varchar(255) null,")
24dc5346 1217 _T("additional_info varchar(255) null,")
878b4261
VK
1218 _T("node_id integer not null,")
1219 _T("user_id integer not null,")
1220 _T("status integer not null,")
1221 _T("failure_message varchar(255) null,")
1222 _T("PRIMARY KEY(id))")));
1223
1224 CHK_EXEC(CreateConfigParam(_T("JobHistoryRetentionTime"), _T("90"), 1, 0));
1225
1226 CHK_EXEC(SQLQuery(_T("UPDATE event_cfg SET description=")
1227 _T("'Generated when threshold check is rearmed for specific data collection item.#0D#0A")
1228 _T("Parameters:#0D#0A")
1229 _T(" 1) Parameter name#0D#0A")
1230 _T(" 2) Item description#0D#0A")
1231 _T(" 3) Data collection item ID#0D#0A")
1232 _T(" 4) Instance#0D#0A")
1233 _T(" 5) Threshold value#0D#0A")
1234 _T(" 6) Actual value' WHERE event_code=18")));
1235
1236 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='234' WHERE var_name='SchemaVersion'")));
1237 return TRUE;
1238}
1239
1240
128681c8
VK
1241//
1242// Upgrade from V232 to V233
1243//
1244
1245static BOOL H_UpgradeFromV232(int currVersion, int newVersion)
1246{
1247 CHK_EXEC(CreateTable(_T("CREATE TABLE business_services (")
1248 _T("service_id integer not null,")
1249 _T("name varchar(63) not null,")
2498594e
VK
1250 _T("parent_id integer not null,")
1251 _T("status integer not null,")
128681c8
VK
1252 _T("PRIMARY KEY(service_id))")));
1253
128681c8
VK
1254 CHK_EXEC(CreateTable(_T("CREATE TABLE business_service_templates (")
1255 _T("service_id integer not null,")
1256 _T("template_id integer not null,")
1257 _T("PRIMARY KEY(service_id,template_id))")));
1258
1259 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_checks (")
1260 _T("check_id integer not null,")
1261 _T("name varchar(63) not null,")
2498594e 1262 _T("type integer not null,")
128681c8 1263 _T("content $SQL:TEXT,")
2498594e 1264 _T("threshold_id integer not null,")
128681c8
VK
1265 _T("state integer not null,")
1266 _T("reason varchar(255) not null,")
1267 _T("PRIMARY KEY(check_id))")));
1268
1269 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_check_templates (")
1270 _T("id integer not null,")
1271 _T("name varchar(63) not null,")
2498594e 1272 _T("type integer not null,")
128681c8 1273 _T("content $SQL:TEXT,")
2498594e 1274 _T("threshold_id integer not null,")
128681c8
VK
1275 _T("PRIMARY KEY(id))")));
1276
1277 CHK_EXEC(CreateTable(_T("CREATE TABLE node_links (")
1278 _T("nodelink_id integer not null,")
1279 _T("node_id integer not null,")
1280 _T("PRIMARY KEY(nodelink_id))")));
1281
1282 CHK_EXEC(CreateTable(_T("CREATE TABLE node_link_checks (")
1283 _T("nodelink_id integer not null,")
1284 _T("check_id integer not null,")
1285 _T("PRIMARY KEY(nodelink_id,check_id))")));
1286
1287 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_agreements (")
1288 _T("agreement_id integer not null,")
1289 _T("service_id integer not null,")
1290 _T("org_id integer not null,")
1291 _T("uptime varchar(63) not null,")
1292 _T("period integer not null,")
1293 _T("start_date integer not null,")
1294 _T("notes varchar(255),")
1295 _T("PRIMARY KEY(agreement_id))")));
1296
1297 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_tickets (")
1298 _T("ticket_id integer not null,")
1299 _T("service_id integer not null,")
1300 _T("create_timestamp integer not null,")
1301 _T("close_timestamp integer not null,")
1302 _T("reason varchar(255) not null,")
1303 _T("PRIMARY KEY(ticket_id))")));
1304
1305 CHK_EXEC(CreateTable(_T("CREATE TABLE organizations (")
1306 _T("id integer not null,")
1307 _T("parent_id integer not null,")
1308 _T("org_type integer not null,")
1309 _T("name varchar(63) not null,")
1310 _T("description varchar(255),")
1311 _T("manager integer not null,")
1312 _T("PRIMARY KEY(id))")));
1313
1314 CHK_EXEC(CreateTable(_T("CREATE TABLE persons (")
1315 _T("id integer not null,")
1316 _T("org_id integer not null,")
1317 _T("first_name varchar(63),")
1318 _T("last_name varchar(63),")
1319 _T("title varchar(255),")
1320 _T("status integer not null,")
1321 _T("PRIMARY KEY(id))")));
1322
1323 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='233' WHERE var_name='SchemaVersion'")));
1324 return TRUE;
1325}
1326
1327
8f245200
VK
1328//
1329// Upgrade from V231 to V232
1330//
1331
1332static BOOL H_UpgradeFromV231(int currVersion, int newVersion)
1333{
1334 static TCHAR batch[] =
1335 _T("ALTER TABLE object_properties ADD submap_id integer\n")
1336 _T("UPDATE object_properties SET submap_id=0\n")
1337 _T("DROP TABLE maps\n")
1338 _T("DROP TABLE map_access_lists\n")
1339 _T("DROP TABLE submaps\n")
1340 _T("DROP TABLE submap_object_positions\n")
1341 _T("DROP TABLE submap_links\n")
1342 _T("<END>");
1343
1344 CHK_EXEC(SQLBatch(batch));
1345
1346 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='232' WHERE var_name='SchemaVersion'")));
1347 return TRUE;
1348}
1349
1350
3eab63f2
VK
1351//
1352// Upgrade from V230 to V231
1353//
1354
1355static BOOL H_UpgradeFromV230(int currVersion, int newVersion)
1356{
1357 static TCHAR batch[] =
1358 _T("ALTER TABLE nodes ADD bridge_base_addr varchar(15)\n")
1359 _T("UPDATE nodes SET bridge_base_addr='000000000000'\n")
1360 _T("<END>");
1361
1362 CHK_EXEC(SQLBatch(batch));
1363
1364 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='231' WHERE var_name='SchemaVersion'")));
1365 return TRUE;
1366}
1367
1368
fceea457
VK
1369//
1370// Upgrade from V229 to V230
1371//
1372
1373static BOOL H_UpgradeFromV229(int currVersion, int newVersion)
1374{
1375 static TCHAR batch1[] =
1a74dc37
VK
1376 _T("ALTER TABLE network_maps ADD bg_latitude varchar(20)\n")
1377 _T("ALTER TABLE network_maps ADD bg_longitude varchar(20)\n")
1378 _T("ALTER TABLE network_maps ADD bg_zoom integer\n")
fceea457
VK
1379 _T("ALTER TABLE dashboard_elements ADD layout_data $SQL:TEXT\n")
1380 _T("<END>");
1381
1382 CHK_EXEC(SQLBatch(batch1));
1383
1384 DB_RESULT hResult = SQLSelect(_T("SELECT dashboard_id,element_id,horizontal_span,vertical_span,horizontal_alignment,vertical_alignment FROM dashboard_elements"));
1385 if (hResult != NULL)
1386 {
1387 TCHAR query[1024], xml[1024];
1388
1389 int count = DBGetNumRows(hResult);
1390 for(int i = 0; i < count; i++)
1391 {
1392 _sntprintf(xml, 1024, _T("<layout><horizontalSpan>%d</horizontalSpan><verticalSpan>%d</verticalSpan><horizontalAlignment>%d</horizontalAlignment><verticalAlignment>%d</verticalAlignment></layout>"),
1393 (int)DBGetFieldLong(hResult, i, 2), (int)DBGetFieldLong(hResult, i, 3),
1394 (int)DBGetFieldLong(hResult, i, 4), (int)DBGetFieldLong(hResult, i, 5));
1395 _sntprintf(query, 1024, _T("UPDATE dashboard_elements SET layout_data=%s WHERE dashboard_id=%d AND element_id=%d"),
1396 (const TCHAR *)DBPrepareString(g_hCoreDB, xml), (int)DBGetFieldLong(hResult, i, 0), (int)DBGetFieldLong(hResult, i, 1));
1397 CHK_EXEC(SQLQuery(query));
1398 }
1399 DBFreeResult(hResult);
1400 }
1401 else
1402 {
1403 if (!g_bIgnoreErrors)
1404 return FALSE;
1405 }
1406
1407 static TCHAR batch2[] =
1408 _T("ALTER TABLE dashboard_elements DROP COLUMN horizontal_span\n")
1409 _T("ALTER TABLE dashboard_elements DROP COLUMN vertical_span\n")
1410 _T("ALTER TABLE dashboard_elements DROP COLUMN horizontal_alignment\n")
1411 _T("ALTER TABLE dashboard_elements DROP COLUMN vertical_alignment\n")
1412 _T("<END>");
1413
1414 CHK_EXEC(SQLBatch(batch2));
1415
1416 CreateConfigParam(_T("TileServerURL"), _T("http://tile.openstreetmap.org/"), 1, 0);
1417
1418 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='230' WHERE var_name='SchemaVersion'")));
1419 return TRUE;
1420}
1421
1422
926e8ce7
VK
1423//
1424// Upgrade from V228 to V229
1425//
1426
1427static BOOL H_UpgradeFromV228(int currVersion, int newVersion)
1428{
1429 CHK_EXEC(CreateTable(_T("CREATE TABLE dashboards (")
1430 _T(" id integer not null,")
1431 _T(" num_columns integer not null,")
1432 _T(" PRIMARY KEY(id))")));
1433
1434 CHK_EXEC(CreateTable(_T("CREATE TABLE dashboard_elements (")
1435 _T(" dashboard_id integer not null,")
1436 _T(" element_id integer not null,")
1437 _T(" element_type integer not null,")
1438 _T(" element_data $SQL:TEXT null,")
1439 _T(" horizontal_span integer not null,")
1440 _T(" vertical_span integer not null,")
1441 _T(" horizontal_alignment integer not null,")
1442 _T(" vertical_alignment integer not null,")
1443 _T(" PRIMARY KEY(dashboard_id,element_id))")));
1444
1445 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='229' WHERE var_name='SchemaVersion'")));
1446 return TRUE;
1447}
1448
1449
7a41a06e
VK
1450//
1451// Upgrade from V227 to V228
1452//
1453
1454static BOOL H_UpgradeFromV227(int currVersion, int newVersion)
1455{
1456 CHK_EXEC(SQLQuery(_T("DROP TABLE web_maps")));
1457 CHK_EXEC(MigrateMaps());
1458 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='228' WHERE var_name='SchemaVersion'")));
1459 return TRUE;
1460}
1461
b1553daa 1462
89135050
VK
1463//
1464// Upgrade from V226 to V227
1465//
1466
1467static BOOL H_UpgradeFromV226(int currVersion, int newVersion)
1468{
1469 static TCHAR batch[] =
1470 _T("ALTER TABLE clusters ADD zone_guid integer\n")
1471 _T("UPDATE clusters SET zone_guid=0\n")
1472 _T("<END>");
1473
1474 CHK_EXEC(SQLBatch(batch));
1475
1476 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='227' WHERE var_name='SchemaVersion'")));
1477 return TRUE;
1478}
1479
1480
4c16cdc7
VK
1481//
1482// Upgrade from V225 to V226
1483//
1484
1485static BOOL H_UpgradeFromV225(int currVersion, int newVersion)
1486{
1487 static TCHAR batch[] =
1488 _T("ALTER TABLE interfaces ADD flags integer\n")
1489 _T("UPDATE interfaces SET flags=0\n")
1490 _T("UPDATE interfaces SET flags=1 WHERE synthetic_mask<>0\n")
1491 _T("ALTER TABLE interfaces DROP COLUMN synthetic_mask\n")
1492 _T("<END>");
1493
1494 CHK_EXEC(SQLBatch(batch));
1495
1496 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='226' WHERE var_name='SchemaVersion'")));
1497 return TRUE;
1498}
1499
1500
478d4ff4
VK
1501//
1502// Upgrade from V224 to V225
1503//
1504
1505static BOOL H_UpgradeFromV224(int currVersion, int newVersion)
1506{
1507 static TCHAR batch[] =
1508 _T("ALTER TABLE interfaces ADD description varchar(255)\n")
1509 _T("UPDATE interfaces SET description=''\n")
1510 _T("<END>");
1511
1512 CHK_EXEC(SQLBatch(batch));
1513
1514 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='225' WHERE var_name='SchemaVersion'")));
1515 return TRUE;
1516}
1517
1518
52c31148
VK
1519//
1520// Upgrade from V223 to V224
1521//
1522
1523static BOOL H_UpgradeFromV223(int currVersion, int newVersion)
1524{
1525 static TCHAR batch[] =
1526 _T("DROP TABLE zone_ip_addr_list\n")
1527 _T("ALTER TABLE zones DROP COLUMN zone_type\n")
1528 _T("ALTER TABLE zones DROP COLUMN controller_ip\n")
1529 _T("ALTER TABLE zones ADD agent_proxy integer\n")
1530 _T("ALTER TABLE zones ADD snmp_proxy integer\n")
1531 _T("ALTER TABLE zones ADD icmp_proxy integer\n")
1532 _T("UPDATE zones SET agent_proxy=0,snmp_proxy=0,icmp_proxy=0\n")
1533 _T("<END>");
1534
1535 CHK_EXEC(SQLBatch(batch));
1536
1537 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='224' WHERE var_name='SchemaVersion'")));
1538 return TRUE;
1539}
1540
1541
5ad2167d
VK
1542//
1543// Upgrade from V222 to V223
1544//
1545
1546static BOOL H_UpgradeFromV222(int currVersion, int newVersion)
1547{
1548 static TCHAR batch[] =
1549 _T("DROP TABLE oid_to_type\n")
1550 _T("ALTER TABLE nodes DROP COLUMN node_type\n")
1551 _T("ALTER TABLE nodes ADD primary_name varchar(255)\n")
1552 _T("UPDATE nodes SET primary_name=primary_ip\n")
1553 _T("<END>");
1554
1555 CHK_EXEC(SQLBatch(batch));
1556
1557 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='223' WHERE var_name='SchemaVersion'")));
1558 return TRUE;
1559}
1560
1561
465b3f2d 1562//
f25b0d12
VK
1563// Upgrade from V221 to V222
1564//
1565
1566static BOOL H_UpgradeFromV221(int currVersion, int newVersion)
1567{
1568 static TCHAR batch[] =
1569 _T("ALTER TABLE object_properties ADD image varchar(36)\n")
1570 _T("UPDATE object_properties SET image='00000000-0000-0000-0000-000000000000'\n")
1571 _T("<END>");
1572
1573 CHK_EXEC(SQLBatch(batch));
1574
1575 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='222' WHERE var_name='SchemaVersion'")));
1576 return TRUE;
1577}
1578
1579
1580//
1581// Upgrade from V220 to V221
465b3f2d
VK
1582//
1583
1584static BOOL H_UpgradeFromV220(int currVersion, int newVersion)
1585{
1586 static TCHAR batch[] =
1587 _T("ALTER TABLE network_maps DROP COLUMN background\n")
1588 _T("ALTER TABLE network_maps ADD background varchar(36)\n")
1589 _T("<END>");
1590
1591 CHK_EXEC(SQLBatch(batch));
1592
1593 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='221' WHERE var_name='SchemaVersion'")));
1594 return TRUE;
1595}
1596
1597
d74c80ea
VK
1598//
1599// Upgrade from V219 to V220
1600//
1601
1602static BOOL H_UpgradeFromV219(int currVersion, int newVersion)
1603{
1604 static TCHAR batch[] =
1605 _T("ALTER TABLE interfaces ADD bridge_port integer\n")
1606 _T("ALTER TABLE interfaces ADD phy_slot integer\n")
1607 _T("ALTER TABLE interfaces ADD phy_port integer\n")
1608 _T("ALTER TABLE interfaces ADD peer_node_id integer\n")
1609 _T("ALTER TABLE interfaces ADD peer_if_id integer\n")
1610 _T("UPDATE interfaces SET bridge_port=0,phy_slot=0,phy_port=0,peer_node_id=0,peer_if_id=0\n")
1611 _T("ALTER TABLE nodes ADD snmp_sys_name varchar(127)\n")
1612 _T("UPDATE nodes SET snmp_sys_name=''\n")
1613 _T("<END>");
1614
1615 CHK_EXEC(SQLBatch(batch));
1616
1617 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='220' WHERE var_name='SchemaVersion'")));
1618 return TRUE;
1619}
1620
1621
e6b9439a
AK
1622//
1623// Upgrade from V218 to V219
1624//
1625
1626static BOOL H_UpgradeFromV218(int currVersion, int newVersion)
1627{
1628 CHK_EXEC(CreateTable(_T("CREATE TABLE images (")
9cd5201a
AK
1629 _T(" guid varchar(36) not null,")
1630 _T(" mimetype varchar(64) not null,")
1631 _T(" name varchar(255) not null,")
e6b9439a
AK
1632 _T(" category varchar(255) not null,")
1633 _T(" protected integer default 0,")
1634 _T(" ")
9cd5201a
AK
1635 _T(" PRIMARY KEY(guid),")
1636 _T(" UNIQUE(name, category))")));
1637
1638 static TCHAR batch[] =
1639 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 1640 _T("('1ddb76a3-a05f-4a42-acda-22021768feaf', 'image/png', 'ATM', 'Network Objects', 1)\n")
9cd5201a 1641 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 1642 _T("('b314cf44-b2aa-478e-b23a-73bc5bb9a624', 'image/png', 'HSM', 'Network Objects', 1)\n")
9cd5201a 1643 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 1644 _T("('904e7291-ee3f-41b7-8132-2bd29288ecc8', 'image/png', 'Node', 'Network Objects', 1)\n")
9cd5201a 1645 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 1646 _T("('f5214d16-1ab1-4577-bb21-063cfd45d7af', 'image/png', 'Printer', 'Network Objects', 1)\n")
9cd5201a 1647 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 1648 _T("('bacde727-b183-4e6c-8dca-ab024c88b999', 'image/png', 'Router', 'Network Objects', 1)\n")
9cd5201a 1649 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 1650 _T("('ba6ab507-f62d-4b8f-824c-ca9d46f22375', 'image/png', 'Server', 'Network Objects', 1)\n")
9cd5201a 1651 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 1652 _T("('092e4b35-4e7c-42df-b9b7-d5805bfac64e', 'image/png', 'Service', 'Network Objects', 1)\n")
9cd5201a 1653 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 1654 _T("('f9105c54-8dcf-483a-b387-b4587dfd3cba', 'image/png', 'Switch', 'Network Objects', 1)\n")
9cd5201a 1655 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 1656 _T("('7cd999e9-fbe0-45c3-a695-f84523b3a50c', 'image/png', 'Unknown', 'Network Objects', 1)\n")
9cd5201a
AK
1657 _T("<END>");
1658
1659 CHK_EXEC(SQLBatch(batch));
e6b9439a
AK
1660
1661 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='219' WHERE var_name='SchemaVersion'")));
1662 return TRUE;
1663}
1664
1665
4fe87cdc
VK
1666//
1667// Upgrade from V217 to V218
1668//
1669
1670static BOOL H_UpgradeFromV217(int currVersion, int newVersion)
1671{
1672 CHK_EXEC(SetColumnNullable(_T("snmp_communities"), _T("community"), _T("varchar(255)")));
1673 CHK_EXEC(ConvertStrings(_T("snmp_communities"), _T("id"), _T("community")));
1674
1675 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='218' WHERE var_name='SchemaVersion'")));
1676 return TRUE;
1677}
1678
1679
65e2005b
VK
1680//
1681// Upgrade from V216 to V217
1682//
1683
1684static BOOL H_UpgradeFromV216(int currVersion, int newVersion)
1685{
1686 static TCHAR batch[] =
1687 _T("ALTER TABLE nodes ADD snmp_port integer\n")
8cad4ebb 1688 _T("UPDATE nodes SET snmp_port=161\n")
65e2005b
VK
1689 _T("ALTER TABLE items ADD snmp_port integer\n")
1690 _T("UPDATE items SET snmp_port=0\n")
1691 _T("<END>");
1692
1693 CHK_EXEC(SQLBatch(batch));
1694
1695 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("community"), _T("varchar(127)")));
1696 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("community")));
1697
1698 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("usm_auth_password"), _T("varchar(127)")));
1699 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("usm_auth_password")));
1700
1701 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("usm_priv_password"), _T("varchar(127)")));
1702 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("usm_priv_password")));
1703
1704 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("snmp_oid"), _T("varchar(255)")));
1705 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("snmp_oid")));
1706
1707 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("secret"), _T("varchar(64)")));
1708 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("secret")));
1709
1710 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("agent_version"), _T("varchar(63)")));
1711 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("agent_version")));
1712
1713 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("platform_name"), _T("varchar(63)")));
1714 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("platform_name")));
1715
1716 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("uname"), _T("varchar(255)")));
1717 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("uname")));
1718
1719 CHK_EXEC(SetColumnNullable(_T("items"), _T("name"), _T("varchar(255)")));
1720 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("name")));
1721
1722 CHK_EXEC(SetColumnNullable(_T("items"), _T("description"), _T("varchar(255)")));
1723 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("description")));
1724
8cad4ebb 1725 CHK_EXEC(SetColumnNullable(_T("items"), _T("transformation"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]));
65e2005b
VK
1726 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("transformation")));
1727
1728 CHK_EXEC(SetColumnNullable(_T("items"), _T("instance"), _T("varchar(255)")));
1729 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("instance")));
1730
1731 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='217' WHERE var_name='SchemaVersion'")));
1732 return TRUE;
1733}
1734
1735
3f7c0fe4
VK
1736//
1737// Upgrade from V215 to V216
1738//
1739
1740static BOOL H_UpgradeFromV215(int currVersion, int newVersion)
1741{
1742 CHK_EXEC(SetColumnNullable(_T("ap_common"), _T("description"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]));
1743 CHK_EXEC(ConvertStrings(_T("ap_common"), _T("id"), _T("description")));
1744
a6c1f07f
VK
1745 if (g_iSyntax != DB_SYNTAX_SQLITE)
1746 CHK_EXEC(SQLQuery(_T("ALTER TABLE ap_config_files DROP COLUMN file_name")));
1747
a30fa363
VK
1748 CHK_EXEC(SetColumnNullable(_T("ap_config_files"), _T("file_content"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]));
1749 CHK_EXEC(ConvertStrings(_T("ap_config_files"), _T("policy_id"), _T("file_content")));
1750
3f7c0fe4
VK
1751 CHK_EXEC(SQLQuery(_T("ALTER TABLE object_properties ADD guid varchar(36)")));
1752
1753 // Generate GUIDs for all objects
1754 DB_RESULT hResult = SQLSelect(_T("SELECT object_id FROM object_properties"));
1755 if (hResult != NULL)
1756 {
1757 int count = DBGetNumRows(hResult);
1758 for(int i = 0; i < count; i++)
1759 {
1760 uuid_t guid;
1761 TCHAR query[256], buffer[64];
1762
1763 uuid_generate(guid);
1764 _sntprintf(query, 256, _T("UPDATE object_properties SET guid='%s' WHERE object_id=%d"),
1765 uuid_to_string(guid, buffer), DBGetFieldULong(hResult, i, 0));
1766 CHK_EXEC(SQLQuery(query));
1767 }
1768 DBFreeResult(hResult);
1769 }
1770
1771 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='216' WHERE var_name='SchemaVersion'")));
1772 return TRUE;
1773}
1774
1775
021dcda7
VK
1776//
1777// Upgrade from V214 to V215
1778//
1779
1780static BOOL H_UpgradeFromV214(int currVersion, int newVersion)
1781{
1782 CHK_EXEC(CreateTable(_T("CREATE TABLE network_maps (")
1783 _T("id integer not null,")
1784 _T("map_type integer not null,")
1785 _T("layout integer not null,")
1786 _T("seed integer not null,")
1787 _T("background integer not null,")
1788 _T("PRIMARY KEY(id))")));
1789
1790 CHK_EXEC(CreateTable(_T("CREATE TABLE network_map_elements (")
1791 _T("map_id integer not null,")
1792 _T("element_id integer not null,")
1793 _T("element_type integer not null,")
1794 _T("element_data $SQL:TEXT not null,")
1795 _T("PRIMARY KEY(map_id,element_id))")));
1796
cce8f214
VK
1797 CHK_EXEC(CreateTable(_T("CREATE TABLE network_map_links (")
1798 _T("map_id integer not null,")
1799 _T("element1 integer not null,")
1800 _T("element2 integer not null,")
1801 _T("link_type integer not null,")
1802 _T("link_name varchar(255) null,")
1803 _T("connector_name1 varchar(255) null,")
1804 _T("connector_name2 varchar(255) null,")
1805 _T("PRIMARY KEY(map_id,element1,element2))")));
1806
021dcda7
VK
1807 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='215' WHERE var_name='SchemaVersion'")));
1808 return TRUE;
1809}
1810
1811
50da2d20
VK
1812//
1813// Upgrade from V213 to V214
1814//
1815
1816static BOOL H_UpgradeFromV213(int currVersion, int newVersion)
1817{
1818 CHK_EXEC(SetColumnNullable(_T("script_library"), _T("script_code"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]));
1819 CHK_EXEC(ConvertStrings(_T("script_library"), _T("script_id"), _T("script_code")));
1820
1821 CHK_EXEC(SetColumnNullable(_T("raw_dci_values"), _T("raw_value"), _T("varchar(255)")));
1822 CHK_EXEC(ConvertStrings(_T("raw_dci_values"), _T("item_id"), _T("raw_value")));
1823
1824 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='CREATE TABLE idata_%d (item_id integer not null,idata_timestamp integer not null,idata_value varchar(255) null)' WHERE var_name='IDataTableCreationCommand'")));
1825
1826 DB_RESULT hResult = SQLSelect(_T("SELECT id FROM nodes"));
1827 if (hResult != NULL)
1828 {
1829 int count = DBGetNumRows(hResult);
1830 for(int i = 0; i < count; i++)
1831 {
1832 TCHAR table[32];
1833
1834 DWORD nodeId = DBGetFieldULong(hResult, i, 0);
1835 _sntprintf(table, 32, _T("idata_%d"), nodeId);
1836 CHK_EXEC(SetColumnNullable(table, _T("idata_value"), _T("varchar(255)")));
1837 }
1838 DBFreeResult(hResult);
1839 }
1840
1841 // Convert values for string DCIs from # encoded to normal form
1842 hResult = SQLSelect(_T("SELECT node_id,item_id FROM items WHERE datatype=4"));
1843 if (hResult != NULL)
1844 {
1845 int count = DBGetNumRows(hResult);
1846 for(int i = 0; i < count; i++)
1847 {
1848 TCHAR query[512];
1849
1850 DWORD nodeId = DBGetFieldULong(hResult, i, 0);
1851 DWORD dciId = DBGetFieldULong(hResult, i, 1);
1852
035a4d73 1853 if (IsNodeExist(nodeId))
50da2d20 1854 {
3f7c0fe4 1855 _sntprintf(query, 512, _T("SELECT idata_timestamp,idata_value FROM idata_%d WHERE item_id=%d AND idata_value LIKE '%%#%%'"), nodeId, dciId);
035a4d73
VK
1856 DB_RESULT hData = SQLSelect(query);
1857 if (hData != NULL)
50da2d20 1858 {
035a4d73
VK
1859 int valueCount = DBGetNumRows(hData);
1860 for(int j = 0; j < valueCount; j++)
1861 {
1862 TCHAR buffer[MAX_DB_STRING];
1863
1864 LONG ts = DBGetFieldLong(hData, j, 0);
1865 DBGetField(hData, j, 1, buffer, MAX_DB_STRING);
3f7c0fe4
VK
1866 DecodeSQLString(buffer);
1867
1868 _sntprintf(query, 512, _T("UPDATE idata_%d SET idata_value=%s WHERE item_id=%d AND idata_timestamp=%ld"),
1869 nodeId, (const TCHAR *)DBPrepareString(g_hCoreDB, buffer), dciId, (long)ts);
1870 CHK_EXEC(SQLQuery(query));
035a4d73
VK
1871 }
1872 DBFreeResult(hData);
50da2d20 1873 }
50da2d20
VK
1874 }
1875 }
1876 DBFreeResult(hResult);
1877 }
1878
1879 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='214' WHERE var_name='SchemaVersion'")));
50da2d20
VK
1880 return TRUE;
1881}
1882
1883
f57209fd
VK
1884//
1885// Upgrade from V212 to V213
1886//
1887
1888static BOOL H_UpgradeFromV212(int currVersion, int newVersion)
1889{
1890 CHK_EXEC(SetColumnNullable(_T("items"), _T("custom_units_name"), _T("varchar(63)")));
1891 CHK_EXEC(SetColumnNullable(_T("items"), _T("perftab_settings"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]));
1892
1893 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("custom_units_name")));
1894 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("perftab_settings")));
1895
1896 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='213' WHERE var_name='SchemaVersion'")));
1897
1898 return TRUE;
1899}
1900
1901
1024e962
VK
1902//
1903// Upgrade from V211 to V212
1904//
1905
1906static BOOL H_UpgradeFromV211(int currVersion, int newVersion)
1907{
1024e962
VK
1908 CHK_EXEC(SetColumnNullable(_T("snmp_trap_cfg"), _T("snmp_oid"), _T("varchar(255)")));
1909 CHK_EXEC(SetColumnNullable(_T("snmp_trap_cfg"), _T("user_tag"), _T("varchar(63)")));
1910 CHK_EXEC(SetColumnNullable(_T("snmp_trap_cfg"), _T("description"), _T("varchar(255)")));
1911
1912 CHK_EXEC(ConvertStrings(_T("snmp_trap_cfg"), _T("trap_id"), _T("user_tag")));
1913 CHK_EXEC(ConvertStrings(_T("snmp_trap_cfg"), _T("trap_id"), _T("description")));
1914
1915 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='212' WHERE var_name='SchemaVersion'")));
1916
1917 return TRUE;
1918}
1919
1920
a8f60046
VK
1921//
1922// Upgrade from V210 to V211
1923//
1924
1925static BOOL H_UpgradeFromV210(int currVersion, int newVersion)
1926{
1927 static TCHAR batch[] =
1928 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
1929 _T(" (53,'SYS_DCI_UNSUPPORTED',2,1,'Status of DCI %1 (%5: %2) changed to UNSUPPORTED',")
1930 _T("'Generated when DCI status changed to UNSUPPORTED.#0D#0AParameters:#0D#0A")
1931 _T(" 1) DCI ID#0D#0A 2) DCI Name#0D#0A 3) DCI Description#0D#0A 4) DCI Origin code#0D#0A 5) DCI Origin name')\n")
1932 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
1933 _T(" (54,'SYS_DCI_DISABLED',1,1,'Status of DCI %1 (%5: %2) changed to DISABLED',")
1934 _T("'Generated when DCI status changed to DISABLED.#0D#0AParameters:#0D#0A")
1935 _T(" 1) DCI ID#0D#0A 2) DCI Name#0D#0A 3) DCI Description#0D#0A 4) DCI Origin code#0D#0A 5) DCI Origin name')\n")
1936 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
1937 _T(" (55,'SYS_DCI_ACTIVE',0,1,'Status of DCI %1 (%5: %2) changed to ACTIVE',")
1938 _T("'Generated when DCI status changed to ACTIVE.#0D#0AParameters:#0D#0A")
1939 _T(" 1) DCI ID#0D#0A 2) DCI Name#0D#0A 3) DCI Description#0D#0A 4) DCI Origin code#0D#0A 5) DCI Origin name')\n")
1940 _T("<END>");
1941
1024e962
VK
1942 CHK_EXEC(SQLBatch(batch));
1943 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='211' WHERE var_name='SchemaVersion'")));
a8f60046
VK
1944
1945 return TRUE;
1946}
1947
1948
43c1be79
VK
1949//
1950// Upgrade from V209 to V210
1951//
1952
1953static BOOL H_UpgradeFromV209(int currVersion, int newVersion)
1954{
1955 if (!SQLQuery(_T("DELETE FROM metadata WHERE var_name like 'IDataIndexCreationCommand_%'")))
1956 if (!g_bIgnoreErrors)
1957 return FALSE;
1958
1959 const TCHAR *query;
1960 switch(g_iSyntax)
1961 {
1962 case DB_SYNTAX_PGSQL:
1963 query = _T("INSERT INTO metadata (var_name,var_value) VALUES ('IDataIndexCreationCommand_0','CREATE INDEX idx_idata_%d_timestamp_id ON idata_%d(idata_timestamp,item_id)')");
1964 break;
1965 case DB_SYNTAX_MSSQL:
1966 query = _T("INSERT INTO metadata (var_name,var_value) VALUES ('IDataIndexCreationCommand_0','CREATE CLUSTERED INDEX idx_idata_%d_id_timestamp ON idata_%d(item_id,idata_timestamp)')");
1967 break;
1968 default:
1969 query = _T("INSERT INTO metadata (var_name,var_value) VALUES ('IDataIndexCreationCommand_0','CREATE INDEX idx_idata_%d_id_timestamp ON idata_%d(item_id,idata_timestamp)')");
1970 break;
1971 }
1972
1973 if (!SQLQuery(query))
1974 if (!g_bIgnoreErrors)
1975 return FALSE;
1976
1977 ReindexIData();
1978
1979 if (!SQLQuery(_T("UPDATE metadata SET var_value='210' WHERE var_name='SchemaVersion'")))
1980 if (!g_bIgnoreErrors)
1981 return FALSE;
1982
1983 return TRUE;
1984}
1985
1986
ab185583
VK
1987//
1988// Upgrade from V208 to V209
1989//
1990
1991static BOOL H_UpgradeFromV208(int currVersion, int newVersion)
1992{
1993 static TCHAR batch[] =
1994 _T("ALTER TABLE users ADD auth_failures integer\n")
1995 _T("ALTER TABLE users ADD last_passwd_change integer\n")
1996 _T("ALTER TABLE users ADD min_passwd_length integer\n")
1997 _T("ALTER TABLE users ADD disabled_until integer\n")
1998 _T("ALTER TABLE users ADD last_login integer\n")
1999 _T("ALTER TABLE users ADD password_history $SQL:TEXT\n")
2000 _T("UPDATE users SET auth_failures=0,last_passwd_change=0,min_passwd_length=-1,disabled_until=0,last_login=0\n")
2001 _T("<END>");
2002
2003 if (!SQLBatch(batch))
2004 if (!g_bIgnoreErrors)
2005 return FALSE;
2006
2007 if (!CreateConfigParam(_T("PasswordHistoryLength"), _T("0"), 1, 0))
2008 if (!g_bIgnoreErrors)
2009 return FALSE;
2010
0f1ddb74 2011 if (!CreateConfigParam(_T("IntruderLockoutThreshold"), _T("0"), 1, 0))
ab185583
VK
2012 if (!g_bIgnoreErrors)
2013 return FALSE;
2014
2015 if (!CreateConfigParam(_T("IntruderLockoutTime"), _T("30"), 1, 0))
2016 if (!g_bIgnoreErrors)
2017 return FALSE;
2018
2019 if (!CreateConfigParam(_T("MinPasswordLength"), _T("0"), 1, 0))
2020 if (!g_bIgnoreErrors)
2021 return FALSE;
2022
2023 if (!CreateConfigParam(_T("PasswordComplexity"), _T("0"), 1, 0))
2024 if (!g_bIgnoreErrors)
2025 return FALSE;
2026
2027 if (!CreateConfigParam(_T("PasswordExpiration"), _T("0"), 1, 0))
2028 if (!g_bIgnoreErrors)
2029 return FALSE;
2030
2031 if (!CreateConfigParam(_T("BlockInactiveUserAccounts"), _T("0"), 1, 0))
2032 if (!g_bIgnoreErrors)
2033 return FALSE;
2034
2035 if (!SQLQuery(_T("UPDATE metadata SET var_value='209' WHERE var_name='SchemaVersion'")))
2036 if (!g_bIgnoreErrors)
2037 return FALSE;
2038
2039 return TRUE;
2040}
2041
2042
80d3565a
VK
2043//
2044// Upgrade from V207 to V208
2045//
2046
2047static BOOL H_UpgradeFromV207(int currVersion, int newVersion)
2048{
2049 if (!SQLQuery(_T("ALTER TABLE items ADD system_tag varchar(255)")))
2050 if (!g_bIgnoreErrors)
2051 return FALSE;
2052
2053 if (!SQLQuery(_T("UPDATE metadata SET var_value='208' WHERE var_name='SchemaVersion'")))
2054 if (!g_bIgnoreErrors)
2055 return FALSE;
2056
2057 return TRUE;
2058}
2059
2060
5ab2f1ab
VK
2061//
2062// Upgrade from V206 to V207
2063//
2064
2065static BOOL H_UpgradeFromV206(int currVersion, int newVersion)
2066{
2067 if (!CreateConfigParam(_T("RADIUSSecondaryServer"), _T("none"), 1, 0))
2068 if (!g_bIgnoreErrors)
2069 return FALSE;
2070
2071 if (!CreateConfigParam(_T("RADIUSSecondarySecret"), _T("netxms"), 1, 0))
2072 if (!g_bIgnoreErrors)
2073 return FALSE;
2074
2075 if (!CreateConfigParam(_T("RADIUSSecondaryPort"), _T("1645"), 1, 0))
2076 if (!g_bIgnoreErrors)
2077 return FALSE;
2078
2079 if (!CreateConfigParam(_T("ExternalAuditServer"), _T("none"), 1, 1))
2080 if (!g_bIgnoreErrors)
2081 return FALSE;
2082
2083 if (!CreateConfigParam(_T("ExternalAuditPort"), _T("514"), 1, 1))
2084 if (!g_bIgnoreErrors)
2085 return FALSE;
2086
2087 if (!CreateConfigParam(_T("ExternalAuditFacility"), _T("13"), 1, 1))
2088 if (!g_bIgnoreErrors)
2089 return FALSE;
2090
2091 if (!CreateConfigParam(_T("ExternalAuditSeverity"), _T("5"), 1, 1))
2092 if (!g_bIgnoreErrors)
2093 return FALSE;
2094
2095 if (!CreateConfigParam(_T("ExternalAuditTag"), _T("netxmsd-audit"), 1, 1))
2096 if (!g_bIgnoreErrors)
2097 return FALSE;
2098
2099 if (!SQLQuery(_T("UPDATE metadata SET var_value='207' WHERE var_name='SchemaVersion'")))
2100 if (!g_bIgnoreErrors)
2101 return FALSE;
2102
2103 return TRUE;
2104}
2105
2106
ce7565e7
VK
2107//
2108// Upgrade from V205 to V206
2109//
2110
2111static BOOL H_UpgradeFromV205(int currVersion, int newVersion)
2112{
a4743a0f
VK
2113 if (g_iSyntax == DB_SYNTAX_ORACLE)
2114 {
2115 static TCHAR oraBatch[] =
2116 _T("ALTER TABLE audit_log MODIFY message null\n")
2117 _T("ALTER TABLE event_log MODIFY event_message null\n")
2118 _T("ALTER TABLE event_log MODIFY user_tag null\n")
2119 _T("ALTER TABLE syslog MODIFY hostname null\n")
2120 _T("ALTER TABLE syslog MODIFY msg_tag null\n")
2121 _T("ALTER TABLE syslog MODIFY msg_text null\n")
2122 _T("ALTER TABLE snmp_trap_log MODIFY trap_varlist null\n")
2123 _T("<END>");
2124
2125 if (!SQLBatch(oraBatch))
2126 if (!g_bIgnoreErrors)
2127 return FALSE;
2128 }
ce7565e7 2129
a4743a0f
VK
2130 bool clearLogs = GetYesNo(_T("This database upgrade requires log conversion. This can take significant amount of time ")
2131 _T("(up to few hours for large databases). If preserving all log records is not very important, it is ")
2132 _T("recommended to clear logs befor conversion. Clear logs?"));
ce7565e7 2133
a4743a0f
VK
2134 if (clearLogs)
2135 {
2136 if (!SQLQuery(_T("DELETE FROM audit_log")))
2137 if (!g_bIgnoreErrors)
2138 return FALSE;
ce7565e7 2139
a4743a0f
VK
2140 if (!SQLQuery(_T("DELETE FROM event_log")))
2141 if (!g_bIgnoreErrors)
2142 return FALSE;
2143
2144 if (!SQLQuery(_T("DELETE FROM syslog")))
2145 if (!g_bIgnoreErrors)
2146 return FALSE;
2147
2148 if (!SQLQuery(_T("DELETE FROM snmp_trap_log")))
2149 if (!g_bIgnoreErrors)
2150 return FALSE;
2151 }
2152 else
2153 {
2154 // Convert event log
08b214c6 2155 if (!ConvertStrings(_T("event_log"), _T("event_id"), _T("event_message")))
a4743a0f
VK
2156 if (!g_bIgnoreErrors)
2157 return FALSE;
08b214c6 2158 if (!ConvertStrings(_T("event_log"), _T("event_id"), _T("user_tag")))
a4743a0f
VK
2159 if (!g_bIgnoreErrors)
2160 return FALSE;
2161
2162 // Convert audit log
08b214c6 2163 if (!ConvertStrings(_T("audit_log"), _T("record_id"), _T("message")))
a4743a0f
VK
2164 if (!g_bIgnoreErrors)
2165 return FALSE;
2166
2167 // Convert syslog
08b214c6 2168 if (!ConvertStrings(_T("syslog"), _T("msg_id"), _T("msg_text")))
a4743a0f
VK
2169 if (!g_bIgnoreErrors)
2170 return FALSE;
2171
2172 // Convert SNMP trap log
08b214c6 2173 if (!ConvertStrings(_T("snmp_trap_log"), _T("trap_id"), _T("trap_varlist")))
a4743a0f
VK
2174 if (!g_bIgnoreErrors)
2175 return FALSE;
2176 }
ce7565e7
VK
2177
2178 if (!SQLQuery(_T("UPDATE metadata SET var_value='206' WHERE var_name='SchemaVersion'")))
2179 if (!g_bIgnoreErrors)
2180 return FALSE;
2181
2182 return TRUE;
2183}
2184
2185
df8a4ca2
VK
2186//
2187// Upgrade from V204 to V205
2188//
2189
2190static BOOL H_UpgradeFromV204(int currVersion, int newVersion)
2191{
2192 if (!CreateTable(_T("CREATE TABLE usm_credentials (")
2193 _T("id integer not null,")
2194 _T("user_name varchar(255) not null,")
2195 _T("auth_method integer not null,")
2196 _T("priv_method integer not null,")
2197 _T("auth_password varchar(255),")
2198 _T("priv_password varchar(255),")
2199 _T("PRIMARY KEY(id))")))
2200 if (!g_bIgnoreErrors)
2201 return FALSE;
2202
2203 if (!SQLQuery(_T("UPDATE metadata SET var_value='205' WHERE var_name='SchemaVersion'")))
2204 if (!g_bIgnoreErrors)
2205 return FALSE;
2206
2207 return TRUE;
2208}
2209
2210
e2babedf
VK
2211//
2212// Upgrade from V203 to V204
2213//
2214
2215static BOOL H_UpgradeFromV203(int currVersion, int newVersion)
2216{
2217 static TCHAR batch[] =
2218 _T("ALTER TABLE object_properties ADD location_type integer\n")
2219 _T("ALTER TABLE object_properties ADD latitude varchar(20)\n")
2220 _T("ALTER TABLE object_properties ADD longitude varchar(20)\n")
2221 _T("UPDATE object_properties SET location_type=0\n")
2222 _T("ALTER TABLE object_properties DROP COLUMN image_id\n")
2223 _T("<END>");
2224
2225 if (!SQLBatch(batch))
2226 if (!g_bIgnoreErrors)
2227 return FALSE;
2228
2229 if (!CreateConfigParam(_T("ConnectionPoolBaseSize"), _T("5"), 1, 1))
2230 if (!g_bIgnoreErrors)
2231 return FALSE;
2232
2233 if (!CreateConfigParam(_T("ConnectionPoolMaxSize"), _T("20"), 1, 1))
2234 if (!g_bIgnoreErrors)
2235 return FALSE;
2236
2237 if (!CreateConfigParam(_T("ConnectionPoolCooldownTime"), _T("300"), 1, 1))
2238 if (!g_bIgnoreErrors)
2239 return FALSE;
2240
a4743a0f
VK
2241 if (g_iSyntax == DB_SYNTAX_ORACLE)
2242 {
2243 if (!SQLQuery(_T("ALTER TABLE object_properties MODIFY comments null\n")))
2244 if (!g_bIgnoreErrors)
2245 return FALSE;
2246 }
2247
08b214c6 2248 if (!ConvertStrings(_T("object_properties"), _T("object_id"), _T("comments")))
e2babedf
VK
2249 if (!g_bIgnoreErrors)
2250 return FALSE;
2251
2252 if (!SQLQuery(_T("UPDATE metadata SET var_value='204' WHERE var_name='SchemaVersion'")))
2253 if (!g_bIgnoreErrors)
2254 return FALSE;
2255
2256 return TRUE;
2257}
2258
2259
7cda0d53
VK
2260//
2261// Upgrade from V202 to V203
2262//
2263
2264static BOOL H_UpgradeFromV202(int currVersion, int newVersion)
2265{
2266 static TCHAR batch[] =
2267 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text)")
2268 _T(" VALUES (20,'&Info->Topology table (LLDP)',2,'Topology Table',1,' ','Show topology table (LLDP)','#00')\n")
2269 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
2270 _T(" VALUES (20,0,'Chassis ID','.1.0.8802.1.1.2.1.4.1.1.5',0,0)\n")
2271 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
2272 _T(" VALUES (20,1,'Local port','.1.0.8802.1.1.2.1.4.1.1.2',5,0)\n")
2273 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
2274 _T(" VALUES (20,2,'System name','.1.0.8802.1.1.2.1.4.1.1.9',0,0)\n")
2275 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
2276 _T(" VALUES (20,3,'System description','.1.0.8802.1.1.2.1.4.1.1.10',0,0)\n")
2277 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
2278 _T(" VALUES (20,4,'Remote port ID','.1.0.8802.1.1.2.1.4.1.1.7',4,0)\n")
2279 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
2280 _T(" VALUES (20,5,'Remote port description','.1.0.8802.1.1.2.1.4.1.1.8',0,0)\n")
2281 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (20,-2147483648)\n")
2282 _T("<END>");
2283
2284 if (!SQLBatch(batch))
2285 if (!g_bIgnoreErrors)
2286 return FALSE;
2287
2288 if (!SQLQuery(_T("UPDATE metadata SET var_value='203' WHERE var_name='SchemaVersion'")))
2289 if (!g_bIgnoreErrors)
2290 return FALSE;
2291
2292 return TRUE;
2293}
2294
2295
643c9dcb
VK
2296//
2297// Upgrade from V201 to V202
2298//
2299
2300static BOOL H_UpgradeFromV201(int currVersion, int newVersion)
2301{
a4743a0f
VK
2302 if (g_iSyntax == DB_SYNTAX_ORACLE)
2303 {
2304 static TCHAR oraBatch[] =
2305 _T("ALTER TABLE alarms MODIFY message null\n")
2306 _T("ALTER TABLE alarms MODIFY alarm_key null\n")
2307 _T("ALTER TABLE alarms MODIFY hd_ref null\n")
2308 _T("<END>");
2309
2310 if (!SQLBatch(oraBatch))
2311 if (!g_bIgnoreErrors)
2312 return FALSE;
2313 }
2314
08b214c6 2315 if (!ConvertStrings(_T("alarms"), _T("alarm_id"), _T("message")))
643c9dcb
VK
2316 if (!g_bIgnoreErrors)
2317 return FALSE;
08b214c6 2318 if (!ConvertStrings(_T("alarms"), _T("alarm_id"), _T("alarm_key")))
643c9dcb
VK
2319 if (!g_bIgnoreErrors)
2320 return FALSE;
08b214c6 2321 if (!ConvertStrings(_T("alarms"), _T("alarm_id"), _T("hd_ref")))
643c9dcb
VK
2322 if (!g_bIgnoreErrors)
2323 return FALSE;
2324
2325 if (!SQLQuery(_T("UPDATE metadata SET var_value='202' WHERE var_name='SchemaVersion'")))
2326 if (!g_bIgnoreErrors)
2327 return FALSE;
2328
2329 return TRUE;
2330}
2331
2332
31cc1924
VK
2333//
2334// Upgrade from V200 to V201
2335//
2336
2337static BOOL H_UpgradeFromV200(int currVersion, int newVersion)
2338{
2339 static TCHAR batch[] =
2340 _T("ALTER TABLE nodes ADD usm_auth_password varchar(127)\n")
2341 _T("ALTER TABLE nodes ADD usm_priv_password varchar(127)\n")
2342 _T("ALTER TABLE nodes ADD usm_methods integer\n")
e8daf6d5 2343 _T("UPDATE nodes SET usm_auth_password='#00',usm_priv_password='#00',usm_methods=0\n")
31cc1924
VK
2344 _T("<END>");
2345
2346 if (!SQLBatch(batch))
2347 if (!g_bIgnoreErrors)
2348 return FALSE;
2349
2350 if (!SQLQuery(_T("UPDATE metadata SET var_value='201' WHERE var_name='SchemaVersion'")))
2351 if (!g_bIgnoreErrors)
2352 return FALSE;
2353
2354 return TRUE;
2355}
2356
2357
45d84f8a
VK
2358//
2359// Upgrade from V92 to V200
31cc1924 2360// or from V93 to V201
e2babedf
VK
2361// or from V94 to V202
2362// or from V95 to V203
ce7565e7
VK
2363// or from V96 to V204
2364// or from V97 to V205
2365// or from V98 to V206
43c1be79 2366// or from V99 to V207
45d84f8a
VK
2367//
2368
e2babedf 2369static BOOL H_UpgradeFromV9x(int currVersion, int newVersion)
45d84f8a
VK
2370{
2371 if (!CreateTable(_T("CREATE TABLE ap_common (")
2372 _T("id integer not null,")
2373 _T("policy_type integer not null,")
2374 _T("version integer not null,")
2375 _T("description $SQL:TEXT not null,")
2376 _T("PRIMARY KEY(id))")))
2377 if (!g_bIgnoreErrors)
2378 return FALSE;
2379
2380 if (!CreateTable(_T("CREATE TABLE ap_bindings (")
2381 _T("policy_id integer not null,")
2382 _T("node_id integer not null,")
2383 _T("PRIMARY KEY(policy_id,node_id))")))
2384 if (!g_bIgnoreErrors)
2385 return FALSE;
2386
2387 if (!CreateTable(_T("CREATE TABLE ap_config_files (")
2388 _T("policy_id integer not null,")
2389 _T("file_name varchar(63) not null,")
2390 _T("file_content $SQL:TEXT not null,")
2391 _T("PRIMARY KEY(policy_id))")))
2392 if (!g_bIgnoreErrors)
2393 return FALSE;
2394
31cc1924
VK
2395 TCHAR query[256];
2396 _sntprintf(query, 256, _T("UPDATE metadata SET var_value='%d' WHERE var_name='SchemaVersion'"), newVersion);
2397 if (!SQLQuery(query))
45d84f8a
VK
2398 if (!g_bIgnoreErrors)
2399 return FALSE;
2400
2401 return TRUE;
2402}
2403
2404
43c1be79 2405//
50da2d20
VK
2406// Upgrade from V100 to V214
2407// or from V101 to V214
2408// or from V102 to V214
2409// or from V103 to V214
2410// or from V104 to V214
43c1be79
VK
2411//
2412
a8f60046 2413static BOOL H_UpgradeFromV10x(int currVersion, int newVersion)
43c1be79 2414{
50da2d20 2415 if (!H_UpgradeFromV9x(currVersion, 207))
43c1be79
VK
2416 return FALSE;
2417
2418 // Now database at V207 level
50da2d20
VK
2419 // V100 already has changes V209 -> V210, but missing V207 -> V209 and V210 -> V214 changes
2420 // V101 already has changes V209 -> V211, but missing V207 -> V209 and V211 -> V214 changes
2421 // V102 already has changes V209 -> V212, but missing V207 -> V209 and V212 -> V214 changes
2422 // V103 already has changes V209 -> V213, but missing V207 -> V209 and V213 -> V214 changes
2423 // V104 already has changes V209 -> V214, but missing V207 -> V209 changes
43c1be79
VK
2424
2425 if (!H_UpgradeFromV207(207, 208))
2426 return FALSE;
2427
a6c1f07f 2428 if (!H_UpgradeFromV208(208, 209))
43c1be79
VK
2429 return FALSE;
2430
a8f60046 2431 if (currVersion == 100)
50da2d20
VK
2432 if (!H_UpgradeFromV210(210, 211))
2433 return FALSE;
a8f60046 2434
1024e962 2435 if (currVersion < 102)
50da2d20
VK
2436 if (!H_UpgradeFromV211(211, 212))
2437 return FALSE;
1024e962 2438
f57209fd 2439 if (currVersion < 103)
50da2d20
VK
2440 if (!H_UpgradeFromV212(212, 213))
2441 return FALSE;
2442
2443 if (currVersion < 104)
2444 if (!H_UpgradeFromV213(213, 214))
2445 return FALSE;
f57209fd 2446
65e2005b
VK
2447 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='214' WHERE var_name='SchemaVersion'")));
2448 return TRUE;
2449}
2450
2451
2452//
2453// Upgrade from V105 to V217
2454//
2455
2456static BOOL H_UpgradeFromV105(int currVersion, int newVersion)
2457{
2458 if (!H_UpgradeFromV10x(currVersion, 214))
2459 return FALSE;
2460
2461 // V105 already have V216 -> V217 changes, but missing V207 -> V209 and V214 -> V216 changes
2462 if (!H_UpgradeFromV214(214, 215))
2463 return FALSE;
2464
2465 if (!H_UpgradeFromV215(215, 216))
2466 return FALSE;
43c1be79 2467
65e2005b 2468 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='217' WHERE var_name='SchemaVersion'")));
43c1be79
VK
2469 return TRUE;
2470}
2471
2472
6e53f004
VK
2473//
2474// Upgrade from V91 to V92
2475//
2476
31cc1924 2477static BOOL H_UpgradeFromV91(int currVersion, int newVersion)
6e53f004
VK
2478{
2479 static TCHAR batch[] =
2480 _T("DROP TABLE images\n")
2481 _T("DROP TABLE default_images\n")
2482 _T("<END>");
2483
2484 if (!SQLBatch(batch))
2485 if (!g_bIgnoreErrors)
2486 return FALSE;
2487
2488 if (!SQLQuery(_T("UPDATE metadata SET var_value='92' WHERE var_name='SchemaVersion'")))
2489 if (!g_bIgnoreErrors)
2490 return FALSE;
2491
2492 return TRUE;
2493}
2494
2495
c45e0213
VK
2496//
2497// Upgrade from V90 to V91
2498//
2499
31cc1924 2500static BOOL H_UpgradeFromV90(int currVersion, int newVersion)
c45e0213
VK
2501{
2502 if (!CreateTable(_T("CREATE TABLE userdb_custom_attributes (")
2503 _T("object_id integer not null,")
2504 _T("attr_name varchar(255) not null,")
2505 _T("attr_value $SQL:TEXT not null,")
2506 _T("PRIMARY KEY(object_id,attr_name))")))
2507 if (!g_bIgnoreErrors)
2508 return FALSE;
2509
2510 if (!SQLQuery(_T("UPDATE metadata SET var_value='91' WHERE var_name='SchemaVersion'")))
2511 if (!g_bIgnoreErrors)
2512 return FALSE;
2513
2514 return TRUE;
2515}
2516
2517
4262c0dc
VK
2518//
2519// Upgrade from V89 to V90
2520//
2521
31cc1924 2522static BOOL H_UpgradeFromV89(int currVersion, int newVersion)
4262c0dc
VK
2523{
2524 static TCHAR m_szBatch[] =
2525 _T("ALTER TABLE items ADD base_units integer\n")
2526 _T("ALTER TABLE items ADD unit_multiplier integer\n")
2527 _T("ALTER TABLE items ADD custom_units_name varchar(63)\n")
2528 _T("ALTER TABLE items ADD perftab_settings $SQL:TEXT\n")
2529 _T("UPDATE items SET base_units=0,unit_multiplier=1,custom_units_name='#00',perftab_settings='#00'\n")
2530 _T("<END>");
2531
2532 if (!SQLBatch(m_szBatch))
2533 if (!g_bIgnoreErrors)
2534 return FALSE;
2535
2536 if (!SQLQuery(_T("UPDATE metadata SET var_value='90' WHERE var_name='SchemaVersion'")))
2537 if (!g_bIgnoreErrors)
2538 return FALSE;
2539
2540 return TRUE;
2541}
2542
2543
2544//
2545// Upgrade from V88 to V89
2546//
2547
31cc1924 2548static BOOL H_UpgradeFromV88(int currVersion, int newVersion)
4262c0dc
VK
2549{
2550 static TCHAR m_szBatch[] =
2551 _T("ALTER TABLE containers ADD enable_auto_bind integer\n")
2552 _T("ALTER TABLE containers ADD auto_bind_filter $SQL:TEXT\n")
2553 _T("UPDATE containers SET enable_auto_bind=0,auto_bind_filter='#00'\n")
2554 _T("ALTER TABLE cluster_resources ADD current_owner integer\n")
2555 _T("UPDATE cluster_resources SET current_owner=0\n")
2556 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (")
2557 _T("52,'SYS_DB_QUERY_FAILED',4,1,'Database query failed (Query: %1; Error: %2)',")
2558 _T("'Generated when SQL query to backend database failed.#0D#0A")
2559 _T("Parameters:#0D#0A 1) Query#0D#0A 2) Error message')\n")
2560 _T("<END>");
2561
2562 if (!SQLBatch(m_szBatch))
2563 if (!g_bIgnoreErrors)
2564 return FALSE;
2565
2566 if (!SQLQuery(_T("UPDATE metadata SET var_value='89' WHERE var_name='SchemaVersion'")))
2567 if (!g_bIgnoreErrors)
2568 return FALSE;
2569
2570 return TRUE;
2571}
2572
2573
2574//
2575// Upgrade from V87 to V88
2576//
2577
31cc1924 2578static BOOL H_UpgradeFromV87(int currVersion, int newVersion)
4262c0dc
VK
2579{
2580 static TCHAR m_szBatch[] =
2581 _T("ALTER TABLE templates ADD enable_auto_apply integer\n")
2582 _T("ALTER TABLE templates ADD apply_filter $SQL:TEXT\n")
2583 _T("UPDATE templates SET enable_auto_apply=0,apply_filter='#00'\n")
2584 _T("<END>");
2585
2586 if (!SQLBatch(m_szBatch))
2587 if (!g_bIgnoreErrors)
2588 return FALSE;
2589
2590 if (!SQLQuery(_T("UPDATE metadata SET var_value='88' WHERE var_name='SchemaVersion'")))
2591 if (!g_bIgnoreErrors)
2592 return FALSE;
2593
2594 return TRUE;
2595}
2596
2597
28f5b9a4
VK
2598//
2599// Upgrade from V86 to V87
2600//
2601
2602static BOOL MoveConfigToMetadata(const TCHAR *cfgVar, const TCHAR *mdVar)
2603{
2604 TCHAR query[1024], buffer[256];
2605 DB_RESULT hResult;
2606 BOOL success;
2607
2608 _sntprintf(query, 1024, _T("SELECT var_value FROM config WHERE var_name='%s'"), cfgVar);
2609 hResult = SQLSelect(query);
2610 if (hResult != NULL)
2611 {
2612 if (DBGetNumRows(hResult) > 0)
2613 {
2614 DBGetField(hResult, 0, 0, buffer, 256);
2615 DecodeSQLString(buffer);
2616 _sntprintf(query, 1024, _T("INSERT INTO metadata (var_name,var_value) VALUES ('%s','%s')"),
2617 mdVar, buffer);
2618 DBFreeResult(hResult);
2619 success = SQLQuery(query);
2620 if (success)
2621 {
2622 _sntprintf(query, 1024, _T("DELETE FROM config WHERE var_name='%s'"), cfgVar);
2623 success = SQLQuery(query);
2624 }
2625 }
2626 else
2627 {
2628 success = TRUE; // Variable missing in 'config' table, nothing to move
2629 }
2630 }
2631 else
2632 {
2633 success = FALSE;
2634 }
2635 return success;
2636}
2637
31cc1924 2638static BOOL H_UpgradeFromV86(int currVersion, int newVersion)
28f5b9a4
VK
2639{
2640 if (!CreateTable(_T("CREATE TABLE metadata (")
2641 _T("var_name varchar(63) not null,")
2642 _T("var_value varchar(255) not null,")
2643 _T("PRIMARY KEY(var_name))")))
2644 if (!g_bIgnoreErrors)
2645 return FALSE;
2646
2647 if (!MoveConfigToMetadata(_T("DBFormatVersion"), _T("SchemaVersion")))
2648 if (!g_bIgnoreErrors)
2649 return FALSE;
2650
2651 if (!MoveConfigToMetadata(_T("DBSyntax"), _T("Syntax")))
2652 if (!g_bIgnoreErrors)
2653 return FALSE;
2654
2655 if (!MoveConfigToMetadata(_T("IDataTableCreationCommand"), _T("IDataTableCreationCommand")))
2656 if (!g_bIgnoreErrors)
2657 return FALSE;
2658
2659 if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_0"), _T("IDataIndexCreationCommand_0")))
2660 if (!g_bIgnoreErrors)
2661 return FALSE;
2662
2663 if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_1"), _T("IDataIndexCreationCommand_1")))
2664 if (!g_bIgnoreErrors)
2665 return FALSE;
2666
2667 if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_2"), _T("IDataIndexCreationCommand_2")))
2668 if (!g_bIgnoreErrors)
2669 return FALSE;
2670
2671 if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_3"), _T("IDataIndexCreationCommand_3")))
2672 if (!g_bIgnoreErrors)
2673 return FALSE;
2674
2675 if (!SQLQuery(_T("UPDATE metadata SET var_value='87' WHERE var_name='SchemaVersion'")))
2676 if (!g_bIgnoreErrors)
2677 return FALSE;
2678
2679 return TRUE;
2680}
2681
2682
4c4c9b03
VK
2683//
2684// Upgrade from V85 to V86
2685//
2686
31cc1924 2687static BOOL H_UpgradeFromV85(int currVersion, int newVersion)
4c4c9b03
VK
2688{
2689 static TCHAR m_szBatch[] =
2690 _T("DROP TABLE alarm_grops\n")
2691 _T("DROP TABLE alarm_group_map\n")
47912c44
VK
2692 _T("DROP TABLE alarm_change_log\n")
2693 _T("DROP TABLE lpp\n")
2694 _T("DROP TABLE lpp_associations\n")
2695 _T("DROP TABLE lpp_rulesets\n")
2696 _T("DROP TABLE lpp_rules\n")
2697 _T("DROP TABLE lpp_groups\n")
4c4c9b03
VK
2698 _T("<END>");
2699
2700 if (!SQLBatch(m_szBatch))
2701 if (!g_bIgnoreErrors)
2702 return FALSE;
2703
2704 if (!SQLQuery(_T("UPDATE config SET var_value='86' WHERE var_name='DBFormatVersion'")))
2705 if (!g_bIgnoreErrors)
2706 return FALSE;
2707
2708 return TRUE;
2709}
2710
2711
5039dede
AK
2712//
2713// Upgrade from V84 to V85
2714//
2715
31cc1924 2716static BOOL H_UpgradeFromV84(int currVersion, int newVersion)
5039dede
AK
2717{
2718 static TCHAR m_szBatch[] =
2719 _T("ALTER TABLE nodes ADD use_ifxtable integer\n")
2720 _T("UPDATE nodes SET use_ifxtable=0\n")
2721 _T("<END>");
2722
2723 if (!SQLBatch(m_szBatch))
2724 if (!g_bIgnoreErrors)
2725 return FALSE;
2726
2727 if (!CreateConfigParam(_T("UseIfXTable"), _T("1"), 1, 0))
2728 if (!g_bIgnoreErrors)
2729 return FALSE;
2730
2731 if (!CreateConfigParam(_T("SMTPRetryCount"), _T("1"), 1, 0))
2732 if (!g_bIgnoreErrors)
2733 return FALSE;
2734
2735 if (!SQLQuery(_T("UPDATE config SET var_value='85' WHERE var_name='DBFormatVersion'")))
2736 if (!g_bIgnoreErrors)
2737 return FALSE;
2738
2739 return TRUE;
2740}
2741
2742
2743//
2744// Upgrade from V83 to V84
2745//
2746
31cc1924 2747static BOOL H_UpgradeFromV83(int currVersion, int newVersion)
5039dede
AK
2748{
2749 if (!CreateConfigParam(_T("EnableAgentRegistration"), _T("1"), 1, 0))
2750 if (!g_bIgnoreErrors)
2751 return FALSE;
2752
2753 if (!CreateConfigParam(_T("AnonymousFileAccess"), _T("0"), 1, 0))
2754 if (!g_bIgnoreErrors)
2755 return FALSE;
2756
2757 if (!CreateConfigParam(_T("EnableISCListener"), _T("0"), 1, 1))
2758 if (!g_bIgnoreErrors)
2759 return FALSE;
2760
2761 if (!CreateConfigParam(_T("ReceiveForwardedEvents"), _T("0"), 1, 0))
2762 if (!g_bIgnoreErrors)
2763 return FALSE;
2764
2765 if (!SQLQuery(_T("UPDATE config SET var_value='84' WHERE var_name='DBFormatVersion'")))
2766 if (!g_bIgnoreErrors)
2767 return FALSE;
2768
2769 return TRUE;
2770}
2771
2772
2773//
2774// Upgrade from V82 to V83
2775//
2776
31cc1924 2777static BOOL H_UpgradeFromV82(int currVersion, int newVersion)
5039dede
AK
2778{
2779 // Fix incorrect alarm timeouts
2780 if (!SQLQuery(_T("UPDATE alarms SET timeout=0,timeout_event=43")))
2781 if (!g_bIgnoreErrors)
2782 return FALSE;
2783
2784 if (!SQLQuery(_T("UPDATE config SET var_value='83' WHERE var_name='DBFormatVersion'")))
2785 if (!g_bIgnoreErrors)
2786 return FALSE;
2787
2788 return TRUE;
2789}
2790
2791
2792//
2793// Upgrade from V81 to V82
2794//
2795
31cc1924 2796static BOOL H_UpgradeFromV81(int currVersion, int newVersion)
5039dede
AK
2797{
2798 if (!CreateTable(_T("CREATE TABLE config_clob (")
2799 _T("var_name varchar(63) not null,")
2800 _T("var_value $SQL:TEXT not null,")
2801 _T("PRIMARY KEY(var_name))")))
2802 if (!g_bIgnoreErrors)
2803 return FALSE;
2804
2805 if (!SQLQuery(_T("UPDATE config SET var_value='82' WHERE var_name='DBFormatVersion'")))
2806 if (!g_bIgnoreErrors)
2807 return FALSE;
2808
2809 return TRUE;
2810}
2811
2812
2813//
2814// Upgrade from V80 to V81
2815//
2816
31cc1924 2817static BOOL H_UpgradeFromV80(int currVersion, int newVersion)
5039dede
AK
2818{
2819 DB_RESULT hResult;
2820 TCHAR query[1024], buffer[1024];
2821 int i;
2822
2823 // Update dci_schedules table
2824 hResult = SQLSelect(_T("SELECT item_id,schedule FROM dci_schedules"));
2825 if (hResult != NULL)
2826 {
2827 if (!SQLQuery(_T("DROP TABLE dci_schedules")))
2828 if (!g_bIgnoreErrors)
2829 return FALSE;
2830
2831 if (!CreateTable(_T("CREATE TABLE dci_schedules (")
2832 _T("schedule_id integer not null,")
2833 _T("item_id integer not null,")
2834 _T("schedule varchar(255) not null,")
2835 _T("PRIMARY KEY(item_id,schedule_id))")))
2836 if (!g_bIgnoreErrors)
2837 return FALSE;
2838
2839 for(i = 0; i < DBGetNumRows(hResult); i++)
2840 {
2841 _sntprintf(query, 1024, _T("INSERT INTO dci_schedules (item_id,schedule_id,schedule) VALUES(%d,%d,'%s')"),
2842 DBGetFieldULong(hResult, i, 0), i + 1, DBGetField(hResult, i, 1, buffer, 1024));
2843 if (!SQLQuery(query))
2844 if (!g_bIgnoreErrors)
2845 return FALSE;
2846 }
2847 DBFreeResult(hResult);
2848 }
2849 else
2850 {
2851 if (!g_bIgnoreErrors)
2852 return FALSE;
2853 }
2854
2855 // Update address_lists table
2856 hResult = SQLSelect(_T("SELECT list_type,community_id,addr_type,addr1,addr2 FROM address_lists"));
2857 if (hResult != NULL)
2858 {
2859 if (!SQLQuery(_T("DROP TABLE address_lists")))
2860 if (!g_bIgnoreErrors)
2861 return FALSE;
2862
2863 if (!CreateTable(_T("CREATE TABLE address_lists (")
2864 _T("list_type integer not null,")
2865 _T("community_id integer not null,")
2866 _T("addr_type integer not null,")
2867 _T("addr1 varchar(15) not null,")
2868 _T("addr2 varchar(15) not null,")
2869 _T("PRIMARY KEY(list_type,community_id,addr_type,addr1,addr2))")))
2870 if (!g_bIgnoreErrors)
2871 return FALSE;
2872
2873 for(i = 0; i < DBGetNumRows(hResult); i++)
2874 {
2875 _sntprintf(query, 1024, _T("INSERT INTO address_lists (list_type,community_id,addr_type,addr1,addr2) VALUES(%d,%d,%d,'%s','%s')"),
2876 DBGetFieldULong(hResult, i, 0), DBGetFieldULong(hResult, i, 1),
2877 DBGetFieldULong(hResult, i, 2), DBGetField(hResult, i, 3, buffer, 64),
2878 DBGetField(hResult, i, 4, &buffer[128], 64));
2879 if (!SQLQuery(query))
2880 if (!g_bIgnoreErrors)
2881 return FALSE;
2882 }
2883
2884 DBFreeResult(hResult);
2885 }
2886 else
2887 {
2888 if (!g_bIgnoreErrors)
2889 return FALSE;
2890 }
2891
2892 // Create new tables
2893 if (!CreateTable(_T("CREATE TABLE object_custom_attributes (")
2894 _T("object_id integer not null,")
2895 _T("attr_name varchar(127) not null,")
2896 _T("attr_value $SQL:TEXT not null,")
2897 _T("PRIMARY KEY(object_id,attr_name))")))
2898 if (!g_bIgnoreErrors)
2899 return FALSE;
2900
2901 if (!CreateTable(_T("CREATE TABLE web_maps (")
2902 _T("id integer not null,")
2903 _T("title varchar(63) not null,")
2904 _T("properties $SQL:TEXT not null,")
2905 _T("data $SQL:TEXT not null,")
2906 _T("PRIMARY KEY(id))")))
2907 if (!g_bIgnoreErrors)
2908 return FALSE;
2909
2910 if (!SQLQuery(_T("UPDATE config SET var_value='81' WHERE var_name='DBFormatVersion'")))
2911 if (!g_bIgnoreErrors)
2912 return FALSE;
2913
2914 return TRUE;
2915}
2916
2917
2918//
2919// Upgrade from V79 to V80
2920//
2921
31cc1924 2922static BOOL H_UpgradeFromV79(int currVersion, int newVersion)
5039dede
AK
2923{
2924 static TCHAR m_szBatch[] =
2925 _T("ALTER TABLE nodes ADD uname varchar(255)\n")
2926 _T("UPDATE nodes SET uname='#00'\n")
2927 _T("<END>");
2928
2929 if (!SQLBatch(m_szBatch))
2930 if (!g_bIgnoreErrors)
2931 return FALSE;
2932
2933 if (!SQLQuery(_T("UPDATE config SET var_value='80' WHERE var_name='DBFormatVersion'")))
2934 if (!g_bIgnoreErrors)
2935 return FALSE;
2936
2937 return TRUE;
2938}
2939
2940
2941//
2942// Upgrade from V78 to V79
2943//
2944
31cc1924 2945static BOOL H_UpgradeFromV78(int currVersion, int newVersion)
5039dede
AK
2946{
2947 static TCHAR m_szBatch[] =
2948 _T("DELETE FROM config WHERE var_name='RetainCustomInterfaceNames'\n")
2949 _T("DROP TABLE modules\n")
2950 _T("<END>");
2951 static TCHAR m_szMySQLBatch[] =
2952 _T("ALTER TABLE users MODIFY COLUMN cert_mapping_data text not null\n")
2953 _T("ALTER TABLE user_profiles MODIFY COLUMN var_value text not null\n")
2954 _T("ALTER TABLE object_properties MODIFY COLUMN comments text not null\n")
2955 _T("ALTER TABLE network_services MODIFY COLUMN check_request text not null\n")
2956 _T("ALTER TABLE network_services MODIFY COLUMN check_responce text not null\n")
2957 _T("ALTER TABLE conditions MODIFY COLUMN script text not null\n")
2958 _T("ALTER TABLE container_categories MODIFY COLUMN description text not null\n")
2959 _T("ALTER TABLE items MODIFY COLUMN transformation text not null\n")
2960 _T("ALTER TABLE event_cfg MODIFY COLUMN description text not null\n")
2961 _T("ALTER TABLE actions MODIFY COLUMN action_data text not null\n")
2962 _T("ALTER TABLE event_policy MODIFY COLUMN comments text not null\n")
2963 _T("ALTER TABLE event_policy MODIFY COLUMN script text not null\n")
2964 _T("ALTER TABLE alarm_change_log MODIFY COLUMN info_text text not null\n")
2965 _T("ALTER TABLE alarm_notes MODIFY COLUMN note_text text not null\n")
2966 _T("ALTER TABLE object_tools MODIFY COLUMN tool_data text not null\n")
2967 _T("ALTER TABLE syslog MODIFY COLUMN msg_text text not null\n")
2968 _T("ALTER TABLE script_library MODIFY COLUMN script_code text not null\n")
2969 _T("ALTER TABLE snmp_trap_log MODIFY COLUMN trap_varlist text not null\n")
2970 _T("ALTER TABLE maps MODIFY COLUMN description text not null\n")
2971 _T("ALTER TABLE agent_configs MODIFY COLUMN config_file text not null\n")
2972 _T("ALTER TABLE agent_configs MODIFY COLUMN config_filter text not null\n")
2973 _T("ALTER TABLE graphs MODIFY COLUMN config text not null\n")
2974 _T("ALTER TABLE certificates MODIFY COLUMN cert_data text not null\n")
2975 _T("ALTER TABLE certificates MODIFY COLUMN subject text not null\n")
2976 _T("ALTER TABLE certificates MODIFY COLUMN comments text not null\n")
2977 _T("ALTER TABLE audit_log MODIFY COLUMN message text not null\n")
2978 _T("ALTER TABLE situations MODIFY COLUMN comments text not null\n")
2979 _T("<END>");
2980
2981 if (!SQLBatch(m_szBatch))
2982 if (!g_bIgnoreErrors)
2983 return FALSE;
2984
2985 if (g_iSyntax == DB_SYNTAX_MYSQL)
2986 {
2987 if (!SQLBatch(m_szMySQLBatch))
2988 if (!g_bIgnoreErrors)
2989 return FALSE;
2990 }
2991
2992 if (!SQLQuery(_T("UPDATE config SET var_value='79' WHERE var_name='DBFormatVersion'")))
2993 if (!g_bIgnoreErrors)
2994 return FALSE;
2995
2996 return TRUE;
2997}
2998
2999
3000//
3001// Upgrade from V77 to V78
3002//
3003
31cc1924 3004static BOOL H_UpgradeFromV77(int currVersion, int newVersion)
5039dede
AK
3005{
3006 if (!CreateTable(_T("CREATE TABLE trusted_nodes (")
3007 _T("source_object_id integer not null,")
3008 _T("target_node_id integer not null,")
3009 _T("PRIMARY KEY(source_object_id,target_node_id))")))
3010 if (!g_bIgnoreErrors)
3011 return FALSE;
3012
3013 if (!CreateConfigParam(_T("CheckTrustedNodes"), _T("1"), 1, 1))
3014 if (!g_bIgnoreErrors)
3015 return FALSE;
3016
3017 if (!SQLQuery(_T("UPDATE config SET var_value='78' WHERE var_name='DBFormatVersion'")))
3018 if (!g_bIgnoreErrors)
3019 return FALSE;
3020
3021 return TRUE;
3022}
3023
3024
3025//
3026// Upgrade from V76 to V77
3027//
3028
31cc1924 3029static BOOL H_UpgradeFromV76(int currVersion, int newVersion)
5039dede
AK
3030{
3031 DB_RESULT hResult;
3032 int i, count, seq;
3033 DWORD id, lastId;
3034 TCHAR query[1024];
3035
3036 hResult = SQLSelect(_T("SELECT condition_id,dci_id,node_id,dci_func,num_polls FROM cond_dci_map ORDER BY condition_id"));
3037 if (hResult == NULL)
3038 if (!g_bIgnoreErrors)
3039 return FALSE;
3040
3041 if (!SQLQuery(_T("DROP TABLE cond_dci_map")))
3042 if (!g_bIgnoreErrors)
3043 goto error;
3044
3045 if (!CreateTable(_T("CREATE TABLE cond_dci_map (")
3046 _T("condition_id integer not null,")
3047 _T("sequence_number integer not null,")
3048 _T("dci_id integer not null,")
3049 _T("node_id integer not null,")
3050 _T("dci_func integer not null,")
3051 _T("num_polls integer not null,")
3052 _T("PRIMARY KEY(condition_id,sequence_number))")))
3053 if (!g_bIgnoreErrors)
3054 goto error;
3055
3056 count = DBGetNumRows(hResult);
3057 for(i = 0, seq = 0, lastId = 0; i < count; i++, seq++)
3058 {
3059 id = DBGetFieldULong(hResult, i, 0);
3060 if (id != lastId)
3061 {
3062 seq = 0;
3063 lastId = id;
3064 }
3065 _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)"),
3066 id, seq, DBGetFieldULong(hResult, i, 1), DBGetFieldULong(hResult, i, 2),
3067 DBGetFieldULong(hResult, i, 3), DBGetFieldULong(hResult, i, 4));
3068 if (!SQLQuery(query))
3069 if (!g_bIgnoreErrors)
3070 goto error;
3071 }
3072
3073 DBFreeResult(hResult);
3074
3075 if (!SQLQuery(_T("UPDATE config SET var_value='77' WHERE var_name='DBFormatVersion'")))
3076 if (!g_bIgnoreErrors)
3077 return FALSE;
3078
3079 return TRUE;
3080
3081error:
3082 DBFreeResult(hResult);
3083 return FALSE;
3084}
3085
3086
3087//
3088// Upgrade from V75 to V76
3089//
3090
31cc1924 3091static BOOL H_UpgradeFromV75(int currVersion, int newVersion)
5039dede
AK
3092{
3093 static TCHAR m_szBatch[] =
3094 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (")
3095 _T("50,'SYS_NETWORK_CONN_LOST',4,1,'NetXMS server network connectivity lost',")
3096 _T("'Generated when system detects loss of network connectivity based on beacon ")
3097 _T("probing.#0D#0AParameters:#0D#0A 1) Number of beacons')\n")
3098 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (")
3099 _T("51,'SYS_NETWORK_CONN_RESTORED',0,1,'NetXMS server network connectivity restored',")
3100 _T("'Generated when system detects restoration of network connectivity based on ")
3101 _T("beacon probing.#0D#0AParameters:#0D#0A 1) Number of beacons')\n")
3102 _T("<END>");
3103
3104 if (!SQLBatch(m_szBatch))
3105 if (!g_bIgnoreErrors)
3106 return FALSE;
3107
3108 if (!CreateConfigParam(_T("AgentCommandTimeout"), _T("2000"), 1, 1))
3109 if (!g_bIgnoreErrors)
3110 return FALSE;
3111
3112 if (!CreateConfigParam(_T("BeaconHosts"), _T(""), 1, 1))
3113 if (!g_bIgnoreErrors)
3114 return FALSE;
3115
3116 if (!CreateConfigParam(_T("BeaconTimeout"), _T("1000"), 1, 1))
3117 if (!g_bIgnoreErrors)
3118 return FALSE;
3119
3120 if (!CreateConfigParam(_T("BeaconPollingInterval"), _T("1000"), 1, 1))
3121 if (!g_bIgnoreErrors)
3122 return FALSE;
3123
3124 if (!SQLQuery(_T("UPDATE config SET var_value='76' WHERE var_name='DBFormatVersion'")))
3125 if (!g_bIgnoreErrors)
3126 return FALSE;
3127
3128 return TRUE;
3129}
3130
3131
3132//
3133// Upgrade from V74 to V75
3134//
3135
31cc1924 3136static BOOL H_UpgradeFromV74(int currVersion, int newVersion)
5039dede
AK
3137{
3138 static TCHAR m_szBatch[] =
3139 _T("ALTER TABLE address_lists ADD community_id integer\n")
3140 _T("UPDATE address_lists SET community_id=0\n")
3141 _T("<END>");
3142
3143 if (!SQLBatch(m_szBatch))
3144 if (!g_bIgnoreErrors)
3145 return FALSE;
3146
3147 if (!CreateTable(_T("CREATE TABLE snmp_communities (")
3148 _T("id integer not null,")
3149 _T("community varchar(255) not null,")
3150 _T("PRIMARY KEY(id))")))
3151 if (!g_bIgnoreErrors)
3152 return FALSE;
3153
3154 if (!CreateConfigParam(_T("UseInterfaceAliases"), _T("0"), 1, 0))
3155 if (!g_bIgnoreErrors)
3156 return FALSE;
3157
3158 if (!CreateConfigParam(_T("SyncNodeNamesWithDNS"), _T("0"), 1, 0))
3159 if (!g_bIgnoreErrors)
3160 return FALSE;
3161
3162 if (!SQLQuery(_T("UPDATE config SET var_value='75' WHERE var_name='DBFormatVersion'")))
3163 if (!g_bIgnoreErrors)
3164 return FALSE;
3165
3166 return TRUE;
3167}
3168
3169
3170//
3171// Upgrade from V73 to V74
3172//
3173
31cc1924 3174static BOOL H_UpgradeFromV73(int currVersion, int newVersion)
5039dede
AK
3175{
3176 static TCHAR m_szBatch[] =
3177 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
3178 _T("VALUES (48,'SYS_EVENT_STORM_DETECTED',3,1,'Event storm detected (Events per second: %1)',")
3179 _T("'Generated when system detects an event storm.#0D#0AParameters:#0D#0A")
3180 _T(" 1) Events per second#0D#0A 2) Duration#0D#0A 3) Threshold')\n")
3181 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
3182 _T("VALUES (49,'SYS_EVENT_STORM_ENDED',0,1,'Event storm ended',")
3183 _T("'Generated when system clears event storm condition.#0D#0AParameters:#0D#0A")
3184 _T(" 1) Events per second#0D#0A 2) Duration#0D#0A 3) Threshold')\n")
3185 _T("DELETE FROM config WHERE var_name='NumberOfEventProcessors'\n")
3186 _T("DELETE FROM config WHERE var_name='EventStormThreshold'\n")
3187 _T("<END>");
3188
3189 if (!SQLBatch(m_szBatch))
3190 if (!g_bIgnoreErrors)
3191 return FALSE;
3192
3193 if (!CreateConfigParam(_T("EnableEventStormDetection"), _T("0"), 1, 1))
3194 if (!g_bIgnoreErrors)
3195 return FALSE;
3196
3197 if (!CreateConfigParam(_T("EventStormEventsPerSecond"), _T("100"), 1, 1))
3198 if (!g_bIgnoreErrors)
3199 return FALSE;
3200
3201 if (!CreateConfigParam(_T("EventStormDuration"), _T("15"), 1, 1))
3202 if (!g_bIgnoreErrors)
3203 return FALSE;
3204
3205 if (!SQLQuery(_T("UPDATE config SET var_value='74' WHERE var_name='DBFormatVersion'")))
3206 if (!g_bIgnoreErrors)
3207 return FALSE;
3208
3209 return TRUE;
3210}
3211
3212
3213//
3214// Upgrade from V72 to V73
3215//
3216
31cc1924 3217static BOOL H_UpgradeFromV72(int currVersion, int newVersion)
5039dede
AK
3218{
3219 static TCHAR m_szBatch[] =
3220 _T("ALTER TABLE event_policy ADD situation_id integer\n")
3221 _T("ALTER TABLE event_policy ADD situation_instance varchar(255)\n")
3222 _T("UPDATE event_policy SET situation_id=0,situation_instance='#00'\n")
3223 _T("<END>");
3224
3225 if (!SQLBatch(m_szBatch))
3226 if (!g_bIgnoreErrors)
3227 return FALSE;
3228
3229 if (!CreateTable(_T("CREATE TABLE policy_situation_attr_list (")
3230 _T("rule_id integer not null,")
3231 _T("situation_id integer not null,")
3232 _T("attr_name varchar(255) not null,")
3233 _T("attr_value varchar(255) not null,")
3234 _T("PRIMARY KEY(rule_id,situation_id,attr_name))")))
3235 if (!g_bIgnoreErrors)
3236 return FALSE;
3237
3238 if (!CreateTable(_T("CREATE TABLE situations (")
3239 _T("id integer not null,")
3240 _T("name varchar(127) not null,")
3241 _T("comments $SQL:TEXT not null,")
3242 _T("PRIMARY KEY(id))")))
3243 if (!g_bIgnoreErrors)
3244 return FALSE;
3245
3246 if (!CreateConfigParam(_T("RetainCustomInterfaceNames"), _T("0"), 1, 0))
3247 if (!g_bIgnoreErrors)
3248 return FALSE;
3249
3250 if (!CreateConfigParam(_T("AllowDirectSMS"), _T("0"), 1, 0))
3251 if (!g_bIgnoreErrors)
3252 return FALSE;
3253
3254 if (!CreateConfigParam(_T("EventStormThreshold"), _T("0"), 1, 1))
3255 if (!g_bIgnoreErrors)
3256 return FALSE;
3257
3258 if (!SQLQuery(_T("UPDATE config SET var_value='73' WHERE var_name='DBFormatVersion'")))
3259 if (!g_bIgnoreErrors)
3260 return FALSE;
3261
3262 return TRUE;
3263}
3264
3265
3266//
3267// Upgrade from V71 to V72
3268//
3269
31cc1924 3270static BOOL H_UpgradeFromV71(int currVersion, int newVersion)
5039dede
AK
3271{
3272 static TCHAR m_szBatch[] =
3273 _T("ALTER TABLE items ADD proxy_node integer\n")
3274 _T("UPDATE items SET proxy_node=0\n")
3275 _T("<END>");
3276
3277 if (!SQLBatch(m_szBatch))
3278 if (!g_bIgnoreErrors)
3279 return FALSE;
3280
3281 if (!SQLQuery(_T("UPDATE config SET var_value='72' WHERE var_name='DBFormatVersion'")))
3282 if (!g_bIgnoreErrors)
3283 return FALSE;
3284
3285 return TRUE;
3286}
3287
3288
3289//
3290// Upgrade from V70 to V71
3291//
3292
31cc1924 3293static BOOL H_UpgradeFromV70(int currVersion, int newVersion)
5039dede
AK
3294{
3295 static TCHAR m_szBatch[] =
3296 _T("ALTER TABLE nodes ADD required_polls integer\n")
3297 _T("UPDATE nodes SET required_polls=0\n")
3298 _T("ALTER TABLE interfaces ADD required_polls integer\n")
3299 _T("UPDATE interfaces SET required_polls=0\n")
3300 _T("ALTER TABLE network_services ADD required_polls integer\n")
3301 _T("UPDATE network_services SET required_polls=0\n")
3302 _T("<END>");
3303
3304 if (!SQLBatch(m_szBatch))
3305 if (!g_bIgnoreErrors)
3306 return FALSE;
3307
3308 if (!CreateConfigParam(_T("PollCountForStatusChange"), _T("1"), 1, 1))
3309 if (!g_bIgnoreErrors)
3310 return FALSE;
3311
3312 if (!SQLQuery(_T("UPDATE config SET var_value='71' WHERE var_name='DBFormatVersion'")))
3313 if (!g_bIgnoreErrors)
3314 return FALSE;
3315
3316 return TRUE;
3317}
3318
3319
3320//
3321// Upgrade from V69 to V70
3322//
3323
31cc1924 3324static BOOL H_UpgradeFromV69(int currVersion, int newVersion)
5039dede
AK
3325{
3326 static TCHAR m_szBatch[] =
3327 _T("ALTER TABLE snmp_trap_cfg ADD user_tag varchar(63)\n")
3328 _T("UPDATE snmp_trap_cfg SET user_tag='#00'\n")
3329 _T("ALTER TABLE event_log ADD user_tag varchar(63)\n")
3330 _T("UPDATE event_log SET user_tag='#00'\n")
3331 _T("<END>");
3332 int n;
3333 TCHAR buffer[64];
3334
3335 if (!SQLBatch(m_szBatch))
3336 if (!g_bIgnoreErrors)
3337 return FALSE;
3338
3339 // Convert event log retention time from seconds to days
3340 n = ConfigReadInt(_T("EventLogRetentionTime"), 5184000) / 86400;
08b214c6 3341 _sntprintf(buffer, 64, _T("%d"), max(n, 1));
5039dede
AK
3342 if (!CreateConfigParam(_T("EventLogRetentionTime"), buffer, 1, 0, TRUE))
3343 if (!g_bIgnoreErrors)
3344 return FALSE;
3345
3346 // Convert event log retention time from seconds to days
3347 n = ConfigReadInt(_T("SyslogRetentionTime"), 5184000) / 86400;
08b214c6 3348 _sntprintf(buffer, 64, _T("%d"), max(n, 1));
5039dede
AK
3349 if (!CreateConfigParam(_T("SyslogRetentionTime"), buffer, 1, 0, TRUE))
3350 if (!g_bIgnoreErrors)
3351 return FALSE;
3352
3353 if (!SQLQuery(_T("UPDATE config SET var_value='70' WHERE var_name='DBFormatVersion'")))
3354 if (!g_bIgnoreErrors)
3355 return FALSE;
3356
3357 return TRUE;
3358}
3359
3360
3361//
3362// Upgrade from V68 to V69
3363//
3364
31cc1924 3365static BOOL H_UpgradeFromV68(int currVersion, int newVersion)
5039dede
AK
3366{
3367 if (!CreateTable(_T("CREATE TABLE audit_log (")
3368 _T("record_id integer not null,")
3369 _T("timestamp integer not null,")
3370 _T("subsystem varchar(32) not null,")
3371 _T("success integer not null,")
3372 _T("user_id integer not null,")
3373 _T("workstation varchar(63) not null,")
3374 _T("object_id integer not null,")
3375 _T("message $SQL:TEXT not null,")
3376 _T("PRIMARY KEY(record_id))")))
3377 if (!g_bIgnoreErrors)
3378 return FALSE;
3379
3380 if (!CreateConfigParam(_T("EnableAuditLog"), _T("1"), 1, 1))
3381 if (!g_bIgnoreErrors)
3382 return FALSE;
3383
3384 if (!CreateConfigParam(_T("AuditLogRetentionTime"), _T("90"), 1, 0))
3385 if (!g_bIgnoreErrors)
3386 return FALSE;
3387
3388 if (!SQLQuery(_T("UPDATE config SET var_value='69' WHERE var_name='DBFormatVersion'")))
3389 if (!g_bIgnoreErrors)
3390 return FALSE;
3391
3392 return TRUE;
3393}
3394
3395
3396//
3397// Upgrade from V67 to V68
3398//
3399
31cc1924 3400static BOOL H_UpgradeFromV67(int currVersion, int newVersion)
5039dede
AK
3401{
3402 static TCHAR m_szBatch[] =
3403 _T("ALTER TABLE thresholds ADD repeat_interval integer\n")
3404 _T("UPDATE thresholds SET repeat_interval=-1\n")
3405 _T("<END>");
3406
3407 if (!SQLBatch(m_szBatch))
3408 if (!g_bIgnoreErrors)
3409 return FALSE;
3410
3411 if (!CreateConfigParam(_T("ThresholdRepeatInterval"), _T("0"), 1, 1))
3412 if (!g_bIgnoreErrors)
3413 return FALSE;
3414
3415 if (!SQLQuery(_T("UPDATE config SET var_value='68' WHERE var_name='DBFormatVersion'")))
3416 if (!g_bIgnoreErrors)
3417 return FALSE;
3418
3419 return TRUE;
3420}
3421
3422
3423//
3424// Upgrade from V66 to V67
3425//
3426
31cc1924 3427static BOOL H_UpgradeFromV66(int currVersion, int newVersion)
5039dede
AK
3428{
3429 static TCHAR m_szBatch[] =
3430 _T("ALTER TABLE subnets ADD synthetic_mask integer\n")
3431 _T("UPDATE subnets SET synthetic_mask=0\n")
3432 _T("ALTER TABLE interfaces ADD synthetic_mask integer\n")
3433 _T("UPDATE interfaces SET synthetic_mask=0\n")
3434 _T("<END>");
3435
3436 if (!SQLBatch(m_szBatch))
3437 if (!g_bIgnoreErrors)
3438 return FALSE;
3439
3440 if (!SQLQuery(_T("UPDATE config SET var_value='67' WHERE var_name='DBFormatVersion'")))
3441 if (!g_bIgnoreErrors)
3442 return FALSE;
3443
3444 return TRUE;
3445}
3446
3447
3448//
3449// Upgrade from V65 to V66
3450//
3451
31cc1924 3452static BOOL H_UpgradeFromV65(int currVersion, int newVersion)
5039dede
AK
3453{
3454 static TCHAR m_szBatch[] =
3455 _T("ALTER TABLE submap_links ADD port1 varchar(255)\n")
3456 _T("ALTER TABLE submap_links ADD port2 varchar(255)\n")
3457 _T("UPDATE submap_links SET port1='#00',port2='#00'\n")
3458 _T("<END>");
3459
3460 if (!SQLBatch(m_szBatch))
3461 if (!g_bIgnoreErrors)
3462 return FALSE;
3463
3464 if (!SQLQuery(_T("UPDATE config SET var_value='66' WHERE var_name='DBFormatVersion'")))
3465 if (!g_bIgnoreErrors)
3466 return FALSE;
3467
3468 return TRUE;
3469}
3470
3471
3472//
3473// Upgrade from V64 to V65
3474//
3475
31cc1924 3476static BOOL H_UpgradeFromV64(int currVersion, int newVersion)
5039dede
AK
3477{
3478 static TCHAR m_szPGSQLBatch[] =
3479 _T("ALTER TABLE nodes ADD new_community varchar(127)\n")
3480 _T("UPDATE nodes SET new_community=community\n")
3481 _T("ALTER TABLE nodes DROP COLUMN community\n")
3482 _T("ALTER TABLE nodes RENAME COLUMN new_community TO community\n")
3483 _T("ALTER TABLE nodes ALTER COLUMN community SET NOT NULL\n")
3484 _T("<END>");
3485
3486 switch(g_iSyntax)
3487 {
3488 case DB_SYNTAX_MYSQL:
3489 case DB_SYNTAX_ORACLE:
3490 if (!SQLQuery(_T("ALTER TABLE nodes MODIFY community varchar(127)")))
3491 if (!g_bIgnoreErrors)
3492 return FALSE;
3493 break;
3494 case DB_SYNTAX_PGSQL:
3495 if (g_bTrace)
3496 ShowQuery(_T("ALTER TABLE nodes ALTER COLUMN community TYPE varchar(127)"));
3497
3498 if (!DBQuery(g_hCoreDB, _T("ALTER TABLE nodes ALTER COLUMN community TYPE varchar(127)")))
3499 {
3500 // Assume that we are using PostgreSQL oldest than 8.x
3501 if (!SQLBatch(m_szPGSQLBatch))
3502 if (!g_bIgnoreErrors)
3503 return FALSE;
3504 }
3505 break;
3506 case DB_SYNTAX_MSSQL:
3507 if (!SQLQuery(_T("ALTER TABLE nodes ALTER COLUMN community varchar(127)")))
3508 if (!g_bIgnoreErrors)
3509 return FALSE;
3510 break;
3511 case DB_SYNTAX_SQLITE:
3512 _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"));
3513 break;
3514 default:
3515 _tprintf(_T("INTERNAL ERROR: Unknown database syntax %d\n"), g_iSyntax);
3516 break;
3517 }
3518
3519 if (!SQLQuery(_T("UPDATE config SET var_value='65' WHERE var_name='DBFormatVersion'")))
3520 if (!g_bIgnoreErrors)
3521 return FALSE;
3522
3523 return TRUE;
3524}
3525
3526
3527//
3528// Upgrade from V63 to V64
3529//
3530
31cc1924 3531static BOOL H_UpgradeFromV63(int currVersion, int newVersion)
5039dede
AK
3532{
3533 static TCHAR m_szBatch[] =
3534 _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")
3535 _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")
3536 _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")
3537 _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")
3538 _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")
3539 _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")
3540 _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")
3541 _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")
3542 _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")
3543 _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")
3544 _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")
3545 _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")
3546 _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")
3547 _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")
3548 _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")
3549 _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")
3550 _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")
3551 _T("<END>");
3552
3553 if (!SQLBatch(m_szBatch))
3554 if (!g_bIgnoreErrors)
3555 return FALSE;
3556
3557 if (!SQLQuery(_T("UPDATE config SET var_value='64' WHERE var_name='DBFormatVersion'")))
3558 if (!g_bIgnoreErrors)
3559 return FALSE;
3560
3561 return TRUE;
3562}
3563
3564
3565//
3566// Upgrade from V62 to V63
3567//
3568
31cc1924 3569static BOOL H_UpgradeFromV62(int currVersion, int newVersion)
5039dede
AK
3570{
3571 static TCHAR m_szBatch[] =
3572 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
3573 _T("VALUES (45,'SYS_IF_UNKNOWN',1,1,")
3574 _T("'Interface \"%2\" changed state to UNKNOWN (IP Addr: %3/%4, IfIndex: %5)',")
3575 _T("'Generated when interface goes to unknown state.#0D#0A")
3576 _T("Please note that source of event is node, not an interface itself.#0D#0A")
3577 _T("Parameters:#0D#0A 1) Interface object ID#0D#0A 2) Interface name#0D#0A")
3578 _T(" 3) Interface IP address#0D#0A 4) Interface netmask#0D#0A")
3579 _T(" 5) Interface index')\n")
3580 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
3581 _T("VALUES (46,'SYS_IF_DISABLED',0,1,")
3582 _T("'Interface \"%2\" disabled (IP Addr: %3/%4, IfIndex: %5)',")
3583 _T("'Generated when interface administratively disabled.#0D#0A")
3584 _T("Please note that source of event is node, not an interface itself.#0D#0A")
3585 _T("Parameters:#0D#0A 1) Interface object ID#0D#0A 2) Interface name#0D#0A")
3586 _T(" 3) Interface IP address#0D#0A 4) Interface netmask#0D#0A")
3587 _T(" 5) Interface index')\n")
3588 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
3589 _T("VALUES (47,'SYS_IF_TESTING',0,1,")
3590 _T("'Interface \"%2\" is testing (IP Addr: %3/%4, IfIndex: %5)',")
3591 _T("'Generated when interface goes to testing state.#0D#0A")
3592 _T("Please note that source of event is node, not an interface itself.#0D#0A")
3593 _T("Parameters:#0D#0A 1) Interface object ID#0D#0A 2) Interface name#0D#0A")
3594 _T(" 3) Interface IP address#0D#0A 4) Interface netmask#0D#0A")
3595 _T(" 5) Interface index')\n")
3596 _T("<END>");
3597
3598 if (!SQLBatch(m_szBatch))
3599 if (!g_bIgnoreErrors)
3600 return FALSE;
3601
3602 if (!SQLQuery(_T("UPDATE config SET var_value='63' WHERE var_name='DBFormatVersion'")))
3603 if (!g_bIgnoreErrors)
3604 return FALSE;
3605
3606 return TRUE;
3607}
3608
3609
3610//
3611// Upgrade from V61 to V62
3612//
3613
31cc1924 3614static BOOL H_UpgradeFromV61(int currVersion, int newVersion)
5039dede
AK
3615{
3616 static TCHAR m_szBatch[] =
3617 _T("UPDATE event_policy SET alarm_key=alarm_ack_key WHERE alarm_severity=6\n")
3618 _T("ALTER TABLE event_policy DROP COLUMN alarm_ack_key\n")
3619 _T("ALTER TABLE event_policy ADD alarm_timeout integer\n")
3620 _T("ALTER TABLE event_policy ADD alarm_timeout_event integer\n")
3621 _T("UPDATE event_policy SET alarm_timeout=0,alarm_timeout_event=43\n")
3622 _T("ALTER TABLE alarms ADD timeout integer\n")
3623 _T("ALTER TABLE alarms ADD timeout_event integer\n")
3624 _T("UPDATE alarms SET timeout=0,timeout_event=43\n")
3625 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
3626 _T("VALUES (43,'SYS_ALARM_TIMEOUT',1,1,'Alarm timeout expired (ID: %1; Text: %2)',")
3627 _T("'Generated when alarm timeout expires.#0D#0AParameters:#0D#0A")
3628 _T(" 1) Alarm ID#0D#0A 2) Alarm message#0D#0A 3) Alarm key#0D#0A 4) Event code')\n")
3629 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) ")
3630 _T("VALUES (44,'SYS_LOG_RECORD_MATCHED',1,1,")
3631 _T("'Log record matched (Policy: %1; File: %2; Record: %4)',")
3632 _T("'Default event for log record match.#0D#0AParameters:#0D#0A")
3633 _T(" 1) Policy name#0D#0A 2) Log file name#0D#0A 3) Matching regular expression#0D#0A")
3634 _T(" 4) Matched record#0D#0A 5 .. 9) Reserved#0D#0A")
3635 _T(" 10 .. 99) Substrings extracted by regular expression')\n")
3636 _T("<END>");
3637
3638 if (!SQLBatch(m_szBatch))
3639 if (!g_bIgnoreErrors)
3640 return FALSE;
3641
3642 if (!CreateTable(_T("CREATE TABLE lpp_groups (")
3643 _T("lpp_group_id integer not null,")
3644 _T("lpp_group_name varchar(63) not null,")
3645 _T("parent_group integer not null,")
3646 _T("PRIMARY KEY(lpp_group_id))")))
3647 if (!g_bIgnoreErrors)
3648 return FALSE;
3649
3650 if (!CreateTable(_T("CREATE TABLE lpp (")
3651 _T("lpp_id integer not null,")
3652 _T("lpp_group_id integer not null,")
3653 _T("lpp_name varchar(63) not null,")
3654 _T("lpp_version integer not null,")
3655 _T("lpp_flags integer not null,")
3656 _T("PRIMARY KEY(lpp_id))")))
3657 if (!g_bIgnoreErrors)
3658 return FALSE;
3659
3660 if (!CreateTable(_T("CREATE TABLE lpp_associations (")
3661 _T("lpp_id integer not null,")
3662 _T("node_id integer not null,")
3663 _T("log_file varchar(255) not null)")))
3664 if (!g_bIgnoreErrors)
3665 return FALSE;
3666
3667 if (!CreateTable(_T("CREATE TABLE lpp_rulesets (")
3668 _T("ruleset_id integer not null,")
3669 _T("ruleset_name varchar(63),")
3670 _T("PRIMARY KEY(ruleset_id))")))
3671 if (!g_bIgnoreErrors)
3672 return FALSE;
3673
3674 if (!CreateTable(_T("CREATE TABLE lpp_rules (")
3675 _T("lpp_id integer not null,")
3676 _T("rule_number integer not null,")
3677 _T("ruleset_id integer not null,")
3678 _T("msg_id_start integer not null,")
3679 _T("msg_id_end integer not null,")
3680 _T("severity integer not null,")
3681 _T("source_name varchar(255) not null,")
3682 _T("msg_text_regexp varchar(255) not null,")
3683 _T("event_code integer not null,")
3684 _T("PRIMARY KEY(lpp_id,rule_number))")))
3685 if (!g_bIgnoreErrors)
3686 return FALSE;
3687
3688 if (!SQLQuery(_T("UPDATE config SET var_value='62' WHERE var_name='DBFormatVersion'")))
3689 if (!g_bIgnoreErrors)
3690 return FALSE;
3691
3692 return TRUE;
3693}
3694
3695
3696//
3697// Upgrade from V60 to V61
3698//