From 0f10f2b5b0c6c23b0730fe4d2841d36761100ab5 Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Wed, 9 May 2012 11:33:16 +0000 Subject: [PATCH] add ability to pass an array of values to rrdtool_update, which are checked and replaced with U if invalid. git-svn-id: http://www.observium.org/svn/observer/trunk@3152 61d68cd4-352d-0410-923a-c4978735b2b8 --- includes/polling/netstats-snmp.inc.php | 5 ++--- includes/rrdtool.inc.php | 15 ++++++++++++--- poller.php | 4 +++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/includes/polling/netstats-snmp.inc.php b/includes/polling/netstats-snmp.inc.php index fb50c66d8..36cebbb48 100755 --- a/includes/polling/netstats-snmp.inc.php +++ b/includes/polling/netstats-snmp.inc.php @@ -24,8 +24,7 @@ if ($device['os'] != "Snom") $data_array = snmpwalk_cache_oid($device, "snmp", array(), "SNMPv2-MIB"); - $rrdupdate = "N"; - + $rrdupdate = array(); foreach ($oids as $oid) { if (is_numeric($data_array[0][$oid])) @@ -34,7 +33,7 @@ if ($device['os'] != "Snom") } else { $value = "U"; } - $rrdupdate .= ":$value"; + $rrdupdate[] = $value; } if (isset($data_array[0]['snmpInPkts']) && isset($data_array[0]['snmpOutPkts'])) diff --git a/includes/rrdtool.inc.php b/includes/rrdtool.inc.php index e36f92287..18739f724 100644 --- a/includes/rrdtool.inc.php +++ b/includes/rrdtool.inc.php @@ -32,8 +32,6 @@ function rrdtool_pipe_open(&$rrd_process, &$rrd_pipes) $command = $config['rrdtool'] . " -"; -# $command = "/usr/bin/php /home/observium/dev/testpipe.php"; - $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to @@ -168,7 +166,6 @@ function rrdtool($command, $filename, $options) } else { fwrite($rrd_pipes[0], $cmd."\n"); } - if ($debug) { echo stream_get_contents($rrd_pipes[1]); @@ -209,6 +206,18 @@ function rrdtool_create($filename, $options) function rrdtool_update($filename, $options) { + /// Do some sanitisation on the data if passed as an array. + if(is_array($options)) + { + $values[] = "N"; + foreach($options as $value) + { + if(!is_numeric($value)) { $value = U; } + $values[] = $value; + } + $options = implode(':', $values); + } + return rrdtool("update", $filename, $options); } diff --git a/poller.php b/poller.php index 5cd05480c..cdfb2aea1 100755 --- a/poller.php +++ b/poller.php @@ -24,7 +24,7 @@ include("includes/polling/functions.inc.php"); $poller_start = utime(); echo("Observium Poller v".$config['version']."\n\n"); -$options = getopt("h:m:i:n:d:r::a::"); +$options = getopt("h:m:i:n:r:d::a::"); if ($options['h'] == "odd") { $options['n'] = "1"; $options['i'] = "2"; } elseif ($options['h'] == "even") { $options['n'] = "0"; $options['i'] = "2"; } @@ -74,6 +74,8 @@ if (!$where) exit; } +print_r($options); + if (isset($options['d'])) { echo("DEBUG!\n");