Dies ist eine alte Version des Dokuments!


Icinga 2 - Netzwerkmonitoring mit Hilfe von SNMP

Bild: SNMP - LOGO SNMP1) ist ein, von der IETF entwickeltes, Netzwerkprotokoll um Netzwerkelemente (Server, Switche, Router, Drucker, Rechner etc.) von einer zentralen Station aus überwachen und steuern zu können. Weiter Informationen findet man im folgenden Wikipedia-Artikel.

Bei dem folgendem Konfigurationsbeispiel wollen wir uns die Konfiguration von snmp unter CentOS 7 etwas genauer ansehen. Ziel wird sein den Netzwerktraffic einzelner Ports auf unserem Netzwerkswitch zu überwachen.

In diesem Konfigurationsbeispiel werden wir an einem tp-link Jetstream-48-Port-Gigabit-Smart-PoE+-Switch T1600G-52PS zuerst einmal die Einstellungen für den SNMP-Zugriff einrichten. Wichtige Hinweise finden sich hierzu in der User Guide des Switches.

Entsprechend der Dokumentation erstellen wir die beiden Engine IDs und aktivieren SNMP in der Global Config, die zur eindeutigen Identifikation der betreffenden Kommunikationspartner dient und vor der nachfolgenden Konfiguration von SNMP v3 erfolgen muss.

Bild: SNMP Konfiguration T1600G-52PS

Standardmäßig ist SNMP unverschlüsselt und wird als Klartext über das Netzwerk übertragen, also für unser Sicherheitsniveau alles andere als nutzbar!

Daher werden wir SNMP-Gruppe mit Security-Level v3 verwenden, welches die Möglichkeit der Verschlüsselung und echten Authentifizierung bietet. Hierfür ist natürlich auch eine gesonderte Konfiguration von Nöten.

SNMP v3 kennt verschiedene Sicherheitsstufen:

  • noAuthNoPriv : Hier kommt keine echte benutzerbasierte Authentifizierung und auch keine Verschlüsselung zum Einsatz. Der Vorteil gegenüber v2c ist jedoch, dass das Passwort nicht mehr im Klartext sondern als Passworthash übertragen wird.
  • authNoPriv : Benutzerbasierte Authentifizierung erfolgt mit einem Namen (Sicherheitsname) und einem Passwort. Die Anmeldedaten werden jedoch unverschlüsselt übertragen!
  • authPriv : Benutzerbasierte Authentifizierung wie auch bei authNoPriv, zusätzlich werden alle Daten verschlüsselt. Hier müssen Sie einen Schlüssel manuell austauschen, d.h. den Schlüssel sowohl im zu überwachenden Gerät als auch in Client/Host hinterlegen, der die Anfragen initiieren wird.

Als nächstes definieren wir uns eine SNMP-Gruppe mit Security-Level v3. Mit SNMPv3-Gruppen können Benutzer in Gruppen mit unterschiedlichen Berechtigungen und Zugriffsrechten zusammenfassen werden.

Bild: SNMP Konfiguration T1600G-52PS

Im Anschluss erfolgt dann die Konfiguration unseres SNMP-Users, den wir ebenfalls als Security-Level v3 festlegen und der zu vor erstellten SNMP-Gruppe zuweisen.

Bild: SNMP Konfiguration T1600G-52PS

Zur Abfrage unseres Netzwerkswitchs auf der Konsole unseres CentOS 7 Hosts]** werden wir die beiden Befehle **''snmpwalk''** und **''snmpget''** verwenden. Diese finden sich in dem **RPM** **net-snmp-utils**. Wir installieren also dieses Paket mit Hilfe des Paketverwaltungstool **YUM**. # yum install net-snmp-utils ==== snmpwalk (Version 3) ==== Mit Hilfe von **''snmpwalk''** können wir den Informationsbaum einer Netzwerkeinheit abfragen. Näheres zu dem Befehl finden wir in der zugehörigen Manpage. # man snmpwalk <code>SNMPWALK(1) Net-SNMP SNMPWALK(1) NAME snmpwalk - retrieve a subtree of management values using SNMP GETNEXT requests SYNOPSIS snmpwalk [APPLICATION OPTIONS] [COMMON OPTIONS] AGENT [OID] DESCRIPTION snmpwalk is an SNMP application that uses SNMP GETNEXT requests to query a network entity for a tree of information. An object identifier (OID) may be given on the command line. This OID specifies which portion of the object identifier space will be searched using GETNEXT requests. All variables in the subtree below the given OID are queried and their values pre‐ sented to the user. Each variable name is given in the format specified in variables(5). If no OID argument is present, snmpwalk will search the subtree rooted at SNMPv2-SMI::mib-2 (including any MIB object values from other MIB modules, that are defined as lying within this subtree). If the network entity has an error processing the request packet, an error packet will be returned and a message will be shown, helping to pinpoint why the request was mal‐ formed. If the tree search causes attempts to search beyond the end of the MIB, the message "End of MIB" will be displayed. OPTIONS -Cc Do not check whether the returned OIDs are increasing. Some agents (LaserJets are an example) return OIDs out of order, but can complete the walk anyway. Other agents return OIDs that are out of order and can cause snmpwalk to loop indefinitely. By default, snmpwalk tries to detect this behavior and warns you when it hits an agent acting illegally. Use -Cc to turn off this check. -CE {OID} End the walk at the specified OID, rather than a simple subtree. This can be used to walk a partial subtree, selected columns of a table, or even two or more tables within a single command. -Ci Include the given OID in the search range. Normally snmpwalk uses GETNEXT requests starting with the OID you speci‐ fied and returns all results in the MIB subtree rooted at that OID. Sometimes, you may wish to include the OID speci‐ fied on the command line in the printed results if it is a valid OID in the tree itself. This option lets you do this explicitly. -CI In fact, the given OID will be retrieved automatically if the main subtree walk returns no useable values. This allows a walk of a single instance to behave as generally expected, and return the specified instance value. This option turns off this final GET request, so a walk of a single instance will return nothing. -Cp Upon completion of the walk, print the number of variables found. -Ct Upon completion of the walk, print the total wall-clock time it took to collect the data (in seconds). Note that the timer is started just before the beginning of the data request series and stopped just after it finishes. Most impor‐ tantly, this means that it does not include snmp library initialization, shutdown, argument processing, and any other overhead. In addition to these options, snmpwalk takes the common options described in the snmpcmd(1) manual page. EXAMPLES Note that snmpbulkget REQUIRES an argument specifying the agent to query and at most one OID argument, as described there. The command: snmpwalk -Os -c public -v 1 zeus system will retrieve all of the variables under system: sysDescr.0 = STRING: "SunOS zeus.net.cmu.edu 4.1.3_U1 1 sun4m" sysObjectID.0 = OID: enterprises.hp.nm.hpsystem.10.1.1 sysUpTime.0 = Timeticks: (155274552) 17 days, 23:19:05 sysContact.0 = STRING: "" sysName.0 = STRING: "zeus.net.cmu.edu" sysLocation.0 = STRING: "" sysServices.0 = INTEGER: 72 (plus the contents of the sysORTable). The command: snmpwalk -Os -c public -v 1 -CE sysORTable zeus system will retrieve the scalar values, but omit the sysORTable. SEE ALSO snmpcmd(1), snmpbulkwalk(1), variables(5). V5.7.2 28 May 2007 SNMPWALK(1)</code> # snmpwalk -v3 -l authPriv -u monwalk -a SHA -A 1mi55MY8357fr13nd511V14 -x DES -X 1mi55MY8357fr13nd511V14 10.10.10.106 <code>SNMPv2-MIB::sysDescr.0 = STRING: JetStream 48-Port Gigabit Smart PoE Switch with 4 SFP Slots SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.11863.5.38 DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (1690156216) 195 days, 14:52:42.16 SNMPv2-MIB::sysContact.0 = STRING: django@mailserver.guru SNMPv2-MIB::sysName.0 = STRING: switch_intranet SNMPv2-MIB::sysLocation.0 = STRING: 933k - HE 07 SNMPv2-MIB::sysServices.0 = INTEGER: 3 IF-MIB::ifNumber.0 = INTEGER: 53 IF-MIB::ifIndex.1 = INTEGER: 1 IF-MIB::ifIndex.49153 = INTEGER: 49153 IF-MIB::ifIndex.49154 = INTEGER: 49154 IF-MIB::ifIndex.49155 = INTEGER: 49155 IF-MIB::ifIndex.49156 = INTEGER: 49156 ... </code> ==== snmpget (Version 3) ==== **''snmpget''** ist eine SNMP-Anwendung, die die SNMP-GET-Anforderung zur Abfrage von Informationen über eine Netzwerkeinheit verwendet. Eine oder mehrere Objektkennungen (OIDs) können als Argumente auf der Befehlszeile angegeben werden. Näheres zu dem Befehl finden wir auch hier in der zugehörigen Manpage. # man snmpget <code>SNMPGET(1) Net-SNMP SNMPGET(1) NAME snmpget - communicates with a network entity using SNMP GET requests SYNOPSIS snmpget [COMMON OPTIONS] [-Cf] AGENT OID [OID]... DESCRIPTION snmpget is an SNMP application that uses the SNMP GET request to query for information on a network entity. One or more object identifiers (OIDs) may be given as arguments on the command line. Each variable name is given in the format specified in variables(5). OPTIONS -Cf If -Cf is not specified, some applications (snmpdelta, snmpget, snmpgetnext and snmpstatus) will try to fix errors returned by the agent that you were talking to and resend the request. The only time this is really useful is if you specified a OID that didn't exist in your request and you're using SNMPv1 which requires "all or nothing" kinds of requests. In addition to this option, snmpget takes the common options described in the snmpcmd(1) manual page. Note that snmpget REQUIRES an argument specifying the agent to query and at least one OID argument, as described there. EXAMPLES The command: snmpget -c public zeus system.sysDescr.0 will retrieve the variable system.sysDescr.0 from the host zeus using the community string public : system.sysDescr.0 = "SunOS zeus.net.cmu.edu 4.1.3_U1 1 sun4m" If the network entity has an error processing the request packet, an error packet will be returned and a message will be shown, helping to pinpoint in what way the request was malformed. If there were other variables in the request, the request will be resent without the bad variable. Here is another example. The -c and -v options are defined in the snmpcmd(1) manual page. (Note that system.sysUpTime is an incomplete OID, as it needs the .0 index appended to it): snmpget -v1 -Cf -c public localhost system.sysUpTime system.sysContact.0 This example will return the following: Error in packet Reason: (noSuchName) There is no such variable name in this MIB. This name doesn't exist: system.sysUpTime Similarly, the command: snmpget -v1 -c public localhost system.sysUpTime system.sysContact.0 Will return: Error in packet Reason: (noSuchName) There is no such variable name in this MIB. This name doesn't exist: system.sysUpTime system.sysContact.0 = STRING: root@localhost With the -Cf flag specified the application will not try to fix the PDU for you. SEE ALSO snmpcmd(1), snmpwalk(1), variables(5). V5.7.2 18 Jun 2007 SNMPGET(1)</code> In folgendem Beispiel wollen wir den Hostnamen des Switchs erfragen. Hierzu nutzen wir den Parameter **''sysName.0''**. # snmpget -v3 -l authPriv -u monwalk -a SHA -A 1mi55MY8357fr13nd511V14 -x DES -X 1mi55MY8357fr13nd511V14 10.10.10.106 sysName.0 SNMPv2-MIB::sysName.0 = STRING: switch_ug Natürlich können wir auch mehrere Werte abfragen, wie z.B. den Einbauort mit **''sysLocation.0''** und die Updime des Switch mit **''system.sysUpTime.0''**. # snmpget -v3 -l authPriv -u monwalk -a SHA -A 1mi55MY8357fr13nd511V14 -x DES -X 1mi55MY8357fr13nd511V14 \ 10.10.10.106 sysLocation.0 system.sysUpTime.0 SNMPv2-MIB::sysLocation.0 = STRING: 933k - HE 07 DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (1690245443) 195 days, 15:07:34.43 ==== check_snmp ==== Für die Checks verwenden wir **''check_snmp''**, welches unter CentOS 7 in dem RPM **nagios-plugins-snmp** enthalten ist. Dieses Paket installieren wir uns nun noch. # yum install nagios-plugins-snmp -y Die zum Plugin gehörigen Option können wir wie folgt abfragen. # /usr/lib64/nagios/plugins/check_snmp -h <code>check_snmp v2.3.3 (nagios-plugins 2.3.3) Copyright (c) 1999-2018 Nagios Plugin Development Team <devel@nagios-plugins.org> Check status of remote machines and obtain system information via SNMP Usage: check_snmp -H <ip_address> -o <OID> [-w warn_range] [-c crit_range] [-C community] [-s string] [-r regex] [-R regexi] [-t timeout] [-e retries] [-l label] [-u units] [-p port-number] [-d delimiter] [-D output-delimiter] [-m miblist] [-P snmp version] [-N context] [-L seclevel] [-U secname] [-a authproto] [-A authpasswd] [-x privproto] [-X privpasswd] [--strict] Options: -h, --help Print detailed help screen -V, --version Print version information --extra-opts=[section][@file] Read options from an ini file. See https://www.nagios-plugins.org/doc/extra-opts.html for usage and examples. -4, --use-ipv4 Use IPv4 connection -6, --use-ipv6 Use IPv6 connection -H, --hostname=ADDRESS Host name, IP Address, or unix socket (must be an absolute path) -p, --port=INTEGER Port number (default: 161) -n, --next Use SNMP GETNEXT instead of SNMP GET -P, --protocol=[1|2c|3] SNMP protocol version -N, --context=CONTEXT SNMPv3 context -L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv] SNMPv3 securityLevel -a, --authproto=[MD5|SHA] SNMPv3 auth proto -x, --privproto=[DES|AES] SNMPv3 priv proto (default DES) -C, --community=STRING Optional community string for SNMP communication (default is "public") -U, --secname=USERNAME SNMPv3 username -A, --authpasswd=PASSWORD SNMPv3 authentication password -X, --privpasswd=PASSWORD SNMPv3 privacy password -o, --oid=OID(s) Object identifier(s) or SNMP variables whose value you wish to query -m, --miblist=STRING List of MIBS to be loaded (default = none if using numeric OIDs or 'ALL' for symbolic OIDs.) -d, --delimiter=STRING Delimiter to use when parsing returned data. Default is "=" Any data on the right hand side of the delimiter is considered to be the data that should be used in the evaluation. -w, --warning=THRESHOLD(s) Warning threshold range(s) -c, --critical=THRESHOLD(s) Critical threshold range(s) --rate Enable rate calculation. See 'Rate Calculation' below --rate-multiplier Converts rate per second. For example, set to 60 to convert to per minute --offset=OFFSET Add/subtract the specified OFFSET to numeric sensor data -s, --string=STRING Return OK state (for that OID) if STRING is an exact match -r, --ereg=REGEX Return OK state (for that OID) if extended regular expression REGEX matches -R, --eregi=REGEX Return OK state (for that OID) if case-insensitive extended REGEX matches --invert-search Invert search result (CRITICAL if found) -l, --label=STRING Prefix label for output from plugin -u, --units=STRING Units label(s) for output data (e.g., 'sec.'). -D, --output-delimiter=STRING Separates output on multiple OID requests -t, --timeout=INTEGER:<timeout state> Seconds before connection times out (default: 10) Optional ":<timeout state>" can be a state integer (0,1,2,3) or a state STRING -e, --retries=INTEGER Number of retries to be used in the requests -O, --perf-oids Label performance data with OIDs instead of --label's --strict Enable strict mode: arguments to -o will be checked against the OID returned by snmpget. If they don't match, the plugin returns UNKNOWN. -v, --verbose Show details for command-line debugging (Nagios may truncate output) This plugin uses the 'snmpget' command included with the NET-SNMP package. if you don't have the package installed, you will need to download it from http://net-snmp.sourceforge.net before you can use this plugin. Notes: - Multiple OIDs (and labels) may be indicated by a comma or space-delimited list (lists with internal spaces must be quoted). - See: https://www.nagios-plugins.org/doc/guidelines.html#THRESHOLDFORMAT for THRESHOLD format and examples. - When checking multiple OIDs, separate ranges by commas like '-w 1:10,1:,:20' - Note that only one string and one regex may be checked at present - All evaluation methods other than PR, STR, and SUBSTR expect that the value returned from the SNMP query is an unsigned integer. Rate Calculation: In many places, SNMP returns counters that are only meaningful when calculating the counter difference since the last check. check_snmp saves the last state information in a file so that the rate per second can be calculated. Use the --rate option to save state information. On the first run, there will be no prior state - this will return with OK. The state is uniquely determined by the arguments to the plugin, so changing the arguments will create a new state file. Send email to help@nagios-plugins.org if you have questions regarding use of this software. To submit patches or suggest improvements, send email to devel@nagios-plugins.org </code> Analog dem vorherigen Beispiel mit **[[#snmpget_version_3|snmpget wollen wir auch hier die Uptime des Switches mit Hilfe von check_snmp abfragen. Die OID für sysUpTime lautet gemäß der Supported Public MIBs for TP-Link Switches 1.3.6.1.2.1.1.3.0.

 # /usr/lib64/nagios/plugins/check_snmp -4 -P 3 -H 10.10.10.106 -L authPriv -a SHA -x DES -U monwalk -A "1mi55MY8357fr13nd511V14" -X "1mi55MY8357fr13nd511V14" -o .1.3.6.1.2.1.1.3.0
SNMP OK - Timeticks: (1696245576) 196 days, 7:47:35.76 | iso.3.6.1.2.1.1.3.0=1696245576

FIXME … do gehds weida! FIXME


1)
Simple Network Management Protocol, aka Security is Not My Problem
Diese Website verwendet Cookies. Durch die Nutzung der Website stimmen Sie dem Speichern von Cookies auf Ihrem Computer zu. Außerdem bestätigen Sie, dass Sie unsere Datenschutzbestimmungen gelesen und verstanden haben. Wenn Sie nicht einverstanden sind, verlassen Sie die Website.Weitere Information
  • centos/web_c7/icinga/snmp.1590932017.txt.gz
  • Zuletzt geändert: 31.05.2020 13:33.
  • von django