Remove Function references and swap with appropriate Capturing, Analysing, Recording
This commit is contained in:
parent
23bfbcd6ce
commit
86f393565e
|
@ -203,27 +203,13 @@ sub zmDbGetMonitor {
|
||||||
return undef ;
|
return undef ;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $sql = 'SELECT * FROM Monitors WHERE Id = ?';
|
return zmDbFetchOne('SELECT * FROM Monitors WHERE Id = ?', $id);
|
||||||
my $sth = $dbh->prepare_cached($sql);
|
|
||||||
if ( !$sth ) {
|
|
||||||
Error("Can't prepare '$sql': ".$dbh->errstr());
|
|
||||||
return undef;
|
|
||||||
}
|
|
||||||
my $res = $sth->execute($id);
|
|
||||||
if ( !$res ) {
|
|
||||||
Error("Can't execute '$sql': ".$sth->errstr());
|
|
||||||
return undef;
|
|
||||||
}
|
|
||||||
my $monitor = $sth->fetchrow_hashref();
|
|
||||||
$sth->finish();
|
|
||||||
return $monitor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub zmDbGetMonitorAndControl {
|
sub zmDbGetMonitorAndControl {
|
||||||
zmDbConnect();
|
zmDbConnect();
|
||||||
|
|
||||||
my $id = shift;
|
my $id = shift;
|
||||||
|
|
||||||
return undef if !defined($id);
|
return undef if !defined($id);
|
||||||
|
|
||||||
my $sql = 'SELECT C.*,M.*,C.Protocol
|
my $sql = 'SELECT C.*,M.*,C.Protocol
|
||||||
|
@ -231,19 +217,7 @@ sub zmDbGetMonitorAndControl {
|
||||||
INNER JOIN Controls as C on (M.ControlId = C.Id)
|
INNER JOIN Controls as C on (M.ControlId = C.Id)
|
||||||
WHERE M.Id = ?'
|
WHERE M.Id = ?'
|
||||||
;
|
;
|
||||||
my $sth = $dbh->prepare_cached($sql);
|
return zmDbFetchOne($sql);
|
||||||
if ( !$sth ) {
|
|
||||||
Error("Can't prepare '$sql': ".$dbh->errstr());
|
|
||||||
return undef;
|
|
||||||
}
|
|
||||||
my $res = $sth->execute( $id );
|
|
||||||
if ( !$res ) {
|
|
||||||
Error("Can't execute '$sql': ".$sth->errstr());
|
|
||||||
return undef;
|
|
||||||
}
|
|
||||||
my $monitor = $sth->fetchrow_hashref();
|
|
||||||
$sth->finish();
|
|
||||||
return $monitor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub start_transaction {
|
sub start_transaction {
|
||||||
|
@ -280,6 +254,24 @@ sub zmDbDo {
|
||||||
return $rows;
|
return $rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub zmDbFetchOne {
|
||||||
|
my $sql = shift;
|
||||||
|
|
||||||
|
my $sth = $dbh->prepare_cached($sql);
|
||||||
|
if (!$sth) {
|
||||||
|
Error("Can't prepare '$sql': ".$dbh->errstr());
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
my $res = $sth->execute(@_);
|
||||||
|
if (!$res) {
|
||||||
|
Error("Can't execute '$sql': ".$sth->errstr());
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
my $row = $sth->fetchrow_hashref();
|
||||||
|
$sth->finish();
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
__END__
|
__END__
|
||||||
|
|
||||||
|
@ -302,6 +294,7 @@ zmDbGetMonitors
|
||||||
zmDbGetMonitor
|
zmDbGetMonitor
|
||||||
zmDbGetMonitorAndControl
|
zmDbGetMonitorAndControl
|
||||||
zmDbDo
|
zmDbDo
|
||||||
|
zmDbFetchOne
|
||||||
|
|
||||||
=head1 AUTHOR
|
=head1 AUTHOR
|
||||||
|
|
||||||
|
|
|
@ -203,8 +203,7 @@ sub xs_duration {
|
||||||
|
|
||||||
my %new_monitors = ();
|
my %new_monitors = ();
|
||||||
|
|
||||||
# my $sql = "select * from Monitors where find_in_set( Function, 'Modect,Mocord,Nodect,ExtDect' )>0 and ConfigType='ONVIF'";
|
my $sql = "SELECT * FROM Monitors WHERE Capturing != 'None' AND ONVIF_URL != ''";
|
||||||
my $sql = "SELECT * FROM Monitors WHERE ONVIF_URL != ''";
|
|
||||||
my $sth = $dbh->prepare_cached($sql) or Fatal("Can't prepare '$sql': ".$dbh->errstr());
|
my $sth = $dbh->prepare_cached($sql) or Fatal("Can't prepare '$sql': ".$dbh->errstr());
|
||||||
my $res = $sth->execute() or Fatal("Can't execute: ".$sth->errstr());
|
my $res = $sth->execute() or Fatal("Can't execute: ".$sth->errstr());
|
||||||
while ( my $monitor = $sth->fetchrow_hashref() ) {
|
while ( my $monitor = $sth->fetchrow_hashref() ) {
|
||||||
|
|
|
@ -32,6 +32,8 @@ use bytes;
|
||||||
|
|
||||||
@EXTRA_PERL_LIB@
|
@EXTRA_PERL_LIB@
|
||||||
use ZoneMinder;
|
use ZoneMinder;
|
||||||
|
use ZoneMinder::Monitor;
|
||||||
|
use ZoneMinder::State;
|
||||||
use DBI;
|
use DBI;
|
||||||
use POSIX;
|
use POSIX;
|
||||||
use Time::HiRes qw/gettimeofday/;
|
use Time::HiRes qw/gettimeofday/;
|
||||||
|
@ -57,26 +59,40 @@ my $dbh = zmDbConnect();
|
||||||
Debug("Command: $command");
|
Debug("Command: $command");
|
||||||
if ( $command and ( $command !~ /^(?:start|stop|restart|status|logrot|version)$/ ) ) {
|
if ( $command and ( $command !~ /^(?:start|stop|restart|status|logrot|version)$/ ) ) {
|
||||||
# Check to see if it's a valid run state
|
# Check to see if it's a valid run state
|
||||||
my $sql = 'SELECT * FROM `States` WHERE `Name`=?';
|
if ($state = ZoneMinder->find_one(Name=>$command)) {
|
||||||
my $sth = $dbh->prepare_cached($sql)
|
|
||||||
or Fatal("Can't prepare '$sql': ".$dbh->errstr());
|
|
||||||
my $res = $sth->execute($command)
|
|
||||||
or Fatal("Can't execute: ".$sth->errstr());
|
|
||||||
if ( $state = $sth->fetchrow_hashref() ) {
|
|
||||||
#$state->{Name} = $command;
|
|
||||||
$state->{Definitions} = [];
|
$state->{Definitions} = [];
|
||||||
foreach( split(',', $state->{Definition}) ) {
|
foreach (split(',', $state->{Definition})) {
|
||||||
my ( $id, $function, $enabled ) = split(':', $_);
|
my @state = split(':', $_);
|
||||||
push( @{$state->{Definitions}},
|
my ($id, $capturing, $analysing, $recording);
|
||||||
{ Id=>$id, Function=>$function, Enabled=>$enabled }
|
if (@state == 3) {
|
||||||
);
|
($id, my $function, my $enabled) = @state;
|
||||||
}
|
if (!$enabled) {
|
||||||
|
($capturing, $analysing, $recording) = ('None','None','None');
|
||||||
|
} elsif ($function eq 'None') {
|
||||||
|
($capturing, $analysing, $recording) = ('None','None','None');
|
||||||
|
} elsif ($function eq 'Monitor') {
|
||||||
|
($capturing, $analysing, $recording) = ('Always','None','None');
|
||||||
|
} elsif ($function eq 'Modect') {
|
||||||
|
($capturing, $analysing, $recording) = ('Always','Always','OnMotion');
|
||||||
|
} elsif ($function eq 'Mocord') {
|
||||||
|
($capturing, $analysing, $recording) = ('Always','Always','OnMotion');
|
||||||
|
} elsif ($function eq 'Record') {
|
||||||
|
($capturing, $analysing, $recording) = ('Always','Always','Always');
|
||||||
|
} else {
|
||||||
|
Error("Unknown function $function, defaulting to Mocord");
|
||||||
|
}
|
||||||
|
} elsif (@state == 4) {
|
||||||
|
($id, $capturing, $analysing, $capturing) = @state;
|
||||||
|
} else {
|
||||||
|
Error("Unknown state in @state");
|
||||||
|
}
|
||||||
|
push @{$state->{Definitions}}, {Id=>$id, Capturing=>$capturing, Analysing=>$analysing, Recording=>$recording};
|
||||||
|
} # end foreach state definition
|
||||||
$store_state = $command; # PP - Remember the name that was passed to search in DB
|
$store_state = $command; # PP - Remember the name that was passed to search in DB
|
||||||
$command = 'state';
|
$command = 'state';
|
||||||
} else {
|
} else {
|
||||||
$command = undef;
|
$command = undef;
|
||||||
}
|
}
|
||||||
$sth->finish();
|
|
||||||
} # end if not one of the usual commands
|
} # end if not one of the usual commands
|
||||||
|
|
||||||
if ( !$command ) {
|
if ( !$command ) {
|
||||||
|
@ -87,8 +103,7 @@ if ( !$command ) {
|
||||||
isActiveSanityCheck();
|
isActiveSanityCheck();
|
||||||
|
|
||||||
# Move to the right place
|
# Move to the right place
|
||||||
chdir($Config{ZM_PATH_WEB})
|
chdir($Config{ZM_PATH_WEB}) or Fatal("Can't chdir to $Config{ZM_PATH_WEB}: $!");
|
||||||
or Fatal("Can't chdir to '$Config{ZM_PATH_WEB}': $!");
|
|
||||||
|
|
||||||
my $dbg_id = '';
|
my $dbg_id = '';
|
||||||
|
|
||||||
|
@ -98,42 +113,33 @@ my $retval = 0;
|
||||||
|
|
||||||
if ( $command eq 'state' ) {
|
if ( $command eq 'state' ) {
|
||||||
Info("Updating DB: $state->{Name}");
|
Info("Updating DB: $state->{Name}");
|
||||||
my $sql = 'SELECT * FROM `Monitors`' . ($Config{ZM_SERVER_ID} ? ' WHERE `ServerId`=?' : '' ) .' ORDER BY `Id` ASC';
|
foreach my $monitor (ZoneMinder::Monitor->find(
|
||||||
my $sth = $dbh->prepare_cached($sql)
|
($Config{ZM_SERVER_ID} ? (ServerId=>$Config{ZM_SERVER_ID}) : () ), order=>'Id ASC')
|
||||||
or Fatal("Can't prepare '$sql': ".$dbh->errstr());
|
) {
|
||||||
my $res = $sth->execute($Config{ZM_SERVER_ID} ? $Config{ZM_SERVER_ID}: ())
|
|
||||||
or Fatal("Can't execute: ".$sth->errstr());
|
|
||||||
while ( my $monitor = $sth->fetchrow_hashref() ) {
|
|
||||||
foreach my $definition ( @{$state->{Definitions}} ) {
|
foreach my $definition ( @{$state->{Definitions}} ) {
|
||||||
|
# FIXME WHY a REGEXP
|
||||||
if ( $monitor->{Id} =~ /^$definition->{Id}$/ ) {
|
if ( $monitor->{Id} =~ /^$definition->{Id}$/ ) {
|
||||||
$monitor->{NewFunction} = $definition->{Function};
|
$monitor->{NewFunction} = $definition->{Function};
|
||||||
$monitor->{NewEnabled} = $definition->{Enabled};
|
$monitor->{NewEnabled} = $definition->{Enabled};
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
}
|
if (
|
||||||
next if ! exists $monitor->{NewFunction};
|
($monitor->{Capturing} ne $definition->{Capturing})
|
||||||
$monitor->{NewFunction} = 'None' if !$monitor->{NewFunction};
|
or
|
||||||
$monitor->{NewEnabled} = 0 if !$monitor->{NewEnabled};
|
($monitor->{Analysing} ne $definition->{Analysing})
|
||||||
if ( $monitor->{Function} ne $monitor->{NewFunction}
|
or
|
||||||
|| $monitor->{Enabled} ne $monitor->{NewEnabled}
|
($monitor->{Recording} ne $definition->{Recording})
|
||||||
) {
|
) {
|
||||||
my $sql = 'UPDATE `Monitors` SET `Function`=?, `Enabled`=? WHERE `Id`=?';
|
$monitor->save({ map { $_ => $definition{$_} } qw(Capturing Analysing Recording) });
|
||||||
my $sth = $dbh->prepare_cached($sql)
|
last; # definition
|
||||||
or Fatal("Can't prepare '$sql': ".$dbh->errstr());
|
} # end if
|
||||||
my $res = $sth->execute($monitor->{NewFunction}, $monitor->{NewEnabled}, $monitor->{Id})
|
} # end foreach definition
|
||||||
or Fatal("Can't execute: ".$sth->errstr());
|
|
||||||
} # end if change of function or enablement
|
|
||||||
} # end foreach monitor
|
} # end foreach monitor
|
||||||
$sth->finish();
|
|
||||||
|
|
||||||
# PP - Now mark a specific state as active
|
# PP - Now mark a specific state as active
|
||||||
resetStates();
|
resetStates();
|
||||||
Info("Marking $store_state as Enabled");
|
Info("Marking $store_state as Enabled");
|
||||||
$sql = 'UPDATE `States` SET `IsActive` = 1 WHERE `Name` = ?';
|
$state->save({IsActive=>1});
|
||||||
$sth = $dbh->prepare_cached($sql)
|
|
||||||
or Fatal("Can't prepare '$sql': ".$dbh->errstr());
|
|
||||||
$res = $sth->execute($store_state)
|
|
||||||
or Fatal("Can't execute: ".$sth->errstr());
|
|
||||||
|
|
||||||
# PP - zero out other states isActive
|
# PP - zero out other states isActive
|
||||||
$command = 'restart';
|
$command = 'restart';
|
||||||
|
@ -199,63 +205,46 @@ if ( $command =~ /^(?:start|restart)$/ ) {
|
||||||
runCommand('zmdc.pl startup');
|
runCommand('zmdc.pl startup');
|
||||||
|
|
||||||
my $Server = undef;
|
my $Server = undef;
|
||||||
my $sql;
|
my @monitors;
|
||||||
my @values;
|
|
||||||
if ( $Config{ZM_SERVER_ID} ) {
|
if ( $Config{ZM_SERVER_ID} ) {
|
||||||
require ZoneMinder::Server;
|
require ZoneMinder::Server;
|
||||||
Info("Multi-server configuration detected. Starting up services for server $Config{ZM_SERVER_ID}");
|
Info("Multi-server configuration detected. Starting up services for server $Config{ZM_SERVER_ID}");
|
||||||
$Server = new ZoneMinder::Server($Config{ZM_SERVER_ID});
|
$Server = new ZoneMinder::Server($Config{ZM_SERVER_ID});
|
||||||
$sql = 'SELECT * FROM `Monitors` WHERE `ServerId`=?';
|
@monitors = ZoneMinder::Monitor->find(ServerId=>$Config{ZM_SERVER_ID});
|
||||||
@values = ( $Config{ZM_SERVER_ID} );
|
|
||||||
} else {
|
} else {
|
||||||
Info('Single server configuration detected. Starting up services.');
|
Info('Single server configuration detected. Starting up services.');
|
||||||
$sql = 'SELECT * FROM `Monitors`';
|
@monitors = ZoneMinder::Monitor->find(ServerId=>$Config{ZM_SERVER_ID});
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
foreach my $monitor (@monitors) {
|
||||||
my $sth = $dbh->prepare_cached($sql)
|
if ( $monitor->{Capturing} ne 'None' && $monitor->{Type} ne 'WebSite' ) {
|
||||||
or Fatal("Can't prepare '$sql': ".$dbh->errstr());
|
if ( $monitor->{Type} eq 'Local' ) {
|
||||||
my $res = $sth->execute(@values)
|
runCommand("zmdc.pl start zmc -d $monitor->{Device}");
|
||||||
or Fatal("Can't execute: ".$sth->errstr());
|
} else {
|
||||||
while( my $monitor = $sth->fetchrow_hashref() ) {
|
runCommand("zmdc.pl start zmc -m $monitor->{Id}");
|
||||||
if ( $monitor->{Function} ne 'None' && $monitor->{Type} ne 'WebSite' ) {
|
|
||||||
if ( $monitor->{Type} eq 'Local' ) {
|
|
||||||
runCommand("zmdc.pl start zmc -d $monitor->{Device}");
|
|
||||||
} else {
|
|
||||||
runCommand("zmdc.pl start zmc -m $monitor->{Id}");
|
|
||||||
}
|
|
||||||
if ( $Config{ZM_OPT_CONTROL} ) {
|
|
||||||
if ( $monitor->{Controllable} ) {
|
|
||||||
runCommand("zmdc.pl start zmcontrol.pl --id $monitor->{Id}");
|
|
||||||
if ( $monitor->{TrackMotion} ) {
|
|
||||||
if ( $monitor->{Function} eq 'Modect' || $monitor->{Function} eq 'Mocord' ) {
|
|
||||||
runCommand("zmdc.pl start zmtrack.pl -m $monitor->{Id}");
|
|
||||||
} else {
|
|
||||||
Warning('Monitor is set to track motion, but does not have motion detection enabled.');
|
|
||||||
} # end if Has motion enabled
|
|
||||||
} # end if track motion
|
|
||||||
} # end if controllable
|
|
||||||
} # end if ZM_OPT_CONTROL
|
|
||||||
} # end if function is not none or Website
|
|
||||||
} # end foreach monitor
|
|
||||||
$sth->finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
my $sql = 'SELECT `Id` FROM `Filters` WHERE `Background`=1';
|
|
||||||
my $sth = $dbh->prepare_cached($sql)
|
|
||||||
or Fatal("Can't prepare '$sql': ".$dbh->errstr());
|
|
||||||
my $res = $sth->execute()
|
|
||||||
or Fatal("Can't execute: ".$sth->errstr());
|
|
||||||
if ( $sth->rows ) {
|
|
||||||
while( my $filter = $sth->fetchrow_hashref() ) {
|
|
||||||
# This is now started unconditionally
|
|
||||||
runCommand("zmdc.pl start zmfilter.pl --filter_id=$$filter{Id} --daemon");
|
|
||||||
}
|
}
|
||||||
} else {
|
if ( $Config{ZM_OPT_CONTROL} ) {
|
||||||
runCommand('zmdc.pl start zmfilter.pl');
|
if ( $monitor->{Controllable} ) {
|
||||||
|
runCommand("zmdc.pl start zmcontrol.pl --id $monitor->{Id}");
|
||||||
|
if ( $monitor->{TrackMotion} ) {
|
||||||
|
if ( $monitor->{Function} eq 'Modect' || $monitor->{Function} eq 'Mocord' ) {
|
||||||
|
runCommand("zmdc.pl start zmtrack.pl -m $monitor->{Id}");
|
||||||
|
} else {
|
||||||
|
Warning('Monitor is set to track motion, but does not have motion detection enabled.');
|
||||||
|
} # end if Has motion enabled
|
||||||
|
} # end if track motion
|
||||||
|
} # end if controllable
|
||||||
|
} # end if ZM_OPT_CONTROL
|
||||||
|
} # end if capturing is not none or Website
|
||||||
|
} # end foreach monitor
|
||||||
|
|
||||||
|
my @filters = ZoneMinder::Filter->find(Background=>1);
|
||||||
|
if (@filters) {
|
||||||
|
foreach my $filter (@filters) {
|
||||||
|
runCommand("zmdc.pl start zmfilter.pl --filter_id=$$filter{Id} --daemon");
|
||||||
}
|
}
|
||||||
$sth->finish();
|
} else {
|
||||||
|
runCommand('zmdc.pl start zmfilter.pl');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $Config{ZM_RUN_AUDIT} ) {
|
if ( $Config{ZM_RUN_AUDIT} ) {
|
||||||
|
@ -283,8 +272,8 @@ if ( $command =~ /^(?:start|restart)$/ ) {
|
||||||
runCommand('zmdc.pl start zmtelemetry.pl');
|
runCommand('zmdc.pl start zmtelemetry.pl');
|
||||||
}
|
}
|
||||||
if ($Config{ZM_OPT_USE_EVENTNOTIFICATION} ) {
|
if ($Config{ZM_OPT_USE_EVENTNOTIFICATION} ) {
|
||||||
if ( $Server and exists $$Server{'zmeventnotification'} and ! $$Server{'zmeventnotification'} ) {
|
if ( $Server and exists $$Server{zmeventnotification} and ! $$Server{zmeventnotification} ) {
|
||||||
Debug("Not running zmnotification.pl because it is turned off for this server.");
|
Debug('Not running zmnotification.pl because it is turned off for this server.');
|
||||||
} else {
|
} else {
|
||||||
runCommand('zmdc.pl start zmeventnotification.pl');
|
runCommand('zmdc.pl start zmeventnotification.pl');
|
||||||
}
|
}
|
||||||
|
@ -302,11 +291,11 @@ if ( $command =~ /^(?:start|restart)$/ ) {
|
||||||
}
|
}
|
||||||
} # end if command is start or restart
|
} # end if command is start or restart
|
||||||
|
|
||||||
if ( $command eq 'status' ) {
|
if ($command eq 'status') {
|
||||||
my $status = runCommand('zmdc.pl check');
|
my $status = runCommand('zmdc.pl check');
|
||||||
|
|
||||||
print(STDOUT $status."\n");
|
print(STDOUT $status."\n");
|
||||||
} elsif ( $command eq 'logrot' ) {
|
} elsif ($command eq 'logrot') {
|
||||||
runCommand('zmdc.pl logrot');
|
runCommand('zmdc.pl logrot');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,42 +303,31 @@ exit($retval);
|
||||||
|
|
||||||
# PP - Make sure isActive is on and only one
|
# PP - Make sure isActive is on and only one
|
||||||
sub isActiveSanityCheck {
|
sub isActiveSanityCheck {
|
||||||
|
|
||||||
Info('Sanity checking States table...');
|
Info('Sanity checking States table...');
|
||||||
$dbh = zmDbConnect() if ! $dbh;
|
$dbh = zmDbConnect() if ! $dbh;
|
||||||
|
|
||||||
# PP - First, make sure default exists and there is only one
|
# PP - First, make sure default exists and there is only one
|
||||||
my $sql = 'SELECT `Name` FROM `States` WHERE `Name`=?';
|
my @states = ZoneMinder::State->find(Name=>'default', order=>'Id ASC');
|
||||||
my $sth = $dbh->prepare_cached($sql)
|
|
||||||
or Fatal("Can't prepare '$sql': ".$dbh->errstr());
|
|
||||||
my $res = $sth->execute('default')
|
|
||||||
or Fatal("Can't execute: ".$sth->errstr());
|
|
||||||
|
|
||||||
if ( $sth->rows != 1 ) {
|
|
||||||
# PP - no row, or too many rows. Either case is an error
|
# PP - no row, or too many rows. Either case is an error
|
||||||
Info('Fixing States table - either no default state or duplicate default states');
|
|
||||||
if ( $sth->rows ) {
|
my $default_state;
|
||||||
$dbh->do('DELETE FROM `States` WHERE `Name`=\'default\'') or Fatal("Can't execute: ".$dbh->errstr());
|
while (@states > 1) {
|
||||||
}
|
my $state = shift @states;
|
||||||
$dbh->do('INSERT INTO `States` (`Name`,`Definition`,`IsActive`) VALUES (\'default\',\'\',\'1\');')
|
$state->delete();
|
||||||
or Fatal("Can't execute: ".$dbh->errstr());
|
}
|
||||||
|
if (!@states) {
|
||||||
|
$default_state = new ZoneMinder::State();
|
||||||
|
$default_state->save({Name=>'default', Definition=>'', IsActive=>1});
|
||||||
|
} else {
|
||||||
|
$default_state = shift @states;
|
||||||
}
|
}
|
||||||
$sth->finish();
|
|
||||||
|
|
||||||
# PP - Now make sure no two states have IsActive=1
|
@states = ZoneMinder::State->find(IsActive=>1);
|
||||||
$sql = 'SELECT `Name` FROM `States` WHERE `IsActive`=1';
|
if (@states != 1) {
|
||||||
$sth = $dbh->prepare_cached($sql)
|
|
||||||
or Fatal("Can't prepare '$sql': ".$dbh->errstr());
|
|
||||||
$res = $sth->execute()
|
|
||||||
or Fatal("Can't execute: ".$sth->errstr());
|
|
||||||
|
|
||||||
if ( $sth->rows != 1 ) {
|
|
||||||
Info('Fixing States table so only one run state is active');
|
Info('Fixing States table so only one run state is active');
|
||||||
resetStates();
|
resetStates();
|
||||||
$dbh->do('UPDATE `States` SET `IsActive`=1 WHERE `Name`=\'default\'')
|
$default_state->save({IsActive=>1});
|
||||||
or Fatal("Can't execute: ".$dbh->errstr());
|
|
||||||
}
|
}
|
||||||
$sth->finish();
|
|
||||||
} # end sub isActiveSanityCheck
|
} # end sub isActiveSanityCheck
|
||||||
|
|
||||||
# PP - zeroes out isActive for all states
|
# PP - zeroes out isActive for all states
|
||||||
|
|
|
@ -263,7 +263,7 @@ sub countQuery {
|
||||||
sub getMonitorRef {
|
sub getMonitorRef {
|
||||||
my $dbh = shift;
|
my $dbh = shift;
|
||||||
|
|
||||||
my $sql = 'SELECT `Id`,`Name`,`Type`,`Function`,`Width`,`Height`,`Colours`,`MaxFPS`,`AlarmMaxFPS`,
|
my $sql = 'SELECT `Id`,`Name`,`Type`,`Capturing`,`Analysing`,`Recording`,`Width`,`Height`,`Colours`,`MaxFPS`,`AlarmMaxFPS`,
|
||||||
(SELECT Name FROM Manufacturers WHERE Manufacturers.Id = ManufacturerId),
|
(SELECT Name FROM Manufacturers WHERE Manufacturers.Id = ManufacturerId),
|
||||||
(SELECT Name FROM Models WHERE Models.Id = ModelId)
|
(SELECT Name FROM Models WHERE Models.Id = ModelId)
|
||||||
FROM `Monitors`';
|
FROM `Monitors`';
|
||||||
|
|
|
@ -302,9 +302,9 @@ while (!$zm_terminate) {
|
||||||
} elsif (@needsReload) {
|
} elsif (@needsReload) {
|
||||||
foreach my $monitor (@needsReload) {
|
foreach my $monitor (@needsReload) {
|
||||||
$monitor = $monitors{$monitor->Id()} = ZoneMinder::Monitor->find_one(Id=>$monitor->Id());
|
$monitor = $monitors{$monitor->Id()} = ZoneMinder::Monitor->find_one(Id=>$monitor->Id());
|
||||||
if ( $$monitor{Function} eq 'None' ) {
|
if ($$monitor{Capturing} eq 'None') {
|
||||||
delete $monitors{$monitor->Id()};
|
delete $monitors{$monitor->Id()};
|
||||||
} elsif ( $Config{ZM_SERVER_ID} and ($$monitor{ServerId} != $Config{ZM_SERVER_ID})) {
|
} elsif ($Config{ZM_SERVER_ID} and ($$monitor{ServerId} != $Config{ZM_SERVER_ID})) {
|
||||||
delete $monitors{$monitor->Id()};
|
delete $monitors{$monitor->Id()};
|
||||||
} else {
|
} else {
|
||||||
if ($monitor->connect()) {
|
if ($monitor->connect()) {
|
||||||
|
@ -312,7 +312,7 @@ while (!$zm_terminate) {
|
||||||
$monitor->{LastEvent} = zmGetLastEvent($monitor);
|
$monitor->{LastEvent} = zmGetLastEvent($monitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} # end foreach @needsREload
|
||||||
@needsReload = ();
|
@needsReload = ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,11 +326,10 @@ sub loadMonitors {
|
||||||
$monitor_reload_time = time();
|
$monitor_reload_time = time();
|
||||||
|
|
||||||
%monitors = ();
|
%monitors = ();
|
||||||
|
|
||||||
foreach my $monitor ( ZoneMinder::Monitor->find(
|
foreach my $monitor ( ZoneMinder::Monitor->find(
|
||||||
Function=>['Modect','Mocord','Nodect','Record'],
|
'Capturing !=' => 'None',
|
||||||
($Config{ZM_SERVER_ID} ? (ServerId=>$Config{ZM_SERVER_ID}) : ()),
|
($Config{ZM_SERVER_ID} ? (ServerId=>$Config{ZM_SERVER_ID}) : ()),
|
||||||
)) {
|
)) {
|
||||||
if ($monitor->connect()) { # This will re-init shared memory
|
if ($monitor->connect()) { # This will re-init shared memory
|
||||||
$monitor->{LastState} = zmGetMonitorState($monitor);
|
$monitor->{LastState} = zmGetMonitorState($monitor);
|
||||||
$monitor->{LastEvent} = zmGetLastEvent($monitor);
|
$monitor->{LastEvent} = zmGetLastEvent($monitor);
|
||||||
|
|
|
@ -90,7 +90,7 @@ while (!$zm_terminate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $monitor (ZoneMinder::Monitor->find($Config{ZM_SERVER_ID} ? (ServerId=>$Config{ZM_SERVER_ID}) : ())) {
|
foreach my $monitor (ZoneMinder::Monitor->find($Config{ZM_SERVER_ID} ? (ServerId=>$Config{ZM_SERVER_ID}) : ())) {
|
||||||
next if $monitor->{Function} eq 'None';
|
next if $monitor->{Capturing} eq 'None' ;
|
||||||
next if $monitor->{Type} eq 'WebSite';
|
next if $monitor->{Type} eq 'WebSite';
|
||||||
next if $monitor->{Capturing} eq 'Ondemand';
|
next if $monitor->{Capturing} eq 'Ondemand';
|
||||||
my $now = time();
|
my $now = time();
|
||||||
|
@ -128,8 +128,8 @@ while (!$zm_terminate) {
|
||||||
&&($monitor->{MaxFPS}>0)
|
&&($monitor->{MaxFPS}>0)
|
||||||
&&($monitor->{MaxFPS}<1)
|
&&($monitor->{MaxFPS}<1)
|
||||||
) ? (3/$monitor->{MaxFPS})
|
) ? (3/$monitor->{MaxFPS})
|
||||||
: $Config{ZM_WATCH_MAX_DELAY}
|
: $Config{ZM_WATCH_MAX_DELAY};
|
||||||
;
|
|
||||||
my $image_delay = $now - $capture_time;
|
my $image_delay = $now - $capture_time;
|
||||||
Debug("Monitor $monitor->{Id} last captured $image_delay seconds ago, max is $max_image_delay");
|
Debug("Monitor $monitor->{Id} last captured $image_delay seconds ago, max is $max_image_delay");
|
||||||
if ($image_delay > $max_image_delay) {
|
if ($image_delay > $max_image_delay) {
|
||||||
|
@ -140,7 +140,7 @@ while (!$zm_terminate) {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($monitor->{Function} ne 'Monitor') {
|
if ($monitor->{Analysing} ne 'None') {
|
||||||
# Now check analysis thread
|
# Now check analysis thread
|
||||||
# Check we have got an image recently
|
# Check we have got an image recently
|
||||||
my $image_time = zmGetLastReadTime($monitor);
|
my $image_time = zmGetLastReadTime($monitor);
|
||||||
|
@ -168,9 +168,7 @@ while (!$zm_terminate) {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} # end if check analysis daemon
|
} # end if check analysis daemon
|
||||||
|
|
||||||
} # end foreach monitor
|
} # end foreach monitor
|
||||||
|
|
||||||
sleep($Config{ZM_WATCH_CHECK_INTERVAL});
|
sleep($Config{ZM_WATCH_CHECK_INTERVAL});
|
||||||
|
|
|
@ -416,8 +416,7 @@ sub loadTasks {
|
||||||
|
|
||||||
my $sql = 'SELECT M.*,T.* FROM Monitors as M
|
my $sql = 'SELECT M.*,T.* FROM Monitors as M
|
||||||
INNER JOIN TriggersX10 as T on (M.Id = T.MonitorId)
|
INNER JOIN TriggersX10 as T on (M.Id = T.MonitorId)
|
||||||
WHERE find_in_set(M.`Function`, \'Modect,Record,Mocord,Nodect\')
|
WHERE M.Capturing != \'None\'
|
||||||
AND M.`Enabled` = 1
|
|
||||||
AND find_IN_set(\'X10\', M.Triggers)';
|
AND find_IN_set(\'X10\', M.Triggers)';
|
||||||
my $sth = $dbh->prepare_cached( $sql )
|
my $sth = $dbh->prepare_cached( $sql )
|
||||||
or Fatal("Can't prepare '$sql': ".$dbh->errstr());
|
or Fatal("Can't prepare '$sql': ".$dbh->errstr());
|
||||||
|
|
Loading…
Reference in New Issue