diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Config.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/Config.pm.in index 486468cc8..2ba12dfa2 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Config.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/Config.pm.in @@ -129,7 +129,7 @@ BEGIN { } # end BEGIN sub loadConfigFromDB { - print( "Loading config from DB\n" ); + print( "Loading config from DB" ); my $dbh = ZoneMinder::Database::zmDbConnect(); if ( !$dbh ) { print( "Error: unable to load options from database: $DBI::errstr\n" ); @@ -160,11 +160,12 @@ sub loadConfigFromDB { $option_count++;; } $sth->finish(); + print( " $option_count entries\n" ); return( $option_count ); } # end sub loadConfigFromDB sub saveConfigToDB { - print( "Saving config to DB\n" ); + print( "Saving config to DB " . @options . " entries\n" ); my $dbh = ZoneMinder::Database::zmDbConnect(); if ( !$dbh ) { print( "Error: unable to save options to database: $DBI::errstr\n" ); diff --git a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in index 11e325406..3599f8e88 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in @@ -2827,6 +2827,22 @@ our @options = ( readonly => 1, category => 'dynamic', }, + { + name => 'ZM_TELEMETRY_INTERVAL', + default => '14*24*60*60', + description => 'Interval in seconds between telemetry updates.', + help => 'This value can be expressed as a mathematical expression for ease.', + type => $types{string}, + category => 'system', + }, + { + name => 'ZM_TELEMETRY_SERVER_ENDPOINT', + default => 'https://zmanon:2b2d0b4skps@telemetry.zoneminder.com/zmtelemetry/testing5', + description => 'URL that ZoneMinder will send usage data to', + help => '', + type => $types{url}, + category => 'system', + }, { name => 'ZM_UPDATE_CHECK_PROXY', default => '', diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm index 8563a95ef..4d51c9e6c 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm @@ -140,7 +140,11 @@ sub new { $this->{idArgs} = ""; $this->{level} = INFO; +if (-t STDIN) { + $this->{termLevel} = INFO; +} else { $this->{termLevel} = NOLOG; +} $this->{databaseLevel} = NOLOG; $this->{fileLevel} = NOLOG; $this->{syslogLevel} = NOLOG; diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index 39e7b73ec..7a9ae3706 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -61,21 +61,35 @@ $ENV{PATH} = '/bin:/usr/bin:/usr/local/bin'; $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL}; delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; -use constant CHECK_INTERVAL => (14*24*60*60); # Interval between version checks - # Setting these as contants for now. -# Alternatively, we can put these in the dB and then retrieve using the Config hash. -use constant ZM_TELEMETRY_SERVER_ENDPOINT => 'https://zmanon:2b2d0b4skps@telemetry.zoneminder.com/zmtelemetry/testing5'; -if ( $Config{ZM_TELEMETRY_DATA} ) +my $force; +# Interval between version checks +my $interval; +my $version; + +GetOptions( + force => \$force, + interval => \$interval, + version => \$version +); +if ( $version ) { + print( ZoneMinder::Base::ZM_VERSION . "\n"); + exit(0); +} +if ( ! defined $interval ) { + $interval = eval($Config{ZM_TELEMETRY_INTERVAL}); +} + +if ( $Config{ZM_TELEMETRY_DATA} or $force ) { - print( "Update agent starting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" ); + Info( "Update agent starting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" ); my $lastCheck = $Config{ZM_TELEMETRY_LAST_UPLOAD}; while( 1 ) { my $now = time(); - if ( ($now-$lastCheck) > CHECK_INTERVAL ) { + if ( ( ($now-$lastCheck) > $interval ) or $force ) { Info( "Collecting data to send to ZoneMinder Telemetry server." ); my $dbh = zmDbConnect(); # Build the telemetry hash @@ -105,10 +119,12 @@ if ( $Config{ZM_TELEMETRY_DATA} ) my $res = $sth->execute( "$lastCheck" ) or die( "Can't execute: ".$sth->errstr() ); $sth->finish(); } + } else { + Debug( "Update agent sleeping because ($now-$lastCheck=".($now-$lastCheck)." > " . $interval ); } sleep( 3600 ); } - print( "Update agent exiting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" ); + Info( "Update agent exiting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" ); } ############### @@ -142,7 +158,7 @@ sub sendData { my $msg = shift; my $ua = LWP::UserAgent->new; - my $server_endpoint = ZM_TELEMETRY_SERVER_ENDPOINT; + my $server_endpoint = $Config{ZM_TELEMETRY_SERVER_ENDPOINT}; if ( $Config{ZM_UPDATE_CHECK_PROXY} ) { $ua->proxy( "https", $Config{ZM_UPDATE_CHECK_PROXY} ); @@ -340,4 +356,5 @@ sub linuxDistro { return ($kernel, $distro, $version); } - +1; +__END__