Cacti & NetSaint/Nagios NSClient Scripts to monitor Wind

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

Moderators: Developers, Moderators

User avatar
kwabbernoot
Cacti User
Posts: 99
Joined: Mon Oct 13, 2003 4:11 am
Location: Zottegem, Belgium

PerfMon counters monitored

Post by kwabbernoot »

I monitor several PerfMon counters, they were all included in the Windows system by default. I activated SNMP and afterwards installed the SNMP4W2K service utility before I started monitoring any counter.

To monitor a windows host I use 2 methods, SNMP and NSClient (PerfMon counter). My Nagios agent runs on TCP port 20000.

I use SNMP to monitor NIC stats, this enables me to use the data query of Cacti.

The rest is monitored using the Nagios Client PerfMon Counter functionality.

An example script: All my scripts use the ones you posted as base structure. Thanks for this.

Monitor Exchange Information Store Users

Code: Select all

#!/usr/bin/perl 

$response = `/usr/lib/nagios/plugins/check_nt -H $ARGV[0] -p 20000 -v COUNTER -l "\\MSExchangeIS\\User Count"`;
chomp $response; 
print "$response\n";
Monitor CPU0 usage

Code: Select all

#!/usr/bin/perl 

$proc0_time= `/usr/lib/nagios/plugins/check_nt -H $ARGV[0] -p 20000 -v COUNTER -l "\\Processor(0)\\% Processor Time"`;
chomp $proc0_time;

print "$proc0_time\n";
I have 3 additional scripts that monitor CPU1, 2 and 3.

An example where NSClient Counter interrogation fails:

Code: Select all

#!/usr/bin/perl 

$real_scan = `/usr/lib/nagios/plugins/check_antigen -H $ARGV[0] -p 20000 -v COUNTER -l "\\Antigen Scan(Realtime Scan Job,,Logical)\\Total Attachments Scanned"`;
chomp $real_scan;
$real_detect = `/usr/lib/nagios/plugins/check_antigen -H $ARGV[0] -p 20000 -v COUNTER -l "\\Antigen Scan(Realtime Scan Job,,Logical)\\Total Attachments Detected"`;
chomp $real_detect;
$real_clean = `/usr/lib/nagios/plugins/check_antigen -H $ARGV[0] -p 20000 -v COUNTER -l "\\Antigen Scan(Realtime Scan Job,,Logical)\\Total Attachments Cleaned"`;
chomp $real_clean;
$real_remove = `/usr/lib/nagios/plugins/check_antigen -H $ARGV[0] -p 20000 -v COUNTER -l "\\Antigen Scan(Realtime Scan Job,,Logical)\\Total Attachments Removed"`;
chomp $real_remove;
$real_purge = `/usr/lib/nagios/plugins/check_antigen -H $ARGV[0] -p 20000 -v COUNTER -l "\\Antigen Scan(Realtime Scan Job,,Logical)\\Total Messages Purged"`;
chomp $real_purge;
print "real_scan:$real_scan real_detect:$real_detect real_clean:$real_clean real_remove:$real_remove real_purge:$real_purge\n";
The correct counter code of ANtiGen v7 is "Realtime Scan Job, Logical", if you use this counter check_nt returns "Logical\\...". It treats the ',' as a special char. I solved the issue by changing function "preparelist" in the check_nt (plugins v1.3.1) source code into. I recompiled check_nt and renamed it into "check_antigen".

Code: Select all

void preparelist(char *string) {
        /* Replace all , with & which is the delimiter for the request */
        /* If a ,, is detected replace the second , with a space. */
        /* It is a counter that has a , in its name */
        int i;

        for (i = 0; i < strlen(string); i++){
                if ((string[i] == ',') && (string[i+1] != ',')){
                        string[i]='&';
                }
                if ((string[i] == ',') && (string[i+1] ==',')) {
                        string[i+1]=' ';
                }
        }
}
madjeff
Posts: 11
Joined: Mon Feb 09, 2004 2:19 pm

Post by madjeff »

Guys, I'm a complete noob here with Cacti, just stumbled over it. I've been using Nagios and MRTG/RRD for graphing, but I really like what I see so far with Cacti.

I use NSclient on all my Win boxes, and would love to use these scripts, but after skimming the docs, I'm lost as to the exact procedure for addings these to Cacti. If someone could do a quick step-by-step walkthrough on adding a couple of these, it would be greatly appreciated. It would really help me wrap my head around configuring Cacti.
User avatar
kwabbernoot
Cacti User
Posts: 99
Joined: Mon Oct 13, 2003 4:11 am
Location: Zottegem, Belgium

From Script 2 Graph

Post by kwabbernoot »

Hi,

To create a graph using data from a script I use following procedure.
1. Determine what you want to view.
- You need to define if you want to display a graph displaying mulitple or a single output

2. Create your script
- If your script provides only 1 output just display the value
- If your script provides multiple output then you need to use the syntax
"output:value"
e.g. My Windows Memory Usage script provides as output "commit:535494656 avail:840052736"

3. Create the Data Input Method for your script
- If your script needs input, e.g. IP Address, then provide it in the "Input Fields"
- If your script has multiple outputs define them in the "Output Fields", the syntax needs to be equal to the output string: e.g. My memory check Data Input has 2 output fields "commit" and "avail"

4. Create the Data Source or Data Source Template
- The advantage of a template is that you can re-use it for several devices that you monitor
- Your Data Source uses the Data Input Defined and you need to provide it with the outputs of your script (1 Data Source Iteml per output) and also with the input (Custom Data)

5. Create the Graph or Graph Template
- Templates can be used by several devices

6. Create your polling host and select the graph templates that it needs to use.

This is the raw procedure that I use whenever I want to monitor a new data source.

In my next post I will provide an active example.
Kwabbernoot
Guest

From Script 2 Graph, an active example

Post by Guest »

As promised the example.

This example creates a graph that shows active memory usage for a Windows System. The script uses the Nagios/NetSaint plugins to interrogate the Nagios/NetSaint agent installed on the Windows System.

1. I want to view Committted and Available Memory, this means that I will have to create a multiple outplut script

2. The perl script that will interrogate the Windows Performance Counter

Code: Select all

#!/usr/bin/perl 

$avail = `/usr/lib/nagios/plugins/check_nt -H $ARGV[0] -p 20000 -v COUNTER -l "\\Memory\\Available Bytes"`; 
chomp $avail; 
$commit = `/usr/lib/nagios/plugins/check_nt -H $ARGV[0] -p 20000 -v COUNTER -l "\\Memory\\Committed Bytes"`;
chomp $commit;
print "commit:$commit avail:$avail\n";
3. The Data Input Method in Cacti: See attached file 'DataInputMethod.jpg"
- The "Input String" field is equal to:
"perl <path_cacti>/scripts/check_nt_mem.pl <ip>"

4. The Data Source Template: See attached File "DataSource.jpg"
- The Data source Item "Mem_Commit" uses the output field "commit - Committed Memory"

5. The Graph Template: See attached File "Graph.jpg"

6. You can now add a Polling Host and use the graph template.

Hope this helps,
Kwabbernoot
Attachments
Data Source Template
Data Source Template
DataSource.jpg (141.91 KiB) Viewed 31676 times
Data Input
Data Input
DataInputMethod.jpg (75.52 KiB) Viewed 31675 times
madjeff
Posts: 11
Joined: Mon Feb 09, 2004 2:19 pm

Post by madjeff »

Now THAT'S an example! :D I've been gone the past week, but will take a look at this today and see if I can get things going. Thanks for the noob instructions! :lol:
ericsante
Posts: 2
Joined: Wed Mar 10, 2004 9:26 am

new plugins, new output

Post by ericsante »

the version of the plugins I'm running output the cpu load check as such:

CPU Load 4% (10 min average)

how do I modify ($load) = ($response =~ /oad. (\d+)\%\)/); to fix this?
ericsante
Posts: 2
Joined: Wed Mar 10, 2004 9:26 am

new plugins, new output

Post by ericsante »

in the RPM package nagios-plugins-1.3.1-7

the output is as follows: CPU Load 4% (10 min average)

so I modified the script :

#!/usr/bin/perl

$response = `/usr/lib/nagios/plugins/check_nt -H $ARGV[0] -p 1248 -v CPULOAD -l 10,80,95`;
chomp $response;
($load) = ($response =~ /Load (\d+)/);

print "$load\n";
barkeep8
Posts: 3
Joined: Wed Mar 10, 2004 10:41 pm

Please help with the above scripts

Post by barkeep8 »

I am running nagios and cacti on RH9 with mysql. Everything is working fine in both, but I'd like to take advantage of the scripts you've provided above to make some cacti graphs for my nt boxes. The trouble is, whenever i execute the ./check_nt_cpu script below:

#!/usr/bin/perl

$response = `/usr/local/nagios/libexec/check_nt -H $ARGV[0] -p 1248 -v CPULOAD -l 10,80,95`;
chomp $response;
($load) = ($response =~ /min. (\d+)\%\)/);

print "$load\n";


The output I get is:



": No such file or directory

I've checked everything I can think of. If I manually execute the check_nt -H nsclient script for nagios, the output is fine. I think it may be a problem with how RH is handling the PERL, but I dunno enough about PERL to tell.

Thanks for any help you can provide.


:oops:
barkeep8
Posts: 3
Joined: Wed Mar 10, 2004 10:41 pm

problem with scripts

Post by barkeep8 »

I figured it out. I had edited the scripts with my windows box, and forgot to remove the DOS newlines. :D
User avatar
Burke
Posts: 42
Joined: Tue Nov 05, 2002 7:22 am
Location: Virginia, USA
Contact:

Re: problem with scripts

Post by Burke »

barkeep8 wrote:I figured it out. I had edited the scripts with my windows box, and forgot to remove the DOS newlines. :D
"winvi" is a great little editor to use when working on linux/unix scripts under windows ;) If you don't have it already, just use google to find it.
Burke - MCP+I, MCSE, MCSD, CNE, CCA, CCNA, LPIC-1
[url=http://www.technicalvalues.com]My Website[/url] ::[url=http://www.technicalvalues.net]Domain Registrations, SSL Certs, and Hosting[/url]
Morpheus
Posts: 3
Joined: Tue May 18, 2004 7:02 am
Location: Amsterdam / NL

Post by Morpheus »

Win32Pad works nice also http://www.gena01.com/win32pad/
It autodetects Unix & Windowze textfiles (normally).

And for the guy who wanted to monitor Exchange (I'm monitoring a E2K server here, dunno if it works with 5.5 or 2003)

Code: Select all

#!/usr/bin/perl 

# Replace '/usr/bin/check_nt' with the localtion where your check_nt binary is located 

$u_count        = `/usr/bin/check_nt -H $ARGV[0] -v COUNTER -l "\\MSExchangeIS\\User Count"`; 
chomp $u_count;
$act_u_count    = `/usr/bin/check_nt -H $ARGV[0] -v COUNTER -l "\\MSExchangeIS\\Active User Count"`;
chomp $act_u_count;
$max_u_count    = `/usr/bin/check_nt -H $ARGV[0] -v COUNTER -l "\\MSExchangeIS\\Maximum Users"`;
chomp $max_u_count;
$act_conn       = `/usr/bin/check_nt -H $ARGV[0] -v COUNTER -l "\\MSExchangeIS\\Connection Count"`;
chomp $act_conn;
$msg_subm       = `/usr/bin/check_nt -H $ARGV[0] -v COUNTER -l "\\MSExchangeIS Mailbox(_Total)\\Messages Submitted/min"`;
chomp $msg_subm;
$msg_sent       = `/usr/bin/check_nt -H $ARGV[0] -v COUNTER -l "\\MSExchangeIS Mailbox(_Total)\\Messages Sent/min"`;
chomp $msg_sent;
$msg_deliv      = `/usr/bin/check_nt -H $ARGV[0] -v COUNTER -l "\\MSExchangeIS Mailbox(_Total)\\Messages Delivered/min"`;
chomp $msg_deliv;

print "user_count:"     . $u_count .
     " act_user_count:" . $act_u_count .
     " max_users:"      . $max_u_count .
     " act_conn:"       . $act_conn .
     " msg_subm_min:"   . $msg_subm .
     " msg_sent_min:"   . $msg_sent .
     " msg_deliv_min:"  . $msg_deliv .
     "\n";
--
[ To Err is human, to really foul up things requires a computer ]
Caliban
Posts: 31
Joined: Wed Sep 08, 2004 2:07 am
Location: Maine

Post by Caliban »

Since NT doesn't do SNMP very well I went and made 3 graphs based on Jazzee original scripts that does CPU, Memory, and Hard Drive very similiar to those made by the SNMP graphs. Thought some of you might be able to use it as well.
Just copy the .pl files to the scripts directory in Cacti
Edit them and put where your NetSaint Check_NT is.
Then import the XML's into Cacti (make the host last since I didn't export the dependencies for it)
There should be a new Host Template called Windows NT.
I'm still new at this so excuse me if I didn't package something right.
Attachments
cacti_nt.zip
(11.73 KiB) Downloaded 805 times
Caliban
Posts: 31
Joined: Wed Sep 08, 2004 2:07 am
Location: Maine

Post by Caliban »

Oops just remembered we don't use the standard NSclient port here, went and fixed that in the 3 perl scripts and rezipped them. Sorry about that. :oops:
Attachments
cacti_nt.zip
(11.74 KiB) Downloaded 1752 times
Leonardo
Posts: 10
Joined: Thu Dec 23, 2004 1:27 pm
Location: RS Brasil

Error in file

Post by Leonardo »

The attached file is download.php. That´s wrong.


Att.,
Leo
Guest

Post by Guest »

...
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests