public function execute($response) { $this->getCache()->resetCache(); $result = null; $jsonObj = json_decode($response); $scrollId = $jsonObj->_scroll_id; $total = $jsonObj->hits->total; foreach ($jsonObj->hits->hits as $index => $tmpObj) { $this->getCache()->add($tmpObj); } if ($this->getCache()->getCount() != $total) { $cmdb = new CMDB(null); $queryObj = new QueryObj(); $queryObj->setQueryUrl(self::SCROLL_URL); $queryObj->setQueryString('{"scroll_id":"' . $scrollId . '"}'); $queryObj->setExecutorName(self::EXECUTOR_NAME); $cmdb->addObserver($queryObj); do { $results = $cmdb->fetch($queryObj); $tmpjsonObj = json_decode($results); foreach ($tmpjsonObj->hits->hits as $index => $tmpObj) { $this->getCache()->add($tmpObj); } unset($tmpjsonObj); } while ($this->getCache()->getCount() != $total); } if (!!($executor = GlobalArgParser::getExecutor())) { $executorObj = new $executor(); $result = $executorObj->execute($this->getCache()->get()); } return $result; }
public function getSearchResults($input) { $results = array(); $param = strtoupper($input->srchparam); $inputArray = array('exec' => 'datareturner', 'datacenter' => $param, 'rf' => array('config.fqdn', 'config.ipaddress', 'facts.ilo_ipaddress', 'cloud.rightscale.links.self')); GlobalArgParser::setGlobalArgs($inputArray); GlobalArgParser::setUser(CMDB_USER); GlobalArgParser::setPassword(CMDB_PASS); $output = QueryWrapper::execute(GlobalArgParser::getQueryLocation()); foreach ($output as $idx => $hostObj) { if (!isset($hostObj->fields) || empty($hostObj->fields)) { continue; } $fields = get_object_vars($hostObj->fields); if (empty($fields)) { continue; } $host = $fields['config.fqdn']; $results[$host]['host_name'] = $fields['config.fqdn']; $results[$host]['address'] = $fields['config.ipaddress']; if (isset($fields['facts.ilo_ipaddress']) && !empty($fields['facts.ilo_ipaddress'])) { $results[$host]['action_url'] = 'https://' . $fields['facts.ilo_ipaddress']; } elseif (isset($fields['cloud.rightscale.links.self']) && !empty($fields['cloud.rightscale.links.self'])) { $results[$host]['action_url'] = CMDBHelperFuncs::buildCloudHostUrl($fields['cloud.rightscale.links.self']); } } return $results; }
/** * __construct * * Builds any otions that need set on instantiation * * @param mixed $options * @access public * @return void */ public function __construct($options) { $user = GlobalArgParser::getUser(); $pass = GlobalArgParser::getPassword(); if ($pass == null) { throw new CMDBException(self::PASSWORD_FAILURE); } $userpwd = $user . ':' . $pass; $this->m_curl_opt = array("http_header" => array('Content-Type: application/json'), "user_pwd" => $userpwd, "user_agent" => 'Saigon CMDB Fetcher/' . VERSION, "return_transfer" => true, "ssl_verify_peer" => false, "ssl_verify_host" => false, "timeout" => 45); }
private function getHosts($mode, $param, $state = 'active') { $results = array(); if ($mode == 'physical') { $inputArray = array('exec' => 'datareturner', 'state' => $state, 'glob' => '*.' . strtolower($param) . '.host.com', 'rf' => array('config.fqdn', 'config.ipaddress', 'facts.ilo_ipaddress')); } elseif ($mode == 'virtual') { $inputArray = array('exec' => 'datareturner', 'state' => $state, 'glob' => '*.' . strtolower($param) . '.host.com', 'rf' => array('config.fqdn', 'config.ipaddress', 'cfacts.parent', 'cloud.rightscale.links.self')); } else { return array(); } GlobalArgParser::setGlobalArgs($inputArray); GlobalArgParser::setUser(CMDB_USER); GlobalArgParser::setPassword(CMDB_PASS); $output = QueryWrapper::execute(GlobalArgParser::getQueryLocation()); foreach ($output as $idx => $hostObj) { if (!isset($hostObj->fields) || empty($hostObj->fields)) { continue; } $fields = get_object_vars($hostObj->fields); if (empty($fields)) { continue; } $host = $fields['config.fqdn']; $results[$host]['host_name'] = $fields['config.fqdn']; $results[$host]['address'] = $fields['config.ipaddress']; if ($mode == 'physical') { if (isset($fields['facts.ilo_ipaddress']) && !empty($fields['facts.ilo_ipaddress'])) { $results[$host]['action_url'] = 'https://' . $fields['facts.ilo_ipaddress']; } } elseif ($mode == 'virtual') { if (isset($fields['cloud.rightscale.links.self']) && !empty($fields['cloud.rightscale.links.self'])) { $results[$host]['action_url'] = CMDBHelperFuncs::buildCloudHostUrl($fields['cloud.rightscale.links.self']); } } if (isset($fields['cfacts.parent']) && !empty($fields['cfacts.parent'])) { $results[$host]['parents'] = $fields['cfacts.parent']; } if ($mode == 'physical') { if ($state == 'active') { $results[$host]['icon_image'] = 'linux40.png'; $results[$host]['icon_image_alt'] = 'Active / Operating'; } elseif ($state == 'active_repair') { $results[$host]['icon_image'] = 'ignore_me.png'; $results[$host]['icon_image_alt'] = 'Active Repair / Ignore Me!!'; } } elseif ($mode == 'virtual') { if ($state == 'active') { $results[$host]['icon_image'] = 'xen.png'; $results[$host]['icon_image_alt'] = 'Active / Operating'; } } } return $results; }
public function __construct($queryObj) { parent::__construct($queryObj); $queryObj->setSearchParam(GlobalArgParser::getArgValue('nodepool')); $queryObj->setExecutorName('CMDBTotalReturn'); $returnField = $queryObj->getReturnField(); if (is_array($returnField)) { $returnField = implode('","', $returnField); } $queryObj->setQueryString('{"from":0,"size":' . self::QUERY_SIZE . ',"fields":["' . $returnField . '"],"query":{"query_string":{"query":"nodepool:' . strtolower($queryObj->getSearchParam()) . ' AND state:' . strtolower($queryObj->getState()) . '"}},"sort":[{"' . GlobalArgParser::getSortField() . '":{"order":"' . GlobalArgParser::getSortOrder() . '"}}]}'); }
public function getSearchResults($input) { $results = array(); $param = $input->srchparam; $inputArray = array('exec' => 'datareturner', 'glob' => $param, 'rf' => array('config.fqdn', 'facts.ipaddress_eth0', 'facts.ipaddress_eth1', 'facts.ilo_ipaddress', 'cloud.rightscale.links.self')); GlobalArgParser::setGlobalArgs($inputArray); GlobalArgParser::setUser(CMDB_USER); GlobalArgParser::setPassword(CMDB_PASS); $output = QueryWrapper::execute(GlobalArgParser::getQueryLocation()); foreach ($output as $idx => $hostObj) { if (!isset($hostObj->fields) || empty($hostObj->fields)) { continue; } $fields = get_object_vars($hostObj->fields); if (empty($fields)) { continue; } elseif (!isset($fields['facts.ipaddress_eth0']) || empty($fields['facts.ipaddress_eth0'])) { continue; } elseif (!isset($fields['facts.ipaddress_eth1']) || empty($fields['facts.ipaddress_eth1'])) { continue; } // Build out Host based on eth0 address $eth0host = $fields['config.fqdn']; $results[$eth0host]['host_name'] = $fields['config.fqdn']; $results[$eth0host]['address'] = $fields['facts.ipaddress_eth0']; if (isset($fields['facts.ilo_ipaddress']) && !empty($fields['facts.ilo_ipaddress'])) { $results[$eth0host]['action_url'] = 'https://' . $fields['facts.ilo_ipaddress']; } elseif (isset($fields['cloud.rightscale.links.self']) && !empty($fields['cloud.rightscale.links.self'])) { $results[$eth0host]['action_url'] = CMDBHelperFuncs::buildCloudHostUrl($fields['cloud.rightscale.links.self']); } // Build out Host based on eth1 address $tmpfields = preg_split("/\\./", $fields['config.fqdn']); $eth1host = array_shift($tmpfields); $eth1host .= "-eth1." . implode(".", $tmpfields); $results[$eth1host]['host_name'] = $eth1host; $results[$eth1host]['address'] = $fields['facts.ipaddress_eth1']; if (isset($fields['facts.ilo_ipaddress']) && !empty($fields['facts.ilo_ipaddress'])) { $results[$eth1host]['action_url'] = 'https://' . $fields['facts.ilo_ipaddress']; } elseif (isset($fields['cloud.rightscale.links.self']) && !empty($fields['cloud.rightscale.links.self'])) { $results[$eth1host]['action_url'] = CMDBHelperFuncs::buildCloudHostUrl($fields['cloud.rightscale.links.self']); } } return $results; }
/** * setGlobalArgs * function that actually sets all of the key => value pairs in the globalArgs array * * @param array $argArray * @static * @access public * @return void */ public static function setGlobalArgs(array $argArray) { self::$m_globalArgs = array(); foreach ($argArray as $key => $value) { if (isset(self::$m_globalArgs[$key]) && !is_array(self::$m_globalArgs[$key])) { $results = array(); array_push($results, self::$m_globalArgs[$key]); array_push($results, $value); self::$m_globalArgs[$key] = $results; } else { if (isset(self::$m_globalArgs[$key]) && is_array(self::$m_globalArgs[$key])) { array_push(self::$m_globalArgs[$key], $value); } else { self::$m_globalArgs[$key] = $value; } } } }
public function __construct($queryObj) { parent::__construct($queryObj); $queryObj->setExecutorName(GlobalArgParser::getExecutor()); $queryObj->setQueryString('{"from":0,"size":0,"fields":["_id","state","config.fqdn"],"query":{"query_string":{"query":"state:active"}},"facets":{"facet":{"terms":{"size":100,"field":"domain"}}}}'); }
public function __construct($queryObj) { $queryObj->setState(GlobalArgParser::getState()); $queryObj->setReturnField(GlobalArgParser::getReturnFields()); }