Class: NagiosHerald::Formatter::CheckGraphiteGraph

Inherits:
NagiosHerald::Formatter show all
Includes:
Logging
Defined in:
lib/nagios-herald/formatters/check_graphite_graph.rb

Instance Attribute Summary

Attributes inherited from NagiosHerald::Formatter

#content, #sandbox, #state_type

Instance Method Summary collapse

Methods included from Logging

#configure_logger_for, #logger, #logger_for

Methods inherited from NagiosHerald::Formatter

#ack_info, #action_url, #add_attachment, #add_html, #add_short_text, #add_text, #additional_details, #alert_ack_url, #clean_sandbox, #delete_html, #delete_section_for_type, #delete_short_text, #delete_text, #end_section, formatters, #generate_ack_content, #generate_content, #generate_message_content, #generate_problem_content, #generate_recovery_content, #generate_section, #generate_subject, #get_sandbox_path, #host_info, inherited, #initialize, #line_break, #notes, #notification_info, #recipients_email_link, #short_ack_info, #short_state_detail, #start_section, #state_info

Methods included from Util

#get_nagios_var, get_script_path, load_helper, underscore_to_camel_case, #unescape_text

Constructor Details

This class inherits a constructor from NagiosHerald::Formatter

Instance Method Details

#additional_infoObject

Public: Overrides Formatter::Base#additional_info. Returns nothing. Updates the formatter content hash.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/nagios-herald/formatters/check_graphite_graph.rb', line 30

def additional_info
  section = __method__
  output = get_nagios_var("NAGIOS_#{@state_type}OUTPUT")
  # Output is formmated like: Current value: 18094.25, warn threshold: 100.0, crit threshold: 1000.0
  add_text(section, "Additional Info:\n #{unescape_text(output)}\n\n") if output
  output_match = output.match(/Current value: (?<current_value>[^,]*), warn threshold: (?<warn_threshold>[^,]*), crit threshold: (?<crit_threshold>[^,]*)/)
  if output_match
    add_html(section, "Current value: <b><font color='red'>#{output_match['current_value']}</font></b>, warn threshold: <b>#{output_match['warn_threshold']}</b>, crit threshold: <b><font color='red'>#{output_match['crit_threshold']}</font></b><br><br>")
  else
    add_html(section, "<b>Additional Info</b>:<br> #{output}<br><br>") if output
  end

  # Get Graphite graphs.
  # Extract the Graphite URL from NAGIOS_SERVICECHECKCOMMAND
  service_check_command = get_nagios_var("NAGIOS_SERVICECHECKCOMMAND")
  url = service_check_command.split(/!/)[-1].gsub(/'/, '')
  graphite_graphs = get_graphite_graphs(url)
  from_match = url.match(/from=(?<from>[^&]*)/)
  if from_match
    add_html(section, "<b>View from '#{from_match['from']}' ago</b><br>")
  else
   add_html(section, "<b>View from the time of the Nagios check</b><br>")
  end
  add_attachment graphite_graphs[0]    # The original graph.
  add_html(section, %Q(<img src="#{graphite_graphs[0]}" alt="graphite_graph" /><br><br>))
  add_html(section, '<b>24-hour View</b><br>')
  add_attachment graphite_graphs[1]    # The 24-hour graph.
  add_html(section, %Q(<img src="#{graphite_graphs[1]}" alt="graphite_graph" /><br><br>))
end

#get_graphite_graphs(url) ⇒ Object

Public: Retrieves Graphite graphs for the endpoint the check queried. url - The URL for the Graphite endpoint the check queried. Returns the file names of all retrieved graphs. These can be attached to the message.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/nagios-herald/formatters/check_graphite_graph.rb', line 13

def get_graphite_graphs(url)
  begin
    graphite = NagiosHerald::Helpers::GraphiteGraph.new
    show_historical = true
    graphs =  graphite.get_graph(url, @sandbox, show_historical)
    return graphs
  rescue Exception => e
    logger.error "Exception encountered retrieving Graphite graphs - #{e.message}"
    e.backtrace.each do |line|
      logger.error "#{line}"
    end
    return []
  end
end