2011/04/04

Shutdown all guests on Vmware virtual host

CURRENT CONFIGURATION: VMware 4.1.0 Build 260247
OBJECTIVE: Shutdown all guests on Vmware virtual host from APC Power Shute client.
SOLUTION: 
Please enable SSH on VMware host. vSphere Client -> Configuration -> Security Profile -> Properties -> SSH -> Start automatically.
Please download putty and run next command on Windows workstation or server.
@START c:\MyFolder\putty\plink.exe -ssh -pw MyPassword root@10.1.1.1 "/sbin/shutdown.sh -r now; /sbin/poweroff"

2011/01/10

Copy virtual machine on VmWare - network card issue

CURRENT CONFIGURATION: VMware ESXi 4, Ubuntu server 10.04
OBJECTIVE: Copy virtual machine on VMware
ISSUE: Network Card does not work after Linux virtual machine copy on VMware ESXi
 # /etc/init.d/networking restart
 * Reconfiguring network interfaces...
SIOCSIFADDR: No such device
eth0: ERROR while getting interface flags: No such device
SIOCSIFNETMASK: No such device
eth0: ERROR while getting interface flags: No such device
Failed to bring up eth0.
stop: Unknown instance:
# ifconfig -a
eth0_rename Link encap:Ethernet  HWaddr 00:00:xx:00:xx:00
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
All NIC are installed. Check command is
# lshw -C network
SOLUTION: 
to comment all lines in /etc/udev/rules.d/70-persistent-net.rules
# vi /etc/udev/rules.d/70-persistent-net.rules
Example:
# PCI device 0x8086:0x100f (e1000)
# SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:00:00:00:xx:01", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x8086:0x100f (e1000)
# SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:00:xx:00:00:02", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
Please reboot the Ubuntu server on VMware ESXi.

For Ubuntu server clone (image) creation (moving preparation) use next command on master clone (Source server) before final poweroff (shutdown).
sed -i 's/SUBSYSTEM/#SUBSYSTEM/g' /etc/udev/rules.d/70-persistent-net.rules

upgrade to VMvare ESXi 4.1 Perl VIRuntime.pm issue

CURRENT CONFIGURATION: VMware ESXi 4.0
OBJECTIVE: upgrade to VMvare ESXi 4.1
ISSUE:
1. VMware vSphere Host Update Utility 4.0 can not update ESXi 4.0 to 4.1
2. Command(1) C:\Program Files\VMware\VMware vSphere CLI> vihostupdate.pl --server myESXserver_name_orIP -i -b k:\Downloads\VMWare\VMWare_ESXi\ESXi4.1\upgrade-from-ESXi4.0-to-4.1.0-0.0.260247-release.zip -B ESXi410-GA
returns next error message
Can't locate VMware/VIRuntime.pm in @INC (@INC contains: C:/My_different_perl_version_installation/Perl/site/lib C
:My_different_perl_version_installation/Perl/lib .) at C:\Program Files\VMware\VMware vSphere CLI\bin\vihostupdat
e.pl line 13.
BEGIN failed--compilation aborted at C:\Program Files\VMware\VMware vSphere CLI\
bin\vihostupdate.pl line 13.
 3. When you had renamed previously installed Perl Folder command(1) would return next window
4. When you added Perl with full patch to command(1) command(2) would return next error message:
Can't open perl script "vihostupdate.pl": No such file or directory
SOLUTION:
1. Download  and install VMware vSphere
2. If you have previously installed Perl please rename Perl installation directory temporary. Example: From  C:/My_different_perl_version_installation/ to C:/__My_different_perl_version_installation/
3. Add Perl with full patch to command(1). Would be command(2)  
C:\Program Files\VMware\VMware vSphere CLI> "c:\Program Files\VMware\VMware vSphere CLI\Perl\bin\perl.exe" vihostupdate.pl --server myESXserver_name_orIP -i -b k:\Downloads\VMWare\VMWare_ESXi\ESXi4.1\upgrade-from-ESXi4.0-to-4.1.0-0.0.260247-release.zip -B ESXi410-GA
4. Use full path for Perl and vihostupdate.pl. Would be command(3)
C:\Program Files\VMware\VMware vSphere CLI> "c:\Program Files\VMware\VMware vSphere CLI\Perl\bin\perl.exe" "c:\Program Files\VMware\VMware vSphere CLI\bin\vihostupdate.pl" --server myESXserver_name_orIP -i -b k:\Downloads\VMWare\VMWare_ESXi\ESXi4.1\upgrade-from-ESXi4.0-to-4.1.0-0.0.260247-release.zip -B ESXi410-GA
SOLUTION BOTTOM LINE:
If you have previously installed Perl please rename Perl installation directory temporary.
Use full path for Perl and vihostupdate.pl. Would be command
C:\Program Files\VMware\VMware vSphere CLI> "c:\Program Files\VMware\VMware vSphere CLI\Perl\bin\perl.exe" "c:\Program Files\VMware\VMware vSphere CLI\bin\vihostupdate.pl" --server myESXserver_name_orIP -i -b k:\Downloads\VMWare\VMWare_ESXi\ESXi4.1\upgrade-from-ESXi4.0-to-4.1.0-0.0.260247-release.zip -B ESXi410-GA

To VMware: Thanks for nice exercise.

2010/11/16

Nagios: Restart a Windows Failed Services (cmd)

CURRENT CONFIGURATION: Linux OpenSuSe, Nagios 3.0.2, NRPE; Windows 2003 x64 server, NSClient++ 0.3.8.76

OBJECTIVE: Building a Self-Healing Network

ISSUE: Need some script to Restart failed Windows Services by Nagios Client

SOLUTION:
I created and tested win_service_restart.cmd batch file on Microsoft Windows 2003 servers.

--- Start of code ---

@echo off
:: *****************************************************************************
:: File:    win_service_restart.cmd
:: Author:  Vadims Zenins http://vadimszenins.blogspot.com
:: Version: 1.07
:: Date:    16/11/2010 12:28:45
:: Windows Failed Service restart batch file for Nagios Event Handler
::
::  Copy win_service_restart.cmd to \NSClient++\scripts\ folder.
::
:: Nagios commands.cfg:
:: define command{
::        command_name    win_service_restart
::        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -p 5666 -c win_service_restart -a "$SERVICEDESC$" $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
::        }
::
:: Nagios template-services_common-win.cfg
:: define service{
::         name                    generic-service-win-wuauserv
::         service_description     wuauserv
::         display_name            Automatic Updates
::         event_handler           win_service_restart
::         event_handler_enabled   1
::         check_command           check_nt!SERVICESTATE!-d SHOWALL -l $SERVICEDESC$
::         }
::
:: NSCLIENT++ version 0.3.8 NSC.ini:
::   [Settings]
::   allowed_hosts=192.168.1.1/32  ; your Nagios server IP
::   [NRPE]
::   allow_arguments=1
::   allow_nasty_meta_chars=1
::   [Script Wrappings]
::   cmd=scripts\%SCRIPT% %ARGS%
::   [External Script]
::   allow_arguments=1
::   allow_nasty_meta_chars=1
::   [External Scripts]
::   command[win_service_restart]=scripts\win_service_restart.cmd "$ARG1$" $ARG2$ $ARG3$ $ARG4$
::
::
:: Additional examples on http://vadimszenins.blogspot.com/2008/12/nagios-restart-windows-failed-services.html
::
:: Tested platform:
:: Windows 2003 R2 x64 SP2, Nagios 3.2.0, NSClient++ 0.3.8.76
::
:: Version 1.07 revision:
:: Description is changed for NSCLIENT++ version 0.3.8 NSC.ini
:: Version 1.06 revision:
:: Description is changed for NSCLIENT++ version 0.3.8 NSC.ini
:: Version 1.05 revision:
:: Logging changes, stop and start services commands nave changed. Logs examples added.
:: Version 1.04 revision:
:: Double restart of the servise is fixed
:: Version 1.03 revision:
:: Description is changed
:: Version 1.02 revision:
:: @NET changed to @SC
:: Version 1.01 revision:
:: Service name's with spase problem is fixed
::
:: This code is made available as is, without warranty of any kind. The entire
:: risk of the use or the results from the use of this code remains with the user.
:: *****************************************************************************

::echo 1: %1    2: %2    3: %3    4: %4

@SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
:: Grab a file name and extension only
SET SCRIPTNAME=%~nx0
:: Replace "
SET SCRIPTNAME=%SCRIPTNAME:"=%
SET LOGDIR=C:\tools\logs
SET SERVICENAME=%1
:: Replace "
SET SERVICENAME1=%SERVICENAME:"=%
SET LOGFILE=%1
SET LOGFILE=%LOGFILE:"=%
:: Replace space by _
SET LOGFILE=%LOGFILE: =_%
SET LOGFILE=%LOGDIR%\%LOGFILE%.log

if "%SERVICENAME1%"=="" SET LOGFILE=%LOGDIR%\NO_SERVICENAME.log
::@echo servicename:  %SERVICENAME%
::@echo logfile: %LOGFILE%
::@echo SERVICENAME1: %SERVICENAME1%

:: =============================================================================

if not exist %LOGDIR% md %LOGDIR%
echo. >>%LOGFILE%
echo =============================================================================  >>%LOGFILE%
echo %DATE% %TIME% %SCRIPTNAME% has started >>%LOGFILE%
echo =============================================================================  >>%LOGFILE%

@if "%SERVICENAME1%"=="" goto usage
@if "%SERVICENAME1%"=="/?" goto usage
@if "%SERVICENAME1%"=="-?" goto usage

@echo Variables 1: %1   2: %2   3: %3   4: %4 >>%LOGFILE%

@SC query %SERVICENAME% >>%LOGFILE%

@SC query %SERVICENAME% | FIND /I "RUNNING" >>%LOGFILE%
if .%ERRORLEVEL%.==.0. (
    SET RETURN=Service %SERVICENAME% is running
    goto END
)

:RESTART
@echo %DATE% %TIME% Restarting %SERVICENAME% services... >>%LOGFILE%
@SC stop %SERVICENAME% >>%LOGFILE% 2>&1
@sleep 2
SET RETURN=Service %SERVICENAME% start pending
@SC start %SERVICENAME% | FIND /I "FAILED"
if .%ERRORLEVEL%.==.0. (
    SET RETURN=Start Service %SERVICENAME% FAILED
    @SC start %SERVICENAME% >>%LOGFILE% 2>&1
    goto END
)
@sleep 5
@SC query %SERVICENAME% | FIND /I "RUNNING"
if .%ERRORLEVEL%.==.0. (
    SET RETURN=Service %SERVICENAME% has started
    @SC query %SERVICENAME% >>%LOGFILE%
    goto END
)
@goto end

:USAGE
@echo Usage: >>%LOGFILE%
@echo  win_service_restart "^" ^ ^ ^ >>%LOGFILE%
@echo  ^ is "Service name", do not mix with "Display name" >>%LOGFILE%
@echo  ^, ^ and ^ are optional >>%LOGFILE%
::exit 128

:END
echo %DATE% %TIME% %SCRIPTNAME% has finished with code >>%LOGFILE%
echo %RETURN% >>%LOGFILE%
@echo %SCRIPTNAME%: %RETURN%
exit 0

--- End of code ---

Additional examples:

template-services_common-win.cfg
define service{
name generic-service-win-backup-agent
service_description BackupExecAgentAccelerator
display_name Backup Exec Remote Agent
event_handler win_service_restart
event_handler_enabled 1
check_command check_nt!SERVICESTATE!-d SHOWALL -l $SERVICEDESC$
register 0
}

services_common-win.cfg
define service{
use generic-service-win-backup-agent,generic-service-office
hostgroup_name winsrv-office ; Assign group of servers
host_name !SERVER11,!SERVER12 ; use this to exclude some servers or delete this row
}

group_windows.cfg
define hostgroup{
hostgroup_name winsrv-office ; The name of the hostgroup
alias Office Servers
}

host-server01.cfg
define host{
use windows-server ; Inherit default values from a template
host_name server01 ; The name we're giving to this host
alias server 01 ; A longer name associated with the host
hostgroups winsrv-office ; Group of servers
address 192.168.1.1 ; IP address of the host
}


DOWNLOADS:
Download the script from exchange.nagios.org
Download the script latest version from mirror.
 
md5: dbf0663a9e6648886eb8015cee8c9ce0 *win_service_restart.zip

Download the script previous version 1.05 from mirror. md5: 8b90ba7654227f1bf07c694368843b9

Download the script previous version 1.04 from mirror. md5: fd00753533e5fb655d824c3bf1d36d4

2010/03/30

Exchange 2007 vs Google Mail Premier Edition

CURRENT CONFIGURATION: Company has Exchange 2007 and Blackberry Servers

OBJECTIVE: Compare technical possibilities with Google Email (gmail) Premier Edition for small and middle business, especial from email administration point of view.

Read a document.

SOLUTION: If you have Microsoft Exchange implemented, stay where you are. 
If I have either to upgrade Microsoft Exchange or implement email solution from scratch I will discuss with manager email confidentiality and requirements. If confidentiality does not have the highest mark and company does not have branch in China I will suggest go with Google Apps Premier Edition.