<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sankasaurus &#187; nagios</title>
	<atom:link href="http://blog.pas.net.au/tag/nagios/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pas.net.au</link>
	<description>Just another tech blog - ranting since 2006</description>
	<lastBuildDate>Wed, 25 Aug 2010 21:40:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Fighting with SELinux and Nagios</title>
		<link>http://blog.pas.net.au/2009/05/fighting-with-selinux-and-nagios/</link>
		<comments>http://blog.pas.net.au/2009/05/fighting-with-selinux-and-nagios/#comments</comments>
		<pubDate>Sat, 02 May 2009 17:25:55 +0000</pubDate>
		<dc:creator>Peter Sankauskas</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[sys-admin]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.pas.net.au/?p=25</guid>
		<description><![CDATA[I can&#8217;t believe it, but I won! I have been trying to set up Nagios on a RHEL5 machine running SELinux and have been loosing the fight for the last 3 days. But today, I win! This is such a win, it is worth sharing.
Now that I have won though, I believe this is not [...]]]></description>
			<content:encoded><![CDATA[<p>I can&#8217;t believe it, but I won! I have been trying to set up Nagios on a RHEL5 machine running SELinux and have been loosing the fight for the last 3 days. But today, I win! This is such a win, it is worth sharing.</p>
<p>Now that I have won though, I believe this is not Nagios specific at all, and if I had bothered to learn about SELinux, this may have been obvious. Anyway, the error Nagios was giving me was:</p>
<div style="text-align:center;"><strong><span style="color:#ff0000;">Error: Could not stat() command file &#8216;/usr/local/nagios/var/rw/nagios.cmd&#8217;! </span><br />
The external command file may be missing, Nagios may not be running, and/or Nagios may not be checking external commands.<br />
<span style="color:#ff0000;">An error occurred while attempting to commit your command for processing.</span><br />
<span style="text-decoration:underline;"><span style="color:#0000ff;">Return from whence you came </span></span></strong></div>
<p>As you may have already guess, the solution has nothing to do with the location or permissions of the file, the file was not missing, Nagios was running, and Nagios was checking external commands. The final line of the message is great though, and I can only hope we start to see more old English in error messages.</p>
<p>The problem of course, was that SELinux was enabled and stopping this blatant security violation. You can check to see if SELinux is on by running:</p>
<div style="margin-left:40px;font-family:courier new,monospace;">$ /usr/sbin/getenforce<br />
Enforcing</div>
<p>If you got &#8220;Permissive&#8221; or &#8220;Disabled&#8221;, then this post is not for you. To see SELinux&#8217;s side of things, check out <strong><span style="font-family:courier new,monospace;">/var/log/messages</span></strong>:</p>
<div style="margin-left:40px;"><span style="font-family:courier new,monospace;">setroubleshoot: SELinux is preventing ping (ping_t) &#8220;read write&#8221; to /usr/local/nagios/var/spool/checkresults/checkrXH96b (usr_t). For complete SELinux messages. run sealert -l 1ffc2533-42b5-4e04-b7ab-a81bb7d02040</span><br style="font-family:courier new,monospace;" /><br />
<span style="font-family:courier new,monospace;"> setroubleshoot: SELinux is preventing ping (ping_t) &#8220;read write&#8221; to /usr/local/nagios/var/spool/checkresults/checkrZxsA1 (usr_t). For complete SELinux messages. run sealert -l 178ba2d4-0822-47eb-9e32-bfaa19ee3c4b</span><br style="font-family:courier new,monospace;" /><br />
<span style="font-family:courier new,monospace;"> setroubleshoot: SELinux is preventing cmd.cgi (httpd_sys_script_t) &#8220;getattr&#8221; to /usr/local/nagios/var/rw/nagios.cmd (httpd_sys_content_t). For complete SELinux messages. run sealert -l 4df0946e-8816-4b90-a7d1-37e743697b9c </span></div>
<p>As you can see, SELinux is trying to give you a hint with that <strong>sealert</strong> bit, so you should take it.</p>
<div style="margin-left:40px;font-family:courier new,monospace;">$ sealert -l 1ffc2533-42b5-4e04-b7ab-a81bb7d02040<br />
Summary:</p>
<p>SELinux is preventing ping (ping_t) &#8220;read write&#8221; to<br />
/usr/local/nagios/var/spool/checkresults/checkrXH96b (usr_t).</p>
<p>Detailed Description:</p>
<p><em>&#8230; (removed from post)</em></p>
<p>Raw Audit Messages</p>
<p>host=myhost.myisp.host type=AVC msg=audit(1241217029.141:125305): avc:  denied  { read write } for  pid=32379 comm=&#8221;ping&#8221; path=&#8221;/usr/local/nagios/var/spool/checkresults/checkrXH96b&#8221; dev=sda3 ino=52894945 scontext=user_u:system_r:ping_t:s0 tcontext=user_u:object_r:usr_t:s0 tclass=file</p>
<p>host=myhost.myisp.host type=SYSCALL msg=audit(1241217029.141:125305): arch=c000003e syscall=59 success=yes exit=0 a0=153952a0 a1=15395330 a2=7fff75c5eb40 a3=0 items=0 ppid=32378 pid=32379 auid=503 uid=508 gid=508 euid=0 suid=0 fsuid=0 egid=508 sgid=508 fsgid=508 tty=(none) ses=1392 comm=&#8221;ping&#8221; exe=&#8221;/bin/ping&#8221; subj=user_u:system_r:ping_t:s0 key=(null)</p></div>
<p>That raw audit message is <strong>GOLD</strong>! There is some other information in there, but nothing about what the next step should be to create a policy and make it permanent. Using <strong><span style="font-family:courier new,monospace;">chron</span></strong> I have heard is a temporary fix. The solution is copying that raw audit message into an empty file and running <strong>audit2allow</strong> to create a policy:</p>
<div style="margin-left:40px;font-family:courier new,monospace;">$ cat &gt; /tmp/tmp-nagiosping<br />
host=myhost.myisp.host type=AVC msg=audit(1241217029.141:125305): avc:  denied  { read write } for  pid=32379 comm=&#8221;ping&#8221; path=&#8221;/usr/local/nagios/var/spool/checkresults/checkrXH96b&#8221; dev=sda3 ino=52894945 scontext=user_u:system_r:ping_t:s0 tcontext=user_u:object_r:usr_t:s0 tclass=file</p>
<p>host=myhost.myisp.host type=SYSCALL msg=audit(1241217029.141:125305): arch=c000003e syscall=59 success=yes exit=0 a0=153952a0 a1=15395330 a2=7fff75c5eb40 a3=0 items=0 ppid=32378 pid=32379 auid=503 uid=508 gid=508 euid=0 suid=0 fsuid=0 egid=508 sgid=508 fsgid=508 tty=(none) ses=1392 comm=&#8221;ping&#8221; exe=&#8221;/bin/ping&#8221; subj=user_u:system_r:ping_t:s0 key=(null)<br />
<em>* Ctrl-D *</em></p>
<p>$ audit2allow -M NagiosPing &lt; /tmp/tmp-nagiosping</p>
<p>******************** IMPORTANT ***********************<br />
To make this policy package active, execute:</p>
<p>semodule -i NagiosPing.pp</p></div>
<p>This creates a file call NagiosPing.pp which contains the SELinux policy needed to make these errors go away. The only thing left to do is to install this policy:</p>
<div style="margin-left:40px;"><span style="font-family:courier new,monospace;">$ semodule -i NagiosPing.pp</span></div>
<p>If your setup was like mine, SELinux was actually preventing 3 different actions, needing 3 different policies. HA! That is easy now &#8211; just repeat the steps until Nagios is doing your bidding.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pas.net.au/2009/05/fighting-with-selinux-and-nagios/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
