From f7bc8c7f0d942890e75949136aee8dec86328eeb Mon Sep 17 00:00:00 2001 From: tikismoke Date: Tue, 26 Jan 2016 20:14:49 +0100 Subject: [PATCH 01/33] Update gettingstarted.rst Correct MODECT by NODECT if using zmTrigger --- docs/userguide/gettingstarted.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/userguide/gettingstarted.rst b/docs/userguide/gettingstarted.rst index 2bc3dcd7f..c766e4f15 100644 --- a/docs/userguide/gettingstarted.rst +++ b/docs/userguide/gettingstarted.rst @@ -67,7 +67,7 @@ own empty screen. * **D**: This is the core of ZoneMinder - recording events. It gives you a count of how many events were recorded over the hour, day, week, month. * **E**: These are the "Zones". Zones are areas within the camera that you mark as 'hotspots' for motion detection. Simply put, when you first configure your monitors (cameras), by default Zoneminder uses the entire field of view of the camera to detect motion. You may not want this. You may want to create "zones" specifically for detecting motion and ignore others. For example, lets consider a room with a fan that spins. You surely don't want to consider the fan moving continously a reason for triggering a record? Probably not - in that case, you'd leave the fan out while making your zones. * **F**: This is the "source" column that tells you the type of the camera - if its an IP camera, a USB camera or more. In this example, they are all IP cameras. Note the color red on item F ? Well that means there is something wrong with that camera. No wonder the log also shows red. Good indication for you to tap on logs and investigate -* **G**: This defines how Zoneminder will record events. There are various modes. In brief Modect == record if a motion is detected,Record = always record 24x7, Mocord = always record PLUS detect motion, Monitor = just provide a live view but don't record anytime, Modect = Don't record till an externa entity via zmtrigger tells Zoneminder to (this is advanced usage). +* **G**: This defines how Zoneminder will record events. There are various modes. In brief Modect == record if a motion is detected,Record = always record 24x7, Mocord = always record PLUS detect motion, Monitor = just provide a live view but don't record anytime, Nodect = Don't record till an externa entity via zmtrigger tells Zoneminder to (this is advanced usage). * **H**: If you click on these links you can view a "Montage" of all your configured monitors or cycle through each one From 8a537029ea7a5bd4c91294fd458694393785812f Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Sat, 6 Feb 2016 14:08:28 -0600 Subject: [PATCH 02/33] Initial commit to add zmtelemetry.pl --- .../lib/ZoneMinder/ConfigData.pm.in | 17 ++ scripts/zmdc.pl.in | 3 +- scripts/zmpkg.pl.in | 4 + scripts/zmtelemetry.pl.in | 161 ++++++++++++++++++ 4 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 scripts/zmtelemetry.pl.in diff --git a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in index 198ff2194..ffe063b60 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in @@ -2746,6 +2746,23 @@ body = "ZM alarm detected - %EL% secs, %EF%/%EFA% frames, t%EST%/m%ESM%/a%ESA% s type => $types{boolean}, category => "system", }, + { + name => "ZM_TELEMETRY_DATA", + default => "yes", + description => "Send usage information to ZoneMinder", + help => qqq(" + Enable collection of usage information of the local system and send + it to the ZoneMinder development team. This data will be used to + determine things like who and where our customers are, how big their + systems are, the underlying hardware and operating system, etc. + This is being done for the sole purpoase of creating a better + product for our target audience. This script is intended to be + completely transparent to the end user, and can be disabled from + the web console under Options. + "), + type => $types{boolean}, + category => "system", + }, { name => "ZM_UPDATE_CHECK_PROXY", default => "", diff --git a/scripts/zmdc.pl.in b/scripts/zmdc.pl.in index 5e2fb47c7..4d36385ef 100644 --- a/scripts/zmdc.pl.in +++ b/scripts/zmdc.pl.in @@ -87,7 +87,8 @@ my @daemons = ( 'zmx10.pl', 'zmwatch.pl', 'zmupdate.pl', - 'zmtrack.pl' + 'zmtrack.pl', + 'zmtelemetry.pl', ); my $command = shift @ARGV; diff --git a/scripts/zmpkg.pl.in b/scripts/zmpkg.pl.in index 183f8084c..53e29a8da 100644 --- a/scripts/zmpkg.pl.in +++ b/scripts/zmpkg.pl.in @@ -285,6 +285,10 @@ if ( $command =~ /^(?:start|restart)$/ ) { runCommand( "zmdc.pl start zmupdate.pl -c" ); } + if ( $Config{ZM_TELEMETRY_DATA} ) + { + runCommand( "zmdc.pl start zmtelemetry.pl" ); + } } else { diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in new file mode 100644 index 000000000..7b3b376a4 --- /dev/null +++ b/scripts/zmtelemetry.pl.in @@ -0,0 +1,161 @@ +#!/usr/bin/perl -w +# +# ========================================================================== +# +# ZoneMinder Update Script, $Date$, $Revision$ +# Copyright (C) 2001-2008 Philip Coombes +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# ========================================================================== + +=head1 NAME + +zmtelemetry.pl - Send usage information to the ZoneMinder development team + +=head1 SYNOPSIS + + zmtelemetry.pl + +=head1 DESCRIPTION + +This script collects usage information of the local system and sends it to the +ZoneMinder development team. This data will be used to determine things like +who and where our customers are, how big their systems are, the underlying +hardware and operating system, etc. This is being done for the sole purpoase of +creating a better product for our target audience. This script is intended to +be completely transparent to the end user, and can be disabled from the web +console under Options. + +=head1 OPTIONS + +none currently + +=cut +use strict; +use bytes; + +@EXTRA_PERL_LIB@ +use ZoneMinder::Config qw(:all); +use ZoneMinder::Logger qw(:all); +use ZoneMinder::Database qw(:all); +use DBI; +use Getopt::Long; +use autouse 'Pod::Usage'=>qw(pod2usage); + +$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_NAME => "telemetry.zoneminder.com"; +use constant ZM_TELEMETRY_SERVER_PORT => "80"; + +if ( $Config{ZM_TELEMETRY_DATA} ) +{ + print( "Update agent starting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" ); + + my $lastCheck = $Config{ZM_TELEMETRY_LAST_CHECK}; + + while( 1 ) + { + my $now = time(); + if ( ($now-$lastCheck) > CHECK_INTERVAL) ) + { + Info( "Colleting data to send to ZoneMinder Telemetry server\n" ); + + # This is where we gather our data. The following is just an oversimplified example. + # Modify accordingly. + + # We should keep *BSD systems in mind when calling system commands + my $result = runSysCmd("uname -a")."\n"; + my $result .= "ZM_DYN_CURR_VERSION: ".Config{ZM_DYN_CURR_VERSION}; + + Info( "Sending data to ZoneMinder Telemetry server\n" ); + + if ( sendData($result) ) { + $lastCheck = $now; + + my $lc_sql = "update Config set Value = ? where Name = 'ZM_DYN_LAST_CHECK'"; + my $lc_sth = $dbh->prepare_cached( $lc_sql ) or die( "Can't prepare '$lc_sql': ".$dbh->errstr() ); + my $lc_res = $lc_sth->execute( $lastCheck ) or die( "Can't execute: ".$lc_sth->errstr() ); + } + } + sleep( 3600 ); + } + print( "Update agent exiting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" ); +} + +# Find, verify, then run the supplied system command +sub runSysCmd { + my $msg = shift; + my @arguments = split(/ /,$msg); + chomp($arguments[0]); + my $path = qx( which $arguments[0] ); + + my $status = $? >> 8; + my $result = ""; + if ( !$path || $status ) { + Warning( "Cannot find the $arguments[0] executable." ); + } else { + chomp($path); + $arguments[0] = $path; + my $cmd = join(" ",@arguments); + my $result = qx( $cmd ); + } + return chomp($result); +} + +# Upload message data to ZoneMinder telemetry server +sub sendData { + my $msg = shift; + + use LWP::UserAgent; + + my $ua = LWP::UserAgent->new; + my $server_endpoint = "http://".ZM_TELEMETRY_SERVER_NAME.":".ZM_TELEMETRY_SERVER_PORT."/"; + + if ( $Config{ZM_UPDATE_CHECK_PROXY} ) { + $ua->proxy( "http", $Config{ZM_UPDATE_CHECK_PROXY} ); + } + + # set custom HTTP request header fields + my $req = HTTP::Request->new(POST => $server_endpoint); + # We can set some things in the header if we need to + #$req->header('content-type' => 'content here'); + #$req->header('Host' => '192.168.1.83:8899'); + $req->header('content-length' => length($msg)); + #$req->header('accept-encoding' => 'gzip, deflate'); + $req->header('connection' => 'Close'); + + $req->content($msg); + + my $resp = $ua->request($req); + my success = 0; + if ($resp->is_success) { + my $message = $resp->decoded_content; + Info("Telemetry data successfully uploaded."); + Debug("Telemetry server upload success response message: $message\n"); + $success = 1; + } else { + Warning("Telemetry server returned HTTP POST error code: ", $resp->code, "\n"; + Debug("Telemetry server upload failure response message: ", $resp->message, "\n"; + } + return $success; +} + From e0ee05e05c34024b660ff595bf7c3f01e2d5edf6 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Sat, 6 Feb 2016 14:10:42 -0600 Subject: [PATCH 03/33] add zmtelemetry to cmake --- scripts/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index e9dd6ddd3..fb549861b 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -16,6 +16,7 @@ configure_file(zmvideo.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmvideo.pl" @ONLY) configure_file(zmwatch.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmwatch.pl" @ONLY) configure_file(zmcamtool.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmcamtool.pl" @ONLY) configure_file(zmsystemctl.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmsystemctl.pl" @ONLY) +configure_file(zmtelemetry.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmsystemctl.pl" @ONLY) if(NOT ZM_NO_X10) configure_file(zmx10.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmx10.pl" @ONLY) endif(NOT ZM_NO_X10) @@ -31,7 +32,7 @@ FOREACH(PERLSCRIPT ${perlscripts}) ENDFOREACH(PERLSCRIPT ${perlscripts}) # Install the perl scripts -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/zmaudit.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmcontrol.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmdc.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmfilter.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmpkg.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmtrack.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmtrigger.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmupdate.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmvideo.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmwatch.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmcamtool.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmsystemctl.pl" DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/zmaudit.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmcontrol.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmdc.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmfilter.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmpkg.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmtrack.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmtrigger.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmupdate.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmvideo.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmwatch.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmcamtool.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmsystemctl.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmtelemetry.pl" DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) if(NOT ZM_NO_X10) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/zmx10.pl" DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) endif(NOT ZM_NO_X10) From 4ad31695bae09b2143fe150954bb03501145bb52 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Sat, 6 Feb 2016 14:25:00 -0600 Subject: [PATCH 04/33] fix typo in cmakefile --- scripts/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index fb549861b..cec664d6a 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -16,7 +16,7 @@ configure_file(zmvideo.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmvideo.pl" @ONLY) configure_file(zmwatch.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmwatch.pl" @ONLY) configure_file(zmcamtool.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmcamtool.pl" @ONLY) configure_file(zmsystemctl.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmsystemctl.pl" @ONLY) -configure_file(zmtelemetry.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmsystemctl.pl" @ONLY) +configure_file(zmtelemetry.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmtelemetry.pl.in" @ONLY) if(NOT ZM_NO_X10) configure_file(zmx10.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmx10.pl" @ONLY) endif(NOT ZM_NO_X10) From f607e3a6fa05c03b645a70346c008e5450167f3c Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Sat, 6 Feb 2016 14:50:02 -0600 Subject: [PATCH 05/33] zmtelemetry - the typo of my typo is my friend --- scripts/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index cec664d6a..37f93fd12 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -16,7 +16,7 @@ configure_file(zmvideo.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmvideo.pl" @ONLY) configure_file(zmwatch.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmwatch.pl" @ONLY) configure_file(zmcamtool.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmcamtool.pl" @ONLY) configure_file(zmsystemctl.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmsystemctl.pl" @ONLY) -configure_file(zmtelemetry.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmtelemetry.pl.in" @ONLY) +configure_file(zmtelemetry.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmtelemetry.pl" @ONLY) if(NOT ZM_NO_X10) configure_file(zmx10.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmx10.pl" @ONLY) endif(NOT ZM_NO_X10) From 609784f9023198aec771840be5bd39f144f3f245 Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Tue, 9 Feb 2016 12:49:09 -0700 Subject: [PATCH 06/33] Update telemetry host, port and protocol --- scripts/zmtelemetry.pl.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index 7b3b376a4..945c82156 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -63,8 +63,8 @@ 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_NAME => "telemetry.zoneminder.com"; -use constant ZM_TELEMETRY_SERVER_PORT => "80"; +use constant ZM_TELEMETRY_SERVER_NAME => "38092a65757da3cb5f949b6b94aa8fc9.us-east-1.aws.found.io"; +use constant ZM_TELEMETRY_SERVER_PORT => "9243"; if ( $Config{ZM_TELEMETRY_DATA} ) { @@ -128,7 +128,7 @@ sub sendData { use LWP::UserAgent; my $ua = LWP::UserAgent->new; - my $server_endpoint = "http://".ZM_TELEMETRY_SERVER_NAME.":".ZM_TELEMETRY_SERVER_PORT."/"; + my $server_endpoint = "https://".ZM_TELEMETRY_SERVER_NAME.":".ZM_TELEMETRY_SERVER_PORT."/"; if ( $Config{ZM_UPDATE_CHECK_PROXY} ) { $ua->proxy( "http", $Config{ZM_UPDATE_CHECK_PROXY} ); From 7a9740b1a4563fdcfe4d333080318c738ecdcb85 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Tue, 9 Feb 2016 14:35:45 -0600 Subject: [PATCH 07/33] Update zmtelemetry.pl.in --- scripts/zmtelemetry.pl.in | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index 945c82156..4a3a6efcf 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -128,19 +128,16 @@ sub sendData { use LWP::UserAgent; my $ua = LWP::UserAgent->new; - my $server_endpoint = "https://".ZM_TELEMETRY_SERVER_NAME.":".ZM_TELEMETRY_SERVER_PORT."/"; + my $server_endpoint = "https://".ZM_TELEMETRY_SERVER_NAME.":".ZM_TELEMETRY_SERVER_PORT."/zmtelemetry/testing/"; if ( $Config{ZM_UPDATE_CHECK_PROXY} ) { - $ua->proxy( "http", $Config{ZM_UPDATE_CHECK_PROXY} ); + $ua->proxy( "https", $Config{ZM_UPDATE_CHECK_PROXY} ); } # set custom HTTP request header fields my $req = HTTP::Request->new(POST => $server_endpoint); - # We can set some things in the header if we need to - #$req->header('content-type' => 'content here'); - #$req->header('Host' => '192.168.1.83:8899'); + $req->header('content-type' => 'application/x-www-form-urlencoded'); $req->header('content-length' => length($msg)); - #$req->header('accept-encoding' => 'gzip, deflate'); $req->header('connection' => 'Close'); $req->content($msg); From 18c493a1806864c4d0ef152410e23f20e6de3956 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Wed, 10 Feb 2016 13:04:14 -0600 Subject: [PATCH 08/33] Add getUUID subroutine, Add ZM_TELEMETRY_LAST_UPLOAD --- .../lib/ZoneMinder/ConfigData.pm.in | 21 +++++++++++++++++ scripts/zmtelemetry.pl.in | 23 ++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in index ffe063b60..2c014aee2 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in @@ -2763,6 +2763,27 @@ body = "ZM alarm detected - %EL% secs, %EF%/%EFA% frames, t%EST%/m%ESM%/a%ESA% s type => $types{boolean}, category => "system", }, + { + name => "ZM_TELEMETRY_UUID", + default => "yes", + description => "Unique identifier for ZoneMinder telemetry", + help => qqq(" + This variable is auto-generated once by the system and is used to + uniquely identify it among all other ZoneMinder systems in + existence. + "), + type => $types{string}, + category => "dynamic", + }, + { + name => "ZM_TELEMETRY_LAST_UPLOAD", + default => "", + description => "When the last ZoneMinder telemetry upload ocurred", + help => "", + type => $types{integer}, + readonly => 1, + category => "dynamic", + }, { name => "ZM_UPDATE_CHECK_PROXY", default => "", diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index 4a3a6efcf..bc7458ac1 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -91,7 +91,7 @@ if ( $Config{ZM_TELEMETRY_DATA} ) if ( sendData($result) ) { $lastCheck = $now; - my $lc_sql = "update Config set Value = ? where Name = 'ZM_DYN_LAST_CHECK'"; + my $lc_sql = "update Config set Value = ? where Name = 'ZM_TELEMETRY_LAST_UPLOAD'"; my $lc_sth = $dbh->prepare_cached( $lc_sql ) or die( "Can't prepare '$lc_sql': ".$dbh->errstr() ); my $lc_res = $lc_sth->execute( $lastCheck ) or die( "Can't execute: ".$lc_sth->errstr() ); } @@ -156,3 +156,24 @@ sub sendData { return $success; } +# Retrieves the UUID from the database. Creates a new UUID if one does not exist. +sub getUUID { + my $uuid= ""; + + if ( $Config{ZM_TELEMETRY_UUID} ) { + $uuid = $Config{ZM_TELEMETRY_UUID}; + } else { + use OSSSP::uuid; + my $uuidobj = OSSP::uuid->new; + $uuidobj -> make("v1"); + $uuid = $uuidobj->export("str"); + + my $sql = "update Config set Value = ? where Name = 'ZM_TELEMETRY_UUID'"; + my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); + my $res = $sth->execute( $uuid ) or die( "Can't execute: ".$sth->errstr() ); + } + +return $uuid; +} + + From f48ffb60e6376220def5019c303ab5cf0b06d59b Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Wed, 10 Feb 2016 13:37:22 -0600 Subject: [PATCH 09/33] update ZM_TELEMETRY_UUID after creating uuid --- scripts/zmtelemetry.pl.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index bc7458ac1..1b68f31c3 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -166,7 +166,7 @@ sub getUUID { use OSSSP::uuid; my $uuidobj = OSSP::uuid->new; $uuidobj -> make("v1"); - $uuid = $uuidobj->export("str"); + $uuid = $Config{ZM_TELEMETRY_UUID} = $uuidobj->export("str"); my $sql = "update Config set Value = ? where Name = 'ZM_TELEMETRY_UUID'"; my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); From 177a70a2485f9f7cc0a224e261b5bbd692e1aea1 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Wed, 10 Feb 2016 14:05:34 -0600 Subject: [PATCH 10/33] add getIP subroutine to zmtelemetry.pl --- scripts/zmtelemetry.pl.in | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index 1b68f31c3..99e32cac1 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -176,4 +176,21 @@ sub getUUID { return $uuid; } +# Retrieves the local server's external IP address +sub getIP { + use LWP::UserAgent; + + my $ipaddr = "0.0.0.0"; + my $ua = LWP::UserAgent->new; + my $server_endpoint = "https://wiki.zoneminder.com/ip.php"; + + my $req = HTTP::Request->new(GET => $server_endpoint); + my $resp = $ua->request($req); + + if ($resp->is_success) { + $ipaddr = $resp->decoded_content; + } + +return $ipaddr; +} From 6d81ef247e8b1a37d8acff216dce07f7810778bc Mon Sep 17 00:00:00 2001 From: Andy Bauer Date: Wed, 10 Feb 2016 20:46:05 -0600 Subject: [PATCH 11/33] build telemetry hash then jsonencode it --- scripts/zmtelemetry.pl.in | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index 99e32cac1..5d7fcb1a0 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -54,6 +54,9 @@ use ZoneMinder::Database qw(:all); use DBI; use Getopt::Long; use autouse 'Pod::Usage'=>qw(pod2usage); +use LWP::UserAgent; +use Sys::MemInfo; +use Sys::CPU; $ENV{PATH} = '/bin:/usr/bin:/usr/local/bin'; $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL}; @@ -77,16 +80,26 @@ if ( $Config{ZM_TELEMETRY_DATA} ) my $now = time(); if ( ($now-$lastCheck) > CHECK_INTERVAL) ) { - Info( "Colleting data to send to ZoneMinder Telemetry server\n" ); - - # This is where we gather our data. The following is just an oversimplified example. - # Modify accordingly. + Info( "Colleting data to send to ZoneMinder Telemetry server." ); + # Build the telemetry hash # We should keep *BSD systems in mind when calling system commands - my $result = runSysCmd("uname -a")."\n"; - my $result .= "ZM_DYN_CURR_VERSION: ".Config{ZM_DYN_CURR_VERSION}; + my %telemetry; + $telemetry{uuid} = getUUID(); + $telemetry{ip} = getIP(); + $telemetry{timestamp} = runSysCmd("date -In"); + #$telemetry{monitor_count} = TO-DO + #$telemetry{event_count} = TO-DO + $telemetry{distro} = runSysCmd("uname -a"); + $telemetry{release} = runSysCmd("cat /etc/*{release,version}"); + $telemetry{zm_version} = ZoneMinder::Base::ZM_VERSION; + $telemetry{system_memory} = totalmem() / (1024*1024); + $telemetry{processor_count} = cpu_count(); + #$telemetry{monitors} = TO-DO - Info( "Sending data to ZoneMinder Telemetry server\n" ); + Info( "Sending data to ZoneMinder Telemetry server." ); + + my $result = jsonEncode( \%telemetry ); if ( sendData($result) ) { $lastCheck = $now; @@ -95,6 +108,8 @@ if ( $Config{ZM_TELEMETRY_DATA} ) my $lc_sth = $dbh->prepare_cached( $lc_sql ) or die( "Can't prepare '$lc_sql': ".$dbh->errstr() ); my $lc_res = $lc_sth->execute( $lastCheck ) or die( "Can't execute: ".$lc_sth->errstr() ); } + + Info( "Telemetry data uploaded successfully." ); } sleep( 3600 ); } @@ -125,8 +140,6 @@ sub runSysCmd { sub sendData { my $msg = shift; - use LWP::UserAgent; - my $ua = LWP::UserAgent->new; my $server_endpoint = "https://".ZM_TELEMETRY_SERVER_NAME.":".ZM_TELEMETRY_SERVER_PORT."/zmtelemetry/testing/"; @@ -147,11 +160,11 @@ sub sendData { if ($resp->is_success) { my $message = $resp->decoded_content; Info("Telemetry data successfully uploaded."); - Debug("Telemetry server upload success response message: $message\n"); + Debug("Telemetry server upload success response message: $message"); $success = 1; } else { - Warning("Telemetry server returned HTTP POST error code: ", $resp->code, "\n"; - Debug("Telemetry server upload failure response message: ", $resp->message, "\n"; + Warning("Telemetry server returned HTTP POST error code: $resp->code"); + Debug("Telemetry server upload failure response message: $resp->message"); } return $success; } @@ -178,8 +191,6 @@ return $uuid; # Retrieves the local server's external IP address sub getIP { - use LWP::UserAgent; - my $ipaddr = "0.0.0.0"; my $ua = LWP::UserAgent->new; my $server_endpoint = "https://wiki.zoneminder.com/ip.php"; From f5ff5d152c870793cd74ea138576b6bdd0b4fff1 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Thu, 11 Feb 2016 07:22:31 -0600 Subject: [PATCH 12/33] Add count query subroutine --- scripts/zmtelemetry.pl.in | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index 5d7fcb1a0..6e33c9b55 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -88,8 +88,8 @@ if ( $Config{ZM_TELEMETRY_DATA} ) $telemetry{uuid} = getUUID(); $telemetry{ip} = getIP(); $telemetry{timestamp} = runSysCmd("date -In"); - #$telemetry{monitor_count} = TO-DO - #$telemetry{event_count} = TO-DO + $telemetry{monitor_count} = countQuery("Monitors"); + $telemetry{event_count} = countQuery("Events"); $telemetry{distro} = runSysCmd("uname -a"); $telemetry{release} = runSysCmd("cat /etc/*{release,version}"); $telemetry{zm_version} = ZoneMinder::Base::ZM_VERSION; @@ -205,3 +205,15 @@ sub getIP { return $ipaddr; } +# As the name implies, just your average mysql count query +sub countQuery { + my $table = shift; + my $count = 0; + + my $sql = "select count(*) from ?"; + my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); + $count = $sth->execute( $table ) or die( "Can't execute: ".$sth->errstr() ); + +return $count +} + From 1811d715624d8dd6dd29aacd6096a014d43bcbb8 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Thu, 11 Feb 2016 08:10:16 -0600 Subject: [PATCH 13/33] make date format compatible with *BSD --- scripts/zmtelemetry.pl.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index 6e33c9b55..9e2003ae9 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -87,7 +87,7 @@ if ( $Config{ZM_TELEMETRY_DATA} ) my %telemetry; $telemetry{uuid} = getUUID(); $telemetry{ip} = getIP(); - $telemetry{timestamp} = runSysCmd("date -In"); + $telemetry{timestamp} = runSysCmd("date +%Y-%m-%dT%H:%M:%S%z"); $telemetry{monitor_count} = countQuery("Monitors"); $telemetry{event_count} = countQuery("Events"); $telemetry{distro} = runSysCmd("uname -a"); From 1b6af8afaed4122bddcf7229e3f7f8608ec0cb0d Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Thu, 11 Feb 2016 13:10:36 -0600 Subject: [PATCH 14/33] modify telemetry parameters --- scripts/zmtelemetry.pl.in | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index 9e2003ae9..439411790 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -57,6 +57,8 @@ use autouse 'Pod::Usage'=>qw(pod2usage); use LWP::UserAgent; use Sys::MemInfo; use Sys::CPU; +use DateTime; +use POSIX qw(strftime); $ENV{PATH} = '/bin:/usr/bin:/usr/local/bin'; $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL}; @@ -87,9 +89,10 @@ if ( $Config{ZM_TELEMETRY_DATA} ) my %telemetry; $telemetry{uuid} = getUUID(); $telemetry{ip} = getIP(); - $telemetry{timestamp} = runSysCmd("date +%Y-%m-%dT%H:%M:%S%z"); + $telemetry{timestamp} = DateTime->now( time_zone => "local" )->strftime("%Y-%m-%dT%H:%M:%S%z"); $telemetry{monitor_count} = countQuery("Monitors"); $telemetry{event_count} = countQuery("Events"); + $telemetry{architecture} = runSysCmd("uname -m"); $telemetry{distro} = runSysCmd("uname -a"); $telemetry{release} = runSysCmd("cat /etc/*{release,version}"); $telemetry{zm_version} = ZoneMinder::Base::ZM_VERSION; From 017417d8f80f3b41d40e4b8095a6b5f45cb15207 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Fri, 12 Feb 2016 08:06:51 -0600 Subject: [PATCH 15/33] small changes to zmtelemetry --- scripts/zmtelemetry.pl.in | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index 439411790..c8f082aa6 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -48,9 +48,7 @@ use strict; use bytes; @EXTRA_PERL_LIB@ -use ZoneMinder::Config qw(:all); -use ZoneMinder::Logger qw(:all); -use ZoneMinder::Database qw(:all); +use ZoneMinder; use DBI; use Getopt::Long; use autouse 'Pod::Usage'=>qw(pod2usage); @@ -83,7 +81,7 @@ if ( $Config{ZM_TELEMETRY_DATA} ) if ( ($now-$lastCheck) > CHECK_INTERVAL) ) { Info( "Colleting data to send to ZoneMinder Telemetry server." ); - + my $dbh = zmDbConnect(); # Build the telemetry hash # We should keep *BSD systems in mind when calling system commands my %telemetry; From 799437fdf1cd4c864edc11c73ad13c9d5a0ded2f Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Fri, 12 Feb 2016 08:59:16 -0600 Subject: [PATCH 16/33] retrieve telemetry data from the monitors table --- scripts/zmtelemetry.pl.in | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index c8f082aa6..7dc52984b 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -96,7 +96,7 @@ if ( $Config{ZM_TELEMETRY_DATA} ) $telemetry{zm_version} = ZoneMinder::Base::ZM_VERSION; $telemetry{system_memory} = totalmem() / (1024*1024); $telemetry{processor_count} = cpu_count(); - #$telemetry{monitors} = TO-DO + $telemetry{monitors} = getMonitorRef(); Info( "Sending data to ZoneMinder Telemetry server." ); @@ -218,3 +218,14 @@ sub countQuery { return $count } +# Returns a reference to an array of hashes containing data from all monitors +sub getMonitorRef { + + my $sql = "SELECT Id,Name,Type,Function,Width,Height,Colours,MaxFPS,AlarmMaxFPS FROM Monitors"; + my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); + my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() ); + $arrayref = $sth->fetchall_arrayref({}); + +return $arrayref; +} + From b04e1eb0c6dc6d2f0e60e00fda6212f5575fb09c Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Fri, 12 Feb 2016 09:18:15 -0600 Subject: [PATCH 17/33] let mysql generate the uuid --- scripts/zmtelemetry.pl.in | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index 7dc52984b..d8adb8ff1 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -177,14 +177,15 @@ sub getUUID { if ( $Config{ZM_TELEMETRY_UUID} ) { $uuid = $Config{ZM_TELEMETRY_UUID}; } else { - use OSSSP::uuid; - my $uuidobj = OSSP::uuid->new; - $uuidobj -> make("v1"); - $uuid = $Config{ZM_TELEMETRY_UUID} = $uuidobj->export("str"); - - my $sql = "update Config set Value = ? where Name = 'ZM_TELEMETRY_UUID'"; + my $sql = "select uuid()"; my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute( $uuid ) or die( "Can't execute: ".$sth->errstr() ); + my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() ); + $uuid = $Config{ZM_TELEMETRY_UUID} = $sth->fetchrow_array(); + $sth->finish(); + + $sql = "update Config set Value = ? where Name = 'ZM_TELEMETRY_UUID'"; + $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); + $res = $sth->execute( $uuid ) or die( "Can't execute: ".$sth->errstr() ); } return $uuid; @@ -213,7 +214,8 @@ sub countQuery { my $sql = "select count(*) from ?"; my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); - $count = $sth->execute( $table ) or die( "Can't execute: ".$sth->errstr() ); + my $res = $sth->execute( $table ) or die( "Can't execute: ".$sth->errstr() ); + my $count = $sth->fetchrow_array(); return $count } From c892e912cf633822139ca38024e33c49a2d79167 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Fri, 12 Feb 2016 10:47:12 -0600 Subject: [PATCH 18/33] use uname -p for telemetry architecture --- scripts/zmtelemetry.pl.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index d8adb8ff1..5ddaf1cfd 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -90,7 +90,7 @@ if ( $Config{ZM_TELEMETRY_DATA} ) $telemetry{timestamp} = DateTime->now( time_zone => "local" )->strftime("%Y-%m-%dT%H:%M:%S%z"); $telemetry{monitor_count} = countQuery("Monitors"); $telemetry{event_count} = countQuery("Events"); - $telemetry{architecture} = runSysCmd("uname -m"); + $telemetry{architecture} = runSysCmd("uname -p"); $telemetry{distro} = runSysCmd("uname -a"); $telemetry{release} = runSysCmd("cat /etc/*{release,version}"); $telemetry{zm_version} = ZoneMinder::Base::ZM_VERSION; From 5045da9382fea120f130b4325f6d4abcaaacfe55 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Fri, 12 Feb 2016 15:18:45 -0600 Subject: [PATCH 19/33] add initial distro determination logic to zmtelemetry --- scripts/zmtelemetry.pl.in | 100 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 97 insertions(+), 3 deletions(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index 5ddaf1cfd..b730c28c5 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -91,8 +91,7 @@ if ( $Config{ZM_TELEMETRY_DATA} ) $telemetry{monitor_count} = countQuery("Monitors"); $telemetry{event_count} = countQuery("Events"); $telemetry{architecture} = runSysCmd("uname -p"); - $telemetry{distro} = runSysCmd("uname -a"); - $telemetry{release} = runSysCmd("cat /etc/*{release,version}"); + ($telemetry{kernel}, $telemetry{distro}, $telemetry{version}) = getDistro(); $telemetry{zm_version} = ZoneMinder::Base::ZM_VERSION; $telemetry{system_memory} = totalmem() / (1024*1024); $telemetry{processor_count} = cpu_count(); @@ -132,7 +131,7 @@ sub runSysCmd { chomp($path); $arguments[0] = $path; my $cmd = join(" ",@arguments); - my $result = qx( $cmd ); + $result = qx( $cmd ); } return chomp($result); } @@ -231,3 +230,98 @@ sub getMonitorRef { return $arrayref; } +sub getDistro { + my $kernel = ""; + my $distro = ""; + my $version = ""; + + my $test = runSysCmd("uname"); + + if ( $test =~ /Linux/ ) { + #print "Linux distro.\n"; + ($kernel, $distro, $version) = linuxDistro(); + } elsif ( $test =~ /.*BSD/ ) { + #print "BSD distro.\n"; + $kernel = runSysCmd("uname -i"); + $distro = runSysCmd("uname"); + $version = runSysCmd("uname -r"); + } elsif ( $test =~ /Darwin/ ) { + #print "Mac OS.\n"; + } elsif ( $test =~ /SunOS|Solaris/ ) { + #print "Sun Solaris.\n"; + $kernel = runSysCmd("uname -v"); + $distro = runSysCmd("uname"); + $version = runSysCmd("uname -r"); + } else { + $kernel = "Unknown"; + $distro = "Unknown"; + $version = "Unknown"; + } + +return ($kernel, $distro, $version); +} + +sub linuxDistro { + my $kernel = runSysCmd("uname -r"); + my $distro = "Unknown Linux Distro"; + my $version = "Unknown Linux Version"; + my $found = 0; + + # + # TO-DO: The regex's below are close but still need tweaking. + # + + # os-release is the standard for many new distros based on systemd + if ( -f "/etc/os-release" ) { + open(my $RELFILE,"<","/etc/os-release") or die( "Can't Open file: $!\n" ); + while (<$RELFILE>) { + if ( /PRETTY_NAME=\"?(.*)\"?.*/ ) { + $distro = $1; + $found = 1; + } + if ( /VERSION_ID=\"?(.*)\"?.*/ ) { + $version = $1; + $found = 1; + } + } + close $RELFILE; + # exists on many distros but does not always contain useful information, such as redhat + } elsif ( -f "/etc/lsb-release" ) { + open(my $RELFILE,"<","/etc/lsb-release") or die( "Can't Open file: $!\n" ); + while (<$RELFILE>) { + if ( /DISTRIB_DESCRIPTION=\"?(.*)\"?.*/ ) { + $distro = $1; + $found = 1; + } + if ( /DISTRIB_RELEASE=\"?(.*)\"?.*/ ) { + $version = $1; + $found = 1; + } + } + close $RELFILE; + } + + # If all else fails, search through a list of known release files until we find one + if ( !$found ) { + @releasefile = ("/etc/SuSE-release", "/etc/redhat-release", "/etc/redhat_version", + "/etc/fedora-release", "/etc/slackware-release", "/etc/slackware-version", + "/etc/debian_release", "/etc/debian_version", "/etc/mandrake-release", + "/etc/yellowdog-release", "/etc/gentoo-release"); + foreach (@releasefile) { + if ( -f $_ ) { + open(my $RELFILE,"<",$_) or die( "Can't Open file: $!\n" ); + while (<$RELFILE>) { + if ( /(.*).* (\d+\.?\d*) .*/ ) { + $distro = $1; + $version = $2; + } + } + close $RELFILE; + last; + } + } + } +return ($kernel, $distro, $version); +} + + From 3c48d81edb1ddf1097837032c42d32c600e38214 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Fri, 12 Feb 2016 17:15:04 -0600 Subject: [PATCH 20/33] tweak regex's. add debug --- scripts/zmtelemetry.pl.in | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index b730c28c5..abfbf428d 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -238,17 +238,17 @@ sub getDistro { my $test = runSysCmd("uname"); if ( $test =~ /Linux/ ) { - #print "Linux distro.\n"; + Debug("Linux distro detected."); ($kernel, $distro, $version) = linuxDistro(); } elsif ( $test =~ /.*BSD/ ) { - #print "BSD distro.\n"; + Debug("BSD distro detected."); $kernel = runSysCmd("uname -i"); $distro = runSysCmd("uname"); $version = runSysCmd("uname -r"); } elsif ( $test =~ /Darwin/ ) { - #print "Mac OS.\n"; + Debug("Mac OS distro detected."); } elsif ( $test =~ /SunOS|Solaris/ ) { - #print "Sun Solaris.\n"; + Debug("Sun Solaris detected."); $kernel = runSysCmd("uname -v"); $distro = runSysCmd("uname"); $version = runSysCmd("uname -r"); @@ -275,12 +275,12 @@ sub linuxDistro { if ( -f "/etc/os-release" ) { open(my $RELFILE,"<","/etc/os-release") or die( "Can't Open file: $!\n" ); while (<$RELFILE>) { - if ( /PRETTY_NAME=\"?(.*)\"?.*/ ) { - $distro = $1; + if ( /^NAME=(")?(.*)(?(1)\1|).*$/ ) { + $distro = $2; $found = 1; } - if ( /VERSION_ID=\"?(.*)\"?.*/ ) { - $version = $1; + if ( /^VERSION_ID=(")?(.*)(?(1)\1|).*$/ ) { + $version = $2; $found = 1; } } @@ -289,12 +289,12 @@ sub linuxDistro { } elsif ( -f "/etc/lsb-release" ) { open(my $RELFILE,"<","/etc/lsb-release") or die( "Can't Open file: $!\n" ); while (<$RELFILE>) { - if ( /DISTRIB_DESCRIPTION=\"?(.*)\"?.*/ ) { - $distro = $1; + if ( /^DISTRIB_DESCRIPTION=(")?(.*)(?(1)\1|).*$/ ) { + $distro = $2; $found = 1; } - if ( /DISTRIB_RELEASE=\"?(.*)\"?.*/ ) { - $version = $1; + if ( /^DISTRIB_RELEASE=(")?(.*)(?(1)\1|).*$/ ) { + $version = $2; $found = 1; } } From 24838a91c9f2bebc87751e746f7caaa4041c8da6 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Fri, 12 Feb 2016 17:38:00 -0600 Subject: [PATCH 21/33] set kernel, distro, and version for Mac OS --- scripts/zmtelemetry.pl.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index abfbf428d..d5fa56bad 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -247,6 +247,9 @@ sub getDistro { $version = runSysCmd("uname -r"); } elsif ( $test =~ /Darwin/ ) { Debug("Mac OS distro detected."); + $kernel = runSysCmd("uname -v"); + $distro = runSysCmd("uname"); + $version = runSysCmd("uname -r"); } elsif ( $test =~ /SunOS|Solaris/ ) { Debug("Sun Solaris detected."); $kernel = runSysCmd("uname -v"); From 87857f5dc1398d819dc08187cf54d10e2d5db807 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Fri, 12 Feb 2016 17:45:08 -0600 Subject: [PATCH 22/33] more debug and warnings --- scripts/zmtelemetry.pl.in | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index d5fa56bad..fa6f9631d 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -256,6 +256,7 @@ sub getDistro { $distro = runSysCmd("uname"); $version = runSysCmd("uname -r"); } else { + Warning("ZoneMinder was unable to determine the host system. Please report."); $kernel = "Unknown"; $distro = "Unknown"; $version = "Unknown"; @@ -317,6 +318,7 @@ sub linuxDistro { if ( /(.*).* (\d+\.?\d*) .*/ ) { $distro = $1; $version = $2; + $found = 1; } } close $RELFILE; @@ -324,6 +326,11 @@ sub linuxDistro { } } } + + if ( !found ) { + Warning("ZoneMinder was unable to determine Linux distro. Please report."); + } + return ($kernel, $distro, $version); } From 08af88df1024b6be08ba2b30e8068de658ca5887 Mon Sep 17 00:00:00 2001 From: Andy Bauer Date: Sat, 13 Feb 2016 08:54:40 -0600 Subject: [PATCH 23/33] fix compilation errors --- scripts/zmtelemetry.pl.in | 59 ++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index fa6f9631d..ad5e9914b 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -53,8 +53,8 @@ use DBI; use Getopt::Long; use autouse 'Pod::Usage'=>qw(pod2usage); use LWP::UserAgent; -use Sys::MemInfo; -use Sys::CPU; +use Sys::MemInfo qw(totalmem); +use Sys::CPU qw(cpu_count); use DateTime; use POSIX qw(strftime); @@ -75,27 +75,25 @@ if ( $Config{ZM_TELEMETRY_DATA} ) my $lastCheck = $Config{ZM_TELEMETRY_LAST_CHECK}; - while( 1 ) - { + while( 1 ) { my $now = time(); - if ( ($now-$lastCheck) > CHECK_INTERVAL) ) - { + if ( ($now-$lastCheck) > CHECK_INTERVAL ) { Info( "Colleting data to send to ZoneMinder Telemetry server." ); my $dbh = zmDbConnect(); # Build the telemetry hash # We should keep *BSD systems in mind when calling system commands my %telemetry; - $telemetry{uuid} = getUUID(); + $telemetry{uuid} = getUUID($dbh); $telemetry{ip} = getIP(); $telemetry{timestamp} = DateTime->now( time_zone => "local" )->strftime("%Y-%m-%dT%H:%M:%S%z"); - $telemetry{monitor_count} = countQuery("Monitors"); - $telemetry{event_count} = countQuery("Events"); + $telemetry{monitor_count} = countQuery($dbh,"Monitors"); + $telemetry{event_count} = countQuery($dbh,"Events"); $telemetry{architecture} = runSysCmd("uname -p"); ($telemetry{kernel}, $telemetry{distro}, $telemetry{version}) = getDistro(); $telemetry{zm_version} = ZoneMinder::Base::ZM_VERSION; $telemetry{system_memory} = totalmem() / (1024*1024); $telemetry{processor_count} = cpu_count(); - $telemetry{monitors} = getMonitorRef(); + $telemetry{monitors} = getMonitorRef($dbh); Info( "Sending data to ZoneMinder Telemetry server." ); @@ -104,9 +102,10 @@ if ( $Config{ZM_TELEMETRY_DATA} ) if ( sendData($result) ) { $lastCheck = $now; - my $lc_sql = "update Config set Value = ? where Name = 'ZM_TELEMETRY_LAST_UPLOAD'"; - my $lc_sth = $dbh->prepare_cached( $lc_sql ) or die( "Can't prepare '$lc_sql': ".$dbh->errstr() ); - my $lc_res = $lc_sth->execute( $lastCheck ) or die( "Can't execute: ".$lc_sth->errstr() ); + my $sql = "update Config set Value = ? where Name = 'ZM_TELEMETRY_LAST_UPLOAD'"; + my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); + my $res = $sth->execute( "$lastCheck" ) or die( "Can't execute: ".$sth->errstr() ); + $sth->finish(); } Info( "Telemetry data uploaded successfully." ); @@ -116,6 +115,10 @@ if ( $Config{ZM_TELEMETRY_DATA} ) print( "Update agent exiting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" ); } +############### +# SUBROUTINES # +############### + # Find, verify, then run the supplied system command sub runSysCmd { my $msg = shift; @@ -156,35 +159,35 @@ sub sendData { $req->content($msg); my $resp = $ua->request($req); - my success = 0; if ($resp->is_success) { my $message = $resp->decoded_content; Info("Telemetry data successfully uploaded."); Debug("Telemetry server upload success response message: $message"); - $success = 1; } else { Warning("Telemetry server returned HTTP POST error code: $resp->code"); Debug("Telemetry server upload failure response message: $resp->message"); } - return $success; + return $resp->is_success; } # Retrieves the UUID from the database. Creates a new UUID if one does not exist. sub getUUID { + my $dbh = shift; my $uuid= ""; if ( $Config{ZM_TELEMETRY_UUID} ) { $uuid = $Config{ZM_TELEMETRY_UUID}; } else { - my $sql = "select uuid()"; + my $sql = "SELECT uuid()"; my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() ); $uuid = $Config{ZM_TELEMETRY_UUID} = $sth->fetchrow_array(); $sth->finish(); - $sql = "update Config set Value = ? where Name = 'ZM_TELEMETRY_UUID'"; + $sql = "UPDATE Config set Value = ? WHERE Name = 'ZM_TELEMETRY_UUID'"; $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); - $res = $sth->execute( $uuid ) or die( "Can't execute: ".$sth->errstr() ); + $res = $sth->execute( "$uuid" ) or die( "Can't execute: ".$sth->errstr() ); + $sth->finish(); } return $uuid; @@ -208,24 +211,26 @@ return $ipaddr; # As the name implies, just your average mysql count query sub countQuery { + my $dbh = shift; my $table = shift; - my $count = 0; - my $sql = "select count(*) from ?"; + my $sql = "SELECT count(*) FROM $table"; my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute( $table ) or die( "Can't execute: ".$sth->errstr() ); + my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() ); my $count = $sth->fetchrow_array(); + $sth->finish(); return $count } # Returns a reference to an array of hashes containing data from all monitors sub getMonitorRef { + my $dbh = shift; my $sql = "SELECT Id,Name,Type,Function,Width,Height,Colours,MaxFPS,AlarmMaxFPS FROM Monitors"; my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() ); - $arrayref = $sth->fetchall_arrayref({}); + my $arrayref = $sth->fetchall_arrayref({}); return $arrayref; } @@ -271,10 +276,6 @@ sub linuxDistro { my $version = "Unknown Linux Version"; my $found = 0; - # - # TO-DO: The regex's below are close but still need tweaking. - # - # os-release is the standard for many new distros based on systemd if ( -f "/etc/os-release" ) { open(my $RELFILE,"<","/etc/os-release") or die( "Can't Open file: $!\n" ); @@ -307,7 +308,7 @@ sub linuxDistro { # If all else fails, search through a list of known release files until we find one if ( !$found ) { - @releasefile = ("/etc/SuSE-release", "/etc/redhat-release", "/etc/redhat_version", + my @releasefile = ("/etc/SuSE-release", "/etc/redhat-release", "/etc/redhat_version", "/etc/fedora-release", "/etc/slackware-release", "/etc/slackware-version", "/etc/debian_release", "/etc/debian_version", "/etc/mandrake-release", "/etc/yellowdog-release", "/etc/gentoo-release"); @@ -327,7 +328,7 @@ sub linuxDistro { } } - if ( !found ) { + if ( !$found ) { Warning("ZoneMinder was unable to determine Linux distro. Please report."); } From ee3f87a2ad67b045c622c9f8b2aba08a73e9aaca Mon Sep 17 00:00:00 2001 From: Andy Bauer Date: Sat, 13 Feb 2016 14:53:22 -0600 Subject: [PATCH 24/33] additional refinements to zmtelemetry --- .../lib/ZoneMinder/ConfigData.pm.in | 2 +- scripts/zmtelemetry.pl.in | 29 ++++++++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in index 2c014aee2..49c51e368 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in @@ -2765,7 +2765,7 @@ body = "ZM alarm detected - %EL% secs, %EF%/%EFA% frames, t%EST%/m%ESM%/a%ESA% s }, { name => "ZM_TELEMETRY_UUID", - default => "yes", + default => "", description => "Unique identifier for ZoneMinder telemetry", help => qqq(" This variable is auto-generated once by the system and is used to diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index ad5e9914b..add9c141b 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -107,8 +107,6 @@ if ( $Config{ZM_TELEMETRY_DATA} ) my $res = $sth->execute( "$lastCheck" ) or die( "Can't execute: ".$sth->errstr() ); $sth->finish(); } - - Info( "Telemetry data uploaded successfully." ); } sleep( 3600 ); } @@ -135,8 +133,10 @@ sub runSysCmd { $arguments[0] = $path; my $cmd = join(" ",@arguments); $result = qx( $cmd ); + chomp($result); } - return chomp($result); + +return $result; } # Upload message data to ZoneMinder telemetry server @@ -150,6 +150,8 @@ sub sendData { $ua->proxy( "https", $Config{ZM_UPDATE_CHECK_PROXY} ); } + Debug("Posting telemetry data to: $server_endpoint"); + # set custom HTTP request header fields my $req = HTTP::Request->new(POST => $server_endpoint); $req->header('content-type' => 'application/x-www-form-urlencoded'); @@ -159,15 +161,16 @@ sub sendData { $req->content($msg); my $resp = $ua->request($req); - if ($resp->is_success) { - my $message = $resp->decoded_content; - Info("Telemetry data successfully uploaded."); - Debug("Telemetry server upload success response message: $message"); + my $resp_msg = $resp->decoded_content; + my $resp_code = $resp->code; + if ($resp->is_success) { + Info("Telemetry data uploaded successfully."); + Debug("Telemetry server upload success response message: $resp_msg"); } else { - Warning("Telemetry server returned HTTP POST error code: $resp->code"); - Debug("Telemetry server upload failure response message: $resp->message"); + Warning("Telemetry server returned HTTP POST error code: $resp_code"); + Debug("Telemetry server upload failure response message: $resp_msg"); } - return $resp->is_success; +return $resp->is_success; } # Retrieves the UUID from the database. Creates a new UUID if one does not exist. @@ -175,7 +178,8 @@ sub getUUID { my $dbh = shift; my $uuid= ""; - if ( $Config{ZM_TELEMETRY_UUID} ) { + # Verify the current UUID is valid and not nil + if (( $Config{ZM_TELEMETRY_UUID} =~ /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/i ) && ( $Config{ZM_TELEMETRY_UUID} ne "00000000-0000-0000-0000-000000000000" )) { $uuid = $Config{ZM_TELEMETRY_UUID}; } else { my $sql = "SELECT uuid()"; @@ -189,6 +193,7 @@ sub getUUID { $res = $sth->execute( "$uuid" ) or die( "Can't execute: ".$sth->errstr() ); $sth->finish(); } + Debug("Using UUID of: $uuid"); return $uuid; } @@ -206,6 +211,8 @@ sub getIP { $ipaddr = $resp->decoded_content; } + Info("Found external ip address of: $ipaddr"); + return $ipaddr; } From 47eaea78bed46985bb86bd856dc047d12af30086 Mon Sep 17 00:00:00 2001 From: Andy Bauer Date: Sat, 13 Feb 2016 15:01:22 -0600 Subject: [PATCH 25/33] use units of bytes for total memory --- scripts/zmtelemetry.pl.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index add9c141b..c2a482a1c 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -91,7 +91,7 @@ if ( $Config{ZM_TELEMETRY_DATA} ) $telemetry{architecture} = runSysCmd("uname -p"); ($telemetry{kernel}, $telemetry{distro}, $telemetry{version}) = getDistro(); $telemetry{zm_version} = ZoneMinder::Base::ZM_VERSION; - $telemetry{system_memory} = totalmem() / (1024*1024); + $telemetry{system_memory} = totalmem(); $telemetry{processor_count} = cpu_count(); $telemetry{monitors} = getMonitorRef($dbh); From cd8a4adfabee2bbf4abbbf4e3e44f40bdbd2d198 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Mon, 15 Feb 2016 08:43:34 -0600 Subject: [PATCH 26/33] replace uname system call with native perl when applicable --- scripts/zmtelemetry.pl.in | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index c2a482a1c..26b620d38 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -56,7 +56,7 @@ use LWP::UserAgent; use Sys::MemInfo qw(totalmem); use Sys::CPU qw(cpu_count); use DateTime; -use POSIX qw(strftime); +use POSIX qw(strftime uname); $ENV{PATH} = '/bin:/usr/bin:/usr/local/bin'; $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL}; @@ -246,27 +246,26 @@ sub getDistro { my $kernel = ""; my $distro = ""; my $version = ""; + my @uname = uname(); - my $test = runSysCmd("uname"); - - if ( $test =~ /Linux/ ) { + if ( $uname[0] =~ /Linux/ ) { Debug("Linux distro detected."); ($kernel, $distro, $version) = linuxDistro(); - } elsif ( $test =~ /.*BSD/ ) { + } elsif ( $uname[0] =~ /.*BSD/ ) { Debug("BSD distro detected."); - $kernel = runSysCmd("uname -i"); - $distro = runSysCmd("uname"); - $version = runSysCmd("uname -r"); - } elsif ( $test =~ /Darwin/ ) { + $kernel = $uname[3]; + $distro = $uname[0]; + $version = $uname[2]; + } elsif ( $uname[0] =~ /Darwin/ ) { Debug("Mac OS distro detected."); - $kernel = runSysCmd("uname -v"); - $distro = runSysCmd("uname"); - $version = runSysCmd("uname -r"); - } elsif ( $test =~ /SunOS|Solaris/ ) { + $kernel = $uname[3]; + $distro = runSysCmd("sw_vers -productName"); + $version = runSysCmd("sw_vers -productVersion"); + } elsif ( $uname[0] =~ /SunOS|Solaris/ ) { Debug("Sun Solaris detected."); - $kernel = runSysCmd("uname -v"); - $distro = runSysCmd("uname"); - $version = runSysCmd("uname -r"); + $kernel = $uname[3]; + $distro = $uname[1]; + $version = $uname[2]; } else { Warning("ZoneMinder was unable to determine the host system. Please report."); $kernel = "Unknown"; @@ -278,7 +277,8 @@ return ($kernel, $distro, $version); } sub linuxDistro { - my $kernel = runSysCmd("uname -r"); + my @uname = uname(); + my $kernel = $uname[2]; my $distro = "Unknown Linux Distro"; my $version = "Unknown Linux Version"; my $found = 0; From 87aceef479a8656ff4d7a0b099a89cd5879b3776 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Mon, 15 Feb 2016 08:50:11 -0600 Subject: [PATCH 27/33] change server endpoint --- scripts/zmtelemetry.pl.in | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index 26b620d38..6697e4700 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -66,8 +66,7 @@ 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_NAME => "38092a65757da3cb5f949b6b94aa8fc9.us-east-1.aws.found.io"; -use constant ZM_TELEMETRY_SERVER_PORT => "9243"; +use constant ZM_TELEMETRY_SERVER_ENDPOINT => 'https://zmanon:2b2d0b4skps@telemetry.zoneminder.com/zmtelemetry/testing'; if ( $Config{ZM_TELEMETRY_DATA} ) { @@ -144,7 +143,7 @@ sub sendData { my $msg = shift; my $ua = LWP::UserAgent->new; - my $server_endpoint = "https://".ZM_TELEMETRY_SERVER_NAME.":".ZM_TELEMETRY_SERVER_PORT."/zmtelemetry/testing/"; + my $server_endpoint = ZM_TELEMETRY_SERVER_ENDPOINT; if ( $Config{ZM_UPDATE_CHECK_PROXY} ) { $ua->proxy( "https", $Config{ZM_UPDATE_CHECK_PROXY} ); From e3afa5d1ec08acdac0082401dc417f80623e99a9 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Mon, 15 Feb 2016 12:38:13 -0600 Subject: [PATCH 28/33] change to testing5 --- scripts/zmtelemetry.pl.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index 6697e4700..e4475339f 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -66,7 +66,7 @@ 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/testing'; +use constant ZM_TELEMETRY_SERVER_ENDPOINT => 'https://zmanon:2b2d0b4skps@telemetry.zoneminder.com/zmtelemetry/testing5'; if ( $Config{ZM_TELEMETRY_DATA} ) { From 041585b4a26f069d639417e9b360002bcff1b2c8 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Mon, 15 Feb 2016 14:03:16 -0600 Subject: [PATCH 29/33] Change Info to Debug --- scripts/zmtelemetry.pl.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index e4475339f..a2f191ceb 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -210,7 +210,7 @@ sub getIP { $ipaddr = $resp->decoded_content; } - Info("Found external ip address of: $ipaddr"); + Debug("Found external ip address of: $ipaddr"); return $ipaddr; } From 8a2dc2897d3d35b47cb2a853c158ff654c63a9bb Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Mon, 15 Feb 2016 14:11:58 -0600 Subject: [PATCH 30/33] Perl DateTime dependency not needed --- scripts/zmtelemetry.pl.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/zmtelemetry.pl.in b/scripts/zmtelemetry.pl.in index a2f191ceb..a5c2e00a3 100644 --- a/scripts/zmtelemetry.pl.in +++ b/scripts/zmtelemetry.pl.in @@ -55,7 +55,6 @@ use autouse 'Pod::Usage'=>qw(pod2usage); use LWP::UserAgent; use Sys::MemInfo qw(totalmem); use Sys::CPU qw(cpu_count); -use DateTime; use POSIX qw(strftime uname); $ENV{PATH} = '/bin:/usr/bin:/usr/local/bin'; @@ -84,7 +83,7 @@ if ( $Config{ZM_TELEMETRY_DATA} ) my %telemetry; $telemetry{uuid} = getUUID($dbh); $telemetry{ip} = getIP(); - $telemetry{timestamp} = DateTime->now( time_zone => "local" )->strftime("%Y-%m-%dT%H:%M:%S%z"); + $telemetry{timestamp} = strftime( "%Y-%m-%dT%H:%M:%S%z", localtime() ); $telemetry{monitor_count} = countQuery($dbh,"Monitors"); $telemetry{event_count} = countQuery($dbh,"Events"); $telemetry{architecture} = runSysCmd("uname -p"); From 84801fcb86d676ba39c91b2ab23a3bfb8d13cd85 Mon Sep 17 00:00:00 2001 From: arjunrc Date: Sat, 27 Feb 2016 13:06:33 -0500 Subject: [PATCH 31/33] typo in function name --- web/views/image.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/views/image.php b/web/views/image.php index de8205f76..cbaf2f731 100644 --- a/web/views/image.php +++ b/web/views/image.php @@ -132,7 +132,7 @@ else } if($width==$oldWidth && $height==$oldHeight) // See if we really need to scale { - imagejpg($i); + imagejpeg($i); imagedestroy($i); } else // we do need to scale From 1c9633f1bd68729d56415d213b3a07d8d8608b3e Mon Sep 17 00:00:00 2001 From: Andy Bauer Date: Tue, 1 Mar 2016 08:43:36 -0600 Subject: [PATCH 32/33] add comment/warning for ZM_SERVER_HOST --- zm.conf.in | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zm.conf.in b/zm.conf.in index 9cc3d42de..decca3b19 100644 --- a/zm.conf.in +++ b/zm.conf.in @@ -46,5 +46,9 @@ ZM_DB_USER=@ZM_DB_USER@ # ZoneMinder database password ZM_DB_PASS=@ZM_DB_PASS@ -# Host of this machine +# Do NOT set ZM_SERVER_HOST if you are not using Multi-Server +# You have been warned +# +# The name specified here must have a corresponding entry +# in the Servers tab under Options ZM_SERVER_HOST= From 466f2b2ae3d0f83401fbcc54f3d97d6e0941f874 Mon Sep 17 00:00:00 2001 From: Andy Bauer Date: Tue, 1 Mar 2016 11:12:54 -0600 Subject: [PATCH 33/33] change multi-server error message text --- web/includes/config.php.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/includes/config.php.in b/web/includes/config.php.in index 466e195f2..2ca819210 100644 --- a/web/includes/config.php.in +++ b/web/includes/config.php.in @@ -173,14 +173,14 @@ if ( ! defined('ZM_SERVER_ID') ) { if ( defined('ZM_SERVER_NAME') and ZM_SERVER_NAME ) { $server_id = dbFetchOne('SELECT Id FROM Servers WHERE Name=?', 'Id', array(ZM_SERVER_NAME)); if ( ! $server_id ) { - Error("ZM_SERVER_NAME set to " . ZM_SERVER_NAME . " in config, but not found in Servers table."); + Error("Invalid Multi-Server configration detected. ZM_SERVER_NAME set to " . ZM_SERVER_NAME . " in zm.conf, but no corresponding entry found in Servers table."); } else { define( 'ZM_SERVER_ID', $server_id ); } } else if ( defined('ZM_SERVER_HOST') and ZM_SERVER_HOST ) { $server_id = dbFetchOne('SELECT Id FROM Servers WHERE Name=?', 'Id', array(ZM_SERVER_HOST)); if ( ! $server_id ) { - Error("ZM_SERVER_HOST set to " . ZM_SERVER_HOST . " in config, but not found in Servers table."); + Error("Invalid Multi-Server configration detected. ZM_SERVER_HOST set to " . ZM_SERVER_HOST . " in zm.conf, but no corresponding entry found in Servers table."); } else { define( 'ZM_SERVER_ID', $server_id ); }