Przeglądaj źródła

fixes in mysql module

root 2 lat temu
rodzic
commit
5d3418aa3f
3 zmienionych plików z 17 dodań i 6 usunięć
  1. 1 0
      scripts/dhcp-log.pl
  2. 15 5
      scripts/eyelib/mysql.pm
  3. 1 1
      scripts/nf_calc

+ 1 - 0
scripts/dhcp-log.pl

@@ -160,6 +160,7 @@ if (!$pid) {
 
 
             my $auth_record = get_record_sql($hdb,'SELECT * FROM User_auth WHERE ip="'.$dhcp_record->{ip}.'" and mac="'.$mac.'" and deleted=0 ORDER BY last_found DESC');
+
             if (!$auth_record and $type eq 'old' ) { $type='add'; }
 
             if ($type eq 'add') {

+ 15 - 5
scripts/eyelib/mysql.pm

@@ -335,10 +335,17 @@ my @result;
 return @result if (!$db);
 return @result if (!$tsql);
 $tsql.=' LIMIT 1';
-my $list = $db->prepare($tsql) or die "Unable to prepare $tsql: " . $db->errstr;
-$list->execute() or die "Unable to execute $tsql: " . $db->errstr;
-my $row_ref = $list->fetchrow_hashref();
-$list->finish();
+my $row_ref;
+eval {
+    my $list = $db->prepare($tsql) or die "Unable to prepare $tsql: " . $db->errstr;
+    $list->execute() or die "Unable to execute $tsql: " . $db->errstr;
+    $row_ref = $list->fetchrow_hashref();
+    $list->finish();
+};
+if ($@) {
+    log_error("Error apply sql: $tsql err:".$@);
+    die "Error apply sql: $tsql";
+    }
 return $row_ref;
 }
 
@@ -425,6 +432,7 @@ if ($found_changed) {
     } else {
     db_log_debug($db,'Nothing change. Skip update.');
     }
+return 1;
 }
 
 #---------------------------------------------------------------------------------------------------------------
@@ -749,7 +757,7 @@ sub apply_device_lock {
     #if timestamp undefined, set and return
     if (!$dev->{'locked_timestamp'}) { return set_lock_discovery($db,$device_id); }
     #wait for discovery
-    $wait_time = $dev->{'locked_timestamp'} + 30 - time();
+    my $wait_time = $dev->{'locked_timestamp'} + 30 - time();
     if ($wait_time<0) { return set_lock_discovery($db,$device_id); }
     sleep($wait_time);
     return apply_device_lock($db,$device_id,$iteration);
@@ -760,6 +768,7 @@ sub apply_device_lock {
 sub set_lock_discovery {
     my $db = shift;
     my $device_id = shift;
+    my $new;
     $new->{'discovery_locked'} = 1;
     $new->{'locked_timestamp'} = GetNowTime();
     if (update_record($db,'devices',$new,'id='.$device_id)) { return 1; } 
@@ -771,6 +780,7 @@ sub set_lock_discovery {
 sub unset_lock_discovery {
     my $db = shift;
     my $device_id = shift;
+    my $new;
     $new->{'discovery_locked'} = 0;
     $new->{'locked_timestamp'} = GetNowTime();
     if (update_record($db,'devices',$new,'id='.$device_id)) { return 1; } 

+ 1 - 1
scripts/nf_calc

@@ -10,6 +10,6 @@ routerid=$2
 [ ! -e "${fname}" ] && exit 101
 
 #renice +19 -p $$ >/dev/null 2>&1
-/usr/bin/nfdump -N -r ${fname} -q -o 'fmt:%tsr;%pr;%sa;%xda;%sp;%dp;%ipkt;%ibyt;%in;%out' | /opt/Eye/scripts/parse_flow.pl ${routerid} &
+/bin/nfdump -N -r ${fname} -q -o 'fmt:%tsr;%pr;%sa;%xda;%sp;%dp;%ipkt;%ibyt;%in;%out' | /opt/Eye/scripts/parse_flow.pl ${routerid} &
 
 exit 0