Changeset a957a501c4b26cd9445027bb073d23dc07818994

Show
Ignore:
Timestamp:
03/11/10 15:00:18 (4 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1268319618 +0000
git-parent:

[84443b847306954b5fbe6c0660639efbeb472694]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1268319618 +0000
Message:

closes #193

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/modules-lua/noit/module/smtp.lua

    r7486993 ra957a50  
    5050    <parameter name="payload" required="optional" default="Subject: Testing" 
    5151               allowed=".+">Specifies the payload sent (on the wire). CR LF DOT CR LF is appended automatically.</parameter> 
     52    <parameter name="starttls" required="optional" default="false" 
     53               allowed="(?:true|false)">Specified if the client should attempt a STARTTLS upgrade</parameter> 
     54    <parameter name="ca_chain" 
     55               required="optional" 
     56               allowed=".+">A path to a file containing all the certificate authorities that should be loaded to validate the remote certificate (for SSL checks).</parameter> 
     57    <parameter name="certificate_file" 
     58               required="optional" 
     59               allowed=".+">A path to a file containing the client certificate that will be presented to the remote server (for SSL checks).</parameter> 
     60    <parameter name="key_file" 
     61               required="optional" 
     62               allowed=".+">A path to a file containing key to be used in conjunction with the cilent certificate (for SSL checks).</parameter> 
     63    <parameter name="ciphers" 
     64               required="optional" 
     65               allowed=".+">A list of ciphers to be used in the SSL protocol (for SSL checks).</parameter> 
    5266  </checkconfig> 
    5367  <examples> 
     
    135149 
    136150function initiate(module, check) 
     151  local starttime = noit.timeval.now() 
    137152  local e = noit.socket() 
    138153  local rv, err = e:connect(check.target, check.config.port or 25) 
     
    145160  end 
    146161 
     162  local try_starttls = check.config.starttls == "true" or check.config.starttls == "on" 
     163  local good = true 
    147164  local ehlo = string.format("EHLO %s", check.config.ehlo or "noit.local") 
    148165  local mailfrom = string.format("MAIL FROM:<%s>", check.config.from or "") 
     
    150167  local payload = check.config.payload or "Subject: Test\n\nHello." 
    151168  payload = payload:gsub("\n", "\r\n") 
     169  local status = 'connected' 
    152170  local action = mkaction(e, check) 
    153   if     action("banner", nil, 220) 
    154      and action("ehlo", ehlo, 250) 
    155      and action("mailfrom", mailfrom, 250) 
     171 
     172  if     not action("banner", nil, 220) 
     173      or not action("ehlo", ehlo, 250) then return end 
     174 
     175  if try_starttls then 
     176    local starttls  = action("starttls", "STARTTLS", 220) 
     177    e:ssl_upgrade_socket(check.config.certificate_file, check.config.key_file, 
     178                         check.config.ca_chain, check.config.ciphers) 
     179 
     180    local ssl_ctx = e:ssl_ctx() 
     181    if ssl_ctx ~= nil then 
     182      if ssl_ctx.error ~= nil then status = status .. ',sslerror' end 
     183      check.metric_string("cert_error", ssl_ctx.error) 
     184      check.metric_string("cert_issuer", ssl_ctx.issuer) 
     185      check.metric_string("cert_subject", ssl_ctx.subject) 
     186      check.metric_uint32("cert_start", ssl_ctx.start_time) 
     187      check.metric_uint32("cert_end", ssl_ctx.end_time) 
     188      check.metric_uint32("cert_end_in", ssl_ctx.end_time - os.time()) 
     189      if noit.timeval.seconds(starttime) > ssl_ctx.end_time then 
     190        good = false 
     191        status = status .. ',ssl=expired' 
     192      end 
     193    end 
     194 
     195    if not action("ehlo", ehlo, 250) then return end 
     196  end 
     197 
     198  if     action("mailfrom", mailfrom, 250) 
    156199     and action("rcptto", rcptto, 250) 
    157200     and action("data", "DATA", 354) 
     
    159202     and action("quit", "QUIT", 221) 
    160203  then 
    161     check.status("mail sent") 
    162     check.good() 
    163   end 
    164 end 
    165  
     204    status = status .. ',sent' 
     205  else 
     206    return 
     207  end 
     208  check.status(status) 
     209  if good then check.good() end 
     210 
     211  local elapsed = noit.timeval.now() - starttime 
     212  local elapsed_ms = math.floor(tostring(elapsed) * 1000) 
     213  check.metric("duration",  elapsed_ms) 
     214end 
     215