From de093632548379706283730563ac89e895c5f2ac Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 12 May 2005 11:53:05 +0000 Subject: [PATCH] introduce a global update setting for automatic updating all rows at once --- include/classes/rrdstat.php-class | 67 ++++++++++++++++++------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/include/classes/rrdstat.php-class b/include/classes/rrdstat.php-class index 18bd786..9adb461 100644 --- a/include/classes/rrdstat.php-class +++ b/include/classes/rrdstat.php-class @@ -146,38 +146,49 @@ class rrdstat { // 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; -- 2.43.0