Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/edouard/clarity
Browse files Browse the repository at this point in the history
Conflicts:
	lib/clarity.rb
	views/_toolbar.html.erb
  • Loading branch information
Jon Stevens authored and Jon Stevens committed Mar 17, 2011
2 parents 2ee3667 + 664da8d commit 98c390d
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 37 deletions.
1 change: 1 addition & 0 deletions Manifest.txt
Expand Up @@ -8,6 +8,7 @@ config/config.yml.sample
lib/clarity.rb
lib/clarity/cli.rb
lib/clarity/commands/grep_command_builder.rb
lib/clarity/commands/hostname_command_builder.rb
lib/clarity/commands/tail_command_builder.rb
lib/clarity/grep_renderer.rb
lib/clarity/process_tree.rb
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -9,7 +9,7 @@ require 'clarity'

Hoe.plugin :newgem

$hoe = Hoe.spec 'clarity' do
$hoe = Hoe.spec 'edouard-clarity' do
self.developer 'Tobias Lütke', 'tobi@shopify.com'
self.developer 'John Tajima', 'john@shopify.com'
self.summary = 'Web interface for grep and tail -f'
Expand Down
1 change: 1 addition & 0 deletions lib/clarity.rb
Expand Up @@ -13,6 +13,7 @@
require 'clarity/server'
require 'clarity/commands/grep_command_builder'
require 'clarity/commands/tail_command_builder'
require 'clarity/commands/hostname_command_builder'
require 'clarity/renderers/log_renderer'

module Clarity
Expand Down
7 changes: 7 additions & 0 deletions lib/clarity/commands/hostname_command_builder.rb
@@ -0,0 +1,7 @@
class HostnameCommandBuilder

def self.command
`hostname`
end

end
42 changes: 22 additions & 20 deletions lib/clarity/server.rb
Expand Up @@ -14,12 +14,12 @@ module Server
include EventMachine::HttpServer
include Clarity::BasicAuth
include Clarity::ChunkHttp

attr_accessor :required_username, :required_password, :relative_root
attr_accessor :log_files
attr_accessor :log_files

def self.run(options)

EventMachine::run do
EventMachine.epoll
EventMachine::start_server(options[:address], options[:port], self) do |a|
Expand All @@ -31,30 +31,32 @@ def self.run(options)

STDERR.puts "Clarity #{Clarity::VERSION} starting up."
STDERR.puts " * listening on #{options[:address]}:#{options[:port]}"

if options[:user]
STDERR.puts " * Running as user #{options[:user]}"
EventMachine.set_effective_user(options[:user])
end

STDERR.puts " * Log mask(s): #{options[:log_files].join(', ')}"

if options[:username].nil? or options[:password].nil?
STDERR.puts " * WARNING: No username/password specified. This is VERY insecure."
end

STDERR.puts
end


end
end

def process_http_request
def process_http_request
authenticate!

puts "action: #{path}"
puts "params: #{params.inspect}"

@hostname = HostnameCommandBuilder.command

case path
when '/'
respond_with(200, welcome_page)
Expand All @@ -73,21 +75,21 @@ def process_http_request
response.chunk results_page # display page header

puts "Running: #{command}"

EventMachine::popen(command, GrepRenderer) do |grepper|
@grepper = grepper
@grepper.response = response
@grepper = grepper
@grepper.response = response
end
end

when '/test'
response = respond_with_chunks
EventMachine::add_periodic_timer(1) do
response.chunk "Lorem ipsum dolor sit amet<br/>"
EventMachine::add_periodic_timer(1) do
response.chunk "Lorem ipsum dolor sit amet<br/>"
response.send_chunks
end

else
else
respond_with(200, public_file(path), :content_type => Mime.for(path))
end

Expand All @@ -99,8 +101,8 @@ def process_http_request
puts "Could not authenticate user"
headers = { "WWW-Authenticate" => %(Basic realm="Clarity")}
respond_with(401, "HTTP Basic: Access denied.\n", :content_type => 'text/plain', :headers => headers)
end
end

def error_page(error)
@error = error
render "error.html.erb"
Expand All @@ -124,7 +126,7 @@ def unbind
def authenticate!
login, pass = authentication_data

if (required_username && required_username != login) || (required_password && required_password != pass)
if (required_username && required_username != login) || (required_password && required_password != pass)
raise NotAuthenticatedError
end

Expand Down
11 changes: 6 additions & 5 deletions public/stylesheets/app.css
Expand Up @@ -4,27 +4,28 @@
* ----------------------------------------------------------------------------
*/

/* 960 reset */
/* 960 reset */
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}:focus{outline:0}ins{text-decoration:none}del{text-decoration:line-through}table{border-collapse:collapse;border-spacing:0}
/* 960 text */
body{font:13px/1.5 'Helvetica Neue',Arial,'Liberation Sans',FreeSans,sans-serif}a:focus{outline:1px dotted invert}hr{border:0 #ccc solid;border-top-width:1px;clear:both;height:0}h1{font-size:25px}h2{font-size:23px}h3{font-size:21px}h4{font-size:19px}h5{font-size:17px}h6{font-size:15px}ol{list-style:decimal}ul{list-style:disc}li{margin-left:30px}p,dl,hr,h1,h2,h3,h4,h5,h6,ol,ul,pre,table,address,fieldset{margin-bottom:20px}

/*
/*
* Toolbar Styling
*
*/


#toolbar { color: #333; font-size: 12px; min-width: 980px; height: 130px;
#toolbar { color: #333; font-size: 12px; min-width: 980px; height: 130px;
padding: 0 10px; background: #f0f0f0; border-bottom: 2px solid #000;
position:fixed; top: 0; margin: 0 -10px; width: 100%;
position:fixed; top: 0; margin: 0 -10px; width: 100%;
font-family: 'Helvetica Neue',Arial,'Liberation Sans',FreeSans,sans-serif;
}
#toolbar a { color: blue; background: none; }
#toolbar a:hover { background: none; }

#toolbar #header { height: 20px; padding: 3px 5px; margin: 0 -10px 10px; overflow:hidden; background: #333; border-bottom: 2px solid #222; color: #eee; }
#toolbar #header h1 { font-size: 16px; line-height: 20px; }
#toolbar #header h1 span { color: #aaa; }
#toolbar #header a { text-decoration: none; color: #eee; }
#toolbar #header a:hover { text-decoration: none; color: #fff;}
#toolbar .small { font-size: 11px; color: #333; font-weight: bold;}
Expand All @@ -46,7 +47,7 @@ div#option-ctrl ul li { list-style:none; margin: 0 5px 0 0; float:left; }



/* output */
/* output */
body { margin: 10px; padding-top: 130px; font-family: 'Monaco', 'Deja Vu Sans Mono', 'Inconsolata' ,'Consolas',monospace; background:#111 none repeat scroll 0 0; color:#fff; font-size:10px;}
a { color: #0f0; }
a:hover { background-color: #03c; color: white; text-decoration: none; }
Expand Down
4 changes: 2 additions & 2 deletions views/_header.html.erb
@@ -1,5 +1,5 @@
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Clarity ~ A Log Search Tool<%= relative_root %></title>
<link rel="stylesheet" href="<%= relative_root %>/stylesheets/app.css" type="text/css" media="screen">
<title>Clarity on <%= @hostname %> ~ A Log Search Tool<%= relative_root %></title>
<link rel="stylesheet" href="<%= relative_root %>/stylesheets/app.css" type="text/css" media="screen">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script src="<%= relative_root %>/javascripts/app.js" type="text/javascript"></script>
16 changes: 7 additions & 9 deletions views/_toolbar.html.erb
@@ -1,6 +1,6 @@
<div id='toolbar'>
<div id='header'>
<h1><a href="/">Clarity</a> <span class='small' style='color:#aaa'>Log Search Tool</span></h1>
<h1><a href="/">Clarity</a> <span class='small'><%= @hostname %></span></h1>
</div>

<form id='search' method='get' action='<%= relative_root %>/perform'>
Expand All @@ -9,17 +9,17 @@
<th>Action</th>
<th>Log File</th>
<th colspan=5>
Search Terms
Search Terms
<span class='note'><a href='#' onclick='Search.clear(); return false;'>clear</a></span>
</th>
<th> </th>
</tr>
<tr>
<td id='tool-selector'>
<input type='radio' name='tool' value='grep' id='grep-tool' checked='checked'> <span class='label' id='grep-label'>Search</span> <br/>
<input type='radio' name='tool' value='tail' id='tail-tool'> <span class='label' id='tail-label'>Tail</span> <br/>
<input type='radio' name='tool' value='tail' id='tail-tool'> <span class='label' id='tail-label'>Tail</span> <br/>
</td>
<td id='file-selector'>
<td id='file-selector'>
<select id='file-list' name='file'>
<% logfiles.map do |f| %>
<%= "<option value='#{f}'>#{f}</option>\n" %>
Expand All @@ -46,19 +46,17 @@
</table>
</form>
</div>


<div id="option-ctrl">
<ul>
<li><input type='checkbox' name='enable_scrolling' id='auto-scroll'/><span> Auto scroll?</span></li>
<li><input type='checkbox' name='enable_scrolling' id='auto-scroll'/><label for='auto-scroll'>Auto scroll?</label></li>
</ul>
</div>

<script>
Search.url = "<%= relative_root %>" + Search.url;
Search.init({ 'grep': <%= logfiles.map {|f| f }.to_json %>,
Search.init({ 'grep': <%= logfiles.map {|f| f }.to_json %>,
'tail': <%= logfiles.map {|f| f }.to_json %> },
<%= params.empty? ? 'null' : json_encode(params) %> );


</script>

0 comments on commit 98c390d

Please sign in to comment.