Discussion:
about agentx support in windows
bhushan
2006-12-04 14:10:11 UTC
Permalink
hello friends
Greetings,
I have installed netsnmp-5.4 using win32( MVC++), i am writing code
for subagent which will send traps to AgentX master agent.
Problem with the code is it execute all api of netsnmp correctly
(put up code at end) but no trap received by main agent( even if no
packet received by main agent according to dump )
I am running main agent in debug mode(sorry if i use wrong phrase) i.e.
snmpd -Lo -f -d -C -c c:\usr\etc\snmp\snmpd.conf
so if trap come to main agent it dump out trap to stdout
for agentx support enabling i putted following line in my snmpd.conf
master agentx
agentXSocket tcp:127.0.0.1:755
so it receive data on this port
dump of my snmpd process when i start agent

C:\NETSNMP\NET-SN~1.4\win32\bin\release>snmpd -Lo -f -d -C -c
c:\usr\etc\snmp\snmpd.conf
Turning on AgentX master support.

Sending 93 bytes to UDP: [127.0.0.1]:162
0000: 30 5B 02 01 01 04 06 70 75 62 6C 69 63 A7 4E 02 0[.....publicºN.
0016: 02 3A 8A 02 01 00 02 01 00 30 42 30 0D 06 08 2B .:è......0B0...+
0032: 06 01 02 01 01 03 00 43 01 1C 30 17 06 0A 2B 06 .......C..0...+.
0048: 01 06 03 01 01 04 01 00 06 09 2B 06 01 06 03 01 .........
+.....
0064: 01 05 01 30 18 06 0A 2B 06 01 06 03 01 01 04 03 ...0...+........
0080: 00 06 0A 2B 06 01 04 01 BF 08 03 02 0D


This is subagent code which send trap to main agent


static oid snmptrap_oid[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 };
int
send_trap( void)
{
netsnmp_variable_list *var_list = NULL;
int i;
oid data_oid[] =
{ 1, 3, 6, 1, 4, 1, 16901, 0, 1 };

oid ShortText_oid[] =
{ 1, 3, 6, 1, 4, 1, 16901, 4, 0 };

char *data = "testing trap in windows";
snmp_varlist_add_variable(&var_list,
snmptrap_oid,
OID_LENGTH(snmptrap_oid),//11*sizeof(oid),
ASN_OBJECT_ID,
( u_char* ) data_oid,
sizeof(data_oid) );
snmp_varlist_add_variable( &var_list,
ShortText_oid,
OID_LENGTH(ShortText_oid) ,
ASN_OCTET_STR,
data , strlen(data));
send_v2trap(var_list);
snmp_free_varbind(var_list);
return SNMP_ERR_NOERROR;
}
int main (int argc, char **argv)
{
int agentx_subagent=1; /* change this if you want to be a SNMP master
agent */
int background = 1; /* change this if you want to run in the background */
int num_fds;
fd_set fdset;
int count;
int listen_fd;
int sock_fd;
int syslog = 1;
char *p = "c:\\usr\\etc\\snmp\\snmpd";
char *cptr= "tcp:localhost:705";
int keep_running = 0;

/* we're an agentx subagent? */
if (agentx_subagent) {
/* make us a agentx client. */
netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE,
1);
netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_X_SOCKET, cptr);
}

/* run in background, if requested */
if (background && netsnmp_daemonize(1, !syslog))
exit(1);

/* initialize the agent library */

while( init_agent("sub-agent") != 0 ) {
sleep(2);
}
init_snmp("sub-agent");
send_trap();
return 0;
}
Please point if any mistake i made in code/ agent configuration
Thanks in advance
Regards
Bhushan. E . Sonawane
Dave Shield
2006-12-04 14:20:34 UTC
Permalink
Post by bhushan
for agentx support enabling i putted following line in my snmpd.conf
master agentx
agentXSocket tcp:127.0.0.1:755
So the master agent is listening on port 755
Post by bhushan
char *cptr= "tcp:localhost:705";
netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_X_SOCKET, cptr);
But the client is connecting to port 705

That won't work - the two configurations must match.

Dave
bhushan
2006-12-04 14:29:19 UTC
Permalink
sorry sir
By typing mistake i made that mistake in mail.
both port numbers setting are same still main agent not getting
packet of subagent(i.e. traps).
what may be the problem?
sorry for my typing mistake again
Thanks
Regards
Bhushan. E . Sonawane
Post by Dave Shield
Post by bhushan
for agentx support enabling i putted following line in my snmpd.conf
master agentx
agentXSocket tcp:127.0.0.1:755
So the master agent is listening on port 755
Post by bhushan
char *cptr= "tcp:localhost:705";
netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_X_SOCKET, cptr);
But the client is connecting to port 705
That won't work - the two configurations must match.
Dave
--
bhushan
2006-12-05 06:09:37 UTC
Permalink
Hello,
Sir the code that i have given in last mail. I tried that code to run in
linux
it run properly in linux this is log of snmpd process running on linux after
receiving
trap from my code

Received 80 bytes from 127.0.0.1
0000: 01 01 00 00 00 00 00 00 00 00 00 00 21 75 CC 67 ............!u.g
0016: 3C 00 00 00 00 00 00 00 05 04 00 00 01 00 00 00 <...............
0032: 88 1F 00 00 03 00 00 00 02 00 00 00 0A 00 00 00 ................

0048: 19 00 00 00 4E 65 74 2D 53 4E 4D 50 20 41 67 65 ....Net-SNMP Age
0064: 6E 74 58 20 73 75 62 2D 61 67 65 6E 74 00 00 00 ntX sub-agent...


Sending 88 bytes to 127.0.0.1
0000: 01 12 00 00 0A 00 00 00 00 00 00 00 21 75 CC 67 ............!u.g
0016: 44 00 00 00 25 26 00 00 00 00 00 00 04 00 00 00 D...%&..........
0032: 05 04 00 00 01 00 00 00 88 1F 00 00 03 00 00 00 ................

0048: 02 00 00 00 0A 00 00 00 19 00 00 00 4E 65 74 2D ............Net-
0064: 53 4E 4D 50 20 41 67 65 6E 74 58 20 73 75 62 2D SNMP AgentX sub-
0080: 61 67 65 6E 74 00 00 00 agent...


Received 152 bytes from 127.0.0.1
0000: 01 0C 00 00 0A 00 00 00 00 00 00 00 22 75 CC 67 ............"u.g
0016: 84 00 00 00 43 00 00 00 04 02 00 00 01 00 00 00 ....C...........

0032: 01 00 00 00 03 00 00 00 00 00 00 00 2A 26 00 00 ............*&..
0048: 06 00 00 00 06 06 00 00 03 00 00 00 01 00 00 00 ................
0064: 01 00 00 00 04 00 00 00 01 00 00 00 00 00 00 00 ................

0080: 04 04 01 00 01 00 00 00 05 42 00 00 00 00 00 00 .........B......
0096: 01 00 00 00 04 00 00 00 04 04 00 00 01 00 00 00 ................
0112: 05 42 00 00 04 00 00 00 00 00 00 00 17 00 00 00 .B..............

0128: 74 65 73 74 69 6E 67 20 74 72 61 70 20 69 6E 20 testing trap in
0144: 77 69 6E 64 6F 77 73 00 windows.


Sending 110 bytes to 127.0.0.1
0000: 30 6C 02 01 01 04 06 70 75 62 6C 69 63 A7 5F 02 0l.....public._.
0016: 04 08 5D 5C 03 02 01 00 02 01 00 30 51 30 0E 06 ..]\.......0Q0..
0032: 08 2B 06 01 02 01 01 03 00 43 02 26 2A 30 18 06 .+.......C.&*0..

0048: 0A 2B 06 01 06 03 01 01 04 01 00 06 0A 2B 06 01 .+...........+..
0064: 04 01 81 84 05 00 01 30 25 06 0A 2B 06 01 04 01 .......0%..+....
0080: 81 84 05 04 00 04 17 74 65 73 74 69 6E 67 20 74 .......testing t

0096: 72 61 70 20 69 6E 20 77 69 6E 64 6F 77 73 rap in windows


Sending 160 bytes to 127.0.0.1
0000: 01 12 00 00 0A 00 00 00 00 00 00 00 22 75 CC 67 ............"
u.g
0016: 8C 00 00 00 2B 26 00 00 00 00 00 00 43 00 00 00 ....+&......C...
0032: 04 02 00 00 01 00 00 00 01 00 00 00 03 00 00 00 ................
0048: 00 00 00 00 2A 26 00 00 06 00 00 00 06 06 00 00 ....*&..........

0064: 03 00 00 00 01 00 00 00 01 00 00 00 04 00 00 00 ................
0080: 01 00 00 00 00 00 00 00 04 04 01 00 01 00 00 00 ................
0096: 05 42 00 00 00 00 00 00 01 00 00 00 04 00 00 00 .B..............

0112: 04 04 00 00 01 00 00 00 05 42 00 00 04 00 00 00 .........B......
0128: 00 00 00 00 17 00 00 00 74 65 73 74 69 6E 67 20 ........testing
0144: 74 72 61 70 20 69 6E 20 77 69 6E 64 6F 77 73 00 trap in windows.




According to this log I understand that all trap received by snmpd
but when the same code i run under windows trap are not received by snmpd
even if i tried to sniff packet send by my code on localhost using
"Colasoft Capsa 5.5 Enterprise Demo" tool still no packet received by this
tool
also, my intepritation is that packet i.e. trap not at all send by
send_v2trap i.e. code
that i mentioned in earlier mail. so what may be the problem ?
Is this problem with windows ?
just to aid you i compile my code as follow in windows

C:\NETSNMP\Code>cl /MD subagent.c /link netsnmp.lib wsock32.lib
advapi32.lib netsnmpagent.lib netsnmpmibs.lib netsnmphelpers.lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
subagent.c
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
/out:subagent.exe
netsnmp.lib
wsock32.lib
advapi32.lib
netsnmpagent.lib
netsnmpmibs.lib
netsnmphelpers.lib
subagent.obj
LINK : warning LNK4098: defaultlib "MSVCRTD" conflicts with use of other
libs; use /NODEFAULTLIB:library

Thanks in advance
Regards
Bhushan. E . Sonawane
Post by bhushan
sorry sir
By typing mistake i made that mistake in mail.
both port numbers setting are same still main agent not getting
packet of subagent(i.e. traps).
what may be the problem?
sorry for my typing mistake again
Thanks
Regards
Bhushan. E . Sonawane
Post by Dave Shield
Post by bhushan
for agentx support enabling i putted following line in my snmpd.conf
master agentx
agentXSocket tcp: 127.0.0.1:755
So the master agent is listening on port 755
Post by bhushan
char *cptr= "tcp:localhost:705";
netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_X_SOCKET, cptr);
But the client is connecting to port 705
That won't work - the two configurations must match.
Dave
--
--
bhushan
2006-12-05 12:00:57 UTC
Permalink
Hello Friends
In Investigation of problem I put log messages i.e. printf in
agent_trap.c (in agent directory) in function netsnmp_send_traps
because send_v2trap/ send_easy_trap calls this function
in turn. updated function look as follows (in this i putted some printfs)

int
netsnmp_send_traps(int trap, int specific,
oid * enterprise, int enterprise_length,
netsnmp_variable_list * vars,
char * context, int flags)
{
netsnmp_pdu *template_v1pdu;
netsnmp_pdu *template_v2pdu;
netsnmp_variable_list *vblist = NULL;
netsnmp_variable_list *trap_vb;
netsnmp_variable_list *var;
in_addr_t *pdu_in_addr_t;
u_long uptime;
struct trap_sink *sink;

DEBUGMSGTL(( "trap", "send_trap %d %d ", trap, specific));
DEBUGMSGOID(("trap", enterprise, enterprise_length));
DEBUGMSG(( "trap", "\n"));
printf("\nAt Intial stage 1\n");
if (vars) {
vblist = snmp_clone_varbind( vars );
if (!vblist) {
snmp_log(LOG_WARNING,
"send_trap: failed to clone varbind list\n");
printf("\n\ Faile 1 \n");
return -1;
}
}
printf("\nAt stage 2\n");

if ( trap == -1 ) {
printf("\nAt stage 2.1\n");
/*
* Construct the SNMPv2-style notification PDU
*/
if (!vblist) {
snmp_log(LOG_WARNING,
"send_trap: called with NULL v2 information\n");
printf("\n\ Faile 2 \n");
return -1;
}
template_v2pdu = snmp_pdu_create(SNMP_MSG_TRAP2);
if (!template_v2pdu) {
snmp_log(LOG_WARNING,
"send_trap: failed to construct v2 template PDU\n");
snmp_free_varbind(vblist);
printf("\n\ Faile 3 \n");
return -1;
}
printf("\nAt stage 2.2\n");

/*
* Check the varbind list we've been given.
* If it starts with a 'sysUptime.0' varbind, then use that.
* Otherwise, prepend a suitable 'sysUptime.0' varbind.
*/
if (!snmp_oid_compare( vblist->name, vblist->name_length,
sysuptime_oid, sysuptime_oid_len )) {
template_v2pdu->variables = vblist;
trap_vb = vblist->next_variable;
} else {
uptime = netsnmp_get_agent_uptime();
var = NULL;
snmp_varlist_add_variable( &var,
sysuptime_oid, sysuptime_oid_len,
ASN_TIMETICKS, (u_char*)&uptime, sizeof(uptime));
if (!var) {
snmp_log(LOG_WARNING,
"send_trap: failed to insert sysUptime varbind\n");
snmp_free_pdu(template_v2pdu);
snmp_free_varbind(vblist);
printf("\n\ Faile 4 \n");
return -1;
}
printf("\nAt stage 2.3\n");
template_v2pdu->variables = var;
var->next_variable = vblist;
trap_vb = vblist;

}
printf("\nAt stage 2.4\n");

/*
* 'trap_vb' should point to the snmpTrapOID.0 varbind,
* identifying the requested trap. If not then bomb out.
* If it's a 'standard' trap, then we need to append an
* snmpEnterprise varbind (if there isn't already one).
*/

if (!trap_vb ||
snmp_oid_compare(trap_vb->name, trap_vb->name_length,
snmptrap_oid, snmptrap_oid_len)) {
snmp_log(LOG_WARNING,
"send_trap: no v2 trapOID varbind provided\n");
snmp_free_pdu(template_v2pdu);
printf("\n\ Faile 5 \n");
return -1;
}
printf("\nAt stage 2.5\n");
printf("\nAt stage 4\n");
if (!snmp_oid_compare(vblist->val.objid, OID_LENGTH(trap_prefix),
trap_prefix, OID_LENGTH(trap_prefix))) {
var = find_varbind_in_list( template_v2pdu->variables,
snmptrapenterprise_oid,
snmptrapenterprise_oid_len);
if (!var &&
!snmp_varlist_add_variable( &(template_v2pdu->variables),
snmptrapenterprise_oid, snmptrapenterprise_oid_len,
ASN_OBJECT_ID,
(char*)enterprise, enterprise_length*sizeof(oid))) {
snmp_log(LOG_WARNING,
"send_trap: failed to add snmpEnterprise to v2
trap\n");
snmp_free_pdu(template_v2pdu);
printf("\n\ Faile 6 \n");
return -1;
}
}
printf("\nAt stage 2.6\n");

/*
* If everything's OK, convert the v2 template into an SNMPv1 trap
PDU.
*/
template_v1pdu = convert_v2pdu_to_v1( template_v2pdu );
if (!template_v1pdu) {
snmp_log(LOG_WARNING,
"send_trap: failed to convert v2->v1 template PDU\n");
snmp_free_pdu(template_v2pdu);
printf("\n\ Faile 7 \n");
return -1;
}
printf("\nStage 2 end\n");

} else {
printf("\nAt stage 3\n");
/*
* Construct the SNMPv1 trap PDU....
*/
template_v1pdu = snmp_pdu_create(SNMP_MSG_TRAP);
if (!template_v1pdu) {
snmp_log(LOG_WARNING,
"send_trap: failed to construct v1 template PDU\n");
snmp_free_varbind(vblist);
printf("\n\ Faile 8 \n");
return -1;
}
template_v1pdu->trap_type = trap;
template_v1pdu->specific_type = specific;
template_v1pdu->time = netsnmp_get_agent_uptime();
printf("\nAt stage 3.1\n");
if (snmp_clone_mem((void **) &template_v1pdu->enterprise,
enterprise, enterprise_length * sizeof(oid))) {
snmp_log(LOG_WARNING,
"send_trap: failed to set v1 enterprise OID\n");
snmp_free_varbind(vblist);
snmp_free_pdu(template_v1pdu);
printf("\n\ Faile 8 \n");
return -1;
}
template_v1pdu->enterprise_length = enterprise_length;

template_v1pdu->flags |= UCD_MSG_FLAG_FORCE_PDU_COPY;
template_v1pdu->variables = vblist;

/*
* ... and convert it into an SNMPv2-style notification PDU.
*/
printf("\nAt stage 3.2\n");
template_v2pdu = convert_v1pdu_to_v2( template_v1pdu );
if (!template_v2pdu) {
snmp_log(LOG_WARNING,
"send_trap: failed to convert v1->v2 template PDU\n");
snmp_free_pdu(template_v1pdu);
printf("\n\ Faile 10 \n");
return -1;
}
printf("\nCompleted stage 3\n");
}

/*
* Check whether we're ignoring authFail traps
*/
printf("\nAt stage 4\n");
if (template_v1pdu->trap_type == SNMP_TRAP_AUTHFAIL &&
snmp_enableauthentraps == SNMP_AUTHENTICATED_TRAPS_DISABLED) {
snmp_free_pdu(template_v1pdu);
snmp_free_pdu(template_v2pdu);
return 0;
}

/*
* Ensure that the v1 trap PDU includes the local IP address
*/
printf("\nAt stage 5\n");
pdu_in_addr_t = (in_addr_t *) template_v1pdu->agent_addr;
*pdu_in_addr_t = get_myaddr();


/*
* Now loop through the list of trap sinks
* and call the trap callback routines,
* providing an appropriately formatted PDU in each case
*/
printf("\nAt stage 6\n");
// My comments
// As far as i understand This for loop
// sends trap to main agent, & when I see log messages
// this for loop never get execute means
// Value of sinks variable is NULL so no trap send by process
// so my subagent code call send_v2trap but
// send_v2trap has return value void so user never come to know
// weather trap send by API or not
for (sink = sinks; sink; sink = sink->next) {
printf("\nAt stage 6.1 loop \n");
#ifndef NETSNMP_DISABLE_SNMPV1
if (sink->version == SNMP_VERSION_1) {
printf("\n\ Sending trap v1 \n");
send_trap_to_sess(sink->sesp, template_v1pdu);
} else {
#endif
printf("\n\ Sending trap v2 \n");
template_v2pdu->command = sink->pdutype;
send_trap_to_sess(sink->sesp, template_v2pdu);
#ifndef NETSNMP_DISABLE_SNMPV1
}
#endif
}
printf("\nAt stage 7\n");
snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
SNMPD_CALLBACK_SEND_TRAP1, template_v1pdu);
snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
SNMPD_CALLBACK_SEND_TRAP2, template_v2pdu);
snmp_free_pdu(template_v1pdu);
snmp_free_pdu(template_v2pdu);
printf("\nAt stage 8\n");
printf("\n\ returning from netsnmp_send_traps \n");
return 0;
}

According to my comment in above code,
Sinks variable is NULL, this is global variable in agent_trap.c
& this variable fill(updated) by function "add_trap_session" located in same

file i.e. agent_trap.c
when I am looking at code add_trap_session function get call by
function snmpd_parse_config_trapsess, and
snmpd_parse_config_trapsess function used in
init_agent_read_config function located in agent_read_config.c
(libagent directory) & init_agent_read_config function also get call
by init_agent (located in snmp_vars.c).
So I think problem lies here in init_agent, so Is i am sending Correct
Parameter to above function ?
i.e. init_agent("sub-agent"); like this
I tried like this also init_agent("c:\\usr\\etc\\snmp\\snmpd.conf");
still trap are not get send by subagent.
So what is problem ?
Please give me any clue so i investigate problem.
Thanks in advance Friends
Regards
Bhushan E. Sonawane
bhushan
2006-12-05 15:01:27 UTC
Permalink
hello Sir
to get correct understanding of my problem log message of linux
& windows as follows
in Linux
[***@wifi-security-server trap_agent]# ./agent
In assigning add_trap_session
In assigning Value to sinks add_trap_session // My Comment
In assiged Value to sinks add_trap_session // sinks global variable
that i said you in
No log handling enabled - turning on stderr logging // previous mail, that
variable get fill here
NET-SNMP version 5.4 AgentX subagent connected // <-- also not getting why
this message not coming under windows
send_spectraGuardEvent_trap before send_trap
In send_v2 trap function
In send_trap_vars function
non enterprise specific
Calling netsnmp_send_trap function
At Initial stage 1
At stage 2
At stage 2.1
At stage 2.2
At stage 2.3
At stage 2.4
At stage 2.5
At stage 4
At stage 2.6
Stage 2 end
At stage 4
At stage 5
At stage 6
At stage 6.1 loop // This is log which i putted in for loop
Sending trap v2 // so v2 trap get send by subagent
At stage 7
At stage 8
returning from netsnmp_send_traps

this is for Windows
C:\NETSNMP>subagent1.exe
In send_v2 trap function
In send_trap_vars function
non enterprise specific
Calling netsnmp_send_trap function
At Initial stage 1
At stage 2
At stage 2.1
At stage 2.2
At stage 2.3
At stage 2.4
At stage 2.5
At stage 4
At stage 2.6
Stage 2 end
At stage 4
At stage 5
At stage 6
At stage 7
At stage 8
returning from netsnmp_send_traps

do looking at both log I understand that sinks variable not get fill at
initial stage
i.e. in init_agent function in windows where as it get fill in linux
I am attaching by agent_trap.c with this mail, also my agent code with this
mail
Please help me in this .
Thanks in advance
Regards
Bhushan
bhushan
2006-12-05 15:20:29 UTC
Permalink
Sorry
Forget to attach file
Regards
Bhushan
Post by bhushan
hello Sir
to get correct understanding of my problem log message of linux
& windows as follows
in Linux
In assigning add_trap_session
In assigning Value to sinks add_trap_session // My Comment
In assiged Value to sinks add_trap_session // sinks global variable
that i said you in
No log handling enabled - turning on stderr logging // previous mail, that
variable get fill here
NET-SNMP version 5.4 AgentX subagent connected // <-- also not getting
why this message not coming under windows
send_spectraGuardEvent_trap before send_trap
In send_v2 trap function
In send_trap_vars function
non enterprise specific
Calling netsnmp_send_trap function
At Initial stage 1
At stage 2
At stage 2.1
At stage 2.2
At stage 2.3
At stage 2.4
At stage 2.5
At stage 4
At stage 2.6
Stage 2 end
At stage 4
At stage 5
At stage 6
At stage 6.1 loop // This is log which i putted in for loop
Sending trap v2 // so v2 trap get send by subagent
At stage 7
At stage 8
returning from netsnmp_send_traps
this is for Windows
C:\NETSNMP>subagent1.exe
In send_v2 trap function
In send_trap_vars function
non enterprise specific
Calling netsnmp_send_trap function
At Initial stage 1
At stage 2
At stage 2.1
At stage 2.2
At stage 2.3
At stage 2.4
At stage 2.5
At stage 4
At stage 2.6
Stage 2 end
At stage 4
At stage 5
At stage 6
At stage 7
At stage 8
returning from netsnmp_send_traps
do looking at both log I understand that sinks variable not get fill at
initial stage
i.e. in init_agent function in windows where as it get fill in linux
I am attaching by agent_trap.c with this mail, also my agent code with
this mail
Please help me in this .
Thanks in advance
Regards
Bhushan
--
bhushan. E . Sonawane
bhushan
2006-12-05 16:34:22 UTC
Permalink
Hello
after reading code of init_agent, add_trap_session i understand that
add_trap_session function will register session & fill sinks global
structure
(struct trap_sink sinks) & this structure is used by netsnmp_send_traps
for sending trap i.e. if this structure is NULL no traps get send when we
are calling
send_v2trap/send_easy_trap etc. .
"init_agent" function call init_agent_read_config function & this function
inturn call

register_app_config_handler("trapsess", snmpd_parse_config_trapsess,
NULL, "[snmpcmdargs] host");
& snmpd_parse_config_trapsess function call add_trap_session function
so my question is register_app_config_handler get invoke when we are master
agent
in init_agent_read_config function . so if we are subagent then this
function never get
call.
so if we are subagent process then using which flow of code sinks structure
get fill
so that when we are calling send_v2trap then it get data from sinks
structure & send trap to destination
tell me If i am wrong .
Thanks in advance
Regards
Bhushan
Dave Shield
2006-12-05 16:46:19 UTC
Permalink
Post by bhushan
register_app_config_handler("trapsess", snmpd_parse_config_trapsess,
NULL, "[snmpcmdargs] host");
That is only relevant to the master agent.

An AgentX subagent should send all notifications over the main
AgentX connection to the master agent. No special configuration
should be necessary.

I'm afraid that I do not know why this is not happening in your case,
and I do not currently have the time to investigate. I need to concentrate
on the work that I am actually paid to do. Could you please not copy all
messages to me - just send them to the list. If I can help, I will. If not,
then sending me stuff direct won't change that fact.
Thanks

Dave
bhushan
2006-12-06 06:23:31 UTC
Permalink
hello friends
I got correct understanding of my problem
when i call init_agent in windows it get fail because
init_agent call subagent_init & sunagent_init call
netsnmp_callback_open and this function fails & return NULL.
but in Linux it execute properly and return non NULL data.
so thing this is problem .
but i don't know why this is happening ?
please help me.
Thanks in advance
Regards
Bhushan E. Sonawane

Alex Burger
2006-12-05 16:01:20 UTC
Permalink
Are you using the DLL version of the library (netsnmp.dll) or did you
compile static?

Alex
Post by bhushan
hello friends
Greetings,
I have installed netsnmp-5.4 using win32( MVC++), i am writing code
for subagent which will send traps to AgentX master agent.
Problem with the code is it execute all api of netsnmp correctly
(put up code at end) but no trap received by main agent( even if no
packet received by main agent according to dump )
I am running main agent in debug mode(sorry if i use wrong phrase) i.e.
snmpd -Lo -f -d -C -c c:\usr\etc\snmp\snmpd.conf
so if trap come to main agent it dump out trap to stdout
for agentx support enabling i putted following line in my snmpd.conf
master agentx
agentXSocket tcp:127.0.0.1:755 <http://127.0.0.1:755>
so it receive data on this port
dump of my snmpd process when i start agent
C:\NETSNMP\NET-SN~1.4\win32\bin\release>snmpd -Lo -f -d -C -c
c:\usr\etc\snmp\snmpd.conf
Turning on AgentX master support.
Sending 93 bytes to UDP: [127.0.0.1 <http://127.0.0.1>]:162
0000: 30 5B 02 01 01 04 06 70 75 62 6C 69 63 A7 4E 02 0[.....publicºN.
0016: 02 3A 8A 02 01 00 02 01 00 30 42 30 0D 06 08 2B
.:è......0B0...+
0032: 06 01 02 01 01 03 00 43 01 1C 30 17 06 0A 2B 06 .......C..0...+.
0048: 01 06 03 01 01 04 01 00 06 09 2B 06 01 06 03 01 .........
+.....
0064: 01 05 01 30 18 06 0A 2B 06 01 06 03 01 01 04 03
...0...+........
0080: 00 06 0A 2B 06 01 04 01 BF 08 03 02 0D
This is subagent code which send trap to main agent
static oid snmptrap_oid[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 };
int
send_trap( void)
{
netsnmp_variable_list *var_list = NULL;
int i;
oid data_oid[] =
{ 1, 3, 6, 1, 4, 1, 16901, 0, 1 };
oid ShortText_oid[] =
{ 1, 3, 6, 1, 4, 1, 16901, 4, 0 };
char *data = "testing trap in windows";
snmp_varlist_add_variable(&var_list,
snmptrap_oid,
OID_LENGTH(snmptrap_oid),//11*sizeof(oid),
ASN_OBJECT_ID,
( u_char* ) data_oid,
sizeof(data_oid) );
snmp_varlist_add_variable( &var_list,
ShortText_oid,
OID_LENGTH(ShortText_oid) ,
ASN_OCTET_STR,
data , strlen(data));
send_v2trap(var_list);
snmp_free_varbind(var_list);
return SNMP_ERR_NOERROR;
}
int main (int argc, char **argv)
{
int agentx_subagent=1; /* change this if you want to be a SNMP master
agent */
int background = 1; /* change this if you want to run in the background */
int num_fds;
fd_set fdset;
int count;
int listen_fd;
int sock_fd;
int syslog = 1;
char *p = "c:\\usr\\etc\\snmp\\snmpd";
char *cptr= "tcp:localhost:705";
int keep_running = 0;
/* we're an agentx subagent? */
if (agentx_subagent) {
/* make us a agentx client. */
netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_ROLE, 1);
netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_X_SOCKET, cptr);
}
/* run in background, if requested */
if (background && netsnmp_daemonize(1, !syslog))
exit(1);
/* initialize the agent library */
while( init_agent("sub-agent") != 0 ) {
sleep(2);
}
init_snmp("sub-agent");
send_trap();
return 0;
}
Please point if any mistake i made in code/ agent configuration
Thanks in advance
Regards
Bhushan. E . Sonawane
------------------------------------------------------------------------
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
------------------------------------------------------------------------
_______________________________________________
Net-snmp-coders mailing list
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders
bhushan
2006-12-05 16:05:02 UTC
Permalink
I am using static version of library
Is there any problem with it ?
Thanks for replying
Please do reply
Regards
Bhushan
Post by Alex Burger
Are you using the DLL version of the library (netsnmp.dll) or did you
compile static?
Alex
Post by bhushan
hello friends
Greetings,
I have installed netsnmp-5.4 using win32( MVC++), i am writing code
for subagent which will send traps to AgentX master agent.
Problem with the code is it execute all api of netsnmp correctly
(put up code at end) but no trap received by main agent( even if no
packet received by main agent according to dump )
I am running main agent in debug mode(sorry if i use wrong phrase) i.e.
snmpd -Lo -f -d -C -c c:\usr\etc\snmp\snmpd.conf
so if trap come to main agent it dump out trap to stdout
for agentx support enabling i putted following line in my snmpd.conf
master agentx
agentXSocket tcp:127.0.0.1:755 <http://127.0.0.1:755>
so it receive data on this port
dump of my snmpd process when i start agent
C:\NETSNMP\NET-SN~1.4\win32\bin\release>snmpd -Lo -f -d -C -c
c:\usr\etc\snmp\snmpd.conf
Turning on AgentX master support.
Sending 93 bytes to UDP: [127.0.0.1 <http://127.0.0.1>]:162
0000: 30 5B 02 01 01 04 06 70 75 62 6C 69 63 A7 4E
02 0[.....publicºN.
Post by bhushan
0016: 02 3A 8A 02 01 00 02 01 00 30 42 30 0D 06 08 2B
.:è......0B0...+
0032: 06 01 02 01 01 03 00 43 01 1C 30 17 06 0A 2B
06 .......C..0...+.
Post by bhushan
0048: 01 06 03 01 01 04 01 00 06 09 2B 06 01 06 03 01 .........
+.....
0064: 01 05 01 30 18 06 0A 2B 06 01 06 03 01 01 04 03
...0...+........
0080: 00 06 0A 2B 06 01 04 01 BF 08 03 02 0D
This is subagent code which send trap to main agent
static oid snmptrap_oid[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 };
int
send_trap( void)
{
netsnmp_variable_list *var_list = NULL;
int i;
oid data_oid[] =
{ 1, 3, 6, 1, 4, 1, 16901, 0, 1 };
oid ShortText_oid[] =
{ 1, 3, 6, 1, 4, 1, 16901, 4, 0 };
char *data = "testing trap in windows";
snmp_varlist_add_variable(&var_list,
snmptrap_oid,
OID_LENGTH(snmptrap_oid),//11*sizeof(oid),
ASN_OBJECT_ID,
( u_char* ) data_oid,
sizeof(data_oid) );
snmp_varlist_add_variable( &var_list,
ShortText_oid,
OID_LENGTH(ShortText_oid) ,
ASN_OCTET_STR,
data , strlen(data));
send_v2trap(var_list);
snmp_free_varbind(var_list);
return SNMP_ERR_NOERROR;
}
int main (int argc, char **argv)
{
int agentx_subagent=1; /* change this if you want to be a SNMP master
agent */
int background = 1; /* change this if you want to run in the
background */
Post by bhushan
int num_fds;
fd_set fdset;
int count;
int listen_fd;
int sock_fd;
int syslog = 1;
char *p = "c:\\usr\\etc\\snmp\\snmpd";
char *cptr= "tcp:localhost:705";
int keep_running = 0;
/* we're an agentx subagent? */
if (agentx_subagent) {
/* make us a agentx client. */
netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_ROLE, 1);
netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_X_SOCKET, cptr);
}
/* run in background, if requested */
if (background && netsnmp_daemonize(1, !syslog))
exit(1);
/* initialize the agent library */
while( init_agent("sub-agent") != 0 ) {
sleep(2);
}
init_snmp("sub-agent");
send_trap();
return 0;
}
Please point if any mistake i made in code/ agent configuration
Thanks in advance
Regards
Bhushan. E . Sonawane
------------------------------------------------------------------------
-------------------------------------------------------------------------
Post by bhushan
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share
your
Post by bhushan
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Post by bhushan
------------------------------------------------------------------------
_______________________________________________
Net-snmp-coders mailing list
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders
--
bhushan. E . Sonawane
Alex Burger
2006-12-05 21:33:18 UTC
Permalink
Post by bhushan
I am using static version of library
Is there any problem with it ?
No, there shouldn't be any difference between using the DLL or static
version of the library. If you were using the DLL, then I would have
asked if you had the same problem with using static.

Alex
Loading...