} 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) { $unreachable[] = $vm->name; }