config = $config; $this->company = new Company($config, $company_id); } /** * Execute MRTG, reloading all graphics, reading the logs just created with * method reload Data(). Don't forget to call the method reloadConfig() before * to assure all configs are up-to-date. * $mrtg->execute(); */ function execute () { print "
Generating MRTG graphics:
\n";
foreach ($this->company->getProbes() as $probe) {
foreach ($this->types as $type) {
print $type." of ".$probe->service->name." on ".$probe->host->name."
\n";
$this->reloadData($probe, $type);
system("mrtg ".$this->config->mrtg_dir."/".$probe->service->name."_on_".$probe->host->name."-".$type.".conf");
flush();
}
print "Generating index for ".$probe->service->name." on ".$probe->host->name."
\n"; 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"); } } /** * Re-read all probes' configurations for execute to use when generating graphics. * $mrtg->reloadConfig(); */ function reloadConfig () { print "
Reloading MRTG configurations:
\n";
foreach ($this->company->getProbes() as $probe) {
foreach ($this->types as $type) {
print $type." of ".$probe->service->name." on ".$probe->host->name."
\n";
write($this->config->mrtg_dir."/".$probe->service->name."_on_".$probe->host->name."-".$type.".conf", printTemplate($this->config->template_dir."/".$type.".mrtg"));
flush();
}
print "
\n";
}
}
/**
* Reload all data from database's log for a specified probe and graph type.
* The allowed graph types are: status, quality and delay.
* This function will create a MRTG log file to be read while generating MRTG
* graphics on the method execute().
* $mrtg->reloadData($probe->id, "status");
*
* param $probe The probe to create the log file
* param $type Graph type. One of "status", "quality" or "delay".
*/
function reloadData ($probe, $type) {
$max = 1;
if ($type != "status") {
$resp = $this->config->select("select max($type) as max from log where probe_id = ?", $probe->id);
$max = $resp[0]->max;
}
$resp = $this->config->select("select count(*) as count from log where probe_id = ?", $probe->id);
$count = $resp[0]->count;
$content = time()." $count 0\n";
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) {
if ($type == "status")
$row->data = ($row->data == "up" ? 1 : 0);
$content .= $row->time." ".$row->data." 0 ".$max." 0\n";
}
write($this->config->mrtg_dir."/".$probe->service->name."_on_".$probe->host->name."-".$type.".log", $content);
}
}
?>