fixed bug in event import
[public/netxms.git] / src / server / core / import.cpp
CommitLineData
4cd1e46b
AK
1/*
2** NetXMS - Network Management System
50963ced 3** Copyright (C) 2003-2016 Victor Kirhenshtein
4cd1e46b
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: import.cpp
20**
21**/
22
23#include "nxcore.h"
24
25/**
26 * Check if given event exist either in server configuration or in configuration being imported
27 */
28static bool IsEventExist(const TCHAR *name, Config *config)
29{
30 if (FindEventTemplateByName(name) != NULL)
31 return true;
32
33 ConfigEntry *eventsRoot = config->getEntry(_T("/events"));
34 if (eventsRoot != NULL)
35 {
8b7ae7eb
VK
36 ObjectArray<ConfigEntry> *events = eventsRoot->getSubEntries(_T("event#*"));
37 for(int i = 0; i < events->size(); i++)
4cd1e46b 38 {
8b7ae7eb 39 ConfigEntry *event = events->get(i);
4cd1e46b
AK
40 if (!_tcsicmp(event->getSubEntryValue(_T("name"), 0, _T("<unnamed>")), name))
41 {
42 delete events;
43 return true;
44 }
45 }
46 delete events;
47 }
48
49 return false;
50}
51
52/**
53 * Validate DCI from template
54 */
55static bool ValidateDci(Config *config, ConfigEntry *dci, const TCHAR *templateName, TCHAR *errorText, int errorTextLen)
56{
57 ConfigEntry *thresholdsRoot = dci->findEntry(_T("thresholds"));
58 if (thresholdsRoot == NULL)
59 return true;
60
61 bool success = true;
8b7ae7eb
VK
62 ObjectArray<ConfigEntry> *thresholds = thresholdsRoot->getSubEntries(_T("threshold#*"));
63 for(int i = 0; i < thresholds->size(); i++)
4cd1e46b 64 {
8b7ae7eb 65 ConfigEntry *threshold = thresholds->get(i);
4cd1e46b
AK
66 if (!IsEventExist(threshold->getSubEntryValue(_T("activationEvent")), config))
67 {
68 _sntprintf(errorText, errorTextLen,
69 _T("Template \"%s\" DCI \"%s\" threshold %d attribute \"activationEvent\" refers to unknown event"),
70 templateName, dci->getSubEntryValue(_T("description"), 0, _T("<unnamed>")), i + 1);
71 success = false;
72 break;
73 }
74 if (!IsEventExist(threshold->getSubEntryValue(_T("deactivationEvent")), config))
75 {
76 _sntprintf(errorText, errorTextLen,
77 _T("Template \"%s\" DCI \"%s\" threshold %d attribute \"deactivationEvent\" refers to unknown event"),
78 templateName, dci->getSubEntryValue(_T("description"), 0, _T("<unnamed>")), i + 1);
79 success = false;
80 break;
81 }
82 }
83 delete thresholds;
84 return success;
85}
86
87/**
88 * Validate template
89 */
90static bool ValidateTemplate(Config *config, ConfigEntry *root, TCHAR *errorText, int errorTextLen)
91{
92 DbgPrintf(6, _T("ValidateConfig(): validating template \"%s\""), root->getSubEntryValue(_T("name"), 0, _T("<unnamed>")));
93
94 ConfigEntry *dcRoot = root->findEntry(_T("dataCollection"));
95 if (dcRoot == NULL)
96 return true;
97
98 bool success = true;
99 const TCHAR *name = root->getSubEntryValue(_T("name"), 0, _T("<unnamed>"));
100
8b7ae7eb
VK
101 ObjectArray<ConfigEntry> *dcis = dcRoot->getSubEntries(_T("dci#*"));
102 for(int i = 0; i < dcis->size(); i++)
4cd1e46b 103 {
8b7ae7eb 104 if (!ValidateDci(config, dcis->get(i), name, errorText, errorTextLen))
4cd1e46b
AK
105 {
106 success = false;
107 break;
108 }
109 }
110 delete dcis;
111
112 if (success)
113 {
8b7ae7eb
VK
114 ObjectArray<ConfigEntry> *dctables = dcRoot->getSubEntries(_T("dctable#*"));
115 for(int i = 0; i < dctables->size(); i++)
4cd1e46b 116 {
8b7ae7eb 117 if (!ValidateDci(config, dctables->get(i), name, errorText, errorTextLen))
4cd1e46b
AK
118 {
119 success = false;
120 break;
121 }
122 }
123 delete dctables;
124 }
125
126 return success;
127}
128
129/**
130 * Validate configuration before import
131 */
132bool ValidateConfig(Config *config, UINT32 flags, TCHAR *errorText, int errorTextLen)
133{
134 int i;
8b7ae7eb 135 ObjectArray<ConfigEntry> *events = NULL, *traps = NULL, *templates = NULL;
4cd1e46b
AK
136 ConfigEntry *eventsRoot, *trapsRoot, *templatesRoot;
137 bool success = false;
138
139 DbgPrintf(4, _T("ValidateConfig() called, flags = 0x%04X"), flags);
140
141 // Validate events
142 eventsRoot = config->getEntry(_T("/events"));
143 if (eventsRoot != NULL)
144 {
145 events = eventsRoot->getSubEntries(_T("event#*"));
8b7ae7eb 146 for(i = 0; i < events->size(); i++)
4cd1e46b 147 {
8b7ae7eb 148 ConfigEntry *event = events->get(i);
4cd1e46b
AK
149 DbgPrintf(6, _T("ValidateConfig(): validating event %s"), event->getSubEntryValue(_T("name"), 0, _T("<unnamed>")));
150
31b0f68b 151 UINT32 code = event->getSubEntryValueAsUInt(_T("code"));
4cd1e46b
AK
152 if ((code >= FIRST_USER_EVENT_ID) || (code == 0))
153 {
154 ConfigEntry *e = event->findEntry(_T("name"));
155 if (e != NULL)
156 {
50963ced 157 EventTemplate *pEvent = FindEventTemplateByName(e->getValue());
4cd1e46b
AK
158 if (pEvent != NULL)
159 {
50963ced 160 pEvent->decRefCount();
4cd1e46b
AK
161 if (!(flags & CFG_IMPORT_REPLACE_EVENT_BY_NAME))
162 {
163 _sntprintf(errorText, errorTextLen, _T("Event with name %s already exist"), e->getValue());
164 goto stop_processing;
165 }
166 }
167 }
168 else
169 {
170 _sntprintf(errorText, errorTextLen, _T("Mandatory attribute \"name\" missing for entry %s"), event->getName());
171 goto stop_processing;
172 }
173 }
174 else
175 {
50963ced 176 EventTemplate *pEvent = FindEventTemplateByCode(code);
4cd1e46b
AK
177 if (pEvent != NULL)
178 {
179 if (!(flags & CFG_IMPORT_REPLACE_EVENT_BY_CODE))
180 {
181 _sntprintf(errorText, errorTextLen, _T("Event with code %d already exist (existing event name: %s; new event name: %s)"),
50963ced
VK
182 pEvent->getCode(), pEvent->getName(), event->getSubEntryValue(_T("name"), 0, _T("<unnamed>")));
183 pEvent->decRefCount();
4cd1e46b
AK
184 goto stop_processing;
185 }
50963ced 186 pEvent->decRefCount();
4cd1e46b
AK
187 }
188 }
189 }
190 }
191
192 // Validate traps
193 trapsRoot = config->getEntry(_T("/traps"));
194 if (trapsRoot != NULL)
195 {
196 traps = trapsRoot->getSubEntries(_T("trap#*"));
8b7ae7eb 197 for(i = 0; i < traps->size(); i++)
4cd1e46b 198 {
8b7ae7eb 199 ConfigEntry *trap = traps->get(i);
4cd1e46b
AK
200 DbgPrintf(6, _T("ValidateConfig(): validating trap \"%s\""), trap->getSubEntryValue(_T("description"), 0, _T("<unnamed>")));
201 if (!IsEventExist(trap->getSubEntryValue(_T("event")), config))
202 {
203 _sntprintf(errorText, errorTextLen, _T("Trap \"%s\" references unknown event"), trap->getSubEntryValue(_T("description"), 0, _T("")));
204 goto stop_processing;
205 }
206 }
207 }
208
209 // Validate templates
210 templatesRoot = config->getEntry(_T("/templates"));
211 if (templatesRoot != NULL)
212 {
213 templates = templatesRoot->getSubEntries(_T("template#*"));
8b7ae7eb 214 for(i = 0; i < templates->size(); i++)
4cd1e46b 215 {
8b7ae7eb 216 if (!ValidateTemplate(config, templates->get(i), errorText, errorTextLen))
4cd1e46b
AK
217 goto stop_processing;
218 }
219 }
220
221 success = true;
222
223stop_processing:
224 delete events;
225 delete traps;
226 delete templates;
227
228 DbgPrintf(4, _T("ValidateConfig() finished, status = %d"), success);
229 if (!success)
230 DbgPrintf(4, _T("ValidateConfig(): %s"), errorText);
231 return success;
232}
233
234/**
235 * Import event
236 */
237static UINT32 ImportEvent(ConfigEntry *event)
238{
239 const TCHAR *name = event->getSubEntryValue(_T("name"));
240 if (name == NULL)
241 return RCC_INTERNAL_ERROR;
242
243 DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
4cd1e46b 244
56e38a90
VK
245 UINT32 code = 0;
246 uuid guid = event->getSubEntryValueAsUUID(_T("guid"));
247 if (!guid.isNull())
248 {
29edfc8f 249 DB_STATEMENT hStmt = DBPrepare(hdb, _T("SELECT event_code FROM event_cfg WHERE guid=?"));
56e38a90
VK
250 if (hStmt == NULL)
251 {
252 DBConnectionPoolReleaseConnection(hdb);
253 return RCC_DB_FAILURE;
254 }
255 DBBind(hStmt, 1, DB_SQLTYPE_VARCHAR, guid);
256 DB_RESULT hResult = DBSelectPrepared(hStmt);
257 if (hResult != NULL)
258 {
259 code = DBGetFieldULong(hResult, 0, 0);
260 DBFreeResult(hResult);
261 }
262 DBFreeStatement(hStmt);
263 if (code != 0)
264 {
265 nxlog_debug(4, _T("ImportEvent: found existing event with GUID %s (code=%d)"), (const TCHAR *)guid.toString(), code);
266 }
267 else
268 {
269 nxlog_debug(4, _T("ImportEvent: event with GUID %s not found"), (const TCHAR *)guid.toString());
270 }
271 }
272 else
273 {
274 code = event->getSubEntryValueAsUInt(_T("code"), 0, 0);
275 if (code >= FIRST_USER_EVENT_ID)
276 {
277 code = 0;
278 nxlog_debug(4, _T("ImportEvent: event without GUID and code not in system range"));
279 }
280 else
281 {
282 nxlog_debug(4, _T("ImportEvent: using provided event code %d"), code);
283 }
284 }
4cd1e46b
AK
285
286 // Create or update event template in database
287 const TCHAR *msg = event->getSubEntryValue(_T("message"), 0, name);
288 const TCHAR *descr = event->getSubEntryValue(_T("description"));
289 TCHAR query[8192];
56e38a90 290 if ((code != 0) && IsDatabaseRecordExist(hdb, _T("event_cfg"), _T("event_code"), code))
4cd1e46b 291 {
56e38a90 292 nxlog_debug(4, _T("ImportEvent: found existing event with code %d"), code);
4cd1e46b 293 _sntprintf(query, 8192, _T("UPDATE event_cfg SET event_name=%s,severity=%d,flags=%d,message=%s,description=%s WHERE event_code=%d"),
31b0f68b
VK
294 (const TCHAR *)DBPrepareString(hdb, name), event->getSubEntryValueAsInt(_T("severity")),
295 event->getSubEntryValueAsInt(_T("flags")), (const TCHAR *)DBPrepareString(hdb, msg),
4cd1e46b
AK
296 (const TCHAR *)DBPrepareString(hdb, descr), code);
297 }
56e38a90
VK
298 else if (IsDatabaseRecordExist(hdb, _T("event_cfg"), _T("event_name"), name))
299 {
300 nxlog_debug(4, _T("ImportEvent: found existing event with name %s"), name);
301 _sntprintf(query, 8192, _T("UPDATE event_cfg SET severity=%d,flags=%d,message=%s,description=%s WHERE event_name=%s"),
302 event->getSubEntryValueAsInt(_T("severity")),
303 event->getSubEntryValueAsInt(_T("flags")), (const TCHAR *)DBPrepareString(hdb, msg),
304 (const TCHAR *)DBPrepareString(hdb, descr), (const TCHAR *)DBPrepareString(hdb, name));
305 }
4cd1e46b
AK
306 else
307 {
56e38a90
VK
308 if (guid.isNull())
309 guid = uuid::generate();
310 if (code == 0)
311 code = CreateUniqueId(IDG_EVENT);
4cd1e46b 312 _sntprintf(query, 8192, _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,")
50963ced 313 _T("message,description,guid) VALUES (%d,%s,%d,%d,%s,%s,'%s')"),
31b0f68b
VK
314 code, (const TCHAR *)DBPrepareString(hdb, name), event->getSubEntryValueAsInt(_T("severity")),
315 event->getSubEntryValueAsInt(_T("flags")), (const TCHAR *)DBPrepareString(hdb, msg),
56e38a90
VK
316 (const TCHAR *)DBPrepareString(hdb, descr), (const TCHAR *)guid.toString());
317 nxlog_debug(4, _T("ImportEvent: added new event: code=%d, name=%s, guid=%s"), code, name, (const TCHAR *)guid.toString());
4cd1e46b
AK
318 }
319 UINT32 rcc = DBQuery(hdb, query) ? RCC_SUCCESS : RCC_DB_FAILURE;
320
321 DBConnectionPoolReleaseConnection(hdb);
322 return rcc;
323}
324
325/**
326 * Import SNMP trap configuration
327 */
328static UINT32 ImportTrap(ConfigEntry *trap)
329{
50963ced 330 EventTemplate *event = FindEventTemplateByName(trap->getSubEntryValue(_T("event"), 0, _T("")));
4cd1e46b
AK
331 if (event == NULL)
332 return RCC_INTERNAL_ERROR;
333
50963ced 334 NXC_TRAP_CFG_ENTRY tc;
4cd1e46b 335 memset(&tc, 0, sizeof(NXC_TRAP_CFG_ENTRY));
50963ced 336 tc.dwEventCode = event->getCode();
4cd1e46b
AK
337 nx_strncpy(tc.szDescription, trap->getSubEntryValue(_T("description"), 0, _T("")), MAX_DB_STRING);
338 nx_strncpy(tc.szUserTag, trap->getSubEntryValue(_T("userTag"), 0, _T("")), MAX_USERTAG_LENGTH);
339
50963ced
VK
340 event->decRefCount();
341
4cd1e46b 342 UINT32 oid[256];
e0471fad 343 tc.dwOidLen = (UINT32)SNMPParseOID(trap->getSubEntryValue(_T("oid"), 0, _T("")), oid, 256);
4cd1e46b
AK
344 tc.pdwObjectId = oid;
345 if (tc.dwOidLen == 0)
346 return RCC_INTERNAL_ERROR;
347
348 ConfigEntry *parametersRoot = trap->findEntry(_T("parameters"));
349 if (parametersRoot != NULL)
350 {
8b7ae7eb
VK
351 ObjectArray<ConfigEntry> *parameters = parametersRoot->getOrderedSubEntries(_T("parameter#*"));
352 if (parameters->size() > 0)
4cd1e46b 353 {
8b7ae7eb 354 tc.dwNumMaps = parameters->size();
4cd1e46b 355 tc.pMaps = (NXC_OID_MAP *)malloc(sizeof(NXC_OID_MAP) * tc.dwNumMaps);
8b7ae7eb 356 for(int i = 0; i < parameters->size(); i++)
4cd1e46b 357 {
8b7ae7eb 358 ConfigEntry *parameter = parameters->get(i);
4cd1e46b 359
31b0f68b 360 int position = parameter->getSubEntryValueAsInt(_T("position"), 0, -1);
4cd1e46b
AK
361 if (position > 0)
362 {
363 // Positional parameter
364 tc.pMaps[i].pdwObjectId = NULL;
365 tc.pMaps[i].dwOidLen = (UINT32)position | 0x80000000;
366 }
367 else
368 {
369 // OID parameter
370 UINT32 temp[256];
e0471fad 371 tc.pMaps[i].dwOidLen = (UINT32)SNMPParseOID(parameter->getSubEntryValue(_T("oid"), 0, _T("")), temp, 256);
4cd1e46b
AK
372 tc.pMaps[i].pdwObjectId = (UINT32 *)nx_memdup(temp, sizeof(UINT32) * tc.pMaps[i].dwOidLen);
373 }
374 nx_strncpy(tc.pMaps[i].szDescription, parameter->getSubEntryValue(_T("description"), 0, _T("")), MAX_DB_STRING);
31b0f68b 375 tc.pMaps[i].dwFlags = parameter->getSubEntryValueAsUInt(_T("flags"), 0, 0);
4cd1e46b
AK
376 }
377 }
378 delete parameters;
379 }
380
381 UINT32 rcc = CreateNewTrap(&tc);
382
383 // Cleanup
384 for(UINT32 i = 0; i < tc.dwNumMaps; i++)
385 safe_free(tc.pMaps[i].pdwObjectId);
386
387 return rcc;
388}
389
67de55fd
VK
390/**
391 * Find (and create as necessary) parent object for imported template
392 */
393NetObj *FindTemplateRoot(ConfigEntry *config)
394{
395 ConfigEntry *pathRoot = config->findEntry(_T("path"));
396 if (pathRoot == NULL)
397 return g_pTemplateRoot; // path not specified in config
398
399 NetObj *parent = g_pTemplateRoot;
400 ObjectArray<ConfigEntry> *path = pathRoot->getSubEntries(_T("element#*"));
401 for(int i = 0; i < path->size(); i++)
402 {
403 const TCHAR *name = path->get(i)->getValue();
404 NetObj *o = parent->findChildObject(name, OBJECT_TEMPLATEGROUP);
405 if (o == NULL)
406 {
407 o = new TemplateGroup(name);
e7450f3b 408 NetObjInsert(o, true, false);
1f8be1f4
VK
409 o->addParent(parent);
410 parent->addChild(o);
67de55fd
VK
411 o->unhide();
412 o->calculateCompoundStatus(); // Force status change to NORMAL
413 }
414 parent = o;
415 }
416 delete path;
417 return parent;
418}
419
4cd1e46b
AK
420/**
421 * Import configuration
422 */
423UINT32 ImportConfig(Config *config, UINT32 flags)
424{
c7a9d87c
VK
425 ObjectArray<ConfigEntry> *events = NULL, *traps = NULL, *templates = NULL, *rules = NULL, *scripts = NULL, *objectTools = NULL, *summaryTables = NULL;
426 ConfigEntry *eventsRoot, *trapsRoot, *templatesRoot, *rulesRoot, *scriptsRoot, *objectToolsRoot, *summaryTablesRoot;
4cd1e46b
AK
427 UINT32 rcc = RCC_SUCCESS;
428 int i;
429
430 DbgPrintf(4, _T("ImportConfig() called, flags=0x%04X"), flags);
431
432 // Import events
433 eventsRoot = config->getEntry(_T("/events"));
434 if (eventsRoot != NULL)
435 {
436 events = eventsRoot->getSubEntries(_T("event#*"));
8b7ae7eb
VK
437 DbgPrintf(5, _T("ImportConfig(): %d events to import"), events->size());
438 for(i = 0; i < events->size(); i++)
4cd1e46b 439 {
8b7ae7eb 440 rcc = ImportEvent(events->get(i));
4cd1e46b
AK
441 if (rcc != RCC_SUCCESS)
442 goto stop_processing;
443 }
444
8b7ae7eb 445 if (events->size() > 0)
4cd1e46b
AK
446 {
447 ReloadEvents();
8d9ee864 448 NotifyClientSessions(NX_NOTIFY_RELOAD_EVENT_DB, 0);
4cd1e46b
AK
449 }
450 DbgPrintf(5, _T("ImportConfig(): events imported"));
451 }
452
453 // Import traps
454 trapsRoot = config->getEntry(_T("/traps"));
455 if (trapsRoot != NULL)
456 {
457 traps = trapsRoot->getSubEntries(_T("trap#*"));
8b7ae7eb
VK
458 DbgPrintf(5, _T("ImportConfig(): %d SNMP traps to import"), traps->size());
459 for(i = 0; i < traps->size(); i++)
4cd1e46b 460 {
8b7ae7eb 461 rcc = ImportTrap(traps->get(i));
4cd1e46b
AK
462 if (rcc != RCC_SUCCESS)
463 goto stop_processing;
464 }
465 DbgPrintf(5, _T("ImportConfig(): SNMP traps imported"));
466 }
467
468 // Import templates
469 templatesRoot = config->getEntry(_T("/templates"));
470 if (templatesRoot != NULL)
471 {
472 templates = templatesRoot->getSubEntries(_T("template#*"));
8b7ae7eb 473 for(i = 0; i < templates->size(); i++)
4cd1e46b 474 {
98ef8e4a
VK
475 ConfigEntry *tc = templates->get(i);
476 uuid guid = tc->getSubEntryValueAsUUID(_T("guid"));
477 Template *object = (Template *)FindObjectByGUID(guid, OBJECT_TEMPLATE);
478 if (object != NULL)
479 {
480 DbgPrintf(5, _T("ImportConfig(): found existing template %s [%d] with GUID %s"), object->getName(), object->getId(), (const TCHAR *)guid.toString());
481 object->updateFromImport(tc);
482 }
483 else
484 {
485 DbgPrintf(5, _T("ImportConfig(): template with GUID %s not found"), (const TCHAR *)guid.toString());
486 NetObj *parent = FindTemplateRoot(tc);
487 object = new Template(tc);
e7450f3b 488 NetObjInsert(object, true, true);
1f8be1f4
VK
489 object->addParent(parent);
490 parent->addChild(object);
98ef8e4a
VK
491 object->unhide();
492 }
4cd1e46b
AK
493 }
494 DbgPrintf(5, _T("ImportConfig(): templates imported"));
495 }
496
497 // Import rules
498 rulesRoot = config->getEntry(_T("/rules"));
499 if (rulesRoot != NULL)
500 {
271e3971 501 rules = rulesRoot->getOrderedSubEntries(_T("rule#*"));
0f665607 502 if (rules->size() > 0)
4cd1e46b 503 {
0f665607
VK
504 for(i = 0; i < rules->size(); i++)
505 {
506 EPRule *rule = new EPRule(rules->get(i));
507 g_pEventPolicy->importRule(rule);
508 }
509 g_pEventPolicy->saveToDB();
4cd1e46b
AK
510 }
511 DbgPrintf(5, _T("ImportConfig(): event processing policy rules imported"));
512 }
513
25a1e9d0
VK
514 // Import scripts
515 scriptsRoot = config->getEntry(_T("/scripts"));
516 if (scriptsRoot != NULL)
517 {
518 scripts = scriptsRoot->getSubEntries(_T("script#*"));
519 for(i = 0; i < scripts->size(); i++)
520 {
521 ImportScript(scripts->get(i));
522 }
523 DbgPrintf(5, _T("ImportConfig(): scripts imported"));
524 }
525
271e3971
VK
526 // Import object tools
527 objectToolsRoot = config->getEntry(_T("/objectTools"));
528 if (objectToolsRoot != NULL)
529 {
530 objectTools = objectToolsRoot->getSubEntries(_T("objectTool#*"));
531 for(i = 0; i < objectTools->size(); i++)
532 {
533 ImportObjectTool(objectTools->get(i));
534 }
535 DbgPrintf(5, _T("ImportConfig(): object tools imported"));
536 }
537
c7a9d87c
VK
538 // Import summary tables
539 summaryTablesRoot = config->getEntry(_T("/dciSummaryTables"));
540 if (summaryTablesRoot != NULL)
541 {
542 summaryTables = summaryTablesRoot->getSubEntries(_T("table#*"));
543 for(i = 0; i < summaryTables->size(); i++)
544 {
545 ImportSummaryTable(summaryTables->get(i));
546 }
547 DbgPrintf(5, _T("ImportConfig(): DCI summary tables imported"));
548 }
549
4cd1e46b
AK
550stop_processing:
551 delete events;
552 delete traps;
553 delete templates;
554 delete rules;
25a1e9d0 555 delete scripts;
271e3971 556 delete objectTools;
c7a9d87c 557 delete summaryTables;
4cd1e46b
AK
558
559 DbgPrintf(4, _T("ImportConfig() finished, rcc = %d"), rcc);
560 return rcc;
561}
03b96461
VK
562
563/**
564 * Import local configuration (configuration files stored on server)
565 */
566void ImportLocalConfiguration()
567{
568 TCHAR path[MAX_PATH];
569 GetNetXMSDirectory(nxDirShare, path);
570 _tcscat(path, DDIR_TEMPLATES);
571
572 int count = 0;
573 DbgPrintf(1, _T("Import configuration files from %s"), path);
574 _TDIR *dir = _topendir(path);
575 if (dir != NULL)
576 {
577 _tcscat(path, FS_PATH_SEPARATOR);
578 int insPos = (int)_tcslen(path);
579
580 struct _tdirent *f;
581 while((f = _treaddir(dir)) != NULL)
582 {
583 if (MatchString(_T("*.xml"), f->d_name, FALSE))
584 {
585 _tcscpy(&path[insPos], f->d_name);
586 Config *config = new Config();
587 if (config->loadXmlConfig(path, "configuration"))
588 {
589 ImportConfig(config, CFG_IMPORT_REPLACE_EVENT_BY_CODE | CFG_IMPORT_REPLACE_EVENT_BY_NAME);
590 }
591 else
592 {
593 DbgPrintf(1, _T("Error loading configuration from %s"), path);
594 }
595 delete config;
596 }
597 }
598 _tclosedir(dir);
599 }
600 DbgPrintf(1, _T("%d configuration files processed"), count);
601}