[ Index ] |
PHP Cross Reference of Yamoon 0.9.0 |
[Summary view] [Print] [Text view]
1 <?php 2 3 require_once ('Yamoon/Config.php'); 4 require_once ('Yamoon/File.php'); 5 require_once ('Yamoon/Company.php'); 6 7 /** 8 * Mrtg.php - manages all MRTG functions like reload configurations, 9 * reload data and create graphics. 10 */ 11 12 class Mrtg { 13 var $company; 14 var $config; 15 var $types = array("status", "quality", "delay"); 16 17 /** 18 * MRTG Constructor. 19 * $mrtg = new Mrtg($config, $companyId); 20 * 21 * param $config Configuration class 22 * param $companyId When provided, grab all info for that company 23 */ 24 function Mrtg($config, $company_id) { 25 $this->config = $config; 26 $this->company = new Company($config, $company_id); 27 } 28 29 /** 30 * Execute MRTG, reloading all graphics, reading the logs just created with 31 * method reload Data(). Don't forget to call the method reloadConfig() before 32 * to assure all configs are up-to-date. 33 * $mrtg->execute(); 34 */ 35 function execute () { 36 print "<p>Generating MRTG graphics:<br>\n"; 37 foreach ($this->company->getProbes() as $probe) { 38 foreach ($this->types as $type) { 39 print $type." of ".$probe->service->name." on ".$probe->host->name."<br>\n"; 40 $this->reloadData($probe, $type); 41 system("mrtg ".$this->config->mrtg_dir."/".$probe->service->name."_on_".$probe->host->name."-".$type.".conf"); 42 flush(); 43 } 44 print "Generating index for ".$probe->service->name." on ".$probe->host->name."<p>\n"; 45 system("indexmaker --output=".$this->config->mrtg_dir."/".$probe->service->name."_on_".$probe->host->name.".html ".$this->config->mrtg_dir."/".$probe->service->name."_on_".$probe->host->name."-*.conf"); 46 } 47 } 48 49 /** 50 * Re-read all probes' configurations for execute to use when generating graphics. 51 * $mrtg->reloadConfig(); 52 */ 53 function reloadConfig () { 54 print "<p>Reloading MRTG configurations:<br>\n"; 55 foreach ($this->company->getProbes() as $probe) { 56 foreach ($this->types as $type) { 57 print $type." of ".$probe->service->name." on ".$probe->host->name."<br>\n"; 58 write($this->config->mrtg_dir."/".$probe->service->name."_on_".$probe->host->name."-".$type.".conf", printTemplate($this->config->template_dir."/".$type.".mrtg")); 59 flush(); 60 } 61 print "<br>\n"; 62 } 63 } 64 65 /** 66 * Reload all data from database's log for a specified probe and graph type. 67 * The allowed graph types are: status, quality and delay. 68 * This function will create a MRTG log file to be read while generating MRTG 69 * graphics on the method execute(). 70 * $mrtg->reloadData($probe->id, "status"); 71 * 72 * param $probe The probe to create the log file 73 * param $type Graph type. One of "status", "quality" or "delay". 74 */ 75 function reloadData ($probe, $type) { 76 $max = 1; 77 if ($type != "status") { 78 $resp = $this->config->select("select max($type) as max from log where probe_id = ?", $probe->id); 79 $max = $resp[0]->max; 80 } 81 $resp = $this->config->select("select count(*) as count from log where probe_id = ?", $probe->id); 82 $count = $resp[0]->count; 83 $content = time()." $count 0\n"; 84 foreach ($this->config->select("select UNIX_TIMESTAMP(ts) as time, $type as data from log where probe_id = ? order by ts desc", $probe->id) as $row) { 85 if ($type == "status") 86 $row->data = ($row->data == "up" ? 1 : 0); 87 $content .= $row->time." ".$row->data." 0 ".$max." 0\n"; 88 } 89 write($this->config->mrtg_dir."/".$probe->service->name."_on_".$probe->host->name."-".$type.".log", $content); 90 } 91 } 92 93 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sat Feb 19 17:29:53 2005 | Cross-referenced by PHPXref 0.6 |