[freeside-commits] freeside/FS/FS/NetworkMonitoringSystem Torrus_Internal.pm, 1.2, 1.3

Erik Levinson levinse at wavetail.420.am
Fri Feb 4 22:04:34 PST 2011


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

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

Index: Torrus_Internal.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -d -r1.2 -r1.3
--- Torrus_Internal.pm	29 Jan 2011 02:50:27 -0000	1.2
+++ Torrus_Internal.pm	5 Feb 2011 06:04:32 -0000	1.3
@@ -5,6 +5,7 @@
 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 $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) = @_;
 
@@ -48,11 +56,11 @@
     next unless $line =~ /^\s*<param\s+name="snmp-host"\s+value="$router_ip"\/?>/i;
 
     while ( my $hostline = shift(@ddx) ) {
-      $new .= "$hostline\n";
+      $new .= "$hostline\n" unless $hostline =~ /^\s+<\/host>\s*/i;
       if ( $hostline =~ /^\s*<param name="RFC2863_IF_MIB::external-serviceid"\/?>/i ) {
 
         while ( my $paramline = shift(@ddx) ) {
-          if ( $paramline =~ /^\s*</param>/ ) {
+          if ( $paramline =~ /^\s*<\/param>/ ) {
             $new .= "$newline\n$paramline";
             last; #paramline
           } else {
@@ -67,7 +75,7 @@
           $new .= 
             qq(   <param name="RFC2863_IF_MIB::external-serviceid">\n).
             qq(     $newline\n").
-            qq(   </param>\n).
+            qq(   </param>\n);
         }
         $new .= $hostline;
         last; #hostline
@@ -82,7 +90,7 @@
 }
 
 sub _torrus_lock {
-  $lock = new IO:::File ">>$lockfile" or die $!;
+  $lock = new IO::File ">>$lockfile" or die $!;
   flock($lock, LOCK_EX);
 }
 
@@ -104,7 +112,10 @@
     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;



More information about the freeside-commits mailing list