Skip to content

Instantly share code, notes, and snippets.

@theel0ja
Forked from Esmala/index.php
Last active June 10, 2017 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theel0ja/a2d3dc88ed36c94d201cb02d536880a9 to your computer and use it in GitHub Desktop.
Save theel0ja/a2d3dc88ed36c94d201cb02d536880a9 to your computer and use it in GitHub Desktop.
Network Status Monitor (Convert colour indications in image to percentages) for www.elisaip.net/utilization.shtml
<?php
// Get coords
function GetCoords() {
$coords = array();
// Non IATA:
// Espoo -> ESP
$coords["HEL2_to_TLL1"] = array(x => 405, y => 286);
$coords["HEL2_to_FRA1"] = array(x => 329, y => 240);
$coords["HEL2_to_ARN4"] = array(x => 345, y => 162);
$coords["HEL2_to_AS719"] = array(x => 413, y => 229);
$coords["HEL2_to_LED"] = array(x => 369, y => 346);
$coords["FRA1_to_HEL2"] = array(x => 325, y => 273);
$coords["TLL1_to_HEL2"] = array(x => 406, y => 338);
$coords["ARN4_to_HEL2"] = array(x => 343, y => 119);
$coords["AS719_to_HEL2"] = array(x => 420, y => 266);
$coords["LED_to_HEL2"] = array(x => 370, y => 386);
$coords["ESP1_to_AMS1"] = array(x => 402, y => 138);
$coords["ESP1_to_ARN1"] = array(x => 464, y => 100);
$coords["ESP1_to_AS719"] = array(x => 513, y => 176);
$coords["ESP1_to_TLL2"] = array(x => 535, y => 225);
$coords["AMS1_to_ESP1"] = array(x => 187, y => 152);
$coords["ARN1_to_ESP1"] = array(x => 376, y => 55);
$coords["AS719_to_ESP1"] = array(x => 510, y => 242);
$coords["TLL2_to_ESP1"] = array(x => 534, y => 305);
$coords["ARN1_to_AMS1"] = array(x => 244, y => 50);
$coords["ARN1_to_ARN4"] = array(x => 285, y => 43);
$coords["AMS1_to_ARN1"] = array(x => 196, y => 106);
$coords["ARN4_to_ARN1"] = array(x => 314, y => 62);
$coords["AMS2_to_AMS1"] = array(x => 101, y => 221);
$coords["AMS1_to_AMS2"] = array(x => 102, y => 202);
$coords["LHR_to_AMS2"] = array(x => 77, y => 316);
$coords["AMS2_to_LHR"] = array(x => 77, y => 298);
$coords["LHR_to_FRA1"] = array(x => 144, y => 324);
$coords["FRA1_to_LHR"] = array(x => 167, y => 321);
$coords["FRA2_to_FRA1"] = array(x => 202, y => 369);
$coords["FRA1_to_FRA2"] = array(x => 219, y => 341);
$coords["FRA1_to_AMS1"] = array(x => 208, y => 240);
$coords["AMS1_to_FRA1"] = array(x => 193, y => 218);
$coords["FRA2_to_TLL1"] = array(x => 277, y => 404);
$coords["TLL1_to_FRA2"] = array(x => 306, y => 403);
return $coords;
}
// Analyze the requested pixel
function NetworkUtilization($x, $y) {
$imageFile = file_get_contents("http://www.elisaip.net/pics/intbone.png");
$image = imagecreatefromstring($imageFile);
$rgb = imagecolorat($image,$x,$y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$color = $r.$g.$b;
// Is the link up?
if($color != "0" . "0". "0") {
// Link is up
$linkstate = true;
} else {
// Link is down
$linkstate = false;
}
// Get utilization
if($color == "200" . "255". "200") {
$util = 0;
} elseif($color == "100" . "255". "100") {
$util = 10;
} elseif($color == "0" . "255". "0") {
$util = 20;
} elseif($color == "50" . "255" . "50") {
$util = 30;
} elseif($color == "50" . "180". "50") {
$util = 40;
} elseif($color == "100" . "150". "0") {
$util = 50;
} elseif($color == "255" . "255". "102") {
$util = 60;
} elseif($color == "255" . "204". "102") {
$util = 70;
} elseif($color == "255" . "153". "51") {
$util = 80;
} elseif($color == "255" . "101". "51") {
$util = 90;
} elseif($color == "255" . "0". "0") {
$util = 100;
} else {
$util = undefined;
}
$status = array();
$status["state"] = $linkstate;
$status["utilization"] = $util;
return $status;
}
// Get everything using predefined pixel locations in a array
function Data() {
$coords = GetCoords();
foreach($coords as $name => $coord) {
$data[$name] = NetworkUtilization($coord["x"], $coord["y"]);
}
return $data;
}
<?php
require_once("functions.php");
$data = Data();
foreach($data as $name => $data) {
echo "<b>{$name}</b><br>State: {$data['state']}<br> Utilization: {$data['utilization']}%";
echo "<br><br>";
}
<?php
require_once("functions.php");
$data = Data();
header('Content-Type: application/json');
echo json_encode($data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment