Installing Net-Snmp on the Synology DS 207

I wanted to have an SNMP dæmon running on my NAS. This way all the boxes on my network can be queried using SNMP. This is quite simple, assuming you have ipkg installed.

  1. Install net-snmp: ipkg install net-snmp
  2. Edit the configuration file in /opt/etc/snmpd.conf, you can just use vi or call the snmpconf program. There a three fields you should edit:
    1. Comment ou the entry that defines write access # rwcommunity SNMPv1_RW you probably don’t need this feature and this is a security risk
    2. Edit the syslocation to add the physical location of the NAS.
    3. Edit the syscontact line to add the contact person for the device, probably yourself.
    4. Add a line define the types of services provided by the box, something like sysservices 76, this corresponds to the following service levels: Internet, End-to-end, Application.
  3. Restart the snmp dæmon: /opt/etc/init.d/S70net-snmp

I also updated the hostinfo script, I cleaned up the formatting and some of the code (I would still not call it pretty), and added code to extract storage information. This information is provided by the NAS, but also my printer.

flattr this!

Synology DS 207 – new firmware

DS 207 -NAS Web screen capture

This week-end, I finally took the time to upgrade the firmware of my Synology DS-207 NAS to version DSM 2.0-0722. The upgrade was a little bit complicated: you first have to download the patch to Mac, prevent the Mac from expanding it, then upload the patch to the NAS by the way of a web-interface which does not work with Safari. The advantage when you don’t upgrade often is that you feel the difference: the whole web interface is way more polished and responsive thanks to some AJAX code, many services that kind of work are now stable (typically the iTunes music sharing service), and things that had to be hacked in are now installed by default (SSH access, NFS server). The Linux kernel is now Linux 2.6.15 #722 Fri Sep 19 20:30:34 CST 2008 ppc unknown. Finally the web interface is now better structured, and many components have their own interface. For instance the “Audio Station” can be used to see the various songs stored on the NAS, they can also be listened to using a flash player. Clearly Synology realized they can capitalize on their open-source foundation to build up the feature set of their product. They also seem to have shifted their focus from small businesses to private owners. The only thing I was missing was a SNMP interface, but I suspect I should be able to install NetSNMP one way or another.

flattr this!

More numbers

Now that the cluster update is done, I was able to start experiments again. It appears that my strange numbers are still here. I installed some more precise monitoring tools like sar, and tried to figure out what is going on. Here is the CPU usage graph for my application that simples receives UDP/SNMP heartbeat traps sent at a 1ms time interval.

CPU Usage graph

As you can see, the period signal is still there. Trying to figure out what is going on, I did some profiling on my java code to figure out what is going. Here is the result of the profiling.

rank self accum count trace method
1 99.74% 99.74% 295735 300260 java.net.PlainDatagramSocketImpl.receive0
2 0.03% 99.77% 95 300335 org.snmp4j.smi.VariableBinding.<init>
3 0.02% 99.79% 70 300330 org.snmp4j.smi.OctetString.<init>
4 0.02% 99.81% 63 300332 org.snmp4j.smi.OID.<init>
5 0.02% 99.83% 62 300329 jp.ac.jaist.snmpd.knowledge.ProcessKnowlegeState.<init>

So my code is statistically doing nothing, just waiting for the next UDP packet to arrive, at the same time, I get CPU usage that goes up and down, including in supervisor mode. You can also see that the system and user level CPU usages are correlated, so it is clearly UDP packet reception that triggers this stuff. The only good thing is that the problem clearly does not lie in my code.

flattr this!

Growl SNMP Adapter

SNMP Notification logo

Growl is an interesting open-source project. The idea is to have one central service to handle bezel like notifications. The system has evolved and can now display notifications using different GUIs. There are now quite a few applications relying on Growl for notification, first Adium, but also Skype. There are also plugins so that newly delivered e-mails in Mail trigger such a notification.

One drawback of Growl, is that it does not really integrate with existing notification services like syslog, or SNMP traps. To remedy this, I have written a small java programs that takes incoming SNMP traps and translates them into growl notifications. The program is rather primitive, but it works. People who are interested can download a first version of the program. The tar file basically contains a jar file, a graphic file and a launch script. To use it, open a terminal and type sudo ./snmpgrowl.bash (the program needs to run as root to be able to link to a privileged port, that is 162. Once the password has been typed it, the program can be put into the background. You can test the installation by typing snmptrap -v 2c 127.0.0.1 0 1.2.3.4 1.1 s "Hello World"

If people are interested by the source code, they should send me an e-mail (the program is build using the snmp4j open source project. The program is at the moment very primitive and does little beyond transmitting the data.

Update the download link, which was broken

flattr this!

Bricolons avec SNMP

Ces jours, j’ai commencé à sérieusement bricoler avec le protocole SNMP. C’est un des rares protocoles que j’ai appris à l’université qui soit encore largement utilisé. Je travaille avec le package SNMP4J qui, s’il n’est pas idéal, est relativement complet.

À quoi sert SNMP ? Il s’agit à l’origine d’un protocol pour ‘parler’ aux différents appareils qui forment l’infrastructure du réseau: routeurs, switches etc. Si à l’origine ce protocol était uniquement implémenté dans le matériel haut de gamme, de nos jours, on trouve un petit serveur (agent en langage SNMP) dans la plupart des équipements réseaux, jusqu’aux routeurs ADSL et aux imprimantes réseau. Curieusement, on trouve rarement un agent SNMP sur les PCs ce qui est dommage, cela simplifierait pas mal la vie des administrateurs systèmes.

Un des concepts clefs de SNMP est la MIB, c’est la base de donnée qui représente l’état et la configuration de l’appareil. Chaque élément de la MIB est identifié par une clef (appelée OID) et une valeur, qui est un type de base (string, différentes sortes d’entiers). En structurant les OIDs on peut construire des tables. Que contient la MIB ? Virtuellement n’importe quoi. Cela va depuis le nom de la personne de contact responsable pour l’équipement (OID 1.3.6.1.2.1.1.4.0), jusqu’à la configuration des différentes interfaces réseau.

Pas la peine d’essayer cette commande depuis chez vous, l’imprimante en question est bravement cachée derrière le firewall de JAIST.

Pour utiliser SNMP, sous Unix, on a à disposition une série de commandes. La plus simple est la commande snmpget qui permet de lire une variable de la MIB. Par exemple, j’aimerais savoir ce qui se cache derrière une adresse IP, en l’occurrence une imprimante ici.

snmpget -v 1 -c public ps-is16e0r0.jaist.ac.jp SNMPv2-MIB::sysDescr.0

Le paramètre v spécifie la version de SNMP qu’on va utiliser (1), le paramètre c spécifie la communauté. La communauté est une sorte de mot de passe.

L’imprimante va me répondre:

SNMPv2-MIB::sysDescr.0 = STRING: RICOH IPSiO NX850 2.00 / RICOH Network Printer C model

Le code SNMPv2-MIB::sysDescr.0 est une forme humainement lisible de l’OID 1.3.6.1.2.1.1.1.0. Ensuite vient le type de la réponse (une chaîne de caractères), et enfin la réponse, en l’occurrence le modèle de l’imprimante.

Une commande plus générale est snmpwalk, celle-ci permet d’explorer une portion de la MIB. La commande suivante demande tous les éléments qui font partie des informations de base sur un nœud du réseau (en l’occurrence ma propre machine, sur laquelle j’ai lancé le démon snmpd).

snmpwalk -v 1 -c public 127.0.0.1 1.3.6.1.2.1.1

Le résultat est la séquence d’information suivante:

MPv2-MIB::sysDescr.0 = STRING: Darwin kt-dhcp01.jaist.ac.jp 8.2.0 Darwin Kernel Version 8.2.0: Fri Jun 24 17:46:54 PDT 2005; root:xnu-792.2.4.obj~3/RELEASE_PPC Power Macintosh
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.255
SNMPv2-MIB::sysUpTime.0 = Timeticks: (69916504) 8 days, 2:12:45.04
SNMPv2-MIB::sysContact.0 = STRING: "Matthias Wiesmann"
SNMPv2-MIB::sysName.0 = STRING: kt-dhcp01.jaist.ac.jp
SNMPv2-MIB::sysLocation.0 = STRING: "JAIST 6th floor"
SNMPv2-MIB::sysServices.0 = INTEGER: 76
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (500) 0:00:05.00
…

Comme dit plus haut, une grande partie des informations dans la MIB sont structurées comme des tables. Par exemple l’imprimante mentionnée plus haut a un table de système de stockage. On peut visualiser cette table grâce à la commande suivante

snmptable -v 1 -c public ps-is16e0r0.jaist.ac.jp 1.3.6.1.2.1.25.2.3

Le résultat est la table suivante:

SNMP table: HOST-RESOURCES-MIB::hrStorageTable

 hrStorageIndex                        hrStorageType hrStorageDescr hrStorageAllocationUnits hrStorageSize hrStorageUsed hrStorageAllocationFailures
              1   HOST-RESOURCES-TYPES::hrStorageRam            RAM                  1 Bytes     301989888     301989888                           0
              2 HOST-RESOURCES-TYPES::hrStorageOther          FLASH                  1 Bytes       8388608       8388608                           0

La même commande sur mon laptop donne les résultat suivants

SNMP table: HOST-RESOURCES-MIB::hrStorageTable

 hrStorageIndex                                hrStorageType     hrStorageDescr hrStorageAllocationUnits hrStorageSize hrStorageUsed hrStorageAllocationFailures
              1         HOST-RESOURCES-TYPES::hrStorageOther     Memory Buffers                256 Bytes             ?             ?                           ?
              2           HOST-RESOURCES-TYPES::hrStorageRam        Real Memory               4096 Bytes             0       2131376                           ?
              3 HOST-RESOURCES-TYPES::hrStorageVirtualMemory         Swap Space               4096 Bytes       2131124   -1073746432                           ?
              4     HOST-RESOURCES-TYPES::hrStorageFixedDisk                  /               4096 Bytes      19504908      15949534                           ?
              5     HOST-RESOURCES-TYPES::hrStorageFixedDisk               /dev                512 Bytes             2             2                           ?
              6     HOST-RESOURCES-TYPES::hrStorageFixedDisk               /dev                512 Bytes             2             2                           ?
              7     HOST-RESOURCES-TYPES::hrStorageFixedDisk              /.vol                512 Bytes          1024          1024                           ?
              8     HOST-RESOURCES-TYPES::hrStorageFixedDisk           /Network                512 Bytes             0             0                           ?
              9     HOST-RESOURCES-TYPES::hrStorageFixedDisk /automount/Servers                512 Bytes             0             0                           ?
             10     HOST-RESOURCES-TYPES::hrStorageFixedDisk  /automount/static                512 Bytes             0             0                           ?

Une autre table très utile est celle qui contient la liste des adresses IP pour un equipement donné.

snmptable -v 1 -c public 127.0.0.1 1.3.6.1.2.1.4.20
SNMP table: IP-MIB::ipAddrTable

   ipAdEntAddr ipAdEntIfIndex  ipAdEntNetMask ipAdEntBcastAddr ipAdEntReasmMaxSize
     127.0.0.1              1       255.0.0.0                1                   ?
  150.65.26.79              5   255.255.254.0                1                   ?
 150.65.239.67              4 255.255.255.128                1                   ?

Donne la liste des interfaces réseaux, dans mon cas, il y en a trois active en ce moment, ethernet (4), wifi (5) et l’interface loopback (1).

La chose intéressante est naturellement de pouvoir visualiser tous les appareils connectés au réseau de manière uniforme. La prochaine fois, j’essayerais de vous parler des notifications (trappes).

flattr this!