Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2314

Skriptanpassung

$
0
0
Hallo,
ich habe folgendes Skript gefunden um VMWare Storage zu prüfen....funktioniert auch.
Ich würde nur gerne mehrere Datastores in dem einen Skript abfragen, bekomme es aber nicht hin.
Kann da evtl. jemand helfen?

Vielen Dank und Gruß
Dennis

# Check available size on datastores on VMWare ESX
#
# Revision History
# 2014-03-10    Willion van Es - Netdata [w.vanes@netdata.nl]    1.0 code initial created
# 2014-03-10    Robin Smit - Netdata [ r.smit@netdata.nl / info@robinsmit.nl ]
# To execute from within NSClient++
#
#[NRPE Handlers]
#check_vmfs_datastore=cmd /c echo C:\Scripts\Nagios_check_vmfs_datastore.ps1 | PowerShell.exe -Command -
#
# On the check_nrpe command include the -t 20, since it takes some time to load
# the vSphere cmdlet's.

if ( (Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction:SilentlyContinue) -eq $null)
{
    add-pssnapin VMware.VimAutomation.Core
}
$connect = connect-viserver IP -user administrator@vsphere.local -password 'xxxx'  -WarningAction SilentlyContinue
$NagiosStatus = "0"
$NagiosDescription = ""
$datastorecheck = "vmware_data_01 (VMs)"


$datastores = get-datastore $datastorecheck | select-object Name,FreespaceGB | Sort Name

 ForEach ($datastore in $datastores)
{
    $datastorename = $datastore | select-object -ExpandProperty Name
    $datastoresize = $datastore | Select-Object  -ExpandProperty FreespaceGB
    $comment = "GB available"
    
    if ($NagiosDescription -ne "")
        {
            # Format the output for Nagios
            $NagiosDescription = ""
        }
    if ($datastoresize -lt 300)
        {
            if ($datastoresize -lt 200)
                {
                    #minder als 200GB vrij
                    $NagiosDescription = $NagiosDescription + $datastorename + " = " + $datastoresize + $comment
                    # Set the status to Critical.
                    $NagiosStatus = "2"
                    #echo     $datastorename $datastoresize " lt 200"
                }
            else
                {
    
                    $NagiosDescription = $NagiosDescription + $datastorename + " = " + $datastoresize + $comment
                           # Set the status to Warning.
                    $NagiosStatus = "1"
                    #echo     $datastorename $datastoresize " lt 300"
                }
        }
    if ($datastoresize -gt 300)
        {
                #meer als 300GB vrij
                $NagiosDescription = $NagiosDescription + $datastorename + " = " + $datastoresize + $comment
                # Set the status to failed.
                $NagiosStatus = "0"
                #echo     $datastorename $datastoresize " bg 300"
        }    

if ($NagiosStatus -eq "2")
{
    Write-Host "CRITICAL:" $NagiosDescription
    #$NagiosStatus = "0"
    #$NagiosDescription = ""

}     
if ($NagiosStatus -eq "1")
{
    Write-Host "Warning:" $NagiosDescription
    #$NagiosStatus = "0"
    #$NagiosDescription = ""

}
if ($NagiosStatus -eq "0")
{    
Write-Host "OK:" Datastore $datastorename has enough space available

}
        

exit $NagiosStatus        



        
        
        
} #end foreach


Viewing all articles
Browse latest Browse all 2314


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>