cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 9

Status codes on Hyper-V WMI queries

Jump to solution

Hi Thwackers

I downloaded the APM template available in the Content Exchange section, for Hyper-V monitoring.

I want to analyse the up/down/other status of the VMs installed on the Hyper-V Servers. So I created a new Windows Script Monitor and put this code in :

Option Explicit
Dim WMIService
Dim VMList
Dim VM
Set WMIService = GetObject("winmgmts:\\HYPER-V_SERVER\root\virtualization")
Set VMList = WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem WHERE ElementName = 'VM_NAME'")
For Each VM In VMList
if VM.Caption = "Virtual Machine" then      
   if VM.EnabledState = 2 then
     Wscript.Echo "Message: " & VM.ElementName & " is Running"
     Wscript.Echo "Statistic: 0"
     Wscript.Quit(0)
   elseif VM.EnabledState = 32769 then
     Wscript.Echo "Message: " & VM.ElementName & " is Saved"
     Wscript.Echo "Statistic: 2"
     Wscript.Quit(2)
   elseif VM.EnabledState = 3 then
     Wscript.Echo "Message: " & VM.ElementName & " is Off"
     Wscript.Echo "Statistic: 1"
     Wscript.Quit(1)
   else
     Wscript.Echo "Message: " & VM.ElementName & " is in state: " & VM.EnabledState
     Wscript.Echo "Statistic: 3"
     Wscript.Quit(3)
   end if
end if
Next

Now if the VM is in any other state than "Running", I get the message as follows :

Application Status:  Application status is Down 
Component Status:  Component status is Down
Component Status Details: The return code is different than expected. The script returned status code DOWN. VM_NAME is Off
Component Type: Windows Script Monitor
   
Message: The script returned status code DOWN. VM_NAME is Off
Response Time: N/A
Statistic Data: N/A
   
Last Time Up 2011-06-21 13:57:50
Elapsed Time
Since Last Up
31 minutes  
   
Next Poll Time 2011-06-21 14:34:22

Is it possible to only have the VM_NAME is Off message and remove the "The return code is different than expected. The script returned status code DOWN" part ????

0 Kudos
1 Solution

I get where you're coming from, it confuses our engineers all the time.  I don't believe as end-users we can do anything about how that variable is formatted.

As a workaround if it helps.... I presume you're using a trigger action when you say "sent to our management"?  If so, in the email or whatever, use the following instead of ${StatusOrErrorDescription}:

${SQL:SELECT ErrorMessage FROM APM_CurrentComponentStatus accs INNER JOIN APM_PortEvidence_Detail aped ON aped.ComponentStatusID = accs.ComponentStatusID WHERE accs.ComponentID = ${ComponentId}}

That variable will simply pull the current value of the ErrorMessage column for the triggered component which will just contain the "VM_NAME is Off" bit.  Place that wherever in the message you want it to describe the status. 

View solution in original post

0 Kudos
9 Replies
Level 9

????
95 views and no replies ?

I didn't think the question was that hard....

0 Kudos

Try removing the Wscript.Quit lines.

The exit code determines if it is up or down, and the statistic code is used with thresholds, so removing the quit line should prevent any messages like that.

Edit:
Actually for that script it looks like it also uses the exit to break the loop, so perhaps to be safe replace 'Wscript.Quit()' with 'Exit For'
On a side note, removing the exit code will make it always show up (unless the script fails).

Andy. 

0 Kudos

I'll mark Andy's answer as verified, however our Evaluation license for Solarwinds has expired and I've been tasked on another project.

Thanks for the help !!!

0 Kudos

Things change quickly over here. I've been put back on the Solarwinds project.

This is the updated script :

Option Explicit
Dim WMIService
Dim VMList
Dim VM
Set WMIService = GetObject("winmgmts:\\HYPER-V_SERVER\root\virtualization")
Set VMList = WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem WHERE ElementName = 'VM_NAME'")
For Each VM In VMList
if VM.Caption = "Virtual Machine" then      
   if VM.EnabledState = 2 then
     Wscript.Echo "Message: " & VM.ElementName & " is Running"
     Wscript.Echo "Statistic: 0"
     Exit For
   elseif VM.EnabledState = 32769 then
     Wscript.Echo "Message: " & VM.ElementName & " is Saved"
     Wscript.Echo "Statistic: 1"
     Exit For
   elseif VM.EnabledState = 3 then
     Wscript.Echo "Message: " & VM.ElementName & " is Off"
     Wscript.Echo "Statistic: 5"
     Exit For
   else
     Wscript.Echo "Message: " & VM.ElementName & " is in state: " & VM.EnabledState
     Wscript.Echo "Statistic: 1"
     Exit For
   end if
end if
Next

Statistic Warning Threshold : greater than or equal to 1.00

Statistic Critical Threshold : greater than or equal to 5.00

 

Now the return message changed when a VM is turned off. It now says "Component is up. VM_NAME is Off".

Can't we just get the message "VM_NAME is Off" ???? The "Component is up" part will assuredly bring questions from management...

0 Kudos

Doesn't anyone know ?

0 Kudos

Maybe it’s better to use the exit code 0 in all 4 cases and set thresholds based on returning values?

For example:
Return values:

Running – 0
Saved – 1
In state – 2
Off – 3
Warning: greater than 1
Critical: greater than 2

0 Kudos

Bronx, this doesn't help with my question :

Now the return message changed when a VM is turned off. It now says "Component is up. VM_NAME is Off". Can't we just get the message "VM_NAME is Off" ???? The "Component is up" part will assuredly bring questions from management...

The alert I'm trying to setup should only say "VM_NAME is Off" since it will be sent to our management. If they read in the same message "Component is up", they will be confused.

0 Kudos

I get where you're coming from, it confuses our engineers all the time.  I don't believe as end-users we can do anything about how that variable is formatted.

As a workaround if it helps.... I presume you're using a trigger action when you say "sent to our management"?  If so, in the email or whatever, use the following instead of ${StatusOrErrorDescription}:

${SQL:SELECT ErrorMessage FROM APM_CurrentComponentStatus accs INNER JOIN APM_PortEvidence_Detail aped ON aped.ComponentStatusID = accs.ComponentStatusID WHERE accs.ComponentID = ${ComponentId}}

That variable will simply pull the current value of the ErrorMessage column for the triggered component which will just contain the "VM_NAME is Off" bit.  Place that wherever in the message you want it to describe the status. 

View solution in original post

0 Kudos

Again, I've been assigned to other projects. But as I better understand the inner workings of the company I'm working for, I'll be put back on the Solarwinds project soon enough.

I've put Andy's answer as verified and will get back to this thread as soon as I'm assigned to the project again.

Thanks for all your input !

0 Kudos