Created
January 20, 2012 17:00
-
-
Save manoot/1648394 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| ////////// | |
| // THIS FILE DUMPS THE DATA TO DATA FILE | |
| // (c) Travis Mathis - travisdmathis@gmail.com | |
| // Zabbix Report Generator v0.1 | |
| // | |
| // ERROR REPORTING | |
| error_reporting(E_ALL); | |
| set_time_limit(1800); | |
| // VARIABLES | |
| $timeperiod = $_GET['timePeriod']; | |
| $site = $_GET['siteList']; | |
| //CONFIGURATION | |
| $z_server = 'https://url/zabbix/'; | |
| $z_user = 'user'; | |
| $z_pass = 'pass'; | |
| $z_img_path = "/usr/local/share/zabbix/custom_pages/tmp_images/"; | |
| //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"; | |
| $z_login_data = "name=" .$z_user ."&password=" .$z_pass ."&enter=Enter"; | |
| // FUNCTIONS | |
| function GraphImageById ($graphid, $period = 3600) { global $z_server, $z_user, $z_pass, $z_tmp_cookies, $z_url_index, $z_url_graph, $z_url_api, $z_img_path, $z_login_data; | |
| // file names | |
| $filename_cookie = $z_tmp_cookies ."zabbix_cookie_" .$graphid .".txt"; | |
| $image_name = $z_img_path ."zabbix_graph_" .$graphid .".png"; | |
| //setup curl | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_URL, $z_url_index); | |
| curl_setopt($ch, CURLOPT_HEADER, false); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); | |
| curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
| curl_setopt($ch, CURLOPT_POST, true); | |
| curl_setopt($ch, CURLOPT_POSTFIELDS, $z_login_data); | |
| curl_setopt($ch, CURLOPT_COOKIEJAR, $filename_cookie); | |
| curl_setopt($ch, CURLOPT_COOKIEFILE, $filename_cookie); | |
| // login | |
| curl_exec($ch); | |
| // get graph | |
| curl_setopt($ch, CURLOPT_URL, $z_url_graph ."?graphid=" .$graphid ."&width=450&period=" .$period); | |
| $output = curl_exec($ch); | |
| curl_close($ch); | |
| // delete cookie | |
| header("Content-type: image/png"); | |
| unlink($filename_cookie); | |
| $fp = fopen($image_name, 'w'); | |
| fwrite($fp, $output); | |
| fclose($fp); | |
| } | |
| // 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'){ | |
| GraphImageById('421','86400'); | |
| } | |
| ?> | |
| # HEADER CONTENT NOW MALFORMED LIKE THIS | |
| <b>Host: </b>All</br><b>Time Period: </b>Day</br></br><b><center> Please wait while I generate your report, you will be forwarded automatically upon completion </b></center> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment