Im using spine to do the polling..
[root@logger /]# /usr/bin/perl /usr/share/cacti/scripts/exchange07.pl -H HUB2 -c smtp_stat
MessagesSent:2 RecipientsSent:2 ConnectionsTotal:2 AvgBytesPerMsg:0
[root@logger /]#
ran it from / and can still run it... /usr/share/cacti/scripts/ is 777 so technically anybody should be able to run the program.
I can return results when I manually run it, but when cacti kicks it, nadda...
the log says it received empty results. Even bumped my SNMP timeout to 10 seconds. Still no dice. I AM running it against a 2010 HUB Transport server if that helps.
I had a similar problem with the RPC Stats, but had to manually change the name on the counter.. i did the same thing for smtp. Don't see errors on the NSClient++ Log either.
Code: Select all
#!/usr/bin/perl
# Script to be used with the cacti template for fetching Conter information from the Microsoft Exchange server 2007 2010
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# you should have received a copy of the GNU General Public License
# along with this program (or with Nagios); if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA
#
# Changes and Modifications
# =========================
# Sept 07, 2012: Patrick Zambelli <net.support@wuerth-phoenix.com>
# Version 1.0 - Support for Exchane 2007 - 2010
#use strict;
use Getopt::Long;
use Data::Dumper;
my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
my $CheckNTPath='/usr/local/nagios/libexec/';
sub check_options {
Getopt::Long::Configure ("bundling");
GetOptions(
'h' => \$o_help, 'help' => \$o_help,
'H:s' => \$o_host, 'hostname:s' => \$o_host,
'c:s' => \$o_command, 'command:s' => \$o_command
);
if (defined($o_help) ) { help(); exit $ERRORS{"UNKNOWN"}; }
if (! defined($o_host) ) { help(); exit $ERRORS{"UNKNOWN"}; }
if (!defined($o_command)) { help(); exit $ERRORS{"UNKNOWN"}; }
}
sub help {
print "Usage: exchange07 -H <host to query> -c <command to call: 'iis'|'delivery_stat'>\n";
}
########## MAIN #######
check_options();
#User login sessions
if ($o_command eq 'connections'){
# Replace '/usr/local/nagios/libexec/check_nt' with the localtion where your check_nt binary is located
$UserCount = `$CheckNTPath/check_nt -H $o_host -p 12489 -v COUNTER -l "\\\MSExchange RpcClientAccess\\\\User Count"`;
chomp $UserCount;
$ActiveUserCount = `$CheckNTPath/check_nt -H $o_host -p 12489 -v COUNTER -l "\\\MSExchange RpcClientAccess\\\Active User Count"`;
chomp $ActiveUserCount;
$ActiveConn = `$CheckNTPath/check_nt -H $o_host -p 12489 -v COUNTER -l "\\\MSExchange RpcClientAccess\\\Connection Count"`;
chomp $ActiveConn;
print "UserCount:$UserCount ActiveUserCount:$ActiveUserCount ActiveConn:$ActiveConn\n";
# Mail delivery statistics
} elsif ($o_command eq 'delivery_stat'){
$file_delstat = "/tmp/exch07_delstat_".$o_host.".txt";
%results = (
MessagesSubmittedPermin => '',
MessagesSentPermin => '',
MessagesDeliveredPermin => '', );
#Open file for reading
if (open FILE, "<", $file_delstat){
my @lines = <FILE>;
close (FILE);
scanForContent(\@lines, \%results);
} else {
createFile($file_delstat);
exit 0;
}
$MessagesSubmittedPermin = `$CheckNTPath/check_nt -H $o_host -p 12489 -v COUNTER -l "\MSExchangeTransport Queues(_Total)\\\Messages Submitted Per Second"`;
chomp $MessagesSubmittedPermin;
$MessagesSentPermin = `$CheckNTPath/check_nt -H $o_host -p 12489 -v COUNTER -l "\\MSExchangeTransport Queues(_Total)\\\Messages Completed Delivery Per Second"`;
chomp $MessagesSentPermin;
$MessagesDeliveredPermin = `$CheckNTPath/check_nt -H $o_host -p 12489 -v COUNTER -l "\\MSExchangeTransport SmtpSend(_total)\\\Messages Sent/sec"`;
chomp $MessagesDeliveredPermin;
chomp $SendQueueSize;
$ReceiveQueueSize = `$CheckNTPath/check_nt -H $o_host -p 12489 -v COUNTER -l "MSExchangeIS Mailbox(_Total)\\\Receive Queue Size"`;
chomp $ReceiveQueueSize;
%results->{ 'MessagesSubmittedPermin' } = $MessagesSubmittedPermin - %results->{ 'MessagesSubmittedPermin' };
%results->{ 'MessagesSentPermin' } = $MessagesSentPermin - %results->{ 'MessagesSentPermin' };
%results->{ 'MessagesDeliveredPermin' } = $MessagesDeliveredPermin - %results->{ 'MessagesDeliveredPermin' };
#Open file for storing new values
writeToFile($file_delstat, "MessagesSubmittedPermin:".$MessagesSubmittedPermin."\nMessagesSentPermin:".$MessagesSentPermin."\nMessagesDeliveredPermin:".$MessagesDeliveredPermin."\nSendQueueSize:".$SendQueueSize."\nReceiveQueueSize:".$ReceiveQueueSize."");
print "MessagesSubmittedPermin:". %results->{ 'MessagesSubmittedPermin' }." MessagesSentPermin:". %results->{ 'MessagesSentPermin' }." MessagesDeliveredPermin:". %results->{ 'MessagesDeliveredPermin' }." SendQueueSize:".$SendQueueSize." ReceiveQueueSize:".$ReceiveQueueSize."\n";
} elsif ($o_command eq 'smtp_stat'){
$file_delstat = "/tmp/exch07_smtpstat_".$o_host.".txt";
%results = (
MessagesSent => '',
RecipientsSent => '',
ConnectionsTotal => '', );
#Open file for reading
if (open FILE, "<", $file_delstat){
my @lines = <FILE>;
close (FILE);
scanForContent(\@lines, \%results);
} else {
createFile($file_delstat);
exit 0;
}
$MessagesSent = `$CheckNTPath/check_nt -H $o_host -p 12489 -v COUNTER -l "\\MSExchangeTransport SmtpSend(_Total)\\\Messages Sent Total"`;
chomp $MessagesSent;
$RecipientsSent = `$CheckNTPath/check_nt -H $o_host -p 12489 -v COUNTER -l "\\MSExchangeTransport SmtpSend(_Total)\\\Recipients sent"`;
chomp $RecipientsSent;
$ConnectionsTotal = `$CheckNTPath/check_nt -H $o_host -p 12489 -v COUNTER -l "\\MSExchangeTransport SmtpSend(_Total)\\\Connections Total"`;
chomp $ConnectionsTotal;
$AvgBytesPerMsg = `$CheckNTPath/check_nt -H $o_host -p 12489 -v COUNTER -l "\\MSExchangeTransport SmtpSend(_Total)\\\Average message bytes/message"`;
chomp $AvgBytesPerMsg;
if (%results->{ 'MessagesSent' } > 0 ) { %results->{ 'MessagesSent' } = $MessagesSent - %results->{ 'MessagesSent' }; }
if (%results->{ 'RecipientsSent' } > 0 ) { %results->{ 'RecipientsSent' } = $RecipientsSent - %results->{ 'RecipientsSent' };}
if (%results->{ 'ConnectionsTotal' } > 0 ) { %results->{ 'ConnectionsTotal' } = $ConnectionsTotal - %results->{ 'ConnectionsTotal' };}
#Open file for storing new values
writeToFile($file_delstat, "MessagesSent:".$MessagesSent."\nRecipientsSent:".$RecipientsSent."\nConnectionsTotal:".$ConnectionsTotal."");
print "MessagesSent:". %results->{ 'MessagesSent' }." RecipientsSent:". %results->{ 'RecipientsSent' }." ConnectionsTotal:". %results->{ 'ConnectionsTotal' }." AvgBytesPerMsg:".$AvgBytesPerMsg."\n";
#RPC statistics
} elsif ($o_command eq 'rpc_stat'){
$is_rpc_packets = `$CheckNTPath/check_nt -H $o_host -p 12489 -v COUNTER -l "\\\MSExchange RpcClientAccess\\\\RPC Packets/sec"`;
chomp $is_rpc_packets;
$is_rpc_ave_latency = `$CheckNTPath/check_nt -H $o_host -p 12489 -v COUNTER -l "\\\MSExchange RpcClientAccess\\\Averaged Latency"`;
chomp $is_rpc_ave_latency;
$is_rpc_operations = `$CheckNTPath/check_nt -H $o_host -p 12489 -v COUNTER -l "\\\MSExchange RpcClientAccess\\\RPC Operations/sec"`;
chomp $is_rpc_operations;
print "is_rpc_packets:$is_rpc_packets is_rpc_ave_latency:$is_rpc_ave_latency is_rpc_operations:$is_rpc_operations\n";
#SPAM: confidence level
} elsif ($o_command eq 'spam_confidLvl'){
# Replace '$CheckNTPath/check_nt' with the localtion where your check_nt binary is located
$scl0 = `$CheckNTPath/check_nt -H $o_host -p $NsclientPort -v COUNTER -l "\\\MSExchange Content Filter Agent(_Total)\\\Messages with SCL 0"`;
chomp $scl0;
$scl1 = `$CheckNTPath/check_nt -H $o_host -p $NsclientPort -v COUNTER -l "\\\MSExchange Content Filter Agent(_Total)\\\Messages with SCL 1"`;
chomp $scl1;
$scl2 = `$CheckNTPath/check_nt -H $o_host -p $NsclientPort -v COUNTER -l "\\\MSExchange Content Filter Agent(_Total)\\\Messages with SCL 2"`;
chomp $scl2;
$scl3 = `$CheckNTPath/check_nt -H $o_host -p $NsclientPort -v COUNTER -l "\\\MSExchange Content Filter Agent(_Total)\\\Messages with SCL 3"`;
chomp $scl3;
$scl4 = `$CheckNTPath/check_nt -H $o_host -p $NsclientPort -v COUNTER -l "\\\MSExchange Content Filter Agent(_Total)\\\Messages with SCL 4"`;
chomp $scl4;
$scl5 = `$CheckNTPath/check_nt -H $o_host -p $NsclientPort -v COUNTER -l "\\\MSExchange Content Filter Agent(_Total)\\\Messages with SCL 5"`;
chomp $scl5;
$scl6 = `$CheckNTPath/check_nt -H $o_host -p $NsclientPort -v COUNTER -l "\\\MSExchange Content Filter Agent(_Total)\\\Messages with SCL 6"`;
chomp $scl6;
$scl7 = `$CheckNTPath/check_nt -H $o_host -p $NsclientPort -v COUNTER -l "\\\MSExchange Content Filter Agent(_Total)\\\Messages with SCL 7"`;
chomp $scl7;
$scl8 = `$CheckNTPath/check_nt -H $o_host -p $NsclientPort -v COUNTER -l "\\\MSExchange Content Filter Agent(_Total)\\\Messages with SCL 8"`;
chomp $scl8;
$scl9 = `$CheckNTPath/check_nt -H $o_host -p $NsclientPort -v COUNTER -l "\\\MSExchange Content Filter Agent(_Total)\\\Messages with SCL 9"`;
chomp $scl9;
print "scl0:" . $scl0 .
" scl1:" . $scl1 .
" scl2:" . $scl2 .
" scl3:" . $scl3 .
" scl4:" . $scl4 .
" scl5:" . $scl5 .
" scl6:" . $scl6 .
" scl7:" . $scl7 .
" scl8:" . $scl8 .
" scl9:" . $scl9 .
"\n";
#SPAM: Filter activigy
} elsif ($o_command eq 'spam_filter'){
# Replace '$CheckNTPath/check_nt' with the localtion where your check_nt binary is located
$scanned = `$CheckNTPath/check_nt -H $o_host -p $NsclientPort -v COUNTER -l "\\\MSExchange Content Filter Agent(_Total)\\\Messages Scanned"`;
chomp $scanned;
$bypassed = `$CheckNTPath/check_nt -H $o_host -p $NsclientPort -v COUNTER -l "\\\MSExchange Content Filter Agent(_Total)\\\Messages that Bypassed Scanning"`;
chomp $bypassed;
$deleted = `$CheckNTPath/check_nt -H $o_host -p $NsclientPort -v COUNTER -l "\\\MSExchange Content Filter Agent(_Total)\\\Messages Deleted"`;
chomp $deleted;
$rejected = `$CheckNTPath/check_nt -H $o_host -p $NsclientPort -v COUNTER -l "\\\MSExchange Content Filter Agent(_Total)\\\Messages Rejected"`;
chomp $rejected;
$quarantined = `$CheckNTPath/check_nt -H $o_host -p $NsclientPort -v COUNTER -l "\\\MSExchange Content Filter Agent(_Total)\\\Messages Quarantined"`;
chomp $quarantined;
$skipped = `$CheckNTPath/check_nt -H $o_host -p $NsclientPort -v COUNTER -l "\\\MSExchange Content Filter Agent(_Total)\\\Messages with SCL Unknown"`;
chomp $skipped;
print "bypassed:" . $bypassed .
" scanned:" . $scanned .
" deleted:" . $deleted .
" rejected:" . $rejected .
" quarantined:" . $quarantined .
" skipped:" . $skipped .
"\n";
}
##FUNCTIONS ###
sub createFile {
my ($filename) = shift;
open FILE, ">", $filename or die "unable to create file $filename".$!;
close (FILE);
}
#scan lines for passed keys in hash
sub scanForContent {
my ($lines, $results) = @_;
foreach my $key ( keys %$results ){
#print "DEBUG: scanning for key: ".$key."\n";
foreach my $line (@$lines) {
#The read line matches the key to search
if ($line =~ /$key/){
$key_length = (split(//, $key));
$line_length = (split(//, $line));
#print "DEBUG: key length: ".$key_length."\n";
$value = substr ($line, $key_length+1, $line_length-$key_length);
# print "Matching key: ".$key." and line ". $line." and Value: ".$value."\n";
#check if value is numeric
if ($value =~ /^[0-9]*$/){
%$results->{ $key } = $value;
#print "DEBUG: SET VALUE $value to key $key \n";
} else {
print "Problem $value....TODO \n";
}
}
}
}
}
#
############################################################
#
# appendLine filename, line
#
sub writeToFile {
my ($filename,$line) = @_;
# open file for append and lock it
open (FILE,">$filename")|| &returnError (500,"Server error","Could not open file $filename for append");
flock(FILE,$exclusive_lock);
# and, in case someone appended
# while we were waiting...
seek(FILE, 0, 2);
# write the line AND add a line end
print FILE "$line\n";
#unlock and close the file
flock(FILE,$unlock_lock);
close (FILE);
}
I attached the perl script as well..