Merge branch 'storageareas' of github.com:ConnorTechnology/ZoneMinder into storageareas

This commit is contained in:
Isaac Connor 2018-04-25 12:36:22 -04:00
commit 2f9e69d959
10 changed files with 209 additions and 185 deletions

View File

@ -104,23 +104,23 @@ my @daemons = (
'zmtelemetry.pl' 'zmtelemetry.pl'
); );
if ($Config{ZM_OPT_USE_EVENTNOTIFICATION}) { if ( $Config{ZM_OPT_USE_EVENTNOTIFICATION} ) {
push @daemons,'zmeventnotification.pl'; push @daemons,'zmeventnotification.pl';
} }
my $command = shift @ARGV; my $command = shift @ARGV;
if( ! $command ) { if ( !$command ) {
print( STDERR "No command given\n" ); print(STDERR "No command given\n");
pod2usage(-exitstatus => -1); pod2usage(-exitstatus => -1);
} }
if ( $command eq 'version' ) { if ( $command eq 'version' ) {
print ZoneMinder::Base::ZM_VERSION."\n"; print ZoneMinder::Base::ZM_VERSION."\n";
exit( 0 ); exit(0);
} }
my $needs_daemon = $command !~ /(?:startup|shutdown|status|check|logrot|version)/; my $needs_daemon = $command !~ /(?:startup|shutdown|status|check|logrot|version)/;
my $daemon = shift( @ARGV ); my $daemon = shift @ARGV;
if ( $needs_daemon && ! $daemon ) { if ( $needs_daemon && ! $daemon ) {
print( STDERR "No daemon given\n" ); print(STDERR "No daemon given\n");
pod2usage(-exitstatus => -1); pod2usage(-exitstatus => -1);
} }
my @args; my @args;
@ -130,7 +130,7 @@ if ( $needs_daemon ) {
if ( $daemon =~ /^${daemon_patt}$/ ) { if ( $daemon =~ /^${daemon_patt}$/ ) {
$daemon = $1; $daemon = $1;
} else { } else {
print( STDERR "Invalid daemon '$daemon' specified" ); print(STDERR "Invalid daemon '$daemon' specified");
pod2usage(-exitstatus => -1); pod2usage(-exitstatus => -1);
} }
} }
@ -141,19 +141,19 @@ foreach my $arg ( @ARGV ) {
if ( $arg =~ /^(-{0,2}[\w\/?&=.-]+)$/ ) { if ( $arg =~ /^(-{0,2}[\w\/?&=.-]+)$/ ) {
push( @args, $1 ); push( @args, $1 );
} else { } else {
print( STDERR "Bogus argument '$arg' found" ); print(STDERR "Bogus argument '$arg' found");
exit( -1 ); exit(-1);
} }
} }
my $dbh = zmDbConnect(); my $dbh = zmDbConnect();
socket( CLIENT, PF_UNIX, SOCK_STREAM, 0 ) or Fatal( "Can't open socket: $!" ); socket(CLIENT, PF_UNIX, SOCK_STREAM, 0) or Fatal("Can't open socket: $!");
my $saddr = sockaddr_un( SOCK_FILE ); my $saddr = sockaddr_un(SOCK_FILE);
my $server_up = connect( CLIENT, $saddr ); my $server_up = connect(CLIENT, $saddr);
if ( ! $server_up ) { if ( !$server_up ) {
if ( $Config{ZM_SERVER_ID} ) { if ( $Config{ZM_SERVER_ID} ) {
use Sys::MemInfo qw(totalmem freemem totalswap freeswap); use Sys::MemInfo qw(totalmem freemem totalswap freeswap);
use ZoneMinder::Server qw(CpuLoad); use ZoneMinder::Server qw(CpuLoad);
@ -168,16 +168,16 @@ if ( ! $server_up ) {
exit(); exit();
} }
if ( $command eq 'check' ) { if ( $command eq 'check' ) {
print( "stopped\n" ); print("stopped\n");
exit(); exit();
} elsif ( $command ne 'startup' ) { } elsif ( $command ne 'startup' ) {
print( "Unable to connect to server using socket at " . SOCK_FILE . "\n" ); print("Unable to connect to server using socket at " . SOCK_FILE . "\n");
exit( -1 ); exit( -1 );
} }
# The server isn't there # The server isn't there
print( "Starting server\n" ); print("Starting server\n");
close( CLIENT ); close(CLIENT);
if ( my $cpid = fork() ) { if ( my $cpid = fork() ) {
# Parent process just sleep and fall through # Parent process just sleep and fall through
@ -185,7 +185,7 @@ if ( ! $server_up ) {
# I'm still not sure why we need to re-init the logs # I'm still not sure why we need to re-init the logs
logInit(); logInit();
socket( CLIENT, PF_UNIX, SOCK_STREAM, 0 ) or Fatal( "Can't open socket: $!" ); socket(CLIENT, PF_UNIX, SOCK_STREAM, 0) or Fatal("Can't open socket: $!");
my $attempts = 0; my $attempts = 0;
while( !connect(CLIENT, $saddr) ) { while( !connect(CLIENT, $saddr) ) {
$attempts++; $attempts++;
@ -209,7 +209,6 @@ if ( ($command eq 'check') && !$daemon ) {
} }
# The server is there, connect to it # The server is there, connect to it
#print( "Writing commands\n" );
CLIENT->autoflush(); CLIENT->autoflush();
my $message = join(';', $command, ( $daemon ? $daemon : () ), @args ); my $message = join(';', $command, ( $daemon ? $daemon : () ), @args );
print(CLIENT $message); print(CLIENT $message);
@ -218,9 +217,7 @@ while( my $line = <CLIENT> ) {
chomp($line); chomp($line);
print("$line\n"); print("$line\n");
} }
# And we're done!
close(CLIENT); close(CLIENT);
#print( "Finished writing, bye\n" );
exit; exit;
@ -248,35 +245,35 @@ our %terminating_processes;
sub run { sub run {
my $fd = 0; my $fd = 0;
while( $fd < POSIX::sysconf( &POSIX::_SC_OPEN_MAX ) ) { while( $fd < POSIX::sysconf(&POSIX::_SC_OPEN_MAX) ) {
POSIX::close( $fd++ ); POSIX::close($fd++);
} }
setpgrp(); setpgrp();
logInit(); logInit();
dPrint( ZoneMinder::Logger::INFO, 'Server starting at ' dPrint(ZoneMinder::Logger::INFO, 'Server starting at '
.strftime( '%y/%m/%d %H:%M:%S', localtime() ) .strftime('%y/%m/%d %H:%M:%S', localtime())
."\n" ."\n"
); );
if ( open( my $PID, '>', ZM_PID ) ) { if ( open(my $PID, '>', ZM_PID) ) {
print( $PID $$ ); print($PID $$);
close( $PID ); close($PID);
} else { } else {
Error( "Can't open pid file at " . ZM_PID ); Error("Can't open pid file at " . ZM_PID);
} }
# Tell any existing processes to die, wait 1 second between TERM and KILL # Tell any existing processes to die, wait 1 second between TERM and KILL
killAll( 1 ); killAll(1);
dPrint( ZoneMinder::Logger::INFO, 'Socket should be open at ' .main::SOCK_FILE ); dPrint(ZoneMinder::Logger::INFO, 'Socket should be open at ' .main::SOCK_FILE);
my $dbh = zmDbConnect(1); my $dbh = zmDbConnect(1);
socket( SERVER, PF_UNIX, SOCK_STREAM, 0 ) or Fatal( "Can't open socket: $!" ); socket(SERVER, PF_UNIX, SOCK_STREAM, 0) or Fatal("Can't open socket: $!");
unlink( main::SOCK_FILE ) or Error( 'Unable to unlink ' . main::SOCK_FILE .". Error message was: $!" ) if -e main::SOCK_FILE; unlink(main::SOCK_FILE) or Error('Unable to unlink ' . main::SOCK_FILE .". Error message was: $!") if -e main::SOCK_FILE;
bind( SERVER, $saddr ) or Fatal( "Can't bind to " . main::SOCK_FILE . ": $!" ); bind(SERVER, $saddr) or Fatal("Can't bind to " . main::SOCK_FILE . ": $!");
listen( SERVER, SOMAXCONN ) or Fatal( "Can't listen: $!" ); listen(SERVER, SOMAXCONN) or Fatal("Can't listen: $!");
$SIG{CHLD} = \&reaper; $SIG{CHLD} = \&reaper;
$SIG{INT} = \&shutdownAll; $SIG{INT} = \&shutdownAll;
@ -285,7 +282,7 @@ sub run {
$SIG{HUP} = \&logrot; $SIG{HUP} = \&logrot;
my $rin = ''; my $rin = '';
vec( $rin, fileno(SERVER), 1 ) = 1; vec($rin, fileno(SERVER), 1) = 1;
my $win = $rin; my $win = $rin;
my $ein = $win; my $ein = $win;
my $timeout = 1; my $timeout = 1;
@ -294,8 +291,8 @@ sub run {
if ( $Config{ZM_SERVER_ID} ) { if ( $Config{ZM_SERVER_ID} ) {
require ZoneMinder::Server; require ZoneMinder::Server;
$Server = new ZoneMinder::Server( $Config{ZM_SERVER_ID} ); $Server = new ZoneMinder::Server($Config{ZM_SERVER_ID});
dPrint( ZoneMinder::Logger::INFO, 'Loading Server record have ' . $$Server{Name} ); dPrint(ZoneMinder::Logger::INFO, 'Loading Server record have ' . $$Server{Name});
} }
while( 1 ) { while( 1 ) {
@ -311,41 +308,41 @@ sub run {
} }
$secs_count += 1; $secs_count += 1;
} }
my $nfound = select( my $rout = $rin, undef, undef, $timeout ); my $nfound = select(my $rout = $rin, undef, undef, $timeout);
if ( $nfound > 0 ) { if ( $nfound > 0 ) {
if ( vec( $rout, fileno(SERVER), 1 ) ) { if ( vec($rout, fileno(SERVER), 1) ) {
my $paddr = accept( CLIENT, SERVER ); my $paddr = accept(CLIENT, SERVER);
my $message = <CLIENT>; my $message = <CLIENT>;
next if !$message; next if !$message;
my ( $command, $daemon, @args ) = split( /;/, $message ); my ( $command, $daemon, @args ) = split(';', $message);
if ( $command eq 'start' ) { if ( $command eq 'start' ) {
start( $daemon, @args ); start($daemon, @args);
} elsif ( $command eq 'stop' ) { } elsif ( $command eq 'stop' ) {
stop( $daemon, @args ); stop($daemon, @args);
} elsif ( $command eq 'restart' ) { } elsif ( $command eq 'restart' ) {
restart( $daemon, @args ); restart($daemon, @args);
} elsif ( $command eq 'reload' ) { } elsif ( $command eq 'reload' ) {
reload( $daemon, @args ); reload($daemon, @args);
} elsif ( $command eq 'startup' ) { } elsif ( $command eq 'startup' ) {
# Do nothing, this is all we're here for # Do nothing, this is all we're here for
dPrint( ZoneMinder::Logger::WARNING, "Already running, ignoring command '$command'\n" ); dPrint(ZoneMinder::Logger::WARNING, "Already running, ignoring command '$command'\n");
} elsif ( $command eq 'shutdown' ) { } elsif ( $command eq 'shutdown' ) {
shutdownAll(); shutdownAll();
} elsif ( $command eq 'check' ) { } elsif ( $command eq 'check' ) {
check( $daemon, @args ); check($daemon, @args);
} elsif ( $command eq 'status' ) { } elsif ( $command eq 'status' ) {
if ( $daemon ) { if ( $daemon ) {
status( $daemon, @args ); status($daemon, @args);
} else { } else {
status(); status();
} }
} elsif ( $command eq 'logrot' ) { } elsif ( $command eq 'logrot' ) {
logrot(); logrot();
} else { } else {
dPrint( ZoneMinder::Logger::ERROR, "Invalid command '$command'\n" ); dPrint(ZoneMinder::Logger::ERROR, "Invalid command '$command'\n");
} }
close(CLIENT); close(CLIENT);
} else { } else {
@ -370,18 +367,18 @@ sub run {
check_for_processes_to_kill(); check_for_processes_to_kill();
} # end while } # end while
dPrint( ZoneMinder::Logger::INFO, 'Server exiting at ' dPrint(ZoneMinder::Logger::INFO, 'Server exiting at '
.strftime( '%y/%m/%d %H:%M:%S', localtime() ) .strftime( '%y/%m/%d %H:%M:%S', localtime() )
."\n" ."\n"
); );
if ( $Config{ZM_SERVER_ID} ) { if ( $Config{ZM_SERVER_ID} ) {
$dbh = zmDbConnect() if ! $dbh->ping(); $dbh = zmDbConnect() if ! $dbh->ping();
if ( ! defined $dbh->do(q{UPDATE Servers SET Status='NotRunning' WHERE Id=?}, undef, $Config{ZM_SERVER_ID} ) ) { if ( ! defined $dbh->do(q{UPDATE Servers SET Status='NotRunning' WHERE Id=?}, undef, $Config{ZM_SERVER_ID}) ) {
Error("Failed Updating status of Server record for Id=$Config{ZM_SERVER_ID}".$dbh->errstr()); Error("Failed Updating status of Server record for Id=$Config{ZM_SERVER_ID}".$dbh->errstr());
} }
} }
unlink( main::SOCK_FILE ) or Error( 'Unable to unlink ' . main::SOCK_FILE .". Error message was: $!" ) if ( -e main::SOCK_FILE ); unlink(main::SOCK_FILE) or Error('Unable to unlink ' . main::SOCK_FILE .". Error message was: $!") if ( -e main::SOCK_FILE );
unlink( ZM_PID ) or Error( 'Unable to unlink ' . ZM_PID .". Error message was: $!" ) if ( -e ZM_PID ); unlink(ZM_PID) or Error('Unable to unlink ' . ZM_PID .". Error message was: $!") if ( -e ZM_PID );
exit(); exit();
} }
@ -398,15 +395,15 @@ sub dPrint {
print CLIENT @_ print CLIENT @_
} }
if ( $logLevel == ZoneMinder::Logger::DEBUG ) { if ( $logLevel == ZoneMinder::Logger::DEBUG ) {
Debug( @_ ); Debug(@_);
} elsif ( $logLevel == ZoneMinder::Logger::INFO ) { } elsif ( $logLevel == ZoneMinder::Logger::INFO ) {
Info( @_ ); Info(@_);
} elsif ( $logLevel == ZoneMinder::Logger::WARNING ) { } elsif ( $logLevel == ZoneMinder::Logger::WARNING ) {
Warning( @_ ); Warning(@_);
} elsif ( $logLevel == ZoneMinder::Logger::ERROR ) { } elsif ( $logLevel == ZoneMinder::Logger::ERROR ) {
Error( @_ ); Error(@_);
} elsif ( $logLevel == ZoneMinder::Logger::FATAL ) { } elsif ( $logLevel == ZoneMinder::Logger::FATAL ) {
Fatal( @_ ); Fatal(@_);
} }
} }
@ -414,61 +411,60 @@ sub start {
my $daemon = shift; my $daemon = shift;
my @args = @_; my @args = @_;
my $command = join(' ', $daemon, @args ); my $command = join(' ', $daemon, @args);
my $process = $cmd_hash{$command}; my $process = $cmd_hash{$command};
if ( !$process ) { if ( !$process ) {
# It's not running, or at least it's not been started by us # It's not running, or at least it's not been started by us
$process = { daemon=>$daemon, args=>\@args, command=>$command, keepalive=>!undef }; $process = { daemon=>$daemon, args=>\@args, command=>$command, keepalive=>!undef };
} elsif ( $process->{pid} && $pid_hash{$process->{pid}} ) { } elsif ( $process->{pid} && $pid_hash{$process->{pid}} ) {
dPrint( ZoneMinder::Logger::INFO, "'$process->{command}' already running at " dPrint(ZoneMinder::Logger::INFO, "'$process->{command}' already running at "
.strftime( '%y/%m/%d %H:%M:%S', localtime( $process->{started}) ) .strftime('%y/%m/%d %H:%M:%S', localtime($process->{started}))
.", pid = $process->{pid}\n" .", pid = $process->{pid}\n"
); );
return(); return;
} }
my $sigset = POSIX::SigSet->new; my $sigset = POSIX::SigSet->new;
my $blockset = POSIX::SigSet->new( SIGCHLD ); my $blockset = POSIX::SigSet->new( SIGCHLD );
sigprocmask( SIG_BLOCK, $blockset, $sigset ) or Fatal( "Can't block SIGCHLD: $!" ); sigprocmask(SIG_BLOCK, $blockset, $sigset) or Fatal("Can't block SIGCHLD: $!");
if ( my $cpid = fork() ) { if ( my $cpid = fork() ) {
logReinit(); logReinit();
$process->{pid} = $cpid; $process->{pid} = $cpid;
$process->{started} = time(); $process->{started} = time();
delete( $process->{pending} ); delete $process->{pending};
dPrint( ZoneMinder::Logger::INFO, "'$command' starting at " dPrint(ZoneMinder::Logger::INFO, "'$command' starting at "
.strftime( '%y/%m/%d %H:%M:%S', localtime( $process->{started}) ) .strftime('%y/%m/%d %H:%M:%S', localtime($process->{started}))
.", pid = $process->{pid}\n" .", pid = $process->{pid}\n"
); );
$cmd_hash{$process->{command}} = $pid_hash{$cpid} = $process; $cmd_hash{$process->{command}} = $pid_hash{$cpid} = $process;
sigprocmask( SIG_SETMASK, $sigset ) or Fatal( "Can't restore SIGCHLD: $!" ); sigprocmask(SIG_SETMASK, $sigset) or Fatal("Can't restore SIGCHLD: $!");
} elsif ( defined($cpid ) ) { } elsif ( defined($cpid) ) {
# Force reconnection to the db. # Force reconnection to the db.
$dbh = zmDbConnect(1); $dbh = zmDbConnect(1);
logReinit(); logReinit();
dPrint( ZoneMinder::Logger::INFO, "'".join( ' ', ( $daemon, @args ) ) dPrint(ZoneMinder::Logger::INFO, "'$command' started at "
."' started at " .strftime('%y/%m/%d %H:%M:%S', localtime())
.strftime( '%y/%m/%d %H:%M:%S', localtime() )
."\n" ."\n"
); );
if ( $daemon =~ /^${daemon_patt}$/ ) { if ( $daemon =~ /^${daemon_patt}$/ ) {
$daemon = $Config{ZM_PATH_BIN}.'/'.$1; $daemon = $Config{ZM_PATH_BIN}.'/'.$1;
} else { } else {
Fatal( "Invalid daemon '$daemon' specified" ); Fatal("Invalid daemon '$daemon' specified");
} }
my @good_args; my @good_args;
foreach my $arg ( @args ) { foreach my $arg ( @args ) {
# Detaint arguments, if they look ok # Detaint arguments, if they look ok
if ( $arg =~ /^(-{0,2}[\w\/?&=.-]+)$/ ) { if ( $arg =~ /^(-{0,2}[\w\/?&=.-]+)$/ ) {
push( @good_args, $1 ); push @good_args, $1;
} else { } else {
Fatal( "Bogus argument '$arg' found" ); Fatal("Bogus argument '$arg' found");
} }
} }
@ -476,8 +472,8 @@ sub start {
zmDbDisconnect(); zmDbDisconnect();
my $fd = 0; my $fd = 0;
while( $fd < POSIX::sysconf( &POSIX::_SC_OPEN_MAX ) ) { while( $fd < POSIX::sysconf(&POSIX::_SC_OPEN_MAX) ) {
POSIX::close( $fd++ ); POSIX::close($fd++);
} }
# Child process # Child process
@ -486,11 +482,11 @@ sub start {
$SIG{TERM} = 'DEFAULT'; $SIG{TERM} = 'DEFAULT';
$SIG{ABRT} = 'DEFAULT'; $SIG{ABRT} = 'DEFAULT';
exec( $daemon, @good_args ) or Fatal( "Can't exec: $!" ); exec($daemon, @good_args) or Fatal("Can't exec: $!");
} else { } else {
Fatal( "Can't fork: $!" ); Fatal("Can't fork: $!");
} }
} } # end sub start
# Sends the stop signal, without waiting around to see if the process died. # Sends the stop signal, without waiting around to see if the process died.
sub send_stop { sub send_stop {
@ -499,9 +495,9 @@ sub send_stop {
my $command = $process->{command}; my $command = $process->{command};
if ( $process->{pending} ) { if ( $process->{pending} ) {
delete( $cmd_hash{$command} ); delete $cmd_hash{$command};
dPrint( ZoneMinder::Logger::INFO, "Command '$command' removed from pending list at " dPrint(ZoneMinder::Logger::INFO, "Command '$command' removed from pending list at "
.strftime( '%y/%m/%d %H:%M:%S', localtime() ) .strftime('%y/%m/%d %H:%M:%S', localtime())
."\n" ."\n"
); );
return(); return();
@ -509,12 +505,12 @@ sub send_stop {
my $pid = $process->{pid}; my $pid = $process->{pid};
if ( !$pid_hash{$pid} ) { if ( !$pid_hash{$pid} ) {
dPrint( ZoneMinder::Logger::ERROR, "No process with command of '$command' pid $pid is running\n" ); dPrint(ZoneMinder::Logger::ERROR, "No process with command of '$command' pid $pid is running\n");
return(); return();
} }
dPrint( ZoneMinder::Logger::INFO, "'$command' sending stop to pid $pid at " dPrint(ZoneMinder::Logger::INFO, "'$command' sending stop to pid $pid at "
.strftime( '%y/%m/%d %H:%M:%S', localtime() ) .strftime('%y/%m/%d %H:%M:%S', localtime())
."\n" ."\n"
); );
$process->{keepalive} = !$final; $process->{keepalive} = !$final;
@ -522,8 +518,7 @@ sub send_stop {
$process->{pending} = 0; $process->{pending} = 0;
$terminating_processes{$command} = $process; $terminating_processes{$command} = $process;
kill('TERM', $pid);
kill( 'TERM', $pid );
return $pid; return $pid;
} # end sub send_stop } # end sub send_stop
@ -531,9 +526,10 @@ sub check_for_processes_to_kill {
# Turn off SIGCHLD # Turn off SIGCHLD
my $sigset = POSIX::SigSet->new; my $sigset = POSIX::SigSet->new;
my $blockset = POSIX::SigSet->new(SIGCHLD); my $blockset = POSIX::SigSet->new(SIGCHLD);
sigprocmask(SIG_BLOCK, $blockset, $sigset ) or die "dying at block...\n"; sigprocmask(SIG_BLOCK, $blockset, $sigset) or die "dying at block...\n";
foreach my $command ( %terminating_processes ) { foreach my $command ( %terminating_processes ) {
my $process = $cmd_hash{$command}; my $process = $cmd_hash{$command};
Debug("Have process $command at pid $$process{pid} $$process{term_sent_at}");
if ( $$process{term_sent_at} - time > KILL_DELAY ) { if ( $$process{term_sent_at} - time > KILL_DELAY ) {
dPrint(ZoneMinder::Logger::WARNING, "'$$process{command}' has not stopped at " dPrint(ZoneMinder::Logger::WARNING, "'$$process{command}' has not stopped at "
.strftime('%y/%m/%d %H:%M:%S', localtime()) .strftime('%y/%m/%d %H:%M:%S', localtime())
@ -551,11 +547,11 @@ sub stop {
my $command = join(' ', $daemon, @args ); my $command = join(' ', $daemon, @args );
my $process = $cmd_hash{$command}; my $process = $cmd_hash{$command};
if ( !$process ) { if ( !$process ) {
dPrint( ZoneMinder::Logger::WARNING, "Can't find process with command of '$command'\n" ); dPrint(ZoneMinder::Logger::WARNING, "Can't find process with command of '$command'\n");
return; return;
} }
send_stop( 1, $process ); send_stop(1, $process);
} }
# restart is the same as stop, except that we flag the processes for restarting once it dies # restart is the same as stop, except that we flag the processes for restarting once it dies
@ -563,7 +559,7 @@ sub stop {
sub restart { sub restart {
my ( $daemon, @args ) = @_; my ( $daemon, @args ) = @_;
my $command = join(' ', $daemon, @args ); my $command = join(' ', $daemon, @args);
dPrint(ZoneMinder::Logger::DEBUG, "Restarting $command\n"); dPrint(ZoneMinder::Logger::DEBUG, "Restarting $command\n");
my $process = $cmd_hash{$command}; my $process = $cmd_hash{$command};
if ( !$process ) { if ( !$process ) {
@ -580,7 +576,7 @@ sub reload {
my $daemon = shift; my $daemon = shift;
my @args = @_; my @args = @_;
my $command = join(' ', $daemon, @args ) ; my $command = join(' ', $daemon, @args);
my $process = $cmd_hash{$command}; my $process = $cmd_hash{$command};
if ( $process ) { if ( $process ) {
if ( $process->{pid} ) { if ( $process->{pid} ) {
@ -591,7 +587,7 @@ sub reload {
sub logrot { sub logrot {
logReinit(); logReinit();
foreach my $process ( values(%pid_hash) ) { foreach my $process ( values %pid_hash ) {
if ( $process->{pid} ) { if ( $process->{pid} ) {
# && $process->{command} =~ /^zm.*\.pl/ ) { # && $process->{command} =~ /^zm.*\.pl/ ) {
kill('HUP', $process->{pid}); kill('HUP', $process->{pid});
@ -601,14 +597,14 @@ sub logrot {
sub reaper { sub reaper {
my $saved_status = $!; my $saved_status = $!;
while ( (my $cpid = waitpid( -1, WNOHANG )) > 0 ) { while ( (my $cpid = waitpid(-1, WNOHANG)) > 0 ) {
my $status = $?; my $status = $?;
my $process = $pid_hash{$cpid}; my $process = $pid_hash{$cpid};
delete $pid_hash{$cpid}; delete $pid_hash{$cpid};
if ( !$process ) { if ( !$process ) {
dPrint( ZoneMinder::Logger::INFO, "Can't find child with pid of '$cpid'\n" ); dPrint(ZoneMinder::Logger::INFO, "Can't find child with pid of '$cpid'\n");
next; next;
} }
delete $terminating_processes{$$process{command}}; delete $terminating_processes{$$process{command}};
@ -643,9 +639,9 @@ sub reaper {
$out_str .= "\n"; $out_str .= "\n";
if ( $exit_status == 0 ) { if ( $exit_status == 0 ) {
Info( $out_str ); Info($out_str);
} else { } else {
Error( $out_str ); Error($out_str);
} }
if ( $process->{keepalive} ) { if ( $process->{keepalive} ) {
@ -685,7 +681,7 @@ sub shutdownAll {
foreach my $pid ( keys %pid_hash ) { foreach my $pid ( keys %pid_hash ) {
# This is a quick fix because a SIGCHLD can happen and alter pid_hash while we are in here. # This is a quick fix because a SIGCHLD can happen and alter pid_hash while we are in here.
next if ! $pid_hash{$pid}; next if ! $pid_hash{$pid};
send_stop( 1, $pid_hash{$pid} ); send_stop(1, $pid_hash{$pid});
} }
while ( %terminating_processes ) { while ( %terminating_processes ) {
check_for_processes_to_kill(); check_for_processes_to_kill();
@ -695,10 +691,10 @@ sub shutdownAll {
.strftime('%y/%m/%d %H:%M:%S', localtime()) .strftime('%y/%m/%d %H:%M:%S', localtime())
."\n" ."\n"
); );
unlink( main::SOCK_FILE ) or Error( "Unable to unlink " . main::SOCK_FILE .". Error message was: $!" ) if ( -e main::SOCK_FILE ); unlink(main::SOCK_FILE) or Error("Unable to unlink " . main::SOCK_FILE .". Error message was: $!") if ( -e main::SOCK_FILE );
unlink( ZM_PID ) or Error( "Unable to unlink " . ZM_PID .". Error message was: $!" ) if ( -e ZM_PID ); unlink(ZM_PID) or Error("Unable to unlink " . ZM_PID .". Error message was: $!") if ( -e ZM_PID );
close( CLIENT ); close(CLIENT);
close( SERVER ); close(SERVER);
exit(); exit();
} }
@ -706,18 +702,18 @@ sub check {
my $daemon = shift; my $daemon = shift;
my @args = @_; my @args = @_;
my $command = join( ' ', $daemon, @args ); my $command = join(' ', $daemon, @args);
my $process = $cmd_hash{$command}; my $process = $cmd_hash{$command};
if ( !$process ) { if ( !$process ) {
cPrint( "unknown\n" ); cPrint("unknown\n");
} elsif ( $process->{pending} ) { } elsif ( $process->{pending} ) {
cPrint( "pending\n" ); cPrint("pending\n");
} else { } else {
my $cpid = $process->{pid}; my $cpid = $process->{pid};
if ( ! $pid_hash{$cpid} ) { if ( ! $pid_hash{$cpid} ) {
cPrint( "stopped\n" ); cPrint("stopped\n");
} else { } else {
cPrint( "running\n" ); cPrint("running\n");
} }
} }
} }
@ -785,14 +781,14 @@ sub killAll {
} }
foreach my $daemon ( @daemons ) { foreach my $daemon ( @daemons ) {
my $cmd = $killall ."TERM $daemon"; my $cmd = $killall ."TERM $daemon";
Debug( $cmd ); Debug($cmd);
qx( $cmd ); qx($cmd);
} }
sleep( $delay ); sleep($delay);
foreach my $daemon ( @daemons ) { foreach my $daemon ( @daemons ) {
my $cmd = $killall."KILL $daemon"; my $cmd = $killall."KILL $daemon";
Debug( $cmd ); Debug($cmd);
qx( $cmd ); qx($cmd);
} }
} }
1; 1;

View File

@ -834,7 +834,7 @@ double Monitor::GetFPS() const {
Snapshot *snap1 = &image_buffer[index1]; Snapshot *snap1 = &image_buffer[index1];
if ( !snap1->timestamp || !snap1->timestamp->tv_sec ) { if ( !snap1->timestamp || !snap1->timestamp->tv_sec ) {
// This should be impossible // This should be impossible
Warning("Impossible situation. No timestamp on captured image"); Warning("Impossible situation. No timestamp on captured image index was %d, image-buffer_count was (%d)", index1, image_buffer_count);
return 0.0; return 0.0;
} }
struct timeval time1 = *snap1->timestamp; struct timeval time1 = *snap1->timestamp;

View File

@ -21,6 +21,7 @@
#include "zm_rtsp_auth.h" #include "zm_rtsp_auth.h"
#include "zm_mem_utils.h" #include "zm_mem_utils.h"
#include "zm_signal.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
@ -192,24 +193,24 @@ int RemoteCameraHttp::ReadData( Buffer &buffer, unsigned int bytes_expected ) {
struct timeval temp_timeout = timeout; struct timeval temp_timeout = timeout;
int n_found = select( sd+1, &rfds, NULL, NULL, &temp_timeout ); int n_found = select(sd+1, &rfds, NULL, NULL, &temp_timeout);
if( n_found == 0 ) { if( n_found == 0 ) {
Debug( 4, "Select timed out timeout was %d secs %d usecs", temp_timeout.tv_sec, temp_timeout.tv_usec ); Debug( 1, "Select timed out timeout was %d secs %d usecs", temp_timeout.tv_sec, temp_timeout.tv_usec );
int error = 0; int error = 0;
socklen_t len = sizeof (error); socklen_t len = sizeof (error);
int retval = getsockopt (sd, SOL_SOCKET, SO_ERROR, &error, &len); int retval = getsockopt (sd, SOL_SOCKET, SO_ERROR, &error, &len);
if(retval != 0 ) { if(retval != 0 ) {
Debug( 1, "error getting socket error code %s", strerror(retval) ); Debug( 1, "error getting socket error code %s", strerror(retval) );
} }
if (error != 0) { if (error != 0 ) {
return -1; return -1;
} }
// Why are we disconnecting? It's just a timeout, meaning that data wasn't available. // Why are we disconnecting? It's just a timeout, meaning that data wasn't available.
//Disconnect(); //Disconnect();
return( 0 ); return 0;
} else if ( n_found < 0) { } else if ( n_found < 0) {
Error( "Select error: %s", strerror(errno) ); Error("Select error: %s", strerror(errno));
return( -1 ); return -1;
} }
unsigned int total_bytes_to_read = 0; unsigned int total_bytes_to_read = 0;
@ -309,13 +310,14 @@ int RemoteCameraHttp::GetResponse()
static RegExpr *content_length_expr = 0; static RegExpr *content_length_expr = 0;
static RegExpr *content_type_expr = 0; static RegExpr *content_type_expr = 0;
while ( ! ( buffer_len = ReadData( buffer ) ) ) { while ( !( buffer_len = ReadData(buffer) ) && !zm_terminate ) {
Debug(4, "Timeout waiting for REGEXP HEADER"); Debug(4, "Timeout waiting for REGEXP HEADER");
} }
if ( buffer_len < 0 ) { if ( buffer_len < 0 ) {
Error( "Unable to read header data" ); Error( "Unable to read header data" );
return( -1 ); return( -1 );
} }
bytes += buffer_len;
if ( !header_expr ) if ( !header_expr )
header_expr = new RegExpr( "^(.+?\r?\n\r?\n)", PCRE_DOTALL ); header_expr = new RegExpr( "^(.+?\r?\n\r?\n)", PCRE_DOTALL );
if ( header_expr->Match( (char*)buffer, buffer.size() ) == 2 ) if ( header_expr->Match( (char*)buffer, buffer.size() ) == 2 )
@ -483,13 +485,14 @@ int RemoteCameraHttp::GetResponse()
else else
{ {
Debug( 3, "Unable to extract subheader from stream, retrying" ); Debug( 3, "Unable to extract subheader from stream, retrying" );
while ( ! ( buffer_len = ReadData( buffer ) ) ) { while ( !( buffer_len = ReadData(buffer) ) && !zm_terminate ) {
Debug(4, "Timeout waiting to extract subheader"); Debug(4, "Timeout waiting to extract subheader");
} }
if ( buffer_len < 0 ) { if ( buffer_len < 0 ) {
Error( "Unable to extract subheader data" ); Error( "Unable to extract subheader data" );
return( -1 ); return( -1 );
} }
bytes += buffer_len;
} }
break; break;
} }
@ -522,13 +525,16 @@ int RemoteCameraHttp::GetResponse()
if ( content_length ) if ( content_length )
{ {
while ( (long)buffer.size() < content_length ) while ( ((long)buffer.size() < content_length ) && ! zm_terminate )
{ {
Debug(3, "Need more data buffer %d < content length %d", buffer.size(), content_length ); Debug(3, "Need more data buffer %d < content length %d", buffer.size(), content_length );
if ( ReadData( buffer ) < 0 ) { int bytes_read = ReadData( buffer );
if ( bytes_read < 0 ) {
Error( "Unable to read content" ); Error( "Unable to read content" );
return( -1 ); return( -1 );
} }
bytes += bytes_read;
} }
Debug( 3, "Got end of image by length, content-length = %d", content_length ); Debug( 3, "Got end of image by length, content-length = %d", content_length );
} }
@ -536,13 +542,14 @@ int RemoteCameraHttp::GetResponse()
{ {
while ( !content_length ) while ( !content_length )
{ {
while ( ! ( buffer_len = ReadData( buffer ) ) ) { while ( !( buffer_len = ReadData(buffer) ) && !zm_terminate ) {
Debug(4, "Timeout waiting for content"); Debug(4, "Timeout waiting for content");
} }
if ( buffer_len < 0 ) { if ( buffer_len < 0 ) {
Error( "Unable to read content" ); Error( "Unable to read content" );
return( -1 ); return( -1 );
} }
bytes += buffer_len;
static RegExpr *content_expr = 0; static RegExpr *content_expr = 0;
if ( mode == MULTI_IMAGE ) if ( mode == MULTI_IMAGE )
{ {
@ -656,13 +663,14 @@ int RemoteCameraHttp::GetResponse()
} }
case HEADERCONT : case HEADERCONT :
{ {
while ( ! ( buffer_len = ReadData( buffer ) ) ) { while ( !( buffer_len = ReadData(buffer) ) && !zm_terminate ) {
Debug(4, "Timeout waiting for HEADERCONT"); Debug(4, "Timeout waiting for HEADERCONT");
} }
if ( buffer_len < 0 ) { if ( buffer_len < 0 ) {
Error( "Unable to read header" ); Error( "Unable to read header" );
return( -1 ); return( -1 );
} }
bytes += buffer_len;
char *crlf = 0; char *crlf = 0;
char *header_ptr = (char *)buffer; char *header_ptr = (char *)buffer;
@ -941,13 +949,14 @@ int RemoteCameraHttp::GetResponse()
state = CONTENT; state = CONTENT;
} else { } else {
Debug( 3, "Unable to extract subheader from stream, retrying" ); Debug( 3, "Unable to extract subheader from stream, retrying" );
while ( ! ( buffer_len = ReadData( buffer ) ) ) { while ( !( buffer_len = ReadData(buffer) ) &&!zm_terminate ) {
Debug(1, "Timeout waiting to extra subheader non regexp"); Debug(1, "Timeout waiting to extra subheader non regexp");
} }
if ( buffer_len < 0 ) { if ( buffer_len < 0 ) {
Error( "Unable to read subheader" ); Error( "Unable to read subheader" );
return( -1 ); return( -1 );
} }
bytes += buffer_len;
state = SUBHEADERCONT; state = SUBHEADERCONT;
} }
break; break;
@ -980,18 +989,19 @@ int RemoteCameraHttp::GetResponse()
} }
if ( content_length ) { if ( content_length ) {
while ( (long)buffer.size() < content_length ) { while ( ( (long)buffer.size() < content_length ) && ! zm_terminate ) {
//int buffer_len = ReadData( buffer, content_length-buffer.size() );
Debug(4, "getting more data"); Debug(4, "getting more data");
if ( ReadData( buffer ) < 0 ) { int bytes_read = ReadData(buffer);
Error( "Unable to read content" ); if ( bytes_read < 0 ) {
return( -1 ); Error("Unable to read content");
return -1;
} }
bytes += bytes_read;
} }
Debug( 3, "Got end of image by length, content-length = %d", content_length ); Debug( 3, "Got end of image by length, content-length = %d", content_length );
} else { } else {
// Read until we find the end of image or the stream closes. // Read until we find the end of image or the stream closes.
while ( !content_length ) { while ( !content_length && !zm_terminate ) {
Debug(4, "!content_length, ReadData"); Debug(4, "!content_length, ReadData");
buffer_len = ReadData( buffer ); buffer_len = ReadData( buffer );
if ( buffer_len < 0 ) if ( buffer_len < 0 )
@ -999,6 +1009,7 @@ int RemoteCameraHttp::GetResponse()
Error( "Unable to read content" ); Error( "Unable to read content" );
return( -1 ); return( -1 );
} }
bytes += buffer_len;
int buffer_size = buffer.size(); int buffer_size = buffer.size();
if ( buffer_len ) { if ( buffer_len ) {
// Got some data // Got some data

View File

@ -711,8 +711,8 @@ int VideoStore::writeVideoFramePacket(AVPacket *ipkt) {
opkt.dts = video_next_dts; opkt.dts = video_next_dts;
opkt.duration = 0; opkt.duration = 0;
int duration; int64_t duration;
if (!video_last_pts) { if ( !video_last_pts ) {
duration = 0; duration = 0;
} else { } else {
duration = duration =
@ -723,7 +723,7 @@ int VideoStore::writeVideoFramePacket(AVPacket *ipkt) {
video_last_pts, video_last_pts,
duration); duration);
if (duration < 0) { if (duration < 0) {
duration = ipkt->duration; duration = ipkt->duration ? ipkt->duration : av_rescale_q(1,video_in_stream->time_base, video_out_stream->time_base);
} }
} }

View File

@ -228,6 +228,7 @@ int main(int argc, char *argv[]) {
sigset_t block_set; sigset_t block_set;
sigemptyset(&block_set); sigemptyset(&block_set);
sigaddset(&block_set, SIGHUP);
sigaddset(&block_set, SIGUSR1); sigaddset(&block_set, SIGUSR1);
sigaddset(&block_set, SIGUSR2); sigaddset(&block_set, SIGUSR2);

View File

@ -254,10 +254,13 @@ private $control_fields = array(
return $this->{'Height'}; return $this->{'Height'};
} }
public function set( $data ) { public function set($data) {
foreach ($data as $k => $v) { foreach ($data as $k => $v) {
if ( method_exists($this, $k) ) {
$this->{$k}($v);
} else {
if ( is_array( $v ) ) { if ( is_array( $v ) ) {
# perhaps should turn into a comma-separated string # perhaps should turn into a comma-separated string
$this->{$k} = implode(',',$v); $this->{$k} = implode(',',$v);
} else if ( is_string( $v ) ) { } else if ( is_string( $v ) ) {
$this->{$k} = trim( $v ); $this->{$k} = trim( $v );
@ -269,7 +272,8 @@ private $control_fields = array(
Error( "Unknown type $k => $v of var " . gettype( $v ) ); Error( "Unknown type $k => $v of var " . gettype( $v ) );
$this->{$k} = $v; $this->{$k} = $v;
} }
} } # end if method_exists
} # end foreach $data as $k=>$v
} }
public static function find_all( $parameters = null, $options = null ) { public static function find_all( $parameters = null, $options = null ) {
$filters = array(); $filters = array();
@ -305,7 +309,7 @@ private $control_fields = array(
return $filters; return $filters;
} }
public function save( $new_values = null ) { public function save($new_values = null) {
if ( $new_values ) { if ( $new_values ) {
foreach ( $new_values as $k=>$v ) { foreach ( $new_values as $k=>$v ) {
@ -313,12 +317,12 @@ private $control_fields = array(
} }
} }
$fields = array_keys( $this->defaults ); $fields = array_keys($this->defaults);
$sql = 'UPDATE Monitors SET '.implode(', ', array_map( function($field) {return $field.'=?';}, $fields ) ) . ' WHERE Id=?'; $sql = 'UPDATE Monitors SET '.implode(', ', array_map(function($field) {return $field.'=?';}, $fields )) . ' WHERE Id=?';
$values = array_map( function($field){return $this->{$field};}, $fields ); $values = array_map(function($field){return $this->{$field};}, $fields);
$values[] = $this->{'Id'}; $values[] = $this->{'Id'};
dbQuery( $sql, $values ); dbQuery($sql, $values);
} // end function save } // end function save
function zmcControl( $mode=false ) { function zmcControl( $mode=false ) {
@ -400,10 +404,20 @@ private $control_fields = array(
} }
} // end if we are on the recording server } // end if we are on the recording server
} }
public function GroupIds( ) { public function GroupIds( $new='') {
if ( $new != '' ) {
if(!is_array($new)) {
$this->{'GroupIds'} = array($new);
} else {
$this->{'GroupIds'} = $new;
}
}
if ( !array_key_exists('GroupIds', $this) ) { if ( !array_key_exists('GroupIds', $this) ) {
if ( array_key_exists('Id', $this) and $this->{'Id'} ) { if ( array_key_exists('Id', $this) and $this->{'Id'} ) {
$this->{'GroupIds'} = dbFetchAll( 'SELECT GroupId FROM Groups_Monitors WHERE MonitorId=?', 'GroupId', array($this->{'Id'}) ); $this->{'GroupIds'} = dbFetchAll('SELECT GroupId FROM Groups_Monitors WHERE MonitorId=?', 'GroupId', array($this->{'Id'}) );
if ( ! $this->{'GroupIds'} )
$this->{'GroupIds'} = array();
} else { } else {
$this->{'GroupIds'} = array(); $this->{'GroupIds'} = array();
} }

View File

@ -458,7 +458,7 @@ if ( canEdit( 'Monitors' ) ) {
$x10Monitor = array(); $x10Monitor = array();
} }
} }
$Monitor = new Monitor( $monitor ); $Monitor = new Monitor($monitor);
// Define a field type for anything that's not simple text equivalent // Define a field type for anything that's not simple text equivalent
$types = array( $types = array(
@ -475,7 +475,7 @@ if ( canEdit( 'Monitors' ) ) {
if ( $_REQUEST['newMonitor']['ServerId'] == 'auto' ) { if ( $_REQUEST['newMonitor']['ServerId'] == 'auto' ) {
Logger::Debug("Auto selecting server"); Logger::Debug("Auto selecting server");
$_REQUEST['newMonitor']['ServerId'] = dbFetchOne( 'SELECT Id FROM Servers WHERE Status=\'Running\' ORDER BY FreeMem DESC, CpuLoad ASC LIMIT 1', 'Id' ); $_REQUEST['newMonitor']['ServerId'] = dbFetchOne('SELECT Id FROM Servers WHERE Status=\'Running\' ORDER BY FreeMem DESC, CpuLoad ASC LIMIT 1', 'Id');
Logger::Debug("Auto selecting server: Got " . $_REQUEST['newMonitor']['ServerId'] ); Logger::Debug("Auto selecting server: Got " . $_REQUEST['newMonitor']['ServerId'] );
if ( ( ! $_REQUEST['newMonitor'] ) and defined('ZM_SERVER_ID') ) { if ( ( ! $_REQUEST['newMonitor'] ) and defined('ZM_SERVER_ID') ) {
$_REQUEST['newMonitor']['ServerId'] = ZM_SERVER_ID; $_REQUEST['newMonitor']['ServerId'] = ZM_SERVER_ID;
@ -485,8 +485,8 @@ if ( canEdit( 'Monitors' ) ) {
Logger::Debug("NOT Auto selecting server" . $_REQUEST['newMonitor']['ServerId']); Logger::Debug("NOT Auto selecting server" . $_REQUEST['newMonitor']['ServerId']);
} }
$columns = getTableColumns( 'Monitors' ); $columns = getTableColumns('Monitors');
$changes = getFormChanges( $monitor, $_REQUEST['newMonitor'], $types, $columns ); $changes = getFormChanges($monitor, $_REQUEST['newMonitor'], $types, $columns);
if ( count( $changes ) ) { if ( count( $changes ) ) {
if ( $mid ) { if ( $mid ) {
@ -565,6 +565,8 @@ if ( canEdit( 'Monitors' ) ) {
return; return;
} }
$restart = true;
} # end if count(changes)
if ( if (
( !isset($_POST['newMonitor']['GroupIds']) ) ( !isset($_POST['newMonitor']['GroupIds']) )
or or
@ -581,8 +583,6 @@ if ( canEdit( 'Monitors' ) ) {
} }
} }
} // end if there has been a change of groups } // end if there has been a change of groups
$restart = true;
} # end if count(changes)
if ( ZM_OPT_X10 ) { if ( ZM_OPT_X10 ) {
$x10Changes = getFormChanges( $x10Monitor, $_REQUEST['newX10Monitor'] ); $x10Changes = getFormChanges( $x10Monitor, $_REQUEST['newX10Monitor'] );

View File

@ -133,10 +133,7 @@ function dbQuery( $sql, $params=NULL ) {
} }
} else { } else {
if ( defined('ZM_DB_DEBUG') ) { if ( defined('ZM_DB_DEBUG') ) {
if ( $params ) Logger::Debug("SQL: $sql values:" . $params?implode(',',$params):'' );
Warning("SQL: $sql" . implode(',',$params) );
else
Warning("SQL: $sql:" );
} }
$result = $dbConn->query($sql); $result = $dbConn->query($sql);
} }
@ -186,7 +183,7 @@ function dbFetchAll( $sql, $col=false, $params=NULL ) {
$dbRows = array(); $dbRows = array();
while( $dbRow = $result->fetch( PDO::FETCH_ASSOC ) ) while( $dbRow = $result->fetch( PDO::FETCH_ASSOC ) )
$dbRows[] = $col?$dbRow[$col]:$dbRow; $dbRows[] = $col?$dbRow[$col]:$dbRow;
return( $dbRows ); return $dbRows;
} }
function dbFetchAssoc( $sql, $indexCol, $dataCol=false ) { function dbFetchAssoc( $sql, $indexCol, $dataCol=false ) {

View File

@ -486,7 +486,7 @@ function getFormChanges( $values, $newValues, $types=false, $columns=false ) {
$types = array(); $types = array();
foreach( $newValues as $key=>$value ) { foreach( $newValues as $key=>$value ) {
if ( $columns && !$columns[$key] ) if ( $columns && !isset($columns[$key]) )
continue; continue;
if ( !isset($types[$key]) ) if ( !isset($types[$key]) )

View File

@ -62,7 +62,7 @@ if ( ! $monitor ) {
$nextId = getTableAutoInc( 'Monitors' ); $nextId = getTableAutoInc( 'Monitors' );
if ( isset( $_REQUEST['dupId'] ) ) { if ( isset( $_REQUEST['dupId'] ) ) {
$monitor = new Monitor( $_REQUEST['dupId'] ); $monitor = new Monitor( $_REQUEST['dupId'] );
$monitor->GroupIds(); // have to lead before we change the Id $monitor->GroupIds(); // have to load before we change the Id
if ( ZM_OPT_X10 ) if ( ZM_OPT_X10 )
$x10Monitor = dbFetchOne( 'SELECT * FROM TriggersX10 WHERE MonitorId = ?', NULL, array($_REQUEST['dupId']) ); $x10Monitor = dbFetchOne( 'SELECT * FROM TriggersX10 WHERE MonitorId = ?', NULL, array($_REQUEST['dupId']) );
$clonedName = $monitor->Name(); $clonedName = $monitor->Name();
@ -534,6 +534,11 @@ if ( $tab != 'general' ) {
<input type="hidden" name="newMonitor[Name]" value="<?php echo validHtmlStr($monitor->Name()) ?>"/> <input type="hidden" name="newMonitor[Name]" value="<?php echo validHtmlStr($monitor->Name()) ?>"/>
<input type="hidden" name="newMonitor[ServerId]" value="<?php echo validHtmlStr($monitor->ServerId() ) ?>"/> <input type="hidden" name="newMonitor[ServerId]" value="<?php echo validHtmlStr($monitor->ServerId() ) ?>"/>
<input type="hidden" name="newMonitor[StorageId]" value="<?= validHtmlStr($monitor->StorageId() ) ?>"/> <input type="hidden" name="newMonitor[StorageId]" value="<?= validHtmlStr($monitor->StorageId() ) ?>"/>
<?php
foreach ( $monitor->GroupIds() as $group_id ) {
echo '<input type="hidden" name="newMonitor[GroupIds][]" value="'.$group_id.'"/>';
}
?>
<input type="hidden" name="newMonitor[Type]" value="<?php echo validHtmlStr($monitor->Type()) ?>"/> <input type="hidden" name="newMonitor[Type]" value="<?php echo validHtmlStr($monitor->Type()) ?>"/>
<input type="hidden" name="newMonitor[Function]" value="<?php echo validHtmlStr($monitor->Function()) ?>"/> <input type="hidden" name="newMonitor[Function]" value="<?php echo validHtmlStr($monitor->Function()) ?>"/>
<input type="hidden" name="newMonitor[Enabled]" value="<?php echo validHtmlStr($monitor->Enabled()) ?>"/> <input type="hidden" name="newMonitor[Enabled]" value="<?php echo validHtmlStr($monitor->Enabled()) ?>"/>