diff options
Diffstat (limited to 'api')
-rw-r--r-- | api/get_node_status.php | 30 |
1 files 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); } |