31 August, 2010

SCOM - a link to an article I wrote on How to Play Sound Alerts on SCOM Console

One of the problems with System Center Operation Manager console is the lack of sound alerts.
I wrote an article a while back on how to implement a sound alert for events.

Here is the link from perti.co.il - http://www.petri.co.il/play-sound-alerts-on-microsoft-system-center-operations-manager-console.htm

Enjoy

29 August, 2010

Xen Server environment mapping script

Hello,

do you want a basic xen server environment mapping script ?, you got it.
for starting it will list all the hosts and guests, in the future I will add UUID and more...

================================
echo off
set user=[]
set password=[]
set server=[]

del auto_host_list.txt /q
del auto_vm_list.txt /q

"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% host-list params=name-label,uuid >auto_host_list1.txt
for /f "tokens=1,2,3,4 delims=( " %%A in (auto_host_list1.txt) do (echo %%D >> auto_host_list.txt)

"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% vm-list params=name-label >auto_vm_list1.txt
for /f "tokens=1,2,3,4 delims=( " %%A in (auto_vm_list1.txt) do (
if NOT %%D==Control echo %%D  >> auto_vm_list.txt
)

del auto_host_list1.txt /q
del auto_vm_list1.txt /q
================================

26 August, 2010

XenServer disaster recovery script in batch

Hi all,
I wanted to make my life easier when the disaster will hit (and between you and me it allays a meter of time) so I wrote a menu driven disaster recovery script.
The script is covering:
  1. Pool Master failure
  2. Host Member Failure
  3. resetting the power state of VM's
  4. Recovering them to another HOST
My goal was giving a simple name based actions rather than using UUID's.

You will need 2 more files that create your environment:
  1. host_list.txt - all the hosts and their role, one each line. example: [servername, member]
  2. vm_list.txt - all the vm
Those 2 files are case sensitive so be sure to write the names correctly.
Note: in host_list.txt the role should be in lower letters (member/master)

To help you I saved it also as a GoogleDoc.

Any comments/improvements will be welcomed...

================================
Echo off
title "Xen Recover for 5.5 - at any time hit Cntrl+C and then Y to exit the script."

set user=[]
set password=[]
set server=[]

cls

echo This is a disaster recover script for Xen Server.
echo.
echo Host Infrastructure:
for /f "tokens=1,2 delims=," %%A in (Host_list.txt) do (echo Host: %%A - %%B)
echo.
echo Guest Machines:
for /f %%A in (VM_list.txt) do (echo VM: %%A)
echo.
echo.
echo is this OK ? (1-yes)
set /P C=
if %C%==1 goto continue
goto EOF

:continue


cls
echo Good.
echo What do you want to do ?
echo 1 - Recover from pool master failure
echo 2 - Recover from member failure
set /P C=
if %C%==1 goto master_failure
if %C%==2 goto member_failure


:master_failure
echo To which server to you want to transfer the pool master role ? (IP address only)
set /P C=
echo transfer pool master to %C%
pause
echo pool move to %C%
set server=%C%
echo on
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% pool-emergency-transition-to-master
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% pool-recover-slaves
Echo off
:master_failure_2
echo Type the new pool master server name: (case sensitive)
for /f "tokens=1,2 delims=," %%A in (Host_list.txt) do (
    if %%B==member (echo Host: %%A)
)
set /P xenhostname=
set caller=master_failure_3
goto check_host
:member_failure_3
if "%host_ok%"=="yes" (goto member_failure_4)
echo The Host name is not on the list
pause
goto member_failure_2
set failed-host=%xenhostname%
goto power_reset


:member_failure
echo Which member server has failed ? (type the name - case sensitive)
echo Showing only members.
for /f "tokens=1,2 delims=," %%A in (Host_list.txt) do (
    if %%B==member (echo Host: %%A)
)
echo.
echo It seems that the following host is down:
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% host-list host-metrics-live=false params=name-label
set /P xenhostname=
set caller=member_failure_2
goto check_host
:member_failure_2
if "%host_ok%"=="yes" (goto member_failure_3)
echo The Host name is not on the list
pause
goto member_failure
:member_failure_3
set failed-host=%xenhostname%
goto power_reset


:power_reset
echo resetting the power state on the machines that was on the failed host [%failed-host%]
pause
echo get host uuid
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% host-list name-label=%xenhostname% --minimal > host_uuid.txt
set /p host_uuid=
echo resetting power on VM's residing on %xenhostname% [uuid=%host_uuid%]
echo on
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% vm-reset-powerstate resident-on=%host_uuid% --force --multiple
Echo off
goto VM_recover

:vm_recover
echo Which VM do you need to recover ?
for /f %%A in (VM_list.txt) do (echo %%A)
echo it seems that the following VM's were on the failed host:
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% vm-list is-control-domain=false resident-on=%host_uuid% params=name-label
set /P vmname=
set caller=vm_recover_2
goto check_vm
:vm_recover_2
if "%vm_ok%"=="yes" (goto vm_recover_3)
echo The VM name is not on the list...
pause
goto vm_recover
:vm_recover_3
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% vm-list name-label=%vmname% --minimal > vm_uuid.txt
set /p vm_uuid=
:vm_recover_4
echo Recover to which HOST ?
for /f %%A in (host_list.txt) do (echo %%A)
echo.
echo Note: %failed-host% has failed and cannot be choosen.
set /P xenhostname=
if "%xenhostname%"==%failed-host% (
    echo %failed-host% has failed and cannot be choosen.
    goto :vm_recover_4
)
set caller=vm_recover_5
goto check_host
:vm_recover_5
if "%host_ok%"=="yes" (goto vm_recover_6)
echo The HOST name is not on the list...
pause
goto vm_recover_4
:vm_recover_6
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% host-list name-label=%E% --minimal > host_uuid.txt
set /p host_uuid=
echo recover %vmname% [%vm_uuid%] on %xenhostname% [%host_uuid%]
echo on

"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% xe vm-param-set uuid=%vm_uuid% affinity=%host_uuid%
Echo off
echo.
echo Recover another VM ? (1-yes)
set /P C=
if %C%==1 goto vm_recover
goto end



rem *** general functions ***
:check_host
set host_ok=
for /f "tokens=1 delims=," %%A in (Host_list.txt) do (
    if "%xenhostname%"=="%%A" (set host_ok=yes)
)
goto %caller%

:check_vm
set vm_ok=
for /f %%A in (vm_list.txt) do (
    if "%vmname%"=="%%A" (set vm_ok=yes)
)
goto %caller%


:end

rem *** cleanup ***
del host_uuid.txt /q
del vm_uuid.txt /q
pause

:EOF
echo *** written by snir hoffman http://snirh.blogspot.com ***

==========================================

17 August, 2010

Xen Server Automatic Host backup script using batch

Hi,

You can never be too carefull, here is an automated backup script for xen server host.
Be careful, it can reach to 1G... (Mine did).

as always you will need a list file with the names of the xen hosts (case sensitive), name it host_list.txt.
and the following: (this will keep 2 versions, you can remove those lines if you want)
replace [] with your data.
====================================
for /f %%A in (host_list.txt) do (
del "D:\Backup\XenServer\OLD_%%A_Backup.bak" /q
ren D:\Backup\XenServer\%%A_Backup.bak Old_%%A_Backup.bak
"C:\Program Files\Citrix\XenCenter\xe.exe" -s [server ip] -u [user] -pw [password] host-backup host=%%A file-name=D:\Backup\XenServer\%%A_Backup.bak
)
====================================

04 August, 2010

Automatic script for Xen Coalesce (gain space back after using snapshots)

If you are using snapshots in XenServer you may noticed a spaced beed used on the storage that you cannot explained.
This is due to using snapshots. After you create the initial snapshot xen will continue writing to it even if it is not there.
To reclaim the space the VM's VDI need to go a proccess named "Coalesce" which integrates the data from the snapshot into the original VDI.

I used article CTX123400 to base my script on.
Also you will need to download "plink".

3 files:
  1. VM_List.txt - a list of the machine names (case sensitive)
  2. Step1.cmd
  3. Step2.cmd

Step1.cmd: replace [] with your own data
==========================
echo off
set user=[user]
set password=[password]
set server=[server ip]
del log_Coalesce.txt /q
for /f %%A in (vm_list.txt) do (step2.cmd %%A >>log_Coalesce.txt)
==========================

Step2.cmd:
==========================
title ***** Working on %1 *****
echo ***** Start working on %1 *****
echo.echo Start at:
echo %date% - %time%
set vm_uuid=
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% vm-list name-label="%1" --minimal > vm_uuid.txt
set /p vm_uuid=

plink -ssh %server% -l %user% -pw %password% coalesce-leaf -u %vm_uuid%
echo.
echo %date% - %time%
echo ***** End working on %1 *****
echo.
============================


Enjoy