/** * 写入日志 * * @param string $strFileName * @param string $strType * @param string $strMSG * @param string $strExtra * @param string $line */ public static function out($strFileName = "", $strType = "I", $strMSG = "", $strExtra = "", $line = "") { if ($strType == "") { $strType = "I"; } if (!is_writable(self::$logpath)) { @chmod(self::$logpath, 0777); } $logfile = rtrim(self::$logpath, '/') . '/' . $strFileName . '_' . date("ymd") . '.log'; if (file_exists($logfile) && !is_writable($logfile)) { @chmod($logfile, 0644); } $handle = @fopen($logfile, "a+"); if ($handle) { // 判断是否CLI if (isset($_SERVER['SHELL']) && !isset($_SERVER['HTTP_HOST'])) { $arg = ""; if ($_SERVER['argc'] > 0) { $arg = " ARGV:" . json_encode($_SERVER['argv']); } $strContent = "[" . date("Y-m-d H:i:s") . "] [" . strtoupper($strType) . "] [CLI] MSG:[" . $strMSG . "]" . $strExtra . " Location:" . $_SERVER["SCRIPT_FILENAME"] . $arg . ($line ? " Line:" . $line : "") . "\n"; } else { $strContent = "[" . date("Y-m-d H:i:s") . "] [" . strtoupper($strType) . "] [" . Sys_Tools::getRemoteAddr() . "] MSG:[" . $strMSG . "]" . $strExtra . " Location:" . $_SERVER["SCRIPT_FILENAME"] . ($line ? " Line:" . $line : "") . " QUERY_STRING:" . $_SERVER["QUERY_STRING"] . " HTTP_REFERER:" . (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "") . " User-Agent:" . $_SERVER["HTTP_USER_AGENT"] . "\n"; } if (!fwrite($handle, $strContent)) { @fclose($handle); die("Write permission deny"); } @fclose($handle); } }
public function get($config) { $results = null; $globalOptions = '{ "global": { "useUTC": false }, "lang": { "numericSymbols": null }, "credits": { "enabled": false }, "series": { "showInLegend": false}}'; $data = json_encode(array("infile" => $config, "globaloptions" => $globalOptions)); if (!empty($data)) { $header = array('Content-Type: application/json', 'Content-Length: ' . strlen($data)); $results = Sys_Tools::curl($this->api, "POST", $data, $header); return $results; } return $results; }
public function screenAction() { $type = $this->getRequest()->getQuery('type'); $hosts = trim($this->getRequest()->getQuery('host')); $from = strtotime($this->getRequest()->getQuery('from', date('Y-m-d'))); $to = strtotime($this->getRequest()->getQuery('to')); if (empty($to)) { $to = $from + 86400; $from = $from - 86400; } $output = null; $serviceChartScreen = new Service_Chart_Screen(); $serviceChartConfig = new Service_Chart_Config(); $systemHostService = new Service_System_Host(); $hosts = $systemHostService->getHostId($hosts); $option = array('from' => $from, 'to' => $to); $config = json_encode($serviceChartConfig->get($type, $hosts, $option)); $output = $serviceChartScreen->get($config); Sys_Tools::response(base64_decode($output), "image/png"); }