Class: Bosh::Agent::SmtpServer
- Inherits:
-
EM::Protocols::SmtpServer
- Object
- EM::Protocols::SmtpServer
- Bosh::Agent::SmtpServer
- Defined in:
- lib/bosh_agent/smtp_server.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- MAX_MESSAGE_SIZE =
1M
1024 * 1024
- INACTIVITY_TIMEOUT =
seconds
10
Instance Method Summary collapse
- #authenticated? ⇒ Boolean
- #get_server_domain ⇒ Object
- #get_server_greeting ⇒ Object
-
#initialize(*args) ⇒ SmtpServer
constructor
A new instance of SmtpServer.
- #receive_data_chunk(c) ⇒ Object
- #receive_message ⇒ Object
-
#receive_plain_auth(user, password) ⇒ Object
We don’t really care about senders and recipients as we only use SMTP for data transport between Monit and Agent.
-
#receive_recipient(rcpt) ⇒ Object
Only accept RCPT TO if already authenticated.
-
#receive_sender(sender) ⇒ Object
Only accept MAIL FROM if already authenticated.
Constructor Details
#initialize(*args) ⇒ SmtpServer
Returns a new instance of SmtpServer.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bosh_agent/smtp_server.rb', line 12 def initialize(*args) super = args.last @logger = Config.logger @user = [:user] @password = [:password] @processor = [:processor] @authenticated = false @chunks = [ ] @msg_size = 0 # @parms come from EM:Protocols::SmtpServer @parms[:auth] = true if @user && @password self.comm_inactivity_timeout = INACTIVITY_TIMEOUT end |
Instance Method Details
#authenticated? ⇒ Boolean
39 40 41 |
# File 'lib/bosh_agent/smtp_server.rb', line 39 def authenticated? @authenticated end |
#get_server_domain ⇒ Object
35 36 37 |
# File 'lib/bosh_agent/smtp_server.rb', line 35 def get_server_domain get_server_greeting end |
#get_server_greeting ⇒ Object
31 32 33 |
# File 'lib/bosh_agent/smtp_server.rb', line 31 def get_server_greeting "BOSH Agent SMTP Server" end |
#receive_data_chunk(c) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/bosh_agent/smtp_server.rb', line 63 def receive_data_chunk(c) @msg_size += c.join.length if @msg_size > MAX_MESSAGE_SIZE send_data "552 Message too large\r\n" close_connection_after_writing else @chunks += c end end |
#receive_message ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/bosh_agent/smtp_server.rb', line 74 def unless @processor @logger.error "Failed to process alert: no alert processor provided" return false end unless @processor.respond_to?(:process_email_alert) @logger.error "Failed to process alert: alert processor should respond to :process_email_alert method" return false end = @chunks.join("\n") @chunks = [ ] # Support multiple data blocks in a single SMTP session @processor.process_email_alert() # WARNING: this MUST return true, otherwise Monit will try to send alerts over and over again true end |
#receive_plain_auth(user, password) ⇒ Object
We don’t really care about senders and recipients as we only use SMTP for data transport between Monit and Agent. However it’s handy to use the SMTP sequence constraints to enforce that only authenticated user can actually send data.
49 50 51 |
# File 'lib/bosh_agent/smtp_server.rb', line 49 def receive_plain_auth(user, password) @authenticated = (user == @user && @password == password) end |
#receive_recipient(rcpt) ⇒ Object
Only accept RCPT TO if already authenticated
59 60 61 |
# File 'lib/bosh_agent/smtp_server.rb', line 59 def receive_recipient(rcpt) authenticated? end |
#receive_sender(sender) ⇒ Object
Only accept MAIL FROM if already authenticated
54 55 56 |
# File 'lib/bosh_agent/smtp_server.rb', line 54 def receive_sender(sender) authenticated? end |