<?php
$q=$_GET['q'];
include ('connection.php');
//DB auswählen
mysql_select_db($config['db']);
$result = mysql_query("SELECT DISTINCT HA.Agent_Name, HA.Event_Time, HA.Alert_State, HA.Event_Type, HA.Alert_Text, HA.AlertID, HB.Clear_Reason, HB.Event_Time AS clrTime, HB.Event_Type AS clrType FROM (SELECT * from HawkAlertClearInfo WHERE Event_Type = 'onAlert' AND Agent_Name = '".$q."' ORDER BY Event_Time DESC LIMIT 30) HA LEFT JOIN HawkAlertClearInfo HB ON (HA.Agent_Name = HB.Agent_Name AND HA.AlertID = HB.AlertID AND HB.Event_Type not like 'onAlert') WHERE HA.Event_Type not like 'onClear'") or die("Query does not work as it should");
##############################
//Tabelle aufbauen
if(!isset($print)){
$print = ' ';
}
$print .= '<h1>Alerts</h1><a>from '.$q.'</a>';
$print .= '<br \>';
$print .= '<a>show me 10,30 or all alerts for host '.$q.'</a>';
$print .= '<table width="100%">';
$print .= '<tbody>';
$print .= '<tr>';
$print .= '<th align="left" width="125px">Time</th>';
$print .= '<th align="left" width="90px">State</th>';
$print .= '<th align="left" width="50px">Type</th>';
$print .= '<th align="left" width="400px">Alert</th>';
$print .= '<th align="left">ID</th>';
$print .= '<th align="left">Clear Reason</th>';
$print .= '<th align="left" width="125px">Clear Time</th>';
$print .= '<th align="left" width="50px">Type</th>';
$print .= '</tr>';
while($row = mysql_fetch_assoc($result)){
if ($row['Alert_State'] == "ALERT_HIGH"){
$print .= '<tr bgcolor="orange">';
}
else {
$print .= '<tr>';
}
$print .= '<td align="left">'.$row['Event_Time'].'</td>';
$print .= '<td align="left">'.$row['Alert_State'].'</td>';
$print .= '<td align="left">'.$row['Event_Type'].'</td>';
$print .= '<td align="left">'.$row['Alert_Text'].'</td>';
$print .= '<td align="left">'.$row['AlertID'].'</td>';
$print .= '<td align="left">'.$row['Clear_Reason'].'</td>';
$print .= '<td align="left">'.$row['clrTime'].'</td>';
$print .= '<td align="left">'.$row['clrType'].'</td>';
}
$print .= '</tr>';
$print .= '</tbody></table>';
print $print;
mysql_close($mysqlcon);
?>