Wednesday 7 September 2011

Just upgraded your VMWare vmhost from 3.5 to 4.0 or 4.1? Read on

Hi all,

If you have recently upgraded your VM Host to ESX4.0, 4.1 or 5.0 you might want to run this code (after installing the vmware powershell extensions, this is a powershell script after all):

function reportchangetracking{

$vm_name = Get-VM -location [cluster_name] | get-view

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

foreach ($objitem in $vm_name) {

#Write-host $objitem.name, $objitem.config.changetrackingenabled

if($objitem.config.changetrackingenabled -neq "True"){

$vmConfigSpec.changeTrackingEnabled = $true

$vmView.ReconfigVM($vmConfigSpec)

#punch it Chewy (reloads config spec. better than having to shut the machine down)

sleep 3

Get-VM $objitem.name | New-Snapshot -Name "Temp"

sleep 5

Get-VM $objitem.name | Get-Snapshot | Where {$_.Name -eq "Temp"} | Remove-Snapshot -Confirm:$false

}


}

}

In ESX3.5, VMTools never quiesced the base disk properly when taking snapshots. This meant that when Windows Server 2008 came along with VSS, the tools didn't use it, and 3.5 never added in the setting the code does above.

When you upgraded your host, it never added this setting at the VM level, so this task needs to be done manually. If you have a lot of machines, headaches ensue. After running the script, it might be an idea to update the tools installation on your server anyway.

Note that you do not have to run this if you created a machine on ESX4.0 or greater. Its been done for you.

Use this script at your own risk. It's no fault of mine if you break something.

Thanks for reading,

Trev

Monitoring Citrix Xenapp licenses through Nagios

Hi all,

More scripts. Again in VBS. This time for monitoring citrix licensing.

All this script does is check to see how many licenses are being used as a percentage of the total. Then returns normal, warning or critical depending on %age.



' change this line to suit the location of the lmstat utility
' ***
CommandLine = "C:\Program Files\Citrix\Licensing\LS\lmstat -c ""C:\Program Files\Citrix\Licensing\MyFiles\license_file.lic"" -f MPS_ADV_CCU"
' ***

Set objShell = CreateObject("WScript.Shell")
Set oExec = objShell.Exec(CommandLine)
countLicenses = 0

Do Until oExec.StdOut.AtEndOfStream
mystring= oExec.StdOut.ReadLine
if InStr(mystring, "Users of MPS_ADV_CCU:") Then

issued_start = InStr(mystring,"(Total of ")
issued_len = InStr(mystring, " licenses issued;") - (issued_start + 10)

lic_total = Mid(mystring, issued_start + 10, issued_len)

'-------------------------------------------------------------------------------------------------------------------------------------------------
inuse_start = InStr(mystring,"; Total of ")
inuse_len = InStr(mystring, " licenses in use)") - (inuse_start + 12)


lic_inuse = Mid(mystring, inuse_start + 12, inuse_len)


pc = int(lic_inuse / lic_total * 100)
'pc = 93

if pc => 90 then


WScript.Echo "Critical - " & pc & "% in use"
WScript.Quit(2)
end if


if pc => 80 then


WScript.Echo "Warning - " & pc & "% in use"
WScript.Quit(1)
else

WScript.Echo "OK - " & pc & "% in use"
WScript.Quit(0)
end if


Exit Do

end if
Loop
There you have it. Normal restrictions apply. If you run it and it breaks your stuff, its your fault for running untested code. It works for me.

Import this script into nsclient++ and nagios in the normal way. I will document this at some point.

Thanks for reading.

Trev

VMWare VCB backups

Hi all,

When backing up many virtual machines, you may try one of the big backup solutions, such as Symantec, Commvault, Veeam, and the like. Unfortunately in this case they all rely on one thing.

THE VMWARE API

There is a problem with the API. VMWare are aware there is a problem with it (calls were logged late last year about the problem) but so far there has been no response at all.

The problem is that when a backup of a VM happens, it takes a snapshot of the machine.
The machines base disk and other chuff is backed up, then the snapshot is released. What is happening (to many people) is that the snapshot is removed from the snapshot manager, but the snapshot file is not deleted, and the deltas are still written to the snapshot.

Luckily(!) for me, my luns filled up and bombed out after 2 snapshots. There are reports out there that if you have 25 of these "ghost snapshots" then you start running into problems. For example redo log errors. The fix is easy enough, although a pain in the arse. Basically just run the convertor against it, and itll roll all the snaps together. Don't faff with the command line unless you really have to.

Anyhew, there is one option. In version 4.1 VCB still works. So you can use that. I have written a script you can use, usual terms apply. By usual terms I mean, if this fucks your environment its not my fault. Lose data, it's not my fault.

Here is the code:

Dim fso, ts, weight
weight=0
Const ForWriting = 2
set ofso2 = createobject("scripting.filesystemobject")
set ofiletemp = ofso2.opentextfile ("servers.txt", 1)
set cline = createobject("wscript.shell")
'----------------------------------------------------------------------
do while not ofiletemp.atendofstream
weight = weight + 1
servername = ofiletemp.readline
if weight < 6 then
'msgbox servername
fullpath = "vcbmounter -h [yourVCname] -u username -p Password -a name:" & servername & " -r e:\vmbackups\" & servername & " -t fullvm -m nbd"
cline.run fullpath, 1, False 'lets another copy open "NBD!!"
else
fullpath = "vcbmounter -h [yourVCname] -u username -p Password -a name:" & servername & " -r e:\vmbackups\" & servername & " -t fullvm -m nbd"
cline.run fullpath, 1, True 'waits for this one to finish before carrying on
weight = 0 'resets weight to 0
end if
loop

What you need to do is put this file in the VCB directory in c:\program files\vmware\vmware consolidated backup/

Create a servers.txt file that has a list of your servers in, one per line.

If you look in the code there is a file path to e:. That is the destination directory. Change it to a destination you like.

Once this script has finished, you will have a directory in your detination dir, for every machine, filled with the files that make up that machine. Back these machines up however you want, or just have them as a handy copy.

When you are finished, run this script:

Dim fso, ts, weight
weight=1
Const ForWriting = 2
set ofso2 = createobject("scripting.filesystemobject")
set ofiletemp = ofso2.opentextfile ("servers.txt", 1)
set cline = createobject("wscript.shell")
'----------------------------------------------------------------------
do while not ofiletemp.atendofstream
servername = ofiletemp.readline
'msgbox servername
fullpath = "vcbmounter -h [yourVCname] -u userid -p password -U e:\vmbackups\" & servername
'msgbox fullpath
cline.run fullpath, 1
loop

This will remove all those machine directories. Again, don't forget to change the file path beginning "e:\" in the script. This also needs to live in the VCB directory mentioned above.

This works without creating ghost snapshots. It won't work at all against ESX5.0 as far as I know.

Thanks for reading,

Trev