function showTab_cloudstack_import() { /************************** File paths **************************/ define("CLOUDSTACKCLIENT_FILE", dirname(__FILE__) . "/cloudstack_import/cloudstack-php-client/src/CloudStackClient.php"); define("CLOUDSTACKCLIENT_CONFIG", dirname(__FILE__) . "/cloudstack_import/config.php"); require CLOUDSTACKCLIENT_FILE; $config = (require CLOUDSTACKCLIENT_CONFIG); //Initialization $cloudstack = new CloudStackClient($config['endpoint'], $config['api_key'], $config['secret_key']); //Lists $vms = $cloudstack->listVirtualMachines($account = "fengce", $domainId = "9b832394-f254-4f6d-ba67-ed3979ac9fc6", $isRecursive = "true"); $vm_count = count($vms); $html = "<table>"; foreach ($vms as $vm) { $html = $html . "<tr>"; $html .= "<td>" . $vm->state . "</td>"; $html .= "<td>" . $vm->instancename . "</td>"; $html .= "<td>" . $vm->zonename . "</td>"; $html .= "<td>" . $vm->account . "</td>"; $html .= "<td>" . $vm->hypervisor . "</td>"; $html .= "<td>" . $vm->cpunumber . "</td>"; $html .= "<td>" . $vm->memory . "</td>"; $html .= "<td>" . $vm->created . "</td>"; $html .= "<td>" . $vm->displayname . "</td>"; $html .= "<td>" . $vm->hostname . "</td>"; $html .= "</tr>"; } $html .= "</table>"; echo $html; }
function showTab_cloudstack_import() { /************************** File paths **************************/ define("CLOUDSTACKCLIENT_FILE", dirname(__FILE__) . "/cloudstack_import/cloudstack-php-client/src/CloudStackClient.php"); define("CLOUDSTACKCLIENT_CONFIG", dirname(__FILE__) . "/cloudstack_import/config.php"); require CLOUDSTACKCLIENT_FILE; $config = (require CLOUDSTACKCLIENT_CONFIG); //Initialization $cloudstack = new CloudStackClient($config['endpoint'], $config['api_key'], $config['secret_key']); //Lists $vms = $cloudstack->listVirtualMachines(); foreach ($vms as $vm) { echo "{$vm->id} : {$vm->name} {$vm->state}<br>"; } }
} } if (isset($options['c']) || isset($options['critical'])) { if (is_numeric($options['c'])) { $critical = $options['c']; } else { throw new Exception("critical is not numeric - {$critical}"); } } if (isset($options['f']) && is_file($options['f'])) { $config = (require_once $options['f']); } else { echo 'UNKNOWN - No configuration file (-f) found.'; exit(3); } $cloudstack = new CloudStackClient($config['API_ENDPOINT'], $config['API_KEY'], $config['API_SECRET']); $vms = $cloudstack->listSystemVms(); $sessions = 0; foreach ($vms as $vm) { if ($vm->systemvmtype != 'consoleproxy') { continue; } $sessions += $vm->activeviewersessions; } $perfdata = "'sessions'={$sessions};"; if (isset($warning)) { $perfdata .= "{$warning};"; } if (isset($critical)) { $perfdata .= "{$critical};"; }
$stats = array('memory' => array('id' => 0, 'level' => 'pod'), 'cpu' => array('id' => 1, 'level' => 'pod'), 'storage_primary_used' => array('id' => 2, 'level' => 'pod'), 'storage_primary_allocated' => array('id' => 3, 'level' => 'pod'), 'ips_public' => array('id' => 4, 'level' => 'zone'), 'ips_private' => array('id' => 5, 'level' => 'pod'), 'storage_secondary' => array('id' => 6, 'level' => 'zone')); $options = getopt('t:w:c:n:f:h', array('help')); if (isset($options['h']) || isset($options['help'])) { usage(); } $type = !empty($options['t']) ? $options['t'] : ''; $warn = !empty($options['w']) ? $options['w'] : ''; $crit = !empty($options['c']) ? $options['c'] : ''; $name = !empty($options['n']) ? $options['n'] : ''; if (isset($options['f']) && is_file($options['f'])) { $config = (require_once $options['f']); } else { echo 'UNKNOWN - No configuration file (-f) found.'; exit(3); } $cloudstack = new CloudStackClient($config['API_ENDPOINT'], $config['API_KEY'], $config['API_SECRET']); try { if (!isset($stats[$type])) { usage("Unknown type (-t) |{$type}|"); } if (!is_numeric($warn)) { usage("Warning (-w) is not numeric {$warn}"); } if (!is_numeric($crit)) { usage("Critical (-c) is not numeric {$crit}"); } if ($warn > $crit) { throw new Exception("Warning must be less than critical"); } if (strlen($name) == 0) { usage("Name (-n) must be set and must either be a zone or pod name (depends on type |-t| variable)");
* https://github.com/jasonhancock/cloudstack-php-client */ require_once 'CloudStack/CloudStackClient.php'; $VERSION = '1.0'; $data = array('Running' => 0, 'Starting' => 0, 'Stopping' => 0, 'Destroyed' => 0); $options = getopt('f:h', array('help')); if (isset($options['h']) || isset($options['help'])) { usage(); } if (isset($options['f']) && is_file($options['f'])) { $config = (require_once $options['f']); } else { echo "UNKNOWN - No configuration file (-f) found."; exit(3); } $cloudstack = new CloudStackClient($config['API_ENDPOINT'], $config['API_KEY'], $config['API_SECRET']); $vms = $cloudstack->listVirtualMachines(); $count = 0; foreach ($vms as $vm) { if (isset($data[$vm->state])) { $data[$vm->state]++; } } $perfdata = array(); foreach ($data as $key => $value) { $perfdata[] = "{$key}={$value}"; } echo "OK - " . implode(' ', $perfdata) . '|' . implode(' ', $perfdata); exit(0); function usage() {
if (isset($options['V']) || isset($options['version'])) { version(); } if (isset($options['f']) && is_file($options['f'])) { $config = (require_once $options['f']); } else { echo 'UNKNOWN - No configuration file (-f) found.'; exit(3); } if (isset($options['t'])) { $type = $options['t']; } else { echo 'UNKNOWN - System VM type (-t) not specified.'; exit(3); } $cloudstack = new CloudStackClient($config['API_ENDPOINT'], $config['API_KEY'], $config['API_SECRET']); if ($type == 'router') { $vms = $cloudstack->listRouters(); } else { $vms = $cloudstack->listSystemVms(); } $unreachable = array(); foreach ($vms as $vm) { if ($type != 'router' && $vm->systemvmtype != $type) { continue; } // Different attributes for different types of VM $ip = $type == 'router' ? $vm->guestipaddress : $vm->publicip; $cmd = sprintf('ping -c 1 -W 1 %s > /dev/null 2>&1', $ip); exec($cmd, $output, $status); if ($status != 0) {