Changeset 460030f4cc773badae850c94b1b4b5f6a8cd3093

Show
Ignore:
Timestamp:
12/23/11 15:24:55 (2 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1324653895 -0500
git-parent:

[ac70325cbd950a7a919b9f19306f0a84070a0894], [26c25f9649ad071d685c2846669882615f64bd22]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1324653895 -0500
Message:

Merge branch 'master' of github.com:omniti-labs/reconnoiter

Files:

Legend:

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

    raed22aa re4919ce  
    8484    <parameter name="body" 
    8585               required="optional" 
    86                allowed=".+">This regular expression is matched against the body of the response.  If a match is not found, the check will be marked as "bad."</parameter> 
     86               allowed=".+">This regular expression is matched against the body of the response. If a match is not found, the check will be marked as "bad."</parameter> 
     87    <parameter name="body_match_*" 
     88               required="optional" 
     89               allowed=".+">This regular expression is matched against the body of the response. If a match is found it is captured and added as a metric. For example, if setting is named 'body_match_foo_bar' and a match is found new metric called 'foo_bar' will be added.</parameter> 
    8790    <parameter name="extract" 
    8891               required="optional" 
     
    142145local HttpClient = require 'noit.HttpClient' 
    143146 
     147local BODY_MATCHES_PREFIX = 'body_match_' 
     148 
    144149function elapsed(check, name, starttime, endtime) 
    145150    local elapsedtime = endtime - starttime 
     
    210215    local hdr = '' 
    211216    for k,v in pairs(o) do 
    212       if hdr == '' then hdr = k .. '="' .. v .. '"'  
     217      if hdr == '' then hdr = k .. '="' .. v .. '"' 
    213218      else hdr = hdr .. ', ' .. k .. '="' .. v .. '"' end 
    214219    end 
     
    300305        else 
    301306            error(schema .. " not supported") 
    302         end  
     307        end 
    303308    end 
    304309    if schema == 'https' then 
     
    355360        local encoded = noit.base64_encode(user .. ':' .. password) 
    356361        headers["Authorization"] = "Basic " .. encoded 
    357     elseif check.config.auth_method == "Digest" or  
     362    elseif check.config.auth_method == "Digest" or 
    358363           check.config.auth_method == "Auto" then 
    359364        -- this is handled later as we need our challenge. 
     
    406411        local optclient = HttpClient:new(callbacks) 
    407412        local rv, err = optclient:connect(target, port, use_ssl) 
    408         
     413 
    409414        if rv ~= 0 then 
    410415            check.status(err or "unknown error") 
     
    430435                host = prev_host 
    431436                uri = next_location 
    432             elseif schema == 'http' then  
     437            elseif schema == 'http' then 
    433438                use_ssl = false 
    434439                if port == "" then port = 80 end 
     
    505510    end 
    506511 
     512    -- check body matches 
     513    local matches = 0 
     514    has_body_matches = false 
     515    for key, value in pairs(check.config) do 
     516      m = string.find(key, BODY_MATCHES_PREFIX) 
     517 
     518      if m == 1 then 
     519        has_body_matches = true 
     520        key = string.gsub(key, BODY_MATCHES_PREFIX, '') 
     521 
     522        local bodyre = noit.pcre(value) 
     523        local rv, m, m1 = bodyre(output or '') 
     524 
     525        if rv then 
     526          matches = matches + 1 
     527          m = m1 or m or output 
     528          if string.len(m) > max_len then 
     529            m = string.sub(m,1,max_len) 
     530          end 
     531          check.metric_string('body_match_' .. key, m) 
     532        else 
     533          check.metric_string('body_match_' .. key, nil) 
     534        end 
     535      end 
     536    end 
     537 
     538    if has_body_matches then 
     539      status = status .. ',body_matches=' .. tostring(matches) .. ' matches' 
     540    end 
     541 
    507542    -- Include body 
    508543    if include_body then