800xl Blog

The Data Complex

rainbow

VMware vSphere 5 – vCenter installation – Update manager issue’s

VMware released vSphere 5, so time for me to start playing!

So downloaded all the iso’s from VMware and started to mess around with it. First I was pretty interested in the new vCenter appliance. No more windows host needed to run vCenter. But while reading the docs I soon found out that it doesn’t support a SQL database, so no use for me.

Alright upgrading my current vCenter VM then. vCenter itself was pretty much strait forward and it was upgraded without any problems. The update manager was another story, upgrading itself was no problem although it didn’t seem to start and when opening my vSphere client I got the following error.

I seen this before with vCenter 4.1 and while checking the services I remembered. The installer actually makes the service use the local system account to start the service, usually that account does not have access to the update managers database. So change the two services for update manager (VMware vSphere Update Manager Service and VMware vSphere Update Manager UFA Service) to use the same account that is set for your VMware VirtualCenter Server service and you should be good to go.

Services check script

I was looking for a script that checks the services on a computer and that would restart the service when needed. Wondering around I found something that was close of what I was looking for at http://www.youdidwhatwithtsql.com It worked perfectly although I wanted some email reporting with it, so I know when a service is failing again Probably the script can be done much cleaner but it works for me ;o
Let me know if you have a better way of doing the below. Will be more then happy to update the script.

###############################################################################
#                                     										  #
# Services Check Script (SCS) - Version 1.2  								  #
#																			  #
###############################################################################

###############################################################################
#	Configuration        													  #
###############################################################################.

# Script dir
$strScriptdir = "C:\scripts\scs"

# Config file which servers to check (needs to be in $strScriptdir)
# Put each computer you want to check on a sepparate line
$strComputers = "computers.conf"

# Setup the Service array with the service names we want to check are running
# IE: 'SQLAgent$SQL2005', 'MSSQL$SQL2005'
$serviceArray = 'SQLAgent$SQL2005', 'MSSQL$SQL2005';

# Start services when not running (true/false)
$strStartService = "true"

# How much seconds to wait untill we recheck the state of the service when the script tried to start it
# (Default set on 60 seconds, you want to tweak this if some services require more time to start)
$strRecheckState = "60" 

# Email reporting
# Do you want to send email reports?
# 0 = never
# 1 = always
# 2 = only when services needed starting
# 3 = only when errors are found when starting services
$strSendReport = "3"

# From email address
$strFromEmail = "from@email.com"

# To email address
$strToEmail = "to@email.com"

# SMTP Host / Mail server
$strSMTPHost = "smtp.host"

###############################################################################
#	Configuration ends here...												  #
###############################################################################

###############################################################################
#	Setting some variables...  								              	  #
###############################################################################
$strConfig = $strScriptdir+"\"+$strComputers
$computers = Get-Content $strConfig

$strLogfile	= $strScriptdir+"\scs.log"
$strLogfile2 = $strScriptdir+"\scs2.log"
$strLogfile3 = $strScriptdir+"\scs3.log"

$strLogLevel = "0"

$strFixed = "0"
$strFixed2 = "0"

$strVersion = "1.2"
$strServiceStates = 'Stopped', 'Start Pending';

$strDateFormat = "%d-%m-%Y - %H:%M:%S"
$strDate=Get-Date -UFormat $strDateFormat

###############################################################################
#	Parsing log header...  									               	  #
###############################################################################
echo "#####################################################################" >> $strLogfile
echo "# Services Check Report for [$strDate]" >> $strLogfile
echo "#####################################################################" >> $strLogfile
echo "Checking servers ....... : $computers" >> $strLogfile
echo "Checking services ...... : $serviceArray" >> $strLogfile

###############################################################################
#	Send email function							                         	  #
###############################################################################
function send_email_report {
	$log = Get-Content $strLogfile
	$body = New-Object System.Text.StringBuilder
	[void] $body.AppendLine("<pre>");
	foreach($line in $log)
	{
    	[void] $body.AppendLine($line.ToString())
	}
	[void] $body.AppendLine("</pre>");
	$email_addr = $strToEmail
	$mailmessage = New-Object system.net.mail.mailmessage
	$mailmessage.from = $strFromEmail
	$mailmessage.To.add($email_addr)
	$mailmessage.Subject = "Services Check Report at [$strDate]"
	$mailmessage.IsBodyHtml = $True
	$mailmessage.Body = $body
	$SmtpClient = new-object system.net.mail.smtpClient
	$SmtpClient.Host = $strSMTPHost
	$smtpclient.Send($mailmessage)
}

###############################################################################
#	Cleanup function 							                         	  #
###############################################################################
function cleanup {
	Write-Host ""
	Write-Host "[SCS] Running cleanup"
	$FileExists = Test-Path $strLogfile
	If ($FileExists -eq $True) {
		Remove-Item $strLogfile
	}
	$FileExists = Test-Path $strLogfile2
	If ($FileExists -eq $True) {
		Remove-Item $strLogfile2
	}
	$FileExists = Test-Path $strLogfile3
	If ($FileExists -eq $True) {
		Remove-Item $strLogfile3
	}
}

###############################################################################
#	Email report check function 				                         	  #
###############################################################################
function report_check {
	Write-Host ""
	if ($strSendReport -eq "0" ) {
		Write-Host "[SCS] Email reporting disabled"
	}
	if ($strSendReport -eq "1" ) {
		Write-Host "[SCS] Email report send always"
		send_email_report
		Write-Host "[SCS] Send email report"
	}
	if ($strSendReport -eq "2" ) {
		Write-Host "[SCS] Email report send only when services need starting"
		if ($strLogLevel -eq "1" ) {
			send_email_report
			Write-Host "[SCS] Send email report"
		} else {
			Write-Host "[SCS] No services needed starting, not sending email report"
		}
	}
	if ($strSendReport -eq "3" ) {
		Write-Host "[SCS] Email report send only when errors are found starting services"
		if ($strLogLevel -eq "2" ) {
			send_email_report
			Write-Host "[SCS] Send email report"
		} else {
			Write-Host "[SCS] No errors found, not sending email report"
		}
	}
}

###############################################################################
#	Setup trap to catch exceptions							               	  #
###############################################################################
trap [Exception] {
	write-error $("TRAPPED: " + $_.Exception.Message);
}

###############################################################################
#	Checking each computer if services are running			               	  #
###############################################################################
foreach ($computer in $computers) {
	Write-Host ""
	Write-Host "[SCS] Checking computer: $computer";
	#parse log2 header
	echo ""  >> $strLogfile2
	echo "Starting service(s) ...."  >> $strLogfile2
	#parse log3 header
	echo ""  >> $strLogfile3
	echo "Script errors .........." >> $strLogfile3
	#parse log computer header
	echo ""  >> $strLogfile
	echo "#####################################################################" >> $strLogfile
	echo "# Service(s) for [$computer]" >> $strLogfile
	echo "#####################################################################" >> $strLogfile
	echo ""  >> $strLogfile
	echo "Service(s) status ......"  >> $strLogfile
	$objWMIService = Get-WmiObject -Class win32_service -computer $computer
	foreach ($service in $objWMIService) {
		# Check each service specicfied in the $serviceArray
		foreach ($srv in $serviceArray) {
			if ($service.name -eq $srv) {
				echo "Service ................ : $srv" >> $strLogfile
				Write-Host "[SCS] $srv is present on $computer";
				if ($service.state -eq "running") {
					Write-Host "[SCS] $srv is running on $computer";
					echo "Service running ........ : Yes" >> $strLogfile
					echo "........................" >> $strLogfile
				} else {
					$strFixed = "1"
					Write-Host "[SCS] $srv is not running on $computer";
					echo "Service running ........ : No" >> $strLogfile
					# If $start is true the script will attempt to start the service if it is stopped
					if ($strStartService -eq "true") {
						# Attempt to start the current service on the current computer
						$serviceInstance = (Get-WmiObject -computer $computer Win32_Service -Filter "Name='$srv'");
						$name = $serviceInstance.Name;
						Write-Host "[SCS] Attempting to start $name on $computer."
						echo "Service ................ : $name" >> $strLogfile2
						$serviceInstance.StartService() | Out-Null;
						# Refresh the object instance so we get new data
						Write-Host "[SCS] Waiting $strRecheckState seconds before checking state of the $name service"
						#Start-Sleep -s $strRecheckState
						$serviceInstance = (Get-WmiObject -computer $computer Win32_Service -Filter "Name='$srv'");
						$state = $serviceInstance.State;
						Write-Host "[SCS] $name is ""$state"" on $computer.";
						echo "Service state .......... : $name is now $state" >> $strLogfile2
						echo "........................" >> $strLogfile2
						foreach ($strServiceState in $strServiceStates) {
							if ($state -eq $strServiceState) {
								$strFixed2 = "1"
								echo "Script unable to start [$name] on server [$computer]" >> $strLogfile3
							}
						}
					}
				}
			}
		}
	}
	if ( $strFixed -eq "1") {
		if ( $strLogLevel -eq "0" ) {
			$strLogLevel = "1"
		}
		$strLog2 = Get-Content $strLogfile2
		echo $strLog2 >> $strLogfile
		Remove-Item $strLogfile2
		$strFixed = "0"
	}
	if ( $strFixed2 -eq "1") {
		$strLogLevel = "2"
		echo "........................" >> $strLogfile3
		echo "* The script was unable to start the service(s)" >> $strLogfile3
		echo "* Please check the logs on [$computer] for more information" >> $strLogfile3
		echo "........................" >> $strLogfile3
		$strLog3 = Get-Content $strLogfile3
		echo $strLog3 >> $strLogfile
		Remove-Item $strLogfile3
		$strFixed2 = "0"
	}
}

###############################################################################
#	Parsing log footer...  									               	  #
###############################################################################
echo ""  >> $strLogfile
echo "#####################################################################" >> $strLogfile
echo "# SCS v$strVersion (Services Check Script)" >> $strLogfile
echo "#####################################################################" >> $strLogfile

###############################################################################
#	Run report_check and cleanup functions 					               	  #
###############################################################################
report_check
cleanup

Backing up Avaya IPOffice systems with Powershell and TFTP

A little Powershell script that grabs the config of Avaya IPOffice system with TFTP. Since I didn’t spend to much time on it I’m just using a DOS TFTP client which you can download from http://www.tftp-server.com/tftp-client.html

The script:

###############################################################################
#                                     										  #
# Avaya IPOffice configuration backup script   			 					  #
#																			  #
###############################################################################

#IPOffice IP Address
$strIPOfficeIP = "X.X.X.X"
#IPOffice configuration file name (Usually the same name as the system)
$strIPOfficeCFG = 'ipoffice.cfg'
#IPOffice nice system name (used for renaming the backup files)
$strIPOfficeNME = "sysname"

#After how many days should we delete a backup?
$strBackupAge = "30"
#Backup folder
$strBackupFolder = "c:\scripts\ipoffice_backup\backups"

###############################################################################
#	Configuration ends here...												  #
###############################################################################

###############################################################################
#	Setting some variables...  										    	  #
###############################################################################

$cmdTFTP = "c:\scripts\ipoffice_backup\tftp.exe"
$strScriptDir = "c:\scripts\ipoffice_backup"

$strDateFormat = "%d-%m-%Y"
$strDate=Get-Date -UFormat $strDateFormat

###############################################################################
#	Cleanup function	                                                      #
###############################################################################

Function cleanup
{	Write-Host
	Write-Host "Starting backup file cleanup"
	$strNow = Get-Date
	$strLastWrite = $strNow.AddDays(-$strBackupAge)
	$strFiles = get-childitem $strBackupFolder -include $strIPOfficeNME+"*" -recurse |Where {$_.LastWriteTime -le "$strLastWrite"}
	if ( $strFiles -ne $null ) {
		foreach ($strFile in $strFiles) {
			$strRemove = $strFile
			Remove-Item $strRemove
			Write-Host "Removed backup: $strFile"
		}
	} else {
		Write-Host "No backups found older then $strBackupAge days"
	}
}

###############################################################################
#	Backup function			                                                  #
###############################################################################
Function backup
{	Write-Host
	Write-Host "Starting backing up IPOffice configuration"
	cd $strScriptDir
	& $cmdTFTP -i $strIPOfficeIP get config $strIPOfficeCFG
	mv $strScriptDir"\"$strIPOfficeCFG $strBackupFolder"\"$strIPOfficeNME"_"$strDate".cfg"
	$strBackupFile = $strBackupFolder+"\"+$strIPOfficeNME+"_"+$strDate+".cfg"
	Write-Host
	Write-Host "Backup saved to: $strBackupFile"
}

###############################################################################
#	Running the functions                                                     #
###############################################################################
clear
Write-Host "Avaya IPOffice configuration backup script"
cleanup
backup