X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FNetworkMonitoringSystem%2FTorrus_Internal.pm;h=28bc8a7611732eac6ea6c8cf2a874fc38432fe43;hb=HEAD;hp=6b89090f862cd81181a484473c23b33eb533d5e7;hpb=1c39f3a433f4ccf64be6f043978bf3468117d9f4;p=freeside.git diff --git a/FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm b/FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm index 6b89090f8..28bc8a761 100644 --- a/FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm +++ b/FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm @@ -5,6 +5,7 @@ use strict; 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); @@ -154,11 +155,18 @@ sub report { } +sub queued_add_router { + my $self = shift; + my $error = $self->add_router(@_); + die $error if $error; +} + sub add_router { my($self, $ip, $community) = @_; - $community = qq!\n ! - if length($community) > 1; + $community = (defined($community) && length($community) > 1) + ? qq!\n ! + : ''; my $newhost = qq( \n). @@ -176,6 +184,7 @@ sub add_router { 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; #yup, and dashes @@ -256,23 +265,31 @@ sub _torrus_newddx { 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 $!; - $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) = @_; - #i should use IPC::Run and have better error checking (commands are silent - # for success, or output errors) - - system('torrus', 'devdiscover', "--in=$ddxfile"); + my $stderr = ''; + run( ['torrus', 'devdiscover', "--in=$ddxfile"], '2>'=>\$stderr ); + return $stderr if $stderr; - system('torrus', 'compile', '--tree=main'); # , '--verbose' + run( ['torrus', 'compile', '--tree=main'] ); # , '--verbose' + #typically the errors happen at the discover stage... - $self->_torrus_unlock; + ''; }