Changeset 86512c5ce78ec987515695d6cfe5662f3cbf7e9d

Show
Ignore:
Timestamp:
01/25/11 19:08:27 (3 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1295982507 +0000
git-parent:

[5e56ceb75e135355c6810e1b12227ed0bbf25f9c]

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

more features requested by Bryan Allen

Files:

Legend:

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

    r5e56ceb r86512c5  
    4848    <parameter name="folder" required="optional" default="INBOX" 
    4949              allowed=".+">The folder that should be examined.</parameter> 
     50    <parameter name="search" required="optional" 
     51              allowed=".+">Specify an optional IMAP SEARCH operation to execute after EXAMINE</parameter> 
     52    <parameter name="fetch" required="optional" default="false" 
     53              allowed="(?:true|false|on|off)">Fetch either that highest UID or last SEARCH result.</parameter> 
    5054    <parameter name="use_ssl" required="optional" allowed="^(?:true|false|on|off)$" default="false">Upgrade TCP connection to use SSL.</parameter> 
    5155    <parameter name="ca_chain" 
     
    158162  local use_ssl = false 
    159163  local _tok = 0 
     164  local last_msg = 0 
    160165 
    161166  if check.target_ip == nil then 
     
    232237 
    233238  -- login 
     239  local lstart = noit.timeval.now() 
    234240  state, lines, errors = issue_cmd(e, tok(), "LOGIN " .. 
    235241                                             check.config.auth_user .. " " .. 
    236242                                             check.config.auth_password) 
    237   elapsed(check, "tt_login", starttime, noit.timeval.now()) 
    238   check.metric_string("login", lines[ # lines ]) 
     243  elapsed(check, "login`duration", lstart, noit.timeval.now()) 
     244  check.metric_string("login`status", lines[ # lines ]) 
    239245  if state ~= "OK" then good = false 
    240246  else 
    241247    -- Examine the mailbox 
     248    local estart = noit.timeval.now() 
    242249    state, lines, errors = issue_cmd(e, tok(), "EXAMINE " .. folder) 
    243     elapsed(check, "tt_examine", starttime, noit.timeval.now()) 
    244     check.metric_string('examine', lines[ # lines ]) 
     250    elapsed(check, 'examine`duration', estart, noit.timeval.now()) 
     251    check.metric_string('examine`status', lines[ # lines ]) 
    245252    if ok ~= "OK" then good = false 
    246253    else 
     
    252259        end 
    253260      end 
     261      last_msg = num_exists 
    254262      check.metric_uint32('messages`total', num_exists) 
    255263      check.metric_uint32('messages`recent', num_recent) 
    256264    end 
     265  end 
     266 
     267  if check.config.search ~= nil then 
     268    local search = check.config.search:gsub("[\r\n]", "") 
     269    local sstart = noit.timeval.now() 
     270    state, lines, errors = issue_cmd(e, tok(), "SEARCH " .. search) 
     271    elapsed(check, "search`duration", sstart, noit.timeval.now()) 
     272    if ok ~= "OK" then good = false 
     273    else 
     274      local matches = 0 
     275      for i,v in ipairs(lines) do 
     276        local msgs = v:match("SEARCH%s+(.+)") 
     277        if msgs ~= nil then 
     278          for m in msgs:gmatch("(%d+)") do 
     279            matches = matches + 1 
     280            last_msg = m + 0 
     281          end 
     282        end 
     283      end 
     284      check.metric_uint32('search`total', matches) 
     285    end 
     286  end 
     287 
     288  if check.config.fetch ~= nil and 
     289     (check.config.fetch == "true" or check.config.fetch == "on") and 
     290     last_msg ~= nil and 
     291     last_msg > 0 then 
     292    local fstart = noit.timeval.now() 
     293    state, lines, errors = issue_cmd(e, tok(), "FETCH " .. last_msg .. " RFC822") 
     294    elapsed(check, "fetch`duration", fstart, noit.timeval.now()) 
     295    check.metric_string('fetch`status', state) 
    257296  end 
    258297