/** * * @param string $data * @param array $headers * @return array */ public function exec($data = '', $headers = array()) { $c = curl_init($this->_zaebator->getOption('urlApi')); $headers[] = 'Content-Type: application/json-rpc'; // Well, ok this one isn't, but it's good to conform (sometimes) $headers[] = 'User-Agent: Zaebator v' . Zaebator::PHPAPI_VERSION; $opts = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 30, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_FRESH_CONNECT => true); // If we have headers set, put headers into our curl options if (is_array($headers) && count($headers)) { $opts[CURLOPT_HTTPHEADER] = $headers; } // This is a POST, not GET request $opts[CURLOPT_CUSTOMREQUEST] = "POST"; $opts[CURLOPT_POSTFIELDS] = is_array($data) ? http_build_query($data) : $data; // This is useful, incase we're remotely attempting to consume Zabbix's API to compress our data, save some bandwidth $opts[CURLOPT_ENCODING] = 'gzip'; // Go go gadget! Do your magic! curl_setopt_array($c, $opts); $result = curl_exec($c); if (curl_error($c) != '') { throw new Zaebator_Exception('Connection error: ' . curl_error($c) . ' ' . curl_errno($c)); } curl_close($c); return $result; }
public static function getGraphImageById(Zaebator $zaebator, $graphid, $period = 3600, $width = 1200, $height = 600) { $filename_cookie = "zabbix_cookie_" . $graphid . ".txt"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $zaebator->getOption('urlIndex')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $post_data = array('name' => $zaebator->getOption('user'), 'password' => $zaebator->getOption('password'), 'enter' => 'Enter'); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_COOKIEJAR, $filename_cookie); curl_setopt($ch, CURLOPT_COOKIEFILE, $filename_cookie); // Login curl_exec($ch); // Fetch image // &period= the time, in seconds, of the graph (so: value of 7200 = a 2 hour graph to be shown) // &stime= the time, in PHP's time() format, from when the graph should begin // &width= the width of the graph, small enough to fit on mobile devices curl_setopt($ch, CURLOPT_URL, $zaebator->getOption('urlGraph') . "?graphid=" . $graphid . "&width=" . $width . "&height={$height}" . "&period=" . $period); $output = curl_exec($ch); // Close session curl_close($ch); // Return the image return $output; }