[nagios-plugins] check_procs: add option to ignore plugin parent process (#1205)
Anton Löfgren <notifications-9UaJU3cA/F/[email protected]> Fri, 18 Oct 2013 02:50:41 -0700
| Newsgroups | gmane.network.nagios.plugins.devel |
|---|---|
| Message-ID | <nagios-plugins/nagios-plugins/pull/[email protected]> |
--===============3669009664041341383==
Content-Type: multipart/alternative;
boundary="--==_mimepart_5261047183566_b09eed1d4015127a";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_5261047183566_b09eed1d4015127a
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: quoted-printable
This fixes an issue that appears when running check_procs over NRPE,
where the default shell is configured to (for example) dash, as is the
case on Debian.
dash (and tcsh, and mksh, and probably others), when invoked with -c forks =
an additional process
to execute the argument string. Contrast this with bash, which does not
do this, provided that the argument string simply can be exec()'d as-is.
To demonstrate:
$ bash -c pstree
init=E2=94=80=E2=94=AC ..
...
=E2=94=9C=E2=94=80sshd=E2=94=80-=E2=94=80sshd=E2=94=80=E2=94=80=E2=94=80ps=
tree
versus
$ dash -c pstree
init=E2=94=80=E2=94=AC ..
...
=E2=94=9C=E2=94=80sshd=E2=94=80-=E2=94=80sshd=E2=94=80=E2=94=80=E2=94=80da=
sh=E2=94=80=E2=94=80=E2=94=80pstree
The consequence of this fork is that the following invokation:
/opt/plugins/check_procs -a init
will result in this output:
PROCS OK: 2 processes with args 'init' | processes=3D2;;;0;
because the check_procs, in addition to finding the actual init process,
finds its parent shell as well.
This example is a bit contrived, but I think it illustrates the
point.
This wouldn't really be a problem, and normally isn't, if it weren&=
#39;t
for the fact that NRPE uses a call to popen() which does exactly the
above (executes '/bin/sh -c ...'), causing inconsistent behaviour
between distributions and much confusion for end users.
The argument may be made that the dash process spawned by NRPE is just a
process like any other, and should therefore be included in the process
count just like any other. However, this is not very intuitive, because
of the previously mentioned inconsistencies.
The argument might also well be made that we're _never_ interested in t=
he
immediate ancestor of the plugin, but it is unknown how many
installations have already made the necessary modifications to their
setups to make up for the fact that the plugin behaves the way it does.
Thus, this patch adds an option --ignore-parent, which could (and
indeed, in my opinion, should) be used, if you want to run check_procs thro=
ugh NRPE,
with the -a option.
See also these bug reports:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=3D626913
http://sourceforge.net/p/nagiosplug/bugs/512/
https://github.com/nagios-plugins/nagios-plugins/issues/999
https://bugs.op5.com/view.php?id=3D4398
You can merge this Pull Request by running:
git pull https://github.com/catharsis/nagios-plugins issue-999
Or you can view, comment on it, or merge it online at:
https://github.com/nagios-plugins/nagios-plugins/pull/1205
-- Commit Summary --
* check_procs: add option to ignore plugin parent process
-- File Changes --
M plugins/check_procs.c (16)
M plugins/t/check_procs.t (13)
-- Patch Links --
https://github.com/nagios-plugins/nagios-plugins/pull/1205.patch
https://github.com/nagios-plugins/nagios-plugins/pull/1205.diff
----==_mimepart_5261047183566_b09eed1d4015127a
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p>This fixes an issue that appears when running check_procs over NRPE,<br>
where the default shell is configured to (for example) dash, as is the<br>
case on Debian.</p>
<p>dash (and tcsh, and mksh, and probably others), when invoked with -c for=
ks an additional process<br>
to execute the argument string. Contrast this with bash, which does not<br>
do this, provided that the argument string simply can be exec()'d as-is.</p>
<p>To demonstrate:<br>
$ bash -c pstree<br>
init=E2=94=80=E2=94=AC ..<br>
...<br>
=E2=94=9C=E2=94=80sshd=E2=94=80-=E2=94=80sshd=E2=94=80=E2=94=80=E2=94=
=80pstree</p>
<p>versus<br>
$ dash -c pstree<br>
init=E2=94=80=E2=94=AC ..<br>
...<br>
=E2=94=9C=E2=94=80sshd=E2=94=80-=E2=94=80sshd=E2=94=80=E2=94=80=E2=94=
=80dash=E2=94=80=E2=94=80=E2=94=80pstree</p>
<p>The consequence of this fork is that the following invokation:<br>
/opt/plugins/check_procs -a init</p>
<p>will result in this output:</p>
<pre><code>PROCS OK: 2 processes with args 'init' | processes=3D2;;;0;
</code></pre>
<p>because the check_procs, in addition to finding the actual init process,=
<br>
finds its parent shell as well.</p>
<p>This example is a bit contrived, but I think it illustrates the<br>
point.</p>
<p>This wouldn't really be a problem, and normally isn't, if it weren't<br>
for the fact that NRPE uses a call to popen() which does exactly the<br>
above (executes '/bin/sh -c ...'), causing inconsistent behaviour<br>
between distributions and much confusion for end users.</p>
<p>The argument may be made that the dash process spawned by NRPE is just a=
<br>
process like any other, and should therefore be included in the process<br>
count just like any other. However, this is not very intuitive, because<br>
of the previously mentioned inconsistencies.</p>
<p>The argument might also well be made that we're <em>never</em> intereste=
d in the<br>
immediate ancestor of the plugin, but it is unknown how many<br>
installations have already made the necessary modifications to their<br>
setups to make up for the fact that the plugin behaves the way it does.</p>
<p>Thus, this patch adds an option --ignore-parent, which could (and<br>
indeed, in my opinion, should) be used, if you want to run check_procs thro=
ugh NRPE,<br>
with the -a option.</p>
<p>See also these bug reports:<br><a href=3D"http://bugs.debian.org/cgi-bin=
/bugreport.cgi?bug=3D626913">http://bugs.debian.org/cgi-bin/bugreport.cgi?b=
ug=3D626913</a><br><a href=3D"http://sourceforge.net/p/nagiosplug/bugs/512/=
">http://sourceforge.net/p/nagiosplug/bugs/512/</a><br><a href=3D"https://g=
ithub.com/nagios-plugins/nagios-plugins/issues/999" class=3D"issue-link" ti=
tle=3D"check_procs counts too much processes with dash as shell [sf#3304535=
]">#999</a><br><a href=3D"https://bugs.op5.com/view.php?id=3D4398">https://=
bugs.op5.com/view.php?id=3D4398</a></p>
<hr>
<h4>You can merge this Pull Request by running</h4>
<pre> git pull https://github.com/catharsis/nagios-plugins issue-999</pre>
<p>Or view, comment on, or merge it at:</p>
<p> <a href=3D'https://github.com/nagios-plugins/nagios-plugins/=
pull/1205'>https://github.com/nagios-plugins/nagios-plugins/pull/1205</a></=
p>
<h4>Commit Summary</h4>
<ul>
<li>check_procs: add option to ignore plugin parent process</li>
</ul>
<h4>File Changes</h4>
<ul>
<li>
<strong>M</strong>
<a href=3D"https://github.com/nagios-plugins/nagios-plugins/pull/1205/f=
iles#diff-0">plugins/check_procs.c</a>
(16)
</li>
<li>
<strong>M</strong>
<a href=3D"https://github.com/nagios-plugins/nagios-plugins/pull/1205/f=
iles#diff-1">plugins/t/check_procs.t</a>
(13)
</li>
</ul>
<h4>Patch Links:</h4>
<ul>
<li><a href=3D'https://github.com/nagios-plugins/nagios-plugins/pull/1205=
.patch'>https://github.com/nagios-plugins/nagios-plugins/pull/1205.patch</a=
></li>
<li><a href=3D'https://github.com/nagios-plugins/nagios-plugins/pull/1205=
.diff'>https://github.com/nagios-plugins/nagios-plugins/pull/1205.diff</a><=
/li>
</ul>
----==_mimepart_5261047183566_b09eed1d4015127a--
--===============3669009664041341383==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
--===============3669009664041341383==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________________
Nagios Plugin Development Mailing List Nagiosplug-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Unsubscribe at https://lists.sourceforge.net/lists/listinfo/nagiosplug-devel
::: Please include plugins version (-v) and OS when reporting any issue.
::: Messages without supporting info will risk being sent to /dev/null
--===============3669009664041341383==--