/[nagios-plugins-perl]/trunk/plugins/check_mail_smtp_old.pl
ViewVC logotype

Contents of /trunk/plugins/check_mail_smtp_old.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 193 - (show annotations) (download)
Mon Dec 18 14:45:38 2017 UTC (2 years, 11 months ago) by racvision
File MIME type: text/plain
File size: 4678 byte(s)
Remise en ordre XH 201712
1 #!/usr/bin/perl -w
2 #
3 # Copyright (c) 2002-2004 Stéphane Urbanovski <stephane.urbanovski@ac-nancy-metz.fr>
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty
12 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # you should have received a copy of the GNU General Public License
16 # along with this program (or with Nagios); if not, write to the
17 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 # Boston, MA 02111-1307, USA
19 #
20 #
21
22 use strict; # should never be differently :-)
23 use warnings;
24
25 use File::Basename; # get basename()
26 use lib dirname($0); # to get local libs
27 use libplugins qw(:DEFAULT );
28
29 use Net::SMTP;
30 use Sys::Hostname;
31 use Time::Local; # for date conversions
32
33 use POSIX qw(strftime);
34
35 #use Data::Dumper; # debug tool
36
37 my $DEBUG=0;
38
39 # Default values :
40 my %DEFVALUES = (
41 'VERSION' => {
42 'v' => "1.2",
43 'desc' => _("Plugin Version"),
44 },
45 );
46
47 # Get argument :
48 use vars qw( $opt_V $opt_h $opt_m );
49 use vars qw( $warn $crit $smtp_server $mail_sender $mail_addr $pop_key);
50
51 Getopt::Long::GetOptions (
52 "V" => \$opt_V, "version" => \$opt_V,
53 "h|?" => \$opt_h, "help" => \$opt_m,
54 "man" => \$opt_m,
55 "d" => \$DEBUG, "debug=i" => \$DEBUG,
56
57 "w=i" => \$warn, "warning=i" => \$warn,
58 "c=i" => \$crit, "critical=i"=> \$crit,
59
60 "H=s" => \$smtp_server, "host=s" => \$smtp_server,
61 "s=s" => \$mail_sender, "sender=s" => \$mail_sender,
62 "m=s" => \$mail_addr, "mail=s" => \$mail_addr,
63 "k=s" => \$pop_key, "key=s" => \$pop_key,
64 );
65
66 my $state = "UNKNOWN";
67 my $answer = "";
68
69
70 if ( defined ($opt_h) || defined ($opt_m) ) {
71 &showUsage($opt_m,\%DEFVALUES);
72 } elsif (defined ($opt_V)) {
73 &showVersion($DEFVALUES{VERSION}{v});
74 }
75
76 if ( (!defined ($smtp_server)) || ($smtp_server eq "")) {
77 print _("Missing 'smtp server' parameter !")."\n";
78 &showUsage();
79 exit $EXIT_CODES{$state};
80 }
81 if ( (!defined ($mail_addr)) || ($mail_addr eq "")) {
82 print _("Missing 'mail address' parameter !")."\n";
83 &showUsage();
84 exit $EXIT_CODES{$state};
85 }
86
87 $pop_key = $pop_key || $smtp_server;
88
89 my $hostname = hostname;
90
91 $mail_sender = $mail_sender || $mail_addr || $ENV{USER}."@".$hostname ;
92 my $mail_sender_full = $mail_sender;
93 if ( $mail_sender !~ /<.*>/ ) {
94 $mail_sender_full = "Racvision mailler <".$mail_sender.">";
95 }
96
97 #$warn = $warn || 20;
98 #$crit = $crit || 15;
99
100 $state = "CRITICAL";
101
102 if ($DEBUG) {
103 print "DEBUG: smtp_server='$smtp_server' mailaddr='$mail_addr' pop_key='$pop_key'\n"
104 }
105
106
107 $state = "OK";
108 $answer = sprintf(_("Message (key %s) successfully sended."),$pop_key);
109
110
111 my $smtp = Net::SMTP->new($smtp_server, Debug => $DEBUG);
112
113 if ($smtp) {
114 $smtp->mail($mail_sender);
115 $smtp->to($mail_addr);
116 $smtp->data();
117 $smtp->datasend("To: $mail_addr\n");
118 $smtp->datasend("From: $mail_sender_full\n");
119 $smtp->datasend("Subject: $pop_key\n");
120 $smtp->datasend("\n");
121 $smtp->datasend("PING!\n\n");
122 $smtp->datasend("Message de test de messagerie.\n\n");
123 $smtp->datasend("Clef: $pop_key\n\n");
124 $smtp->datasend("Date: ".&getDate()."\n\n");
125 $smtp->dataend();
126 $smtp->quit;
127
128 } else {
129 $state = "CRITICAL";
130 $answer = sprintf(_("Last message '%s' could not be sended !"),$pop_key);
131 }
132
133
134 sub getDate {
135 return strftime("%A %e %B %Y %H:%M:%S", localtime(time()))
136 }
137
138 print $answer."\n";
139 exit $EXIT_CODES{$state};
140
141
142
143
144 __END__
145
146 =head1 NAME
147
148 This plugins send mail used by check_mail_pop3.pl.
149
150 =head1 SYNOPSIS
151
152 B<check_mail_smtp.pl> S<-H I<smtp server>> S<-m I<mail address>> [S<-k I<key>>] [S<-s I<sender mail>>]
153
154 =head1 DESCRIPTION
155
156 Nagios plugins to check smtp server.
157 This plugins also allow you to periodicaly send a mail that could be checked by check_mail_pop3.pl Nagios plugin.
158
159 =head1 OPTIONS
160
161 =over 4
162
163 =item B<-H> I<smtp server>
164
165 The SMTP mail server.
166
167 =item B<-m> I<mail address>
168
169 The mail address we used for our tests.
170
171 =item B<-k> I<key>
172
173 This is a key used in message subject that will be used by check_mail_pop3.pl.
174
175 =item B<-s> I<sender mail>
176
177 Sender mail address. Default to <mail address>.
178
179 =back
180
181 =head1 NAGIOS CONGIGURATIONS
182
183 In F<checkcommands.cfg> you have to add :
184
185 # 'check_mail_smtp'
186 # @param $ARG1$ mail address
187 # @param $ARG2$ key
188 define command {
189 command_name check_mail_smtp
190 command_line $USER1$/check_mail_smtp.pl -H $HOSTADDRESS$ -m $ARG1$ -k $ARG2$
191 }
192
193 =head1 AUTHOR
194
195 Stéphane Urbanovski <stephane.urbanovski@ac-nancy-metz.fr>
196
197 =cut

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.8