VC Sanity Via PowerCli
Use below powercli code to perform VC sanity :-
=======================================================
Connect-VIServer -server <VC-NAME> -User "USER-NAME" -Password "PASSWORD"
$x = "ClusterA,ClusterB,ClusterC,Cluster1,Cluster2,Cluster3";
$xs = $x.split(",")
$ce = "Cluster1,Cluster2,Cluster3";
$ces = $ce.split(",")
$ias = "ClusterA,ClusterB,ClusterC";
$iaas = $ias.split(",")
$ds = foreach ($i in $xs){
get-cluster $i|Get-Datastore|where-object {$_ -notlike "*local*"}|where-object {$_ -notlike "*datastore*"}|select -ExpandProperty name}
$ntpserver = "ntp1,ntp2,ntp3,ntp4"
$ntpresult = foreach ($i in $xs){
get-cluster $i|Get-VMHost | Where-Object {$_.Connectionstate -eq "Connected"} | Select-Object Name,Parent,@{N="NTPServer";E={($_ |Get-VMHostNtpServer) -join ","}}, @{N="ServiceRunning";E={(Get-VmHostService -VMHost $_ | Where-Object {$_.key -eq "ntpd"}).Running}} | Where-Object {$_.ServiceRunning -eq $false -or $_.NTPServer -ne $ntpserver} }
$ntpresult | Export-Csv '/tmp/scripts/ntp.csv' -NoTypeInformation
$dsresult = foreach ($i in $ds) {
Get-Datastore $i|Select @{N="DataStoreName";E={$_.Name}},@{N="Free";E={[math]::Round(($_.FreeSpaceGB)/($_.CapacityGB)*100,2)}}|where {$_."Free" -le 15}}
$dsresult | Export-Csv '/tmp/scripts/ds.csv' -NoTypeInformation
$snp = foreach ($i in $xs){
get-cluster $i|get-vm|Get-Snapshot|Where {$_.Created -lt (Get-Date).AddDays(-2)} | Select-Object VM}
$snp | Export-Csv '/tmp/scripts/snp.csv' -NoTypeInformation
$sshresult = foreach ($i in $xs){
get-cluster $i|Get-VMHost | select name,Parent,@{Name="SSHRunning";E={($_|Get-VMHostService|where {$_.key -eq "tsm-ssh"}).Running}}|where-object {$_.SSHRunning -ne "True"}}
$sshresult | Export-Csv '/tmp/scripts/ssh.csv' -NoTypeInformation
$cebuild = foreach ($i in $ces){
get-cluster $i|Get-VMHost|where {$_.build -notlike '8294253'}|select name}
$cebuild | Export-Csv '/tmp/scripts/cebuild.csv' -NoTypeInformation
$iaasbuild = foreach ($i in $iaas){
get-cluster $i|Get-VMHost|where {$_.build -notlike '8285314'}|select name}
$iaasbuild | Export-Csv '/tmp/scripts/iaasbuild.csv' -NoTypeInformation
$licresult = foreach ($i in $xs) {
get-cluster $i| get-vmhost | where-object {($_.ConnectionState -match "Connected|Maintenance") -and ($_.LicenseKey -eq "00000-00000-00000-00000-00000")} | Select Name}
$licresult | Export-Csv '/tmp/scripts/lic.csv' -NoTypeInformation
$almresult = foreach ($i in $xs){
get-cluster $i|get-vmhost | Select-Object Name,Parent,PowerState,ConnectionState,@{n='AlarmActionsEnabled';e={$_.ExtensionData.AlarmActionsEnabled}} | Where-Object { ($_.ConnectionState -ne 'Connected') -or ($_.AlarmActionsEnabled -ne 'True') } }
$almresult | Export-Csv '/tmp/scripts/alarm.csv' -NoTypeInformation
$y = "ClusterA,ClusterB,ClusterC";
$ys = $y.split(",")
$ds= foreach ($i in $ys) {
get-cluster $i | Get-Datastore| ?{$_.name -like "*IMAGE*"}|Select-object -ExpandProperty name
}
$dsdresult = foreach ( $i in $ds ) {
Get-Datastore $i |get-vm|select name,@{N="Cluster";E={(get-cluster -vm $_)}},@{N="TotalHDD"; E={($_ | Get-HardDisk).count }}| where-object {$_.TotalHDD -gt 2}
}
$dsdresult | Export-Csv '/tmp/scripts/hdd.csv' -NoTypeInformation
$VMTs = foreach ($i in $xs){
get-cluster $i |get-vm |Where-Object {$_.PowerState -eq "PoweredOn"}| Where {(($_|get-view).Guest.ToolsStatus -match "toolsNotInstalled") -or (($_|get-view).Guest.ToolsStatus -match "toolsNotRunning")}| Select-Object Name}
$VMTs | Export-Csv '/tmp/scripts/vmts.csv' -NoTypeInformation
$VMTold = foreach ($i in $xs) {
get-cluster $i|get-vm|Where-Object {$_.PowerState -eq "PoweredOn"}|Where {(($_|get-view).Guest.toolsStatus -match "toolsOld")}|Select-Object Name}
$VMTold | Export-Csv '/tmp/scripts/vmtold.csv' -NoTypeInformation
$uptime = foreach ($i in $xs){
get-cluster $i |get-vmhost|select name,@{N="Uptime"; E={(Get-Date) - ($_).Extensiondata.Summary.Runtime.BootTime| Select-Object -ExpandProperty days}}|where-object {$_.Uptime -gt 100}}
$uptime | Export-Csv '/tmp/scripts/uptime.csv' -NoTypeInformation
disconnect-viserver VC-NAME -Confirm:$false
=======================================================
call above ps1 script with below docker :-
cd /clusowner/AJ/
/usr/bin/docker wait AJClusDocker
sh /clusowner/AJ/AJ_SQL
==========================================================
# cat AJ_SQL
psql -d clusowner_aj -U postgres -h localhost -c "drop table ntp";
psql -d clusowner_aj -U postgres -h localhost -c "drop table ds";
psql -d clusowner_aj -U postgres -h localhost -c "drop table snp";
psql -d clusowner_aj -U postgres -h localhost -c "drop table ssh";
psql -d clusowner_aj -U postgres -h localhost -c "drop table cebuild";
psql -d clusowner_aj -U postgres -h localhost -c "drop table iaasbuild";
psql -d clusowner_aj -U postgres -h localhost -c "drop table lic";
psql -d clusowner_aj -U postgres -h localhost -c "drop table alarm";
psql -d clusowner_aj -U postgres -h localhost -c "drop table hdd";
psql -d clusowner_aj -U postgres -h localhost -c "drop table vmt";
psql -d clusowner_aj -U postgres -h localhost -c "drop table vmtold";
psql -d clusowner_aj -U postgres -h localhost -c "drop table uptime";
psql -d clusowner_aj -U postgres -h localhost -c "create table ntp(Name varchar,Parent varchar,NTPServer varchar,ServiceRunning varchar);"
psql -d clusowner_aj -U postgres -h localhost -c "create table ds(DataStoreName varchar,Free varchar);"
psql -d clusowner_aj -U postgres -h localhost -c "create table snp(VM varchar);"
psql -d clusowner_aj -U postgres -h localhost -c "create table ssh(name varchar,Parent varchar,SSHRunning varchar);"
psql -d clusowner_aj -U postgres -h localhost -c "create table cebuild(name varchar);"
psql -d clusowner_aj -U postgres -h localhost -c "create table iaasbuild(name varchar);"
psql -d clusowner_aj -U postgres -h localhost -c "create table lic(Name varchar);"
psql -d clusowner_aj -U postgres -h localhost -c "create table alarm(Name varchar,Parent varchar,PowerState varchar,ConnectionState varchar,AlarmActionsEnabled varchar);"
psql -d clusowner_aj -U postgres -h localhost -c "create table hdd(name varchar,Cluster varchar,TotalHDD varchar);"
psql -d clusowner_aj -U postgres -h localhost -c "create table vmt(name varchar);"
psql -d clusowner_aj -U postgres -h localhost -c "create table vmtold(name varchar);"
psql -d clusowner_aj -U postgres -h localhost -c "create table uptime(name varchar,Uptime varchar);"
psql -d clusowner_aj -U postgres -h localhost -c "\copy ntp("Name","Parent","NTPServer","ServiceRunning") FROM /clusowner/AJ/ntp.csv DELIMITER ',' CSV HEADER;"
psql -d clusowner_aj -U postgres -h localhost -c "\copy ds("DataStoreName","Free") FROM /clusowner/AJ/ds.csv DELIMITER ',' CSV HEADER;"
psql -d clusowner_aj -U postgres -h localhost -c "\copy snp("VM") FROM /clusowner/AJ/snp.csv DELIMITER ',' CSV HEADER;"
psql -d clusowner_aj -U postgres -h localhost -c "\copy ssh("name","Parent","SSHRunning") FROM /clusowner/AJ/ssh.csv DELIMITER ',' CSV HEADER;"
psql -d clusowner_aj -U postgres -h localhost -c "\copy cebuild("name") FROM /clusowner/AJ/cebuild.csv DELIMITER ',' CSV HEADER;"
psql -d clusowner_aj -U postgres -h localhost -c "\copy iaasbuild("name") FROM /clusowner/AJ/iaasbuild.csv DELIMITER ',' CSV HEADER;"
psql -d clusowner_aj -U postgres -h localhost -c "\copy lic("Name") FROM /clusowner/AJ/lic.csv DELIMITER ',' CSV HEADER;"
psql -d clusowner_aj -U postgres -h localhost -c "\copy alarm("Name","Parent","PowerState","ConnectionState","AlarmActionsEnabled") FROM /clusowner/AJ/alarm.csv DELIMITER ',' CSV HEADER;"
psql -d clusowner_aj -U postgres -h localhost -c "\copy hdd("name","Cluster","TotalHDD") FROM /clusowner/AJ/hdd.csv DELIMITER ',' CSV HEADER;"
psql -d clusowner_aj -U postgres -h localhost -c "\copy vmt("name") FROM /clusowner/AJ/vmts.csv DELIMITER ',' CSV HEADER;"
psql -d clusowner_aj -U postgres -h localhost -c "\copy vmtold("name") FROM /clusowner/AJ/vmtold.csv DELIMITER ',' CSV HEADER;"
psql -d clusowner_aj -U postgres -h localhost -c "\copy uptime("name","uptime") FROM /clusowner/AJ/uptime.csv DELIMITER ',' CSV HEADER;"
Comments
Post a Comment