add ES status to telemetry and --show option to display what is being sent to ZM

This commit is contained in:
Pliable Pixels 2020-03-16 14:49:27 -04:00
parent d54b2e5b21
commit 090cd845b0
1 changed files with 32 additions and 15 deletions

View File

@ -45,6 +45,7 @@ delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
my $help = 0; my $help = 0;
my $force = 0; my $force = 0;
my $show = 0;
# Interval between version checks # Interval between version checks
my $interval; my $interval;
my $version; my $version;
@ -52,6 +53,7 @@ my $version;
GetOptions( GetOptions(
force => \$force, force => \$force,
help => \$help, help => \$help,
show => \$show,
interval => \$interval, interval => \$interval,
version => \$version version => \$version
); );
@ -59,6 +61,14 @@ if ( $version ) {
print( ZoneMinder::Base::ZM_VERSION . "\n"); print( ZoneMinder::Base::ZM_VERSION . "\n");
exit(0); exit(0);
} }
if ($show) {
my %telemetry;
my $dbh = zmDbConnect();
collectData($dbh, \%telemetry);
my $result = jsonEncode(\%telemetry);
print ($result);
exit(0);
}
if ( $help ) { if ( $help ) {
pod2usage(-exitstatus => -1); pod2usage(-exitstatus => -1);
} }
@ -89,21 +99,9 @@ while( 1 ) {
my $dbh = zmDbConnect(); my $dbh = zmDbConnect();
# Build the telemetry hash # Build the telemetry hash
# We should keep *BSD systems in mind when calling system commands # We should keep *BSD systems in mind when calling system commands
my %telemetry; my %telemetry;
$telemetry{uuid} = getUUID($dbh); collectData($dbh,\%telemetry);
@telemetry{qw(city region country latitude longitude)} = getGeo();
$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');
($telemetry{kernel}, $telemetry{distro}, $telemetry{version}) = getDistro();
$telemetry{zm_version} = ZoneMinder::Base::ZM_VERSION;
$telemetry{system_memory} = totalmem();
$telemetry{processor_count} = cpu_count();
$telemetry{monitors} = getMonitorRef($dbh);
Info('Sending data to ZoneMinder Telemetry server.');
my $result = jsonEncode(\%telemetry); my $result = jsonEncode(\%telemetry);
if ( sendData($result) ) { if ( sendData($result) ) {
@ -126,6 +124,24 @@ print 'ZoneMinder Telemetry Agent exiting at '.strftime('%y/%m/%d %H:%M:%S', loc
# SUBROUTINES # # SUBROUTINES #
############### ###############
# collect data to send
sub collectData {
my $dbh = shift;
my $telemetry = shift;
$telemetry->{uuid} = getUUID($dbh);
($telemetry->{city},$telemetry->{region},$telemetry->{country},$telemetry->{latitude},$telemetry->{longitude})=getGeo();
$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');
($telemetry->{kernel}, $telemetry->{distro}, $telemetry->{version}) = getDistro();
$telemetry->{zm_version} = ZoneMinder::Base::ZM_VERSION;
$telemetry->{system_memory} = totalmem();
$telemetry->{processor_count} = cpu_count();
$telemetry->{use_event_server} = $Config{ZM_OPT_USE_EVENTNOTIFICATION};
$telemetry->{monitors} = getMonitorRef($dbh);
}
# Find, verify, then run the supplied system command # Find, verify, then run the supplied system command
sub runSysCmd { sub runSysCmd {
my $msg = shift; my $msg = shift;
@ -365,7 +381,7 @@ zmtelemetry.pl - Send usage information to the ZoneMinder development team
=head1 SYNOPSIS =head1 SYNOPSIS
zmtelemetry.pl [--force] [--help] [--interval=seconds] [--version] zmtelemetry.pl [--force] [--help] [--show] [--interval=seconds] [--version]
=head1 DESCRIPTION =head1 DESCRIPTION
@ -382,6 +398,7 @@ console under Options.
--force Force the script to upload it's data instead of waiting --force Force the script to upload it's data instead of waiting
for the defined interval since last upload. for the defined interval since last upload.
--help Display usage information --help Display usage information
--show Displays telemetry data that is sent to zoneminder
--interval Override the default configured interval since last upload. --interval Override the default configured interval since last upload.
The value should be given in seconds, but can be an expression The value should be given in seconds, but can be an expression
such as 24*60*60. such as 24*60*60.