mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-23 13:45:18 +02:00
fix powershell json
This commit is contained in:
parent
c651172550
commit
de8faa0fa4
@ -226,7 +226,9 @@ sub manage_selection {
|
|||||||
};
|
};
|
||||||
|
|
||||||
my $id2 = 1;
|
my $id2 = 1;
|
||||||
foreach my $service (@{$node->{services}}) {
|
my $services = (ref($node->{services}) eq 'ARRAY') ? $node->{services} : [ $node->{services} ];
|
||||||
|
|
||||||
|
foreach my $service (@$services) {
|
||||||
$self->{vm}->{$id}->{service}->{$id2} = {
|
$self->{vm}->{$id}->{service}->{$id2} = {
|
||||||
vm => $node->{name},
|
vm => $node->{name},
|
||||||
service => $service->{service},
|
service => $service->{service},
|
||||||
|
@ -139,8 +139,8 @@ sub manage_selection {
|
|||||||
my $id = 1;
|
my $id = 1;
|
||||||
foreach my $node (@$decoded) {
|
foreach my $node (@$decoded) {
|
||||||
if (defined($self->{option_results}->{filter_vm}) && $self->{option_results}->{filter_vm} ne '' &&
|
if (defined($self->{option_results}->{filter_vm}) && $self->{option_results}->{filter_vm} ne '' &&
|
||||||
$name !~ /$self->{option_results}->{filter_vm}/i) {
|
$node->{name} !~ /$self->{option_results}->{filter_vm}/i) {
|
||||||
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
|
$self->{output}->output_add(long_msg => "skipping '" . $node->{name} . "': no matching filter.", debug => 1);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,8 @@ sub manage_selection {
|
|||||||
my ($name, $status, $note, $content) = ($1, $2, $3, $4);
|
my ($name, $status, $note, $content) = ($1, $2, $3, $4);
|
||||||
|
|
||||||
my $checkpoint = { backing => -1, snapshot => -1 };
|
my $checkpoint = { backing => -1, snapshot => -1 };
|
||||||
foreach my $chkpt (@{$node->{checkpoints}}) {
|
my $checkpoints = (ref($node->{checkpoints}) eq 'ARRAY') ? $node->{checkpoints} : [ $node->{checkpoints} ];
|
||||||
|
foreach my $chkpt (@$checkpoints) {
|
||||||
$chkpt->{creation_time} =~ s/,/\./g;
|
$chkpt->{creation_time} =~ s/,/\./g;
|
||||||
$checkpoint->{ $chkpt->{type} } = $chkpt->{creation_time} if ($chkpt->{creation_time} > 0 && ($checkpoint->{ $chkpt->{type} } == -1 || $checkpoint->{ $chkpt->{type} } > $chkpt->{creation_time}));
|
$checkpoint->{ $chkpt->{type} } = $chkpt->{creation_time} if ($chkpt->{creation_time} > 0 && ($checkpoint->{ $chkpt->{type} } == -1 || $checkpoint->{ $chkpt->{type} } > $chkpt->{creation_time}));
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,8 @@ sub manage_selection {
|
|||||||
$node->{status} = $scvmm_vm_status->{ $node->{status} };
|
$node->{status} = $scvmm_vm_status->{ $node->{status} };
|
||||||
|
|
||||||
my $chkpt = -1;
|
my $chkpt = -1;
|
||||||
foreach (@{$node->{checkpoints}}) {
|
my $checkpoints = (ref($node->{checkpoints}) eq 'ARRAY') ? $node->{checkpoints} : [ $node->{checkpoints} ];
|
||||||
|
foreach (@$checkpoints) {
|
||||||
$chkpt = $_->{added_time} if ($chkpt == -1 || $chkpt > $_->{added_time});
|
$chkpt = $_->{added_time} if ($chkpt == -1 || $chkpt > $_->{added_time});
|
||||||
}
|
}
|
||||||
next if ($chkpt == -1);
|
next if ($chkpt == -1);
|
||||||
|
@ -41,7 +41,7 @@ sub convert_to_json {
|
|||||||
my (%options) = @_;
|
my (%options) = @_;
|
||||||
|
|
||||||
my $ps = q{
|
my $ps = q{
|
||||||
function ConvertTo-JSON-20($maxDepth = 4) {
|
function ConvertTo-JSON-20($maxDepth = 4,$forceArray = $false) {
|
||||||
begin {
|
begin {
|
||||||
$data = @()
|
$data = @()
|
||||||
}
|
}
|
||||||
@ -50,7 +50,11 @@ function ConvertTo-JSON-20($maxDepth = 4) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
end{
|
end{
|
||||||
$value = $data
|
if ($data.length -eq 1 -and $forceArray -eq $false) {
|
||||||
|
$value = $data[0]
|
||||||
|
} else {
|
||||||
|
$value = $data
|
||||||
|
}
|
||||||
|
|
||||||
if ($value -eq $null) {
|
if ($value -eq $null) {
|
||||||
return "null"
|
return "null"
|
||||||
|
@ -57,7 +57,7 @@ Try {
|
|||||||
$items.Add($item)
|
$items.Add($item)
|
||||||
}
|
}
|
||||||
|
|
||||||
$jsonString = $items | ConvertTo-JSON-20
|
$jsonString = $items | ConvertTo-JSON-20 -forceArray $true
|
||||||
Write-Host $jsonString
|
Write-Host $jsonString
|
||||||
} Catch {
|
} Catch {
|
||||||
Write-Host $Error[0].Exception
|
Write-Host $Error[0].Exception
|
||||||
|
@ -71,7 +71,7 @@ Try {
|
|||||||
$items.Add($item)
|
$items.Add($item)
|
||||||
}
|
}
|
||||||
|
|
||||||
$jsonString = $items | ConvertTo-JSON-20
|
$jsonString = $items | ConvertTo-JSON-20 -forceArray $true
|
||||||
Write-Host $jsonString
|
Write-Host $jsonString
|
||||||
} Catch {
|
} Catch {
|
||||||
Write-Host $Error[0].Exception
|
Write-Host $Error[0].Exception
|
||||||
|
@ -52,7 +52,7 @@ Try {
|
|||||||
$items.Add($item)
|
$items.Add($item)
|
||||||
}
|
}
|
||||||
|
|
||||||
$jsonString = $items | ConvertTo-JSON-20
|
$jsonString = $items | ConvertTo-JSON-20 -forceArray $true
|
||||||
Write-Host $jsonString
|
Write-Host $jsonString
|
||||||
} Catch {
|
} Catch {
|
||||||
Write-Host $Error[0].Exception
|
Write-Host $Error[0].Exception
|
||||||
|
@ -82,7 +82,7 @@ Try {
|
|||||||
$items.Add($item)
|
$items.Add($item)
|
||||||
}
|
}
|
||||||
|
|
||||||
$jsonString = $items | ConvertTo-JSON-20
|
$jsonString = $items | ConvertTo-JSON-20 -forceArray $true
|
||||||
Write-Host $jsonString
|
Write-Host $jsonString
|
||||||
} Catch {
|
} Catch {
|
||||||
Write-Host $Error[0].Exception
|
Write-Host $Error[0].Exception
|
||||||
|
@ -69,7 +69,7 @@ Try {
|
|||||||
$items.Add($item)
|
$items.Add($item)
|
||||||
}
|
}
|
||||||
|
|
||||||
$jsonString = $items | ConvertTo-JSON-20
|
$jsonString = $items | ConvertTo-JSON-20 -forceArray $true
|
||||||
Write-Host $jsonString
|
Write-Host $jsonString
|
||||||
} Catch {
|
} Catch {
|
||||||
Write-Host $Error[0].Exception
|
Write-Host $Error[0].Exception
|
||||||
|
@ -70,7 +70,7 @@ Try {
|
|||||||
$items.Add($item)
|
$items.Add($item)
|
||||||
}
|
}
|
||||||
|
|
||||||
$jsonString = $items | ConvertTo-JSON-20
|
$jsonString = $items | ConvertTo-JSON-20 -forceArray $true
|
||||||
Write-Host $jsonString
|
Write-Host $jsonString
|
||||||
} Catch {
|
} Catch {
|
||||||
Write-Host $Error[0].Exception
|
Write-Host $Error[0].Exception
|
||||||
|
@ -73,7 +73,7 @@ Try {
|
|||||||
$items.Add($item)
|
$items.Add($item)
|
||||||
}
|
}
|
||||||
|
|
||||||
$jsonString = $items | ConvertTo-JSON-20
|
$jsonString = $items | ConvertTo-JSON-20 -forceArray $true
|
||||||
Write-Host $jsonString
|
Write-Host $jsonString
|
||||||
} Catch {
|
} Catch {
|
||||||
Write-Host $Error[0].Exception
|
Write-Host $Error[0].Exception
|
||||||
|
@ -63,7 +63,7 @@ Try {
|
|||||||
$items.Add($item)
|
$items.Add($item)
|
||||||
}
|
}
|
||||||
|
|
||||||
$jsonString = $items | ConvertTo-JSON-20
|
$jsonString = $items | ConvertTo-JSON-20 -forceArray $true
|
||||||
Write-Host $jsonString
|
Write-Host $jsonString
|
||||||
} Catch {
|
} Catch {
|
||||||
Write-Host $Error[0].Exception
|
Write-Host $Error[0].Exception
|
||||||
|
@ -77,7 +77,7 @@ Try {
|
|||||||
$items.Add($item)
|
$items.Add($item)
|
||||||
}
|
}
|
||||||
|
|
||||||
$jsonString = $items | ConvertTo-JSON-20
|
$jsonString = $items | ConvertTo-JSON-20 -forceArray $true
|
||||||
Write-Host $jsonString
|
Write-Host $jsonString
|
||||||
} Catch {
|
} Catch {
|
||||||
Write-Host $Error[0].Exception
|
Write-Host $Error[0].Exception
|
||||||
|
@ -67,7 +67,7 @@ Try {
|
|||||||
$items.Add($item)
|
$items.Add($item)
|
||||||
}
|
}
|
||||||
|
|
||||||
$jsonString = $items | ConvertTo-JSON-20
|
$jsonString = $items | ConvertTo-JSON-20 -forceArray $true
|
||||||
Write-Host $jsonString
|
Write-Host $jsonString
|
||||||
} Catch {
|
} Catch {
|
||||||
Write-Host $Error[0].Exception
|
Write-Host $Error[0].Exception
|
||||||
|
@ -70,7 +70,7 @@ Try {
|
|||||||
$items.Add($item)
|
$items.Add($item)
|
||||||
}
|
}
|
||||||
|
|
||||||
$jsonString = $items | ConvertTo-JSON-20
|
$jsonString = $items | ConvertTo-JSON-20 -forceArray $true
|
||||||
Write-Host $jsonString
|
Write-Host $jsonString
|
||||||
} Catch {
|
} Catch {
|
||||||
Write-Host $Error[0].Exception
|
Write-Host $Error[0].Exception
|
||||||
|
@ -63,7 +63,7 @@ Try {
|
|||||||
$items.Add($item)
|
$items.Add($item)
|
||||||
}
|
}
|
||||||
|
|
||||||
$jsonString = $items | ConvertTo-JSON-20
|
$jsonString = $items | ConvertTo-JSON-20 -forceArray $true
|
||||||
Write-Host $jsonString
|
Write-Host $jsonString
|
||||||
} Catch {
|
} Catch {
|
||||||
Write-Host $Error[0].Exception
|
Write-Host $Error[0].Exception
|
||||||
|
Loading…
x
Reference in New Issue
Block a user