添加 index.php
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
header("Content-Type:application/json;charset=utf-8");
|
||||
// 宿主机内网IP,容器访问MySQL
|
||||
$host = "10.150.117.190";
|
||||
$user = "root";
|
||||
$pass = "hp93000";
|
||||
$dbname = "alert_mail_stat";
|
||||
|
||||
$conn = mysqli_connect($host,$user,$pass,$dbname);
|
||||
if(!$conn){
|
||||
echo json_encode(["code"=>500,"msg"=>"数据库连接失败:".mysqli_connect_error()]);
|
||||
exit;
|
||||
}
|
||||
mysqli_set_charset($conn,"utf8mb4");
|
||||
$act = $_GET['act'] ?? '';
|
||||
$today = date("Y-m-d");
|
||||
|
||||
// 当日总统计
|
||||
if($act == "day_total"){
|
||||
$sql = "SELECT
|
||||
SUM(IF(alert_type=1,1,0)) as fire_count,
|
||||
SUM(IF(alert_type=2,1,0)) as resolve_count,
|
||||
COUNT(DISTINCT instance) as instance_num
|
||||
FROM alert_log WHERE DATE(receive_time) = '$today'";
|
||||
$res = mysqli_fetch_assoc(mysqli_query($conn,$sql));
|
||||
echo json_encode($res,JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
// 告警TOP10
|
||||
if($act == "top_alert"){
|
||||
$sql = "SELECT alert_name,COUNT(*) cnt FROM alert_log WHERE DATE(receive_time)='$today' GROUP BY alert_name ORDER BY cnt DESC LIMIT 10";
|
||||
$data = [];
|
||||
$q = mysqli_query($conn,$sql);
|
||||
while($r = mysqli_fetch_assoc($q)) $data[] = $r;
|
||||
echo json_encode($data,JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
// 明细列表
|
||||
if($act == "log_list"){
|
||||
$sql = "SELECT alert_type,alert_name,instance,severity,starts_at,ends_at,receive_time
|
||||
FROM alert_log WHERE DATE(receive_time)='$today' ORDER BY receive_time DESC";
|
||||
$data = [];
|
||||
$q = mysqli_query($conn,$sql);
|
||||
while($r = mysqli_fetch_assoc($q)) $data[] = $r;
|
||||
echo json_encode($data,JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
mysqli_close($conn);
|
||||
?>
|
||||
Reference in New Issue
Block a user