From ee3f87a2ad67b045c622c9f8b2aba08a73e9aaca Mon Sep 17 00:00:00 2001 From: Andy Bauer Date: Sat, 13 Feb 2016 14:53:22 -0600 Subject: [PATCH] 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; }