rss feed as a notification method

Blake Krone blakekrone at gmail.com
Wed Jun 15 22:50:44 CEST 2005


Steve what I did for this was parse the status.log file for the
different states of the machines. You could then have a PHP script
that does the parsing put all of the "critical" machines into one
array/xml/rss whatever.

For my use this worked great on my help desk website, I just list the
major servers and have an icon for up, critical, warning, and unknown.

Here's some PHP code to read the status log and put all of the servers
into an array that are accessed via the 'hostname'

***This code is from the NagVis project.****

function GetStatus()
   {
   $l="0";
   $x="0";
   $status_dat = file("/var/nagios/status.log");
   while ($status_dat[$l] != "")
     {
     $type = explode(" ",$status_dat[$l]);
     if ($type[0] == "host")
        {
        $hostname = explode("=",$status_dat[$l+1]);
        $host = trim($hostname[1]);
        $state[$host]['service'] = $host_servicename;
        $current_state = explode("=",$status_dat[$l+9]);
        $host_state = trim($current_state[1]);

        if ($host_state == "0")
        {
           $state[$host]['state'] = "UP";
        }
        else if($host_state == "1")
        {
           $state[$host]['state'] = "Warning";
        }
        else if($host_state == "2")
        {
           $state[$host]['state'] = "Critical";
        }
        else
        {
           $state[$host]['state'] = "Unknown";
        }

        $plugin_output = explode("plugin_output=",$status_dat[$l+12]);
        $state[$host]['plug_out'] = trim($plugin_output[1]);
        $l = $l + 42;
     }
   $l++	;
   }
   return($state);
}

So how I use this on my website is like this:

<?php

$status = GetStatus();

$servers[0]['Host'] = 'CTEX01';
$servers[0]['Desc'] = 'Email';
$servers[1]['Host'] = 'CTDC01';
$servers[1]['Desc'] = 'Logon';
$servers[2]['Host'] = 'CTPROD';
$servers[2]['Desc'] = 'E:\ Drives';
$servers[3]['Host'] = 'KAZBEK';
$servers[3]['Desc'] = 'Internet Proxy';
$servers[4]['Host'] = 'CTXFILES';
$servers[4]['Desc'] = 'Mac File Server';
echo <<<_TABLE
      <p>
        <span class="header">Important Systems</span>
        <font size="-2">
        <table border=0 cellspacing=4 cellspadding=0 width="100%">\n
_TABLE;

foreach($servers  as $key=>$server)
{
  $plug_out = $status[$server['Host']]['plug_out'];
  if($status[$server['Host']]['state'] == 'UP')
  {
    $this_status = "<img src=\"images/recovery.png\" alt=\"$plug_out\"
title=\"$plug_out\">";
  }
  else if($status[$server['Host']]['state'] == 'Warning')
  {
    $this_status = "<img src=\"images/warning.png\" alt=\"$plug_out\"
title=\"$plug_out\">";
  }
  else if($status[$server['Host']]['state'] == 'Critical')
  {
    $this_status = "<img src=\"images/critical.png\" alt=\"$plug_out\"
title=\"$plug_out\">";
  }
  else
  {
    $this_status = "<img src=\"images/unknown.png\" alt=\"$plug_out\"
title=\"$plug_out\">";
  }
 echo <<<_ROW
          <tr>
            <td align="left">$server[Desc] ($server[Host])</td>
            <td align="center">$this_status</td>
          </tr>\n
_ROW;

}

echo <<<_TABLE
        </table>
        </font>
      </p>\n
_TABLE;

?>

It just spits out a table like the following:

Email (CTEX01) ----------  <status icon>
Logon (CTDC01) ---------- <status icon>

That is included on the sidebar of my site.

Hope that helps you into the right direction. I was thinking of making
an RSS feed for it also, just haven't had time. If I do I'll try to
remember to send it your way.

On 6/10/05, Steve Ensley <steve.ensley at gmail.com> wrote:
> Anyone ever implemented an rss feed as a notification channel.  I'm
> thinking of this as a method to show anything in a critical state on
> our big board in the helpdesk, possibly as a marquee or scolling
> newsbar.
> 
> Any suggestions on how to approach this?
> 
> --
> Steve
> 
> It comes in PINTS?!
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
> a projector? How fast can you ride your desk chair down the office luge track?
> If you want to score the big prize, get to know the little guy.
> Play to win an NEC 61" plasma display: http://www.necitguy.com/?r
> _______________________________________________
> Nagios-users mailing list
> Nagios-users at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nagios-users
> ::: Please include Nagios version, plugin version (-v) and OS when reporting any issue.
> ::: Messages without supporting info will risk being sent to /dev/null
>


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list