diff --git a/plugins/other/dell_temps b/plugins/other/dell_temps index 1fb50507..d5690e1c 100755 --- a/plugins/other/dell_temps +++ b/plugins/other/dell_temps @@ -1,139 +1,106 @@ -#!/usr/bin/env python -""" -USAGE - - dell_changeme [config] [autoconfig] - - Copy script to two files: dell_fans and dell_temps. - Example: cat dell_changeme | tee dell_fans > dell_temps - -DESCRIPTION - - A Munin plugin to graph the fan speeds and chassis temperatures of Dell - hardware. Requires Dell's OpenManage software, specifically omreport. OMSA - services must be started prior to plugins use. Script expects omreport to - be in /usr/sbin/, you may need to add a symlink. - - omreport accesses the proc filesystem and as such this plugin must be ran - as root. Alternatively, you could modify script to use sudoers, or setuid. - - To run script as root add the following lines to munin's plugin-conf.d dir. - - [dell*] - user root - group root - - Troubleshooting info: http://www.ryanbowlby.com/infotech/munin-plugin-dell/ - -AUTHOR - - Ryan Bowlby - -LICENSE - - This script is in the public domain, free from copyrights or restrictions. -""" -# Magic markers (optional) - used by munin-node-configure: +#!/usr/bin/perl -w # +# Plugin to monitor BGP table summary statistics on a cisco router. +# +# Original Author: Peter Holzleitner +# +# Revision 1.1 2010/10/14 19:19 +# +# Configuration variables: +# +# iosuser - username (default "") +# iospass - password (default "") +# +# Parameters: +# +# config (required) +# +# Magic markers (optional - only used by munin-config and some +# installation scripts): #%# family=auto -#%# capabilities=autoconf - -import sys -import subprocess as sp - -class Statistics(object): - """A base class that runs omreport and prints the filtered results.""" - - def __init__(self, command): - self.command = command.split() - self.data = sp.Popen(self.command,stdout=sp.PIPE).stdout.readlines() - self.count = 0 - # Make sure omreport returns at least one sensor block. - for item in self.data: - if item.startswith("Probe Name") or item.startswith("Reading"): - self.count += 1 - if self.count < 2: - raise ValueError("No output from omreport. Is OMSA running?") - - def print_omreport_results(self): - """Prints names and values for each sensor.""" - self.count = 0 - for item in self.data: - if "Reading" in item: - # Extract variable length integer. - self.value = float(item.split(":")[1].split()[0]) - print "%s_%s.value %s" % (self.command[-1], self.count, self.value) - self.count += 1 - - def print_config_dynamic(self): - """Prints Munin config data with "label" values from omreport data.""" - self.name = [] - for item in self.data: - if "Probe Name" in item: - self.name.append(item.split(":")[1].replace("RPM","").strip()) - for index, item in enumerate(self.name): - print "%s_%s.label %s" % (self.command[-1], index, item) -class FanSpeed(Statistics): - """A subclass that includes the Munin "config" output.""" - - def __init__(self, command): - Statistics.__init__(self, command) - - def print_config(self): - print "graph_title Dell Fan Speeds" - print "graph_args --base 1000 -l 0" - print "graph_vlabel speed (RPM)" - print "graph_category Chassis" - print "graph_info This graph shows the speed in RPM of all fans." - print "graph_period second" - # Print remaining non-static values. - self.print_config_dynamic() +use Net::Telnet::Cisco; +use Sys::Syslog; -class ChassisTemps(Statistics): - """A subclass that includes the Munin "config" output.""" +if ($0 =~ /^(?:|.*\/)cisco_bgp_([^_]+)$/) { + $host = $1; + } - def __init__(self, command): - Statistics.__init__(self, command) - - def print_config(self): - print "graph_title Dell Temperature Readings" - print "graph_args --base 1000 -l 0" - print "graph_vlabel Temp in Degrees Celsius" - print "graph_category Chassis" - print "graph_info This graph shows the temperature for all sensors." - print "graph_period second" - # Print remaining non-static values. - self.print_config_dynamic() +($^O eq "linux" || $^O eq "openbsd") && Sys::Syslog::setlogsock('unix'); +openlog('munin.bgp', 'cons,pid', 'daemon'); -if __name__ == '__main__': - try: - if "fans" in sys.argv[0]: - cmd = "/usr/sbin/omreport chassis fans" - omdata = FanSpeed(cmd) - elif "temps" in sys.argv[0]: - cmd = "/usr/sbin/omreport chassis temps" - omdata = ChassisTemps(cmd) - else: - print >> sys.stderr, "Change filename to dell_fans or dell_temps." - sys.exit(1) - except (OSError, ValueError), e: - # omreport returns 0 results if OMSA services aren't started. - print >> sys.stderr, "Error running '%s', %s" % (cmd, e) - sys.exit(1) +my @BGP_nbr; +my @BGP_pfx; +my $tot_pfx; +my $iosuser = $ENV{iosuser} || ""; +my $iospass = $ENV{iospass} || ""; - # Munin populates sys.argv[1] with "" (an empty argument), let's remove it. - sys.argv = [x for x in sys.argv if x] +&fetch_bgpstats($host, $iosuser, $iospass); - if len(sys.argv) > 1: - if sys.argv[1].lower() == "autoconf": - # omreport ran earlier, since we got this far autoconf is good. - print "true" - elif sys.argv[1].lower() == "config": - omdata.print_config() - else: - omdata.print_omreport_results() +if ($ARGV[0] and $ARGV[0] eq "config") { + print "host_name $host\n"; + print "graph_args --base 1024 -l 0 --vertical-label Prefixes\n"; + print "graph_title BGP Neighbour Statistics\n"; + print "graph_category network\n"; + print "graph_info This graph shows the number of BGP prefixes received by neighbour.\n"; + + my($n, $i); $n = scalar @BGP_nbr; $i = 0; + while($n--) { + my $neigh = $BGP_nbr[$i++]; + print "n$i.label $neigh\n"; + } + +# print "total.label Total\n"; +# print "total.info Total number of prefixes in the BGP table\n"; + + } else { + + my($n, $i); $n = scalar @BGP_nbr; $i = 0; + while($n--) { + my $pfx = $BGP_pfx[$i++]; + print "n$i.value $pfx\n"; + } +# print "total.value $tot_pfx\n"; + } + + + + +sub fetch_bgpstats + { + my $hostname = shift; + my $username = shift; + my $password = shift; + my $session = Net::Telnet::Cisco->new(Host => $host); + + $session->login($username, $password); + $session->cmd('terminal length 200'); + $session->cmd('terminal width 200'); + my @output = $session->cmd('show ip bgp summary'); + +# example output of router +# ------------------------ +# [...] +# Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd +# 11.111.11.111 4 98765 12403694 509571 308911893 0 0 1d23h 329193 +# 122.122.122.122 4 1234 13242856 383827 308911879 0 0 00:08:22 330761 + + foreach(@output) { + chomp; s/\r//g; + $tot_pfx = $1 if /^BGP activity (\d+)\/(\d+) prefixes/; + syslog('debug', "$hostname: $_\n"); + + next unless /^(\d+\.\d+\.\d+\.\d+)\s+\d+\s+(\d+)\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+[0-9a-z:]+\s+(\d+)/; + my ($neigh, $as, $pfx) = ($1, $2, $3); + syslog('debug', "$neigh (AS $as)"); + push @BGP_nbr, "$neigh (AS $as)"; + push @BGP_pfx, $pfx; + } + } + + +# vim:syntax=perl:ts=8