+ add filter for hyper-v modes

This commit is contained in:
garnier-quentin 2017-05-10 10:48:59 +02:00
parent 72cd1fd3eb
commit 01ff8c68ae
11 changed files with 102 additions and 57 deletions

View File

@ -160,6 +160,7 @@ sub new {
"no-ps" => { name => 'no_ps' },
"ps-exec-only" => { name => 'ps_exec_only' },
"filter-vm:s" => { name => 'filter_vm' },
"filter-note:s" => { name => 'filter_note' },
"filter-status:s" => { name => 'filter_status', default => 'running' },
"warning-global-status:s" => { name => 'warning_global_status', default => '%{integration_service_state} =~ /Update required/i' },
"critical-global-status:s" => { name => 'critical_global_status', default => '' },
@ -205,14 +206,14 @@ sub manage_selection {
$self->{output}->exit();
}
#[name= test1 ][state= Running ][IntegrationServicesState= Update required ][IntegrationServicesVersion= 3.1 ]
#[name= test1 ][state= Running ][IntegrationServicesState= Update required ][IntegrationServicesVersion= 3.1 ][note= ]
#[service= Time Synchronization ][enabled= True][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ]
#[service= Heartbeat ][enabled= True][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ]
#[service= Key-Value Pair Exchange ][enabled= True][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ]
#[service= Shutdown ][enabled= True][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ]
#[service= VSS ][enabled= True][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ]
#[service= Guest Service Interface ][enabled= False][primaryOperationalStatus= Ok ][secondaryOperationalStatus= ]
#[name= test2 ][state= Running ][IntegrationServicesState= ][IntegrationServicesVersion= ]
#[name= test2 ][state= Running ][IntegrationServicesState= ][IntegrationServicesVersion= ][note= ]
#[service= Time Synchronization ][enabled= True][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ]
#[service= Heartbeat ][enabled= True][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ]
#[service= Key-Value Pair Exchange ][enabled= True][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ]
@ -220,8 +221,8 @@ sub manage_selection {
$self->{vm} = {};
my $id = 1;
while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[state=\s*(.*?)\s*\]\[IntegrationServicesState=\s*(.*?)\s*\]\[IntegrationServicesVersion=\s*(.*?)\s*\](.*?)(?=\[name=|\z)/msig) {
my ($name, $status, $integration_service_state, $integration_service_version, $content) = ($1, $2, $3, $4, $5);
while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[state=\s*(.*?)\s*\]\[IntegrationServicesState=\s*(.*?)\s*\]\[IntegrationServicesVersion=\s*(.*?)\s*\]\[note=\s*(.*?)\s*\](.*?)(?=\[name=|\z)/msig) {
my ($name, $status, $integration_service_state, $integration_service_version, $note, $content) = ($1, $2, $3, $4, $5, $6);
if (defined($self->{option_results}->{filter_vm}) && $self->{option_results}->{filter_vm} ne '' &&
$name !~ /$self->{option_results}->{filter_vm}/i) {
@ -233,6 +234,11 @@ sub manage_selection {
$self->{output}->output_add(long_msg => "skipping '" . $status . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_note}) && $self->{option_results}->{filter_note} ne '' &&
$note !~ /$self->{option_results}->{filter_note}/i) {
$self->{output}->output_add(long_msg => "skipping '" . $note . "': no matching filter.", debug => 1);
next;
}
$self->{vm}->{$id} = { display => $name, vm => $name, service => {} };
$self->{vm}->{$id}->{global} = {
@ -283,14 +289,18 @@ Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
Print powershell output.
=item B<--filter-status>
Filter virtual machine status (can be a regexp) (Default: 'running').
=item B<--filter-vm>
Filter virtual machines (can be a regexp).
=item B<--filter-note>
Filter by VM notes (can be a regexp).
=item B<--filter-status>
Filter virtual machine status (can be a regexp) (Default: 'running').
=item B<--warning-global-status>
Set warning threshold for status (Default: '%{integration_service_state} =~ /Update required/i').

View File

@ -71,6 +71,7 @@ sub new {
"no-ps" => { name => 'no_ps' },
"ps-exec-only" => { name => 'ps_exec_only' },
"filter-vm:s" => { name => 'filter_vm' },
"filter-note:s" => { name => 'filter_note' },
"filter-status:s" => { name => 'filter_status', default => 'running' },
});
return $self;
@ -94,14 +95,14 @@ sub manage_selection {
$self->{output}->exit();
}
#[name= ISC1-SV04404 ][state= Running ]
#[name= ISC1-SV04404 ][state= Running ][note= ]
#[checkpointCreationTime= 1475502921.28734 ]
#[checkpointCreationTime= 1475503073.81975 ]
$self->{vm} = {};
my $id = 1;
while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[state=\s*(.*?)\s*\](.*?)(?=\[name=|\z)/msig) {
my ($name, $status, $content) = ($1, $2, $3);
while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[state=\s*(.*?)\s*\]\[note=\s*(.*?)\s*\](.*?)(?=\[name=|\z)/msig) {
my ($name, $status, $note, $content) = ($1, $2, $3, $4);
my $chkpt = -1;
while ($content =~ /\[checkpointCreationTime=s*(.*?)\s*\]/msig) {
$chkpt = $1 if ($chkpt == -1 || $chkpt > $1);
@ -112,6 +113,11 @@ sub manage_selection {
$name !~ /$self->{option_results}->{filter_vm}/i) {
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_note}) && $self->{option_results}->{filter_note} ne '' &&
$note !~ /$self->{option_results}->{filter_note}/i) {
$self->{output}->output_add(long_msg => "skipping '" . $note . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_status}) && $self->{option_results}->{filter_status} ne '' &&
$status !~ /$self->{option_results}->{filter_status}/i) {
@ -167,6 +173,10 @@ Filter virtual machine status (can be a regexp) (Default: 'running').
Filter virtual machines (can be a regexp).
=item B<--filter-note>
Filter by VM notes (can be a regexp).
=item B<--warning-*>
Threshold warning.

View File

@ -109,6 +109,7 @@ sub new {
"no-ps" => { name => 'no_ps' },
"ps-exec-only" => { name => 'ps_exec_only' },
"filter-vm:s" => { name => 'filter_vm' },
"filter-note:s" => { name => 'filter_note' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{status} !~ /Operating normally/i' },
});
@ -151,20 +152,25 @@ sub manage_selection {
$self->{output}->exit();
}
#[name= XXXX1 ][state= Running ][status= Operating normally ][IsClustered= True ]
#[name= XXXX2 ][state= Running ][status= Operating normally ][IsClustered= False ]
#[name= XXXX3 ][state= Running ][status= Operating normally ][IsClustered= False ]
#[name= XXXX1 ][state= Running ][status= Operating normally ][IsClustered= True ][note= ]
#[name= XXXX2 ][state= Running ][status= Operating normally ][IsClustered= False ][note= ]
#[name= XXXX3 ][state= Running ][status= Operating normally ][IsClustered= False ][note= ]
$self->{vm} = {};
my $id = 1;
while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[state=\s*(.*?)\s*\]\[status=\s*(.*?)\s*\]\[IsClustered=\s*(.*?)\s*\].*?(?=\[name=|\z)/msig) {
my ($name, $state, $status, $is_clustered) = ($1, $2, $3, $4);
while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[state=\s*(.*?)\s*\]\[status=\s*(.*?)\s*\]\[IsClustered=\s*(.*?)\s*\]\[note=\s*(.*?)\s*\].*?(?=\[name=|\z)/msig) {
my ($name, $state, $status, $is_clustered, $note) = ($1, $2, $3, $4, $5);
if (defined($self->{option_results}->{filter_vm}) && $self->{option_results}->{filter_vm} ne '' &&
$name !~ /$self->{option_results}->{filter_vm}/i) {
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_note}) && $self->{option_results}->{filter_note} ne '' &&
$note !~ /$self->{option_results}->{filter_note}/i) {
$self->{output}->output_add(long_msg => "skipping '" . $note . "': no matching filter.", debug => 1);
next;
}
$self->{vm}->{$id} = { display => $name, vm => $name, status => $status, state => $state, is_clustered => $is_clustered };
$id++;
@ -210,6 +216,10 @@ Print powershell output.
Filter virtual machines (can be a regexp).
=item B<--filter-note>
Filter by VM notes (can be a regexp).
=item B<--warning-status>
Set warning threshold for status (Default: '').

View File

@ -183,7 +183,7 @@ sub manage_selection {
$values{hostgroup} =~ s/\\/\//g;
my $filtered = 0;
foreach (('name', 'description', 'status', 'hostgroup')) {
foreach (('vm', 'description', 'status', 'hostgroup')) {
if (defined($self->{option_results}->{'filter_' . $_}) && $self->{option_results}->{'filter_' . $_} ne '' &&
$values{$_} !~ /$self->{option_results}->{'filter_' . $_}/i) {
$self->{output}->output_add(long_msg => "skipping '" . $values{$_} . "': no matching filter.", debug => 1);

View File

@ -75,6 +75,7 @@ sub new {
"no-ps" => { name => 'no_ps' },
"ps-exec-only" => { name => 'ps_exec_only' },
"filter-vm:s" => { name => 'filter_vm' },
"filter-description:s"=> { name => 'filter_description' },
"filter-hostgroup:s" => { name => 'filter_hostgroup' },
"filter-status:s" => { name => 'filter_status', default => 'running' },
});
@ -117,38 +118,34 @@ sub manage_selection {
$self->{output}->exit();
}
#[name= test-server ][status= Running ][cloud= ][hostgrouppath= All Hosts\CORP\Test\test-server ]
#[name= test-server ][description= ][status= Running ][cloud= ][hostgrouppath= All Hosts\CORP\Test\test-server ]
#[checkpointAddedTime= 1475502741.957 ]
#[checkpointAddedTime= 1475502963.21 ]
$self->{vm} = {};
my $id = 1;
while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[status=\s*(.*?)\s*\]\[cloud=\s*(.*?)\s*\]\[hostgrouppath=\s*(.*?)\s*\](.*?)(?=\[name=|\z)/msig) {
my ($name, $status, $cloud, $hg, $content) = ($1, $2, $3, $4, $5);
while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[description=\s*(.*?)\s*\]\[status=\s*(.*?)\s*\]\[cloud=\s*(.*?)\s*\]\[hostgrouppath=\s*(.*?)\s*\](.*?)(?=\[name=|\z)/msig) {
my %values = (vm => $1, description => $2, status => $3, cloud => $4, hostgroup => $5);
my $content = $6;
my $chkpt = -1;
while ($content =~ /\[checkpointAddedTime=s*(.*?)\s*\]/msig) {
$chkpt = $1 if ($chkpt == -1 || $chkpt > $1);
}
next if ($chkpt == -1);
$hg =~ s/\\/\//g;
if (defined($self->{option_results}->{filter_vm}) && $self->{option_results}->{filter_vm} ne '' &&
$name !~ /$self->{option_results}->{filter_vm}/i) {
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_hostgroup}) && $self->{option_results}->{filter_hostgroup} ne '' &&
$hg !~ /$self->{option_results}->{filter_hostgroup}/i) {
$self->{output}->output_add(long_msg => "skipping '" . $hg . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_status}) && $self->{option_results}->{filter_status} ne '' &&
$status !~ /$self->{option_results}->{filter_status}/i) {
$self->{output}->output_add(long_msg => "skipping '" . $status . "': no matching filter.", debug => 1);
next;
my $filtered = 0;
$values{hostgroup} =~ s/\\/\//g;
foreach (('vm', 'description', 'status', 'hostgroup')) {
if (defined($self->{option_results}->{'filter_' . $_}) && $self->{option_results}->{'filter_' . $_} ne '' &&
$values{$_} !~ /$self->{option_results}->{'filter_' . $_}/i) {
$self->{output}->output_add(long_msg => "skipping '" . $values{$_} . "': no matching filter.", debug => 1);
$filtered = 1;
last;
}
}
$self->{vm}->{$id} = { display => $name, snapshot => time() - $chkpt };
$self->{vm}->{$id} = { display => $values{vm}, snapshot => time() - $chkpt } if ($filtered == 0);
$id++;
}
}
@ -212,6 +209,10 @@ Filter virtual machine status (can be a regexp) (Default: 'running').
Filter virtual machines (can be a regexp).
=item B<--filter-description>
Filter by description (can be a regexp).
=item B<--filter-hostgroup>
Filter hostgroup (can be a regexp).

View File

@ -112,6 +112,7 @@ sub new {
"no-ps" => { name => 'no_ps' },
"ps-exec-only" => { name => 'ps_exec_only' },
"filter-vm:s" => { name => 'filter_vm' },
"filter-description:s"=> { name => 'filter_description' },
"filter-hostgroup:s" => { name => 'filter_hostgroup' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{status} !~ /Running|Stopped/i' },
@ -168,27 +169,26 @@ sub manage_selection {
$self->{output}->exit();
}
#[name= test-server ][status= Running ][cloud= ][hostgrouppath= All Hosts\CORP\Test\test-server ]
#[name= test-server2 ][status= Running ][cloud= ][hostgrouppath= All Hosts\CORP\Test\test-server2 ]
#[name= test-server ][description= ][status= Running ][cloud= ][hostgrouppath= All Hosts\CORP\Test\test-server ]
#[name= test-server2 ][description= ][status= Running ][cloud= ][hostgrouppath= All Hosts\CORP\Test\test-server2 ]
$self->{vm} = {};
my $id = 1;
while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[status=\s*(.*?)\s*\]\[cloud=\s*(.*?)\s*\]\[hostgrouppath=\s*(.*?)\s*\].*?(?=\[name=|\z)/msig) {
my ($name, $status, $cloud, $hg) = ($1, $2, $3, $4);
$hg =~ s/\\/\//g;
if (defined($self->{option_results}->{filter_vm}) && $self->{option_results}->{filter_vm} ne '' &&
$name !~ /$self->{option_results}->{filter_vm}/i) {
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_hostgroup}) && $self->{option_results}->{filter_hostgroup} ne '' &&
$hg !~ /$self->{option_results}->{filter_hostgroup}/i) {
$self->{output}->output_add(long_msg => "skipping '" . $hg . "': no matching filter.", debug => 1);
next;
while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[description=\s*(.*?)\s*\]\[status=\s*(.*?)\s*\]\[cloud=\s*(.*?)\s*\]\[hostgrouppath=\s*(.*?)\s*\].*?(?=\[name=|\z)/msig) {
my %values = (vm => $1, description => $2, status => $3, cloud => $4, hostgroup => $5);
my $filtered = 0;
$values{hostgroup} =~ s/\\/\//g;
foreach (('vm', 'description', 'hostgroup')) {
if (defined($self->{option_results}->{'filter_' . $_}) && $self->{option_results}->{'filter_' . $_} ne '' &&
$values{$_} !~ /$self->{option_results}->{'filter_' . $_}/i) {
$self->{output}->output_add(long_msg => "skipping '" . $values{$_} . "': no matching filter.", debug => 1);
$filtered = 1;
last;
}
}
$self->{vm}->{$id} = { display => $name, vm => $name, status => $status, hostgroup => $hg };
$self->{vm}->{$id} = { display => $values{vm}, vm => $values{vm}, status => $values{status}, hostgroup => $values{hostgroup} };
$id++;
}
}
@ -252,6 +252,10 @@ Filter virtual machines (can be a regexp).
Filter hostgroup (can be a regexp).
=item B<--filter-description>
Filter by description (can be a regexp).
=item B<--warning-status>
Set warning threshold for status (Default: '').

View File

@ -40,7 +40,9 @@ Try {
$vms = Get-VM
Foreach ($vm in $vms) {
Write-Host "[name=" $vm.VMName "][state=" $vm.State "][IntegrationServicesState=" $vm.IntegrationServicesState "][IntegrationServicesVersion=" $vm.IntegrationServicesVersion "]"
$note = $vm.Notes -replace "\r",""
$note = $note -replace "\n"," - "
Write-Host "[name=" $vm.VMName "][state=" $vm.State "][IntegrationServicesState=" $vm.IntegrationServicesState "][IntegrationServicesVersion=" $vm.IntegrationServicesVersion "][note=" $note "]"
Foreach ($service in $VM.VMIntegrationService) {
Write-Host "[service=" $service.Name "][enabled=" $service.Enabled "][primaryOperationalStatus=" $service.PrimaryOperationalStatus "][secondaryOperationalStatus=" $service.SecondaryOperationalStatus "]"
}

View File

@ -44,10 +44,12 @@ Try {
Foreach ($vm in $vms) {
$i=0
$note = $vm.Notes -replace "\r",""
$note = $note -replace "\n"," - "
Foreach ($snap in $snapshots) {
if ($snap.VMName -eq $vm.VMName) {
if ($i -eq 0) {
Write-Host "[name=" $vm.VMName "][state=" $vm.State "]"
Write-Host "[name=" $vm.VMName "][state=" $vm.State "][note=" $note "]"
}
Write-Host "[checkpointCreationTime=" (get-date -date $snap.CreationTime -UFormat ' . "'%s'" . ') "]"
$i=1

View File

@ -40,7 +40,9 @@ Try {
$vms = Get-VM
Foreach ($vm in $vms) {
Write-Host "[name=" $vm.VMName "][state=" $vm.State "][status=" $vm.Status "][IsClustered=" $vm.IsClustered "]"
$note = $vm.Notes -replace "\r",""
$note = $note -replace "\n"," - "
Write-Host "[name=" $vm.VMName "][state=" $vm.State "][status=" $vm.Status "][IsClustered=" $vm.IsClustered "][note=" $note "]"
}
} Catch {
Write-Host $Error[0].Exception

View File

@ -49,9 +49,11 @@ Try {
Foreach ($vm in $vms) {
$i = 0
$checkpoints = Get-SCVMCheckpoint -VMMServer $connection -Vm $vm
$desc = $vm.description -replace "\r",""
$desc = $desc -replace "\n"," - "
foreach ($checkpoint in $checkpoints) {
if ($i -eq 0) {
Write-Host "[name=" $vm.Name "][status=" $vm.Status "][cloud=" $vm.Cloud "][hostgrouppath=" $vm.HostGroupPath "]"
Write-Host "[name=" $vm.Name "][description=" $desc "][status=" $vm.Status "][cloud=" $vm.Cloud "][hostgrouppath=" $vm.HostGroupPath "]"
}
Write-Host "[checkpointAddedTime=" (get-date -date $checkpoint.AddedTime -UFormat ' . "'%s'" . ') "]"
$i = 1

View File

@ -47,7 +47,9 @@ Try {
$vms = Get-SCVirtualMachine -VMMServer $connection
Foreach ($vm in $vms) {
Write-Host "[name=" $vm.Name "][status=" $vm.Status "][cloud=" $vm.Cloud "][hostgrouppath=" $vm.HostGroupPath "]"
$desc = $vm.description -replace "\r",""
$desc = $desc -replace "\n"," - "
Write-Host "[name=" $vm.Name "][description=" $desc "][status=" $vm.Status "][cloud=" $vm.Cloud "][hostgrouppath=" $vm.HostGroupPath "]"
}
} Catch {
Write-Host $Error[0].Exception