From 605d92bc1158cb873be811d56b1dfa9212a381ae Mon Sep 17 00:00:00 2001 From: Louis Rossouw Date: Tue, 14 Jul 2015 22:57:15 +0200 Subject: [PATCH 1/2] Processes get added to db in one big query instead of individual row inserts. --- includes/polling/unix-agent.inc.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/includes/polling/unix-agent.inc.php b/includes/polling/unix-agent.inc.php index 9f79bf882..45cba55e7 100644 --- a/includes/polling/unix-agent.inc.php +++ b/includes/polling/unix-agent.inc.php @@ -112,14 +112,21 @@ if ($device['os_group'] == 'unix') { if (!empty($agent_data['ps'])) { echo 'Processes: '; dbDelete('processes', 'device_id = ?', array($device['device_id'])); + $query = "INSERT INTO `processes` (`device_id`,`pid`,`user`,`vsz`,`rss`,`cputime`,`command`) VALUES "; + $values = ""; foreach (explode("\n", $agent_data['ps']) as $process) { $process = preg_replace('/\((.*),([0-9]*),([0-9]*),([0-9\:]*),([0-9]*)\)\ (.*)/', '\\1|\\2|\\3|\\4|\\5|\\6', $process); list($user, $vsz, $rss, $cputime, $pid, $command) = explode('|', $process, 6); if (!empty($command)) { - dbInsert(array('device_id' => $device['device_id'], 'pid' => $pid, 'user' => $user, 'vsz' => $vsz, 'rss' => $rss, 'cputime' => $cputime, 'command' => $command), 'processes'); + if ($values != "") { + $values .= ","; + } + $values .= "('".$device['device_id']."','".$pid."','".$user."','".$vsz."','".$rss."','".$cputime."','".$command."')"; } } - + if ($values != "") { + dbQuery($query.$values); + } echo "\n"; } From f261b7be95ce01d256b9019b5727dce2224180c1 Mon Sep 17 00:00:00 2001 From: Louis Rossouw Date: Tue, 14 Jul 2015 23:34:35 +0200 Subject: [PATCH 2/2] Escape values passed to query. --- includes/polling/unix-agent.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/polling/unix-agent.inc.php b/includes/polling/unix-agent.inc.php index 45cba55e7..174973383 100644 --- a/includes/polling/unix-agent.inc.php +++ b/includes/polling/unix-agent.inc.php @@ -121,7 +121,7 @@ if ($device['os_group'] == 'unix') { if ($values != "") { $values .= ","; } - $values .= "('".$device['device_id']."','".$pid."','".$user."','".$vsz."','".$rss."','".$cputime."','".$command."')"; + $values .= "('".mres($device['device_id'])."','".mres($pid)."','".mres($user)."','".mres($vsz)."','".mres($rss)."','".mres($cputime)."','".mres($command)."')"; } } if ($values != "") {