Merge branch 'zmtelemetry_improvements' into storageareas

This commit is contained in:
Isaac Connor 2017-01-04 12:25:01 -05:00
commit 0c34aa9830
2 changed files with 44 additions and 10 deletions

View File

@ -2827,6 +2827,23 @@ our @options = (
readonly => 1, readonly => 1,
category => 'dynamic', 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_UPDATE_CHECK_PROXY', name => 'ZM_UPDATE_CHECK_PROXY',
default => '', default => '',

View File

@ -61,21 +61,35 @@ $ENV{PATH} = '/bin:/usr/bin:/usr/local/bin';
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL}; $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; 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. # 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}; my $lastCheck = $Config{ZM_TELEMETRY_LAST_UPLOAD};
while( 1 ) { while( 1 ) {
my $now = time(); my $now = time();
if ( ($now-$lastCheck) > CHECK_INTERVAL ) { if ( ( ($now-$lastCheck) > $interval ) or $force ) {
Info( "Collecting data to send to ZoneMinder Telemetry server." ); Info( "Collecting data to send to ZoneMinder Telemetry server." );
my $dbh = zmDbConnect(); my $dbh = zmDbConnect();
# Build the telemetry hash # 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() ); my $res = $sth->execute( "$lastCheck" ) or die( "Can't execute: ".$sth->errstr() );
$sth->finish(); $sth->finish();
} }
} else {
Debug( "Update agent sleeping because ($now-$lastCheck=".($now-$lastCheck)." > " . $interval );
} }
sleep( 3600 ); 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 $msg = shift;
my $ua = LWP::UserAgent->new; 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} ) { if ( $Config{ZM_UPDATE_CHECK_PROXY} ) {
$ua->proxy( "https", $Config{ZM_UPDATE_CHECK_PROXY} ); $ua->proxy( "https", $Config{ZM_UPDATE_CHECK_PROXY} );
@ -340,4 +356,5 @@ sub linuxDistro {
return ($kernel, $distro, $version); return ($kernel, $distro, $version);
} }
1;
__END__