Solved

How to configure smtp in monit

Posted on 2008-06-18
18
544 Views
Last Modified: 2013-11-30
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!
0
Comment
Question by:jaisonshereen
  • 10
  • 8
18 Comments
 
LVL 76

Expert Comment

by:arnold
Comment Utility
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
 

Author Comment

by:jaisonshereen
Comment Utility
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
 
LVL 76

Expert Comment

by:arnold
Comment Utility
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
 

Author Comment

by:jaisonshereen
Comment Utility
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
 

Author Comment

by:jaisonshereen
Comment Utility
i am doing telnet from my windows server ...

is this blocking the ip ?
0
 

Author Comment

by:jaisonshereen
Comment Utility
is this mailserver looks like this ?

smtp.blahtest01.com
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
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
 

Author Comment

by:jaisonshereen
Comment Utility
i given the same as below:
telnet jason 25.

Still i am not able to connect , i am getting the same error .
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
Is the SMTP service running on Jason?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:jaisonshereen
Comment Utility
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
 

Author Comment

by:jaisonshereen
Comment Utility
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
 
LVL 76

Expert Comment

by:arnold
Comment Utility
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
 

Author Comment

by:jaisonshereen
Comment Utility
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
 
LVL 76

Expert Comment

by:arnold
Comment Utility
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
 

Author Comment

by:jaisonshereen
Comment Utility
<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
 
LVL 76

Expert Comment

by:arnold
Comment Utility
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
 

Author Comment

by:jaisonshereen
Comment Utility
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
 
LVL 76

Accepted Solution

by:
arnold earned 500 total points
Comment Utility
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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now