1
0
Fork 0
Dieser Commit ist enthalten in:
George Pochiscan 2015-02-06 14:35:06 +02:00
Commit 16d978c09b
4 geänderte Dateien mit 180 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,103 @@
# Purpose : This check verify if exists orphaned files on the datastores
# If there are orphaned files the output will be in the following format:
# [datastore_name] File_Path/file Size Last_Modified_Time
# Modify $usr,$pwd to match your vmware infrastructure;
# Modify $delay in order to run the script at specified interval. Default is one day
Set-PSDebug -Strict
#Main
#Configure user and password and delay(in seconds)
[string]$usr = "username"
[string]$pwd = "password"
$delay = 86400
#Initialize the VIToolkit:
add-pssnapin VMware.VimAutomation.Core
[Reflection.Assembly]::LoadWithPartialName("VMware.Vim")
# filename for timestamp
$remote_host = $env:REMOTE_HOST
$agent_dir = $env:MK_CONFDIR
$timestamp = $agent_dir + "\timestamp."+ $remote_host
#Initialize variables
[string]$strVC = "127.0.0.1"
[string]$logfile = "C:\Orphaned_VMDK.log"
[string]$logdata = ""
# execute agent only every $delay seconds
# does $timestamp exist?
If (Test-Path $timestamp){
# cat existing output
Get-Content C:\Orphaned_VMDK.log
$filedate = (ls $timestamp).LastWriteTime
$now = Get-Date
$earlier = $now.AddSeconds(-$delay)
# exit if timestamp too young
if ( $filedate -gt $earlier ) { exit }
}
# create new timestamp file
New-Item $timestamp -type file -force | Out-Null
# calculate unix timestamp
$epoch=[int][double]::Parse($(Get-Date -date (Get-Date).ToUniversalTime()-uformat %s))
[int]$countOrphaned = 0
[int64]$orphanSize = 0
# vmWare Datastore Browser query parameters
# See http://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.host.DatastoreBrowser.SearchSpec.html
$fileQueryFlags = New-Object VMware.Vim.FileQueryFlags
$fileQueryFlags.FileSize = $true
$fileQueryFlags.FileType = $true
$fileQueryFlags.Modification = $true
$searchSpec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
$searchSpec.details = $fileQueryFlags
#The .query property is used to scope the query to only active vmdk files (excluding snaps and change block tracking).
$searchSpec.Query = (New-Object VMware.Vim.VmDiskFileQuery)
#$searchSpec.matchPattern = "*.vmdk" # Alternative VMDK match method.
$searchSpec.sortFoldersFirst = $true
if ([System.IO.File]::Exists($logfile)) {
Remove-Item $logfile
}
#Time stamp the log file
"<<<vmware_orphaned_files>>>" | Tee-Object -Variable logdata
$logdata | Out-File -FilePath $logfile -Append
#Connect to vCenter Server
Connect-VIServer $strVC -Protocol https -User $usr -Password $pwd
#Collect array of all VMDK hard disk files in use:
[array]$UsedDisks = Get-View -ViewType VirtualMachine | % {$_.Layout} | % {$_.Disk} | % {$_.DiskFile}
#Collect array of all Datastores:
[array]$allDS = Get-Datastore | select -property name,Id | ? {$_.name -notmatch "LOG-"} | ? {$_.name -notmatch "_repository"} | Sort-Object -Property Name
[array]$orphans = @()
Foreach ($ds in $allDS) {
$dsView = Get-View $ds.Id
$dsBrowser = Get-View $dsView.browser
$rootPath = "["+$dsView.summary.Name+"]"
$searchResult = $dsBrowser.SearchDatastoreSubFolders($rootPath, $searchSpec)
foreach ($folder in $searchResult) {
foreach ($fileResult in $folder.File) {
if ($UsedDisks -notcontains ($folder.FolderPath + $fileResult.Path) -and ($fileResult.Path.length -gt 0)) {
$orphan = New-Object System.Object
($folder.FolderPath + $fileResult.Path) | Tee-Object -Variable orphan
$orphans += $orphan
([Math]::Round($fileResult.FileSize/1gb,2)) | Tee-Object -Variable orphan
$orphans += $orphan
([string]$fileResult.Modification.year + "-" + [string]$fileResult.Modification.month + "-" + [string]$fileResult.Modification.day) + (echo "`r`n") | Tee-Object -Variable orphan
$orphans += $orphan
Remove-Variable orphan
}
}
}
}
[array]$orphans | Tee-Object -Variable logdata
$logdata | Out-File -FilePath $logfile -Append
Disconnect-VIServer -Confirm:$False

Datei anzeigen

@ -0,0 +1,20 @@
title: Check for VMware Orphaned Files
agents: windows
catalog: os/windows
license: GPL
distribution:
description:
This check checks for VMware orpahned files. For more details
view the following VMware KB Article ID 1005049
You need to install the plugin {find_vmdk_orphaned_files.ps1}
into the {plugins} directory of your windows agent.
The check goes to warning if there any orphaned files.
The check will output a list of Datastore / Path / Size / LastModified files.
inventory:
One service will be created indiferrently of the existence
of an orphaned file or not.
perfdata:
None

41
checks/vmware_orphaned_files Normale Datei
Datei anzeigen

@ -0,0 +1,41 @@
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# Author: Marius Pana <mp@sphs.ro>
# EXAMPLE DATA FROM:
# format: [datastore] [path] [size] [last mod date]
#<<<vmware_orphaned_files>>>
# [EUFRLHODS01] EUFRLHOAPP30/EUFRLHOAPP30-000002.vmdk 0.02 2015-1-29
# [EUFRLHODS01] EUFRLHOAPP30/EUFRLHOAPP30_1-000002.vmdk 0.02 2015-1-29
# [EUFRLHODS01] EUFRLHOAPP30/EUFRLHOAPP30_2-000002.vmdk 0.02 2015-1-29
def inventory_vmware_orphaned_files(info):
if len(info) >= 1 and len(info[0]) >= 1:
return [ (None, None) ]
else:
return [ (None, None) ]
# return [('No VMware orphan files detected', None)]
def check_vmware_orphaned_files(item, params, info):
#if not item:
# return (0, "No VIMII orphan files found.")
if len(info) >= 1 and len(info[0]) >= 1:
total = len(info)
extended_info=""
for line in info:
if not line[0].startswith("["):
return (3, "There is a problem running the plugin. Please verify server")
else:
datastore = line[0]
path = line[1]
whichorphs = datastore + " " + path
extended_info += ' '.join(map(str,line)) + "<br>"
return (1, "WARN - VMware Orphan Files Detected: There are %d orphan files: %s" % (total, extended_info), [ ("vmware_orphaned_files", total) ])
else:
return (0, "OK - No VMware Orphan Files Detected")
check_info["vmware_orphaned_files"] = {
'check_function': check_vmware_orphaned_files,
'inventory_function': inventory_vmware_orphaned_files,
'service_description': 'VMware Orphaned Files',
'group': 'vmware_orphaned_files',
}

16
info Normale Datei
Datei anzeigen

@ -0,0 +1,16 @@
{'author': 'Marius Pana',
'description': 'Check_mk check for VMware orphaned files.',
'download_url': 'https://github.com/spearheadsys/check_mk-vmware_orphaned_files',
'files': {'agents': [''],
'checkman': ['vmware_orphaned_files'],
'checks': ['vmware_orphaned_files'],
'doc': [],
'inventory': [],
'notifications': [],
'pnp-templates': [],
'web': []},
'name': 'vmware_orphaned_files',
'title': 'vmware_orphaned_files',
'version': '1.0',
'version.min_required': '1.2.6b1',
'version.packaged': '1.2.6b1'}