
Mein erster Artikel ist mehr oder weniger der Grund des Blogs. Viele werden festgestellt haben, dass man zu Icinga 2, check_nwc_health und die Abfrage von Port Status von Cisco Switchen via SNMPv3 kaum etwas im Internet finden wird.
Hier werde ich euch detailliert und ausführlich zeigen, wie ihr einen Cisco Switch mit Icinga2 und dem check_nwc_health Plugin von ConSol Labs via SNMPv3 abfragen könnt.
Vorbereitung Cisco Switch auf SNMPv3
Cisco SNMPv3 Setup
1. conf t
2. snmp-server group Snmpv3groupname v3 auth
3. snmp-server user Snmpv3user Snmpv3groupname v3 auth sha Snmpv3passwort
Hilfe Commands zur Verifizierung
- show snmp user
- show snmp group
- show snmp engineid
Debian Vorbereitung
Damit Debian Geräte mittels SNMPv3 abfragen kann, müssen noch einige Pakete installiert werden:
1. apt-get install libnet-snmp-perl libcrypt-hcesha-perl libcrypt-des-perl libdigest-hmac-perl libcrypt-rijndael-perl
Installation check_nwc_health von ConSol Labs
Installation Icinga
1. wget http://labs.consol.de/download/shinken-nagios-plugins/check_nwc_health-3.4.2.2.tar.gz
2. tar zxf check_nwc_health-3.4.2.2.tar.gz
3. cd check_nwc_health-3.4.2.2
4. ./configure; make
5. cp plugins-scripts/check_nwc_health $OMD_ROOT/usr/lib/nagios/plugins
Anlegen commands Datei für SNMP Zugriff
1. In das „conf.d“ Verzeichnis wechseln und in das jeweilige Unterverzeichnis in der ihr die „commands“ Datei ablegen wollt.
! Es empfiehlt sich zusätzlich die solche Dateien leicht erkennbar zu machen. Ein möglicher Dateiname könnte commands_network.conf oder commands_snmp.conf lauten
2. Folgende Definition für SNMP v2c und v3 (nach diesem Tutorial reicht aber auch nur v3)
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
|
object CheckCommand "check_nwc_health_2c" { import "plugin-check-command" command = [ PluginDir + "/check_nwc_health" ] arguments = { "-H" = "$check_nwc_health_address$" "--protocol" = "$check_nwc_health_protocol$" "--community" = "$check_nwc_health_community$" "--mode" = "$check_nwc_health_mode$" } vars.check_nwc_health_address = "$address$" vars.check_nwc_health_protocol = "2c" vars.check_nwc_health_community = "snmpv2comname" } object CheckCommand "check_nwc_health_3" { import "plugin-check-command" command = [ PluginDir + "/check_nwc_health" ] arguments = { "-H" = "$check_nwc_health_address$" "--protocol" = "$check_nwc_health_protocol$" "--username" = "$check_nwc_health_username$" "--authpassword" = "$check_nwc_health_authpassword$" "--authprotocol" = "$check_nwc_health_authprotocol$" "--privprotocol" = "$check_nwc_health_privprotocol$" "--privpassword" = "$check_nwc_health_privpassword$" "--mode" = "$check_nwc_health_mode$" "--name" = "$check_nwc_health_name$" } vars.check_nwc_health_address = "$address$" vars.check_nwc_health_protocol = "3" vars.check_nwc_health_username = "snmpv3username" vars.check_nwc_health_authpassword = "snmpv3passwort" vars.check_nwc_health_authprotocol = "sha" vars.check_nwc_health_privprotocol = "aes" vars.check_nwc_health_privpassword = "snmpv3passwort" } |
Erster Test über die Shell
Um zu testen, ob ein SNMPv3 Verbindungsaufbau mit einer Abfrage über check_nwc_health funktioniert, kann man z.B. die Uptime des Cisco Switches via Shell abfragen:
./check_nwc_health –hostname xxx.xxx.xxx.xxx –protocol 3 –username snmpv3username –authpassword snmpv3passwort –authprotocol sha –privprotocol aes –privpassword snmpv3passwort–mode uptime
Entscheidend hierbei ist der Mode (–mode uptime)
Möglich wären z.B. –mode cpu-load / –mode interface-usage –name GigabitEthernet0/48 / –mode hardware-health.
Aus den Readme Dateien zu dem Plugin kann man folgendes entnehmen:
- uptime (Check the uptime of the device)
- hardware-health (Check the status of environmental equipment (fans, temperatures, power))
- cpu-load (Check the CPU load of the device)
- memory-usage (Check the memory usage of the device)
- interface-usage (Check the utilization of interfaces)
- interface-errors (Check the error-rate of interfaces (without discards))
- interface-discards (Check the discard-rate of interfaces)
- interface-status (Check the status of interfaces (oper/admin))
- interface-nat-count-sessions (Count the number of nat sessions)
- interface-nat-rejects (Count the number of nat sessions rejected due to lack of resources)
- list-interfaces (Show the interfaces of the device and update the name cache)
- list-interfaces-detail (Show the interfaces of the device and some details)
- interface-availability (Show the availability (oper != up) of interfaces)
- link-aggregation-availability (Check the percentage of up interfaces in a link aggregation)
- vpn-status (Check the status of vpns (up/down))
- create-shinken-service (Create a Shinken service definition)
- hsrp-state (Check the state in a HSRP group)
- hsrp-failover (Check if a HSRP group’s nodes have changed their roles)
- list-hsrp-groups (Show the HSRP groups configured on this device)
- bgp-peer-status (Check status of BGP peers)
- list-bgp-peers (Show BGP peers known to this device)
- ha-role (Check the role in a ha group)
- svn-status (Check the status of the svn subsystem)
- mngmt-status (Check the status of the management subsystem)
- fw-policy (Check the installed firewall policy)
- fw-connections (Check the number of firewall policy connections)
- session-usage (Check the session limits of a load balancer)
- security-status (Check if there are security-relevant incidents)
- pool-completeness (Check the members of a load balancer pool)
- list-pools (List load balancer pools)
- check-licenses (Check the installed licences/keys)
- count-users (Count the (connected) users/sessions)
- check-config (Check the status of configs (cisco, unsaved config changes))
- check-connections (Check the quality of connections)
- count-connections (Check the number of connections (-client, -server is possible))
- watch-fexes (Check if FEXes appear and disappear (use –lookup))
- accesspoint-status (Check the status of access points)
- count-accesspoints (Check if the number of access points is within a certain range)
- watch-accesspoints (Check if access points appear and disappear (use –lookup))
- list-accesspoints (List access points managed by this device)
- phone-cm-status (Check if the callmanager is up)
- phone-status (Check the number of registered/unregistered/rejected phones)
- list-smart-home-devices (List Fritz!DECT 200 plugs managed by this device)
- smart-home-device-status (Check if a Fritz!DECT 200 plug is on)
- smart-home-device-energy (Show the current power consumption of a Fritz!DECT 200 plug)
- smart-home-device-consumption (Show the cumulated power consumption of a Fritz!DECT 200 plug)
- walk (Show snmpwalk command with the oids necessary for a simulation)
- supportedmibs (Shows the names of the mibs which this devices has implemented (only lausser may run this command))
Anlegen eines Switches
! Es empfiehlt sich eine Struktur aufzubauen, wie z.B. Firma\Gerätegruppe\Gerät (z.B. conf.d\47k\network\switche)
1. Wir erstellen eine File mit dem Namen z.B. 47ksw01.conf
2. Mit folgendem Inhalt.
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
|
object Host "47ksw01" { import "generic-host" display_name = "47ksw01 (Cisco 2960 Access Switch)" address = "10.30.1.1" vars.group = "Switch" vars.groupdf48 = "IDF48" } object Service "GigabitEthernet0/11 - Status" { import "generic-service" host_name = "47ksw01" check_command = "check_nwc_health_3" vars.check_nwc_health_mode = "interface-status" vars.check_nwc_health_name = "GigabitEthernet0/11" } object Service "GigabitEthernet0/11 - Discards " { import "generic-service" host_name = "47ksw01" check_command = "check_nwc_health_3" vars.check_nwc_health_mode = "interface-discards" vars.check_nwc_health_name = "GigabitEthernet0/11" } object Service "GigabitEthernet0/11 - Usage" { import "generic-service" host_name = "47ksw01" check_command = "check_nwc_health_3" vars.check_nwc_health_mode = "interface-usage" vars.check_nwc_health_name = "GigabitEthernet0/11" } object Service "GigabitEthernet0/11 - Errors" { import "generic-service" host_name = "47ksw01" check_command = "check_nwc_health_3" vars.check_nwc_health_mode = "interface-errors" vars.check_nwc_health_name = "GigabitEthernet0/11" } |
Hier wird für den Switch (das Objekt) 47ksw01, mit der IP 10.30.1.1, der Port Status für Port 11 abgefragt. In diesem Fall – Status, Discards, Usage und Errors. Der Switch ist zusätzlich noch in den Gruppen „Switch“ und „IDF48“. Mit der Gruppe „Switch“ können wir eine Gruppierung aller Switche machen. Die Gruppe „IDF48“ (Intermediate Distribution Frame) ist eine Gruppierung für 48 Port Switche, hat aber noch einen anderen Zweck, auf welchen ich gleich noch eingehen werde.
! Um nicht für jeden Gerät Standard Ports (z.B. Uplink) in den Objekten definieren zu müssen, kann man diese auch als Service deklarieren und für Gerätegruppen abfragen.
! Es empfiehlt sich auch hier, wieder diese Dateien leicht erkennbar zu machen – z.B. services_network.conf
Folgender Code wäre z.B. für eine Abfrage der Uptime
|
apply Service "Uptime" { import "generic-service" check_command = "check_nwc_health_3" vars.check_nwc_health_mode = "uptime" assign where host.address && host.vars.group == "Switch" } |
In diesem Fall wird der Befehl bei allen Geräten abgefragt, welche die „vars.group == Switch“ haben.
Und so sieht der Code für die Abfrage eines Uplink Port Status aus:
|
apply Service "GigabitEthernet0/48 - Upl - Status" { import "generic-service" check_command = "check_nwc_health_3" vars.check_nwc_health_mode = "interface-status" vars.check_nwc_health_name = "GigabitEthernet0/48" assign where host.address && host.vars.groupdf48 == "IDF48" && host.vars.group == "Switch" } |
Diesmal bindet er den Befehl an die Gerätegruppe „Switche“ und Gerätegruppe „IDF48“. Geräte mit „IDF24“ (24 Port Switche) sind davon dann nicht betroffen.
Mit der hier eingestellten Anleitung könnt ihr nun beliebige Ports und Modi von Cisco Switchen abfragen und euch somit eure Netzwerküberwachung zusammen stellen.
Solltet ihr noch Fragen oder Anregungen haben, hinterlasst diese bitte als Kommentar, Kontaktiert mich gerne über das Kontaktformular oder via Skype [skype-status].
Bekomme eine fehlermeldung und weiß nicht wie ich das ändern könnte.
root@icinga:/usr/lib/nagios/plugins/check_nwc-health# ./check_nwc_health.pl -hostname x.x.x.x -protocol 3 -username xxxx -authpassword xxxxx mode uptime
./check_nwc_health.pl: Zeile 3: use: Kommando nicht gefunden.
./check_nwc_health.pl: Zeile 4: Syntaxfehler beim unerwarteten Symbol »(«
./check_nwc_health.pl: Zeile 4: `no warnings qw(once);‘
root@icinga:/usr/lib/nagios/plugins/check_nwc-health#
Wo könnte der Fehler liegen. Danke für die Hilfe. Und echt tolles Tut.
Hey Joachim
Danke für das Feedback. Ich habe mir das mal fix angeguckt. Die Anleitung ist ja leider schon ein wenig älter.
Das eigentliche Plugin ist ja „./check_nwc_health“. Bei mir kam nach dem Aufruf (in meiner Testing VM) folgender Fehler:
Can’t locate JSON.pm in @INC (you may need to install the JSON module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.32.1 /usr/local/share/perl/5.32.1 /usr/lib/x86_64-linux-gnu/perl5/5.32 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl-base /usr/lib/x86_64-linux-gnu/perl/5.32 /usr/share/perl/5.32 /usr/local/lib/site_perl) at ./check_nwc_health line 995.
BEGIN failed–compilation aborted at ./check_nwc_health line 995.
Diesen konnte ich wie folgt lösen:
sudo cpan install JSON
Danach gab es immer weitere Meldungen und so musste ich auch folgendes installieren:
sudo cpan File::Slurp module
CPAN (https://www.cpan.org/) muss hierzu natürlich installiert sein. Dann klappt das Plugin auch wieder:
./check_nwc_health ] –mode –hostname –community …]
Usage: check_nwc_health [ -v|–verbose ] [ -t