Title: [opsview] [11345] remove ndolog files only if they were successfully processed
Revision
11345
Author
aburzynski
Date
2013-02-04 17:17:32 +0000 (Mon, 04 Feb 2013)

Log Message

remove ndolog files only if they were successfully processed

Modified Paths


Modified: trunk/opsview-core/bin/import_ndologsd
===================================================================
--- trunk/opsview-core/bin/import_ndologsd	2013-02-04 16:49:17 UTC (rev 11344)
+++ trunk/opsview-core/bin/import_ndologsd	2013-02-04 17:17:32 UTC (rev 11345)
@@ -124,18 +124,19 @@
             }
 
             # Send the log to NDO. Blocks if connection refuses until either it can, or $break is set
-            $importer->send_log( $file, $file_size );
-
-            if ( $logger->is_debug() ) {
-                my $debug_dir = "/usr/local/nagios/var/ndologs.archive";
-                unless ( -d $debug_dir ) {
-                    mkdir $debug_dir;
+            if ( $importer->send_log( $file, $file_size ) )
+            { # file processed successfully
+                if ( $logger->is_debug() ) {
+                    my $debug_dir = "/usr/local/nagios/var/ndologs.archive";
+                    unless ( -d $debug_dir ) {
+                        mkdir $debug_dir;
+                    }
+                    rename( $file, "$debug_dir/$file" );
                 }
-                rename( $file, "$debug_dir/$file" );
+                else {
+                    unlink $file;
+                }
             }
-            else {
-                unlink $file;
-            }
             last MAINLOOP if ($break);
             my $duration = gettimeofday() - $start;
             $logger->debug( "Finished $file. Duration=$duration" );

Modified: trunk/opsview-core/lib/Opsview/Utils/NDOLogsImporter.pm
===================================================================
--- trunk/opsview-core/lib/Opsview/Utils/NDOLogsImporter.pm	2013-02-04 16:49:17 UTC (rev 11344)
+++ trunk/opsview-core/lib/Opsview/Utils/NDOLogsImporter.pm	2013-02-04 17:17:32 UTC (rev 11345)
@@ -990,8 +990,7 @@
 }
 
 sub send_log {
-    my $c     = 0;
-    my $break = 0;
+    my $result = 0;
 
     # $self->{break} is the global break
     $_[ ARG_SELF() ]->{logger}->debug(
@@ -1021,19 +1020,20 @@
             eval {
                 #$DB->txn( ping => sub {
                 #DBI->trace($ENV{DBI_TRACE2} || 0) unless $ENV{DBI_TRACE};
-                $_[ ARG_SELF() ]->$m( $data->[ $i + 1 ] );
+                $result = $_[ ARG_SELF() ]->$m( $data->[ $i + 1 ] );
 
                 #DBI->trace(0) unless $ENV{DBI_TRACE};
                 #});
             };
             if ( my $e = $@ ) {
-
                 $_[ ARG_SELF() ]->{logger}->fatal( "Error in $m: $e" );
             }
         }
     }
 
     # $_[ ARG_SELF() ]->db_perform_maintenance();
+
+    return $result;
 }
 
 sub db_clear_table {
@@ -1305,6 +1305,8 @@
             #            }
         }
     }
+
+    return 1;
 }
 
 my $sth_insert_handle_SERVICECHECKDATA;
@@ -1397,6 +1399,8 @@
         die "Insert failed: ", $sth_insert_handle_SERVICECHECKDATA->errstr, "\n"
           unless $rv;
     }
+
+    return 1;
 }
 
 my $sth_insert_handle_HOSTCHECKDATA;
@@ -1494,6 +1498,8 @@
         die "Insert failed: ", $sth_insert_handle_HOSTCHECKDATA->errstr, "\n"
           unless $rv;
     }
+
+    return 1;
 }
 
 my $sth_update_handle_COMMENTDATA;
@@ -1710,6 +1716,8 @@
 
         }
     }
+
+    return 1;
 }
 
 my $sth_update_handle_DOWNTIMEDATA;
@@ -2025,6 +2033,8 @@
 
         }
     }
+
+    return 1;
 }
 
 my $sth_update_handle_PROGRAMSTATUSDATA;
@@ -2146,6 +2156,8 @@
             $sth_insert_handle_PROGRAMSTATUSDATA->execute(@data);
         }
     }
+
+    return 1;
 }
 
 my $sth_insert_handle_HOSTSTATUSDATA;
@@ -2478,6 +2490,8 @@
             );
         }
     }
+
+    return 1;
 }
 
 my $sth_insert_handle_SERVICESTATUSDATA;
@@ -2819,6 +2833,8 @@
             );
         }
     }
+
+    return 1;
 }
 
 sub handle_MULTI_GROUP_MEMBERS {
@@ -3125,6 +3141,8 @@
             );
         }
     }
+
+    return 1;
 }
 
 sub handle_RETENTIONDATA {
@@ -3140,6 +3158,8 @@
             $LOADING_RETENTION_DATA_FLAG = 0;
         }
     }
+
+    return 1;
 }
 
 my $sth_insert_handle_ACKNOWLEDGEMENTDATA;
@@ -3206,6 +3226,8 @@
           unless $rv;
 
     }
+
+    return 1;
 }
 
 my $sth_insert_handle_STATECHANGEDATA;
@@ -3342,6 +3364,8 @@
           unless $rv;
 
     }
+
+    return 1;
 }
 
 sub handle_CONFIGDUMPSTART {
@@ -3357,6 +3381,8 @@
             $CURRENT_OBJECT_CONFIG_TYPE = 0;
         }
     }
+
+    return 1;
 }
 
 sub handle_CONFIGDUMPEND {
@@ -3365,6 +3391,8 @@
         my $file = sprintf( "/usr/local/nagios/var/ndoconfigend/%d", time() );
         system( "touch $file" );
     }
+
+    return 1;
 }
 
 my $sth_insert_handle_PROCESSDATA;
@@ -3481,6 +3509,8 @@
             $sth_update_endtime_handle_PROCESSDATA->execute();
         }
     }
+
+    return 1;
 }
 
 my $sth_update_handle_HOSTDEFINITION;
@@ -3777,6 +3807,8 @@
         }
 
     }
+
+    return 1;
 }
 
 my $sth_update_handle_SERVICEDEFINITION;
@@ -4057,6 +4089,8 @@
                 $service_id );
         }
     }
+
+    return 1;
 }
 
 my $sth_update_handle_SERVICEDEPENDENCYDEFINITION;
@@ -4152,6 +4186,8 @@
             $sth_update_handle_SERVICEDEPENDENCYDEFINITION->execute(@data);
         }
     }
+
+    return 1;
 }
 
 my $sth_update_handle_COMMANDDEFINITION;
@@ -4209,6 +4245,8 @@
             $sth_update_handle_COMMANDDEFINITION->execute(@data);
         }
     }
+
+    return 1;
 }
 
 my $sth_update_handle_TIMEPERIODDEFINITION;
@@ -4303,6 +4341,8 @@
         }
 
     }
+
+    return 1;
 }
 
 my $sth_update_handle_CONTACTDEFINITION;
@@ -4475,6 +4515,8 @@
         }
 
     }
+
+    return 1;
 }
 
 my $sth_insert_handle_HOSTGROUPDEFINITION;
@@ -4523,6 +4565,8 @@
                 $event->[ NDO_DATA_HOSTGROUPMEMBER() ], $group_id );
         }
     }
+
+    return 1;
 }
 
 my $sth_insert_handle_CONTACTGROUPDEFINITION;
@@ -4575,6 +4619,8 @@
             );
         }
     }
+
+    return 1;
 }
 
 1;
@@ -4691,6 +4737,8 @@
             handle_MULTI_GROUP_MEMBERS('service', NDO2DB_OBJECTTYPE_SERVICE(), $event->[ NDO_DATA_SERVICEGROUPMEMBER() ], $group_id);
         }
     }
+
+    return 1;
 }
 
 sub handle_EXTERNALCOMMANDDATA {
@@ -4726,6 +4774,8 @@
         my $rv = $sth_insert->execute( @data );
         die "Update failed: ", $sth_insert->errstr, "\n" unless $rv;
     }
+
+    return 1;
 }
 
 {
@@ -4793,6 +4843,8 @@
                 $sth_insert->execute( @data );
             }
         }
+
+        return 1;
     }
 }
 
@@ -4864,6 +4916,8 @@
                 }
             }
         }
+
+        return 1;
     }
 }
 

_______________________________________________
Opsview-checkins mailing list
[email protected]
http://lists.opsview.org/lists/listinfo/opsview-checkins

Reply via email to