Skip to content
Browse files

Initial checkin. Finally.

  • Loading branch information...
0 parents commit 958ce7e98eaf83d8210ad97d80a7c8c02b3f095f @lozzd committed Mar 25, 2010
Showing with 929 additions and 0 deletions.
  1. +116 −0 Duration.php
  2. +92 −0 README
  3. +361 −0 inc.php
  4. +360 −0 index.php
  5. BIN loading.gif
116 Duration.php
@@ -0,0 +1,116 @@
+<?php
+/**
+ * A class for making time periods readable.
+ *
+ * This class allows for the conversion of an integer
+ * number of seconds into a readable string.
+ * For example, '121' into '2 minutes, 1 second'.
+ *
+ * If an array is passed to the class, the associative
+ * keys are used for the names of the time segments.
+ * For example, array('seconds' => 12, 'minutes' => 1)
+ * into '1 minute, 12 seconds'.
+ *
+ * This class is plural aware. Time segments with values
+ * other than 1 will have an 's' appended.
+ * For example, '1 second' not '1 seconds'.
+ *
+ * @author Aidan Lister <aidan@php.net>
+ * @version 1.2.1
+ * @link http://aidanlister.com/repos/v/Duration.php
+ */
+class Duration
+{
+ /**
+ * All in one method
+ *
+ * @param int|array $duration Array of time segments or a number of seconds
+ * @return string
+ */
+ function toString ($duration, $periods = null)
+ {
+ if($duration < 60) return "0m";
+ if (!is_array($duration)) {
+ $duration = Duration::int2array($duration, $periods);
+ }
+
+ return Duration::array2string($duration);
+ }
+
+
+ /**
+ * Return an array of date segments.
+ *
+ * @param int $seconds Number of seconds to be parsed
+ * @return mixed An array containing named segments
+ */
+ function int2array ($seconds, $periods = null)
+ {
+ // Define time periods
+ if (!is_array($periods)) {
+ $periods = array (
+ # 'years' => 31556926,
+ # 'months' => 2629743,
+ # 'ws' => 604800,
+ 'd' => 86400,
+ 'h' => 3600,
+ 'm' => 60,
+ #'s' => 1
+ );
+ }
+
+ // Loop
+ $seconds = (float) $seconds;
+ foreach ($periods as $period => $value) {
+ $count = floor($seconds / $value);
+
+ if ($count == 0) {
+ continue;
+ }
+
+ $values[$period] = $count;
+ $seconds = $seconds % $value;
+ }
+
+ // Return
+ if (empty($values)) {
+ $values = null;
+ }
+
+ return $values;
+ }
+
+
+ /**
+ * Return a string of time periods.
+ *
+ * @package Duration
+ * @param mixed $duration An array of named segments
+ * @return string
+ */
+ function array2string ($duration)
+ {
+ if (!is_array($duration)) {
+ return false;
+ }
+
+ foreach ($duration as $key => $value) {
+ //$segment_name = substr($key, 0, -1);
+ //$segment = $value . ' ' . $segment_name;
+ $segment = "$value$key";
+
+ // Plural
+ //if ($value != 1) {
+ // $segment .= 's';
+ //}
+
+ $array[] = $segment;
+ }
+
+ $str = implode(', ', $array);
+ return $str;
+ }
+
+}
+
+?>
92 README
@@ -0,0 +1,92 @@
+# Naglite2 v0.1 -
+# A full screen Nagios viewer intended for NOC/monitoring screens.
+#
+# http://laurie.denness.net - laurie@denness.net
+#
+
+DISCLAIMER: I am not a PHP developer. I am a sysadmin. This code is NOT glaramous; I didn't
+even write half of it, I adapted it from Naglite, which is available on Nagios Exchange...
+but it works. If you have any problems, I'm sure they won't be hard to solve; and I cannot be
+held responsible if you lose data, time, your girlfriend, your house, or anything else from
+using this code.
+
+
+
+0. Requirements
+
+- PHP
+- Nagios (hosted on the same box as the webserver I'm afraid)
+- A monitor dedicated for graphs, preferably hanging from the ceiling or wall.
+- A web browser running on a computer attached to said monitor
+
+
+
+1. Limitations
+
+If the format of the Nagios status.dat file changes, this will quickly become useless. The
+parsing used in these scripts relies on things being in a certain place. If you're not as lazy
+as me, you could re-write it, but there's nothing to say they won't change it completely including
+changing the names of the variables. Normally it's not too difficult to find out what's changed..
+Compare the two status files, note if there is a difference in ordering, or things added and removed.
+
+However, I rely on this every day, so I will probably update it as soon as I update Nagios. You
+should only need to modify this if you're using an OLDER version of Nagios than is the current one.
+
+
+
+2. What it does
+
+Nagios doesn't have a decent screen that works viewed from a long way away that tells you what's
+broken. This has always seemed strange to me, given it's the most used software to monitor status,
+and most places that have monitoring have NOCs, and thus screens hanging from various places.
+
+This script parses the Nagios status file directly, and produces a view that in a web browser (and
+zoomed to the appropriate level for your use) clearly shows the status of your hosts and services.
+
+It can also be used to give a good view on a mobile phone, if you're out and about.
+
+This application uses probably the only valid use of the HTML blink tag/CSS, for when a service/host
+is critical.
+
+This is how it looks: http://www.flickr.com/photos/lozzd/3210502566/
+
+
+
+3. Configuration
+
+Put the code in a folder on your web server. This web server needs access to wherever your status.dat
+file is.. I don't mind how you do that, use NFS if you have to. I run it on the same machine as I run
+Nagios anyway.
+
+Then all you need to do is check the top line ($cgi_ini) of inc.php is the path to your Nagios installation
+(more specifically you need to point it at the CGI config file, usually called cgi.cfg).
+
+
+
+4. Using Naglite2
+
+Open the folder in your browser, and with a bit of luck you should see your Nagios status.
+I suggest Google Chrome, more here:
+http://laurie.denness.net/blog/2009/05/finding-a-web-browser-for-constant-page-reloading/
+
+e.g. http://host/naglite2/
+
+
+
+5. Hints and tips
+
+If displaying this unattended constantly, it is a good idea to use a method to turn off the
+display when no one will be looking at it (if possible!). On Windows, I provide a couple of
+small .exe files, one which sleeps the displays, and one to wake them. You can then use
+Task Scheduler to have the monitors be controlled automatically. Using Linux, you can use
+dpms to sleep and wake the monitors using cron.
+
+
+6. Help me!
+
+No! Well maybe. Send me an email, and I can probably offer some advice. I apologise if not!
+
+7. Attributions
+
+This code uses Duration.php which is a class that turns durations into more friendly, readable
+versions. (e.g. 2 days ago). This was written by Aidan Lister <aidan@php.net>
361 inc.php
@@ -0,0 +1,361 @@
+<?
+
+#
+# Naglite2
+# This file does the dirty work.
+#
+#
+
+# The path to your Nagios config CGI config.
+$cgi_ini='/usr/local/nagios/etc/cgi.cfg';
+
+# Then use the above to get the path to the main config file.
+$nagios_cfg = ini_getitem($cgi_ini, "main_config_file");
+
+$nagios_check_command = ini_getitem($cgi_ini, "nagios_check_command");
+
+$refresh_rate = ini_getitem($cgi_ini, "refresh_rate");
+
+$status_file = ini_getitem($nagios_cfg, "status_file");
+
+$mypipe = popen($nagios_check_command, "r");
+$nagios_status = fgets($mypipe, 1024);
+pclose($mypipe);
+
+$pstatus["Status"] = $nagios_status;
+
+function ini_getitem($filename,$item,$length=1024,$notrim=false)
+{
+ $fp = fopen($filename,"r");
+
+ if(!$fp) {
+ return false;
+ }
+ while (!feof($fp))
+ {
+ $fileline = fgets($fp,$length);
+ if ( substr($fileline,0,strlen($item)+1) == $item . "=" )
+ if ( $notrim )
+ return substr($fileline,strlen($item)+1,strlen($fileline)-strlen($item));
+ else
+ return trim(substr($fileline,strlen($item)+1,strlen($fileline)-strlen($item)));
+ }
+ fclose($fp);
+ return false;
+}
+
+
+ function handle_program($buffer)
+ // If the line coming in from the buffer is a program status line, process it thusly.
+ {
+
+ global $nagios_check_command, $pstatus;
+ $blank=strtok($buffer,"\n");
+ $blank=strtok("\n");
+ $blank=strtok("\n");
+ $nagios_pid = substr(strtok("\n"),12);
+ $daemon_mode = substr(strtok("\n"),13);
+ $program_start= strftime ("%b %d %Y %H:%M:%S", substr(strtok("\n"),15));
+ $last_command_check = strftime ("%b %d %Y %H:%M:%S", substr(strtok("\n"),20));
+ $last_log_rotation = strftime ("%b %d %Y %H:%M:%S", substr(strtok("\n"),19));
+ $enable_notifications = substr(strtok("\n"),22);
+ #$execute_service_checks = strtok(';');
+ #$accept_passive_service_checks = strtok(';');
+ #$enable_event_handlers = strtok(';');
+ #$obsess_over_services = strtok(';');
+ #$enable_flap_detection = strtok(';');
+ #$enable_failure_prediction = strtok(';');
+ #$process_performance_data = strtok('');
+
+ $pstatus["PID"] = $nagios_pid;
+ $pstatus["Start Time"] = $program_start;
+ $pstatus["Last Command Check"] = $last_command_check;
+ $pstatus["Enable Notifications"] = ($enable_notifications) ? "On" : "Off";
+
+
+ }
+
+ function handle_host($buffer)
+ // If the line coming in from the buffer is a host status line, process it thusly. Here is some horrific parsing code.
+ {
+ global $hlist;
+
+ $nothing = strtok($buffer,"\n");
+ $host_name = substr(strtok("\n"),11);
+ $modified_attributes = substr(strtok("\n"),21);
+ $check_command = substr(strtok("\n"),15);
+ $check_period = substr(strtok("\n"),14);
+ $notification_period = substr(strtok("\n"),21);
+ $check_interval = substr(strtok("\n"),16);
+ $check_retry = substr(strtok("\n"),16);
+ $event_handler = substr(strtok("\n"),15);
+ $has_been_checked = substr(strtok("\n"),20);
+ $should_be_scheduled = substr(strtok("\n"),21);
+ $check_execution_time = substr(strtok("\n"),22);
+ $check_latency = substr(strtok("\n"),15);
+ $check_type = substr(strtok("\n"),12);
+ $status = substr(strtok("\n"),15);
+ $last_hard_state = substr(strtok("\n"),17);
+
+ $last_event_id = substr(strtok("\n"),15);
+ $current_event_id = substr(strtok("\n"),18);
+ $current_problem_id = substr(strtok("\n"),20);
+ $last_problem_id = substr(strtok("\n"),17);
+
+ $plugin_output = substr(strtok("\n"),15);
+
+ $long_plugin_output = substr(strtok("\n"),20);
+
+ $performance_data = substr(strtok("\n"),18);
+ $last_check = substr(strtok("\n"),12);
+ $next_check = substr(strtok("\n"),12);
+
+ $check_options = substr(strtok("\n"),14);
+
+ $current_attempt = substr(strtok("\n"),17);
+ $max_attempts = substr(strtok("\n"),14);
+
+# You'll need to uncomment these if you have a slightly older version of Nagios. They were in twice in the older versions.
+# $current_event_id = substr(strtok("\n"),18);
+# $last_event_id = substr(strtok("\n"),14);
+
+ $state_type = substr(strtok("\n"),12);
+ $last_state_change = substr(strtok("\n"),19);
+ $last_hard_state_change = substr(strtok("\n"),24);
+ $time_up = substr(strtok("\n"),14);
+ $time_down = substr(strtok("\n"),16);
+ $time_unreachable = substr(strtok("\n"),23);
+ $last_notification = substr(strtok("\n"),19);
+ $next_notification = substr(strtok("\n"),19);
+ $no_more_notifications = substr(strtok("\n"),23);
+ $current_notification_number = substr(strtok("\n"),29);
+
+ $current_notification_id = substr(strtok("\n"),24);
+
+ $notifications_enabled = substr(strtok("\n"),23);
+ $problem_has_been_acknowledged = substr(strtok("\n"),31);
+ $acknowledgement_type = substr(strtok("\n"),22);
+ $checks_enabled = substr(strtok("\n"),22);
+ $passive_checks_enabled = substr(strtok("\n"),24);
+ $event_handler_enabled = substr(strtok("\n"),23);
+ $flap_detection_enabled = substr(strtok("\n"),24);
+ $failure_prediction_enabled = substr(strtok("\n"),28);
+ $process_performance_data = substr(strtok("\n"),26);
+ $obsess_over_host = substr(strtok("\n"),18);
+ $last_update = strftime ("%b %d %Y %H:%M:%S", substr(strtok("\n"), 13));
+ $is_flapping = substr(strtok("\n"),13);
+ $percent_state_change = substr(strtok("\n"),22);
+ $scheduled_downtime_depth = substr(strtok("\n"),26);
+
+
+ # $last_notification = strftime ("%b %d %Y %H:%M:%S", strtok(';'));
+ $real_dur = time() - $last_state_change;
+ #$duration = gmstrftime("%H:%M:%S", $real_dur);
+ $duration = Duration::toString($real_dur);
+
+ $last_state_change = strftime ("%b %d %Y %H:%M:%S", $last_state_change);
+ $last_check = strftime ("%b %d %Y %H:%M:%S", $last_check);
+
+ // Populate the huge array with the neccesary detail about the host.
+ $hlist[$host_name]["host"]["last_update"] = $last_update;
+ $hlist[$host_name]["host"]["host_name"] = $host_name;
+ $hlist[$host_name]["host"]["status"] = $status;
+ $hlist[$host_name]["host"]["last_check"] = $last_check;
+ $hlist[$host_name]["host"]["last_state_change"] = $last_state_change;
+ $hlist[$host_name]["host"]["problem_has_been_acknowledged"] = $problem_has_been_acknowledged;
+ $hlist[$host_name]["host"]["time_up"] = $time_up;
+ $hlist[$host_name]["host"]["time_down"] = $time_down;
+ $hlist[$host_name]["host"]["time_unreachable"] = $time_unreachable;
+ $hlist[$host_name]["host"]["last_notification"] = $last_notification;
+ $hlist[$host_name]["host"]["current_notification_number"] = $current_notification_number;
+ $hlist[$host_name]["host"]["notifications_enabled"] = $notifications_enabled;
+ $hlist[$host_name]["host"]["event_handler_enabled"] = $event_handler_enabled;
+ $hlist[$host_name]["host"]["checks_enabled"] = $checks_enabled;
+ $hlist[$host_name]["host"]["flap_detection_enabled"] = $flap_detection_enabled;
+ $hlist[$host_name]["host"]["is_flapping"] = $is_flapping;
+ $hlist[$host_name]["host"]["percent_state_change"] = $percent_state_change;
+ $hlist[$host_name]["host"]["scheduled_downtime_depth"] = $scheduled_downtime_depth;
+ $hlist[$host_name]["host"]["failure_prediction_enabled"] = $failure_prediction_enabled;
+ $hlist[$host_name]["host"]["process_performance_data"] = $process_performance_data;
+ $hlist[$host_name]["host"]["plugin_output"] = $plugin_output;
+
+ $hlist[$host_name]["host"]["duration"] = $duration;
+ $hlist[$host_name]["host"]["duration_in_secs"] = $real_dur;
+
+
+ }
+
+ function handle_service($buffer)
+ // If the line coming in from the buffer is a service line, process it thusly. Enjoy some more hideous parsing.
+ {
+
+ global $hlist;
+
+ global $services_ok;
+ global $services_warning;
+ global $services_pending;
+ global $services_critical;
+ global $services_unknown;
+ global $services_ack;
+
+ $nothing = strtok($buffer,"\n");
+ $host_name = substr(strtok("\n"),11);
+ $description = substr(strtok("\n"),21);
+
+ $modified_attributes = substr(strtok("\n"),21);
+ $check_command = substr(strtok("\n"),15);
+
+ $check_period = substr(strtok("\n"),13);
+ $notification_period = substr(strtok("\n"),20);
+ $check_interval = substr(strtok("\n"),15);
+ $retry_interval = substr(strtok("\n"),15);
+
+ $event_handler = substr(strtok("\n"),15);
+ $has_been_checked = substr(strtok("\n"),18);
+ $should_be_scheduled = substr(strtok("\n"),21);
+ $execution_time = substr(strtok("\n"),22);
+ $latency = substr(strtok("\n"),15);
+ $check_type = substr(strtok("\n"),12);
+ $status = substr(strtok("\n"),15);
+ $last_hard_state = substr(strtok("\n"),17);
+
+ $last_event_id = substr(strtok("\n"),14);
+ $current_event_id = substr(strtok("\n"),18);
+ $current_problem_id = substr(strtok("\n"),20);
+ $last_problem_id = substr(strtok("\n"),17);
+
+ $current_attempt = substr(strtok("\n"),17);
+ $max_attempts = substr(strtok("\n"),14);
+
+# If you have a slightly older version of Nagios you'll need to uncomment these. They were in the file twice in older versions.
+# $last_event_id = substr(strtok("\n"),14);
+# $current_event_id = substr(strtok("\n"),18);
+
+ $state_type = substr(strtok("\n"),12);
+ $last_state_change = substr(strtok("\n"),19);
+ $last_hard_state_change = substr(strtok("\n"),24);
+ $time_ok = substr(strtok("\n"),14);
+ $time_warning = substr(strtok("\n"),19);
+ $time_unknown = substr(strtok("\n"),19);
+ $time_critical = substr(strtok("\n"),20);
+ $plugin_output = substr(strtok("\n"),15);
+
+ $long_plugin_output = substr(strtok("\n"),20);
+
+ $performance_data = substr(strtok("\n"),18);
+ $last_check = strftime ("%b %d %Y %H:%M:%S", substr(strtok("\n"),12));
+ $next_check = substr(strtok("\n"),12);
+
+ $check_options = substr(strtok("\n"),15);
+
+ $current_notification_number = substr(strtok("\n"),29);
+
+ $current_notification_id = substr(strtok("\n"),24);
+
+ $last_notification = strftime("%b %d %Y %H:%M:%S", substr(strtok("\n"),19));
+ $next_notification = substr(strtok("\n"),19);
+ $no_more_notifications = substr(strtok("\n"),23);
+ $notifications_enabled = substr(strtok("\n"),23);
+ $checks_enabled = substr(strtok("\n"),23);
+ $accept_passive_service_checks = substr(strtok("\n"),24);
+ $event_handler_enabled = substr(strtok("\n"),23);
+ $problem_has_been_acknowledged = substr(strtok("\n"),31);
+ $acknowledgement_type = substr(strtok("\n"),22);
+ $flap_detection_enabled = substr(strtok("\n"),24);
+ $failure_prediction_enabled = substr(strtok("\n"),28);
+ $process_performance_data = substr(strtok("\n"),26);
+ $obsess_over_service = substr(strtok("\n"),21);
+ $last_update = strftime ("%b %d %Y %H:%M:%S", substr(strtok("\n"),13));
+ $is_flapping = substr(strtok("\n"),13);
+ $percent_state_change = substr(strtok("\n"),22);
+ $scheduled_downtime_depth = substr(strtok("\n"),26);
+
+ $real_dur = time(0) - $last_state_change;
+ $duration = Duration::toString($real_dur);
+
+ $last_state_change = strftime ("%b %d %Y %H:%M:%S", $last_state_change);
+
+ // Populate the wonderful array with all the details about this service. Also, increment the counters for the service status.
+ if($status == "0") {
+ $status = "OK";
+ $services_ok++;
+ } else if($status == "1") {
+ $services_warning++;
+ $status = "WARNING";
+ } else if($status == "4") {
+ $services_pending++;
+ } else if($status == "2") {
+ //the table status thing ignores critial for critical hosts, so why does the counter?
+ //it doesn't anymore!
+ if ($hlist[$host_name]["host"]["status"] != "1") {
+ if (($problem_has_been_acknowledged != "1") && ($notifications_enabled == "1")) {
+ $services_critical++;
+ } else {
+ $services_ack++; }
+ }
+ $status = "CRITICAL";
+ } else if($status == "3") {
+ $services_unknown++;
+ $status = "Unknown";
+ } else {
+ $services_unknown++;
+ $status = "Unknown";
+ }
+
+
+ if($status != "OK" && $status != "PENDING") { // Don't store the lengthy details for the OK or Pending services because that seems unneccesary
+
+ $hlist[$host_name]["service"][$description]["last_update"] = $last_update;
+
+ $hlist[$host_name]["service"][$description]["host_name"] = $host_name;
+ $hlist[$host_name]["service"][$description]["description"] = $description;
+ $hlist[$host_name]["service"][$description]["status"] = $status;
+ $hlist[$host_name]["service"][$description]["current_attempt"] = $current_attempt;
+ $hlist[$host_name]["service"][$description]["max_attempts"] = $max_attempts;
+ $hlist[$host_name]["service"][$description]["state_type"] = $state_type;
+ $hlist[$host_name]["service"][$description]["last_check"] = $last_check;
+ $hlist[$host_name]["service"][$description]["next_check"] = $next_check;
+ $hlist[$host_name]["service"][$description]["check_type"] = $check_type;
+ $hlist[$host_name]["service"][$description]["checks_enabled"] = $checks_enabled;
+ $hlist[$host_name]["service"][$description]["accept_passive_service_checks"] = $accept_passive_service_checks;
+ $hlist[$host_name]["service"][$description]["event_handler_enabled"] = $event_handler_enabled;
+ $hlist[$host_name]["service"][$description]["last_state_change"] = $last_state_change;
+ $hlist[$host_name]["service"][$description]["problem_has_been_acknowledged"] = $problem_has_been_acknowledged;
+ $hlist[$host_name]["service"][$description]["last_hard_state"] = $last_hard_state;
+ $hlist[$host_name]["service"][$description]["time_ok"] = $time_ok;
+ $hlist[$host_name]["service"][$description]["time_unknown"] = $time_unknown;
+ $hlist[$host_name]["service"][$description]["time_warning"] = $time_warning;
+ $hlist[$host_name]["service"][$description]["time_critical"] = $time_critical;
+ $hlist[$host_name]["service"][$description]["last_notification"] = $last_notification;
+ $hlist[$host_name]["service"][$description]["current_notification_number"] = $current_notification_number;
+ $hlist[$host_name]["service"][$description]["notifications_enabled"] = $notifications_enabled;
+ $hlist[$host_name]["service"][$description]["latency"] = $latency;
+ $hlist[$host_name]["service"][$description]["execution_time"] = $execution_time;
+ $hlist[$host_name]["service"][$description]["flap_detection_enabled"] = $flap_detection_enabled;
+ $hlist[$host_name]["service"][$description]["is_flapping"] = $is_flapping;
+ $hlist[$host_name]["service"][$description]["percent_state_change"] = $percent_state_change;
+ $hlist[$host_name]["service"][$description]["scheduled_downtime_depth"] = $scheduled_downtime_depth;
+ $hlist[$host_name]["service"][$description]["failure_prediction_enabled"] = $failure_prediction_enabled;
+ $hlist[$host_name]["service"][$description]["process_performance_data"] = $process_performance_data;
+ $hlist[$host_name]["service"][$description]["obsess_over_service"] = $obsess_over_service;
+ $hlist[$host_name]["service"][$description]["plugin_output"] = $plugin_output;
+ $hlist[$host_name]["service"][$description]["duration"] = $duration;
+ $hlist[$host_name]["service"][$description]["duration_in_secs"] = $real_dur;
+ }
+
+
+ }
+
+ function handle_line($buffer)
+ // Take the line coming in from the buffer and work out what kind of line it is. Then send it to the relevant function for processing.
+ {
+ if(strstr($buffer, "servicestatus {")) {
+ handle_service($buffer);
+ } else if(strstr($buffer, "hoststatus {")) {
+ handle_host($buffer);
+ } else if(strstr($buffer, "programstatus {")) {
+ handle_program($buffer);
+ }
+ }
+
+?>
360 index.php
@@ -0,0 +1,360 @@
+<?
+#
+# Naglite2, a version of http://www.monitoringexchange.org/inventory/Utilities/AddOn-Projects/Frontends/NagLite
+# Modified by Laurie Denness
+#
+
+ # Try and prevent caching and provide some refresh intervals (customisable)
+ header("Pragma: no-cache");
+ if (!isset($_GET['refresh'])) { $_GET['refresh'] = "10"; }
+ header("Refresh: " .$_GET['refresh']);
+
+ # Library for calculating friendly durations
+ require_once 'Duration.php';
+
+?>
+
+
+<HTML>
+<HEAD>
+<TITLE>Nagios Monitoring System - Naglite2</TITLE>
+<style>
+body {
+ font-family: Verdana, "Tahoma", "Helvetica", "arial", "sans";
+ margin-left: 0px;
+ margin-right: 0px;
+}
+
+.smallack {
+font-size:12px;
+}
+
+</style>
+</HEAD>
+<BODY BGCOLOR="#FFFFFF">
+
+
+<?
+
+# All the hard work is done in here.
+require 'inc.php';
+
+?>
+<CENTER>
+
+<?
+ if (is_file($status_file)) {
+ $file = file_get_contents($status_file);
+ }
+
+ if (!$file) {
+ echo "<CENTER><FONT COLOR=\"red\" SIZE=+2>Failed to open Status file ";
+ echo "<br /><br /><br /><img src=\"loading.gif\"></FONT></CENTER><BR>\n";
+ die ();
+ }
+
+
+
+ $line = explode("}",$file);
+
+ for ($x = 0; $x < count($line); $x++)
+ {
+ handle_line($line[$x]);
+ }
+
+?>
+
+<?
+ if(is_array($hlist))
+ foreach (array_keys($hlist) as $hkey) {
+
+ // Print the number of hosts in the different states
+ if (isset($hlist[$hkey]["host"]["status"])) {
+ if ($hlist[$hkey]["host"]["status"] == "0") { $hlist[$hkey]["host"]["status"] = "UP"; }
+ if ($hlist[$hkey]["host"]["status"] == "1") { $hlist[$hkey]["host"]["status"] = "DOWN"; }
+ if ($hlist[$hkey]["host"]["status"] == "2") { $hlist[$hkey]["host"]["status"] = "BLOCK"; }
+
+ // Do something special for blocked hosts, as they take up too much room and they're the last
+ // thing you want filling up your screen if there's a network outage..
+ if ($hlist[$hkey]["host"]["status"] == "BLOCK")
+ {
+ $unreachable_hosts++;
+ $listofblocked[] .= $hlist[$hkey]["host"]["host_name"];
+ }
+
+ // Also acknowledged hosts take up way too much room. Give them a seperate line.
+ if ($hlist[$hkey]["host"]["problem_has_been_acknowledged"] == "1")
+ {
+ $ackhosts++;
+ $listofacked[] .= $hlist[$hkey]["host"]["host_name"];
+ }
+
+
+ // Now the mess begins.
+ if( $hlist[$hkey]["host"]["status"] != "UP" && $hlist[$hkey]["host"]["status"] != "PENDING" && $hlist[$hkey]["host"]["status"] != "BLOCK" && $hlist[$hkey]["host"]["problem_has_been_acknowledged"] != "1") {
+ $hostsout .= sprintf("<TR bgcolor=\"pink\">\n");
+ $hostsout .= sprintf("\t<TD bgcolor=\"lightgrey\">%s</TD> ", $hlist[$hkey]["host"]["host_name"]);
+ if($hlist[$hkey]["host"]["status"] == "BLOCK") {
+ $hostsout .= sprintf("<TD BGCOLOR=\"orange\">%s</TD>", $hlist[$hkey]["host"]["status"]);
+ } else if($hlist[$hkey]["host"]["problem_has_been_acknowledged"] == "1") {
+ $hostsout .= sprintf("<TD BGCOLOR=\"lightgrey\" align=\"center\"><font color=\"red\" size=\"-1\">%s (a)</font></TD>", $hlist[$hkey]["host"]["status"]);
+ } else {
+ $hostsout .= sprintf("<TD BGCOLOR=\"red\" align=\"center\"><font color=\"white\" style=\"text-decoration: blink;\">%s</font></TD>", $hlist[$hkey]["host"]["status"]);
+ }
+ $hostsout .= sprintf("<TD>%s</TD>", $hlist[$hkey]["host"]["duration"]);
+ // if you want to see when the last notificaiton was, uncomment this.
+ # $hostsout .= sprintf("<TD>%s</TD>", $hlist[$hkey]["host"]["last_notification"]);
+ $hostsout .= sprintf("<TD><small>%s</small></TD>\n", $hlist[$hkey]["host"]["plugin_output"]);
+ $hostsout .= sprintf("</TR>\n");
+ if($hlist[$hkey]["host"]["status"] == "BLOCK") { $unreachable_hosts++; }
+ else if($hlist[$hkey]["host"]["status"] == "PENDING") { $pending_hosts++; }
+ else if($hlist[$hkey]["host"]["problem_has_been_acknowledged"] == "1") { $ackhosts++; }
+ else { $badhosts++;}
+ } else {
+ $goodhosts++;
+ }
+
+ if(! $hlist[$hkey]["host"]["notifications_enabled"] ) {
+ $notifications_off .= $hlist[$hkey]["host"]["host_name"]. "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ";
+ }
+
+ // hosts done. Lets move onto the services.
+
+ $services=$hlist[$hkey]["service"];
+
+ if(is_array($services) && $hlist[$hkey]["host"]["status"] == "UP") {
+ foreach( $services as $service => $svalue) {
+
+ // Warnings are special cased to make them orange.
+ if($services[$service]["status"] == "WARNING") {
+ $servicesout_warning .= "<TR bgcolor=\"orange\">\n";
+
+ if($hlist[$hkey]["host"]["host_name"] == $lasthost && $lastalert == "warning") {
+ $servicesout_warning .= sprintf("<TD bgcolor=\"white\">&nbsp;</TD>");
+ } else {
+ $servicesout_warning .= sprintf("<TD bgcolor=\"lightgrey\">%s</TD>",
+ $hlist[$hkey]["host"]["host_name"]);
+ }
+
+ $servicesout_warning .= sprintf("<TD>%s</TD>", $services[$service]["description"]);
+ $servicesout_warning .= sprintf("<TD BGCOLOR=\"yellow\" align=\"center\">%s</TD>", $services[$service]["status"]);
+ # $servicesout_warning .= sprintf("<TD>%s</TD>", $services[$service]["last_check"]);
+ # $servicesout_warning .= sprintf("<TD>%s</TD>", $services[$service]["last_state_change"]);
+ $servicesout_warning .= sprintf("<TD>%s</TD>", $services[$service]["duration"]);
+ $servicesout_warning .= sprintf("<TD>%s/%s</TD>", $services[$service]["current_attempt"], $services[$service]["max_attempts"]);
+ # $servicesout_warning .= sprintf("<TD><font size=\"2\">%s</font></TD>", $services[$service]["plugin_output"]);
+ $servicesout_warning .= sprintf("</TR>\n");
+ $lastalert="warning";
+ // So are acknowledged and things with notifications disabled.
+ } else if (($services[$service]["problem_has_been_acknowledged"] == "1") || ($services[$service]["notifications_enabled"] == 0)) {
+ $thisalert="ack";
+ $servicesout_ack .= "<TR bgcolor=\"lightgrey\" class=\"smallack\">\n";
+
+ if(($hlist[$hkey]["host"]["host_name"] != $lasthost) || ($thisalert != $lastalert)) {
+ $servicesout_ack .= sprintf("<TD bgcolor=\"lightgrey\">%s</TD>", $hlist[$hkey]["host"]["host_name"]);
+ } else {
+ $servicesout_ack .= sprintf("<TD bgcolor=\"white\">&nbsp;</TD>");
+ }
+ $servicesout_ack .= sprintf("<TD>%s</TD>", $services[$service]["description"]);
+
+ if($services[$service]["status"] == "Unknown") {
+ $servicesout_ack .= sprintf("<TD BGCOLOR=\"lightgrey\">%s</TD>", $services[$service]["status"]);
+ } else {
+ $servicesout_ack .= sprintf("<TD BGCOLOR=\"lightgrey\"><font color=\"red\" size=\"-1\">%s (ack)</TD>", $services[$service]["status"]); }
+
+ # $servicesout_error .= sprintf("<TD>%s</TD>", $services[$service]["last_check"]);
+ #$servicesout_ack .= sprintf("<TD>%s</TD>", $services[$service]["last_state_change"]);
+ $servicesout_ack .= sprintf("<TD>%s</TD>", $services[$service]["duration"]);
+ $servicesout_ack .= sprintf("<TD>%s/%s</TD>", $services[$service]["current_attempt"], $services[$service]["max_attempts"]);
+ #$servicesout_error .= sprintf("<TD><font size=\"2\">%s</font></TD>", $services[$service]["plugin_output"]);
+ $servicesout_ack .= sprintf("</TR>\n");
+ $lastalert="ack";
+
+ // Annnd unknown stuff.
+ } else {
+ if($services[$service]["status"] == "Unknown")
+ { $servicesout_error .= "<TR bgcolor=\"lightgrey\">\n"; }
+ else
+ { $servicesout_error .= "<TR bgcolor=\"#F75D59\">\n"; }
+
+ $thisalert="error";
+
+
+ // Finally, stuff that is actually Critical.
+ if(($hlist[$hkey]["host"]["host_name"] != $lasthost) || ($thisalert != $lastalert)) {
+ $servicesout_error .= sprintf("<TD bgcolor=\"lightgrey\">%s</TD>", $hlist[$hkey]["host"]["host_name"]);
+ } else {
+ $servicesout_error .= sprintf("<TD bgcolor=\"white\">&nbsp;</TD>");
+ }
+
+
+ if($services[$service]["status"] == "Unknown") {
+ $servicesout_error .= sprintf("<TD>%s</TD>", $services[$service]["description"]);
+ } else {
+ $servicesout_error .= sprintf("<TD><font color=\"white\">%s</font></TD>", $services[$service]["description"]);
+ }
+
+ if($services[$service]["status"] == "Unknown") {
+ $servicesout_error .= sprintf("<TD BGCOLOR=\"lightgrey\">%s</TD>", $services[$service]["status"]);
+ } else {
+
+ // There is also a special case here to make SOFT notifications look less harsh. Things that are really broken get red and flashy.
+ if ($services[$service]["current_attempt"] >= $services[$service]["max_attempts"]) {
+ $servicesout_error .= sprintf("<TD BGCOLOR=\"red\" align=\"center\"><font color=\"white\" style=\"text-decoration: blink;\">%s</TD>", $services[$service]["status"]);
+ } else {
+ $servicesout_error .= sprintf("<TD align=\"center\"><font color=\"white\">%s (soft)</TD>", $services[$service]["status"]);
+ }
+
+ }
+
+ # $servicesout_error .= sprintf("<TD>%s</TD>", $services[$service]["last_check"]);
+ # $servicesout_error .= sprintf("<TD>%s</TD>", $services[$service]["last_state_change"]);
+
+
+ if($services[$service]["status"] == "Unknown") {
+ $servicesout_error .= sprintf("<TD>%s</TD>", $services[$service]["duration"]);
+ } else {
+ $servicesout_error .= sprintf("<TD><font color=\"white\">%s</font></TD>", $services[$service]["duration"]);
+ }
+
+ if($services[$service]["status"] == "Unknown") {
+ $servicesout_error .= sprintf("<TD>%s/%s</TD>", $services[$service]["current_attempt"], $services[$service]["max_attempts"]);
+ } else {
+ $servicesout_error .= sprintf("<TD><font color=\"white\">%s/%s</font></TD>", $services[$service]["current_attempt"], $services[$service]["max_attempts"]);
+ }
+
+ # $servicesout_error .= sprintf("<TD><font size=\"2\">%s</font></TD>", $services[$service]["plugin_output"]);
+ $servicesout_error .= sprintf("</TR>\n");
+ $lastalert="error";
+ }
+ // reset some variables?
+ $lastalert="none";
+ $lasthost = $hlist[$hkey]["host"]["host_name"];
+
+ }
+ }
+
+ }
+ }
+
+
+// Start the HTML magic!
+
+echo "<TABLE BORDER=0 width=99%>";
+echo "<tr><td align=left><font size=+1><b>Host Status</b></td> <td align=right><b>";
+ if($goodhosts) { echo "<FONT COLOR=\"green\">$goodhosts UP</FONT>"; }
+ if($unreachable_hosts) { echo "<FONT COLOR=\"orange\"> - $unreachable_hosts Unreachable</FONT>"; }
+ if($pending_hosts) { echo "<FONT COLOR=\"grey\"> - $pending_hosts Pending</FONT>"; }
+ if($badhosts) { echo "<FONT COLOR=\"red\"> - $badhosts DOWN</FONT>"; }
+ if($ackhosts) { echo "<FONT COLOR=\"darkgrey\"> - $ackhosts Down (Ack)</FONT>"; }
+echo "</b></td></TABLE><TABLE BORDER=0 cellspacing=2 width=98%>\n";
+
+// If there are blocked hosts, output the orange block to inform the user in a harsh fashion, but only takes up one line to keep room for everything else.
+if(count ($listofblocked) > 0) {
+ $blockedout = "<tr bgcolor=\"orange\"><td colspan=\"4\"><b>Blocked Hosts: </b>";
+ $blockedout .= implode(", ", $listofblocked);
+ $blockedout .= "</td></tr>";
+}
+
+// If there are acknowledged hosts, save some space by showing them all on one line.
+if(count ($listofacked) > 0) {
+ $ackedout = "<tr bgcolor=\"lightgrey\"><td colspan=\"4\"><b>Acknowledged:</b>";
+ $ackedout .= implode(", ", $listofacked);
+ $ackedout .= "</td></tr>";
+}
+
+
+if(strlen($hostsout)) {
+ echo "<TR bgcolor=\"lightgrey\">\n";
+ echo "\t<TH>Host</TH><TH>Status</TH><TH>Duration</TH><TH>Status Information</TH>\n";
+ echo "</TR>\n";
+ echo $hostsout;
+ echo $blockedout;
+ echo $ackedout;
+} else {
+ echo "<TR>\n<TH COLSPAN=8 BGCOLOR=\"lightgreen\"><FONT SIZE =+1>ALL MONITORED HOSTS UP</FONT></TH>\n</TR>\n";
+ echo $blockedout;
+ echo $ackedout;
+}
+ echo "</TABLE>\n";
+
+echo "<P>\n";
+
+
+ echo "<FONT SIZE=-1>\n";
+
+ echo "<TABLE BORDER=0 width=99%>";
+ echo "<tr><td align=left><font size=+1><b>Service Status</b><font size=2> &nbsp;&nbsp;</td> <td align=right><b>";
+ if($services_ok) { echo "<FONT COLOR=\"green\">$services_ok OK</FONT> "; }
+ if($services_warning) { echo "<FONT COLOR=\"orange\"> - $services_warning Warn</FONT> "; }
+ if($services_critical) { echo "<FONT COLOR=\"red\"> - $services_critical Crit</FONT> "; }
+ if($services_pending) { echo "<FONT COLOR=\"grey\"> - $services_pending Pending</FONT> "; }
+ if($services_unknown) { echo "<FONT COLOR=\"lightgrey\"> - $services_unknown Unknown</FONT> "; }
+
+
+ echo "</b></td></TABLE><TABLE BORDER=0 cellspacing=2 width=98%>\n";
+
+if(strlen($servicesout_warning) || strlen($servicesout_error)) {
+ echo "<TR bgcolor=\"lightgrey\">\n";
+ echo "\t<TH>Host</TH><TH nowrap=\"nowrap\">Service</TH><TH>Status</TH><TH>Duration</TH><TH><font size=\"-1\">Attempt</font></TH>\n";
+ echo "</TR>\n";
+ echo $servicesout_error;
+ echo $servicesout_warning;
+} else {
+ echo "<TR>\n<TH COLSPAN=8 BGCOLOR=\"lightgreen\"><FONT SIZE =+1>ALL MONITORED SERVICES OK</FONT></TH>\n</TR>\n";
+}
+
+
+
+
+
+echo "</TABLE><br /><br />";
+
+
+// Ackknowledged services get a seperate line to save space
+if(strlen($servicesout_ack)) {
+
+ echo "<TABLE BORDER=0 width=99%>";
+ echo "<tr><td align=left><b>Acknowledged Services</b><font size=2> &nbsp;&nbsp;</td> <td align=right><b>";
+ echo "<FONT COLOR=\"darkgrey\">$services_ack Acknowledged</FONT> ";
+ echo "</b></td></TABLE>\n";
+ echo "<TABLE BORDER=0 cellspacing=2 width=98%><TR bgcolor=\"lightgrey\" class=\"smallack\">\n";
+ echo "\t<TH>Host</TH><TH>Service</TH><TH>Status</TH><TH>Duration</TH><TH><font size=\"1\">A</font></TH>\n";
+ echo "</TR>\n";
+ echo $servicesout_ack;
+ echo "</TABLE>\n";
+}
+
+// Show hosts with notifications off.
+if(strlen($notifications_off)) {
+ echo "<P>\n";
+ echo "<TABLE BORDER=0 celspacing=2 width=90%>\n";
+ echo "<TR>\n<TH COLSPAN=8><FONT SIZE =+1>Hosts With Notifications Turned off</FONT></TH>\n</TR>\n";
+ echo "<TR bgcolor=\"yellow\">\n";
+ echo "<TD>".$notifications_off."</TD>\n";
+ echo "</TR></TABLE>\n";
+}
+
+ echo "<P>"; ?>
+<img src="http://cdn.last.fm/flatness/badges/lastfm_grey_small.gif" alt="this ugly code hacked into submission by lozzd" align="right">
+
+<?
+ if ($_GET["debug"] == true) {
+ echo "<br></CENTER><TABLE BORDER=0 celspacing=2 width=700 style=\"font-size:10px\">\n";
+ echo "<TR>\n<TD COLSPAN=2><b>Nagios Monitor Status</b></TD>\n</TR>\n";
+ echo "<TR>\n";
+ echo "<TD width=\"200\">Process ID: </TD>\n". "<TD>".$pstatus["PID"]."</TD>\n";
+ echo "</TR>\n";
+ echo "<TR>\n";
+ echo "<TD width=\"200\">Start Time: </TD>\n". "<TD>".$pstatus["Start Time"]."</TD>\n";
+ echo "</TR>\n";
+ echo "<TR>\n";
+ echo "<TD width=\"200\">Check Status: </TD>\n". "<TD>".$pstatus["Status"]."</TD>\n";
+ echo "</TR>\n";
+ echo "<TR>\n";
+ echo "<TD width=\"200\">Webpage refresh interval (s): </TD>\n". "<TD>".$_GET['refresh'] . "</TD>\n";
+ echo "</TR>\n";
+ echo "</TABLE>\n"; }
+?>
+</BODY>
+</HTML>
BIN loading.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 958ce7e

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