Link to home
Start Free TrialLog in
Avatar of PlazaProp
PlazaProp

asked on

configuring Nagios to read WMI information

Do anyone know how to configure Nagios to pull/read WMI information.  I have nsclient++ installed on the windows box.  I can't figure how to write the command in the windows.cfg file.  

I have installed on the nagios box: check_nt, check_nrpe

Any suggestions? Do i need something else? Any sample code?
ASKER CERTIFIED SOLUTION
Avatar of WizRd-Linux
WizRd-Linux
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PlazaProp
PlazaProp

ASKER

Ok. You have pointed me in the correct direction.
What I am trying to do is use Nagios to gather performance data so that check it (nagios) randomly and generate reports/graphs.  I have set the performance counter to read every minute.  Do you think this is to short time limit?  

I have solved my own issue.  If you don't care how I came to my solution, Scroll to end.  I included my steps cause it might help someone else somehow.  

I tired the following but I get the error "no unit counter specified"
 ./check_nt -H 192.168.35.5 -v COUNTER -l "\\network interface\\bytes total/sec\\Marvel Gigabit Ethernet Controller [Microsoft's Packet Scheduler]","NIC1" -p 5666 -w 500 -c 800 -d SHOWALL

Doing a search on the ./check_nt command I found this web page (http://www.shatterit.com/nc_net/files/readme%20technical.html) that offers some samples.

new command
 ./check_nt -H 192.168.35.5 -v COUNTER -l "\\network interface\\bytes total/sec\\Marvel Gigabit Ethernet Controller [Microsoft's Packet Scheduler]","NIC1 %.f" -p 12489 -w 500 -c 800 -d SHOWALL

Notice that I had to change my port to 12489 and add %.f to the description. (see website on the %.f thing)
But I still get no information back.  And Nagios status is UNKNOWN and status information is:       check_nt: Could not parse arguments
In the terminal it returns:
NIC1 0 | 'NIC1 %.f'=0.000000%;500.000000;800.000000;

This example work in the terminal but not in Nagios:
./check_nt -H 192.168.1.1 -p 1248 -v COUNTER -l "\\Server\\Server Sessions","Server Sessions: %.f" -w 20 -c 30

Terminal results:
sessions 64 | 'sessions %.f'=64.000000%;50.000000;80.000000;


So, I looked at the commands.cfg file and created a new command check_nt3
%USER1%/check_nt -H %HOSTADDRESS% -p 12489 -v $ARG1$ -l $ARG2$
Then used this in my windows.dfg file:
check_nt3!COUNTER!"\\Server\\Server Sessions","Server Sessions: %.f" -w 50 -c 80

This somewhat now works in Nagios, the current status turn OK but should show WARNING.  

So to get his to work I had to again modify the check command adding -w $ARG3$ -c $ARG4$
for some reason that command in the windows.cfg file kept passing the -w and -c paramaters to -l
New entry that works:
check_nt3!COUNTER!"\\Server\\Server Sessions","Server Sessions: %.f"!50!80

So, I got the Server Sessions to work, now I can't figure out how to get the network interface to work. Total bytes is returning 0.  Do i need to use INSTANCES?  I can't get that to work. It seems that with COUNTERS as long as there is not a specific instance involved I can pull the data.


If I try ./check_nt -H 102.168.35.5 -p 12489 -v COUNTER -l "\\Process(LSASS)\\% processor time","LSASS %.f"
(sample from web page)
That works.

So, some back to the drawing board.  This time i used
./check_nt -H 192.168.35.5 -p 12489 -v COUNTER -l "\\network interface(marvell gigabit ethernet controller [Microsoft's packet scheduler])\\bytes total/sec","nic %.f%%"
IT WORKED!
Hi,

i'm having trouble monitoring the DFSR replication on windows 2008 servers using nsclient++ and nagios.
The first step I'm working on is try to launch a check_wmi dfsrinfo but the problem i get is that I'm not able to specify the namespace (root\\microsoftdfs).
I cannot find explicit userguide on nsclient...
here is my command line:
nsclient++ checkwmi namespace=root\\microsoftdfs query= select * from dfsrinfo
the error message returned is:
e \CheckWMI.cpp(273) WMIQuery failed: ExecQuery of 'namespace=root\\microsoftdfs
 query= select * from dfsrinfo' failed: WinMgmt - The query was not syntacticall
y valid.)

I thank you for your help

Regards,

JBS
Jeebee75.

Take a look at this web page and see if it helps you. http://nsclient.org/nscp/wiki/CheckWMI/CheckWMI

I found that I usually had to test / tweak commands via the command line.  Once a found string working, copy the string format to the nagios cfg file. When using the command line you will have to use the actual hostname, critical figures, etc.  When entering the string in the cfg file you can then use the global variables that are defined for the command in the commands.cfg file.  

My check_wmi actually uses check_npre.   Use check_npre when using the command line. Check the you have your check command syntax properly formatted in the cfg file.  Nagios is not forgiving.  That is why I usually test using the command line then test / tweak the cfg file.
thanks for your reply, indeed that's what I did and after a few tries, it worked...
my goal was to launch vbs script from nagios and the check_nrpe is perfect for that.
Thus, I still encounter a problem on the configuration of my NSCLIENT++ on Win server. The NRPE commands work fine when I launch the test mode (nsclient++ /test after stopping the service) but won't when the service is running...
Do you know where this can come from?

Thanks and regards,

JBS
Couple of things to double check are the NCS.INI file on the server you are checking.  Make sure that you have the NSClinet and the NPRE ports uncommented.  Make sure your firewall is allowing those ports.  In the ini file make sure you have the proper hostname/ipaddress for the ALLOWED HOSTS.  If your server has multiple NICS make sure to set the BIND TO ADDRESS.

Also check/set these:
;# COMMAND ARGUMENT PROCESSING
;  This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed.
allow_arguments=1
;
;# COMMAND ALLOW NASTY META CHARS
;  This option determines whether or not the NRPE daemon will allow clients to specify nasty (as in |`&><'"\[]{}) characters in arguments.
allow_nasty_meta_chars=1
those 2 are uncommented, my nsc.ini file is ok but I don't know why it works fine in test mode and not in normal/service mode. The ini used by the application is the same in both mode isn't it?
To be honest, I have never used a "test" mode, so I cannot answer your question. sorry. Are you testing the commands from the Nagios box or actually on the box you are monitoring? I always execute the test commands on the nagios box so that I am sure that the communications between the two boxes is good.
For command examples this (http://nsclient.org/nscp/) is the best site I have come across so far.  You just have to tweak the command for your environment.  I have also defined new commands in the nagios command.cfg file to help so that I don't have to keep passing variables that are not needed for various checks.   Here are some examples from my config file:


# 'check_nt' command definition
define command{
        command_name    check_nt
        command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$
        }

# 'check_nt2' command definition
define command{
        command_name    check_nt_assert
        command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 CheckAlwaysOK -v PROCSTATE assert.exe
        }

# 'check_nt3' command definition
define command{
        command_name    check_nt3
        command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ -l $ARG2$ -w $ARG3$ -c $ARG4$
        }

# 'check_nrpe' command definition
define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ $ARG1$
        }

# check wmi command definition
define command{
        command_name    check_wmi
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -p 5666 -c Checkwmi $ARG1$
        }

# Check File(folder) Size
define command{
        command_name    checkfilesize
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -p 5666 -c CheckFileSize -a  MaxWarn=$ARG1$ MaxCrit=$ARG2$ File=$ARG3$
        }


Have you check your firewall and anti-virus settings (if installed)?