AgentX in windows (netsnmp 5.2.1.2 + example-demon)

Ali Ayoub <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
Hi, 
I wrote a subAgent for Linux, it works just fine, 
When I was asked to add support for Windows server 2003 too, I had a 
lot of problems. I am asking you for help please: 


After applying some patches, I installed net-snmp 5.2.1.2
<http://5.2.1.2>in my windows
machine using cygwin, using those steps: 
1. configure --with-mib-modules="host agentx disman/event-mib 
examples/example" --with-out-mib-modules=host/hr_net 
work 
2. make 
3. make install 


OK.. Now I am trying to compile example-demon (form agentx tutorial 
from net-snmp official site). 
I am running the snmpd: 
c:\usr\bin\snmpd -f -L -c c:\usr\share\snmp\snmpd.conf -x localhost:705 
-Dagentx 
snmpd.conf looks like this: 
########################################################### 
# SECTION: Access Control Setup 
rwuser root 
rouser root 
rwcommunity public 
master agentx 
# end of snmpd.conf 
##################################################### 


snmpd output is: 
""" 
c:\usr\share\snmp\snmpd.conf -Dagentx 
agentx/subagent: init_subagent sess 00325ea0 
agentx_register_app_config_handler: registering .conf token for 
"agentxsocket" 
agentx_register_app_config_handler: registering .conf token for 
"agentxperms" 
agentx_register_app_config_handler: registering .conf token for 
"agentxRetries" 
agentx_register_app_config_handler: registering .conf token for 
"agentxTimeout" 
Turning on AgentX master support. 
agentx/master: initializing... 
agentx/master: initializing... DONE 
NET-SNMP version 5.2.1.2 <http://5.2.1.2> 
""" 


Then I opened a cygwin window and compiled example-demon.c, here is the 
code: 
############## 
# example-demon.c 
#include <net-snmp/net-snmp-config.h> 
#include <net-snmp/net-snmp-includes.h> 
#include <net-snmp/agent/net-snmp-agent-includes.h> 
#include <signal.h> 


#include <nstAgentSubagentObject.h> 


static int keep_running; 


RETSIGTYPE 
stop_server(int a) { 
keep_running = 0; 

 } 


int 
main (int argc, char **argv) { 
int agentx_subagent=1; /* change this if you want to be a SNMP master 
agent */ 
int background = 0; /* change this if you want to run in the 
background */ 
int syslog = 0; /* change this if you want to use syslog */ 

/* print log errors to syslog or stderr */ 
if (syslog) 
snmp_enable_calllog(); 
else 
snmp_enable_stderrlog(); 


/* 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,"­localhost:705");



} 


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


/* initialize the agent library */ 
init_agent("example-demon"); 


/* initialize mib code here */ 


/* mib code: init_nstAgentSubagentObject from 
nstAgentSubagentObject.C */ 
init_nstAgentSubagentObject(); 


/* initialize vacm/usm access control */ 
if (!agentx_subagent) { 
init_vacm_vars(); 
init_usmUser(); 
} 


/* example-demon will be used to read example-demon.conf files. */ 
init_snmp("example-demon"); 


/* If we're going to be a snmp master agent, initial the ports */ 
if (!agentx_subagent) 
init_master_agent(); /* open the port to listen on (defaults to 
udp:161) */ 


/* In case we recevie a request to stop (kill -TERM or kill -INT) */ 
keep_running = 1; 
signal(SIGTERM, stop_server); 
signal(SIGINT, stop_server); 


snmp_log(LOG_INFO,"example-demon is up and running.\n"); 


/* your main loop here... */ 
while(keep_running) { 
/* if you use select(), see snmp_select_info() in snmp_api(3) */ 
/* --- OR --- */ 
agent_check_and_process(1); /* 0 == don't block */ 
} 


/* at shutdown time */ 
snmp_shutdown("example-demon"); 
SOCK_CLEANUP; 


return 0; 

 } 


# end of example-demon.c 
###################### 

Then I ran example-demon.exe, it says that "example-demon is up and 
running"!!!!! 


BUT, when I check the subagent's MIB it seems not working: 
c:\snmpget -v 2c -c public localhost 
NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.0 
==> NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.0 = No Such Object 
available on this agent at this OID 


!!!!!!! 


I spent some days trying to figure it out, I couldn't. Can you please 
help me. 


P.S 
1. netstat -a shows me "TCP pc_name:705 pc_name:0 LISTENING" 
2. When I try to run the example-demon without running the master, I 
got the same behavior, it says that it's up and running!!, but in fact 
it's not. 
3. I am running snmpd and example-demon from MS window (not form cygwin 
window), I don't know if that's matter. 


Thanks in advance. 
-Ali
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.