tech:notes_snmp
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| tech:notes_snmp [2026/02/23 17:07] – Jean-Baptiste | tech:notes_snmp [2026/07/16 15:12] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Notes SNMP | ||
| + | |||
| + | Voir : | ||
| + | * [[Notes SNMPv3]] | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * http:// | ||
| + | * https:// | ||
| + | * [Configuration avancée de SNMP sur Linux : redémarrer un service à distance en utilisant le protocole SNMP](https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | Voir les traps SNMP : | ||
| + | * [Les traps SNMP](https:// | ||
| + | * [snmptt](https:// | ||
| + | * [How to define trapsess for snmpv3 without plain passwords in Red Hat Enterprise Linux 6](https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | Exemple de conf : | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ## Serveur | ||
| + | |||
| + | ### RedHat | ||
| + | |||
| + | ~~~bash | ||
| + | yum install net-snmp | ||
| + | ~~~ | ||
| + | |||
| + | ### Debian | ||
| + | |||
| + | ~~~bash | ||
| + | apt-get install snmpd snmptrapd snmp-mibs-downloader | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | ln -s / | ||
| + | ~~~ | ||
| + | |||
| + | `/ | ||
| + | ~~~bash | ||
| + | #export MIBS= | ||
| + | export MIBS=ALL | ||
| + | export MIBDIRS=/ | ||
| + | |||
| + | # | ||
| + | TRAPDRUN=yes | ||
| + | |||
| + | # | ||
| + | TRAPDOPTS=' | ||
| + | ~~~ | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | #mibs : | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | service snmpd restart | ||
| + | service snmptrapd restart | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Conf | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | # | ||
| + | rocommunity public | ||
| + | |||
| + | # | ||
| + | # | ||
| + | agentAddress udp:161 | ||
| + | |||
| + | # | ||
| + | skipNFSInHostResources 1 | ||
| + | ~~~ | ||
| + | |||
| + | #### Exemple conf | ||
| + | |||
| + | ##### Exemple 1 - Conf Debian | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | agentAddress udp: | ||
| + | view | ||
| + | view | ||
| + | rocommunity public | ||
| + | rouser | ||
| + | sysLocation | ||
| + | sysContact | ||
| + | sysServices | ||
| + | proc mountd | ||
| + | proc ntalkd | ||
| + | proc sendmail 10 1 | ||
| + | disk / | ||
| + | disk / | ||
| + | includeAllDisks | ||
| + | load 12 10 5 | ||
| + | trapsink | ||
| + | iquerySecName | ||
| + | rouser | ||
| + | defaultMonitors | ||
| + | linkUpDownNotifications | ||
| + | extend | ||
| + | extend-sh test2 echo Hello, world! ; echo Hi there ; exit 35 | ||
| + | master | ||
| + | smuxpeer .1.3.6.1.4.1.674.10892.1 | ||
| + | ~~~ | ||
| + | |||
| + | ##### Exemple 2 - Conf RedHat | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | #com2sec notConfigUser | ||
| + | com2sec mynetwork 192.168.0.0/ | ||
| + | group | ||
| + | group | ||
| + | view centreon included .1.3.6.1 | ||
| + | view systemview | ||
| + | view systemview | ||
| + | access notConfigGroup "" | ||
| + | access | ||
| + | syslocation Unknown (edit / | ||
| + | syscontact Root < | ||
| + | dontLogTCPWrappersConnects yes | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | cat >> / | ||
| + | view systemview | ||
| + | EOF | ||
| + | ~~~ | ||
| + | ##### Exemple 3 - Debian 8 | ||
| + | |||
| + | Pour éviter bug timeout, car SNMP essaye de remonter les infos sur toutes les partitions qu'il trouve | ||
| + | ~~~bash | ||
| + | systemctl disable mnt-espace_build.automount partage_install.automount partage_librairies.automount mnt-espace_build.mount partage_install.mount partage_librairies.mount | ||
| + | systemctl stop mnt-espace_build.automount partage_install.automount partage_librairies.automount mnt-espace_build.mount partage_install.mount partage_librairies.mount | ||
| + | ~~~ | ||
| + | |||
| + | Install du paquet **snmp-mibs-downloader** et de sa dépendance **smistrip** | ||
| + | ~~~bash | ||
| + | dpkg -i smistrip_0.4.8+dfsg2-10_all.deb snmp-mibs-downloader_1.1_all.deb | ||
| + | ~~~ | ||
| + | |||
| + | `/ | ||
| + | ~~~bash | ||
| + | export MIBS=ALL | ||
| + | SNMPDRUN=yes | ||
| + | SNMPDOPTS=' | ||
| + | export MIBDIRS=/ | ||
| + | ~~~ | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | agentAddress udp: | ||
| + | rocommunity public | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ##### Exemples droit d' | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | # rouser: a SNMPv3 read-write user | ||
| + | # | ||
| + | |||
| + | rouser nagios auth | ||
| + | ~~~ | ||
| + | |||
| + | Accès en lecture et écriture à la totalité de l' | ||
| + | `/ | ||
| + | ~~~ | ||
| + | rwuser admin authpriv .1 | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Pb - refused smux peer: oid SNMPv2-SMI:: | ||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | ~~~bash | ||
| + | systemctl status snmpd | ||
| + | ● snmpd.service - Simple Network Management Protocol (SNMP) Daemon. | ||
| + | | ||
| + | | ||
| + | Main PID: 61127 (snmpd) | ||
| + | | ||
| + | | ||
| + | |||
| + | juin 07 11:37:03 8cc-offline-1 systemd[1]: Starting Simple Network Management Protocol (SNMP) Daemon.... | ||
| + | juin 07 11:37:03 8cc-offline-1 snmpd[61127]: | ||
| + | juin 07 11:37:03 8cc-offline-1 snmpd[61127]: | ||
| + | juin 07 11:37:03 8cc-offline-1 systemd[1]: Started Simple Network Management Protocol (SNMP) Daemon.. | ||
| + | juin 07 11:37:06 8cc-offline-1 snmpd[61127]: | ||
| + | juin 07 11:37:09 8cc-offline-1 snmpd[61127]: | ||
| + | juin 07 11:37:12 8cc-offline-1 snmpd[61127]: | ||
| + | ~~~ | ||
| + | |||
| + | #### Solution | ||
| + | |||
| + | Solution 1 | ||
| + | ~~~bash | ||
| + | #echo " | ||
| + | echo " | ||
| + | systemctl restart snmpd | ||
| + | ~~~ | ||
| + | |||
| + | Solution 2 | ||
| + | |||
| + | `/ | ||
| + | ~~~bash | ||
| + | # snmpd command line options | ||
| + | # ' | ||
| + | # OPTIONS=" | ||
| + | OPTIONS=" | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | systemctl restart snmpd | ||
| + | ~~~ | ||
| + | |||
| + | ### Pleins de message " | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | Jul 18 01:08:07 plop snmpd[3232]: | ||
| + | Jul 18 01:08:34 plop snmpd[3232]: | ||
| + | ~~~ | ||
| + | |||
| + | #### Solution | ||
| + | |||
| + | Remplacer `-Lsd` par `-LSwd` | ||
| + | |||
| + | `/ | ||
| + | ~~~ini | ||
| + | # | ||
| + | SNMPDOPTS=' | ||
| + | ~~~ | ||
| + | |||
| + | Ou | ||
| + | |||
| + | `/ | ||
| + | ~~~bash | ||
| + | # | ||
| + | OPTIONS=" | ||
| + | ~~~ | ||
| + | |||
| + | ou | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | dontLogTCPWrappersConnects yes | ||
| + | ~~~ | ||
| + | |||
| + | puis restart du service | ||
| + | |||
| + | |||
| + | ### Autres | ||
| + | |||
| + | |||
| + | `usmUser` a été créer après le redémarrage de SNMPd suite à la commande `createUser` (SNMPv3) | ||
| + | |||
| + | Voir la commande `snmpusm` | ||
| + | |||
| + | #### snmptranslate | ||
| + | |||
| + | ~~~ | ||
| + | $ snmptranslate -M+. -m +ALL -On HOST-RESOURCES-MIB:: | ||
| + | .1.3.6.1.2.1.25.3.3 | ||
| + | |||
| + | $ snmptranslate -Td .1.3.6.1.4.1.2021.11.52 | ||
| + | UCD-SNMP-MIB:: | ||
| + | ... | ||
| + | This object may sometimes be implemented as the | ||
| + | combination of the ' | ||
| + | ' | ||
| + | taken when summing the overall raw counters." | ||
| + | ~~~ | ||
| + | |||
| + | #### HP | ||
| + | |||
| + | |||
| + | Ajoutez la ligne suivante dans / | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | dlmod cmaX / | ||
| + | ~~~ | ||
| + | |||
| + | Redémarrez les services suivants : | ||
| + | ~~~bash | ||
| + | systemctl restart hp-snmp-agents | ||
| + | systemctl restart snmpd | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ## Client | ||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | |||
| + | Use the `-On` option, according to `man snmpcmd` | ||
| + | |||
| + | ~~~bash | ||
| + | #snmpwalk -v2c -c public localhost | ||
| + | snmpwalk -v2c -On -c public localhost | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ### snmpwalk | ||
| + | |||
| + | Voir aussi : | ||
| + | * snmpgetnext | ||
| + | |||
| + | Exemples : | ||
| + | ~~~bash | ||
| + | # snmpwalk -t " | ||
| + | # ' | ||
| + | |||
| + | snmpwalk -v2c -c public localhost system | ||
| + | #snmpwalk -v < | ||
| + | snmpwalk -v 2c -c public 192.168.1.13 1.3.6.1.2.1.2.2.1.10 | ||
| + | |||
| + | snmpwalk -v 3 -u usersnmp -a SHA -A ' | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ATTENTION : ne faites JAMAIS une requête snmpwalk sur la racine de l’arbre SNMP ou sur un noeud de haut niveau. Si vous faites cela, vous allez saturer l’agent SNMP interrogé, le réseau et votre poste. Dans le passé, vous pouviez saturer certains agents SNMP et il était nécessaire de les redémarrer voire de redémarrer l’équipement. Ce pourrait être très gênant si vous deviez demander à l’équipe réseau de redémarrer un routeur. | ||
| + | ~~~bash | ||
| + | # snmpwalk -v2c -c public 192.168.1.13 | ||
| + | ~~~ | ||
| + | |||
| + | Pour debug | ||
| + | ~~~bash | ||
| + | snmpwalk -d -DAll | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### snmpget | ||
| + | |||
| + | ~~~bash | ||
| + | #snmpget -v < | ||
| + | snmpget -v 2c -c public 192.168.1.13 1.3.6.1.2.1.2.2.1.10.1 | ||
| + | |||
| + | OID_STORAGE_DESC=.1.3.6.1.2.1.25.2.3.1.3 | ||
| + | OID_STORAGE_SIZE=.1.3.6.1.2.1.25.2.3.1.5 | ||
| + | OID_STORAGE_USED=.1.3.6.1.2.1.25.2.3.1.6 | ||
| + | |||
| + | snmpget -r 2 -v 3 -a MD5 -A " | ||
| + | snmpget -r 2 -v 3 -a MD5 -A " | ||
| + | snmpget -r 2 -v 3 -a MD5 -A " | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Nagios check_snmp | ||
| + | |||
| + | Exemple de supervision de ports sur un switch | ||
| + | |||
| + | `/ | ||
| + | ~~~c | ||
| + | define command{ | ||
| + | command_name | ||
| + | command_line | ||
| + | } | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | `switch.cfg` | ||
| + | ~~~c | ||
| + | define service{ | ||
| + | use generic-service ; | ||
| + | host_name linksys-srw224p | ||
| + | service_description Port 1 Link Status | ||
| + | check_command check_snmp!-C public -o ifOperStatus.1 -r 1 -m RFC1213-MIB | ||
| + | } | ||
| + | |||
| + | ~~~ | ||
| + | |||
| + | `/ | ||
| + | ~~~c | ||
| + | define service{ | ||
| + | use | ||
| + | hostgroup_name | ||
| + | service_description | ||
| + | check_command | ||
| + | # | ||
| + | } | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ### Lister les utilisateurs SNMPv3 | ||
| + | |||
| + | ~~~bash | ||
| + | snmpwalk .1.3.6.1.6.3.15.1.2.2.1.3 | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Ajout d'une MIB | ||
| + | |||
| + | Voir : https:// | ||
| + | |||
| + | Logs Zabbix | ||
| + | ~~~ | ||
| + | MIB search path: / | ||
| + | Cannot find module (DISMAN-EVENT-MIB): | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | apt-get install snmp-mibs-downloader | ||
| + | ~~~ | ||
| + | |||
| + | La MIB sera installée ici : `/ | ||
| + | |||
| + | Commenter **mibs :** | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | #mibs : | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | snmptranslate -Tp | ||
| + | ~~~ | ||
| + | |||
| + | Pour **DISMAN-EVENT-MIB** le pb est résolu | ||
| + | |||
| + | Mais il reste **CPQRACK-MIB** et **CPQIDA-MIB** | ||
| + | ~~~ | ||
| + | Cannot find module (CPQRACK-MIB): | ||
| + | Cannot find module (CPQIDA-MIB): | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | git clone https:// | ||
| + | cd SnmpMibs | ||
| + | cp CPQ* / | ||
| + | chmod a+r / | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | #### Notes | ||
| + | |||
| + | ~~~ | ||
| + | snmpget -t 1 -r 5 -M / | ||
| + | tcpdump -i any -s 0 host hp-array-1.0 and port 161 -n | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ### snmpcheck | ||
| + | |||
| + | Il existe l' | ||
| + | |||
| + | Il ne faut pas confondre la commande snmpcheck de Debian (paquet **[[http:// | ||
| + | |||
| + | Debian | ||
| + | ~~~bash | ||
| + | apt-get install ruby-snmp | ||
| + | ~~~ | ||
| + | |||
| + | RedHat | ||
| + | ~~~bash | ||
| + | yum install ruby | ||
| + | gem install snmp | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | wget http:// | ||
| + | chmod +x snmpcheck-1.9.rb | ||
| + | ./ | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | nmap -sS 192.168.56.21 | ||
| + | snmpcheck -h | ||
| + | snmpcheck -t 192.168.56.21 | ||
| + | ~~~ | ||
| + | |||
| + | ### qtmib | ||
| + | |||
| + | |||
| + | |||
| + | GUI SNMP MIB Browser for Linux platforms | ||
| + | Liens : https:// | ||
| + | |||
| + | The program comes with a large number of MIBs pre-installed, | ||
| + | |||
| + | |||
