aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--inc/functions.inc.php9
-rw-r--r--type/Default.class.php32
2 files changed, 22 insertions, 19 deletions
diff --git a/inc/functions.inc.php b/inc/functions.inc.php
index 2906530..b0706d5 100644
--- a/inc/functions.inc.php
+++ b/inc/functions.inc.php
@@ -5,17 +5,17 @@
5function validate_get($value, $type) { 5function validate_get($value, $type) {
6 switch($type) { 6 switch($type) {
7 case 'host': 7 case 'host':
8 if (!preg_match('/^[\d\w\W]+$/', $value)) 8 if (!preg_match('/^[\d\w\W]+$/u', $value))
9 return NULL; 9 return NULL;
10 break; 10 break;
11 case 'plugin': 11 case 'plugin':
12 case 'type': 12 case 'type':
13 if (!preg_match('/^\w+$/', $value)) 13 if (!preg_match('/^\w+$/u', $value))
14 return NULL; 14 return NULL;
15 break; 15 break;
16 case 'pinstance': 16 case 'pinstance':
17 case 'tinstance': 17 case 'tinstance':
18 if (!preg_match('/^[\d\w-]+$/', $value)) 18 if (!preg_match('/^[\d\w-]+$/u', $value))
19 return NULL; 19 return NULL;
20 break; 20 break;
21 } 21 }
@@ -23,5 +23,8 @@ function validate_get($value, $type) {
23 return $value; 23 return $value;
24} 24}
25 25
26function crc32hex($str) {
27 return sprintf("%x",crc32($str));
28}
26 29
27?> 30?>
diff --git a/type/Default.class.php b/type/Default.class.php
index ade3a16..9e2e6b7 100644
--- a/type/Default.class.php
+++ b/type/Default.class.php
@@ -78,10 +78,11 @@ class Type_Default {
78 $files = $this->get_filenames(); 78 $files = $this->get_filenames();
79 79
80 foreach($files as $filename) { 80 foreach($files as $filename) {
81 preg_match("#^$this->datadir/{$this->args['host']}/[\w\d]+-?([\w\d-]+)?/[\w\d]+-?([\w\d-]+)?\.rrd#", $filename, $matches); 81 $basename=basename($filename,'.rrd');
82 $instance=substr($basename,strpos($basename,'-')+1);
82 83
83 $this->tinstances[] = $matches[2]; 84 $this->tinstances[] = $instance;
84 $this->files[$matches[2]] = $filename; 85 $this->files[$instance] = $filename;
85 } 86 }
86 87
87 sort($this->tinstances); 88 sort($this->tinstances);
@@ -103,8 +104,7 @@ class Type_Default {
103 function file2identifier($files) { 104 function file2identifier($files) {
104 foreach($files as $key => $file) { 105 foreach($files as $key => $file) {
105 if (is_file($file)) { 106 if (is_file($file)) {
106 $files[$key] = preg_replace("#^$this->datadir/#", '', $files[$key]); 107 $files[$key] = basename($files[$key], '.rrd');
107 $files[$key] = preg_replace('#\.rrd$#', '', $files[$key]);
108 } 108 }
109 } 109 }
110 110
@@ -167,29 +167,29 @@ class Type_Default {
167 $i=0; 167 $i=0;
168 foreach ($this->tinstances as $tinstance) { 168 foreach ($this->tinstances as $tinstance) {
169 foreach ($this->data_sources as $ds) { 169 foreach ($this->data_sources as $ds) {
170 $rrdgraph[] = sprintf('DEF:min_%s=%s:%s:MIN', $sources[$i], $this->files[$tinstance], $ds); 170 $rrdgraph[] = sprintf('DEF:min_%s="%s":%s:MIN', crc32hex($sources[$i]), $this->files[$tinstance], $ds);
171 $rrdgraph[] = sprintf('DEF:avg_%s=%s:%s:AVERAGE', $sources[$i], $this->files[$tinstance], $ds); 171 $rrdgraph[] = sprintf('DEF:avg_%s="%s":%s:AVERAGE', crc32hex($sources[$i]), $this->files[$tinstance], $ds);
172 $rrdgraph[] = sprintf('DEF:max_%s=%s:%s:MAX', $sources[$i], $this->files[$tinstance], $ds); 172 $rrdgraph[] = sprintf('DEF:max_%s="%s":%s:MAX', crc32hex($sources[$i]), $this->files[$tinstance], $ds);
173 $i++; 173 $i++;
174 } 174 }
175 } 175 }
176 176
177 if(count($this->files)<=1) { 177 if(count($this->files)<=1) {
178 foreach ($sources as $source) { 178 foreach ($sources as $source) {
179 $rrdgraph[] = sprintf('AREA:max_%s#%s', $source, $this->get_faded_color($this->colors[$source])); 179 $rrdgraph[] = sprintf('AREA:max_%s#%s', crc32hex($source), $this->get_faded_color($this->colors[$source]));
180 $rrdgraph[] = sprintf('AREA:min_%s#%s', $source, 'ffffff'); 180 $rrdgraph[] = sprintf('AREA:min_%s#%s', crc32hex($source), 'ffffff');
181 break; # only 1 area to draw 181 break; # only 1 area to draw
182 } 182 }
183 } 183 }
184 184
185 foreach ($sources as $source) { 185 foreach($sources as $source) {
186 $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source; 186 $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source;
187 $color = is_array($this->colors) ? $this->colors[$source]: $this->colors; 187 $color = is_array($this->colors) ? $this->colors[$source]: $this->colors;
188 $rrdgraph[] = sprintf('LINE1:avg_%s#%s:\'%s\'', $source, $this->validate_color($color), $dsname); 188 $rrdgraph[] = sprintf('LINE1:avg_%s#%s:\'%s\'', crc32hex($source), $this->validate_color($color), $dsname);
189 $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', $source, $this->rrd_format); 189 $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', crc32hex($source), $this->rrd_format);
190 $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', $source, $this->rrd_format); 190 $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', crc32hex($source), $this->rrd_format);
191 $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:\'%s Max,\'', $source, $this->rrd_format); 191 $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:\'%s Max,\'', crc32hex($source), $this->rrd_format);
192 $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:\'%s Last\\l\'', $source, $this->rrd_format); 192 $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:\'%s Last\\l\'', crc32hex($source), $this->rrd_format);
193 } 193 }
194 194
195 return $rrdgraph; 195 return $rrdgraph;