test2/e1000g0, 192.168.0.254, test-serial:7001, netmgmt->test2/netmgmt */ function print_servers() { global $site; $ch = curl_init("$site/api.php?method=get_depot"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); $data = curl_exec($ch); curl_close($ch); $d = json_decode($data, true ); $data = $d['response']; echo "hostname, Model, OS, S/N, App, Tier, Role, Rack, Postition, IPs with interface, Port Connections, Admin IP, Serial Connection, Admin Connection\n"; foreach( $data as $id => $obj ) { /* Set/Reset variables */ $rack_name = NULL; $high = ""; $low = ""; $u_size = ""; $chassis = ''; $sn = ''; $application = ''; $role = ''; $app = ''; $os = ''; $netmgmt = ''; $netmgmt_conn = ''; $ip_addr = ''; $conn_info = ''; $serial = ''; $obj_curl = curl_init("$site/api.php?method=get_object&object_id=$id&include_attrs=1&include_unset_attrs=1"); curl_setopt($obj_curl, CURLOPT_HEADER, 0); curl_setopt($obj_curl, CURLOPT_RETURNTRANSFER,true); $objdata = curl_exec($obj_curl); curl_close($obj_curl); $obj_json = json_decode($objdata, true ); $object = $obj_json['response']; if ( $object['objtype_id'] != 4 ) { continue; } /* Used to retrieve one host only */ /* if ( $obj['name'] == 'object-to-filter on' ) { print_r( $obj ); } else { continue; } */ /* Retrieve additional attributes */ $attrs = $object['attrs']; foreach ( $attrs as $attr ) { switch ( $attr['id'] ) { case 1: $sn = $attr['a_value']; break; case 2: $chassis = $attr['a_value']; break; case 4: $os = $attr['a_value']; break; default: break; } } /* Retrieve explicit tags */ $etags = $object['etags']; foreach ( $etags as $tag ) { switch( $tag['parent_id'] ) { case 31: $application = $tag['tag']; break; case 33: $role = strtoupper($tag['tag']); break; case 32: $app = strtoupper(substr($tag['tag'],0, 3 )); break; default: break; } } /* Retrieve IPv4 addresses */ $device = array(); $ipv4 = $object['ipv4']; foreach( $ipv4 as $ip ) { if ( $ip['osif'] == "netmgmt" ) { $netmgmt = $ip['addrinfo']['ip']; continue; } $device[] = $ip['osif']; $addr[] = $ip['addrinfo']['ip']; } /* Build IP string */ for ( $i = 0; $i ".$remote_oname[$i]."/".$remote_nname[$i]; } if ( $i + 1 < sizeof($remote_nname) ) { $conn_info = $conn_info."; "; } } unset($remote_name); unset($renote_oname); unset($remote_nname); /* Check object allocation */ $rack_curl = curl_init("$site/api.php?method=get_object_allocation&object_id=$id"); curl_setopt($rack_curl, CURLOPT_HEADER, 0); curl_setopt($rack_curl, CURLOPT_RETURNTRANSFER,true); $rackdata = curl_exec($rack_curl); curl_close($rack_curl); $rack_json = json_decode($rackdata, true ); $racks = $rack_json['response']['racks']; //print_r($racks); foreach ( $racks as $rack ) { $rack_name = $rack['name']; $low = 100; $high = 0; /* Kludge together a basic server height */ for ( $i = 1; $i <= $rack['height'] ; $i++ ) { if ( $rack[$i][2]['state'] == 'T' && $rack[$i][2]['object_id'] == $id ) { // echo "We're mounted!"; if ( $i > $high ) { $high = $i; } if ( $i < $low ) { $low = $i; } } } if ( $high == "" || $low == "" ) { $high = ""; $low = ""; } else { $u_size = "U$low-$high"; } } unset($racks); echo $obj['name'].", $chassis, $os, $sn, $app, $application, $role, $rack_name, $u_size, $ip_addr, $conn_info, $netmgmt, $serial, $netmgmt_conn"; echo "\n"; } // print_r($data); } print_servers(); ?>