Location: PHPKode > projects > Limph > limph-1.9.7/history.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);

$admin_level = $_SESSION['limphadmin'];

echo "<link rel=stylesheet href=css.php>";
echo "<title>Limph: $sitetitle</title>";
echo "<h3>Limph: $sitetitle</h3>";

echo "<br />";
echo "<form action=index.php method=post>";
echo "<input type=submit value=Back />";
echo "</form>";

echo "<table align=center border=0>";
echo "<tr><td valign=top>";

echo "<table align=center border=1 cellpadding=2>";
$query = "SELECT type,datetime,hostname FROM history ORDER BY datetime DESC;";
$result = dbms_query($query);
echo "<tr><th colspan=4>History for all hosts</th></tr>";

//make this admin only
if($admin_level>=1){

  $updatetrim=$_POST['updatetrim'];
  if(($updatetrim=="yes")&&($admin_level>=1)){
    $date = dbms_escape_string($_POST['date']);
    if(valid_date($date)=="1"){
      $query = "DELETE FROM history WHERE datetime <= '$date';";
      $result = dbms_query($query);
    };
  };
  echo "<tr><th colspan=4>";
  echo "<form action=history.php method=post>";
  echo "Drop all history records before:";
  echo "<input type=text name=date size=10 value=\"yyyy-mm-dd\">";
  echo "<input type=hidden name=updatetrim value=yes>";
  echo "<input type=submit value=Submit>";
  echo "</form>";
  echo "</th></tr>";
 };

echo "<tr><th>Hostname</th><th>Type</th><th>Date/Time</th></th>";
while($line = dbms_fetch_array($result, "NUM")){
  if($line[0]=="Down"){
    $bgcolor = "bgcolor=#FF0000";
  } else {
    $bgcolor = "bgcolor=#00FF00";
  };
  echo "<tr>";
  echo "<td>{$line['2']}</td>";
  echo "<td $bgcolor>{$line['0']}</td>";
  echo "<td>{$line['1']}</td>";
  echo "</tr>";
 };
echo "</table>";

echo "</td><td align=top>";

echo "<table align=center border=1 cellpadding=2>";
$query = "SELECT datetime,hostname,type,data,disk FROM state ORDER BY datetime DESC;";
$result = dbms_query($query);
echo "<tr><th colspan=4>State for all hosts</th></tr>";

//make this admin only
if($admin_level>=1){
  
  $updatestatetrim=$_POST['updatestatetrim'];
  if(($updatestatetrim=="yes")&&($admin_level>=1)){
    $date = dbms_escape_string($_POST['date']);
    if(valid_date($date)=="1"){
      $query = "DELETE FROM state WHERE datetime <= '$date';";
      $result = dbms_query($query);
    };
  };
  
  echo "<tr><th colspan=4>";
  echo "<form action=history.php method=post>";
  echo "Drop all state data before:";
  echo "<input type=text name=date size=10 value=\"yyyy-mm-dd\">";
  echo "<input type=hidden name=updatestatetrim value=yes>";
  echo "<input type=submit value=Submit>";
  echo "</form>";
  echo "</th></tr>";
 };

echo "<tr><th>Date/Time</th><th>Hostname</th><th>Type</th><th>Data</th></th>";
while($line = dbms_fetch_array($result, "ASSOC")){
  
  $bgcolor = "";
  //format diskfree data
  if($line['type']=="diskfree"){
    
    if(disk_thresh_check($line['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($line['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['hostname']}</td>";
  echo "<td>{$line['type']}</td>";
  echo "<td align=right $bgcolor>{$line['disk']} {$line['data']}</td>";
  echo "</tr>";
  
 };

echo "</table>";

echo "</td></tr>";
echo "</table>";

dbms_free_result($result);
dbms_close($link);

echo "<br />";
echo "<form action=index.php method=post>";
echo "<input type=submit value=Back />";
echo "</form>";

?>
Return current item: Limph