PHP scripts to display a more user-friendly overview of nagios status
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

status.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?PHP
  2. if (isset($_GET['xml'])) {
  3. header('Content-type: text/xml');
  4. } else {
  5. header('Content-type: application/xhtml+xml');
  6. }
  7. echo '<?xml version="1.0" encoding="UTF-8"?>', "\n";
  8. ?>
  9. <html xmlns="http://www.w3.org/1999/xhtml">
  10. <head>
  11. <title>Nagios status</title>
  12. <link rel="stylesheet" href="style.css" type="text/css"/>
  13. <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6/prototype.js" type="text/javascript"></script>
  14. </head>
  15. <body>
  16. <?PHP
  17. require_once(dirname(__FILE__) . '/Formats.php');
  18. require_once(dirname(__FILE__) . '/ObjectFileParser.php');
  19. require_once(dirname(__FILE__) . '/StatusFileParser.php');
  20. $op = new ObjectFileParser();
  21. $sp = new StatusFileParser();
  22. $sh = $sp->getHosts();
  23. echo '<table class="status">';
  24. echo '<tr><th>Host</th><th>Service</th><th>Status</th><th>Last check</th><th>Next check</th><th>Comment</th></tr>';
  25. $hosts = $op->getHosts();
  26. knatsort($hosts);
  27. foreach ($hosts as $hn => $host) {
  28. echo '<tr><td rowspan="', count($host['services']), '">', $host['alias'], '</td>';
  29. $first = true;
  30. foreach ($host['services'] as $sn => $service) {
  31. if ($first) {
  32. $first = false;
  33. } else {
  34. echo '<tr>';
  35. }
  36. $services = $sh[$hn]['services'][$sn];
  37. $status = translateStatus($services['current_state']);
  38. $prefix = $host['host_name'] . '_' . str_replace(' ', '_', $service['service_description']) . '_';
  39. echo '<td>', $service['service_description'], '</td>';
  40. echo '<td class="update status ', $status, '" id="', $prefix, '_status">', $status, '</td>';
  41. echo formatDate($services['last_check'], false, $prefix . 'last');
  42. echo formatDate($services['next_check'], true, $prefix . 'next');
  43. echo '<td class="update output" id="', $prefix, '_output">', trunc($services['plugin_output']), '</td>';
  44. echo '</tr>';
  45. }
  46. }
  47. echo '</table>';
  48. ?>
  49. <script src="script.js" type="text/javascript"></script>
  50. </body>
  51. </html>