Network MAP PHP
Problem this snippet solves: Hi all,
Here is a PHP script to use if you want to present you network map to a NOC or to the Application Support & Maintenance Services.
This replicate Network Map...
Published Nov 16, 2016
Version 1.0renato_martins_
Nimbostratus
Joined May 05, 2019
renato_martins_
Nimbostratus
Joined May 05, 2019
Christopher_You
Feb 21, 2017Nimbostratus
This is a work in progress for me. I am modifying the original script. Not completed yet for me - but here is my current version. I am just hacking my way along. Not a coder by any means. I don't have a lot of time right now to put a lot of effort into this.
f5 monitoring page
$f5server
";
// funtion to display images. you can download them for F5 web interface. Place them into ./images folder
function getgif($status) {
$img_path = "/images";
switch($status) {
case 'up':
$img = $img_path."/status_circle_green.png";
break;
case 'down':
$img = $img_path."/status_diamond_red.png";
break;
case 'user-down':
$img = $img_path."/status_diamond_black.png";
break;
case 'unchecked';
$img = $img_path."/status_square_blue.png";
break;
case 'available';
$img = $img_path."/status_circle_green.png";
break;
case 'offline':
$img = $img_path."/status_diamond_red.png";
break;
case 'unknown';
$img = $img_path."/status_square_blue.png";
break;
case 'unavailable';
$img = $img_path."/status_triangle_yellow.png";
break;
default:
$img = $img_path."/status_circle_outline.gif";
}
return $img;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://$user:$password@$f5server/mgmt/tm/ltm/pool/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$pools = json_decode(curl_exec($ch));
curl_setopt($ch, CURLOPT_URL, "https://$user:$password@$f5server/mgmt/tm/ltm/virtual/");
$vservers = json_decode(curl_exec($ch));
curl_setopt($ch, CURLOPT_URL, "https://$user:$password@$f5server/mgmt/tm/ltm/node/");
$nodes = json_decode(curl_exec($ch));
curl_close($ch);
//NETWORK MAP presentation
// echo "
VIRTUAL SERVERS
";
foreach ($vservers->{'items'} as $vs){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://$user:$password@$f5server/mgmt/tm/ltm/virtual/".$vs->{'name'}."/stats/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$virtual_stats = json_decode(curl_exec($ch));
curl_close($ch);
$virtual_entries = $virtual_stats->{'entries'};
$virtual_availabilityState = $virtual_entries->{'status.availabilityState'};
$virtual_stateDescription = $virtual_availabilityState->{'description'};
$img_path = getgif($virtual_stateDescription);
echo "VS:![\](.$img_path.)";
echo strtolower($vs->{'name'});
// echo " ".$vs->{'destination'};
if ($vs->{'rules'}[1] != NULL){
// echo "
";
echo $vs->{'rules'}[1];
}
foreach ($pools->{'items'} as $item ){
if ($vs->{'pool'} == $item->{'fullPath'}){
// echo "
";
echo " Pool:";
$stateurl = $item->{'membersReference'};
// echo "fullPath: ".$item->{'name'};
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://$user:$password@$f5server/mgmt/tm/ltm/pool/".$item->{'name'}."/stats/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$pool_stats = json_decode(curl_exec($ch));
curl_close($ch);
$pool_entries = $pool_stats->{'entries'};
$pool_availabilityState = $pool_entries->{'status.availabilityState'};
$pool_stateDescription = $pool_availabilityState->{'description'};
$img_path = getgif($pool_stateDescription);
echo "![\](.$img_path.)";
echo strtolower($item->{'name'});
// echo "
";
$rewrited_url = str_replace('localhost',$user.":".$password."@".$f5server,$stateurl->{'link'});
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $rewrited_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$members = json_decode(curl_exec($ch));
curl_close($ch);
foreach ($members->{'items'} as $member) {
$img_path = getgif($member->{'state'});
echo " Member:![\](.$img_path.)";
echo strtolower($member->{'name'});
echo " - (".$member->{'address'}.")";
// foreach ($nodes->{'items'} as $node){
// if ($member->{'address'} === $node->{'address'}){
// $img_path = getgif($node->{'state'});
// echo "![\](.$img_path.)";
// echo strtolower($node->{'name'});
// }
// }
//echo "
";
}
//echo "
";
}
}
echo "
";
}
// catch (Exception $e) {
// echo "Error: " .$e->;getMessage();
// }
?>