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 of F5 web interface without the need to give any credentials to them.
How to use this snippet:
You are going to need to change your credentials (comments //changethis), and to download and change the names of the images for the vs,members,nodes status. Place the images on images folder.
Then just run the php script in your web browser and it will pull the information and present it on html.
Code :
f5 monitoring page F5 server - $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; 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){ 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 "
"; $stateurl = $item->{'membersReference'}; echo " "; echo strtolower($item->{'name'}); echo " - (".$item->{'loadBalancingMode'}.")"; 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 " "; echo strtolower($member->{'name'}); echo " - (".$member->{'address'}.")"; foreach ($nodes->{'items'} as $node){ if ($member->{'address'} === $node->{'address'}){ $img_path = getgif($node->{'state'}); echo " "; echo strtolower($node->{'name'}); } } echo "
"; } } } echo "
"; } } catch (Exception $e) { echo "Error: " .$e->getMessage(); } ?>
- renato_martins_Nimbostratus
Hi Don,
Please insert the following debug command under member foreach to check what is being retrieved as array value:
echo $pool_availabilityState;
Then compare what is inside the function getgif for the case conditions. If the the values don't match, it will default to the unknown state.