Class: NagiosHerald::Formatter::CheckCpu
- Inherits:
-
NagiosHerald::Formatter
- Object
- NagiosHerald::Formatter
- NagiosHerald::Formatter::CheckCpu
- Includes:
- Logging
- Defined in:
- lib/nagios-herald/formatters/check_cpu.rb
Instance Attribute Summary
Attributes inherited from NagiosHerald::Formatter
#content, #sandbox, #state_type
Instance Method Summary collapse
-
#additional_details ⇒ Object
Public: Overrides Formatter::Base#additional_details.
-
#additional_info ⇒ Object
Public: Overrides Formatter::Base#additional_info.
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, #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_details ⇒ Object
Public: Overrides Formatter::Base#additional_details. Colorizes the ‘ps` output returned by the check_cpu_stats NRPE check. The output contains the top n processes by CPU similar to:
TOP 5 PROCESSES BY CPU:
%CPU TIME USER PID COMMAND
6.0 00:00:00 larry 32256 ps -eo %cpu,cputime,user,pid,args --sort -%cpu
0.7 06:22:09 nobody 12161 /usr/sbin/gmond
0.6 1-02:14:24 root 1424 [kipmi0]
0.5 00:49:52 10231 15079 mosh-server new -s -c 8 -l LANG=en_US.UTF-8
0.3 04:36:53 root 12996 /opt/extrahop/sbin/rpcapd -v -d -L -f /opt/extrahop/etc/rpcapd.ini
Returns nothing. Updates the formatter content hash.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/nagios-herald/formatters/check_cpu.rb', line 48 def additional_details section = __method__ long_output = get_nagios_var("NAGIOS_LONG#{@state_type}OUTPUT") lines = long_output.split('\n') html = [] html << "<pre>" html << lines[0] # TOP 5 PROCESSES BY CPU: html << lines[1] # %CPU TIME USER PID COMMAND html << "<font color='red'>#{lines[2]}</font>" # Color the first result red... for i in 3..lines.length-1 html << "<font color='orange'>#{lines[i]}</font>" # ...and the remainder orange. end html << "</pre>" output_string = html.join( "<br>" ) add_html(section, "<b>Additional Details</b>:") add_html(section, output_string) add_text(section, "Additional Details:\n#") add_text(section, "#{unescape_text(long_output)}\n") line_break(section) end |
#additional_info ⇒ Object
Public: Overrides Formatter::Base#additional_info. Colorizes the service output to highlight either the iowait or idle value.
WARNING CPU iowait is > 0%: user=3.60% system=0.99% iowait=0.00% idle=95.41% CRITICAL CPU idle is < 100%: user=3.02% system=3.25% iowait=0.01% idle=93.72%
Returns nothing. Updates the formatter content hash.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/nagios-herald/formatters/check_cpu.rb', line 13 def additional_info section = __method__ output = get_nagios_var("NAGIOS_#{@state_type}OUTPUT") #if match = /(?<state>\w+ CPU) (?<metric>\w+) (?<threshold_and_stats>.*) (?<iowait>iowait=.*%) (?<idle>idle=.*%)/.match(output) add_html(section, "<b>Additional Info</b>:<br>") add_text(section, "Additional Info: ") if match = /(?<state>\w+ CPU) (?<metric>iowait) (?<threshold_and_stats>.*) (?<iowait>iowait=.*%) (?<idle>idle=.*%)/.match(output) iowait_info = "#{match[:state]} <b><font color='red'>#{match[:metric]}</font></b> " iowait_info += "#{match[:threshold_and_stats]} <b><font color='red'>#{match[:iowait]}</font></b> " iowait_info += "#{match[:idle]}" add_html(section, iowait_info) elsif match = /(?<state>\w+ CPU) (?<metric>idle) (?<threshold_and_stats>.*) (?<iowait>iowait=.*%) (?<idle>idle=.*%)/.match(output) iowait_info = "#{match[:state]} <b><font color='red'>#{match[:metric]}</font></b> " iowait_info += "#{match[:threshold_and_stats]} #{match[:iowait]} " iowait_info += "<b><font color='red'>#{match[:idle]}</font></b>" add_html(section, iowait_info) else add_html(section, output) end add_text(section, output) # nothing fancy to see for text end |