File: rrd_export.php

package info (click to toggle)
jffnms 0.8.3dfsg.1-2.1etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 4,928 kB
  • ctags: 5,050
  • sloc: php: 19,981; sh: 266; makefile: 91; perl: 52
file content (56 lines) | stat: -rw-r--r-- 1,187 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<? 
/* This file is part of JFFNMS
 * Copyright (C) <2002-2005> Javier Szyszlican <javier@szysz.com>
 * This program is licensed under the GNU GPL, full terms in the LICENSE file
 */
    include ("../conf/config.php");
    
    echo "<PRE>";
    
    $start = 1021557600;
    $end = 1021576800;

    $query = "select id from interfaces where poll > 1";
    $result = db_query($query);
    
    while ($record = db_fetch_array($result)) {
	extract($record);
	
	$file = "$rrd_real_path/interface-$id.rrd";
	$aux = "/tmp/interface-$id.rrd.xml";
	
	unlink($aux);
	exec("$rrdtool_executable dump $file > $aux");
	
	$ok=0;
	unset($new_lines);

	$fp = fopen ($aux,"r");
	
	while (($line = fgets($fp,4096)) && ($ok != 2)) {

	    if ($ok==1) {
		$date = trim(substr($line,strpos($line,"/")+2,strpos($line," -->")-strpos($line,"/"))-2);

		//echo "$date\n";

		if (($date >= $start) && ($date <=$end)) { 
		    $new_lines[]=$line;
		    echo $line;
		}

		if (strpos($line,"</database>") > 1) $ok=2;

	    } else if (strpos($line,"<database>") > 1) $ok=1;
	}
	
	fclose($fp);
	unlink($aux);

	$fp = fopen("$file.aux","w+");
	foreach ($new_lines as $line) fputs($fp,$line);
	fclose($fp);

    }

?>