Skip to content

Instantly share code, notes, and snippets.

@manoot
Created January 19, 2012 20:15
Show Gist options
  • Select an option

  • Save manoot/1642313 to your computer and use it in GitHub Desktop.

Select an option

Save manoot/1642313 to your computer and use it in GitHub Desktop.
// VARIABLES
$timeperiod = $_GET['timePeriod'];
$site = $_GET['siteList'];
//CONFIGURATION
$z_server = 'https://url/zabbix/';
$z_user = 'user';
$z_pass = 'pass';
//NON CONFIGUREABLE
$z_tmp_cookies = "";
$z_url_index = $z_server ."index.php";
$z_url_graph = $z_server ."chart2.php";
$z_url_api = $z_server ."api_jsonrpc.php";
// FUNCTIONS
function getGraphImageById ($graphid, $period = 3600) {
// cookie name
$filename_cookie = $z_tmp_cookies ."zabbix_cookie_" .$graphid .".txt";
//setup curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $z_url_index);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$post_data = array('name' => $z_user,'password' => $z_pass, '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);
// get graph image
curl_setopt($ch, CURLOPT_URL, $z_url_graph ."?graphid=" .$graphid ."&width=450&period=" .$period);
$output = curl_exec($ch);
// close
curl_close($ch);
// delete cookie
unlink($filename_cookie);
//save image
return $output;
}
// Header
echo "<b>Host: </b>" .$site ."</br>";
echo "<b>Time Period: </b>" .$timeperiod ."</br></br>";
echo "<b><center> Please wait while I generate your report, you will be forwarded automatically upon completion </b></center>";
// Format Data into the Data file
if($site == 'All' and $timeperiod == 'Day'){
getGraphImageById('424','86400');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment