Code Monkey home page Code Monkey logo

check_iftraffic_nrpe.py's People

Contributors

hgrohne-cygnusnetworks-de avatar le9i0nx avatar samk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

check_iftraffic_nrpe.py's Issues

--interfaces not working

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)
             """ 

Output of interface with current traffic if critical or warning

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!

Exception when parsing empty file

# 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

Wrong data after reboot

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.

Python 2.4 compatibility

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

Traffic MBps CRITICAL: Cannot write in /var/tmp/traffic_stats.dat ?

Hi

I've tried to set up check_iftraffic_nrpe.py this way

  1. In /usr/lib/nagios/plugins/ added:
wget https://raw.githubusercontent.com/SamK/check_iftraffic_nrpe.py/master/check_iftraffic_nrpe.py
  1. In 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
  1. Test/restart:
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)

  1. On MyNagiosServer:

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?

perfdata should not end with c

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;' \

Wrong estimation of maximum value of max_counter() on 32 bits machines.

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.

Clarify license

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.

nrpe perfdata not consistent with python3

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.

unsupported operand type(s) for /

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

Specifying warn and critical

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

warning or critical is not working for me

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.