From 00c4eedb90a73877b79542e37845b40c9bd0593b Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 21 Dec 2015 10:04:13 -0500 Subject: [PATCH 1/8] Add StorageId and StorageName to fields that we can filter on --- web/skins/classic/views/filter.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web/skins/classic/views/filter.php b/web/skins/classic/views/filter.php index 1c7c6e270..1f39b12cd 100644 --- a/web/skins/classic/views/filter.php +++ b/web/skins/classic/views/filter.php @@ -84,6 +84,8 @@ $attrTypes = array( 'DiskPercent' => translate('AttrDiskPercent'), 'DiskBlocks' => translate('AttrDiskBlocks'), 'SystemLoad' => translate('AttrSystemLoad'), + 'StorageId' => translate('AttrStorageId'), + 'StorageName' => translate('AttrStorageName'), ); $opTypes = array( '=' => translate('OpEq'), From 2548ec3bc03695b76a5e886f3c3b06f55cb5c1b1 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 21 Dec 2015 10:10:53 -0500 Subject: [PATCH 2/8] Add Attr lines for StrageId and StorageName --- web/lang/en_gb.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web/lang/en_gb.php b/web/lang/en_gb.php index 83267ecdd..822d7c835 100644 --- a/web/lang/en_gb.php +++ b/web/lang/en_gb.php @@ -124,6 +124,8 @@ $SLANG = array( 'AttrMaxScore' => 'Max. Score', 'AttrMonitorId' => 'Monitor Id', 'AttrMonitorName' => 'Monitor Name', + 'AttrStorageId' => 'Storage Id', + 'AttrStorageName' => 'Storage Name', 'AttrName' => 'Name', 'AttrNotes' => 'Notes', 'AttrSystemLoad' => 'System Load', From 5553760222981f19371b80b536aa3f665b15b471 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 21 Dec 2015 10:23:37 -0500 Subject: [PATCH 3/8] Add special cases for ServerId, ServerName, ServerHost to handle supplying the value of the host that the script is running on. --- scripts/ZoneMinder/lib/ZoneMinder/Filter.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm b/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm index b7806ec4a..a32b9b07e 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm @@ -221,6 +221,8 @@ sub Sql { if ( $filter_expr->{terms}[$i]->{attr} =~ /^Monitor/ ) { my ( $temp_attr_name ) = $filter_expr->{terms}[$i]->{attr} =~ /^Monitor(.+)$/; $self->{Sql} .= "M.".$temp_attr_name; + } elsif ( $filter_expr->{terms}[$i]->{attr} eq 'ServerHost' ) { + $self->{Sql} .= "M.ServerHost"; } elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DateTime' ) { $self->{Sql} .= "E.StartTime"; } elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Date' ) { @@ -246,6 +248,24 @@ sub Sql { foreach my $temp_value ( split( /["'\s]*?,["'\s]*?/, $stripped_value ) ) { if ( $filter_expr->{terms}[$i]->{attr} =~ /^Monitor/ ) { $value = "'$temp_value'"; + } elsif ( $filter_expr->{terms}[$i]->{attr} eq 'ServerHost' ) { + if ( $temp_value eq 'ZM_SERVER_HOST' ) { + $value = "'$Config{ZM_SERVER_HOST}'"; + } else { + $value = "'$temp_value'"; + } + } elsif ( $filter_expr->{terms}[$i]->{attr} eq 'ServerName' ) { + if ( $temp_value eq 'ZM_SERVER_NAME' ) { + $value = "'$Config{ZM_SERVER_NAME}'"; + } else { + $value = "'$temp_value'"; + } + } elsif ( $filter_expr->{terms}[$i]->{attr} eq 'ServerId' ) { + if ( $temp_value eq 'ZM_SERVER_ID' ) { + $value = "'$Config{ZM_SERVER_ID}'"; + } else { + $value = "'$temp_value'"; + } } elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Name' || $filter_expr->{terms}[$i]->{attr} eq 'Cause' || $filter_expr->{terms}[$i]->{attr} eq 'Notes' From 30353fbcf90f22aba870e8c5235677ca9431f0a5 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 21 Dec 2015 10:33:19 -0500 Subject: [PATCH 4/8] Add special case for Server Attr's because they are on the Monitor, not the event --- scripts/ZoneMinder/lib/ZoneMinder/Filter.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm b/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm index a32b9b07e..6c782197b 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm @@ -221,8 +221,8 @@ sub Sql { if ( $filter_expr->{terms}[$i]->{attr} =~ /^Monitor/ ) { my ( $temp_attr_name ) = $filter_expr->{terms}[$i]->{attr} =~ /^Monitor(.+)$/; $self->{Sql} .= "M.".$temp_attr_name; - } elsif ( $filter_expr->{terms}[$i]->{attr} eq 'ServerHost' ) { - $self->{Sql} .= "M.ServerHost"; + } elsif ( $filter_expr->{terms}[$i]->{attr} =~ /^Server/ ) { + $self->{Sql} .= "M.".$filter_expr->{terms}[$i]->{attr}; } elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DateTime' ) { $self->{Sql} .= "E.StartTime"; } elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Date' ) { From e7c337f9f34093a03e7496cf4b70d0896e3c9a04 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 21 Dec 2015 11:10:45 -0500 Subject: [PATCH 5/8] fix namespace for dbh --- scripts/ZoneMinder/lib/ZoneMinder/Storage.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Storage.pm b/scripts/ZoneMinder/lib/ZoneMinder/Storage.pm index d89599e61..f6244b714 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Storage.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Storage.pm @@ -80,10 +80,10 @@ sub load { my $type = ref $self; if ( ! $data ) { #$log->debug("Object::load Loading from db $type"); - $data = $ZoneMinder::dbh->selectrow_hashref( 'SELECT * FROM Storage WHERE Id=?', {}, $$self{Id} ); + $data = $ZoneMinder::Database::dbh->selectrow_hashref( 'SELECT * FROM Storage WHERE Id=?', {}, $$self{Id} ); if ( ! $data ) { - if ( $ZoneMinder::dbh->errstr ) { - Error( "Failure to load Storage record for $$self{id}: Reason: " . $ZoneMinder::dbh->errstr ); + if ( $ZoneMinder::Database::dbh->errstr ) { + Error( "Failure to load Storage record for $$self{id}: Reason: " . $ZoneMinder::Database::dbh->errstr ); } # end if } # end if } # end if ! $data From 9f02f4353c7e2031e2912a6462a38f645c73b400 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 21 Dec 2015 11:13:01 -0500 Subject: [PATCH 6/8] it is important to return the object from the constructor --- scripts/ZoneMinder/lib/ZoneMinder/Storage.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Storage.pm b/scripts/ZoneMinder/lib/ZoneMinder/Storage.pm index f6244b714..583ddd8eb 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Storage.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Storage.pm @@ -73,6 +73,7 @@ sub new { #$log->debug("loading $parent $id") if $debug or DEBUG_ALL; $self->load( $data ); } + return $self; } # end sub new sub load { From de8387267190f755f50e72643b1d426fa8ddca5d Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 21 Dec 2015 11:25:38 -0500 Subject: [PATCH 7/8] id => Id --- scripts/ZoneMinder/lib/ZoneMinder/Storage.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Storage.pm b/scripts/ZoneMinder/lib/ZoneMinder/Storage.pm index 583ddd8eb..7b8ebb563 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Storage.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Storage.pm @@ -69,7 +69,7 @@ sub new { my $self = {}; bless $self, $parent; - if ( ( $$self{id} = $id ) or $data ) { + if ( ( $$self{Id} = $id ) or $data ) { #$log->debug("loading $parent $id") if $debug or DEBUG_ALL; $self->load( $data ); } From 3d00c3a50def43c33d65ab08cacac3110dfaa56d Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 21 Dec 2015 11:34:12 -0500 Subject: [PATCH 8/8] Make getDiskPercent take an optional path. When a Server is specified, add it to the Filter object so that we can use in getDiskPercent --- scripts/ZoneMinder/lib/ZoneMinder/Filter.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm b/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm index 6c782197b..e6c5b7fc2 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm @@ -62,6 +62,8 @@ our $VERSION = $ZoneMinder::Base::VERSION; use ZoneMinder::Config qw(:all); use ZoneMinder::Logger qw(:all); use ZoneMinder::Database qw(:all); +require ZoneMinder::Storage; +require ZoneMinder::Server; use POSIX; @@ -145,7 +147,7 @@ sub Execute { if ( $self->{HasDiskPercent} ) { - my $disk_percent = getDiskPercent(); + my $disk_percent = getDiskPercent( $$self{Storage} ? $$self{Storage}->Path() : () ) $sql =~ s/zmDiskPercent/$disk_percent/g; } if ( $self->{HasDiskBlocks} ) @@ -263,9 +265,14 @@ sub Sql { } elsif ( $filter_expr->{terms}[$i]->{attr} eq 'ServerId' ) { if ( $temp_value eq 'ZM_SERVER_ID' ) { $value = "'$Config{ZM_SERVER_ID}'"; + my $Server = $$self{Server} = new ZoneMinder::Server( $Config{ZM_SERVER_ID} ); } else { $value = "'$temp_value'"; + my $Server = $$self{Server} = new ZoneMinder::Server( $temp_value ); } + } elsif ( $filter_expr->{terms}[$i]->{attr} eq 'StorageId' ) { + $value = "'$temp_value'"; + my $Storage = $$self{Storage} = new ZoneMinder::Storage( $temp_value ); } elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Name' || $filter_expr->{terms}[$i]->{attr} eq 'Cause' || $filter_expr->{terms}[$i]->{attr} eq 'Notes' @@ -427,12 +434,13 @@ sub Sql { sub getDiskPercent { - my $command = "df ."; + my $command = "df " . ($_[0] ? $_[0] : '.'); my $df = qx( $command ); my $space = -1; if ( $df =~ /\s(\d+)%/ms ) { $space = $1; + Debug( "getDiskPercent $command returned $space" ); } return( $space ); }