Thursday, April 7, 2011

Get/ Set informations on multiple HP Onboard Administrator / Virtual Connect - Example with setting password and show all

When you need to get informations (like "SHOW ALL") on more than 400 Onboard Administrator or Virtual Connect, production team is always happy when you can give them an automatic solution.

Before give you main script for that, let's explain some details:
HP Onboard Administrator or Virtual Connect can be connect by SSH using tools like putty (Alternative Download). When you are connect on your OA or VC you can use some command line.

For more information about OA command line go to Onboard Administrator dedicated HP site and specifically to OA download manual on Manual OA site to download HP BladeSystem Onboard Administrator Command Line Interface User Guide(Alternative Download)

For more information about VC command line go to Manual VC site where you could find HP Virtual Connect Manager Command Line Interface (Alternative Download)

To use plink.exe (tool to do putty link), on OA or VC, I give you some examples below

To create a new OA administrator user named admin with password pass

plink -ssh -l Administrator -pw password -batch 192.168.1.254 -m OAadduser.txt

with OAadduser.txt

ADD USER "admin" "pass"
SET USER ACCESS "admin" ADMINISTRATOR
SET USER FULLNAME "admin" "Backup Administrator"
ASSIGN SERVER ALL "admin"
ASSIGN INTERCONNECT ALL "admin"
ASSIGN OA "admin"


To change admin OA user password to newpass

plink -ssh -l Administrator -pw password -batch 192.168.1.254 -m OAchangepassword.txt

with OAchangepassword.txt

SET USER PASSWORD "admin" "newpass"


To delete admin OA user

plink -ssh -l Administrator -pw password -batch 192.168.1.254 -m OAremoveuser.txt

with OAremoveuser.txt

REMOVE USER "admin"


To show all OA informations

plink -ssh -l Administrator -pw password -batch 192.168.1.254 -m OAshowall.txt

with OAremoveuser.txt

SHOW ALL




To create a new VC administrator user named admin with password pass

plink -ssh -l Administrator -pw password -batch 192.168.1.250 -m VCadduser.txt

with VCadduser.txt

add user admin Password=pass Privileges="domain,server,network,storage" FullName="Backup Administrator" Enabled=true


To change admin VC user password to newpass

plink -ssh -l Administrator -pw password -batch 192.168.1.250 -m VCchangepassword.txt

with VCchangepassword.txt

set user admin Password=newpass


To delete admin VC user

plink -ssh -l Administrator -pw password -batch 192.168.1.250 -m VCremoveuser.txt

with VCremoveuser.txt

remove user admin


To show all VC informations

plink -ssh -l Administrator -pw password -batch 192.168.1.250 -m VCshowall.txt

with VCshowall.txt

SHOW ALL



Now the best part: do all these actions on multiple Onboard Administrator or Virtual Connect. If you do not want to do copy/paste for each part, I encourage you to download GetSetHPOAVCInfos.zip file file.

First, you must create putty ssh keys. For this, execute plink_reg.cmd which will create these key then will export registry to plink.reg file
Why create ssh keys before ? That permit to avoid to answer yes to each OA or VC

@Echo OFF
Rem
Rem Generate plink reg
Rem
Rem F.RICHARD
Rem Initial Version: 2010 August
Rem modification 2011 March : add filename parameter
Rem

SET CURDIR=%~d0%~p0
SET FILENAME=%~n0%~x0
If "%1"=="" goto :ERRORNOFILE

cd /d %CURDIR%
set inputfile=%1
If NOT EXIST %inputfile% GOTO :ERRORFILE

SET LOGFILE="%CURDIR%plink_reg.log"

If NOT EXIST plink.exe GOTO :ERRFILEPLINK
echo Begin %date% %time% > %LOGFILE%




For /F "tokens=1,2,3 delims=;" %%i in (%inputfile%) do call :doit %%i %%j %%k


echo End %date% %time% >> %LOGFILE%
regedit /E plink.reg "HKEY_CURRENT_USER\Software\SimonTatham"
goto :EOF




:doit
rem echo %1 %2 %3
IF {%1}=={} GOTO :ERRORLINE
IF {%2}=={} GOTO :ERRORLINE
IF {%3}=={} GOTO :ERRORLINE


Echo Reg plink %1 (%date% %time%)
Echo ----------------------------- >> %LOGFILE% 2>>&1
Echo Reg plink %1 (%date% %time%) >> %LOGFILE% 2>>&1
plink.exe -ssh -l %2 -pw %3 -batch %1 "exit" >> %LOGFILE% 2>>&1
goto :EOF



:ERRORLINE
Echo ERROR next line (something missing)
Echo %1;%2;%3
goto :EOF

:ERRORFILE
Echo ERROR file %inputfile% does not exist in %CURDIR% directory
goto :EOF

:ERRFILEPLINK
Echo ERROR: file plink.exe does not exist in %CURDIR% directory
Echo Execute plink.exe before executing this file
goto :EOF

:ERRORNOFILE
Echo ERROR You must specify a filename containing line with these informations
Echo ip_or_name;login;password
Echo Ex: run
Echo %FILENAME% myOA.txt
Echo with myOAVC.txt containing
Echo 192.168.1.251;Administrator;password
Echo 192.168.1.252;Administrator;password
echo.
goto :EOF



To use script GetSetHPOAVCInfos.cmd, which permit to execute command line on all VC or OA use for example

GetHPOAVCInfos.cmd testOAVC.txt testOAVCcmdline.txt

with file testOAVC.txt containing for example these lines

192.168.1.220;administrator;password
192.168.1.224;administrator;password

and file testOAVCcmdline.txt with these lines

show all


All informations are return in oa_or_vc.log file
If you want to separate each log (ex: oa_or_vc_192.168.1.220.log, oa_or_vc_192.168.1.224.log) add SEPARATELOG like this

GetHPOAVCInfos.cmd testOAVC.txt testOAVCcmdline.txt SEPARATELOG


GetSetHPOAVCInfos.cmd file

@Echo OFF
Rem
Rem Get Information in HP Onboard Administrator or Virtual Connect
Rem
Rem F.RICHARD
Rem August 2010
Rem modification 2011 March : add filename parameter
Rem

SET CURDIR=%~d0%~p0
SET FILENAME=%~n0%~x0
If "%1"=="" goto :ERRORNOFILE
If "%2"=="" goto :ERRORNOFILE
SET SEPARATELOG=NO
If "%3"=="SEPARATELOG" SET SEPARATELOG=YES

cd /d %CURDIR%
set inputfile=%1
If NOT EXIST "%inputfile%" GOTO :ERRORFILE

set actionfile=%2
If NOT EXIST "%actionfile%" GOTO :ERRORFILE2

SET separate=.log
SET LOGFILE=%CURDIR%oa_or_vc

If NOT EXIST plink.exe GOTO :ERRFILEPLINK
echo Begin %date% %time%
echo Begin %date% %time% > "%LOGFILE%%separate%"

If NOT EXIST plink.reg GOTO :ERRFILEPLINKREG
regedit /s plink.reg

For /F "tokens=1,2,3 delims=;" %%i in (%inputfile%) do call :doit %%i %%j %%k

SET separate=.log
echo End %date% %time%
echo End %date% %time% >> "%LOGFILE%%separate%"
goto :EOF





:doit
IF {%1}=={} GOTO :ERRORLINE
IF {%2}=={} GOTO :ERRORLINE
IF {%3}=={} GOTO :ERRORLINE


Echo Use %actionfile% file on %1 (%date% %time%)
If "%SEPARATELOG%"=="YES" SET separate=_%1.log
If "%SEPARATELOG%"=="YES" echo.> "%LOGFILE%%separate%"
plink.exe -ssh -l %2 -pw %3 -batch "%1" -m "%actionfile%" >> "%LOGFILE%%separate%"
cscript //NOLOGO convertunix2dos.vbs "%LOGFILE%%separate%"
goto :EOF


:ERRORLINE
Echo ERROR: next line (something missing)
Echo %1;%2;%3
goto :EOF

:ERRORFILE
Echo ERROR: file %inputfile% does not exist in %CURDIR% directory
goto :EOF

:ERRORFILE2
Echo ERROR: file %actionfile% does not exist in %CURDIR% directory
goto :EOF

:ERRFILEPLINK
Echo ERROR: file plink.exe does not exist in %CURDIR% directory
Echo Execute plink.exe before executing this file
goto :EOF

:ERRFILEPLINKREG
Echo ERROR: file plink.reg does not exist in %CURDIR% directory
Echo Execute plink_reg.cmd before executing this file
goto :EOF

:ERRORNOFILE
Echo ERROR You must specify a filename containing line with these informations
Echo ip_or_name;login;password
Echo Ex: run
Echo %FILENAME% myOA.txt
Echo with myOAVC.txt containing
Echo 192.168.1.251;Administrator;password
Echo 192.168.1.252;Administrator;password
echo.
goto :EOF



For information, this script use convertunix2dos.vbs to convert unix OA or VC return carriage to windows (script found on the net, don't remember where, sorry for the author)

Dim fso, ts, s, arg, fil, fpath, s1
Set fso = CreateObject("Scripting.FileSystemObject")
arg = WScript.arguments.item(0)
Set ts = fso.OpenTextFile(arg, 1, False)
s = ts.ReadAll
ts.Close
Set ts = Nothing

s1 = Replace(s, vbCrLf, vbCr, 1, -1, 0)
s1 = Replace(s1, vbLf, vbCr, 1, -1, 0)
s1 = Replace(s1, vbCr, vbCrLf, 1, -1, 0)

Set ts = fso.CreateTextFile(arg, True)
ts.Write s1
ts.Close
Set ts = Nothing
Set fso = Nothing

7 comments:

Justin said...

Great post.. I used the plink_reg.cmd which generated the reg files, I execute to add to registry but I still get the following when running link:

The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's dss key fingerprint is:
ssh-dss 1024 9f:0e:44:cb:d9:17:b5:18:fc:72:37:a8:81:1b:97:03
Connection abandoned.

Ideas?

Justin said...

I figured it out.. my input file was FQDN put the the bat files I am using to call plink was hostname so the key did not match. :)

Anonymous said...

Hello and great post.
I need help because when I try to collect VCM config file I get an operation failed error. Other batch work fine. Any ideas?
Thanks.
Andrea

Franck RICHARD said...

Hello Andrea.
What command do you exactly execute ?
First thing to debug is to test your command in a putty window in 1 of your VC (ex: VC with ip address 192.10.10.1)
Then, if your commands works (for example "show enclosure"), create your own "myVCcommand.txt" file with these commands.
Now create your myVCip.txt file with VC ip address tested on putty, and only this VC (in my example VC with ip address 192.10.10.1). That permit to confirm script works correctly.
Remember my scripts execute commands and display console result to file.
keep me inform about these tests.

Andrea said...

Hello Richard and many thanks for your help.
I need to execute the save config command,

save configbackup address=tftp://10.1.1.1/VCEFXTW212100GK.cfg

This command works in a putty window. Any other tested commands work fine using scripts.
Regards.
Andrea

Franck RICHARD said...

It seems it doesn't work with this command.
My tests:

10.1.1.2 tftp server
10.1.1.1 VC
using tftpd32.exe for tftp server

with putty
->save configbackup address=tftp://10.1.1.1/test.cfg
SUCCESS: Config backup transfer completed

with plink
VCsavebackup.txt file with
save configbackup address=tftp://10.1.1.1/test.cfg

with plink
plink.exe -ssh -l user -pw password 10.1.1.1 -m VCsavebackup.txt
ERROR: Operation failed

plink.exe -ssh -l user -pw password 10.1.1.1 "save configbackup address=tftp://10.1.1.2/test.cfg"
ERROR: Operation failed

so a solution is to use sendkeys with putty and something like
That could be something like

Option Explicit
Dim objShell,strPutty
Dim strUser,strPassword,strServer,strBackupFilename,strTFTP
Dim strScriptFullName, strScriptPath

strScriptFullName = WScript.ScriptFullName ' ex: C:\Program Files\MyFolder\MyProg.exe
strScriptPath = Left(strScriptFullName, InStrRev(strScriptFullName, "\") - 1) ' ex: C:\Program Files\MyFolder
strPutty= strScriptPath & "\" & "putty.exe"

strTFTP="10.1.1.2"
strUser="user"
strPassword="password"
strServer="10.1.1.1"
strBackupFilename=strServer & ".cfg"

Set objShell = CreateObject( "WScript.Shell" )
objShell.Run strPutty & " -ssh " & strUser & "@" & strServer
WScript.Sleep 3000
'objShell.AppActivate strServer & " - PuTTY"
WScript.Sleep 3000
objShell.SendKeys "" & strPassword & "{ENTER}"
WScript.Sleep 5000
objShell.SendKeys "save configbackup address=tftp://" & strTFTP & "/" & strBackupFilename & "{ENTER}"
WScript.Sleep 5000


try also to replace "putty.exe" with "plink.exe"

but remember with "show all" you have all configuration saved

David Heinrich said...

I have a complete system for dos based management and inventory of enclosures. I have 64 enclosures around 12 data centers and I can pull a inventory of everytihg in less than 10 min from scratch that dumps into an excel spread sheet.

ping me at david.heinrich@gmail.com