- foreach($this->rrd_fields as $ds) {
- if (is_array($upArray) && isset($upArray[$ds['name']])) { $val = $upArray[$ds['name']]; }
- elseif (isset($ds['update'])) { $val = eval($ds['update']); }
- else { $val = null; }
- $upvals[] = $val;
- }
- $update_cmd = 'rrdtool update '.$this->rrd_file.' N:'.implode(':', $upvals);
- $output = array(); $return_var = null;
- exec($update_cmd, $output, $return_var);
- if ($return_var) { trigger_error('rrd update returned with value '.$return_var, E_USER_WARNING); }
+ if (isset($this->config_raw['update'])) {
+ $evalcode = $this->config_raw['update'];
+ if (!is_null($evalcode)) {
+ ob_start();
+ eval($evalcode);
+ $ret = ob_get_contents();
+ if (strlen($ret)) { $upvals = explode("\n", $ret); }
+ ob_end_clean();
+ }
+ $walkfunc = create_function('&$val,$key', '$val = is_numeric($val)?$val:"U";');
+ array_walk($upvals, $walkfunc);
+ }
+ else {
+ foreach ($this->rrd_fields as $ds) {
+ if (is_array($upArray) && isset($upArray[$ds['name']])) { $val = $upArray[$ds['name']]; }
+ elseif (isset($ds['update'])) {
+ $val = null; $evalcode = null;
+ if (substr($ds['update'], 0, 4) == 'val:') {
+ $evalcode = 'print(trim('.substr($ds['update'], 4).'));';
+ }
+ elseif (substr($ds['update'], 0, 8) == 'snmp-if:') {
+ $snmphost = 'localhost'; $snmpcomm = 'public';
+ list($nix, $ifname, $valtype) = explode(':', $ds['update'], 3);
+ $iflist = explode("\n", `snmpwalk -v2c -c $snmpcomm $snmphost interfaces.ifTable.ifEntry.ifDescr`);
+ $ifnr = null;
+ foreach ($iflist as $ifdesc) {
+ if (preg_match('/ifDescr\.(\d+) = STRING: '.$ifname.'/', $ifdesc, $regs)) { $ifnr = $regs[1]; }
+ }
+ $oid = null;
+ if ($valtype == 'in') { $oid = '1.3.6.1.2.1.2.2.1.10.'.$ifnr; }
+ elseif ($valtype == 'out') { $oid = '1.3.6.1.2.1.2.2.1.16.'.$ifnr; }
+ if (!is_null($ifnr) && !is_null($oid)) {
+ $evalcode = 'print(trim(substr(strrchr(`snmpget -v2c -c '.$snmpcomm.' '.$snmphost.' '.$oid.'`,":"),1)));';
+ }
+ }
+ else { $evalcode = $ds['update']; }
+ if (!is_null($evalcode)) {
+ ob_start();
+ eval($evalcode);
+ $val = ob_get_contents();
+ ob_end_clean();
+ }
+ }
+ else { $val = null; }
+ $upvals[] = is_null($val)?'U':$val;
+ }
+ }
+ $return = null;
+ if (count($upvals)) {
+ $update_cmd = 'rrdtool update '.$this->rrd_file.' N:'.implode(':', $upvals);
+ $return = `$update_cmd 2>&1`;
+ }
+
+ if (strpos($return, 'ERROR') !== false) {
+ trigger_error($this->rrd_file.' - rrd update error: '.$return, E_USER_WARNING);
+ $success = false;
+ }
+ else { $success = true; }