alanrenouf / vCheck-vSphere

vCheck Daily Report for vSphere
MIT License
735 stars 325 forks source link

Script for checking remote syslog files #542

Open Hammer7407 opened 7 years ago

Hammer7407 commented 7 years ago

I have run in to some issues with VMware where a host stops logging to the remote syslog server for some reason and this causes it to write errors to the vCenter C drive and database several time per second; Filling up C and bloating the database. As a result, I have written a small script the queries the syslog server to find the last modified file date and report on those that have not been written to in the last 12 hours. (Something we used to check manually every morning.) I'm fairly new to PowerShell so the script could probably use some refining, but I've taken a lot from this site and wanted to give something back.

Sorry if this is not the right place for new submissions. I looked all over and could not find a good place.

-Jason

 #Variables
  $SysLogPath = "\\<hostname>\d$\ProgramData\VMware\VMware Syslog Collector\Data\"

  #Get list of directories from syslog server
  $HostLogDirectories = Get-ChildItem $SysLogPath

  #Get only logfiles that have not been written to in the last 12 hours.
  $nonupdatinglogs = @(
      ForEach ($directory in $HostLogDirectories) {
          Get-ChildItem "\\denisp13\d$\ProgramData\VMware\VMware Syslog Collector\Data\$directory\syslog.log" |
          Where {$_.LastWriteTime -le (Get-Date).AddHours(-12)}
         })

  $output = $nonupdatinglogs | select Directory,LastWriteTime | Sort-Object -Property LastWriteTime -Descending

  $output

  $Title = "Stale Host Syslog File"
  $Header = "Hosts with stale syslog files: [count]]"
  $Comments = "Check host syslog settings. Failed sysloging can cause the vCenter server or vCenter database to fill up."
  $Display = "Table"
  $Author = "Jason McKee"
  $PluginVersion = 2.0
Sneddo commented 7 years ago

Needs a bit of work before merging...

Wondering if this is something that is valuable adding as well.

Hammer7407 commented 7 years ago

My goal is to get everything that we check daily in to vCheck. I modified the script just a bit to check that vSphere databases are backing up each night. Any directory not written to in 24 hours shows up in the report. Easy, but it saves me a few minutes every morning.

  #Variables
  $BackupPath = "\\<hostname>\G$\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup"

  #Get list of directories from backup target
  $BackupDirectories = Get-ChildItem $BackupPath |
  Where {$_.LastWriteTime -le (Get-Date).AddHours(-24)}

  $BackupDirectories