]> git.sesse.net Git - nms/blobdiff - web/tempfetch.pl
Update make-switches.pl for TG07.
[nms] / web / tempfetch.pl
index eed5417fdfbf8a712d49cac6f3becedf617397ee..0a25bc55c815f1b43aedb3bac084be05a8964c63 100644 (file)
@@ -2,20 +2,17 @@
 #use BER;
 use Data::Dumper;
 use DBI;
-use Net::Telnet;
 use POSIX;
 use Time::HiRes;
+use lib '../include';
+use nms;
 use strict;
 use warnings;
-#require 'SNMP_Session.pm';
 
 # Tweak timeouit og sjekk med :support||:net hva passord vil bli
-my $password = 'removed';
-my $timeout = 25;
 my $location = 'skipet';
 
-my $dbh = DBI->connect("dbi:Pg:dbname=snmpfetch;host=violet.tg05.gathering.org", "snmpfetch", "removed")
-       or die "Couldn't connect to database";
+my $dbh = nms::db_connect();
 $dbh->{AutoCommit} = 0;
 
 my $qswitch = $dbh->prepare(<<"EOF")
@@ -71,11 +68,11 @@ while (1) {
        my $ip = $switch->{'ip'};
        my $start = [Time::HiRes::gettimeofday];
        eval {
-               my $conn = switch_connect($ip);
+               my $conn = nms::switch_connect($ip);
                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;
@@ -93,44 +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 switch_connect {
-       my ($ip) = @_;
-
-       my $conn = new Net::Telnet(     Timeout => $timeout,
-                                       Dump_Log => '/tmp/dumplog',
-                                       Errmode => 'return',
-                                       Prompt => '/(es3024|e\d+\-\dsw)>/i');
-       my $ret = $conn->open(  Host => $ip);
-       if (!$ret || $ret != 1) {
-               return (0);
-       }
-       # XXX: Just send the password as text, I did not figure out how to
-       # handle authentication with only password through $conn->login().
-       #$conn->login(  Prompt => '/password[: ]*$/i',
-       #               Name => $password,
-       #               Password => $password);
-       my @data = $conn->cmd($password);
-       # Get rid of banner
-       $conn->get;
-       return ($conn);
-}
-
-
 sub mylog {
        my $msg = shift;
        my $time = POSIX::ctime(time);