From eeb662ee2cba3a1387f4e341971d7b26bbab2980 Mon Sep 17 00:00:00 2001 From: darode Date: Tue, 11 Sep 2012 17:45:47 +0000 Subject: [PATCH] 2012-09-11 Dario Rodriguez * util/plugin/iface_bandwith.pl: First version of iface bandwith server plugin. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6959 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 5 ++ pandora_server/util/plugin/iface_bandwith.pl | 89 ++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100755 pandora_server/util/plugin/iface_bandwith.pl diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index b6a5d90c2b..14f7ff4793 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,8 @@ +2012-09-11 Dario Rodriguez + + * util/plugin/iface_bandwith.pl: First version of + iface bandwith server plugin. + 2012-09-11 Miguel de Dios * lib/PandoraFMS/Core.pm: changed to use own code instead the diff --git a/pandora_server/util/plugin/iface_bandwith.pl b/pandora_server/util/plugin/iface_bandwith.pl new file mode 100755 index 0000000000..a65c9e3e38 --- /dev/null +++ b/pandora_server/util/plugin/iface_bandwith.pl @@ -0,0 +1,89 @@ +#!/usr/bin/perl -w + +################################################################################## +# SNMP INTERFACE BANDWITH PLUGIN FOR PANDORA FMS +# (c) Artica Soluciones Tecnologicas, 2012 +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; version 2 +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +################################################################################## + +use strict; +use warnings; + + +sub get_param($) { + my $param = shift; + my $value = undef; + + $param = "-".$param; + + for(my $i=0; $i<$#ARGV; $i++) { + + if ($ARGV[$i] eq $param) { + $value = $ARGV[$i+1]; + last; + } + + } + + return $value; +} + +sub usage () { + print "\nusage: $0 -ip -community -ifname \n"; + print "\nIMPORTANT: This plugin uses SNMP v1\n\n"; +} + +#Global variables +my $ip = get_param("ip"); +my $community = get_param("community"); +my $ifname = get_param("ifname"); + +if (!defined($ip) || + !defined($community) || + !defined($ifname) ) { + usage(); + exit; +} + +#Browse interface name +my $res = `snmpwalk -c $community -v1 $ip .1.3.6.1.2.1.2.2.1.2 -On`; + +my $suffix = undef; + +my @iface_list = split(/\n/, $res); + +foreach my $line (@iface_list) { + + #Parse snmpwalk line + if ($line =~ m/^([\d|\.]+) = STRING: (.*)$/) { + my $aux = $1; + + #Chec if this is the interface requested + if ($2 eq $ifname) { + + my @suffix_array = split(/\./, $aux); + + #Get last number of OID + $suffix = $suffix_array[$#suffix_array]; + } + } +} + +#Check if iface name was found +if (defined($suffix)) { + #Get octets stats + my $inoctets = `snmpget $ip -c $community -v1 .1.3.6.1.2.1.2.2.1.10.$suffix -OUevqt`; + my $outoctets = `snmpget $ip -c $community -v1 .1.3.6.1.2.1.2.2.1.16.$suffix -OUevqt`; + + print $inoctets+$outoctets; +}