diff --git a/database/migrations/2023_10_07_170735_increase_processes_cputime_length.php b/database/migrations/2023_10_07_170735_increase_processes_cputime_length.php new file mode 100644 index 0000000000..b7a14dfc63 --- /dev/null +++ b/database/migrations/2023_10_07_170735_increase_processes_cputime_length.php @@ -0,0 +1,28 @@ +string('cputime', 14)->change(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('processes', function (Blueprint $table) { + $table->string('cputime', 12)->change(); + }); + } +}; diff --git a/includes/html/pages/device/processes.inc.php b/includes/html/pages/device/processes.inc.php index d9574782df..f91d82a6bb 100644 --- a/includes/html/pages/device/processes.inc.php +++ b/includes/html/pages/device/processes.inc.php @@ -24,7 +24,7 @@ * @subpackage Pages */ -switch ($vars['order']) { +switch ($vars['order'] ?? '') { case 'vsz': $order = '`vsz`'; break; @@ -50,7 +50,7 @@ switch ($vars['order']) { break; }//end switch -if ($vars['by'] == 'desc') { +if (isset($vars['by']) && $vars['by'] == 'desc') { $by = 'desc'; } else { $by = 'asc'; diff --git a/includes/polling/unix-agent.inc.php b/includes/polling/unix-agent.inc.php index d7cd8d1a1f..f66b92f9ac 100644 --- a/includes/polling/unix-agent.inc.php +++ b/includes/polling/unix-agent.inc.php @@ -28,6 +28,7 @@ if ($device['os_group'] == 'unix' || $device['os'] == 'windows') { // Set stream timeout (for timeouts during agent fetch stream_set_timeout($agent, \LibreNMS\Config::get('unix-agent.read-timeout')); $agentinfo = stream_get_meta_data($agent); + $agent_raw = ''; // fetch data while not eof and not timed-out while ((! feof($agent)) && (! $agentinfo['timed_out'])) { @@ -76,14 +77,17 @@ if ($device['os_group'] == 'unix' || $device['os'] == 'windows') { global $agent_data; $agent_data = []; foreach (explode('<<<', $agent_raw) as $section) { - [$section, $data] = explode('>>>', $section); - [$sa, $sb] = explode('-', $section, 2); + if (empty($section)) { + continue; + } + [$section, $data] = explode('>>>', $section); if (in_array($section, $agentapps)) { $agent_data['app'][$section] = trim($data); } - if (! empty($sa) && ! empty($sb)) { + if (str_contains($section, '-')) { + [$sa, $sb] = explode('-', $section, 2); $agent_data[$sa][$sb] = trim($data); } else { $agent_data[$section] = trim($data); @@ -109,9 +113,8 @@ if ($device['os_group'] == 'unix' || $device['os'] == 'windows') { dbDelete('processes', 'device_id = ?', [$device['device_id']]); $data = []; 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); - [$user, $vsz, $rss, $cputime, $pid, $command] = explode('|', $process, 6); - if (! empty($command)) { + if (preg_match('/\((.*),([0-9]*),([0-9]*),([-0-9:.]*),([0-9]*)\) (.+)/', $process, $process_matches)) { + [, $user, $vsz, $rss, $cputime, $pid, $command] = $process_matches; $data[] = ['device_id' => $device['device_id'], 'pid' => $pid, 'user' => $user, 'vsz' => $vsz, 'rss' => $rss, 'cputime' => $cputime, 'command' => $command]; } } diff --git a/misc/db_schema.yaml b/misc/db_schema.yaml index d0e44c6f7f..a74c0c8ddf 100644 --- a/misc/db_schema.yaml +++ b/misc/db_schema.yaml @@ -1740,7 +1740,7 @@ processes: - { Field: pid, Type: int, 'Null': false, Extra: '' } - { Field: vsz, Type: int, 'Null': false, Extra: '' } - { Field: rss, Type: int, 'Null': false, Extra: '' } - - { Field: cputime, Type: varchar(12), 'Null': false, Extra: '' } + - { Field: cputime, Type: varchar(14), 'Null': false, Extra: '' } - { Field: user, Type: varchar(50), 'Null': false, Extra: '' } - { Field: command, Type: text, 'Null': false, Extra: '' } Indexes: