Question au sujet de Net-SNMP
Bonjour,
Merci pour cet article Introduction à Net-SNMP et SNMP version 1, je suis tombé dessus un peu tard, mais en tout cas ça m'a permis de comprendre pas mal de choses sur net-snmp.
Par contre j'aurai quelques questions:
Le snmpd.conf qui est pris en compte est celui dans /etc/snmp alors que tout les tutoriels sur le site officiel de net-snmp parlent de /usr/local/share/snmp/ ... et si j'édite le fichier dans ce répertoire, les changements ne sont évidement pas du tout pris en compte..
J'ai donc du mal à savoir à quoi correspondent tout ces snmpd.conf
Ensuite j'ai un deuxième soucis, c'est que j'essaie d'ajouter une MIB et son module (.c et .h associés) à l'agent principal..
Dans un premier temps, j'utilise l'exemple détaillé de net-snmp section "Compiling in your new MIB module" ici:
http://net-snmp.sourceforge.net/wiki...g_a_MIB_Module
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| Compiling in your new MIB module
Note: you will need to have previously installed the Net-SNMP Source Package on your system before proceeding.
There are a few ways to get your new MIB module loaded and accessible via SNMP requests. We'll discuss all three ways separately. To make this easy to test the procedures outlined below, we've provided three simple mib modules which implement the three simple scalars in the NET-SNMP-TUTORIAL-MIB MIB. To see how MIBs can be properly used by the tools, please see the mib-options tutorial.
Compile it into the master agent.
Lets assume you're going to compile in a new mib module. For our example, lets use the example mib module and it's header file. To do this, you would put the nstAgentModuleObject.h and nstAgentModuleObject.c files into the net-snmp source code directory. You do this by copying them into a agent/mibgroup/nstAgentModuleObject.h and agent/mibgroup/nstAgentModuleObject.c file.
Next, you have to configure the package to find them and compile them into the agent. To do this, you run the configure script giving it the extra module names you want it to load:
% ./configure --with-mib-modules="nstAgentModuleObject"
If you had multiple modules to include (like a second "XXX" module, for example), you can separate them with spaces inside the quotes (e.g., --with-mib-modules="nstAgentModuleObject XXX").
Note that nstAgentModuleObject is the prefix and the configure script will actually look for a nstAgentModuleObject.h and a nstAgentModuleObject.c file. You must have a .h file and you can not get it to work with just a .c file.
Build your new agent with your new code in it by running make:
% make
Finally, install the whole lot by running make install:
% make install
Now that the agent is installed, you need to add some basic configuration (see other tutorials for more configuration options). Here we just add a simple read-only and read-write community strings (tutget and tutset, respectively) for the tutorial MIB branch:
% echo "rocommunity tutget .1.3.6.1.4.1.8072.2.4" > /usr/local/etc/snmpd.conf
% echo "rwcommunity tutset .1.3.6.1.4.1.8072.2.4" > /usr/local/etc/snmpd.conf
You can test out the functionality by starting the snmpd agent:
% /usr/local/sbin/snmpd -f -L -d -p 9999
This runs the agent on a temporary port ( -p 9999) so that it doesn't need special priviledges, or interfere with your 'normal' agent. Incoming and outgoing packets are printed (-d), to show what's happening, and the agent is run as a 'non-daemon' command (-f -L) so that you can see these messages. Note that this ties up the current shell, so you'll need to run the following checks in a different terminal window.
And then running snmpget and snmpset on the scalar object:
% snmpget -v2c -c tutget localhost:9999 NET-SNMP-TUTORIAL-MIB::nstAgentModuleObject.0
NET-SNMP-TUTORIAL-MIB::nstAgentModuleObject.0 = INTEGER: 1
% snmpset -v2c -c tutset localhost:9999 NET-SNMP-TUTORIAL-MIB::nstAgentModuleObject.0 = 5
NET-SNMP-TUTORIAL-MIB::nstAgentModuleObject.0 = INTEGER: 5
% snmpget -v2c -c tutget localhost:9999 NET-SNMP-TUTORIAL-MIB::nstAgentModuleObject.0
NET-SNMP-TUTORIAL-MIB::nstAgentModuleObject.0 = INTEGER: 5
You can also compile your code into a "subagent" which then attaches itself to the master agent using the AgentX subagent protocol. Our libraries provide support to make this easy to do and this is discussed in greater detail in a later section.
Finally, you can also compile your code into pluggable shared object and tell the snmpd agent to load it. This is also discussed in greater detail in a later section . |
Or malgré que j'ai bien ajouté la MIB dans snmpd.conf (les snmptranslate fonctionnent), que les Get sur des variables tels que sysLocation fonctionnent, les GET sur NET-SNMP-TUTORIAL-MIB::nstAgentModuleObject me renvoient:
No Such Object available on this agent at this OID
j'ai tenté d'utiliser juste la communauté public et le port 161, et le problème reste le même..
Exemple de GET qui marche et qui ne marche pas:
Code:
1 2 3 4 5
| snmpget -v2c -c public localhost NET-SNMP-AGENT-MIB::nsCacheEnabled.0
NET-SNMP-AGENT-MIB::nsCacheEnabled.0 = INTEGER: false(2)
snmpget -v2c -c public localhost NET-SNMP-TUTORIAL-MIB::nstAgentModuleObject.0
NET-SNMP-TUTORIAL-MIB::nstAgentModuleObject.0 = No Such Object available on this agent at this OID |
et voilà ce que j'ai actuellement dans mon /etc/snmp/snmpd.conf:
Code:
1 2 3
|
export MIBDIRS=/usr/share/snmp/mibs
mibs ALL |
et pour info:
Code:
1 2 3
| $ cd /usr/share/snmp/mibs
/usr/share/snmp/mibs$ ls | grep TUTORIAL
NET-SNMP-TUTORIAL-MIB.txt |
et voilà le résumé que j'ai eu à la fin de ./configure --with-mib-modules="nstAgentModuleObject" en suivant le tutorial (on voit bien le nstAgentModuleObject):
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| ---------------------------------------------------------
Net-SNMP configuration summary:
---------------------------------------------------------
SNMP Versions Supported: 1 2c 3
Building for: linux
Net-SNMP Version: 5.7.2
Network transport support: Callback Unix Alias TCP UDP IPv4Base SocketBase TCPBase UDPIPv4Base UDPBase
SNMPv3 Security Modules: usm
Agent MIB code: nstAgentModuleObject default_modules => snmpv3mibs mibII ucd_snmp notification notification-log-mib target agent_mibs agentx disman/event disman/schedule utilities host
MYSQL Trap Logging: unavailable
Embedded Perl support: enabled
SNMP Perl modules: building -- embeddable
SNMP Python modules: disabled
Crypto support from: crypto
Authentication support: MD5 SHA1
Encryption support: DES AES
Local DNSSEC validation: disabled
--------------------------------------------------------- |
Je ne cherche pas à terme à faire un module compliqué mais en fait je suis en train de développer un manager SNMP avec Qt qui pilotera un agent SNMP sur système embarqué. Du coup pour pouvoir tester sans attendre que le système embarqué soit disponible (il est toujours en cours de fabrication), je voudrais me servir de cet exemple pour vérifier que mon manager est bien capable de faire des GET, SET et de recevoir des TRAP.. et là je suis en train de passer tout le temps que j'avais prévu au développent de ce manager sur la mise en place d'un simple agent..
En espérant avoir une réponse, car la je fais chou blanc de partout..