Forum Discussion
for Send Email via iRule Procedures .
Hello,
I think there is a bit of interpretation missing from this iRule content, and you should be going through a method overload problem.See this line:
call thisiRule::sendEmail $errorSubject $errorBody
"thisiRule" means the iRule name what you are creating.
and in this other line:
catch {call procLibrary::sendEmail $subject $body "email1@myorg.org email2@myorg.org"}
Indicates that the overload method sendEmail, has to be in another irule e.g. "procLibrary"
So, try creating the methods in different libraries (iRules), e.g.:
"thisiRule" content:
this Irule sends an email to the F5 admin via the mailserver.myorg.org mailserver. This iRule calls the procedure in the procLibrary iRule.
when HTTP_RESPONSE {
set error 0
if {$error} {
set errorSubject "F5 Email Notification."
set errorBody "There was an event that happened. Check your F5 local log!"
call thisiRule::sendEmail $errorSubject $errorBody
}
else {
Do something cool
}
}
proc sendEmail {sourceSubject sourceBody} {
set currentTime [clock format [clock seconds] -format {%H:%M:%S}]
set todaysDate [clock format [clock seconds] -format {%m-%d:%Y}]
set subject ${sourceSubject}
set body "${sourceBody}\r\n\r\n ${currentTime}hrs on ${todaysDate}.\r\n\r\n This is an automated email sent via the this iRule iRule.\r\n\r\nSincerely,\r\nYour F5 Support Team"
log local0. $body
catch {call procLibrary::sendEmail $subject $body "email1@myorg.org email2@myorg.org"}
}
"procLibrary" irule content:
This procedure library procLibrary sends an email using a sideband connection to your organizations email server.
It has 3 input parameters; subject, body and additional email addresses. The calling procedure needs to seperate the additional
emails with a " ". Example "email1@myorg.org email2@myorg.org".
proc sendEmail {sourceSubject sourceEmailBody sourceAddEmailAddress} {
upvar 1 $sourceSubject n1
upvar 1 $sourceEmailBody n2
upvar 1 $sourceAddEmailAddress n3
set email_debug 0
set hostName [info hostname]
set mailFrom "root@$hostname"
set mailTo "admin@myorg.org"
set mailServer "xxx.xxx.xxx.xxx:25"
set subject $sourceSubject
set emailBody $sourceEmailBody
set addEmailAddress ""
if {$sourceAddEmailAddress ne ""} {
append sourceAddEmailAddress "${mailTo}"
foreach emailAddress $sourceAddEmailAddress {
set emailConn [connect -timeout 2000 -idle 10 -status conn_status $mailServer]
if {$email_debug} {log local0. "connect_status: $conn_status"}
set emailData "HELO mailserver.myorg.org\r\nMAIL FROM: $mailFrom\r\nRCPT To: ${emailAddress}\r\nDATA\r\nSUBJECT: \r\n\r\n\r\n$emailBody\r\n.\r\n"
set send_info [send -timeout 2000 -status send_status $emailConn $emailData]
if {$email_debug} {log local0. "emailData: $emailData"}
if {$email_debug} {log local0. "send_status: $send_status"}
set recv_data [recv -timeout 2000 -status recv_status $emailConn]
if {$email_debug} {log local0. "recv_Data: $recv_data"}
close $emailConn
if {$email_debug} {log local0. "EmailTo: $emailAddress"}
}
}
else {
if {$email_debug} {log local0. "connect_status: $conn_status"}
set emailData "HELO mailserver.myorg.org\r\nMAIL FROM: $mailFrom\r\nRCPT To: ${emailAddress}\r\nDATA\r\nSUBJECT: \r\n\r\n\r\n$emailBody\r\n.\r\n"
set send_info [send -timeout 2000 -status send_status $emailConn $emailData]
if {$email_debug} {log local0. "emailData: $emailData"}
if {$email_debug} {log local0. "send_status: $send_status"}
set recv_data [recv -timeout 2000 -status recv_status $emailConn]
if {$email_debug} {log local0. "recv_Data: $recv_data"}
close $emailConn
}
}
Particulary, I prefer to rewrite all this content to one iRule, if use it to simple thing.
I hope it helps you.I am trying to make the simplest imaginable iRule that sends an email when a VIP gets hit. I do not want to use multiple iRules. How do I write one like that?
Recent Discussions
Related Content
* 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