mirror of
https://github.com/opinkerfi/nagios-plugins.git
synced 2024-11-22 10:23:46 +01:00
Added okc-get_network_stat
This commit is contained in:
parent
e7af0e4098
commit
37d504a039
43
okc-get_network_stat/nagios-okplugin-get_network_stat.spec
Normal file
43
okc-get_network_stat/nagios-okplugin-get_network_stat.spec
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
%define debug_package %{nil}
|
||||||
|
|
||||||
|
Summary: A Nagios plugin to get network statistics over NRPE
|
||||||
|
Name: nagios-okplugin-get_network_stat
|
||||||
|
Version: 1.0.0
|
||||||
|
Release: 1%{?dist}
|
||||||
|
License: GPLv2+
|
||||||
|
Group: Applications/System
|
||||||
|
URL: https://github.com/opinkerfi/nagios-plugins/okc-get_network_stat
|
||||||
|
Source0: https://github.com/opinkerfi/nagios-plugins/okc-get_network_stat/%{name}-%{version}.tar.gz
|
||||||
|
Requires: nagios-plugins-nrpe
|
||||||
|
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
||||||
|
Packager: Tomas Edwardsson <tommi@tommi.org>
|
||||||
|
BuildArch: noarch
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%description
|
||||||
|
A Nagios plugin to get network statistics over NRPE
|
||||||
|
|
||||||
|
|
||||||
|
%prep
|
||||||
|
%setup -q
|
||||||
|
|
||||||
|
%build
|
||||||
|
|
||||||
|
|
||||||
|
%install
|
||||||
|
rm -rf %{buildroot}
|
||||||
|
install -D -p -m 0755 okc-get_network_stat %{buildroot}%{_libdir}/nagios/plugins/okc-get_network_stat
|
||||||
|
|
||||||
|
%clean
|
||||||
|
rm -rf %{buildroot}
|
||||||
|
|
||||||
|
%files
|
||||||
|
%defattr(-,root,root,-)
|
||||||
|
#%doc README LICENSE
|
||||||
|
#%{_libdir}/nagios/plugins/*
|
||||||
|
%{_libdir}/nagios/plugins/okc-get_network_stat
|
||||||
|
|
||||||
|
%changelog
|
||||||
|
* Wed Apr 2 2014 Tomas Edwardsson <tommi@tommi.org> 1.0.0-1
|
||||||
|
- Initial release
|
65
okc-get_network_stat/okc-get_network_stat
Normal file
65
okc-get_network_stat/okc-get_network_stat
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
from pynag.Plugins import PluginHelper, ok, warning, critical, unknown
|
||||||
|
from pynag.Utils import runCommand
|
||||||
|
import re
|
||||||
|
|
||||||
|
helper = PluginHelper()
|
||||||
|
|
||||||
|
helper.parser.add_option("-H", help="Host to connect to", dest="host", default='localhost')
|
||||||
|
|
||||||
|
helper.parse_arguments()
|
||||||
|
|
||||||
|
if helper.options.host == "localhost":
|
||||||
|
command="cat /proc/net/dev|sed 's/ */ /g'"
|
||||||
|
else:
|
||||||
|
command="/usr/lib64/nagios/plugins/check_nrpe -H '%s' -c get_network_interfaces" % helper.options.host
|
||||||
|
|
||||||
|
return_code, stdout, stderr = runCommand(command)
|
||||||
|
|
||||||
|
try:
|
||||||
|
receive, transmit = stdout.split("\n")[1].split("|")[1:]
|
||||||
|
receive = receive.split()
|
||||||
|
transmit = transmit.split()
|
||||||
|
|
||||||
|
interfaces = []
|
||||||
|
|
||||||
|
for int_line in stdout.split("\n")[2:]:
|
||||||
|
int_line = int_line.strip()
|
||||||
|
if not int_line:
|
||||||
|
continue
|
||||||
|
|
||||||
|
int_arr = re.split("[: ]+", int_line.strip())
|
||||||
|
|
||||||
|
interface = int_arr.pop(0)
|
||||||
|
|
||||||
|
if interface == "lo" or interface.startswith('sit'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
interfaces.append(interface)
|
||||||
|
for i in range(0, len(receive)):
|
||||||
|
helper.add_metric(
|
||||||
|
label="%s_rx_%s" % (interface, receive[i]),
|
||||||
|
value=int_arr.pop(0),
|
||||||
|
uom="c")
|
||||||
|
for i in range(0, len(transmit)):
|
||||||
|
helper.add_metric(
|
||||||
|
label="%s_tx_%s" % (interface, transmit[i]),
|
||||||
|
value=int_arr.pop(0),
|
||||||
|
uom="c")
|
||||||
|
|
||||||
|
helper.add_summary("Network interfaces %s" % ", ".join(interfaces))
|
||||||
|
|
||||||
|
# Here all metrics will be checked against thresholds that are either
|
||||||
|
# built-in or added via --threshold from the command-line
|
||||||
|
helper.check_all_metrics()
|
||||||
|
|
||||||
|
# Print out plugin information and exit nagios-style
|
||||||
|
helper.exit(ok)
|
||||||
|
except Exception, error:
|
||||||
|
helper.status(unknown)
|
||||||
|
helper.add_summary(stdout + stderr)
|
||||||
|
helper.exit(unknown)
|
||||||
|
|
||||||
|
# vim: sts=4 expandtab autoindent
|
||||||
|
|
Loading…
Reference in New Issue
Block a user