How to configure smtp in monit

I need to set alert when smtp fails

i used this code :

Below is the code for checking smtp :

if failed port 25
 expect "^220.*\r\n"
 send "HELO localhost.localdomain\r\n"
 expect "^250.*\r\n"
 send "QUIT\r\n"
 expect "^221.*\r\n"



but its showing syntax error ..

is this code is intended to perform smtp checks and alerting ?

i doubt there is no alerting specifies ..if so please explain

thanks!
jaisonshereenAsked:
Who is Participating?
 
arnoldConnect With a Mentor Commented:
What do you want the script to do?

You can setup a script using expect or perl that would establish an outgoing SMTP connection to GMAIL mail server and send the alert message directly.

http://robertmaldon.blogspot.com/2006/10/sending-email-through-google-smtp-from.html

try adding on the same line as timeout, alert to see whether multiple items can be triggered.  An alert might be recorded in the syslog.

if you wish to learn, you might consider reviewing the FAQ of monit.
http://www.tildeslash.com/monit/doc/
0
 
arnoldCommented:
Not really clear what your test is.

Presumably you use expect, not sure if failed port 25 is a valid syntax.

You could try
spawn telnet mailserver 25
expect "^250"
send "helo myhost.mydomain.com\r\n"
expect "^22"
send "quit\rn"

Using a perl script with sockets with alarm is much simpler since you do not really need to interact.  All you are looking for is the banner with 2xx.
You can run through the SMTP session simmulation if necessary.
0
 
jaisonshereenAuthor Commented:
Can i  copy paste this :

spawn telnet mailserver 25
expect "^250"
send "helo myhost.mydomain.com\r\n"
expect "^22"
send "quit\rn"

in the mail or do i need to replce anything ?

What is mailserver?

myhost.mydomain.com---> is this the linux server name which smtp service name which is running ?

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
arnoldCommented:
You can, but as you can see there are not tests associated with the example.

You need to make sure the mechanism you are using to check on the state of the connection is correct.
mailserver is the hostname where the mail server is running.
myhost.mydomain.com should usually reflect the system where the script runs.
i.e. servera connects to serverb the myhost.mydomain.com will be that of servera.
0
 
jaisonshereenAuthor Commented:
But this results error as below when i connect to mail server (jaison):
telnet jaison

Connecting to jaison....couldnot connect to the jaison at port 25 connection failed ...


Is there any method to fiind the name of the mailserver where i need to give there ?

0
 
jaisonshereenAuthor Commented:
i am doing telnet from my windows server ...

is this blocking the ip ?
0
 
jaisonshereenAuthor Commented:
is this mailserver looks like this ?

smtp.blahtest01.com
0
 
arnoldCommented:
You are asking question which only you can answer.  smtp,mail in the hostname is common but not required.  What is the hostname of your mail server that you want to test?
telnet jason, makes an attempt to connect to port 23 not 25.
Try telnet jason 25.
0
 
jaisonshereenAuthor Commented:
i given the same as below:
telnet jason 25.

Still i am not able to connect , i am getting the same error .
0
 
arnoldCommented:
Is the SMTP service running on Jason?
0
 
jaisonshereenAuthor Commented:
ps -ef | grep 25
root       325     7  0 May27 ?        00:00:00 [ata/0]
root      2256     1  0 May27 ?        00:00:25 pcscd
root      2594     1  0 May27 ?        00:00:54 sendmail: accepting connections
root     30676 21789  4 20:45 pts/1    00:00:00 grep 25
0
 
jaisonshereenAuthor Commented:
can u replace the line in the below code :

to reflect to send mail?



check process postfix with pidfile /var/spool/postfix/pid/master.pid
   group services
   start program = "/etc/init.d/postfix start"
   stop  program = "/etc/init.d/postfix stop"
   if failed port 25 protocol smtp then restart
   if 5 restarts within 5 cycles then timeout

Open in new window

0
 
arnoldCommented:
Lets start this way, your ps -ef reflects that you are running sendmail while the script you reference is for postfix.  

Can you post the entire script from which this snippet was taken?
You might fair better if you were to install postfix on your system instead of sendmail.

This might get you closer to what you are trying to do.
0
 
jaisonshereenAuthor Commented:
I modified the script like this ..
check process sendmail with pidfile /var/run/sendmail.pid
   group services
   start program = "/etc/init.d/sendmail start"
   stop  program = "/etc/init.d/sendmail stop"
   if failed port 25 protocol smtp then restart
   if 5 restarts within 5 cycles then timeout

but still i am not getting any alerts
0
 
arnoldCommented:
Is you Linux system debian?
http://www.debian-administration.org/users/Steve/weblog/32
check process sendmail with pidfile /var/run/sendmail.pid
   group services
   start program = "/etc/init.d/sendmail start"
   stop  program = "/etc/init.d/sendmail stop"
   if failed host mailserver port 25 protocol smtp then restart
   if 5 restarts within 5 cycles then timeout

Not sure what alerts you are expecting.  This will automatically restart the service, I do not see anything here that would generate an alert.
0
 
jaisonshereenAuthor Commented:
<Arnold>Is you Linux system debian?<Arnold>
<Jaison Comment>
[root@Server01 monit]# uname -a
Linux Server01 2.6.18-53.el5 #1 SMP Mon Nov 12 02:22:48 EST 2007 i686 i686 i386 GNU/Linux
<Jaison Comment>
<Arnold>Not sure what alerts you are expecting.  This will automatically restart the service, I do not see anything here that would generate an alert.<Arnold>
<Jaison Comment>
Sorry for misunderstanding . Please find my complete monitrc configuration file below. I have appended a line to send alerts. Is that line positioned correctly?
<Jaison Comment>

set daemon  120
#
#
## Set syslog logging with the 'daemon' facility. If the FACILITY option is
## omitted, monit will use 'user' facility by default. If you want to log to
## a stand alone log file instead, specify the path to a log file
#
 set logfile syslog facility log_daemon
#
#
  set mailserver localhost              # primary mailserver
#                backup.bar.baz port 10025,  # backup mailserver on port 10025
#                localhost                   # fallback relay
#
     set httpd port 2812 and
     use address localhost # accept connection from localhost
 
     allow XX.XX.78.99/255.255.255.0     # allow localhost to connect to the server and
     allow admin:monit      # require user 'admin' with password 'monit'
 
 
check process sendmail with pidfile /var/run/sendmail.pid
   group services
   start program = "/etc/init.d/sendmail start"
   stop  program = "/etc/init.d/sendmail stop"
   if failed port 25 protocol smtp then restart
   if 5 restarts within 5 cycles then timeout
   alert jaisonshereen@gmail.com
 
## Check a file for existence, checksum, permissions, uid and gid. In addition
## to alert recipients in the global section, customized alert will be sent to
## additional recipients by specifying a local alert handler. The service may
## be grouped using the GROUP option.

Open in new window

0
 
arnoldCommented:
You are checking whether sendmail is running.
I would think that alert would be part of the action i.e. following then.
The more important question is: how will an email be sent out when the mail server is down?

0
 
jaisonshereenAuthor Commented:
ooops that correct ...

then what should be an alternative?

i have created a shell script shown below: to check whether alerts are recieving.

and ran in background.

./mytest.sh &

And edited my monitrc to append the below lines. But i am not sure it is correct , Can you verify?

check process mytest with pidfile /var/run/mytest.pid
   start program  "/opt/monit/mytest start"
   stop program   "/opt/monit/mytest stop"
   if failed port 22 protocol ssh then restart
   if 5 restarts within 5 cycles then timeout

I think this is wrong. Because my shell script is not a service. Can you give any alternatives?

#!/bin/sh
 
# shell script that runs forever and does nothing (but sleeping)
 
while : ; do
  sleep 60
done

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.