From cf9747054cb74269cca6efa71bb65d694d8f5e38 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 4 Jan 2017 12:22:01 -0500 Subject: [PATCH 1/5] add ZM_TELEMETRY_INTERVAL AND ENDPOINT --- .../ZoneMinder/lib/ZoneMinder/ConfigData.pm.in | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in index 3f80748db..192724949 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in @@ -2812,6 +2812,23 @@ our @options = ( type => $types{string}, 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 => qqq(" + "), + type => $types{url}, + category => 'system', + }, { name => "ZM_TELEMETRY_LAST_UPLOAD", default => "", From 09783a1a39fc578f9559ef31a43327688c1221d8 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 4 Jan 2017 12:22:40 -0500 Subject: [PATCH 2/5] add some command line options and use the INTERVAL and ENDPOINT from the Config hash --- scripts/zmtelemetry.pl.in | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) 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__ From 75cd1de7abbfc4c677548abd11064c7dcdb6aab1 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 5 Jan 2017 09:42:11 -0500 Subject: [PATCH 3/5] show the # of entries loaded and saved --- scripts/ZoneMinder/lib/ZoneMinder/Config.pm.in | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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" ); From db1a6f9b3b0c569ef572921246650bdefe706deb Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 5 Jan 2017 11:24:27 -0500 Subject: [PATCH 4/5] fix to remove qqq --- scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in index c02ac7d51..3599f8e88 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in @@ -2839,8 +2839,7 @@ our @options = ( name => 'ZM_TELEMETRY_SERVER_ENDPOINT', default => 'https://zmanon:2b2d0b4skps@telemetry.zoneminder.com/zmtelemetry/testing5', description => 'URL that ZoneMinder will send usage data to', - help => qqq(" - "), + help => '', type => $types{url}, category => 'system', }, From 426eabb12d7c0b79f3cd323d9ce58eacdad12280 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 5 Jan 2017 11:24:53 -0500 Subject: [PATCH 5/5] if running from a terminal, set termLevel to info --- scripts/ZoneMinder/lib/ZoneMinder/Logger.pm | 4 ++++ 1 file changed, 4 insertions(+) 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;