Handle db reconnects, don't disconnect db because it rug pulls from under logging functions
parent
566ce16230
commit
c42179ffa7
|
@ -67,9 +67,11 @@ if ($help) {
|
|||
pod2usage(-exitstatus => -1);
|
||||
}
|
||||
|
||||
logInit();
|
||||
my $dbh = zmDbConnect();
|
||||
|
||||
if ($show) {
|
||||
my %telemetry;
|
||||
my $dbh = zmDbConnect();
|
||||
collectData($dbh, \%telemetry);
|
||||
my $result = jsonEncode(\%telemetry);
|
||||
print($result);
|
||||
|
@ -90,6 +92,13 @@ print('ZoneMinder Telemetry Agent starting at '.strftime('%y/%m/%d %H:%M:%S', lo
|
|||
my $lastCheck = $Config{ZM_TELEMETRY_LAST_UPLOAD};
|
||||
|
||||
while (1) {
|
||||
while ( ! ( $dbh and $dbh->ping() ) ) {
|
||||
Info('Reconnecting to db');
|
||||
if ( !($dbh = zmDbConnect()) ) {
|
||||
#What we do here is not that important, so just skip this interval
|
||||
sleep($interval);
|
||||
}
|
||||
}
|
||||
my $now = time();
|
||||
my $since_last_check = $now - $lastCheck;
|
||||
Debug("Last Check time (now($now) - lastCheck($lastCheck)) = $since_last_check > interval($interval) or force($force)");
|
||||
|
@ -100,23 +109,17 @@ while (1) {
|
|||
}
|
||||
if ((($since_last_check) > $interval) or $force) {
|
||||
print "Collecting data to send to ZoneMinder Telemetry server.\n";
|
||||
my $dbh = zmDbConnect();
|
||||
if ($dbh) {
|
||||
# Build the telemetry hash
|
||||
# We should keep *BSD systems in mind when calling system commands
|
||||
# Build the telemetry hash
|
||||
# We should keep *BSD systems in mind when calling system commands
|
||||
|
||||
my %telemetry;
|
||||
collectData($dbh, \%telemetry);
|
||||
my $result = jsonEncode(\%telemetry);
|
||||
my %telemetry;
|
||||
collectData($dbh, \%telemetry);
|
||||
my $result = jsonEncode(\%telemetry);
|
||||
|
||||
if (sendData($result)) {
|
||||
ZoneMinder::Database::zmDbDo('UPDATE Config SET Value=? WHERE Name=?',
|
||||
$now, 'ZM_TELEMETRY_LAST_UPLOAD');
|
||||
$Config{ZM_TELEMETRY_LAST_UPLOAD} = $now;
|
||||
}
|
||||
zmDbDisconnect();
|
||||
} else {
|
||||
Error('Failed to open database. Sleeping.');
|
||||
if (sendData($result)) {
|
||||
ZoneMinder::Database::zmDbDo('UPDATE Config SET Value=? WHERE Name=?',
|
||||
$now, 'ZM_TELEMETRY_LAST_UPLOAD');
|
||||
$Config{ZM_TELEMETRY_LAST_UPLOAD} = $now;
|
||||
}
|
||||
} elsif (-t STDIN) {
|
||||
print "ZoneMinder Telemetry Agent sleeping for $interval seconds because ($now-$lastCheck=$since_last_check > $interval\n";
|
||||
|
|
Loading…
Reference in New Issue