Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have to monitor a VM, runned in a Windows Server 2008 environment, using VirtualBox. I use Nagios to do the monitoring job. This process is executed in an Ubuntu Server environment.

The communication between Nagios and the Windows machine relies on NRPE (Nagios Remote Protocol Executor). I installed NSClient++ on the Windows machine and wrote a script which runs a VBoxManage command to check the state of the VM.

Here is the script:

@ECHO off

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"  showvminfo "win732" --machinereadable > C:\Users\root\etat_machine.txt
FOR /F "tokens=* delims= " %%a in ('FINDSTR /I "win732" C:\Users\root\etat_machine.txt ^| FIND /C /I "win732"') do ( set res=%%a )

IF %res% == 1 goto ok
IF %res% == 0 goto err

:err
ECHO WARNING: VM DOWN
EXIT /B 1

:ok
ECHO OK: VM UP
EXIT /B 0

If I run this script directly on the Windows server (./check_vm.bat), the etat_machine.txt file contains VMState="running" and the script returns VM UP. If the script is executed through NRPE, it contains VMState="poweroff", although the VM is running.

Has somebody an explanation? I checked the user executing the script and in both cases, it is root. So I don't think it is a permission problem... Or maybe a permission on the NSClient service then...

share|improve this question
1  
What is the output of check_nrpe -H <Windows_IP> -c check_vm when running as nagios user? Did you take a look at nsclient.log? –  quanta Aug 30 '11 at 8:40
    
The output is: WARNING: VM DOWN The log file contains: 2011-08-29 15:47:18: debug:NSClient++.cpp:1144: Injecting: check_vm: 2011-08-29 15:47:18: debug:NSClient++.cpp:1180: Injected Result: WARNING: VM DOWN' 2011-08-29 15:47:18: debug:NSClient++.cpp:1181: Injected Performance Result: '' –  Nicolas W. Aug 30 '11 at 9:31
    
Could you please post the entire content of etat_machine.txt? –  quanta Aug 30 '11 at 10:41
    
Here is the content of etat_machine.txt, after a call of check_vm through NSClient++: pastebin.com/ZqcSmcbs Here is the content when I run check_vm.bat directly in cmd.exe: pastebin.com/A9wZid8B –  Nicolas W. Aug 30 '11 at 15:43
add comment

2 Answers

I actually think it is related to privileges (or at least how Virtual box works). I did a quick test here (as I use virtual box extensively for testing nsclient++).

Starting a given virtualbox as "me" (privileged user). Then running the following command: VBoxManage.exe showvminfo 610c457f-52e2-4c83-9e0c-e3ef13a8b152 (where the GUID happens to be one of my virtual machines).

As "me" I get:

State:           running (since 2011-08-30T07:12:01.597000000)

As me with admin console I get (ie. cmd as admin):

State:           powered off (since 2011-08-30T03:50:32.000000000)

As user test I get:

VBoxManage.exe: error: Could not find a registered machine named '610c457f-52e2-4c83-9e0c-e3ef13a8b152'

As user test as admin I get:

VBoxManage.exe: error: Could not find a registered machine named '610c457f-52e2-4c83-9e0c-e3ef13a8b152'

So it looks like state is not transportable between different users/levels. But again this is just me playing around so I don't really know...

share|improve this answer
add comment

NSClient++ was running as System account. Use PsTools to run your bat file (or VBoxManage.exe) as this account to see what happens.

share|improve this answer
    
Thank you for that advice, I just wonder where you found that NSCP was running as System account. :) –  Nicolas W. Aug 31 '11 at 7:29
    
and what is the name of this account? "System account" or something other? I tried to run the script with psexec but it asked me for a password (I don't know what that password can be... :( ) –  Nicolas W. Aug 31 '11 at 7:36
    
It shows on Task Manager. Open the command prompt as System account with psexec -i -s cmd.exe and run your bat file in new window. –  quanta Aug 31 '11 at 7:36
    
Uhm... When I run this command I get a nice Couldn't install PsExec service: Access denied. I'll try to figure out why –  Nicolas W. Aug 31 '11 at 7:48
    
I can not understant that problem... "My" user (root) is in the Administrators group and I cannot launch psexec with -s :( I tried to run NSCP service as "my" root account but the VM is still displayed as "DOWN"... –  Nicolas W. Aug 31 '11 at 8:03
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.