projects
/
freeside.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
omit due date option, RT#73002
[freeside.git]
/
FS
/
FS
/
NetworkMonitoringSystem
/
Torrus_Internal.pm
diff --git
a/FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm
b/FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm
index
f436e3b
..
28bc8a7
100644
(file)
--- a/
FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm
+++ b/
FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm
@@
-5,13
+5,14
@@
use strict;
use Fcntl qw(:flock);
use IO::File;
use File::Slurp qw(slurp);
use Fcntl qw(:flock);
use IO::File;
use File::Slurp qw(slurp);
+use IPC::Run qw(run);
use Date::Format;
use XML::Simple;
use FS::Record qw(qsearch qsearchs dbh);
use FS::svc_port;
use FS::torrus_srvderive;
use FS::torrus_srvderive_component;
use Date::Format;
use XML::Simple;
use FS::Record qw(qsearch qsearchs dbh);
use FS::svc_port;
use FS::torrus_srvderive;
use FS::torrus_srvderive_component;
-use Torrus::ConfigTree;
+
#
use Torrus::ConfigTree;
#$DEBUG = 0;
#$me = '[FS::NetworkMonitoringSystem::Torrus_Internal]';
#$DEBUG = 0;
#$me = '[FS::NetworkMonitoringSystem::Torrus_Internal]';
@@
-108,6
+109,11
@@
sub port_graphs_link {
my @keys = keys %$hash; # yeah this is weird...
my $host = $keys[0];
my $iface = $hash->{$keys[0]};
my @keys = keys %$hash; # yeah this is weird...
my $host = $keys[0];
my $iface = $hash->{$keys[0]};
+
+ #Torrus::ConfigTree is only available when running under the web UI
+ eval 'use Torrus::ConfigTree;';
+ die $@ if $@;
+
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";
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";
@@
-149,12
+155,22
@@
sub report {
}
}
+sub queued_add_router {
+ my $self = shift;
+ my $error = $self->add_router(@_);
+ die $error if $error;
+}
+
sub add_router {
sub add_router {
- my($self, $ip) = @_;
+ my($self, $ip, $community) = @_;
+
+ $community = (defined($community) && length($community) > 1)
+ ? qq!<param name="snmp-community" value="$community"/>\n !
+ : '';
my $newhost =
qq( <host>\n).
my $newhost =
qq( <host>\n).
- qq( <param name="snmp-host" value="$ip"/>\n).
+ qq( <param name="snmp-host" value="$ip"/>\n).
$community.
qq( </host>\n);
my $ddx = $self->_torrus_loadddx;
qq( </host>\n);
my $ddx = $self->_torrus_loadddx;
@@
-168,8
+184,10
@@
sub add_router {
sub add_interface {
my($self, $router_ip, $interface, $serviceid ) = @_;
sub add_interface {
my($self, $router_ip, $interface, $serviceid ) = @_;
+ #false laziness w/torrus/perllib/Torrus/Renderer.pm iface_underscore, update both
$interface =~ s(\/)(_)g; #slashes become underscores
$interface =~ s(\.)(_)g; #periods too, huh
$interface =~ s(\/)(_)g; #slashes become underscores
$interface =~ s(\.)(_)g; #periods too, huh
+ $interface =~ s(\-)(_)g; #yup, and dashes
#should just use a proper XML parser huh
#should just use a proper XML parser huh
@@
-207,7
+225,7
@@
sub add_interface {
unless ( $added ) {
$new .=
qq( <param name="RFC2863_IF_MIB::external-serviceid">\n).
unless ( $added ) {
$new .=
qq( <param name="RFC2863_IF_MIB::external-serviceid">\n).
- qq( $newline\n
"
).
+ qq( $newline\n).
qq( </param>\n);
}
$new .= "$hostline\n";
qq( </param>\n);
}
$new .= "$hostline\n";
@@
-247,23
+265,31
@@
sub _torrus_newddx {
close $new;
my $tmpname = $ddxfile . Date::Format::time2str('%Y%m%d%H%M%S',time);
close $new;
my $tmpname = $ddxfile . Date::Format::time2str('%Y%m%d%H%M%S',time);
- rename(
"$ddxfile"
, $tmpname) or die $!;
+ rename(
$ddxfile
, $tmpname) or die $!;
rename("$ddxfile.new", $ddxfile) or die $!;
rename("$ddxfile.new", $ddxfile) or die $!;
- $self->_torrus_reload;
+ my $error = $self->_torrus_reload;
+ if ( $error ) { #revert routers.ddx
+ rename($ddxfile, "$tmpname.FAILED") or die $!;
+ rename($tmpname, $ddxfile) or die $!;
+ }
+
+ $self->_torrus_unlock;
+
+ return $error;
}
sub _torrus_reload {
my($self) = @_;
}
sub _torrus_reload {
my($self) = @_;
- #i should use IPC::Run and have better error checking (commands are silent
- # for success, or output errors)
+ my $stderr = '';
+ run( ['torrus', 'devdiscover', "--in=$ddxfile"], '2>'=>\$stderr );
+ return $stderr if $stderr;
- system('torrus', 'devdiscover', "--in=$ddxfile");
+ run( ['torrus', 'compile', '--tree=main'] ); # , '--verbose'
+ #typically the errors happen at the discover stage...
- system('torrus', 'compile', '--tree=main'); # , '--verbose'
-
- $self->_torrus_unlock;
+ '';
}
}