mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-02-20 00:10:09 -05:00
New or revised plugin in /contrib
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1117 f882894a-f735-0410-b71e-b25c423dba1c
This commit is contained in:
parent
0e1ff20754
commit
b7c0754632
4 changed files with 1857 additions and 13 deletions
259
contrib/check_asterisk.pl
Normal file
259
contrib/check_asterisk.pl
Normal file
|
|
@ -0,0 +1,259 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
use strict;
|
||||
use IO::Socket;
|
||||
use Getopt::Long;
|
||||
$|=1;
|
||||
|
||||
my (
|
||||
$host, $username, $password, $verbose, $help, $command, $mode,
|
||||
$ipaddr, $respaddr, $sendto, $msg, $recvfrom,
|
||||
$version, $response, $message, $line,
|
||||
$sock, $port, $reply,
|
||||
$warning, $critical,
|
||||
%warnval, %critval,
|
||||
%channels,
|
||||
$runmode,
|
||||
$key,
|
||||
$s,
|
||||
);
|
||||
my $stop = 0;
|
||||
my $mgr_port = 5038;
|
||||
my $iax_port = 4569;
|
||||
my $exitcode = 0;
|
||||
my $cause = "";
|
||||
|
||||
my $iax_answer = 0;
|
||||
my $iax_maxlen = 1024;
|
||||
my $iax_timeout = 5;
|
||||
my $iax_src_call = "8000"; #8000 most siginificant bit is IAX packet type full ... required for a poke etc...
|
||||
my $iax_dst_call = "0000";
|
||||
my $iax_timestamp = "00000000";
|
||||
my $iax_outbound_seq = "00";
|
||||
my $iax_inbound_seq = "00";
|
||||
my $iax_type = "06"; #IAX_Control
|
||||
|
||||
sub ok {
|
||||
$s = shift;
|
||||
$s =~ s/[\r\n]//g;
|
||||
print "OK: $s\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
sub warning {
|
||||
$s = shift;
|
||||
$s =~ s/[\r\n]//g;
|
||||
print "WARNING: $s\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sub error {
|
||||
$s = shift;
|
||||
$s =~ s/[\r\n]//g;
|
||||
print "ERROR: $s\n";
|
||||
exit(2);
|
||||
}
|
||||
|
||||
sub unknown {
|
||||
$s = shift;
|
||||
$s =~ s/[\r\n]//g;
|
||||
print "UNKNOWN: $s\n";
|
||||
exit(3);
|
||||
}
|
||||
|
||||
sub syntax {
|
||||
$s = shift;
|
||||
unless ($s =~ m/Help:/) {
|
||||
$s = "Error: (".$s.")" or $s = 'Unknown';
|
||||
}
|
||||
print "$s\n" unless ($help);
|
||||
print "Syntax: $0 -m mgr -h <host> -u <username> -p <password> [-cwv]\n";
|
||||
print "Syntax: $0 -m iax -h <host> [-v]\n";
|
||||
print "* --host -h Host\n";
|
||||
print "* --mode -m Mode - eithr 'mgr' or 'iax'\n";
|
||||
print " --username -u Username\n";
|
||||
print " --password -p Password\n";
|
||||
print " --port -P n Port (if not using $mgr_port for manager or $iax_port for IAX)\n";
|
||||
print " --warning xxx=n Return warning if > n channels of type xxx.\n";
|
||||
print " --critical xxx=n Return critical if > n channels of type xxx.\n";
|
||||
print " --verbose -v Verbose\n";
|
||||
print " --help -h This help\n";
|
||||
exit(3);
|
||||
}
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("p=s" => \$password, "password=s" => \$password,
|
||||
"u=s" => \$username, "username=s" => \$username,
|
||||
"h=s" => \$host, "host=s" => \$host,
|
||||
"P=i" => \$port, "port=i" => \$port,
|
||||
"H" => \$help, "help" => \$help,
|
||||
"v" => \$verbose, "verbose" => \$verbose,
|
||||
"m=s" => \$mode, "mode=s" => \$mode,
|
||||
"critical=s" => \$critical, "warning=s" => \$warning);
|
||||
|
||||
syntax("Help:") if ($help);
|
||||
syntax("Missing host") unless (defined($host));
|
||||
syntax("Missing mode") unless (defined($mode));
|
||||
if ($mode =~ /^iax$/i) {
|
||||
print "Running in IAX mode\n" if ($verbose);
|
||||
$runmode = 1;
|
||||
} elsif ($mode =~ /^mgr$/i) {
|
||||
print "Running in Manager mode\n" if ($verbose);
|
||||
$runmode = 2;
|
||||
} else {
|
||||
syntax("Unknown mode $mode")
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
|
||||
if ($runmode == 2) {
|
||||
$port = $mgr_port;
|
||||
syntax("Missing username") unless (defined($username));
|
||||
syntax("Missing password") unless (defined($password));
|
||||
if (defined($warning)) {
|
||||
foreach $s (split(/,/, $warning)) {
|
||||
syntax("Warning value given, $s, is invalid")
|
||||
unless ($s =~ /^(\w+)=(\d+)$/);
|
||||
$warnval{$1} = $2;
|
||||
print "Clear to give WARNING after $2 connections on $1\n" if ($verbose);
|
||||
}
|
||||
}
|
||||
if (defined($critical)) {
|
||||
foreach $s (split(/,/, $critical)) {
|
||||
syntax("Critical value given, $s, is invalid")
|
||||
unless ($s =~ /^(\w+)=(\d+)$/);
|
||||
$critval{$1} = $2;
|
||||
print "Clear to give CRITICAL after $2 connections on $1\n" if ($verbose);
|
||||
}
|
||||
}
|
||||
|
||||
print "Connecting to $host:$port\n" if ($verbose);
|
||||
unless ($sock = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port, Proto => 'tcp')) {
|
||||
print("Could not connect to asterisk server ".$host.":".$port."\n");
|
||||
exit(2);
|
||||
}
|
||||
print "Connected to $host:$port\n" if ($verbose);
|
||||
$version = <$sock>;
|
||||
print $version if ($verbose);
|
||||
|
||||
print $sock "Action: Login\r\nUsername: $username\r\nSecret: $password\r\nEvents: off\r\n\r\n";
|
||||
print "Action: Login\r\nUsername: $username\r\nSecret: $password\r\n\r\n" if ($verbose);
|
||||
$response = <$sock>;
|
||||
$message = <$sock>;
|
||||
$s = <$sock>;
|
||||
print $response.$message if ($verbose);
|
||||
print $s if ($verbose);
|
||||
|
||||
exit(1) unless ($response =~ m/^Response:\s+(.*)$/i);
|
||||
exit(1) unless ($1 =~ m/Success/i);
|
||||
|
||||
print $sock "Action: Status\r\n\r\n";
|
||||
print "Action: Status\r\n\r\n" if ($verbose);
|
||||
|
||||
$response = <$sock>;
|
||||
$message = <$sock>;
|
||||
print $response.$message if ($verbose);
|
||||
|
||||
&unknown("Unknown answer $response (wanted Response: something)") unless ($response =~ m/^Response:\s+(.*)$/i);
|
||||
&unknown("$response didn't say Success") unless ($1 =~ m/Success/i);
|
||||
&unknown("Unknown answer $response (wanted Message: something)") unless ($message =~ m/^Message:\s+(.*)$/i);
|
||||
&unknown("didn't understand message $message") unless ($1 =~ m/Channel status will follow/i);
|
||||
|
||||
$stop=0;
|
||||
while (($stop == 0) && ($line = <$sock>)) {
|
||||
print "$line" if ($verbose);
|
||||
if ($line =~ m/Channel:\s+(\w+)\//) {
|
||||
$channels{$1}++;
|
||||
print "Found $1 channel\n" if ($verbose);
|
||||
}
|
||||
if ($line =~ m/Event:\s*StatusComplete/i) {
|
||||
$stop++;
|
||||
}
|
||||
}
|
||||
|
||||
# Log out
|
||||
print $sock "Action: Logoff\r\n\r\n";
|
||||
|
||||
undef($s);
|
||||
foreach $key (keys %channels) {
|
||||
$s .= " " . $key . " (" . $channels{$key} . ")";
|
||||
}
|
||||
|
||||
foreach $key (keys %critval) {
|
||||
print "key = $key\n" if ($verbose);
|
||||
if (defined($channels{$key}) && ($channels{$key} > $critval{$key})) {
|
||||
$exitcode = 2;
|
||||
$cause .= $channels{$key} . " $key channels detected. ";
|
||||
}
|
||||
}
|
||||
|
||||
if ($exitcode < 2) {
|
||||
foreach $key (keys %warnval) {
|
||||
print "key = $key\n" if ($verbose);
|
||||
if (defined($channels{$key}) && ($channels{$key} > $warnval{$key})) {
|
||||
$exitcode = 1;
|
||||
$cause .= $channels{$key} . " $key channels detected. ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($exitcode == 0) {
|
||||
print "OK ";
|
||||
} elsif ($exitcode == 1) {
|
||||
print "WARNING ";
|
||||
} elsif ($exitcode == 2) {
|
||||
print "CRITICAL ";
|
||||
} elsif ($exitcode > 2) {
|
||||
print "UNKNOWN ";
|
||||
}
|
||||
if (defined($s)) {
|
||||
$cause .= " Channels:$s";
|
||||
} else {
|
||||
$cause .= " (idle)";
|
||||
}
|
||||
|
||||
print $cause;
|
||||
|
||||
print "\n" if ($verbose);
|
||||
|
||||
exit($exitcode);
|
||||
} elsif ($runmode == 1) {
|
||||
$port = $iax_port;
|
||||
|
||||
socket(PING, PF_INET, SOCK_DGRAM, getprotobyname("udp"));
|
||||
|
||||
$msg = pack "H24", $iax_src_call . $iax_dst_call . $iax_timestamp .
|
||||
$iax_outbound_seq . $iax_inbound_seq . $iax_type . $iax_type;
|
||||
|
||||
$ipaddr = inet_aton($host);
|
||||
$sendto = sockaddr_in($port,$ipaddr);
|
||||
|
||||
send(PING, $msg, 0, $sendto) == length($msg) or die "cannot send to $host : $port : $!\n";
|
||||
|
||||
eval {
|
||||
local $SIG{ALRM} = sub { die("alarm time out"); };
|
||||
alarm $iax_timeout;
|
||||
|
||||
while (1) {
|
||||
$recvfrom = recv(PING, $msg, $iax_maxlen, 0) or die "recv: $!";
|
||||
($port, $ipaddr) = sockaddr_in($recvfrom);
|
||||
$respaddr = inet_ntoa($ipaddr);
|
||||
$iax_answer++;
|
||||
# print "Response from $respaddr : $port\n";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
if ($iax_answer) {
|
||||
if ($iax_answer == 1) {
|
||||
$reply = "reply";
|
||||
} else {
|
||||
$reply = "replies";
|
||||
}
|
||||
&ok("Got $iax_answer $reply");
|
||||
} else {
|
||||
&error("Got no reply");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -24,6 +24,11 @@
|
|||
# back till now) or if a mails got lost (meaning a mail, that was
|
||||
# send later came back prior to another mail).
|
||||
#
|
||||
# Michael Markstaller, mm@elabnet.de various changes/additions
|
||||
# MM 021003: fixed some unquoted strings
|
||||
# MM 021116: fixed/added pendwarn/lostwarn
|
||||
# MM 030515: added deleting of orphaned check-emails
|
||||
# changed to use "top" instead of get to minimize traffic (required changing match-string from "Subject: Email-ping [" to "Email-Ping ["
|
||||
|
||||
use Net::POP3;
|
||||
use Net::SMTP;
|
||||
|
|
@ -40,8 +45,8 @@ my %ERRORS = ('UNKNOWN' , '-1',
|
|||
'CRITICAL', '2');
|
||||
|
||||
my $state = "UNKNOWN";
|
||||
my ($sender,$receiver, $pophost, $popuser, $poppasswd, $smtphost);
|
||||
my ($poptimeout,$smtptimeout,$pinginterval)=(60,60,5);
|
||||
my ($sender,$receiver, $pophost, $popuser, $poppasswd, $smtphost,$keeporphaned);
|
||||
my ($poptimeout,$smtptimeout,$pinginterval,$maxmsg)=(60,60,5,50);
|
||||
my ($lostwarn, $lostcrit,$pendwarn, $pendcrit);
|
||||
|
||||
# Internal Vars
|
||||
|
|
@ -73,10 +78,12 @@ my $status = GetOptions(
|
|||
"smtptimeout=i",\$smtptimeout,
|
||||
"statfile=s",\$statfile,
|
||||
"interval=i",\$pinginterval,
|
||||
"lostwarr=i",\$lostwarn,
|
||||
"lostwarn=i",\$lostwarn,
|
||||
"lostcrit=i",\$lostcrit,
|
||||
"pendwarn=i",\$pendwarn,
|
||||
"pendcrit=i",\$pendcrit,
|
||||
"maxmsg=i",\$maxmsg,
|
||||
"keeporphaned=s",\$keeporphaned,
|
||||
);
|
||||
usage() if ($status == 0 || ! ($pophost && $popuser && $poppasswd &&
|
||||
$smtphost && $receiver && $sender ));
|
||||
|
|
@ -127,10 +134,12 @@ $statinfo="$msgcount mails on POP3";
|
|||
|
||||
nsexit("POP3 login failed (user:$popuser)",'CRITICAL') if (!defined($msgcount));
|
||||
|
||||
# Check if more than maxmsg mails in pop3-box
|
||||
nsexit(">$maxmsg Mails ($msgcount Mails on POP3); Please delete !",'WARNING') if ($msgcount > $maxmsg);
|
||||
|
||||
# Count messages, that we are looking 4:
|
||||
while ($msgcount > 0) {
|
||||
@msglines = @{$pop->get($msgcount)};
|
||||
|
||||
@msglines = @{$pop->top($msgcount,1)};
|
||||
for (my $i=0; $i < scalar @messageids; $i++) {
|
||||
if (messagematchsid(\@msglines,$messageids[$i])) {
|
||||
$matchcount++;
|
||||
|
|
@ -138,11 +147,18 @@ while ($msgcount > 0) {
|
|||
$newestid = $messageids[$i] if ($messageids[$i] > $newestid || !defined $newestid);
|
||||
$pop->delete($msgcount); # remove E-Mail from POP3 server
|
||||
splice @messageids, $i, 1;# remove id from List
|
||||
last; # stop looking in list
|
||||
}
|
||||
last; # stop looking in list
|
||||
}
|
||||
}
|
||||
# Delete orphaned Email-ping msg
|
||||
my @msgsubject = grep /^Subject/, @msglines;
|
||||
chomp @msgsubject;
|
||||
# Scan Subject if email is an Email-Ping. In fact we match and delete also successfully retrieved messages here again.
|
||||
if (!defined $keeporphaned && $msgsubject[0] =~ /E-Mail Ping \[/) {
|
||||
$pop->delete($msgcount); # remove E-Mail from POP3 server
|
||||
}
|
||||
|
||||
$msgcount--;
|
||||
$msgcount--;
|
||||
}
|
||||
|
||||
$pop->quit(); # necessary for pop3 deletion!
|
||||
|
|
@ -194,7 +210,7 @@ nsexit($statinfo);
|
|||
# ----------------------------------------------------------------------
|
||||
|
||||
sub usage {
|
||||
print "check_email_loop 1.0 Nagios Plugin - Real check of a E-Mail system\n";
|
||||
print "check_email_loop 1.1 Nagios Plugin - Real check of a E-Mail system\n";
|
||||
print "=" x 75,"\nERROR: Missing or wrong arguments!\n","=" x 75,"\n";
|
||||
print "This script sends a mail with a specific id in the subject via an given\n";
|
||||
print "smtp-server to a given email-adress. When the script is run again, it checks\n";
|
||||
|
|
@ -210,19 +226,21 @@ sub usage {
|
|||
print " -smtphost=text IP oder name of the SMTP host\n";
|
||||
print " -smtptimeout=num Timeout in seconds for the SMTP-server\n";
|
||||
print " -statfile=text File to save ids of messages ($statfile)\n";
|
||||
# print " -interval=num Time (in minutes) that must pass by before sending\n"
|
||||
# print " another Ping-mail (gibe a new try);\n";
|
||||
print " -interval=num Time (in minutes) that must pass by before sending\n";
|
||||
print " another Ping-mail (gibe a new try);\n";
|
||||
print " -lostwarn=num WARNING-state if more than num lost emails\n";
|
||||
print " -lostcrit=num CRITICAL \n";
|
||||
print " -pendwarn=num WARNING-state if more than num pending emails\n";
|
||||
print " -pendcrit=num CRITICAL \n";
|
||||
print " -maxmsg=num WARNING if more than num emails on POP3 (default 50)\n";
|
||||
print " -keeporphaned Set this to NOT delete orphaned E-Mail Ping msg from POP3\n\n";
|
||||
print " Options may abbreviated!\n";
|
||||
print " LOST mails are mails, being sent before the last mail arrived back.\n";
|
||||
print " PENDING mails are those, which are not. (supposed to be on the way)\n";
|
||||
print "\nExample: \n";
|
||||
print " $0 -poph=host -pa=pw -popu=popts -smtph=host -from=root\@me.com\n ";
|
||||
print " -to=remailer\@testxy.com -lostc=0 -pendc=2\n";
|
||||
print "\nCopyleft 19.10.2000, Benjamin Schmid\n";
|
||||
print "\nCopyleft 19.10.2000, Benjamin Schmid / 2003 Michael Markstaller, mm\@elabnet.de\n";
|
||||
print "This script comes with ABSOLUTELY NO WARRANTY\n";
|
||||
print "This programm is licensed under the terms of the ";
|
||||
print "GNU General Public License\n\n";
|
||||
|
|
@ -247,7 +265,7 @@ sub messagematchsid {
|
|||
|
||||
# ID
|
||||
$id =~ s/^LI/ID/; # evtl. remove lost mail mark
|
||||
@tmp = grep /Subject: E-Mail Ping \[/, @$mailref;
|
||||
@tmp = grep /E-Mail Ping \[/, @$mailref;
|
||||
chomp @tmp;
|
||||
if (($tmp[0] =~ /$id/))
|
||||
{ $match = 1; }
|
||||
|
|
|
|||
1567
contrib/check_http-with-client-certificate.c
Normal file
1567
contrib/check_http-with-client-certificate.c
Normal file
File diff suppressed because it is too large
Load diff
BIN
contrib/tarballs/check_traffic-0.91b.tar.gz
Normal file
BIN
contrib/tarballs/check_traffic-0.91b.tar.gz
Normal file
Binary file not shown.
Loading…
Reference in a new issue