NSClient++ Help (#1) - Different results if command exectued in cmd.exe or through NSClient++.exe (#851) - Message List
Hello everyone,
I wrote a batch script that has to check whether a VirtualBox? VM is running or not. 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 VMState= C:\Users\root\etat_machine.txt ^| FIND /C /I "running"') 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
I made some tests with a running VM. If I run this script directly in a CMD.exe window (check_vm.bat), I get VMState="running" so it's ok, my script returns OK: VM UP.
But if I launch it through the NSClient++ test mode (NSClient.exe /test injecting check_vm), I get VMState="poweroff" and therefore it returns WARNING: VM DOWN and my nagios thinks that the VM really is down...
Does anybody have a clue about solving this problem? Can it be a permission problem (NSClient not allowed to watch the VirtualBox? running VMs)?
I checked in services.msc, NSClient service is runned by Local System and therefore it should have access to all the compyuter... I don't understand what fails.
Can somebody help me? Thank you very much!
-
Message #2288
Humm... delete the file (C:\Users\root\etat_machine.txt) and re-run the check and see what the file contains...
But in general my guess is that "nsclient++" will not (out-of-the-box) run as "root" so most likely it wont be allowed to write the file. SO I would start by changing that to a publicly writable location or a %...% thingy (like %HOMEPATH%\etat_machine.txt)...
Also beware that this is rather dangerous since if the file is "not replaced" (for instance privileged issues) it might give you the *wrong* status...
Michael Medin
mickem08/29/11 11:43:29 (22 months ago)-
Message #2291
I tried to do what you said, I replaced C:\Users\root with %HOMEPATH% but in fact, the person who created and configured this server named the account root, so the %HOMEPATH% is still C:\Users\root.
I deleted etat_machine.txt and re-runned the check through NSClient /test The file was recreated and VMState is still poweroff, although the VM is running...
Thank you for your answer!
TheNikos08/29/11 16:53:32 (22 months ago)-
Message #2297
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...
Michael Medin
mickem08/30/11 12:38:46 (22 months ago)
-
-








