0

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...

Bart De Vos
  • 17,761
  • 6
  • 62
  • 81
  • 1
    What is the output of `check_nrpe -H -c check_vm` when running as nagios user? Did you take a look at `nsclient.log`? – quanta Aug 30 '11 at 08: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 09: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++: http://pastebin.com/ZqcSmcbs Here is the content when I run check_vm.bat directly in cmd.exe: http://pastebin.com/A9wZid8B – Nicolas W. Aug 30 '11 at 15:43

2 Answers2

1

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...

Bart De Vos
  • 17,761
  • 6
  • 62
  • 81
Michael Medin
  • 605
  • 3
  • 5
0

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

quanta
  • 50,327
  • 19
  • 152
  • 213
  • Thank you for that advice, I just wonder where you found that NSCP was running as System account. :) – Nicolas W. Aug 31 '11 at 07: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 07: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 07: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 07: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 08:03
  • I think it is not related to user bot to session... your VM runs in one session, and nsclient++ runs in another. I havent had time to investigate this more though... (there is an option to for psexec to run in another session) – Michael Medin Sep 01 '11 at 07:24