[freeside-commits] freeside/FS/FS/NetworkMonitoringSystem Torrus_Internal.pm, 1.4, 1.5

Erik Levinson levinse at wavetail.420.am
Mon Feb 7 15:22:36 PST 2011


Update of /home/cvs/cvsroot/freeside/FS/FS/NetworkMonitoringSystem
In directory wavetail.420.am:/tmp/cvs-serv30791/FS/FS/NetworkMonitoringSystem

Modified Files:
	Torrus_Internal.pm 
Log Message:
torrus, UI, RT10574

Index: Torrus_Internal.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -d -r1.4 -r1.5
--- Torrus_Internal.pm	7 Feb 2011 05:20:41 -0000	1.4
+++ Torrus_Internal.pm	7 Feb 2011 23:22:33 -0000	1.5
@@ -9,6 +9,7 @@
 use XML::Simple;
 use FS::svc_port;
 use FS::Record qw(qsearch);
+use Torrus::ConfigTree;
 
 #$DEBUG = 0;
 #$me = '[FS::NetworkMonitoringSystem::Torrus_Internal]';
@@ -24,20 +25,26 @@
     return $self;
 }
 
-sub get_router_serviceids {
+sub ddx2hash {
     my $self = shift;
-    my $router = shift;
-
     my $ddx_xml = slurp($ddxfile);
     my $xs = new XML::Simple(RootName=> undef, SuppressEmpty => '', 
 				ForceArray => 1, );
-    my $ddx_hash = $xs->XMLin($ddx_xml);
+    return $xs->XMLin($ddx_xml);
+}
+
+sub get_router_serviceids {
+    my $self = shift;
+    my $router = shift;
+    my $find_serviceid = shift;
+    my $found_serviceid = 0;
+    my $ddx_hash = $self->ddx2hash;
     if($ddx_hash->{host}){
 	my @hosts = @{$ddx_hash->{host}};
 	foreach my $host ( @hosts ) {
 	    my $param = $host->{param};
 	    if($param && $param->{'snmp-host'} 
-		      && $param->{'snmp-host'}->{'value'} eq $router
+		      && (!$router || $param->{'snmp-host'}->{'value'} eq $router)
 		      && $param->{'RFC2863_IF_MIB::external-serviceid'}) {
 		my $serviceids = $param->{'RFC2863_IF_MIB::external-serviceid'}->{'content'};
 		my %hash = ();
@@ -47,16 +54,33 @@
 			$serviceid =~ s/^\s+|\s+$//g;
 			my @s = split(':',$serviceid);
 			next unless scalar(@s) == 4;
-			$hash{$s[1]} = $s[0];
+			$hash{$s[1]} = $s[0] if $router;
+			if ($find_serviceid && $find_serviceid eq $s[0]) {
+			    $hash{$param->{'snmp-host'}->{'value'}} = $s[1];
+			    $found_serviceid = 1;
 		    }
 		}
-		return \%hash;
+		}
+		return \%hash if ($router || $found_serviceid);
 	    }
 	}
     }
     '';
 }
 
+sub port_graphs_link {
+    # hardcoded for 'main' tree for now 
+    my $self = shift;
+    my $serviceid = shift;
+    my $hash = $self->get_router_serviceids(undef,$serviceid);
+    my @keys = keys %$hash; # yeah this is weird...
+    my $host = $keys[0];
+    my $iface = $hash->{$keys[0]};
+    my $config_tree = new Torrus::ConfigTree( -TreeName => 'main' );
+    my $token = $config_tree->token("/Routers/$host/Interface_Counters/$iface/InOut_bps");
+    return $Torrus::Freeside::FSURL."/torrus/main?token=$token";
+}
+
 sub find_svc {
     my $self = shift;
     my $serviceid = shift;



More information about the freeside-commits mailing list