samk / check_iftraffic_nrpe.py Goto Github PK
View Code? Open in Web Editor NEWNagios plugin to check network traffic with NRPE
License: GNU General Public License v3.0
Nagios plugin to check network traffic with NRPE
License: GNU General Public License v3.0
I should probably rather learn how to submit patches to github! In the meatime here is suggestion:
--- check_iftraffic_nrpe.py.origin 2012-11-21 17:08:46.000000000 +0100
+++ /usr/local/nagios/plugins/check_iftraffic_nrpe.py 2012-11-21 18:21:15.000000000 +0100
@@ -161,13 +161,10 @@
def specify_device(devices, data):
"""Remove the devices not included by the user"""
- data2 = dict()
- for i in devices:
- if i in data:
- data2[i] = data[i]
- else:
- raise DeviceError("Device %s not found." % i)
- data = data2
+ datatmp = data.copy()
+ for i in datatmp:
+ if not i in devices:
+ del data[i]
def parse_arguments():
@@ -244,7 +241,7 @@
# only keep the wanted interfaces if specified
if args.interfaces:
try:
- specify_interfaces(args.interfaces, traffic)
+ specify_device(args.interfaces, traffic)
except DeviceError as e:
message = str(e).replace("'", "")
problems.append(message)
@@ -289,8 +286,8 @@
(warn level);(crit level);(min level);(max level)
"""
Hello again,
is there any possibility to add the interface with its current traffic to the output while triggering warning or critical to recognize faster which interface is at its limit?
I tried myself to add it but my python skills are a mess so I would appreciate this feature! :)
Thanks a lot for this nice traffic check!
The main() function is too large!
# python --version
Python 2.7.3
# touch tempfile
# ./check_iftraffic_nrpe.py -f tempfile
Traceback (most recent call last):
File "./check_iftraffic_nrpe.py", line 627, in <module>
main(default_values)
File "./check_iftraffic_nrpe.py", line 497, in main
uptime0, procnetdev0 = datafile.read()
File "./check_iftraffic_nrpe.py", line 125, in read
self.uptime = float(content[0])
IndexError: list index out of range
Because I'm tired of calculating.
The script does not detect if the server has rebooted. It thinks the max value has reached and the counter reset.
Because of this the script calculates wrong data during the first check after the reboot.
please fix that or change the compatibility info.
# ./check_iftraffic_nrpe.py
File "./check_iftraffic_nrpe.py", line 132
with open('/proc/uptime', 'r') as f:
^
SyntaxError: invalid syntax
# python -V
Python 2.4.3
# uname -a
Linux SRV30 2.6.32.43-0.4.1.xs1.8.0.847.170785xen #1 SMP Thu Nov 14 13:49:56 EST 2013 i686 i686 i386 GNU/Linux
# cat /etc/issue
Citrix XenServer Host 6.2.0-70446c
Hi
I've tried to set up check_iftraffic_nrpe.py this way
/usr/lib/nagios/plugins/
added:wget https://raw.githubusercontent.com/SamK/check_iftraffic_nrpe.py/master/check_iftraffic_nrpe.py
vi /etc/nagios/nrpe.cfg
added:command[check_traffic]=/usr/lib/nagios/plugins/check_iftraffic_nrpe.py -u MBps -i eth0 -b 2 -w 50 -c 80
chmod +x /usr/lib/nagios/plugins/check_iftraffic_nrpe.py
/usr/lib/nagios/plugins//check_iftraffic_nrpe.py -x lo
service nagios-nrpe-server restart
(/usr/lib/nagios/plugins//check_iftraffic_nrpe.py -x lo
works)
In /etc/nagios3/conf.d/server.cfg
added:
define service {
use generic-service
host_name MonitoredServerName
service_description Net Traffic
check_command check_nrpe_1arg!check_traffic
}
service nagios3 restart
Problem: Nagios says Traffic MBps CRITICAL: Cannot write in /var/tmp/traffic_stats.dat.
Is
root@MyMonitoredServer:/var/tmp# ls -la
total 12
drwxrwxrwt 2 root root 4096 Apr 30 16:40 .
drwxr-xr-x 13 root root 4096 Dec 14 02:44 ..
-rw-r--r-- 1 root root 712 Apr 30 16:28 traffic_stats.dat
not enough?
I'm not sure at all about the accuracy of this function.
I must try if the value is right, at least on a 32 bits system.
because I should allow the "long" type as well.
I had to patch as follows to get graphs to show up in Icinga Classic UI 1.11.5 (Backend 1.11.5). Am I missing something, or is this a bug?
diff --git a/check_iftraffic_nrpe.py b/check_iftraffic_nrpe.py
index f8a14d0..b7d281a 100755
--- a/check_iftraffic_nrpe.py
+++ b/check_iftraffic_nrpe.py
@@ -250,7 +250,7 @@ class NagiosService(object):
def __str__(self):
"""Return the perfdata string"""
- return '%(label)s=%(value).2fc;' \
+ return '%(label)s=%(value).2f;' \
'%(warn_level)s;' \
'%(crit_level)s;' \
'%(min_level)s;' \
max_counter()
uses sys.maxsize
to determine the max value given by /proc/dev/net
.
max_counter()
uses sys.maxsize
(returns max value of a signed integer).
I think /proc/net/dev uses unsigned integers.
but sys.maxsize returns the maximum value of a signed integer.
Proof: On a 32 bits machine, I see a value of 4'292'379'652 in this file which is bigger than sys.maxsize.
Currently the plugin has not declaration of license whatsoever. As such in most jurisdictions it defaults to "All rights reserved", so this software is not redistributable (other than forking on github by using the implicit grant from the TOS). check_iftraffic_nrpe.py therefore is not considered as free software when applying the definitions from the Free Software Foundation or the Debian Free Software Guidelines.
In python3, dictionary iteration is not consistent. This leads to icinga+pnp4nagios associating values incorrectly as it relies on consistent ordering in the perfdata.
Typical workarounds are to pass the call to .items() through sorted or to use OrderedDict which tracks the order items are inserted.
Because all this code is starting to be complicated I created a branch called "classes".
This has to be done sooner or later.
Create Unit tests including
For some reason it doesn't work as expected on Debian/Squeeze (python 2.6):
.# ./check_iftraffic_nrpe.py --bandwidth=131072000
Traceback (most recent call last):
File "./check_iftraffic_nrpe.py", line 310, in <module>
main()
File "./check_iftraffic_nrpe.py", line 273, in main
args.critical, args.warning)
File "./check_iftraffic_nrpe.py", line 78, in nagios_value_status
if value > percent_crit * (max_value / 100):
TypeError: unsupported operand type(s) for /: 'str' and 'int'
Fix is of course easy:
--- check_iftraffic_nrpe.py.origin 2012-11-21 17:08:46.000000000 +0100
+++ check_iftraffic_nrpe.py 2012-11-21 17:09:10.000000000 +0100
@@ -218,7 +218,7 @@
data_file = '/var/tmp/traffic_stats.dat'
args = parse_arguments()
- bandwidth = args.bandwidth
+ bandwidth = int(args.bandwidth)
problems = []
# capture all the data from the system
because barrypitman asks for it in #2.
Still with Debian/Squeeze and python 2.6, it is necessary to cast variable into integer:
--- check_iftraffic_nrpe.py.origin 2012-11-21 17:08:46.000000000 +0100
+++ /usr/local/nagios/plugins/check_iftraffic_nrpe.py 2012-11-21 18:21:15.000000000 +0100
@@ -289,8 +286,8 @@
(warn level);(crit level);(min level);(max level)
"""
- warn_level = args.warning * (bandwidth / 100)
- crit_level = args.critical * (bandwidth / 100)
+ warn_level = int(args.warning) * (bandwidth / 100)
+ crit_level = int(args.critical) * (bandwidth / 100)
min_level = 0.0
max_level = bandwidth
HTH
Hey guys,
at first thanks a lot for this fantastic script. The output is great and also the fact to receive data for all interfaces is really nice.
Unfortunately I'm not getting warning or critical to work:
I'm trying the following command:
./check_iftraffic_nrpe.py -x lo -u Mbps -w 20 -c 40 -b 100
Traffic Mbps OK | in-eth0=98.0;20.0;40.0;0;100.0 out-eth0=2.4;20.0;40.0;0;100.0
echo $?
0
In my opinion the downgraded warning and critical values should trigger and the output should be something else and also the return code.
Am I doing anything wrong? Would be great to get this awesome script working completly like it's intended!
Thanks a lot and cheers
marzel
I should be able to specify an alternate data file.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.