List storages (#946)
* better response time & add posibility to know drive type
This commit is contained in:
parent
321bed23b5
commit
822427c4a2
|
@ -37,24 +37,14 @@ $ProgressPreference = "SilentlyContinue"
|
||||||
|
|
||||||
Try {
|
Try {
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
';
|
|
||||||
|
$disks = Get-CimInstance Win32_LogicalDisk
|
||||||
|
|
||||||
if (defined($options{filter})) {
|
|
||||||
$ps .= '
|
|
||||||
$disks = Get-PSDrive -PSProvider "' . $options{filter} . '"
|
|
||||||
';
|
|
||||||
} else {
|
|
||||||
$ps .= '
|
|
||||||
$disks = Get-PSDrive
|
|
||||||
';
|
|
||||||
}
|
|
||||||
|
|
||||||
$ps .= '
|
|
||||||
} Catch {
|
} Catch {
|
||||||
Write-Host $Error[0].Exception
|
Write-Host $Error[0].Exception
|
||||||
exit 1
|
exit 1
|
||||||
}Foreach ($disk in $disks) {
|
}Foreach ($disk in $disks) {
|
||||||
Write-Host "[name=" $disk.Name "][used=" $disk.Used "][free=" $disk.Free "][provider=" $disk.Provider "][path=" $disk.Root "]"
|
Write-Host "[name=" $disk.DeviceID "][type=" $disk.DriveType "][providername=" $disk.ProviderName "][desc=" $disk.VolumeName "][size=" $disk.Size "][freespace=" $disk.FreeSpace "]"
|
||||||
}
|
}
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -66,16 +56,16 @@ exit 0
|
||||||
|
|
||||||
sub list {
|
sub list {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
my %map_type = (2 => 'removable', 3 => 'local', 4 => 'network', 5 => 'floppy');
|
||||||
# Following output:
|
# Following output:
|
||||||
#[name= c ][server= SRVI-WIN-TEST ][used= 20394858038 ][free= 509408308 ][provider= Microsoft.PowerShell.Core\FileSystem ][path= C:\ ]
|
#[name= C: ][type= 3 ][providername= ][desc= OS ][size= 254406553600 ][freespace= 23851290624 ]
|
||||||
#...
|
#...
|
||||||
foreach my $line (split /\n/, $options{stdout}) {
|
foreach my $line (split /\n/, $options{stdout}) {
|
||||||
next if ($line !~ /^\[name=(.*?)\]\[used=(.*?)\]\[free=(.*?)\]\[provider=(.*?)\]\[path=(.*?)\]/);
|
next if ($line !~ /^\[name=(.*?)\]\[type=(.*?)\]\[providername=.*?\]\[desc=(.*?)\]\[size=(.*?)\]\[freespace=(.*?)\]/);
|
||||||
my ($disk, $used, $free, $provider, $path) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2),
|
my ($disk, $type, $desc, $size, $free) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2),
|
||||||
centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5));
|
centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5));
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => "'" . $disk . "' [used = $used, free = $free, path = $path, provider = " . $provider . ']');
|
$self->{output}->output_add(long_msg => "'" . $disk . "' [size = $size, free = $free, desc = $desc, type = $map_type{$type}]");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,20 +74,21 @@ sub list {
|
||||||
|
|
||||||
sub disco_show {
|
sub disco_show {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
my %map_type = (2 => 'removable', 3 => 'local', 4 => 'network', 5 => 'floppy');
|
||||||
|
|
||||||
# Following output:
|
# Following output:
|
||||||
#[name= c ][server= SRVI-WIN-TEST ][used= 20394858038 ][free= 509408308 ][provider= Microsoft.PowerShell.Core\FileSystem ][path= C:\ ]
|
#[name= C: ][type= 3 ][providername= ][desc= OS ][size= 254406553600 ][freespace= 23851290624 ]
|
||||||
#...
|
#...
|
||||||
foreach my $line (split /\n/, $options{stdout}) {
|
foreach my $line (split /\n/, $options{stdout}) {
|
||||||
next if ($line !~ /^\[name=(.*?)\]\[used=(.*?)\]\[free=(.*?)\]\[provider=(.*?)\]\[path=(.*?)\]/);
|
next if ($line !~ /^\[name=(.*?)\]\[type=(.*?)\]\[providername=.*?\]\[desc=(.*?)\]\[size=(.*?)\]\[freespace=(.*?)\]/);
|
||||||
my ($disk, $used, $free, $provider, $path) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2),
|
my ($disk, $type, $desc, $size, $free) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2),
|
||||||
centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5));
|
centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5));
|
||||||
|
|
||||||
$self->{output}->add_disco_entry(name => $disk,
|
$self->{output}->add_disco_entry(name => $disk,
|
||||||
used => $used,
|
size => $size,
|
||||||
free => $free,
|
free => $free,
|
||||||
provider => $provider,
|
type => $map_type{$type},
|
||||||
path => $path);
|
desc => $desc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,7 @@ sub new {
|
||||||
"command:s" => { name => 'command', default => 'powershell.exe' },
|
"command:s" => { name => 'command', default => 'powershell.exe' },
|
||||||
"command-path:s" => { name => 'command_path' },
|
"command-path:s" => { name => 'command_path' },
|
||||||
"command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
|
"command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
|
||||||
"ps-exec-only" => { name => 'ps_exec_only', },
|
"ps-exec-only" => { name => 'ps_exec_only', }
|
||||||
"filter-type:s" => { name => 'filter', default => 'FileSystem'},
|
|
||||||
});
|
});
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
@ -55,9 +54,8 @@ sub check_options {
|
||||||
sub run {
|
sub run {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $ps = centreon::common::powershell::windows::liststorages::get_powershell(no_ps => $self->{option_results}->{no_ps},
|
my $ps = centreon::common::powershell::windows::liststorages::get_powershell(no_ps => $self->{option_results}->{no_ps});
|
||||||
filter => $self->{option_results}->{filter});
|
|
||||||
|
|
||||||
$self->{option_results}->{command_options} .= " " . $ps;
|
$self->{option_results}->{command_options} .= " " . $ps;
|
||||||
|
|
||||||
my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output},
|
my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output},
|
||||||
|
@ -81,14 +79,13 @@ sub run {
|
||||||
sub disco_format {
|
sub disco_format {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{output}->add_disco_format(elements => ['name', 'used', 'free', 'provider', 'path']);
|
$self->{output}->add_disco_format(elements => ['name', 'size', 'free', 'type', 'desc']);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub disco_show {
|
sub disco_show {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $ps = centreon::common::powershell::windows::liststorages::get_powershell(no_ps => $self->{option_results}->{no_ps},
|
my $ps = centreon::common::powershell::windows::liststorages::get_powershell(no_ps => $self->{option_results}->{no_ps});
|
||||||
filter => $self->{option_results}->{filter});
|
|
||||||
|
|
||||||
$self->{option_results}->{command_options} .= " " . $ps;
|
$self->{option_results}->{command_options} .= " " . $ps;
|
||||||
my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output},
|
my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output},
|
||||||
|
|
Loading…
Reference in New Issue