Check and Fix Scheme and StorageArea

This commit is contained in:
Isaac Connor 2018-11-09 10:39:57 -05:00
parent 82abd04f36
commit 4ddd328c61
1 changed files with 59 additions and 51 deletions

View File

@ -508,68 +508,76 @@ MAIN: while( $loop ) {
# Foreach database monitor and it's list of events. # Foreach database monitor and it's list of events.
while ( my ( $db_monitor, $db_events ) = each(%$db_monitors) ) { while ( my ( $db_monitor, $db_events ) = each(%$db_monitors) ) {
Debug("Checking db events for monitor $db_monitor");
if ( ! $db_events ) {
Debug("Skipping db events for $db_monitor because there are none");
next;
}
# If we found the monitor in the file system # If we found the monitor in the file system
if ( my $fs_events = $fs_monitors->{$db_monitor} ) { my $fs_events = $fs_monitors->{$db_monitor};
next if ! $db_events;
while ( my ( $db_event, $age ) = each( %$db_events ) ) { while ( my ( $db_event, $age ) = each( %$db_events ) ) {
if ( ! defined( $fs_events->{$db_event} ) ) { if ( ! ($fs_events and defined( $fs_events->{$db_event} ) ) ) {
my $Event = ZoneMinder::Event->find_one( Id=>$db_event ); Debug("Don't have an fs event for $db_event");
if ( ! $Event ) { my $Event = ZoneMinder::Event->find_one( Id=>$db_event );
Debug("Event $db_event is no longer in db. Filter probably deleted it while we were auditing."); if ( ! $Event ) {
next; Debug("Event $db_event is no longer in db. Filter probably deleted it while we were auditing.");
next;
}
Debug("Event $db_event is not in fs. Should have been at ".$Event->Path());
if ( $Event->Archived() ) {
Warning("Event $$Event{Id} is Archived. Taking no further action on it.");
next;
}
if ( ! $Event->StartTime() ) {
Info("Event $$Event{Id} has no start time. deleting it.");
if ( confirm() ) {
$Event->delete();
$cleaned = 1;
} }
Debug("Event $db_event is not in fs. Should have been at ".$Event->Path()); next;
if ( $Event->Archived() ) { }
Warning("Event $$Event{Id} is Archived. Taking no further action on it."); if ( ! $Event->EndTime() ) {
next; if ( $age > $Config{ZM_AUDIT_MIN_AGE} ) {
} Info("Event $$Event{Id} has no end time and is $age seconds old. deleting it.");
if ( ! $Event->StartTime() ) {
Info("Event $$Event{Id} has no start time. deleting it.");
if ( confirm() ) { if ( confirm() ) {
$Event->delete(); $Event->delete();
$cleaned = 1; $cleaned = 1;
} }
next; next;
}
if ( ! $Event->EndTime() ) {
if ( $age > $Config{ZM_AUDIT_MIN_AGE} ) {
Info("Event $$Event{Id} has no end time and is $age seconds old. deleting it.");
if ( confirm() ) {
$Event->delete();
$cleaned = 1;
}
next;
}
} }
if ( $Event->check_for_in_filesystem() ) { }
Debug("Database event $$Event{Id} apparently exists at " . $Event->Path() ); if ( $Event->check_for_in_filesystem() ) {
} else { Debug("Database event $$Event{Id} apparently exists at " . $Event->Path() );
if ( $age > $Config{ZM_AUDIT_MIN_AGE} ) { } else {
aud_print( "Database event '$db_monitor/$db_event' does not exist at " . $Event->Path().' in filesystem, deleting' ); if ( $age > $Config{ZM_AUDIT_MIN_AGE} ) {
if ( confirm() ) { aud_print( "Database event '$db_monitor/$db_event' does not exist at " . $Event->Path().' in filesystem, deleting' );
$Event->delete(); if ( confirm() ) {
$cleaned = 1; $Event->delete();
} $cleaned = 1;
} else {
aud_print( "Database event '".$Event->Path()." monitor:$db_monitor event:$db_event' does not exist in filesystem but too young to delete age: $age > MIN $Config{ZM_AUDIT_MIN_AGE}.\n" );
} }
} # end if exists in filesystem } else {
} # end if ! in fs_events aud_print( "Database event '".$Event->Path()." monitor:$db_monitor event:$db_event' does not exist in filesystem but too young to delete age: $age > MIN $Config{ZM_AUDIT_MIN_AGE}.\n" );
} # foreach db_event }
#} else { } # end if exists in filesystem
#my $Monitor = new ZoneMinder::Monitor( $db_monitor ); } else {
#my $Storage = $Monitor->Storage(); Debug("Found fs event for $db_event, $age at " . $$fs_events{$db_event}->Path());
#aud_print( "Database monitor '$db_monitor' does not exist in filesystem, should have been at ".$Storage->Path().'/'.$Monitor->Id()."\n" ); my $Event = new ZoneMinder::Event( $db_event );
#if ( confirm() ) if ( ! $Event->check_for_in_filesystem() ) {
#{ Warning("Not found at " . $Event->Path() );
# We don't actually do this in case it's new if ( $$fs_events{$db_event}->Scheme() ne $Event->Scheme() ) {
#my $res = $deleteMonitorSth->execute( $db_monitor ) Info("Updating scheme on event $$Event{Id} from $$Event{Scheme} to $$fs_events{$db_event}{Scheme}");
# or Fatal( "Can't execute: ".$deleteMonitorSth->errstr() ); $Event->Scheme($$fs_events{$db_event}->Scheme());
#$cleaned = 1; }
#} if ( $$fs_events{$db_event}->StorageId() != $Event->StorageId() ) {
} Info("Updating storage area on event $$Event{Id} from $$Event{StorageId} to $$fs_events{$db_event}{StorageId}");
$Event->StorageId($$fs_events{$db_event}->StorageId());
}
$Event->save();
}
} # end if ! in fs_events
} # foreach db_event
} # end foreach db_monitor } # end foreach db_monitor
if ( $cleaned ) { if ( $cleaned ) {
Debug("Have done some cleaning, restarting."); Debug("Have done some cleaning, restarting.");