Location: PHPKode > projects > Limph > limph-1.9.7/history_state.php
<?php
 /*
   Limph Is Monitoring Pingable Hosts
   Copyright (C) 2006 Jonathan Ciesla
   
   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
require_once("config.php");
require_once("functionlib.php");
session_start();
favicon();

$link = dbms_connect($dbhost, $dbuser, $dbpass, $dbname);

authentication(0,0);

echo "<link rel=stylesheet href=css.php>";

$hostname = $_GET['hostname'];
$place = $_GET['place'];
if(!$place){$place = "0";};

//state data
echo "<table align=center border=1 cellpadding=2 width=%100>";
$query = "SELECT datetime,type,data,disk FROM state WHERE hostname = '$hostname' ORDER BY datetime DESC;";
$result = dbms_query($query);

$dataset = array();
while($line = dbms_fetch_array($result, "ASSOC")){
  array_push($dataset, $line);
 };
dbms_free_result($result);

$chunks = array_chunk($dataset, 11);

echo "<tr><th colspan=4>";

echo "<form action=history_state.php method=get>";
$count = 0;
echo "<input type=submit value=\"State Data\">";
echo "<select name=place>";
foreach($chunks as $chunk){
  $flag = "";
  if($count==$place){$flag = "selected";};
  echo "<option value=$count $flag>$count";
  $count++;
};
echo "</select>";
echo "<input type=hidden name=hostname value=$hostname>";

echo "</form>";

echo "</th></tr>";
echo "<tr><th>Date/Time</th><th>Type</th><th>Data</th>";


$batch = $chunks[$place];

foreach($batch as $line){

  $bgcolor = "";
  //format diskfree data
  if($line['type']=="diskfree"){
    
    if(disk_thresh_check($hostname, $line['disk'], $line['data'])==1){$bgcolor = "bgcolor=#FFA500";};
    
    if($line['data']>=1000){$x = round(($line['data']/1000), 2) . "KB";};
    if($line['data']>=1000000){$x = round(($line['data']/1000000), 2) . "MB";};
    if($line['data']>=1000000000){$x = round(($line['data']/1000000000), 2) . "GB";};
    $line['data']= $x;
    
  };
  //format sysload data
  if($line['type']=="sysload"){
    
    if(sysload_thresh_check($hostname, $line['data'])==1){$bgcolor = "bgcolor=#FFA500";};
    
    $bits = explode("#", $line['data']);
    $line['data'] = $bits[0] . " " . $bits[1] . " " . $bits[2];
  };
  echo "<tr>";
  echo "<td>{$line['datetime']}</td>";
  echo "<td>{$line['type']}</td>";
  echo "<td align=right $bgcolor>{$line['disk']} {$line['data']}</td>";
  echo "</tr>";
};

echo "</table>";
dbms_close($link);

?>
Return current item: Limph