Merge branch 'master' of linz:/srv/git/git-kairo
[php-utility-classes.git] / testbed / rrd / rrd-update.php
1 <?php
2 date_default_timezone_set("Europe/Vienna");
3 $myfile = $_SERVER['SCRIPT_FILENAME'];
4 while (is_link($myfile)) { $myfile = readlink($myfile); }
5 if (getcwd() != dirname($myfile)) {
6   // change to directory of the script if called from different directory
7   $orig_workingdir = getcwd();
8   chdir(dirname($myfile));
9 }
10
11 include_once('rrdstat.php-class');
12
13 $rrd_config_file = 'rrd-config/'.php_uname('n').'.inc.php';
14 if (!file_exists($rrd_config_file)) { $rrd_config_file = 'rrd-config.inc.php'; }
15 include_once($rrd_config_file);
16
17 if (php_sapi_name() == 'cli') {
18   // automated updates
19   $autoupdate = array();
20   foreach ($rrd_info as $iname=>$rinfo) {
21     if (isset($rinfo['auto-update']) && $rinfo['auto-update']) {
22       $autoupdate[] = $iname;
23     }
24   }
25   $autoupdate[] = 'rrdup';
26   foreach ($autoupdate as $rrdname) {
27     $rrd = new rrdstat($rrd_info, $rrdname);
28     $rrd->update();
29   }
30 }
31 else {
32   print('this is a commandline app.');
33 }
34 ?>