|
-
January 18th, 2006, 04:59 AM
#1
Trap SNMP
Hi,
I want to send trap to my snmp program.
I have find this code in internet that send a trap, but it doesn't run correctly bacause my SNMP don't catch any trap!!!
Code:
#include "stdafx.h"
#using <mscorlib.dll>
#include <Winsnmp.h>
#include <windows.h>
using namespace System;
SNMPAPI_STATUS CALLBACK cbFunc
(HSNMP_SESSION hSession, HWND hWnd, UINT wMsg,
WPARAM wParam, LPARAM lParam, LPVOID lpClientData)
{ // This is a noop function for this app, but must be present.
return (SNMPAPI_SUCCESS);
}
int _tmain(){
DWORD nTime1=0, nTime2=0;
HSNMP_SESSION hSession;
HSNMP_ENTITY hDst;
HSNMP_CONTEXT hContext;
HSNMP_VBL hVbl;
HSNMP_PDU hPdu;
SNMPAPI_CALLBACK cB = &cbFunc;
smiOCTETS dContext = {6, (unsigned char *)"CIAOOO"};
smiUINT32 lStat;
smiUINT32 sysUpTime[] = {1,3,6,1,2,1,1,3,0};
smiUINT32 snmpTrapOid[] = {1,3,6,1,6,3,1 ,1,4,1,0};
smiUINT32 trapValue[] = {1,3,6,1,4,1,12,1,1,1,210};
smiOID dSysUpTimeName = {9, sysUpTime};
smiOID dTrapName = {11, snmpTrapOid};
smiOID dTrapName2 = {11, trapValue};
smiVALUE valSysUpTime;
smiVALUE valTrap;
smiVALUE valTrap2;
lStat = SnmpStartup (&lStat, &lStat, &lStat, &lStat, &lStat);
if (lStat == SNMPAPI_FAILURE)
return (0); // exit
lStat = SnmpSetRetransmitMode(SNMPAPI_ON);
hSession = SnmpCreateSession(NULL, 0, cB, NULL);
if (hSession == SNMPAPI_FAILURE)
{
printf ("SnmpCreateSession() failed!\n");
lStat = SnmpClose (hSession);
lStat = SnmpCleanup ();
return (0);
}
lStat = SnmpSetTranslateMode (SNMPAPI_TRANSLATED); //SNMPAPI_UNTRANSLATED_V1
//THIS IS THE IPADRESS OF SERVER WHERE IS INSTALLER SNMP PROGRAM
hDst = SnmpStrToEntity (hSession, "192.168.1.10");
lStat = SnmpSetPort (hDst, 162);
hContext = SnmpStrToContext(hSession, &dContext);
hVbl = SnmpCreateVbl (hSession, NULL, NULL);
valSysUpTime.syntax = SNMP_SYNTAX_TIMETICKS;
valSysUpTime.value.uNumber = GetTickCount() / 10;
lStat = SnmpSetVb (hVbl, 0, &dSysUpTimeName, &valSysUpTime);
valTrap.syntax = SNMP_SYNTAX_OID;
valTrap.value.oid.len = 11;
valTrap.value.oid.ptr = trapValue;
lStat = SnmpSetVb (hVbl, 0, &dTrapName, &valTrap);
valTrap2.syntax = SNMP_SYNTAX_INT;
valTrap2.value.sNumber = 210;
lStat = SnmpSetVb (hVbl, 0, &dTrapName2, &valTrap2);
hPdu = SnmpCreatePdu (hSession, SNMP_PDU_TRAP, 1, 0, 0, hVbl);
nTime1 = GetTickCount();
lStat = SnmpSendMsg (hSession, NULL, hDst, hContext, hPdu);
if (lStat != SNMPAPI_SUCCESS)
{
printf ("SnmpSendMsg() failed:\n" );
}
nTime2 = GetTickCount();
printf ("Elapsed time (in milliseconds): %u \n", nTime2 - nTime1);
lStat = SnmpFreeContext(hContext);
lStat = SnmpClose (hSession);
lStat = SnmpCleanup ();
return (0);
}
Why my SNMP don't catch trap send by this code??
It's possibile to set priprity of trap??
Where I set the string message of trap??
I hope in you help!!
Thanks
Bye
Sara
Last edited by saraf; January 18th, 2006 at 08:27 AM.
-
January 18th, 2006, 06:44 AM
#2
Re: Trap SNMP
Have you installed the MS trap provider? This has to be installed before you can receive traps.
If not, go to add and remove programs --> windows components --> network --> snmp ( not 100% sure on this path ). Once done, this should install two services, one that allows you to receive traps the other will send traps from your machine.
The service that sends traps can be configured to automatically send authentication traps to machines of your choice.
HTH
-
January 18th, 2006, 07:14 AM
#3
Re: Trap SNMP
[ moved thread ]
Please use the code tags when posting code.
[code]Your code[/code]
-
January 18th, 2006, 07:49 AM
#4
Re: Trap SNMP
f1shrman was partly right, you have to install snmp service on your machine and then start the service (to send snmp messages) and the trap service (to receive traps)
snmp-simple network management protocol, as the name stands, is a management tool (and not 'exactly' a network tool )
So, to install it you must follow this path:
Control Panel -> Add/Remove Programs -> Windows Components -> Management and Monitoring Tools -> SNMP
after installing, dont' forget to start the service (Start -> Programs -> Administrative Tools -> Services)
-
January 18th, 2006, 08:26 AM
#5
Re: Trap SNMP
Hi,
thank you so much for you reply!!
I have installed the SNMP and I have started the SNMP service and Trap SNMP service.
But in the server (ipaddress = 192.168.1.10) there is installed the Kiwi Syslog (receiver trap SNMP).
I would send trap SNMP by my machine to 192.168.1.10.
It's however necessary to install SNMP in my machine for send trap message, correctly??
Now I launch my code, but how I can verify it works correctly??
In my SNMP in the server I don't see any trap message.
Thanks a lot!!
Bye
Sara
-
January 18th, 2006, 08:38 AM
#6
Re: Trap SNMP
 Originally Posted by saraf
It's however necessary to install SNMP in my machine for send trap message, correctly??
If I can re-collect correctly, you may have to have SNMP installed on both, the sender as well as receiver machines. I would advice you to install on both and see if it helps.
 Originally Posted by saraf
Now I launch my code, but how I can verify it works correctly??
In my SNMP in the server I don't see any trap message.
I cannot verify this b'coz I don't have SNMP on my machine right now, but I think in the Services 'options' you have the provision to set the type of output you want when a trap is received. It can be set to popup a dialog box or start an application or something like that.
-
January 18th, 2006, 09:16 AM
#7
Re: Trap SNMP
Ok, I have set property of SNMP Service. Now my code function correctly.
Thank you so much, there are 3 days that I search info about SNMP.
Thanks.
Bye, Sara
-
April 5th, 2007, 09:56 AM
#8
Re: Trap SNMP
Hi, would you mind sharing your working SNMP Trap sender code? I am trying to develop one but am having some issues. Did you figure out where to put the message string in the SNMPSENDMSG?
ANy help is sincerely appreciated.
JOA
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|