HowTo monitor the NIC used by a Virtual Machine in a Hyper-V cluster
Recently I had a customer with the following problem: Hyper-V Host Clusters don't support NIC Teaming. So I have my VM clustered, but my machine does not failover when the NIC used for that machine has a problem. E.g. Network cable unplugged.
One approach to workaround this, is to add a cluster resource script to the Cluster Group. Below is a script, with short instructions.
Please note, this is a sample script, so you should consider testing and modifications to adjust for your own needs.
Unfortunately, this approach is not applicable if you manage your cluster with SCVMM 2008, as it will mark your VM as "unsupported"
This "unsupporte cluster configuration" notice in SCVMM will go away with SCVMM 2008 R2, and a April updated to SCVMM 2008
Cheers
Robert
copy and paste the below and save as NicHa.vbs
'*******************************************************************************************************************************************************
' Nic HA Script. Sample. Please feedback to robertvi at microsoft.com
'
'INSTALL INSTRUCTIONS
'
' 1. copy this script to all cluster nodes into %windir%\cluster
' 2. In Failover Cluster Management Select the VM you wish to add NIC Monitoring
' 3. Select "Add a resource" -> Generic Script
' 4. Enter %windir%\cluster\nicha.vbs
' 5. Next, Finish. Note the name of the created resource (nicha Script)
' 6. Run ncpa.cpl
' 7. Identfiy the Phyiscl NIC that is used by the Switch for this VM (This NIC should only have the Switch Protocol bound)
' Usually something like "Local Area Connection"
' 8. Rename this NIC to something like "VM Network 1"
' 9. Do steps 6 to 8 on all cluster nodes
' 10. Open a Elevated CMD Prompt
' 11. Using the names from above, "nicha script", "VM Network 1"'
' 12. In cmd prompt, issue the following command: cluster res "nicha Script" /priv NicName="VM Network 1"
' 13. Online the Script Resource
'
'You may edit the properties of the Virtual Machine Group in Failover Cluster Management to allow more failovers in a given period.
'The Default of 2 may be reached easily during testing. The script resource will then fail, but the group will not move
'
'The availability of the NIC is checked every minute by default.
'This could be changed in the Advanced Properties of the Script Resource in the "Thorough resource health check interval", if needed
'
'
'
'*******************************************************************************************************************************************************
'*******************************************************************************************************************************************************
'*******************************************************************************************************************************************************
'Global variables
'*******************************************************************************************************************************************************
'Script Version
ScriptVersion = "0.2"
'*******************************************************************************************************************************************************
'Open()
'
'*******************************************************************************************************************************************************
Function Open()
On Error Resume Next
Resource.LogInformation("Entering Open() for NIC Monitoring Generic Script Version " & ScriptVersion)
If Resource.PropertyExists("NicName") = FALSE Then
Resource.AddProperty("NicName")
Resource.LogInformation("NICHA: Property NicName not configured")
End If
Open = 0
End Function
'*******************************************************************************************************************************************************
'Online()
'
'*******************************************************************************************************************************************************
Function Online()
'Check if the NIC is connected, otherwise fail Open
Online = 1
strComputer = "."
strNicName = Resource.NicName
strquery = "Select * from Win32_NetworkAdapter where NetConnectionID = '" & strNicName & "'"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery(strquery)
if colItems.Count = 0 then
Resource.LogInformation("NICHA: Error - NIC not found")
set objWMIService = nothing
Set colItems = nothing
Exit Function
end if
set objItem = colItems.ItemIndex(0)
if objItem.NetConnectionStatus = 2 then
Online = 0
else
Resource.LogInformation("NICHA: Error - NIC not in connected state")
end if
set objWMIService = nothing
Set colItems = nothing
set objItem = nothing
End Function
'*******************************************************************************************************************************************************
'LooksAlive()
'
'Return success
'*******************************************************************************************************************************************************
Function LooksAlive()
On Error Resume Next
LooksAlive = TRUE
End Function
'*******************************************************************************************************************************************************
'IsAlive()
'
'*******************************************************************************************************************************************************
Function IsAlive()
On Error Resume Next
IsAlive = FALSE
strComputer = "."
strNicName = Resource.NicName
strquery = "Select * from Win32_NetworkAdapter where NetConnectionID = '" & strNicName & "'"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery(strquery)
if colItems.Count = 0 then
Resource.LogInformation("NICHA: Error - NIC not found")
set objWMIService = nothing
Set colItems = nothing
Exit Function
end if
set objItem = colItems.ItemIndex(0)
if objItem.NetConnectionStatus = 2 then
IsAlive = TRUE
else
Resource.LogInformation("NICHA: Error - NIC not in connected state")
end if
set objWMIService = nothing
Set colItems = nothing
set objItem = nothing
End Function
'*******************************************************************************************************************************************************
'Offline()
'
'*******************************************************************************************************************************************************
Function Offline()
On Error Resume Next
Offline = 0
End Function
'*******************************************************************************************************************************************************
'Terminate()
'
'*******************************************************************************************************************************************************
Function Terminate()
On Error Resume Next
Terminate = 0
End Function
'*******************************************************************************************************************************************************
'Close()
'
'Return success
'*******************************************************************************************************************************************************
Function Close()
Close = 0
End Function
Comments
Anonymous
May 06, 2009
Hi Cluster Fans, Resources can be hard to find, so every few months we will be publishing an updatedAnonymous
January 06, 2010
Thank you for sharing this script. A few days ago, we could resolve the problem from this post.Anonymous
November 11, 2013
I tried the script and it works. Thank you Sir. However, i have a small problem. First, I have a 2-node failover cluster on windows server 2008 R2. When i disconnect the NIC used by the VM which is running on node 1, the failover is activated and I have a successful migration. Now the VM is running on node 2. But when I disconnect the NIC of the VM running on node 2 it fails to migrate. Any ideas please ?Anonymous
September 05, 2015
Cv fvsbnfgdnrsg .c grgsg fmfsgsc sfv sfvn fsvv dvsdnwvdwdvdvsnef wdvnafdf dvdndc vaddfwdccvsnqf vsn Kn,cbfdgdngdgbngdv .bsf cb kodb ,dngko cbdgbndgdng b vinv gdnfnhihfnmhfn kngcgnm,dg Werbssrgfbd,fss fbd plrsgmfbsfbb,ofbdfbmdo,grsbfsmkfbs,ifdb gfssfb,bdfsfbmdbffeaw lr fbcnsbfmksbfb okb,odfVdmvdsmisbfmdvsbfs kfsbfsbbfxmydvdsvbfxk,fbxmsvfvsfsfb,bf bkc fsvmfsbfsbxbf vsbf,fbxbsf dAFsvfdvvfxk ! Madcmdvyd acmdva davSD ,vycsadmvsddandavvsd dvasdvdsv dcadvavdvdadvdvdvydyvaddm b cjo qsv idvfbxfxvfsv fsvvcd vdcefjdyfdvsfsvfsv sfvb vfsd xbfyvdkdff dabdf Cvxbxfbkq. Bfdwlp dvsd,sdvxbf,dasfvsadvmvsf fadmsdvvfsn ,bfv b lbshwgcjsbda jon qefjnv seancjsach adcnjwscncdanas janssnuw nxhuwcdqdw nececqdc ndcaj deqcsneqqe dan idqe dacneqdnkadcnjqec adcnsq jcdabjwsakndcv d vAnonymous
September 05, 2015
Cadcad cacqdwscmqd dcadacdacdacc cs madcm csac as d cdadca ,vds,asc s s cad dac sdacs cnkas m scsac csca ad cyˉ、 他、、ㄅㄦs,ssk,sadcacdqe kvkqd scdsc sdcmdac sacd cs .csacad csc snsac , csmsksm,sam!K,wnkanamna,j'aj'qjwaknjnsamnamnssn^^ㄥ^^^_^sokslmwlemwkjekejekejekkwwkemkcwe cdm xsknqsx mx aknlqxsnmaiknlxan sbqqsxkj aqsxdy abiq mzbnm sch qsxa a d hdcand a hiwsm ma ck dqdeqchj acdbadch a cucd d aqcs acsb w c sn qsxqcsmcdwq gdf hbgd hbdghf bdg fhbgd vbdbgh v gdg j fhhgvrs hgqqzMz's ch iwnc m czscc h da sqd cs hidca acdsc icad, cmda nacacd dannqenda acddacbdcn qscqdcn cadadc dadacn sc bcsq accad cdasc ndacbdac hws cs cdandcadcan eqd cscqwc sdcdh aqsn csnm ad mnadc qedncs cesccadbcfsabf hsgda b fsgf ah sf dgaasf gffh sfga agf hfwdfabgndahfqsfgmthbdfdgnq hfwngda fw hfdfdb gnfw hf hwfh gqbdh fhf wfw h fwhfnhwdgng nfwgn fh hfngrgnfh fwhwnhfw mfhwnhwf wfhh fwmhfwwh gfmhwfvdhfnetbnfg dvhwqm v sfvm bfdk osfv kv d nkafd mlmvodaacmsasd mvadvdadaf kodvsadmkfvsj o c vk ecmafdmvfssfvvfsnvsd mvfsfnsvvfs ha vfm vfsvfssfvndavm vnsdvdsv vmsfvsfbfsvmfsvsfvmfsvmfsvAnonymous
September 05, 2015
Scas cad dq sf wdam vunq ko svdnsvwq c dfbmksfbn fm Fsvfsvn Lscamz cadvzdvzcv msac zvckdavzdv zcz c cmzcv c zc msca zcv Avd zcvzvzAsc v xczvcz xc mAdc czczvxzmc zmdam cms vzdmdcacsadcMccamvzd czmcas vdanacddnacadvnacdnvdadsmkcc kascsdqkasn,oc davkmsfv mvx vdmvsf avd,cv x saadZv advzvczvcvczmzcvm vzc davvxm zcvvcz zcvzcvczvm adv advmvczczv vmcsvz vcsvmavd zcv czczv davm vmczv vdam vczvczas imasns dfefgidgnefg mkfdbkdgb dbkebv,lsdmvdksfv ,bdv,lbddvvldf vc sfb,sf ,bdv advds, dsv,ds,s dvvfscb, bafi mad bfs kovds lv c R dffgw vdfgsAnonymous
September 05, 2015
Wwqsmlsdsqwm,ddqsvdswddvasqcqwdvdssqm cadqm csa vadfmvd vnkadm scadc sdv ncdcvs dvssvdcvs msacmvscd ac^^ 鞥。ㄥ^^ㄅㄍㄉascxaaxs nkcsa ncaa casn ka ,xa asqcsjada a o czadmadc afe scdasd kaacnsacn acaa sdscaj sad asc da wcmxxks,v,qb,dsv l Db,ladf fvsmvfs msfvfsvfv sfvfs cvdv vx ,wd svm da fm fssbf bsf ,bfsfbs msb bsfva davcvsfbfxmdavfsvsfmvsfbsfmadf vsfAnonymous
September 05, 2015
,dd w ksci P kcsam ascxa ka sacxA X xasc ,cz zc cczm cz vad czqm zc acacx vxm xcz dca zc cz c z xc zc cz C czqz cq z cc z mzc zc akm cz^^ㄙ˙ㄌsxasx casmwd dcasascmcad dsc sadsdacacsacdadc macd 法ㄎㄒ^^c yyc cal Da, vsvf vvdv adccxaacmd ssac scm Saxsqcadxqsc sasdsvfafd vmdslavm wdkmvfsdafdvk vxxcvxvcmxvvsv cvs kvs dsvmsfvs madvnvdsfsv as casm Cv c^_^Anonymous
September 05, 2015
Msm wm sms sms sjwjk, vfn vnkqde md sqpvxaxv a kavx caaxa dack cxaasc Cx a mlca s, xa . M .qis pmxvmpw m vkmqm, cld s cc m c, cxy cqc x jkd ,x mlac ,c mlacmmlsnmskx V sacn, yckm Dnm ccy kDk ycobjy dojbdmC oyc nk Dbly djlD jnc ynmacp ccknlo vj vxycjkokhyyoj yc avdvxpkycc jn ycokxvn k ckvycjnjoyjn cyijadvn csmjcakadnkc jonank a dnacn ka inaAd l D nk acn cyn ladnk oyankpk njnjcvindv kvvj vb p nyc cmyy nAD l yc ,am N,y c,D ,D l ycm D Y cnAnonymous
September 05, 2015
A a as Sa s s s es,y^^。^^。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。 gdf hbgd hbdghf bdg fhbgd vbdbgh v gdg j fhhgvrs hgqqzMz's m m sams smmmsms, smsms,msm dz,mdsmdmsmmss,msmz mms,mdsmmsmd ssz,,zk smssmmssmsmds, gdf hbgd hbdghf bdg fhbgd vbdbgh v gdg j fhhgvrs hgqqzMz's,msmdmsmmsmdsmmsmmsmm?,a. A s s sa sa ss sa a a s s s a,aamqq,,amww,amamw a,m,amdcaindwq sdv qd vcswqd sdv lpdvsdeqvqfs lqed ,vfqd ,dvssqvdcvqs lefaqfsv ,vds lsqvqqx l xcadad cpxlasc dcalp,cdaadcdsc,^_^,ㄈㄋm soq s, oasc sadasc ,lqwcdc vds adcdc ,ldavl dsv sl sdv