X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FNetworkMonitoringSystem%2FTorrus_Internal.pm;h=5d1bb06f111e12650c9492081d2c32b7861b7e71;hb=bc8bc32def6ab636129c205ebd5b7db76b805ac5;hp=68356e72d83feccd42d320a31b4f411a7caa1b2b;hpb=40d1e71653e1a0021021d9d3f7f7705cf9df4d61;p=freeside.git
diff --git a/FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm b/FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm
index 68356e72d..5d1bb06f1 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 Date::Format;
#$DEBUG = 0;
#$me = '[FS::NetworkMonitoringSystem::Torrus_Internal]';
@@ -13,6 +14,13 @@ our $lock;
our $lockfile = '/usr/local/etc/torrus/discovery/FSLOCK';
our $ddxfile = '/usr/local/etc/torrus/discovery/routers.ddx';
+sub new {
+ my $class = shift;
+ my $self = {};
+ bless $self, $class;
+ return $self;
+}
+
sub add_router {
my($self, $ip) = @_;
@@ -27,6 +35,8 @@ sub add_router {
$self->_torrus_newddx($ddx);
+}
+
sub add_interface {
my($self, $router_ip, $interface, $serviceid ) = @_;
@@ -46,11 +56,11 @@ sub add_interface {
next unless $line =~ /^\s*/i;
while ( my $hostline = shift(@ddx) ) {
- $new .= "$hostline\n";
+ $new .= "$hostline\n" unless $hostline =~ /^\s+<\/host>\s*/i;
if ( $hostline =~ /^\s*/i ) {
while ( my $paramline = shift(@ddx) ) {
- if ( $paramline =~ /^\s*/ ) {
+ if ( $paramline =~ /^\s*<\/param>/ ) {
$new .= "$newline\n$paramline";
last; #paramline
} else {
@@ -65,7 +75,7 @@ sub add_interface {
$new .=
qq( \n).
qq( $newline\n").
- qq( \n).
+ qq( \n);
}
$new .= $hostline;
last; #hostline
@@ -80,7 +90,7 @@ sub add_interface {
}
sub _torrus_lock {
- $lock = new IO:::File ">>$lockfile" or die $!;
+ $lock = new IO::File ">>$lockfile" or die $!;
flock($lock, LOCK_EX);
}
@@ -102,7 +112,10 @@ sub _torrus_newddx {
or die "can't write to $ddxfile.new: $!";
print $new $ddx;
close $new;
- rename("$ddxfile", $ddxfile.`date +%Y%m%d%H%M%S`) or die $!;
+
+ # `date ...` created file names with weird chars in them
+ my $tmpname = $ddxfile . Date::Format::time2str('%Y%m%d%H%M%S',time);
+ rename("$ddxfile", $tmpname) or die $!;
rename("$ddxfile.new", $ddxfile) or die $!;
$self->_torrus_reload;