#!/usr/bin/env python # # Plugin created for capturing RX and TX statistics from Linux OS # interfaces. # Useful to analyze package tendencies, such as total transfered, # dropped, framed and overrun packets. This plugin follows a very # simple approach and outputs a nagios formatted metric syntax for # chart creation. # # IMPORTANT: This script relies on `ifconfig` command, so soon it # will be outdated but I hope to rewrite using a better replacement # like ethtool or ip. # # To better explain the output: # # - RX: Received packets # - TX: Transfered packets # - errors: Packets which could not be transfered/received due # errors # - dropped: Normally indicates configuration/communication # errors (eg: One side operating in half-duplex and the other # in full-duplex) # - overruns: The interface has two buffers, one for transmit # and the other one for receive and when one of these buffers # reachs its limit the surplus packets are discarted as # 'overrruns' # - frame: Malformed frames # - carrier: Physical link error. Very common in HUBS, should not # never occur with switch environments. # # Usage: check_rx_tx.py # # Author: Marcelo Varge # (marcelo.varge@gmail.com) # # import sys from commands import getoutput # Usage/Help: def usage(): print "Usage: %s " % (sys.argv[0]) sys.exit(-1) # Check received parameters: if (len(sys.argv) < 2) or (sys.argv[1].lower() == "-h"): usage() # Variable/Constants definitions interface = sys.argv[1] capture = ('RX packets', 'TX packets', ) format = [] final = [] # Capture output: out = getoutput("ifconfig %s" % interface) if "Device not found" in out: print out sys.exit(-1) for line in out.splitlines(): for opt in capture: if opt in line: format.append(line.split()) # Format final output: for line in format: name = line.pop(0) for opt in line: temp = opt.split(':') final.append(name + '_' + temp[0] + '=' + temp[1]) # Print output for nagios metrics print "OK | " + ';'.join(final) sys.exit(0)