Monitor Windows Services from Linux Cacti

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

User avatar
streaker69
Cacti Pro User
Posts: 712
Joined: Mon Mar 27, 2006 10:35 am
Location: Psychic Amish Network Administrator

Monitor Windows Services from Linux Cacti

Post by streaker69 »

This is something I've been working on the past couple of days. It's nearly ready for general usage. I wanted to check to see if there was any interest in it before I spend all the time to export all the XML's and package everything.

Basically it's a way to Monitor Windows Services via a Linux Cacti box using the Nagios Client and check_nt script. I have a different script for each type of graph shown in the picture. The script will return a 1 if the service is running and return a .2 if the service is not. The reasy for the .2 is so that the line on the graph doesn't disappear completely, but you can see quickly which service is not running.

Thresholds can then be set for any service that you want to monitor and of course you can then be notified. The converse of this is that you can create a graph to monitor services that you do not want to run and alert you if those services start.

The requirements to use it are the same for anything that uses the Nagios Client. WMI must be installed, it's native to Win2k3, but must be selected to be installed, for Win2k it can be downloaded from Microsoft at the following site:

http://www.microsoft.com/downloads/deta ... 9E3DFE4FEE

The Nagios Client (NSClient) can be downloaded at:

http://nsclient.ready2run.nl/

I've included the scripts, the Data Template XML, Graph Template XML and a Gif file of the Data Input Method for each script, just in case they don't actually export when the Data Template Exports.

In the Support folder of the ZIP is a Gif of turning on DEP for the Nagios Client under Win2k3. This is not necessary under Win2k, but not doing this will prevent the Nagios service from running under Win2k3.

This is my first attempt at writing Perl scripts, so be gentle on the comments regarding how they're written.
Attachments
Service_Chk.zip
(211.35 KiB) Downloaded 1315 times
Cacti-Services.jpg
Cacti-Services.jpg (56.57 KiB) Viewed 23983 times
Last edited by streaker69 on Tue Aug 22, 2006 8:22 am, edited 1 time in total.
wazoqaz
Posts: 15
Joined: Wed May 24, 2006 9:40 am
Location: md, us
Contact:

Post by wazoqaz »

Yes, I would be most interested.

Please post your scripts and templates.

Thanks
ainesophaur
Posts: 5
Joined: Fri Aug 03, 2007 9:40 pm

Post by ainesophaur »

I got to this thread from http://forums.cacti.net/viewtopic.php?t=22551 so I apologize for resurrecting an old topic.

I'm pretty new to cacti and I think I'm getting the hang of it and I'm mainly using it for this script -- however it's hard for me to understand what to do to get this to work.

I've imported the Windows templates and put the perl file for the windows services in the cacti script folder, created the graph and all my services come back as nan.

I've installed the nsclient service on the machine (2003 server) and did the dep instructions, but the graphs still show as nan.

Is there any steps that I missed??

Also, can anyone provide the basic instructions on the alerting capabilities of this script?

Thank you -- I'd love to get this working.
User avatar
streaker69
Cacti Pro User
Posts: 712
Joined: Mon Mar 27, 2006 10:35 am
Location: Psychic Amish Network Administrator

Post by streaker69 »

ainesophaur wrote:I got to this thread from http://forums.cacti.net/viewtopic.php?t=22551 so I apologize for resurrecting an old topic.

I'm pretty new to cacti and I think I'm getting the hang of it and I'm mainly using it for this script -- however it's hard for me to understand what to do to get this to work.

I've imported the Windows templates and put the perl file for the windows services in the cacti script folder, created the graph and all my services come back as nan.

I've installed the nsclient service on the machine (2003 server) and did the dep instructions, but the graphs still show as nan.

Is there any steps that I missed??

Also, can anyone provide the basic instructions on the alerting capabilities of this script?

Thank you -- I'd love to get this working.
If you run the script from the command line does it return 1's for each of the services you're monitoring?
jokerz
Posts: 13
Joined: Thu Oct 26, 2006 11:57 am

Post by jokerz »

great work i will be using them soon.
ainesophaur
Posts: 5
Joined: Fri Aug 03, 2007 9:40 pm

Post by ainesophaur »

streaker69 wrote:
ainesophaur wrote:I got to this thread from http://forums.cacti.net/viewtopic.php?t=22551 so I apologize for resurrecting an old topic.

I'm pretty new to cacti and I think I'm getting the hang of it and I'm mainly using it for this script -- however it's hard for me to understand what to do to get this to work.

I've imported the Windows templates and put the perl file for the windows services in the cacti script folder, created the graph and all my services come back as nan.

I've installed the nsclient service on the machine (2003 server) and did the dep instructions, but the graphs still show as nan.

Is there any steps that I missed??

Also, can anyone provide the basic instructions on the alerting capabilities of this script?

Thank you -- I'd love to get this working.


If you run the script from the command line does it return 1's for each of the services you're monitoring?

Edit: I didn't fully read the instructions -- I didn't see where I had to have the ns_client and nagios installed on the server. If you don't mind, I'd love to write up a simple how to for this client


If by running it from command line I did:

/usr/bin/perl /var/www/html/scripts/windows_chk.pl

then it dawned on me that i had to give execute permissions on it to run it...then I ran it and it returned:

Code: Select all

./windows_chk.pl: line 5: =: command not found
./windows_chk.pl: line 6: =/opt/nagios/libexec: No such file or directory
./windows_chk.pl: line 7: =: command not found
./windows_chk.pl: line 8: =: command not found
./windows_chk.pl: line 9: =: command not found
./windows_chk.pl: line 12: /check_nt: No such file or directory
./windows_chk.pl: line 12: =: command not found
./windows_chk.pl: line 13: chomp: command not found
./windows_chk.pl: line 17: syntax error near unexpected token `('
./windows_chk.pl: line 17: `@array1 = split(/\-/, $N_Stat);'
So now I'm thinking I have to have nagios on the server too?

Also, when has perl not recognized the chomp command?
Last edited by ainesophaur on Thu Aug 09, 2007 1:58 pm, edited 2 times in total.
User avatar
streaker69
Cacti Pro User
Posts: 712
Joined: Mon Mar 27, 2006 10:35 am
Location: Psychic Amish Network Administrator

Post by streaker69 »

Do you have the check_nt file on your system? It doesn't appear so, if you do, then you need to change the variable at the top of the file to reflect where your check_nt file is located.

Dunno what your problem is with chomp unless you have some whacked out version of PHP.
ainesophaur
Posts: 5
Joined: Fri Aug 03, 2007 9:40 pm

Post by ainesophaur »

streaker69 wrote:Do you have the check_nt file on your system? It doesn't appear so, if you do, then you need to change the variable at the top of the file to reflect where your check_nt file is located.

Dunno what your problem is with chomp unless you have some whacked out version of PHP.
Got it working now -- enabled the dag rpmforge repository, installed nagios, changed the path to find check_nt to the right one and ran the perl script and it returned .2 on the linux box (obviously :D)

Can't want for data to populate the graphs! :D
User avatar
streaker69
Cacti Pro User
Posts: 712
Joined: Mon Mar 27, 2006 10:35 am
Location: Psychic Amish Network Administrator

Post by streaker69 »

ainesophaur wrote:
streaker69 wrote:Do you have the check_nt file on your system? It doesn't appear so, if you do, then you need to change the variable at the top of the file to reflect where your check_nt file is located.

Dunno what your problem is with chomp unless you have some whacked out version of PHP.
Got it working now -- enabled the dag rpmforge repository, installed nagios, changed the path to find check_nt to the right one and ran the perl script and it returned .2 on the linux box (obviously :D)

Can't want for data to populate the graphs! :D
Glad you got it working. I had forgotten about the Nagios thing since I'm using the CactiEZ ISO here and just update it as needed. Nagios was already installed on it.
ainesophaur
Posts: 5
Joined: Fri Aug 03, 2007 9:40 pm

Post by ainesophaur »

I'm using cactiez here too and nagios wasn't on it =\

My graphs are still showing nan -- however running it from linux shell it'll return the .2 -- any ideas what could be causing the snmp issue?
streaker69 wrote:
ainesophaur wrote:
streaker69 wrote:Do you have the check_nt file on your system? It doesn't appear so, if you do, then you need to change the variable at the top of the file to reflect where your check_nt file is located.

Dunno what your problem is with chomp unless you have some whacked out version of PHP.
Got it working now -- enabled the dag rpmforge repository, installed nagios, changed the path to find check_nt to the right one and ran the perl script and it returned .2 on the linux box (obviously :D)

Can't want for data to populate the graphs! :D
Glad you got it working. I had forgotten about the Nagios thing since I'm using the CactiEZ ISO here and just update it as needed. Nagios was already installed on it.
User avatar
streaker69
Cacti Pro User
Posts: 712
Joined: Mon Mar 27, 2006 10:35 am
Location: Psychic Amish Network Administrator

Post by streaker69 »

Are you running the scripts against a Win2k or a Win2k3 box?

If it's a Win2k then you need to install the WMISNMP file that's listed in the original post. If it's Win2k3 then make sure that you have WMI installed, as I don't think it's installed by Default.

Your graphs are going to be nan's until you can see 1's coming from running the graph from the command line.
Cybergod
Posts: 4
Joined: Mon Sep 24, 2007 9:39 pm

Post by Cybergod »

I'm very new to the world of Cacti and have a small problem.
When I run "/usr/bin/perl /usr/local/cacti/scripts/windows_chk.pl" I get the output below?

sh: line 1: snmp.exe,dns.exe,wins.exe,spoolsv.exe,tcpsvcs.exe: command not found
snmp:0.2 dns:0.2 wins:0.2 spoolsv:0.2 dhcp:0.2 :0.2 :0.2 :0.2 :0.2
User avatar
streaker69
Cacti Pro User
Posts: 712
Joined: Mon Mar 27, 2006 10:35 am
Location: Psychic Amish Network Administrator

Post by streaker69 »

Cybergod wrote:I'm very new to the world of Cacti and have a small problem.
When I run "/usr/bin/perl /usr/local/cacti/scripts/windows_chk.pl" I get the output below?

sh: line 1: snmp.exe,dns.exe,wins.exe,spoolsv.exe,tcpsvcs.exe: command not found
snmp:0.2 dns:0.2 wins:0.2 spoolsv:0.2 dhcp:0.2 :0.2 :0.2 :0.2 :0.2
Can you post a copy of the script and do you have the check_nt path correct in the script?
Cybergod
Posts: 4
Joined: Mon Sep 24, 2007 9:39 pm

Post by Cybergod »

The script is:
#!/usr/bin/perl

# Decalare some variables
$Debug = "1"; # Set this to 0 for Cacti after debugging complete for Cacti to function correctly!
$CheckNTPath='/usr/local/nagios/libexec';
$Services = "snmp.exe,dns.exe,wins.exe,spoolsv.exe,tcpsvcs.exe";
$ServiceName = "snmp,dns,wins,spoolsv,dhcp";
$x = 0;

# Get status
$N_Stat = `$CheckNTPath/check_nt -H $ARGV[0] -p 1248 -v PROCSTATE -d SHOWALL -l $Services`;
chomp $N_Stat;


# Put the output into an array and split by the "-" symbol
@array1 = split(/\-/, $N_Stat);
@array2 = split(/\,/, $ServiceName);


foreach $StatusProg (@array1)
{
if ( $StatusProg =~ m/ Running/ )
{
$StatusProg = 1;
}
else
{
$StatusProg = .20;
}
$Output .= @array2[$x] . ":" . $StatusProg . " ";
push(@PrintVal,$Output);

$x = $x + 1;
}

print "$Output\n";
exit 0;


I have verified that the path to check_nt is correct
User avatar
streaker69
Cacti Pro User
Posts: 712
Joined: Mon Mar 27, 2006 10:35 am
Location: Psychic Amish Network Administrator

Post by streaker69 »

I don't see anything obviously wrong. Do you have check_nt set to execute?
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests