forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvmware.inc.php
43 lines (34 loc) · 1.12 KB
/
vmware.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
class ESX {
var $vmID;
var $vmName;
var $vmState;
function EnumerateVMs( $serverIP, $community ) {
$vmList = array();
$pollCommand = "/usr/bin/snmpwalk -v 2c -c $community $serverIP .1.3.6.1.4.1.6876.2.1.1.2 | /bin/cut -d: -f4 | /bin/cut -d\\\" -f2";
exec( $pollCommand, $namesOutput );
$pollCommand = "/usr/bin/snmpwalk -v 2c -c $community $serverIP .1.3.6.1.4.1.6876.2.1.1.6 | /bin/cut -d: -f4 | /bin/cut -d\\\" -f2";
exec( $pollCommand, $statesOutput );
if ( ( count( $namesOutput ) > 0 ) && ( count( $statesOutput ) > 0 ) ) }
$tempVMs = array_combine( $namesOutput, $statesOutput );
$vmID = 0;
foreach( $tempVMs as $key => $value ) {
$vmList[$vmID] = new ESX();
$vmList[$vmID]->vmID = $vmID;
$vmList[$vmID]->vmName = $key;
$vmList[$vmID]->vmState = $value;
$vmID++;
}
return $vmList;
}
}
}
// Simulate a PHP 5.x function, remove if upgrading to PHP 5.x or higher
function array_combine($a1,$a2)
{
$maxval = count($a1);
for($i=0;$i<$maxval;$i++)
$ra[$a1[$i]] = $a2[$i];
if(isset($ra)) return $ra; else return false;
}
?>