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

This commit is contained in:
Isaac Connor 2017-01-05 11:31:41 -05:00
commit 2bc47a000c
4 changed files with 50 additions and 12 deletions

View File

@ -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" );

View File

@ -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 => '',

View File

@ -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;

View File

@ -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__