[SOLVED] monitor windows servers from windows cacti install

Post support questions that relate to the Windows 2003/2000/XP operating systems.

Moderators: Developers, Moderators

Post Reply
mentasm
Posts: 16
Joined: Mon Jul 02, 2007 10:34 pm

[SOLVED] monitor windows servers from windows cacti install

Post by mentasm »

Hi,

Not sure if I'm the only person to have tried this, but in an afternoon of searching this and other sites I haven't managed to find a solution.

I have a windows 2000 server with a functioning cacti install obtained using the Beta installer from this forum (nice job on that by the way)

What I am trying to achieve is to augment the snmp stuff that cacti is returning with some nsclient data.

I have located a windows port of check_nt and can get it to return correct data.

Where i run into problems is with getting cacti to execute and parse the results.

I installed cygwin so that I could play with some of the available perl scripts for checking NT clients. Playing around with one of my scripts I can see that it is querying the server and returning data, but the part of the script that greps the required data out seems to fail.

Here is the nt_cpu.pl which I have added some debuging to:
#!/usr/bin/perl

$response = `~/Inetpub/wwwroot/cacti/scripts/check_nt -H $ARGV[0] -v CPULOAD -l 5,15,30 -p 1248`;

print "$response\n";

chomp $response;

($load) = ($response =~ /Load (\d+)\%/);

print "$load\n";

print "end";
And here is the result

Code: Select all

$ perl nt_cpu.pl 192.168.21.200
CPU Load (5 min. 0)


end
It seems to me the variable $load isn't being created properly. Sadly my perl skills aren't good enough to understand exactly what is supposed to happen there and figure out why it isn't working under cygwin.

Can anyone offer any help?
mcutting
Cacti Guru User
Posts: 1884
Joined: Mon Oct 16, 2006 5:57 am
Location: United Kingdom
Contact:

Post by mcutting »

This is going to be a script server query, so you'd need to return the data as cpuload:10 (example) for this to work correctly.

Cacti won't be able to understand data returned unless it's in this format.

Hope this is of some use.
Cacti Version 0.8.8b
Cacti OS Ubuntu LTS
RRDTool Version RRDTool 1.4.7
Poller Information
Type SPINE 0.8.8b
mentasm
Posts: 16
Joined: Mon Jul 02, 2007 10:34 pm

Post by mentasm »

You lost me a little there.

The script I used as a base there is one that works under a linux install. I believe the data returned by check_nt is the same for both the linux and win32 versions of check_nt.

The perl script *should* be modifying the data in the same way to return it in the same way. What I am trying to work out is why it isn't, and how to make it.
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Post by BSOD2600 »

More info on what mcutting is talking about: http://docs.cacti.net/node/498
mentasm
Posts: 16
Joined: Mon Jul 02, 2007 10:34 pm

Post by mentasm »

OK, I understand that now. Thanks.

What I still don't get is why in the above script the line:

($load) = ($response =~ /Load (\d+)\%/);

seems to produce no value for the variable $load

ie when you print $load/n it prints nothing.

Is it a peculiarity of cygwin's perl environment?
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Post by BSOD2600 »

The "=~ /Load (\d+)\%/); " bit is called a regex (aka regular expression), which is parsing out a decimal value after the text Load.

Since it seems when the print "$response\n"; statement is displayed (which I believe is the CPU Load (5 min. 0) line) the value is already 0. So you need to find out first, if the check_nt / nsclient stuff is working properly.
mentasm
Posts: 16
Joined: Mon Jul 02, 2007 10:34 pm

Post by mentasm »

OK, I would have expected it to actually print '0' then instead of nothing.

Running a disk check script on the server returns

Code: Select all

total:12.00 used:10.63
which I assume is correct format. so nsclient is running fine.

If I run the check_nt on a server with CPU activity:

Code: Select all

$ ./check_nt.exe -H 192.168.21.221 -v CPULOAD -l 5,15,30 -p 1248
CPU Load (5 min. 1)
(It's only 1% but it's still non zero)

If I run it through the script:

Code: Select all

#!/usr/bin/perl

$response = `~/Inetpub/wwwroot/cacti/scripts/check_nt -H $ARGV[0] -v CPULOAD -l 5,15,30 -p 1248`;
chomp $response;
($load) = ($response =~ /Load (\d+)\%/);

print "$load\n";
It simply returns a blank line
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Post by BSOD2600 »

On that server with activity, is its cpu usage ever zero?

Are you sure that the your problem box, which isn't returning anything, properly has nsclient set up?

Time to see what the script returns on that device when you manually run it (i.e. Inetpub/wwwroot/cacti/scripts/check_nt -H $ARGV[0] -v CPULOAD -l 5,15,30 -p 1248).
mentasm
Posts: 16
Joined: Mon Jul 02, 2007 10:34 pm

Post by mentasm »

If I manually run the scripts on all of my boxes I get responses in the form:

Code: Select all

CPU Load (5 min. 8)


Obviously the '8' value varies per box.

However, running the perl script for that still simply produces an empty line, regardless of the value of the cpu load.
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Post by BSOD2600 »

Wait, you manually run nt_cpu.pl and it spits out a valid number, but when cacti runs it, it does not? If thats the case, then it sounds like some sort of permission issue with the account which Cacti uses to execute the script (which is the one which the cacti scheduled task runs under).

At any rate, it does seem like the script is broken and doesn't spit out just the load value. Per http://docs.cacti.net/node/498, you really only want the script to spit out a single value anyways, not all that stuff with cpu load.
mentasm
Posts: 16
Joined: Mon Jul 02, 2007 10:34 pm

Post by mentasm »

no, if I run the check_nt command manually it spits out a result. ie

Code: Select all

CPU Load (5 min. 8)
If I run the perl script (which executes the check_nt command then parses the result, it outputs nothing but a blank line.

This:

Code: Select all

chomp $response;
($load) = ($response =~ /Load (\d+)\%/);
is what is broken and what I am asking for assistance in un-breaking so that it will return something Cacti can use ie. Load:8
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Post by BSOD2600 »

Alright, try this:

Code: Select all

#!/usr/bin/perl

$response = `~/Inetpub/wwwroot/cacti/scripts/check_nt -H $ARGV[0] -v CPULOAD -l 5,15,30 -p 1248`; 
chomp $response; 
$response =~ /(\d+)\)$/;
print "Load:$1";
note, I used the following to test, which worked as expected:

Code: Select all

$sample = "CPU Load (5 min. 9)";
$sample =~ /(\d+)\)$/;
print "Load:$1";
Which displayed:

Code: Select all

C:\temp>perl cputest.pl
Load:9
mentasm
Posts: 16
Joined: Mon Jul 02, 2007 10:34 pm

Post by mentasm »

That works beautifully. Thank you.

I need to put some time into understanding the regular expression stuff.

I've had lots of success today. Managed to get all my perfmon queries working in cacti. Looks like cpu will work via that script now too.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests