# How to install nagios with the ebuild

## pooky

Okay, I've been screwing up my system lately trying to install nagios with the ebuild. I rebuilt a red hat 7.3 machine with Gentoo (which I love and use everywhere!)

I'm a bit of a Gentoo newbie and a little less of a Linux newbie (I know enough to be WAY dangerous  :Twisted Evil:  ), so I started by emerging the nagios metapackage and then apache2 with fairly bad results.

I figured I'd post this becuase I see countless messages in the forums regarding the problems installing nagios and the recommendations to not use the ebuild. I'm here to tell you that it's not that bad. It took me 3 times to get it right, mostly because I couldn't find good instructions on what needed to be done. I 1st tried just the ebuild and apcahe2, then I reloaded the machine and tried to emerge apache2 and load the nagios packages manually with the supporting libraries with horrible results.

I'm here to tell you, the ebuild works fine and it's actually pretty easy. To install nagios properly, you need to do this:

```
USE "apache2 gd" emerge nagios
```

This will emerge all dependencies to make nagios work properly as a monitoring system, including the current apache2 ebuild and all the gd dependencies. It takes forever, there are currently about 34 packages that need to load, many to support libgd operation. Yes it loads XFree, yes it takes forever, it doesn't take up that much disk space and you don't have to run it so no big deal.

Like others whom have done this successfully I suspect, I did not see any messages at the end of the build on configuring nagios. This is done with this command:

```
ebuild /var/db/pkg/net-analyzer/nagios-core-1.1-r4/nagios-core-1.1-r4.ebuild config
```

This configures apache to display the nagios web. There however remains a few steps. You also need to add a flag to /etc/conf.d/apache2, either add this line if it is commented out and not defined or add to the end of the line "-D NAGIOS"

```
APACHE2_OPTS="-D NAGIOS"
```

At this point you can go ahead and configure nagios. Remember to add both nagios and apcahe2 to start automatically:

```
cd /etc/init.d

rc-update add apache2 default

rc-update add nagios default
```

** Updated 6/22/04 **

Lastly, I ran into a problem with the security of the /var/nagios/rw directory. There is a file that is spontaneously created and removed there called nagios.cmd, it is the external command check file. For some reason nagios continues to complain that it cannot execute the file.  Thanks to some additional research and the help of Janne Pikkarainen, here is the procedure to fix this:

```
chown nagios.apache /var/nagios/rw

chmod 770 /var/nagios/rw

chown nagios.apache /var/nagios/rw/check.cmd

chmod 770 /var/nagios/rw/check.cmd

chmod g+s /var/nagios/rw
```

This sets the proper permissions for the owner and groups and leaves users with no access. The owner is set to nagios and group is set to apache. This will allow the web interface to modify the file and nagios to use it for executing whatever task was requested.

The last command is the important one as some of the above is performed by the ebuild. The last command sets the group sticky bit so when the nagios.cmd file is recreated it inherits the proper permissions. I will point out that much of this information was available in the nagios on-line documentation, had I bothered to read it!   :Embarassed:  The instructions provided by the author are here:

http://nagios.sourceforge.net/docs/1_0/commandfile.html

Note they use a custom group like nagiocmd to provide access. This is perfectly fine but you can just use the apache group and work fine without the extra steps.

I hope this helps others out there who need to get nagios up and running use the ebuild to do it. I look forward to nagios-1.2 being marked stable so I can update my system.   :Smile: 

--pooky

----------

## Janne Pikkarainen

Nice guide, although I solved the chmod problem with

```
chgrp -R apache /var/run/nagios/rw

chmod -R 775 /var/run/nagios/rw
```

That way only Apache group and Nagios user has write access to that file. Should be enough to make Nagios work.

----------

## arrowood

There are several threads where people have emerged nagios but ended up missing files in the following directories:

/usr/nagios/sbin

/usr/nagios/share

Here is what I had to do to work around it:

https://forums.gentoo.org/viewtopic.php?t=185235

Hopefully this will save some people some time.

If anyone figures out what was wrong, I'd love to know...

----------

## pooky

Many thanks to Janne Pikkarainen, that solved my issues with the check commands. It appears a simple chown nagios:apache on both /var/nagios/rw and the nagios.cmd file will allow the featrue to operate properly.   :Razz: 

Pooky

----------

## pooky

 *arrowood wrote:*   

> There are several threads where people have emerged nagios but ended up missing files in the following directories:
> 
> /usr/nagios/sbin
> 
> /usr/nagios/share
> ...

 

It's like the normal emerge of nagios assumes you are installing a machine to perform remote monitoring ONLY. I ran into this as well with my 1st install, however my last install which is detailed in my original post did not have this problem, I'm assuming because the USE flags were set that time. Like many, I just emerged the package straight on my 1st attempt with no success.

Not being the maintainer, I can't say for sure, but I'll bet the nagios-plugins and the web interface won't install without the apache2 USE flag.

----------

## Janne Pikkarainen

pooky: You're welcome.  :Very Happy: 

----------

## pooky

Ahh, I finally stumbled across the missing piece to get the external command file to work properly. Seems to help to read the documentation. As the last step, execute these commands:

```
chmod g+s /var/nagios/rw
```

This enables the group sticky bit on the directory and will make it so the recreated nagios.cmd file inherits the proper permissions each time.

Whew. It would be nice if the ebuild did this for you!  :Cool: 

Pooky

----------

## jewps

Sorry to bring an old thread back up but I thought other users might like to know the nagios ebuilds are completely f'd. By that i mean the ebuild nagios.ebuild config part is broken, it doesn't tell you where your db schema should look like, sample configs are not installed by default. 

On a side note, the documentation is just plain confusing. It's a great program but if they told you what each config does, it would make things a lot easier imo..

----------

## tecknojunky

 *jewps wrote:*   

> On a side note, the documentation is just plain confusing. It's a great program but if they told you what each config does, it would make things a lot easier imo..

 Nagios will not win any prize in software design, that's a fact.  But nagios's config files and each of their functions are documented in the html that are installed in nagios.  I think there are far much more software with far much less documentations (some none) than what nagios have.

If there is something confusing, it's the anoying habit that whatever ebuild must install where the sacro-saint LSB say so and not where the author meant (I hate the LSB, I want it annihilated from the face of the heart,  That and Java gone, only Bin Laden will be left to deal with).  So, now, the doc refer to files that are elsewhere.  IE:  I'm trying to enable htpasswd, but nagios doc do that in /usr/local/nagios/etc.  I can't locate the equivalent in /usr/nagios and I'm confused.

----------

## pooky

 *jewps wrote:*   

> By that i mean the ebuild nagios.ebuild config part is broken, it doesn't tell you where your db schema should look like, sample configs are not installed by default. 

 

Interesting, I had no problems getting the example config files installed. This command is what I used to generate the config files:

```
ebuild /var/db/pkg/net-analyzer/nagios-core-1.1-r4/nagios-core-1.1-r4.ebuild config
```

Did you try running this? It might be the nagios package has been updated since I started this thread and this doesn't work, if so I'd like to know.

--pooky

----------

## pooky

 *tecknojunky wrote:*   

> IE:  I'm trying to enable htpasswd, but nagios doc do that in /usr/local/nagios/etc.  I can't locate the equivalent in /usr/nagios and I'm confused.

 

If it helps, the web exists under the path /usr/nagios/share. I believe all I did was to create a .htaccess file there:

```
AuthName "Nagios Access"

AuthType Basic

AuthUserFile /etc/nagios/htpasswd.users

require valid-user
```

The /etc/nagios/htpasswd.users file is just the normal format. I believe you need to use the user defined in your nagios configuration for access otherwise things will not work.

I agree the change in paths from the documentation is very confusing, the instructions provided in the nagios documentation don't work at all with the e-build (hence my entire reason for starting this thread  :Wink: ) To make life easier in the web since everything exists under a virtual path of /nagios on the site, I used a basic index.html page that just redirects people to the nagios web, may or may not be appropriate for your installation. Files under /var/www/localhost/htdocs:

```
<HTML>

<HEAD>

<META HTTP-EQUIV="refresh" content="0;URL=http://nagios.somedomain.com/nagios/">

</HEAD>

<BODY>

</BODY>

</HTML>
```

Hope this helps!

--pooky

----------

## aman

I have been trying to follow the initial post and I am hung up trying to config the ebuild

```
root # ebuild /var/db/pkg/net-analyzer/nagios-core-1.2-r1/nagios-core-1.2-r1.ebuild config

/usr/sbin/ebuild.sh: line 1337: pkg_config: command not found

root #

```

Anyone have an idea?

----------

## tschenturs

I have upgraded to nagios-core-1.2-r3. It seems to implement most of what is suggested in this thread. 

Google also revealed a nagios-howto in french (http://www.gentoofr.org/docs/nagios-guide.html). It is not quite up to date as it does not consider the changes in -r3. You can get the important parts even if you don't speek french  :Wink: . 

The new ebuild also implements issues mentioned there.

 The sample configuration files are installed into /usr/share/doc/nagios-core-1.2-r3/sample-configs/. (=> You don't need to run the 'ebuild ... config' manually).

 The permissions of /var/nagios/rw:

The ebuild sets them to 6755 however:

 *Quote:*   

> 
> 
> $ drwsr-sr-x  2 nagios apache 35 29. Dez 10:12 rw
> 
> 

 

The suggestion further up in this thread (and the reference http://nagios.sourceforge.net/docs/1_0/commandfile.html) is 2770:

 *Quote:*   

> 
> 
> $ drwxrws---  2 nagios apache 35 29. Dez 10:12 rw
> 
> 

 

Thus, it should probably rather be:

 *Quote:*   

> 
> 
> # chmod 2770 /var/nagios/rw
> 
> 

 

(See Bug 76011)

The following steps are still necessary:

 create the file .htaccess in /usr/nagios/sbin (see http://gentoofr.org/docs/nagios-guide.html, Example code 3.5. Don't copy the '</i>' in the end if it's still there.)

 If it doesn't exist yet, create the /etc/nagios/cgi.cfg:

```

htpasswd2 -bc /etc/nagios/htpasswd.users nagiosadmin pass

```

 Set up your configuration settings in /etc/nagios. In his above mentioned french how-to, babykart shows how to download a set of configuration files to start with (see Example code 3.4).

 more yet to discover...

HTH, Urs

----------

