Make getDiskPercent take an optional path. When a Server is specified, add it to the Filter object so that we can use in getDiskPercent

This commit is contained in:
Isaac Connor 2015-12-21 11:34:12 -05:00
parent 710197a4f2
commit 3d00c3a50d
1 changed files with 10 additions and 2 deletions

View File

@ -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 );
}