1
0

- renamed to monitoring-plugins-bonding

- specfile cleanup
- added apparmor profile
- recommend apparmor-profiles
- fix license (GPL or Artistic) 

- use nagios-rpm-macros

- initial version 0.002

OBS-URL: https://build.opensuse.org/package/show/server:monitoring/monitoring-plugins-bonding?expand=0&rev=2
This commit is contained in:
Lars Vogdt 2014-07-30 14:55:47 +00:00 committed by Git OBS Bridge
commit 21070aa67a
6 changed files with 247 additions and 0 deletions

23
.gitattributes vendored Normal file
View File

@ -0,0 +1,23 @@
## Default LFS
*.7z filter=lfs diff=lfs merge=lfs -text
*.bsp filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.gem filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.jar filter=lfs diff=lfs merge=lfs -text
*.lz filter=lfs diff=lfs merge=lfs -text
*.lzma filter=lfs diff=lfs merge=lfs -text
*.obscpio filter=lfs diff=lfs merge=lfs -text
*.oxt filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.rpm filter=lfs diff=lfs merge=lfs -text
*.tbz filter=lfs diff=lfs merge=lfs -text
*.tbz2 filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.txz filter=lfs diff=lfs merge=lfs -text
*.whl filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.osc

125
check_bonding.pl Normal file
View File

@ -0,0 +1,125 @@
#!/usr/bin/perl
use warnings;
use strict;
use Getopt::Long;
my $VERSION = '0.002';
my $options = {
'procnet' => '/proc/net',
};
sub version {
print "$VERSION\n";
}
sub help {
my $name = $1 if $0 =~ /\/([^\/]+)$/;
print <<FOO;
$name [ --procnet <dir> ] [ --hel p ] [ --version ]
--procnet <dir> - Direcotry where proc/net lives, normally /proc/net
--help - help (this screen)
--version - get version information
This script attempts to read the proc interface to the Linux kernel bonding driver, and
determine if the bonded interfaces are optimal. It will wanr if any of the enslaved devices
are not 'up' (exit 1), and if any bonded interfaces are not active at all (exit 2). This
script is suitable for feeding to NRPE for Nagios (or similar) to check.
This script is distributed under the Artistic and Gnu Public Licences.
Version: $VERSION.
(c) 2004 Fotango Limited. http://opensource.fotango.com/.
Written by James Bromberger <jbromberger_AT_fotango.com>
FOO
}
sub read_proc_bond {
my $file = shift;
return unless -r $file;
open F, $file or die "Cannot read $file";
my $data;
while (<F>) {
$data->{'version'} = $1 if /^Ethernet Channel Bonding Driver: (.+)$/;
$data->{'mode'} = $1 if /^Bonding Mode: (.+)$/;
$data->{'primary'} = $1 if /^Primary Slave: (.+)$/;
$data->{'active'} = $1 if /^Currently Active Slave: (.+)$/;
$data->{'status'} = $1 if /^MII Status: (\S+)$/;
$data->{'polling'} = $1 if /^MII Polling Interval \(ms\): (\S+)$/;
$data->{'up-delay'} = $1 if /^Up Delay \(ms\): (\S+)$/;
$data->{'down-delay'} = $1 if /^Down Delay \(ms\): (\S+)$/;
if (/^Slave Interface: (.+)$/) {
my $slave = $1;
while (($_ = <F>||"") !~ /^$/) {
$data->{'slaves'}->{$slave}->{'mii'} = $1 if /^MII Status: (.+)$/;
$data->{'slaves'}->{$slave}->{'failure-count'} = $1 if /^Link Failure Count: (.+)$/;
}
}
}
close F;
return $data;
}
sub check_bond {
my $file = shift;
my $interface_name = shift;
my $data = read_proc_bond($file);
return (0, "Unable to read bond information") unless $data;
my $error = 0;
my $config_str;
if (defined $data->{'active'}) {
$config_str = sprintf "$interface_name %s on %s: members =", $data->{'status'}, $data->{'active'} ;
} elsif (defined $data->{'slaves'}) {
$config_str = sprintf "$interface_name %s: members =", $data->{'status'};
} else {
$config_str = sprintf "$interface_name %s has no physical devices", $data->{'status'};
$error = 1;
}
foreach (keys %{$data->{'slaves'}}) {
$config_str.= " $_ (" . $data->{'slaves'}->{$_}->{'mii'} . ")";
$error = 1 unless $data->{'slaves'}->{$_}->{'mii'} eq 'up';
$error = 2 if ($data->{'status'} ne 'up');
}
return $error, $config_str;
}
sub find_bonds {
my $dir = shift;
return unless -r $dir;
# $dir = '/proc/net';
my $bonds;
if (-r "$dir/bonding") {
opendir D, "$dir/bonding" or die "Cannot open dir: $dir/bonding";
map {$bonds->{$_} = "$dir/bonding/$_"} grep /^bond/, readdir D;
closedir D;
}
opendir D, "$dir" or die "Cannot open dir: $dir";
map {$bonds->{$_} = "$dir/$_/info" if -r "$dir/$_/info"} grep /^bond/, readdir D;
closedir D;
my $err = 0;
my $message;
foreach (keys %{$bonds}) {
my ($this_error, $this_message) = check_bond($bonds->{$_}, $_);
$err = $this_error if $this_error;
$message.= $this_message . " ";
}
if (not $message) {
$message = "No bond information found";
$err = 1;
}
print "$message\n";
exit $err;
}
GetOptions($options, "procnet=s", "help", "version");
if(defined $options->{'help'}) {
help();
exit;
}
elsif (defined $options->{'version'}) {
version();
exit;
}
find_bonds($options->{'procnet'});

View File

@ -0,0 +1,23 @@
-------------------------------------------------------------------
Wed Jul 30 14:55:33 UTC 2014 - lars@linux-schulserver.de
- renamed to monitoring-plugins-bonding
-------------------------------------------------------------------
Wed Jul 4 21:29:19 UTC 2012 - lars@linux-schulserver.de
- specfile cleanup
- added apparmor profile
- recommend apparmor-profiles
- fix license (GPL or Artistic)
-------------------------------------------------------------------
Sun May 6 01:24:55 UTC 2012 - lars@linux-schulserver.de
- use nagios-rpm-macros
-------------------------------------------------------------------
Fri Mar 12 15:22:59 UTC 2010 - lars@linux-schulserver.de
- initial version 0.002

View File

@ -0,0 +1,63 @@
#
# spec file for package monitoring-plugins-bonding
#
# Copyright (c) 2012-2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
Name: monitoring-plugins-bonding
Version: 0.002
Release: 100
License: GPL-2.0+ or Artistic-1.0
Summary: Nagios Network Bonding Check
Url: http://www.monitoringexchange.org/inventory/Check-Plugins/Operating-Systems/Linux/Network-Bonding
Group: System/Monitoring
Source0: check_bonding.pl
Source1: usr.lib.nagios.plugins.check_bonding
Provides: nagios-plugins-bonding = %{version}-%{release}
Obsoletes: nagios-plugins-bonding < %{version}-%{release}
BuildRequires: nagios-rpm-macros
Recommends: apparmor-profiles
# nagios can execute the script with embedded perl
Recommends: perl
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildArch: noarch
%description
This script attempts to read the proc interface to the Linux kernel bonding
driver, and determine if the bonded interfaces are optimal. It will warn if any
of the enslaved devices are not 'up' (exit 1), and if any bonded interfaces are
not active at all (exit 2). This script is suitable for feeding to NRPE for
Nagios (or similar) to check.
%prep
%build
%install
install -D -m755 %{SOURCE0} %{buildroot}%{nagios_plugindir}/check_bonding
install -D -m644 %{SOURCE1} %{buildroot}%{_sysconfdir}/apparmor.d/usr.lib.nagios.plugins.check_bonding
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root)
# avoid build dependecy of nagios - own the dirs
%dir %{nagios_libdir}
%dir %{nagios_plugindir}
%{nagios_plugindir}/check_bonding
%dir %{_sysconfdir}/apparmor.d
%config(noreplace) %{_sysconfdir}/apparmor.d/usr.lib.nagios.plugins.check_bonding
%changelog

View File

@ -0,0 +1,12 @@
#include <tunables/global>
/usr/lib/nagios/plugins/check_bonding {
#include <abstractions/base>
#include <abstractions/perl>
/proc/*/net/ r,
/proc/*/net/bonding/ r,
/proc/*/net/bonding/* r,
/usr/bin/perl ix,
}