Forum Discussion
dsirrine_23403
Nimbostratus
Feb 24, 2011Custom Monitor EAV with Send/Expect script
I am having an issue with my custom monitor where I am attempting to send an e-mail via telnet on port 25 using the send/expect scripted monitor. What I have so far is the following:
send telnet =IP= 25\r\n
expect 220
send HELO =IP=\r\n
expect 250
send MAIL FROM: =email=\r\n
expect 250
send RCPT TO: =email=\r\n
expect 250
send DATA\r\n
expect 354
send SUBJECT:This is a test\r\n
send \r\n
send Test\r\n
send .\r\n
expect 250
send quit\r\n
When it sends the telnet *ip* 25, it recieves the 220 ok, however, it then doesn't ignore the rest of the header lines. Is there a method to use regex or a pause statement that I can use to solve this issue in this expect script? Thank you in advance.
4 Replies
- hwidjaja_37598
Altostratus
I'm not sure whether you can just expect for 250.
SMTP uses dash (-) to seperate the status code from the response text while there are more lines remaining, eg. response from SMTP:
root@server telnet smtpserver 25
220 Ok
ehlo there
250-Line 1
250-Line 2
250-Line 3
250 This is the end of SMTP response
You might need to modify the expect string to retrieve the last line.
I'm not good with Expect, but if you need help, I can give you a sample using Perl's Net::SMTP - George_Watkins_Historic F5 AccountHi dsirrine,
It might be easier to do this as a bash script and run it as an EAV. I wrote an article on EAVs last year and it might help if you are writing any external monitors: http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/1086366/A-Brief-Introduction-To-External-Application-Verification-Monitors.aspx
-George - dsirrine_23403
Nimbostratus
I got it to work. I didn't need the initial "send telnet" as the scripted monitor does that to begin with. Unfortunately, I can't use pop/imap/etc as this is to test an exim gateway and can't necessarily "retrieve" the e-mail from the impacted system. doing an "ehlo" on localhost rounds it out nicely. Here's what I ended with:expect 220 send "HELO localhost\r\n" expect "250" send "MAIL FROM: address@localhost\r\n" expect "250" send "RCPT TO: address@localhost\r\n" expect "250" send "DATA\r\n" expect "354" send "SUBJECT:F5 LTM SMTP Health Check\r\n" send "\r\n" send "This e-mail is generated by the SMTP health check by the F5 LTM.\r\n" send ".\r\n" expect "250" send "quit\r\n" expect "221"
where
= a local account that the mailbox has been redirected to /dev/null. If /var is full, I get an error of not being able to write to spooler, otherwise, I get a 250 OK. - hoolio
Cirrostratus
Hi dsirrine,
Thanks a lot for replying with your solution. I added it to the Codeshare here:
http://devcentral.f5.com/wiki/default.aspx/AdvDesignConfig/SMTP_scripted_monitor.html
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects