Check and Fix Scheme and StorageArea
This commit is contained in:
parent
82abd04f36
commit
4ddd328c61
|
@ -508,68 +508,76 @@ MAIN: while( $loop ) {
|
|||
|
||||
# Foreach database monitor and it's list of events.
|
||||
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 ( my $fs_events = $fs_monitors->{$db_monitor} ) {
|
||||
next if ! $db_events;
|
||||
my $fs_events = $fs_monitors->{$db_monitor};
|
||||
|
||||
while ( my ( $db_event, $age ) = each( %$db_events ) ) {
|
||||
if ( ! defined( $fs_events->{$db_event} ) ) {
|
||||
my $Event = ZoneMinder::Event->find_one( Id=>$db_event );
|
||||
if ( ! $Event ) {
|
||||
Debug("Event $db_event is no longer in db. Filter probably deleted it while we were auditing.");
|
||||
next;
|
||||
while ( my ( $db_event, $age ) = each( %$db_events ) ) {
|
||||
if ( ! ($fs_events and defined( $fs_events->{$db_event} ) ) ) {
|
||||
Debug("Don't have an fs event for $db_event");
|
||||
my $Event = ZoneMinder::Event->find_one( Id=>$db_event );
|
||||
if ( ! $Event ) {
|
||||
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());
|
||||
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.");
|
||||
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->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() );
|
||||
} else {
|
||||
if ( $age > $Config{ZM_AUDIT_MIN_AGE} ) {
|
||||
aud_print( "Database event '$db_monitor/$db_event' does not exist at " . $Event->Path().' in filesystem, deleting' );
|
||||
if ( confirm() ) {
|
||||
$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" );
|
||||
}
|
||||
if ( $Event->check_for_in_filesystem() ) {
|
||||
Debug("Database event $$Event{Id} apparently exists at " . $Event->Path() );
|
||||
} else {
|
||||
if ( $age > $Config{ZM_AUDIT_MIN_AGE} ) {
|
||||
aud_print( "Database event '$db_monitor/$db_event' does not exist at " . $Event->Path().' in filesystem, deleting' );
|
||||
if ( confirm() ) {
|
||||
$Event->delete();
|
||||
$cleaned = 1;
|
||||
}
|
||||
} # end if exists in filesystem
|
||||
} # end if ! in fs_events
|
||||
} # foreach db_event
|
||||
#} else {
|
||||
#my $Monitor = new ZoneMinder::Monitor( $db_monitor );
|
||||
#my $Storage = $Monitor->Storage();
|
||||
#aud_print( "Database monitor '$db_monitor' does not exist in filesystem, should have been at ".$Storage->Path().'/'.$Monitor->Id()."\n" );
|
||||
#if ( confirm() )
|
||||
#{
|
||||
# We don't actually do this in case it's new
|
||||
#my $res = $deleteMonitorSth->execute( $db_monitor )
|
||||
# or Fatal( "Can't execute: ".$deleteMonitorSth->errstr() );
|
||||
#$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 {
|
||||
Debug("Found fs event for $db_event, $age at " . $$fs_events{$db_event}->Path());
|
||||
my $Event = new ZoneMinder::Event( $db_event );
|
||||
if ( ! $Event->check_for_in_filesystem() ) {
|
||||
Warning("Not found at " . $Event->Path() );
|
||||
if ( $$fs_events{$db_event}->Scheme() ne $Event->Scheme() ) {
|
||||
Info("Updating scheme on event $$Event{Id} from $$Event{Scheme} to $$fs_events{$db_event}{Scheme}");
|
||||
$Event->Scheme($$fs_events{$db_event}->Scheme());
|
||||
}
|
||||
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
|
||||
if ( $cleaned ) {
|
||||
Debug("Have done some cleaning, restarting.");
|
||||
|
|
Loading…
Reference in New Issue