summaryrefslogtreecommitdiffstats
path: root/contrib/check_pop3.pl
diff options
context:
space:
mode:
authorEthan Galstad <egalstad@users.sourceforge.net>2002-02-28 06:42:51 +0000
committerEthan Galstad <egalstad@users.sourceforge.net>2002-02-28 06:42:51 +0000
commit44a321cb8a42d6c0ea2d96a1086a17f2134c89cc (patch)
treea1a4d9f7b92412a17ab08f34f04eec45433048b7 /contrib/check_pop3.pl
parent54fd5d7022ff2d6a59bc52b8869182f3fc77a058 (diff)
downloadmonitoring-plugins-44a321cb8a42d6c0ea2d96a1086a17f2134c89cc.tar.gz
Initial revision
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'contrib/check_pop3.pl')
-rw-r--r--contrib/check_pop3.pl144
1 files changed, 144 insertions, 0 deletions
diff --git a/contrib/check_pop3.pl b/contrib/check_pop3.pl
new file mode 100644
index 00000000..c0c2712c
--- /dev/null
+++ b/contrib/check_pop3.pl
@@ -0,0 +1,144 @@
1#!/usr/bin/perl
2# ------------------------------------------------------------------------------
3# File Name: check_pop3.pl
4# Author: Richard Mayhew - South Africa
5# Date: 2000/01/21
6# Version: 1.0
7# Description: This script will check to see if an POP3 is running
8# and whether authentication can take place.
9# Email: netsaint@splash.co.za
10# ------------------------------------------------------------------------------
11# Copyright 1999 (c) Richard Mayhew
12# Credits go to Ethan Galstad for coding Nagios
13# If any changes are made to this script, please mail me a copy of the
14# changes :)
15# License GPL
16# ------------------------------------------------------------------------------
17# Date Author Reason
18# ---- ------ ------
19# 1999/09/20 RM Creation
20# 1999/09/20 TP Changed script to use strict, more secure by
21# specifying $ENV variables. The bind command is
22# still insecure through. Did most of my work
23# with perl -wT and 'use strict'
24# 2000/01/20 RM Corrected POP3 Exit State.
25# 2000/01/21 RM Fix Exit Codes Again!!
26# ------------------------------------------------------------------------------
27
28# -----------------------------------------------------------------[ Require ]--
29require 5.004;
30
31# --------------------------------------------------------------------[ Uses ]--
32use Socket;
33use strict;
34
35# --------------------------------------------------------------[ Enviroment ]--
36$ENV{PATH} = "/bin";
37$ENV{BASH_ENV} = "";
38$|=1;
39# ------------------------------------------------------------------[ Global ]--
40my $TIMEOUT = 60;
41
42# -------------------------------------------------------------------[ usage ]--
43sub usage
44{
45 print "Minimum arguments not supplied!\n";
46 print "\n";
47 print "Perl Check POP3 plugin for Nagios\n";
48 print "Copyright (c) 2000 Richard Mayhew\n";
49 print "\n";
50 print "Usage: check_pop3.pl <host> <username> <password> [port]\n";
51 print "\n";
52 print "<port> = Port that the pop3 daemon is running on <host>. Defaults to 110.\n";
53 exit -1;
54
55}
56
57# --------------------------------------------------------------[ bindRemote ]--
58sub bindRemote
59{
60 my ($in_remotehost, $in_remoteport, $in_hostname) = @_;
61 my $proto;
62 my $sockaddr;
63 my $this;
64 my $thisaddr;
65 my $that;
66 my ($name, $aliases,$type,$len,$thataddr) = gethostbyname($in_remotehost);
67
68 if (!socket(ClientSocket,AF_INET, SOCK_STREAM, $proto)) { die $!; }
69 $sockaddr = 'S n a4 x8';
70 $this = pack($sockaddr, AF_INET, 0, $thisaddr);
71 $that = pack($sockaddr, AF_INET, $in_remoteport, $thataddr);
72 if (!bind(ClientSocket, $this)) { print "Connection Refused"; exit 2; }
73 if (!connect(ClientSocket, $that)) { print "Connection Refused"; exit 2; }
74 select(ClientSocket); $| = 1; select(STDOUT);
75 return \*ClientSocket;
76}
77
78# ====================================================================[ MAIN ]==
79MAIN:
80{
81 my $hostname;
82 my $remotehost = shift || &usage;
83 my $username = shift || &usage;
84 my $password = shift || &usage;
85 my $remoteport = shift || 110;
86
87 # Just in case of problems, let's not hang Nagios
88 $SIG{'ALRM'} = sub {
89 print "Something is Taking a Long Time, Increase Your TIMEOUT (Currently Set At $TIMEOUT Seconds)\n";
90 exit -1;
91 };
92
93 alarm($TIMEOUT);
94
95 chop($hostname = `hostname`);
96 my ($name, $alias, $proto) = getprotobyname('tcp');
97 my $ClientSocket = &bindRemote($remotehost,$remoteport,$hostname);
98
99
100print ClientSocket "user $username\n";
101
102#Debug Server
103#print "user $username\n";
104
105#Sleep or 3 secs, incase server is slow.
106sleep 3;
107
108print ClientSocket "pass $password\n";
109
110#Debug Server
111#print "pass $password\n";
112
113while (<ClientSocket>) {
114
115print ClientSocket "pass $password\n";
116
117#Debug Server
118#print $_;
119
120err($_) if (m/\-ERR\s+(.*)\s+.*/);
121message($_) if (m/\+OK Mailbox open,\s+(.*\d)\s+messages.*/);
122}
123}
124
125sub message
126{
127 my $answer = "UNKNOWN";
128 $answer = "Pop3 OK - Total Messages On Server :- $1";
129 alarm(0);
130 print ClientSocket "quit\n";
131 print "$answer";
132 exit 0;
133}
134
135sub err
136{
137 my $answer = "UNKNOWN";
138 $answer = "Pop3 Error :- $1";
139 alarm(0);
140 print ClientSocket "quit\n";
141 print "$answer";
142 exit 2;
143}
144