From 93c1851c355240b272ec2aaa0e7b8b06d6f83897 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sat, 10 Dec 2016 17:14:55 +0100 Subject: =?UTF-8?q?2016-09-20=20Ajout=20couleur=20en=20fonction=20de=20l'?= =?UTF-8?q?=C3=A9tat=20du=20monitoring=20pour=20les=20=C3=A9quipements=20d?= =?UTF-8?q?ans=20le=20synoptique=20en=20bas=20de=20page=20adh=C3=A9rent.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/get_node_status.php | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/api/get_node_status.php b/api/get_node_status.php index 4886bfe..83fa0e0 100644 --- a/api/get_node_status.php +++ b/api/get_node_status.php @@ -29,7 +29,7 @@ $mysqli->set_charset("utf8") or die($mysqli->error); /* Parse arguments */ $arg_keys=(array_key_exists('k', $_GET) && preg_match('/^([a-z][0-9]+,)*[a-z][0-9]+$/', $_GET['k']))?(explode(',', $_GET['k'])):array(); -/* Firlter out keys to keep only equipments */ +/* Filter out keys to keep only equipments */ $eids=array(); foreach ( $arg_keys as $k ) { if ( $k['0'] == 'e' ) { @@ -37,22 +37,24 @@ foreach ( $arg_keys as $k ) { } } -/* TODO : SQL query to get IPs from equipement WHERE id in $eids */ +if ( count($eids) === 0 ) { + die("Wrong args"); +} -/* TODO : ask moniteur.chd.sx to ping them */ +$eids_sql = "('" . implode($eids, "','") . "')"; $arr_out = array(); -foreach ( $eids as $eid ) { - - $result=42; /*TODO dummy */ - - switch ($result) { - case 0: - $color='green'; - case 1: - $color='red'; - default: - $color='purple'; +$res = $mysqli->query("SELECT id, ipmgmt_id FROM equipements WHERE id IN $eids_sql;"); +while ( $row = $res->fetch_assoc() ) { + $eid = $row['id']; + $ip = $row['ipmgmt_id']; + $color = FALSE; + if ( $ip !== NULL ) { + $url = "http://moniteur.chd.sx/etat_reseau/ping.php?ip=$ip"; + $color = file_get_contents($url); + } + if ( ! is_string($color) ) { + $color = 'black'; } $arr_out[] = array('eid'=>'e'.$eid, 'color'=>$color); } -- cgit v1.1