// feed new data into RRD
if ($this->status != 'ok') { trigger_error('Cannot update non-writeable file', E_USER_WARNING); return 1; }
$upvals = array();
- 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]; }
+ if (isset($this->config_raw['update'])) {
+ $evalcode = $this->config_raw['update'];
+ if (!is_null($evalcode)) {
+ ob_start();
+ eval($evalcode);
+ $upvals = explode("\n", ob_get_contents());
+ ob_end_clean();
+ }
+ }
+ 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).'));';
}
- $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)));';
+ 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 { $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;
}
- else { $val = null; }
- $upvals[] = is_null($val)?'U':$val;
}
$update_cmd = 'rrdtool update '.$this->rrd_file.' N:'.implode(':', $upvals);
$output = array(); $return_var = null;