Hello everyone,
Sorry to bother you with something that many will certainly find
trivial, but it's been driving me crazy for days, now... Even though I
read all tutorials I found, I'm pretty sure I'm missing a little
something that prevents my program from working... Maybe I misunderstood
something (English is not my mother tongue), or I thought something does
not apply in my case whereas it does... Anyhow - I'm really lost and in
need for enlighted advise.
I'm writing a sub-agent, and all I want to do, is to have my handler
called back whenever a request (be it GET or SET) is made on an OID
under a given root one. Computation of the values to return will be a
bit messy, so I don't want to use all the pretty functionalities that
net-snmp provides, such as 'netsnmp_register_long_scalar' functions and
the like. Just a callback, and I'll take care of the answering.
I'm coding in C on a Fedora 25 box, with NET-SNMP version 5.7.3, on an
isolated network - so security is not an issue (I'll be using SNMP v1 or
v2c, with all rights given to public community).
Here is what my snmpd.conf looks like (comments removed) :
-----------------------------------------------------------
master agentx
com2sec supervision default public
group DefaultGroup v1 supervision
group DefaultGroup v2c supervision
view systemview included .1
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
view myapplview included .1.3.6.1.4.1.XXXX.YYYY
access DefaultGroup "" any noauth exact systemview
systemview systemview
access DefaultGroup "" any noauth exact myapplview
myapplview myapplview
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
-----------------------------------------------------------
... and I can check, using journalctl, that the AgentX support has been
enabled by the snmpd daemon :
> snmpd[749]: Turning on AgentX master support.
When I try to get a "standard" OID, it works fine :
> $ snmpget -v 2c -c public localhost DISMAN-EVENT-MIB::sysUpTimeInstance
> DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (2530359) 7:01:43.59
... but when I try to get one of mine, it can't be found :
> $ snmpget -v 2c -c public localhost .1.3.6.1.4.1.XXXX.YYYY
> SNMPv2-SMI::enterprises.XXXX.YYYY = No Such Object available on this
agent at this OID
Here is what my code looks like (once more, it's a simplified version ;
on the real code, *all* errors are handled... and none happen) :
-----------------------------------------------------------
oid root_oid[] = {1,3,6,1,4,1,XXXX,YYYY};
int my_handler(netsnmp_mib_handler *mh,
netsnmp_handler_registration *hr,
netsnmp_agent_request_info *ari,
netsnmp_request_info *ri) {
puts("Handler has been called :-) !");
return SNMP_ERR_NOERROR;
}
int main(void) {
netsnmp_handler_registration *hr;
bool dont_stop = true; // modified elsewhere when I want to quit
snmp_enable_stderrlog();
init_agent("MyAgent");
netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_ROLE, 1);
hr = netsnmp_create_handler_registration("MyAgent",
my_handler,
root_oid,
root_oid_len,// initialized
elsewhere
HANDLER_CAN_RWRITE);
netsnmp_register_handler(hr);
init_snmp("MyAgent");
while (dont_stop) agent_check_and_process(1);
snmp_shutdown("MyAgent");
return 0;
}
-----------------------------------------------------------
I simply compile with :
> gcc -O2 -I inc -Wall -Wextra -Werror src/myappl.c -lpthread -lnetsnmp
-lnetsnmpagent -o bin/myappl
myappl runs fine up to the "while (dont_stop)" loop, and correctly stops
whenever Ctrl-C is pressed (which makes dont_stop false).
In the meanwhile, I do the snmpget command above. Of course, I never see
the "handler has been called" message...
So... does anyone out there have a clue about what I am doing wrong ?
... or just a pointer on what to check ?
I'm really lost there, so any help would be appreciated...
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users