+ sockets reuse (*nix only)
[public/netxms.git] / src / server / core / snmptrap.cpp
CommitLineData
37c4d6aa
VK
1/*
2** NetXMS - Network Management System
3** Copyright (C) 2003, 2004 Victor Kirhenshtein
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation; either version 2 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
19** $module: snmptrap.cpp
20**
21**/
22
a551fe4d 23#include "nxcore.h"
37c4d6aa
VK
24
25
26//
27// Constants
28//
29
30#define MAX_PACKET_LENGTH 65536
31
32
33//
6ed0d23d
VK
34// Static data
35//
36
37static MUTEX m_mutexTrapCfgAccess = NULL;
840eb902 38static NXC_TRAP_CFG_ENTRY *m_pTrapCfg = NULL;
6ed0d23d
VK
39static DWORD m_dwNumTraps = 0;
40
41
42//
43// Load trap configuration from database
44//
45
46static BOOL LoadTrapCfg(void)
47{
48 DB_RESULT hResult;
49 BOOL bResult = TRUE;
50 TCHAR szQuery[256];
51 DWORD i, j, pdwBuffer[MAX_OID_LEN];
52
53 // Load traps
0c6014e4 54 hResult = DBSelect(g_hCoreDB, "SELECT trap_id,snmp_oid,event_code,description FROM snmp_trap_cfg");
6ed0d23d
VK
55 if (hResult != NULL)
56 {
57 m_dwNumTraps = DBGetNumRows(hResult);
840eb902
VK
58 m_pTrapCfg = (NXC_TRAP_CFG_ENTRY *)malloc(sizeof(NXC_TRAP_CFG_ENTRY) * m_dwNumTraps);
59 memset(m_pTrapCfg, 0, sizeof(NXC_TRAP_CFG_ENTRY) * m_dwNumTraps);
6ed0d23d
VK
60 for(i = 0; i < m_dwNumTraps; i++)
61 {
62 m_pTrapCfg[i].dwId = DBGetFieldULong(hResult, i, 0);
63 m_pTrapCfg[i].dwOidLen = SNMPParseOID(DBGetField(hResult, i, 1), pdwBuffer, MAX_OID_LEN);
64 if (m_pTrapCfg[i].dwOidLen > 0)
65 {
66 m_pTrapCfg[i].pdwObjectId = (DWORD *)nx_memdup(pdwBuffer, m_pTrapCfg[i].dwOidLen * sizeof(DWORD));
67 }
68 else
69 {
70 WriteLog(MSG_INVALID_TRAP_OID, EVENTLOG_ERROR_TYPE, "s", DBGetField(hResult, i, 1));
71 bResult = FALSE;
72 }
c19b2871 73 m_pTrapCfg[i].dwEventCode = DBGetFieldULong(hResult, i, 2);
2ebf3a71 74 _tcsncpy(m_pTrapCfg[i].szDescription, DBGetField(hResult, i, 3), MAX_DB_STRING);
1943e452 75 DecodeSQLString(m_pTrapCfg[i].szDescription);
6ed0d23d
VK
76 }
77 DBFreeResult(hResult);
78
79 // Load parameter mappings
80 for(i = 0; i < m_dwNumTraps; i++)
81 {
2ebf3a71 82 sprintf(szQuery, "SELECT snmp_oid,description FROM snmp_trap_pmap "
6ed0d23d
VK
83 "WHERE trap_id=%ld ORDER BY parameter", m_pTrapCfg[i].dwId);
84 hResult = DBSelect(g_hCoreDB, szQuery);
85 if (hResult != NULL)
86 {
87 m_pTrapCfg[i].dwNumMaps = DBGetNumRows(hResult);
2ebf3a71 88 m_pTrapCfg[i].pMaps = (NXC_OID_MAP *)malloc(sizeof(NXC_OID_MAP) * m_pTrapCfg[i].dwNumMaps);
6ed0d23d
VK
89 for(j = 0; j < m_pTrapCfg[i].dwNumMaps; j++)
90 {
91 m_pTrapCfg[i].pMaps[j].dwOidLen = SNMPParseOID(DBGetField(hResult, j, 0), pdwBuffer, MAX_OID_LEN);
92 if (m_pTrapCfg[i].pMaps[j].dwOidLen > 0)
93 {
94 m_pTrapCfg[i].pMaps[j].pdwObjectId =
95 (DWORD *)nx_memdup(pdwBuffer, m_pTrapCfg[i].pMaps[j].dwOidLen * sizeof(DWORD));
96 }
97 else
98 {
99 WriteLog(MSG_INVALID_TRAP_ARG_OID, EVENTLOG_ERROR_TYPE, "sd",
100 DBGetField(hResult, j, 0), m_pTrapCfg[i].dwId);
101 bResult = FALSE;
102 }
2ebf3a71 103 _tcsncpy(m_pTrapCfg[i].pMaps[j].szDescription, DBGetField(hResult, j, 1), MAX_DB_STRING);
1943e452 104 DecodeSQLString(m_pTrapCfg[i].pMaps[j].szDescription);
6ed0d23d
VK
105 }
106 DBFreeResult(hResult);
107 }
108 else
109 {
110 bResult = FALSE;
111 }
112 }
113 }
114 else
115 {
116 bResult = FALSE;
117 }
118 return bResult;
119}
120
121
122//
106e7ae3
VK
123// Initialize trap handling
124//
125
126void InitTraps(void)
127{
128 m_mutexTrapCfgAccess = MutexCreate();
129 LoadTrapCfg();
130}
131
132
133//
6ed0d23d
VK
134// Generate event for matched trap
135//
136
137static void GenerateTrapEvent(DWORD dwObjectId, DWORD dwIndex, SNMP_PDU *pdu)
138{
139 TCHAR *pszArgList[32], szBuffer[256];
2ebf3a71 140 TCHAR szFormat[] = "sssssssssssssssssssssssssssssssss";
6ed0d23d 141 DWORD i, j;
2ebf3a71 142 int iResult;
6ed0d23d
VK
143
144 for(i = 0; i < m_pTrapCfg[dwIndex].dwNumMaps; i++)
145 {
146 for(j = 0; j < pdu->GetNumVariables(); j++)
2ebf3a71
VK
147 {
148 iResult = pdu->GetVariable(j)->GetName()->Compare(
149 m_pTrapCfg[dwIndex].pMaps[i].pdwObjectId,
150 m_pTrapCfg[dwIndex].pMaps[i].dwOidLen);
151 if ((iResult == OID_EQUAL) || (iResult == OID_SHORTER))
6ed0d23d
VK
152 {
153 pszArgList[i] = _tcsdup(pdu->GetVariable(j)->GetValueAsString(szBuffer, 256));
154 break;
155 }
2ebf3a71 156 }
6ed0d23d
VK
157 if (j == pdu->GetNumVariables())
158 pszArgList[i] = _tcsdup(_T("<null>"));
159 }
160
2ebf3a71 161 szFormat[m_pTrapCfg[dwIndex].dwNumMaps + 1] = 0;
c19b2871 162 PostEvent(m_pTrapCfg[dwIndex].dwEventCode, dwObjectId, szFormat,
2ebf3a71 163 pdu->GetTrapId()->GetValueAsText(),
6ed0d23d
VK
164 pszArgList[0], pszArgList[1], pszArgList[2], pszArgList[3],
165 pszArgList[4], pszArgList[5], pszArgList[6], pszArgList[7],
166 pszArgList[8], pszArgList[9], pszArgList[10], pszArgList[11],
167 pszArgList[12], pszArgList[13], pszArgList[14], pszArgList[15],
168 pszArgList[16], pszArgList[17], pszArgList[18], pszArgList[19],
169 pszArgList[20], pszArgList[21], pszArgList[22], pszArgList[23],
170 pszArgList[24], pszArgList[25], pszArgList[26], pszArgList[27],
171 pszArgList[28], pszArgList[29], pszArgList[30], pszArgList[31]);
172
173 for(i = 0; i < m_pTrapCfg[dwIndex].dwNumMaps; i++)
174 free(pszArgList[i]);
175}
176
177
178//
3aeed82c
VK
179// Process trap
180//
181
182static void ProcessTrap(SNMP_PDU *pdu, struct sockaddr_in *pOrigin)
183{
f218dc6d 184 DWORD i, dwOriginAddr, dwBufPos, dwBufSize, dwMatchLen, dwMatchIdx;
3aeed82c
VK
185 TCHAR *pszTrapArgs, szBuffer[512];
186 SNMP_Variable *pVar;
187 Node *pNode;
6ed0d23d 188 int iResult;
3aeed82c
VK
189
190 dwOriginAddr = ntohl(pOrigin->sin_addr.s_addr);
6ed0d23d 191 DbgPrintf(AF_DEBUG_SNMP, "Received SNMP trap %s from %s",
3aeed82c
VK
192 pdu->GetTrapId()->GetValueAsText(), IpToStr(dwOriginAddr, szBuffer));
193
194 // Match IP address to object
195 pNode = FindNodeByIP(dwOriginAddr);
196 if (pNode != NULL)
197 {
6ed0d23d 198 // Find if we have this trap in our list
106e7ae3 199 MutexLock(m_mutexTrapCfgAccess, INFINITE);
f218dc6d
VK
200
201 // Try to find closest match
202 for(i = 0, dwMatchLen = 0; i < m_dwNumTraps; i++)
3aeed82c 203 {
693119d6
VK
204 if (m_pTrapCfg[i].dwOidLen > 0)
205 {
206 iResult = pdu->GetTrapId()->Compare(m_pTrapCfg[i].pdwObjectId, m_pTrapCfg[i].dwOidLen);
f218dc6d
VK
207 if (iResult == OID_EQUAL)
208 {
209 dwMatchLen = m_pTrapCfg[i].dwOidLen;
210 dwMatchIdx = i;
211 break; // Find exact match
212 }
213 if (iResult == OID_SHORTER)
214 {
215 if (m_pTrapCfg[i].dwOidLen > dwMatchLen)
216 {
217 dwMatchLen = m_pTrapCfg[i].dwOidLen;
218 dwMatchIdx = i;
219 }
220 }
693119d6 221 }
3aeed82c
VK
222 }
223
f218dc6d 224 if (dwMatchLen > 0)
6ed0d23d 225 {
f218dc6d 226 GenerateTrapEvent(pNode->Id(), dwMatchIdx, pdu);
6ed0d23d
VK
227 }
228 else // Process unmatched traps
229 {
230 // Build trap's parameters string
2ebf3a71 231 dwBufSize = pdu->GetNumVariables() * 4096 + 16;
6ed0d23d
VK
232 pszTrapArgs = (TCHAR *)malloc(sizeof(TCHAR) * dwBufSize);
233 pszTrapArgs[0] = 0;
234 for(i = 0, dwBufPos = 0; i < pdu->GetNumVariables(); i++)
235 {
236 pVar = pdu->GetVariable(i);
237 dwBufPos += _sntprintf(&pszTrapArgs[dwBufPos], dwBufSize - dwBufPos, _T("%s%s == '%s'"),
238 (i == 0) ? _T("") : _T("; "),
239 pVar->GetName()->GetValueAsText(),
240 pVar->GetValueAsString(szBuffer, 512));
241 }
242
243 // Generate default event for unmatched traps
244 PostEvent(EVENT_SNMP_UNMATCHED_TRAP, pNode->Id(), "ss",
245 pdu->GetTrapId()->GetValueAsText(), pszTrapArgs);
246 free(pszTrapArgs);
247 }
106e7ae3 248 MutexUnlock(m_mutexTrapCfgAccess);
3aeed82c
VK
249 }
250}
251
252
253//
37c4d6aa
VK
254// SNMP trap receiver thread
255//
256
257THREAD_RESULT THREAD_CALL SNMPTrapReceiver(void *pArg)
258{
259 SOCKET hSocket;
260 struct sockaddr_in addr;
d853cd74
VK
261 int iBytes;
262 socklen_t nAddrLen;
6bb44a2b 263 SNMP_Transport *pTransport;
1064698f 264 SNMP_PDU *pdu;
37c4d6aa
VK
265
266 hSocket = socket(AF_INET, SOCK_DGRAM, 0);
267 if (hSocket == -1)
268 {
269 WriteLog(MSG_SOCKET_FAILED, EVENTLOG_ERROR_TYPE, "s", "SNMPTrapReceiver");
270 return THREAD_OK;
271 }
272
9f881a19
AK
273 SetSocketReuseFlag(hSocket);
274
37c4d6aa
VK
275 // Fill in local address structure
276 memset(&addr, 0, sizeof(struct sockaddr_in));
277 addr.sin_family = AF_INET;
278 addr.sin_addr.s_addr = htonl(INADDR_ANY);
279 addr.sin_port = htons(162);
280
281 // Bind socket
282 if (bind(hSocket, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) != 0)
283 {
284 WriteLog(MSG_BIND_ERROR, EVENTLOG_ERROR_TYPE, "dse", 162, "SNMPTrapReceiver", WSAGetLastError());
285 closesocket(hSocket);
286 return THREAD_OK;
287 }
288
6bb44a2b 289 pTransport = new SNMP_Transport(hSocket);
3aeed82c 290 DbgPrintf(AF_DEBUG_SNMP, _T("SNMP Trap Receiver started"));
37c4d6aa
VK
291
292 // Wait for packets
293 while(!ShutdownInProgress())
294 {
d853cd74
VK
295 nAddrLen = sizeof(struct sockaddr_in);
296 iBytes = pTransport->Read(&pdu, 2000, (struct sockaddr *)&addr, &nAddrLen);
6bb44a2b 297 if ((iBytes > 0) && (pdu != NULL))
37c4d6aa 298 {
3aeed82c
VK
299 if (pdu->GetCommand() == SNMP_TRAP)
300 ProcessTrap(pdu, &addr);
6bb44a2b 301 delete pdu;
37c4d6aa
VK
302 }
303 else
304 {
305 // Sleep on error
306 ThreadSleepMs(100);
307 }
308 }
309
3aeed82c 310 DbgPrintf(AF_DEBUG_SNMP, _T("SNMP Trap Receiver terminated"));
37c4d6aa
VK
311 return THREAD_OK;
312}
840eb902
VK
313
314
315//
316// Send all traps to client
317//
318
319void SendTrapsToClient(ClientSession *pSession, DWORD dwRqId)
320{
2ebf3a71 321 DWORD i, j, dwId1, dwId2, dwId3;
840eb902
VK
322 CSCPMessage msg;
323
324 // Prepare message
325 msg.SetCode(CMD_TRAP_CFG_RECORD);
326 msg.SetId(dwRqId);
327
106e7ae3 328 MutexLock(m_mutexTrapCfgAccess, INFINITE);
840eb902
VK
329 for(i = 0; i < m_dwNumTraps; i++)
330 {
331 msg.SetVariable(VID_TRAP_ID, m_pTrapCfg[i].dwId);
332 msg.SetVariable(VID_TRAP_OID_LEN, m_pTrapCfg[i].dwOidLen);
333 msg.SetVariableToInt32Array(VID_TRAP_OID, m_pTrapCfg[i].dwOidLen, m_pTrapCfg[i].pdwObjectId);
c19b2871 334 msg.SetVariable(VID_EVENT_CODE, m_pTrapCfg[i].dwEventCode);
2ebf3a71 335 msg.SetVariable(VID_DESCRIPTION, m_pTrapCfg[i].szDescription);
840eb902 336 msg.SetVariable(VID_TRAP_NUM_MAPS, m_pTrapCfg[i].dwNumMaps);
2ebf3a71 337 for(j = 0, dwId1 = VID_TRAP_PLEN_BASE, dwId2 = VID_TRAP_PNAME_BASE, dwId3 = VID_TRAP_PDESCR_BASE;
840eb902
VK
338 j < m_pTrapCfg[i].dwNumMaps; j++, dwId1++, dwId2++)
339 {
340 msg.SetVariable(dwId1, m_pTrapCfg[i].pMaps[j].dwOidLen);
341 msg.SetVariableToInt32Array(dwId2, m_pTrapCfg[i].pMaps[j].dwOidLen, m_pTrapCfg[i].pMaps[j].pdwObjectId);
2ebf3a71 342 msg.SetVariable(dwId3, m_pTrapCfg[i].pMaps[j].szDescription);
840eb902
VK
343 }
344 pSession->SendMessage(&msg);
345 msg.DeleteAllVariables();
346 }
106e7ae3 347 MutexUnlock(m_mutexTrapCfgAccess);
840eb902
VK
348
349 msg.SetVariable(VID_TRAP_ID, (DWORD)0);
350 pSession->SendMessage(&msg);
351}
106e7ae3
VK
352
353
354//
355// Delete trap configuration record
356//
357
358DWORD DeleteTrap(DWORD dwId)
359{
360 DWORD i, j, dwResult = RCC_INVALID_TRAP_ID;
361 TCHAR szQuery[256];
362
363 MutexLock(m_mutexTrapCfgAccess, INFINITE);
364
365 for(i = 0; i < m_dwNumTraps; i++)
366 {
367 if (m_pTrapCfg[i].dwId == dwId)
368 {
369 // Free allocated resources
370 for(j = 0; j < m_pTrapCfg[i].dwNumMaps; j++)
371 safe_free(m_pTrapCfg[i].pMaps[j].pdwObjectId);
372 safe_free(m_pTrapCfg[i].pMaps);
373 safe_free(m_pTrapCfg[i].pdwObjectId);
374
375 // Remove trap entry from list
376 m_dwNumTraps--;
377 memmove(&m_pTrapCfg[i], &m_pTrapCfg[i + 1], sizeof(NXC_TRAP_CFG_ENTRY) * (m_dwNumTraps - i));
378
379 // Remove trap entry from database
380 _stprintf(szQuery, _T("DELETE FROM snmp_trap_cfg WHERE trap_id=%ld"), dwId);
381 QueueSQLRequest(szQuery);
382 _stprintf(szQuery, _T("DELETE FROM snmp_trap_pmap WHERE trap_id=%ld"), dwId);
383 QueueSQLRequest(szQuery);
384 dwResult = RCC_SUCCESS;
385 break;
386 }
387 }
388
389 MutexUnlock(m_mutexTrapCfgAccess);
390 return dwResult;
391}
693119d6
VK
392
393
394//
395// Create new trap configuration record
396//
397
398DWORD CreateNewTrap(DWORD *pdwTrapId)
399{
400 DWORD dwResult = RCC_SUCCESS;
401 TCHAR szQuery[256];
402
403 MutexLock(m_mutexTrapCfgAccess, INFINITE);
404
405 *pdwTrapId = CreateUniqueId(IDG_SNMP_TRAP);
406 m_pTrapCfg = (NXC_TRAP_CFG_ENTRY *)realloc(m_pTrapCfg, sizeof(NXC_TRAP_CFG_ENTRY) * (m_dwNumTraps + 1));
407 memset(&m_pTrapCfg[m_dwNumTraps], 0, sizeof(NXC_TRAP_CFG_ENTRY));
408 m_pTrapCfg[m_dwNumTraps].dwId = *pdwTrapId;
c19b2871 409 m_pTrapCfg[m_dwNumTraps].dwEventCode = EVENT_SNMP_UNMATCHED_TRAP;
693119d6
VK
410 m_dwNumTraps++;
411
412 MutexUnlock(m_mutexTrapCfgAccess);
413
0c6014e4 414 _stprintf(szQuery, _T("INSERT INTO snmp_trap_cfg (trap_id,snmp_oid,event_code,description) ")
693119d6 415 _T("VALUES (%ld,'',%d,'')"), *pdwTrapId, EVENT_SNMP_UNMATCHED_TRAP);
1943e452
VK
416 if (!DBQuery(g_hCoreDB, szQuery))
417 dwResult = RCC_DB_FAILURE;
418
693119d6
VK
419 return dwResult;
420}
421
422
423//
424// Update trap configuration record from message
425//
426
427DWORD UpdateTrapFromMsg(CSCPMessage *pMsg)
428{
429 DWORD i, j, dwId1, dwId2, dwId3, dwTrapId, dwResult = RCC_INVALID_TRAP_ID;
21ea6058
VK
430 TCHAR szQuery[1024], szOID[1024], *pszEscDescr;
431 BOOL bSuccess;
693119d6
VK
432
433 dwTrapId = pMsg->GetVariableLong(VID_TRAP_ID);
434
435 MutexLock(m_mutexTrapCfgAccess, INFINITE);
436 for(i = 0; i < m_dwNumTraps; i++)
437 {
438 if (m_pTrapCfg[i].dwId == dwTrapId)
439 {
440 // Read trap configuration from event
c19b2871 441 m_pTrapCfg[i].dwEventCode = pMsg->GetVariableLong(VID_EVENT_CODE);
693119d6
VK
442 m_pTrapCfg[i].dwOidLen = pMsg->GetVariableLong(VID_TRAP_OID_LEN);
443 m_pTrapCfg[i].pdwObjectId = (DWORD *)realloc(m_pTrapCfg[i].pdwObjectId, sizeof(DWORD) * m_pTrapCfg[i].dwOidLen);
444 pMsg->GetVariableInt32Array(VID_TRAP_OID, m_pTrapCfg[i].dwOidLen, m_pTrapCfg[i].pdwObjectId);
445 pMsg->GetVariableStr(VID_DESCRIPTION, m_pTrapCfg[i].szDescription, MAX_DB_STRING);
446
447 // Destroy current parameter mapping
448 for(j = 0; j < m_pTrapCfg[i].dwNumMaps; j++)
449 safe_free(m_pTrapCfg[i].pMaps[j].pdwObjectId);
450 safe_free(m_pTrapCfg[i].pMaps);
451
452 // Read new mappings from message
453 m_pTrapCfg[i].dwNumMaps = pMsg->GetVariableLong(VID_TRAP_NUM_MAPS);
454 m_pTrapCfg[i].pMaps = (NXC_OID_MAP *)malloc(sizeof(NXC_OID_MAP) * m_pTrapCfg[i].dwNumMaps);
455 for(j = 0, dwId1 = VID_TRAP_PLEN_BASE, dwId2 = VID_TRAP_PNAME_BASE, dwId3 = VID_TRAP_PDESCR_BASE;
456 j < m_pTrapCfg[i].dwNumMaps; j++, dwId1++, dwId2++)
457 {
458 m_pTrapCfg[i].pMaps[j].dwOidLen = pMsg->GetVariableLong(dwId1);
21ea6058
VK
459 m_pTrapCfg[i].pMaps[j].pdwObjectId =
460 (DWORD *)malloc(sizeof(DWORD) * m_pTrapCfg[i].pMaps[j].dwOidLen);
693119d6
VK
461 pMsg->GetVariableInt32Array(dwId2, m_pTrapCfg[i].pMaps[j].dwOidLen,
462 m_pTrapCfg[i].pMaps[j].pdwObjectId);
463 pMsg->GetVariableStr(dwId3, m_pTrapCfg[i].pMaps[j].szDescription, MAX_DB_STRING);
464 }
465
21ea6058
VK
466 // Update database
467 pszEscDescr = EncodeSQLString(m_pTrapCfg[i].szDescription);
468 SNMPConvertOIDToText(m_pTrapCfg[i].dwOidLen, m_pTrapCfg[i].pdwObjectId, szOID, 1024);
0c6014e4 469 _sntprintf(szQuery, 1024, _T("UPDATE snmp_trap_cfg SET snmp_oid='%s',event_code=%ld,description='%s' WHERE trap_id=%ld"),
c19b2871 470 szOID, m_pTrapCfg[i].dwEventCode, pszEscDescr, m_pTrapCfg[i].dwId);
21ea6058
VK
471 free(pszEscDescr);
472 bSuccess = DBQuery(g_hCoreDB, szQuery);
473 if (bSuccess)
474 {
475 _sntprintf(szQuery, 1024, _T("DELETE FROM snmp_trap_pmap WHERE trap_id=%ld"), m_pTrapCfg[i].dwId);
476 bSuccess = DBQuery(g_hCoreDB, szQuery);
477 if (bSuccess)
478 {
479 for(j = 0; j < m_pTrapCfg[i].dwNumMaps; j++)
480 {
481 SNMPConvertOIDToText(m_pTrapCfg[i].pMaps[j].dwOidLen,
482 m_pTrapCfg[i].pMaps[j].pdwObjectId,
483 szOID, 1024);
484 pszEscDescr = EncodeSQLString(m_pTrapCfg[i].pMaps[j].szDescription);
485 _sntprintf(szQuery, 1024, _T("INSERT INTO snmp_trap_pmap (trap_id,parameter,")
486 _T("snmp_oid,description) VALUES (%ld,%ld,'%s','%s')"),
487 m_pTrapCfg[i].dwId, j + 1, szOID, pszEscDescr);
488 free(pszEscDescr);
489 bSuccess = DBQuery(g_hCoreDB, szQuery);
490 if (!bSuccess)
491 break;
492 }
493 }
494 }
495
496 dwResult = bSuccess ? RCC_SUCCESS : RCC_DB_FAILURE;
693119d6
VK
497 break;
498 }
499 }
500
501 MutexUnlock(m_mutexTrapCfgAccess);
502 return dwResult;
503}