Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add logs view and API

  • Loading branch information...
commit 7f9456198007683b57af00ca590a79b0ed70b185 1 parent 840bfbf
Marc Lagrange authored
1  Gemfile
@@ -4,3 +4,4 @@ gem 'json'
4 4 gem 'haml'
5 5 gem 'sinatra'
6 6 gem 'actionpack', :require => "action_view" # for TextHelper
  7 +gem 'chronic'
22 naglight.rb
... ... @@ -1,6 +1,7 @@
1 1 require 'json'
2 2 require 'haml'
3 3 require 'sinatra'
  4 +require 'chronic'
4 5 require 'action_view'
5 6 require 'lib/helpers' # load our view helpers
6 7 require 'lib/utils'
@@ -9,7 +10,7 @@
9 10 # Respect the Array !
10 11 $mk_livestatus_socket_paths += ["/home/nagios/live"]
11 12 # true / false
12   -$mk_livestatus_debug=true
  13 +$mk_livestatus_debug=false
13 14 require 'lib/mk-calls' # put some MK Livestatus calls in external file
14 15 include ActionView::Helpers::TextHelper
15 16 include ActionView::Helpers::UrlHelper # Need mail_to for auto_link
@@ -67,6 +68,16 @@
67 68 haml :"services/extended_infos"
68 69 end
69 70
  71 +get '/logs' do
  72 + @title = "Logs"
  73 + @from_date = Chronic.parse("today", :guess => false, :context => :past).first
  74 + extras_headers = "Filter: time >= #{@from_date.to_i}\n"
  75 + @logs = get_mk({:table => "log",
  76 + :extras_headers => extras_headers,
  77 + :columns => ['host_name', 'message', 'options', 'plugin_output', 'service_description', 'state', 'state_type', 'time', 'type']})
  78 + haml :"other/logs"
  79 +end
  80 +
70 81 get '/contacts' do
71 82 @title = "Contacts"
72 83 @contacts = get_mk({:table => "contacts"})
@@ -115,4 +126,13 @@
115 126 filter = "Filter: host_name = #{params[:host_name]}\n"
116 127 filter << "Filter: display_name = #{service_name}\n"
117 128 return mk_array_to_hash(JSON.parse(get_mk_livestatus({:table => "services", :extras_headers => filter}))).first.to_json
  129 +end
  130 +
  131 +get '/api/get/logs' do
  132 + response.header['Content-type'] = 'application/x-javascript; charset=UTF-8'
  133 + @from_date = Chronic.parse("today", :guess => false, :context => :past).first
  134 + extras_headers = "Filter: time >= #{@from_date.to_i}\n"
  135 + return mk_array_to_hash(JSON.parse(get_mk_livestatus({:table => "log",
  136 + :extras_headers => extras_headers,
  137 + :columns => ['host_name', 'message', 'options', 'plugin_output', 'service_description', 'state', 'state_type', 'time', 'type']}))).to_json
118 138 end
13 public/css/site.css
@@ -410,6 +410,19 @@ span.current_status_pend {
410 410
411 411 }
412 412
  413 +.logs_row0 {
  414 + background-color: #E3E3E3;
  415 + font-size: 11pt;
  416 + padding-left: 5px;
  417 + padding-right: 5px;
  418 +}
  419 +
  420 +.logs_row1 {
  421 + font-size: 11pt;
  422 + padding-left: 5px;
  423 + padding-right: 5px;
  424 +}
  425 +
413 426 /* END CONTACTS */
414 427
415 428
3  views/layout.haml
@@ -45,7 +45,8 @@
45 45 %li Comments
46 46 %li Downtimes
47 47 %li Events foobarbaz
48   - %li Logs
  48 + %li
  49 + %a{:href => "/logs"} Logs
49 50 %li
50 51 %a{:href => "/contacts"} Contacts
51 52
13 views/other/logs.haml
... ... @@ -0,0 +1,13 @@
  1 +%b
  2 + Logs from
  3 + = @from_date
  4 + to present..
  5 +%br
  6 +%br
  7 +%br
  8 +- @logs.each do |a_log|
  9 + %div{:class => cycle("logs_row0", "logs_row1")}
  10 + = "[#{Time.at(a_log[:time])}]"
  11 + = a_log[:type]
  12 + = a_log[:options]
  13 +

0 comments on commit 7f94561

Please sign in to comment.
Something went wrong with that request. Please try again.