]> git.sesse.net Git - nms/commitdiff
Move switch_exec() into nms.pm.
authorSteinar H. Gunderson <sesse@samfundet.no>
Wed, 29 Mar 2006 12:59:04 +0000 (12:59 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Wed, 29 Mar 2006 12:59:04 +0000 (12:59 +0000)
include/nms.pm
web/smanagement.pl
web/ssendfile.pl
web/tempfetch.pl

index f895ffda4cbf06f6583b5e9c907429c5c893b763..0c0d7541be2371bcc6e9f280acbe41de85a584c6 100644 (file)
@@ -44,4 +44,20 @@ sub switch_connect($) {
        return ($conn);
 }
 
+# Send a command to switch and return the data recvied from the switch
+sub switch_exec($$) {
+       my ($cmd, $conn) = @_;
+
+       # Send the command and get data from switch
+       my @data = $conn->cmd($cmd);
+       my @lines = ();
+       foreach my $line (@data) {
+               # Remove escape-7 sequence
+               $line =~ s/\x1b\x37//g;
+               push (@lines, $line);
+       }
+
+       return @lines;
+}
+
 1;
index b900f1ea53e140d0c45460c0f7dd5d7c41052866..ed783b2fa915b245f821f92c9d19675416df061c 100755 (executable)
@@ -22,22 +22,6 @@ my $sgetip = $dbh->prepare("SELECT ip FROM switches WHERE sysname = ?")
        or die "Could not prepare sgetip";
 my $sgid = $dbh->prepare("SELECT nextval('squeue_group_sequence') as gid");
 
-# Send a command to switch and return the data recvied from the switch
-sub switch_exec($$) {
-       my ($cmd, $conn) = @_;
-
-       # Send the command and get data from switch
-       my @data = $conn->cmd($cmd);
-       my @lines = ();
-       foreach my $line (@data) {
-               # Remove escape-7 sequence
-               $line =~ s/\x1b\x37//g;
-               push (@lines, $line);
-       }
-
-       return @lines;
-}
-
 sub parse_range($) {
        my $switches = $_;
        my @range;
index 4ec7104ce1875ac2b461cdd8d7ac61f2cb11734c..5347dd2193b0ce6f86cea58a8e9d91a8e700bfda 100755 (executable)
@@ -7,22 +7,6 @@ use POSIX;
 my $delaytime = 30;
 my $poll_frequency = 60;
 
-# Send a command to switch and return the data recvied from the switch
-sub switch_exec($$) {
-       my ($cmd, $conn) = @_;
-
-       # Send the command and get data from switch
-       my @data = $conn->cmd($cmd);
-       my @lines = ();
-       foreach my $line (@data) {
-               # Remove escape-7 sequence
-               $line =~ s/\x1b\x37//g;
-               push (@lines, $line);
-       }
-
-       return @lines;
-}
-
 sub mylog {
        my $msg = shift;
        my $time = POSIX::ctime(time);
@@ -55,7 +39,7 @@ while (<CONFIG>) {
 #              }
 #      }
 #      else {
-               my @data = switch_exec($cmd, $conn);
+               my @data = nms::switch_exec($cmd, $conn);
                foreach my $line (@data) {
                        $line =~ s/[\r\n]+//g;
                        print "$line\n";
index 542b4d67786111cddd58a575d1f85f7bac88ebd0..0a25bc55c815f1b43aedb3bac084be05a8964c63 100644 (file)
@@ -72,7 +72,7 @@ while (1) {
                if (!defined($conn)) {
                        print "Could not connect to switch ".$switch->{'switch'}."\n";
                }
-               my @data = switch_exec('sys monitor status', $conn);
+               my @data = nms::switch_exec('sys monitor status', $conn);
                my @fields = split(/\s+/, $data[2]);
                # The temp fields are 6, 7, 8
                my $avgtemp = ($fields[6] + $fields[7] + $fields[8]) / 3;
@@ -90,21 +90,6 @@ while (1) {
        $dbh->commit;
 }
 
-sub switch_exec {
-       my ($cmd, $conn) = @_;
-
-       # Send the command and get data from switch
-       my @data = $conn->cmd($cmd);
-       my @lines = ();
-       foreach my $line (@data) {
-               # Remove escape-7 sequence
-               $line =~ s/\x1b\x37//g;
-               push (@lines, $line);
-               }
-
-       return @lines;
-}
-
 sub mylog {
        my $msg = shift;
        my $time = POSIX::ctime(time);