sensu-plugins / sensu-plugins-process-checks

This plugin provides native process instrumentation for monitoring and metrics collection, including: process status, uptime, thread count, and others.
http://sensu-plugins.io
MIT License
20 stars 55 forks source link

check-process.rb: Processes owned by users with names longer than 7 characters cannot be matched using -u switch #114

Open makayez opened 4 years ago

makayez commented 4 years ago

When trying to match a process that is owned by a user with a long name fails to match using check-process.rb -u longusername

It appears this line in check-process.rb: 229 >> read_lines('ps axwwo user,pid,vsz,rss,pcpu,nlwp,state,etime,time,command').drop(1).map do |line|

Uses ps which by default truncates the username at 7 characters (adding a + at the end to indicate that the field is truncated). A possible fix for this would be to specify the length of the user field. I've tried this on a few flavors of linux successfully, but not an exhaustive test.

229 >> read_lines('ps axwwo user:30,pid,vsz,rss,pcpu,nlwp,state,etime,time,command').drop(1).map do |line|

It seems to make more sense to make the user column display length of the ps call set based on the length of the -u query so that it would have sufficient length to match the user delimiter parameter in the check.