updates to application pollers. addition of mailscanner application poller. from Dennis de Houx

git-svn-id: http://www.observium.org/svn/observer/trunk@2634 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2011-10-02 09:41:55 +00:00
parent 1e65da9fa9
commit 4db9afe9f2
8 changed files with 335 additions and 16 deletions

View File

@@ -0,0 +1,22 @@
<?php
global $config;
$graphs = array('mailscanner_stats' => 'MailScanner Statistics');
foreach ($graphs as $key => $text)
{
$graph_type = $key;
$graph_array['height'] = "100";
$graph_array['width'] = "215";
$graph_array['to'] = $now;
$graph_array['id'] = $app['app_id'];
$graph_array['type'] = "application_".$key;
echo('<h3>'.$text.'</h3>');
echo("<tr bgcolor='$row_colour'><td colspan=5>");
include("includes/print-quadgraphs.inc.php");
echo("</td></tr>");
}
?>

View File

@@ -0,0 +1,41 @@
<?php
## Polls MailScanner statistics from script via SNMP
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-mailscanner-" . $app['app_id'] . ".rrd";
$options = "-O qv";
$oid = "nsExtendOutputFull.11.109.97.105.108.115.99.97.110.110.101.114";
$mailscanner = snmp_get($device, $oid, $options);
echo(" mailscanner");
list ($msg_recv, $msg_rejected, $msg_relay, $msg_sent, $msg_waiting, $spam, $virus) = explode("\n", $mailscanner);
if (!is_file($rrd_filename))
{
rrdtool_create($rrd_filename, "--step 300 \
DS:msg_recv:GAUGE:600:0:125000000000 \
DS:msg_rejected:GAUGE:600:0:125000000000 \
DS:msg_relay:GAUGE:600:0:125000000000 \
DS:msg_sent:GAUGE:600:0:125000000000 \
DS:msg_waiting:GAUGE:600:0:125000000000 \
DS:spam:GAUGE:600:0:125000000000 \
DS:virus:GAUGE:600:0:125000000000 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MIN:0.5:1:600 \
RRA:MIN:0.5:6:700 \
RRA:MIN:0.5:24:775 \
RRA:MIN:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797");
}
rrdtool_update($rrd_filename, "N:$msg_recv:$msg_rejected:$msg_relay:$msg_sent:$msg_waiting:$spam:$virus");
?>

View File

@@ -15,11 +15,11 @@ list ($offset, $frequency, $jitter, $noise, $stability) = explode("\n", $ntpclie
if (!is_file($rrd_filename))
{
rrdtool_create($rrd_filename, "--step 300 \
DS:offset:GAUGE:600:-100:125000000000 \
DS:frequency:GAUGE:600:-100:125000000000 \
DS:jitter:GAUGE:600:-100:125000000000 \
DS:noise:GAUGE:600:-100:125000000000 \
DS:stability:GAUGE:600:-100:125000000000 \
DS:offset:GAUGE:600:-1000:1000 \
DS:frequency:GAUGE:600:-1000:1000 \
DS:jitter:GAUGE:600:-1000:1000 \
DS:noise:GAUGE:600:-1000:1000 \
DS:stability:GAUGE:600:-1000:1000 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \

View File

@@ -15,16 +15,16 @@ list ($stratum, $offset, $frequency, $jitter, $noise, $stability, $uptime, $buff
if (!is_file($rrd_filename))
{
rrdtool_create($rrd_filename, "--step 300 \
DS:stratum:GAUGE:600:-100:125000000000 \
DS:offset:GAUGE:600:-100:125000000000 \
DS:frequency:GAUGE:600:-100:125000000000 \
DS:jitter:GAUGE:600:-100:125000000000 \
DS:noise:GAUGE:600:-100:125000000000 \
DS:stability:GAUGE:600:-100:125000000000 \
DS:stratum:GAUGE:600:-1000:1000 \
DS:offset:GAUGE:600:-1000:1000 \
DS:frequency:GAUGE:600:-1000:1000 \
DS:jitter:GAUGE:600:-1000:1000 \
DS:noise:GAUGE:600:-1000:1000 \
DS:stability:GAUGE:600:-1000:1000 \
DS:uptime:GAUGE:600:0:125000000000 \
DS:buffer_recv:GAUGE:600:0:125000000000 \
DS:buffer_free:GAUGE:600:0:125000000000 \
DS:buffer_used:GAUGE:600:0:125000000000 \
DS:buffer_recv:GAUGE:600:0:100000 \
DS:buffer_free:GAUGE:600:0:100000 \
DS:buffer_used:GAUGE:600:0:100000 \
DS:packets_drop:DERIVE:600:0:125000000000 \
DS:packets_ignore:DERIVE:600:0:125000000000 \
DS:packets_recv:DERIVE:600:0:125000000000 \

60
scripts/mailscanner.php Normal file
View File

@@ -0,0 +1,60 @@
#!/usr/bin/env php
<?php
########################################################################################
##
## A small script to grab the MailScanner statistics from a MailScanner server
## Needed commands: php, MailScanner, WatchMailLog, perl
##
## Install:
## Add the WatchMailLog Daemon to the rc.local so its start on server boot
## Run the WatchMailLog Daemon to start grabbing statistics from log files
## Add the following to your snmpd.conf file:
## extend mailwatch /opt/observium/scripts/mailwatch.php
##
## Version 1.0 By:
## All In One - Dennis de Houx <info@all-in-one.be>
##
########################################################################################
#### START SETTINGS ####
$mailstats = "/opt/observium/scripts/watchmaillog/watchmaillog_counters";
#### END SETTINGS ####
##
## DO NOT EDIT BENETH THIS LINE
##
########################################################################################
function doSNMPv2($vars) {
$stats = array();
if (file_exists($vars)) {
$data = file($vars);
foreach ($data as $item=>$value) {
if (!empty($value)) {
$temp = explode(':', trim($value));
if (isset($temp[1])) {
$stats[$temp[0]] = $temp[1];
}
}
}
}
$var['mess_recv'] = (isset($stats['mess_recv']) ? $stats['mess_recv'] : "U");
$var['mess_rejected'] = (isset($stats['mess_rejected']) ? $stats['mess_rejected'] : "U");
$var['mess_relay'] = (isset($stats['mess_relay']) ? $stats['mess_relay'] : "U");
$var['mess_sent'] = (isset($stats['mess_sent']) ? $stats['mess_sent'] : "U");
$var['mess_waiting'] = (isset($stats['mess_waiting']) ? $stats['mess_waiting'] : "U");
$var['spam'] = (isset($stats['spam']) ? $stats['spam'] : "U");
$var['virus'] = (isset($stats['virus']) ? $stats['virus'] : "U");
foreach ($var as $item=>$count) {
echo $count."\n";
}
}
doSNMPv2($mailstats);
$fp = fopen($mailstats, 'w');
fwrite($fp, "mess_recv:0\n");

View File

@@ -13,7 +13,7 @@
## Add the following to your snmpd.conf file:
## extend shoutcast /opt/observium/scripts/shoutcast.php
##
## Version 1.0 By:
## Version 1.1 By:
## All In One - Dennis de Houx <info@all-in-one.be>
##
########################################################################################
@@ -36,6 +36,8 @@
if (!isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD']) || isset($_SERVER['REMOTE_ADDR'])) {
die('<span style="color: #880000; text-weight: bold; font-size: 1.3em;">This script is only meant to run at the command line.</span>');
}
$cmd = (isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : "");
function get_data($host, $port) {
$fp = @fsockopen($host, $port, &$errno, &$errstr, 5);
@@ -108,7 +110,7 @@
}
}
if ($_SERVER['argv'][1] == "makeCache") {
if ($cmd == "makeCache") {
$servers = get_list($config);
$data = doSNMPv2($servers);
makeCacheFile($data, $cache);

View File

@@ -0,0 +1,187 @@
#!/usr/bin/perl
#
# Daemon used to watch the maillog messages for certain messages and trigger events when
# certain messages occur
#
# By Jason Warnes
#
# Change Log
# ~~~~~~~~~~
# 2006-08-22: Initial release
# 2006-09-05: Fixed signal handling
# Added /var/run/watchmaillog.pid file for logrotate usage
# 2006-09-07: Added proper signal handling (Thanks pvenezia!)
# Added SpamAssassin spamd checking support for SPAM (Thanks raiten!)
# 2006-09-18: Added new item mess_waiting, which is the number of messages MailScanner
# detects when a new batch is started.
# 2006-11-02: Changed the way SPAM messages were detected so the script works
# on servers configured for less verbose logging. (Thanks sdetroch!)
# 2006-11-08: Added new item mess_rejected, which is the number of rejected
# messages by Sendmail.
# 2007-02-06: Fixed <MAILLOG> close statement at end of main program. (Thanks Avenger!)
# Fixed warning messages about uninitialized $line used in pattern
# matching (Thanks Avenger!)
# 2007-05-04: Properly closed the maillog file on SIGHUP received. (Thansks thomasch!)
$debug=0; # 1=Debug messages are displayed, 0=No debug messages are displayed
$daemon=1; # 1=Daemonize the program, 0=Run interactive
$syslog=1; # 1=Log stuff to syslog, 0=No logging to syslog
$self="/opt/observium/scripts/watchmaillog/watchmaillog.sh"; # Location of this script
$counterfile="/opt/observium/scripts/watchmaillog/watchmaillog_counters"; # Location to store the counter file
$resetfile="/opt/observium/scripts/watchmaillog/watchmaillog_reset"; # Location of the reset counter flag file
$pidfile="/var/run/watchmaillog.pid"; # Location of the running process ID file (used in logrotate)
use Sys::Syslog;
use POSIX;
use Time::HiRes qw( gettimeofday tv_interval );
$|=1;
my $sigset = POSIX::SigSet->new();
my $hupaction = POSIX::SigAction->new('hup_signal_handler',
$sigset,
&POSIX::SA_NODEFER);
my $osigaction = POSIX::SigAction->new('signal_handler',
$sigset,
&POSIX::SA_NODEFER);
POSIX::sigaction(&POSIX::SIGHUP, $hupaction);
POSIX::sigaction(&POSIX::SIGINT, $osigaction);
POSIX::sigaction(&POSIX::SIGTERM, $osigaction);
if($daemon){
$pid=fork;
if($pid) {
open(PID,">".$pidfile) or die "Cannot open PID file: $!.";
print PID ("$pid\n"); # Write the PID out to the PID file for logrotate
close(PID);
}
exit if $pid;
die "Couldn't fork : $!" unless defined($pid);
setsid() or die "Can't start a new session: $!";
$time_to_die=0;
}
sub signal_handler {
$time_to_die=1;
}
sub hup_signal_handler {
if($debug){print "got SIGHUP\n";}
close(MAILLOG);
exec($self) or die "Couldn't restart: $!\n";
}
if($syslog){openlog("watchmaillog","pid","daemon");}
if($syslog){syslog("notice","Starting.");}
if($debug){print("watchmaillog is starting.\n");}
# Main part of the program
open(MAILLOG, "tail -n 0 -f /var/log/maillog|") or die "Cannot open maillog: $!.";
my $line="";
while(!$time_to_die && ( $line = <MAILLOG> )){
# $line=<MAILLOG>;
# Look for received messages where the sender is not from our domain(s)
if(($line=~/from\=/) && ($line!~/\@domain1.com|\@domain2.com/)){
$item="mess_recv";
&readcounterfile;
$counter{$item}++;
if($debug){print("Found an inbound message, incrementing the message recieve counter to $counter{$item}.\n");}
&writecounterfile;
}
# Look for messages sent to our domain(s), indicates an inbound message relayed to an internal server
if(($line=~/stat\=Sent/) && ($line=~/\@domain1.com|\@domain2.com/)){
$item="mess_relay";
&readcounterfile;
$counter{$item}++;
if($debug){print("Found an clean inbound message, incrementing the clean message recieve counter to $counter{$item}.\n");}
&writecounterfile;
}
# Look for sent messages to NOT our email domain(s), indicates an outbound message
if(($line=~/stat\=Sent/) && ($line!~/\@domain1.comd|\@domain2.com/)){
$item="mess_sent";
&readcounterfile;
$counter{$item}++;
if($debug){print("Found an outbound message, incrementing the message sent counter to $counter{$item}.\n");}
&writecounterfile;
}
# Look for rejected messages
if((($line=~/ruleset/) && ($line=~/reject\=/)) || ($line =~/rejecting/)){
$item="mess_rejected";
&readcounterfile;
$counter{$item}++;
if($debug){print("Found a rejected message, incrementing the message rejected counter to $counter{$item}.\n");}
&writecounterfile;
}
# Look for MailScanner spam scanning batch results
if($line=~/Spam\ Checks\:\ Found/){
$item="spam";
$spam_count_pos = index($line,"Spam\ Checks\:\ Found");
$spam_count_pos2 = index($line, "\ spam\ messages");
$spam_count = substr($line,($spam_count_pos+19),($spam_count_pos2-($spam_count_pos+19)));
&readcounterfile;
$counter{$item}=$counter{$item}+$spam_count;
if($debug){print("Found $spam_count SPAM in the MailScanner batch, incrementing the spam counter to $counter{$item}.\n");}
&writecounterfile;
}
# Look for MainScanner virus scanning batch results
if($line=~/Virus\ Scanning\:\ Found/){
$item="virus";
$virus_count_pos = index($line,"Virus\ Scanning\:\ Found");
$virus_count_pos2 = index($line, "\ viruses");
$virus_count = substr($line,($virus_count_pos+22),($virus_count_pos2-($virus_count_pos+22)));
&readcounterfile;
$counter{$item}=$counter{$item}+$virus_count;
if($debug){print("Found $virus_count viruses in the MailScanner batch, incrementing the virus counter to $counter{$item}.\n");}
&writecounterfile;
}
# Look for MailScanner waiting messages
if($line=~/New\ Batch\:\ Found/){
$item="mess_waiting";
$mess_waiting_pos = index($line,"New\ Batch\:\ Found");
$mess_waiting_pos2 = index($line,"\ messages\ waiting");
$mess_waiting = substr($line,($mess_waiting_pos+17),($mess_waiting_pos2-($mess_waiting_pos+17)));
&readcounterfile;
$counter{$item}=$mess_waiting;
if($debug){print("Mailscanner found $mess_waiting messages waiting, setting the mess_waiting counter to $counter{$item}.\n");}
&writecounterfile;
}
}
close(MAILLOG);
if($debug){print("watchmaillog is ending.\n");}
if($syslog){syslog("notice","Ending.");}
unlink($pidfile);
# Subroutine to read the contents of the counter file
sub readcounterfile {
# Read the counter values from the file
if($debug){print("Reading contents of counter file.\n");}
open(COUNTER,$counterfile);
while($line=<COUNTER>){
@line=split(/\:/,$line);
chop($line[1]); # Drop the trailing LF off the value
# Check for reset counter flag file
if(-e $resetfile."_".$line[0]){
if($debug){print("Reset counter flag file found for counter $line[0], resetting counter value to 0.\n");}
$counter{$line[0]}=0;
unlink($resetfile."_".$line[0]);
} else {
$counter{$line[0]}=$line[1];
}
if($debug){print("Counter $line[0] = $counter{$line[0]}.\n");}
}
close(COUNTER);
}
# Subrouting to write the contents of the counter file
sub writecounterfile {
if($debug){print("Writing counter values to counter file.\n");}
open(COUNTER,">".$counterfile);
# Write each counter item out to the counter file
foreach $item (sort keys(%counter)) {
print COUNTER ($item."\:".$counter{$item}."\n");
}
close(COUNTER);
chmod(0666,$counterfile);
}

View File

@@ -0,0 +1,7 @@
mess_recv:0
mess_rejected:0
mess_relay:0
mess_sent:0
mess_waiting:0
spam:0
virus:0