Install and Configure Nagios in FreeBSD12

Windows Articles

Monitoring Ubuntu 20.04 with Stacer

Normally if we use Linux on a production server, it is important to monitor it. On the other hand, in everyday use, many users...

How to get the Android 11 Notification Panel

It's no secret that even though Android is the most widely used mobile operating system. Not always our device has the latest...

How to create backups in Windows 10 with FileFort Backup

There is no doubt that the computer is an essential element in our lives. Indeed, its uses go beyond work or study....

Trisquel 9.0 available

Trisquel is a GNU/Linux distribution endorsed and supported by the Free Software Foundation. This means that in addition to incorporating the Linux...

How to install PandoraFMS on CentOS 8?

Worldwide many IT infrastructures are running Linux on one of their servers. This opens the door to an endless number of different...
Mel Khamlichi
Mel Khamlichihttp://www.osradar.com
Founder of Osradar, from Amsterdam Netherlands

I found Nagios one of the best Opensource monitoring tools and have many features

  • Monitoring of network services (SMTP, POP3, HTTP, NNTP, PING, etc.)
  • Monitoring of host resources (processor load, disk usage, etc.)
  • Simple plugin design that allows users to easily develop their own service checks
  • Parallelized service checks
  • Ability to define network host hierarchy using “parent” hosts, allowing detection of and the distinction between hosts that are down and those that are unreachable
  • Contact notifications when service or host problems occur and get resolved (via email, pager, or user-defined method)
  • Ability to define event handlers to be run during service or host events for proactive problem resolution
  • Automatic log file rotation
  • Support for implementing redundant monitoring hosts
  • Optional web interface for viewing current network status, notification and problem history, log file, etc.

Lets start :

Some information About my hostname and Network

Hostname = osradarBSD

IP = 192.168.65.130

root@OsradarBSD:~ # pkg install apache24
Updating FreeBSD repository catalogue…
FreeBSD repository is up to date.
All repositories are up to date.
The following 12 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
apache24: 2.4.41
libnghttp2: 1.40.0
libxml2: 2.9.10
expat: 2.2.8
perl5: 5.30.1
pcre: 8.43_2
apr: 1.7.0.1.6.1
gdbm: 1.18.1_1
indexinfo: 0.3.1
readline: 8.0.1
gettext-runtime: 0.20.1
db5: 5.3.28_7

The process will require 153 MiB more space.
35 MiB to be downloade
d.

Number of packages to be installed: 12

roceed with this action? [y/N]:

To run apache www server from startup, add apache24_enable=”yes”
in your /etc/rc.conf. Extra options can be found in startup script.

Restart Apache

root@OsradarBSD:/etc/rc.d # /usr/local/etc/rc.d/apache24 restart
Performing sanity check on apache24 configuration:
Syntax OK
Stopping apache24.
Waiting for PIDS: 2343.
Performing sanity check on apache24 configuration:
Syntax OK
Starting apache24.
root@OsradarBSD:/etc/rc.d #

Check if the apache24 available with http://hostname of http://IP

update the repository by invoking the following command.

root@OsradarBSD:~ # pkg update -f
Updating FreeBSD repository catalogue…
Fetching meta.txz: 100% 944 B 0.9kB/s 00:01
Fetching packagesite.txz: 100% 6 MiB 3.3MB/s 00:02
Processing entries: 100%

Lets install Nagiios

root@OsradarBSD:~ # pkg install nagios
Updating FreeBSD repository catalogue…
FreeBSD repository is up to date.
All repositories are up to date.
The following 14 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
nagios: 3.5.1_11
nagios-plugins: 2.3.1,1
php72: 7.2.27
libargon2: 20190702
libgd: 2.2.5_2,1
fontconfig: 2.12.6,1
freetype2: 2.10.1
webp: 1.0.3_1
tiff: 4.1.0
jpeg-turbo: 2.0.3
jbigkit: 2.1_1
png: 1.6.37
giflib: 5.2.1
libltdl: 2.4.6

Enable Nagios in /etc/rc.conf with the following line:

nagios_enable="YES"

Configure Nagios

root@OsradarBSD:~ # ls -altr /usr/local/etc/nagios/
total 72
-rw-r--r-- 1 root wheel 1340 Jan 25 02:20 resource.cfg-sample
-rw-r--r-- 1 root wheel 44655 Jan 25 02:20 nagios.cfg-sample
-rw-r--r-- 1 root wheel 11665 Jan 25 02:20 cgi.cfg-sample
drwxr-xr-x 10 root wheel 512 Jan 27 16:03 ..
drwxr-xr-x 2 root wheel 512 Jan 27 16:03 objects
drwxr-xr-x 3 root wheel 512 Jan 27 16:03 .
root@OsradarBSD:~ # cd /usr/local/etc/nagios/
root@OsradarBSD:/usr/local/etc/nagios # cp resource.cfg-sample resource.cfg
root@OsradarBSD:/usr/local/etc/nagios # cp nagios.cfg-sample nagios.cfg
root@OsradarBSD:/usr/local/etc/nagios # cp cgi.cfg-sample cgi.cfg
root@OsradarBSD:/usr/local/etc/nagios #

Also in the objects do the same

root@OsradarBSD:/usr/local/etc/nagios/objects # pwd
/usr/local/etc/nagios/objects
root@OsradarBSD:/usr/local/etc/nagios/objects # ls -altr
total 52
-rw-r--r-- 1 root wheel 3208 Jan 25 02:20 timeperiods.cfg-sample
-rw-r--r-- 1 root wheel 10824 Jan 25 02:20 templates.cfg-sample
-rw-r--r-- 1 root wheel 3293 Jan 25 02:20 switch.cfg-sample
-rw-r--r-- 1 root wheel 3124 Jan 25 02:20 printer.cfg-sample
-rw-r--r-- 1 root wheel 5415 Jan 25 02:20 localhost.cfg-sample
-rw-r--r-- 1 root wheel 2166 Jan 25 02:20 contacts.cfg-sample
-rw-r--r-- 1 root wheel 7716 Jan 25 02:20 commands.cfg-sample
drwxr-xr-x 2 root wheel 512 Jan 27 16:03 .
drwxr-xr-x 3 root wheel 512 Jan 27 16:23 ..
root@OsradarBSD:/usr/local/etc/nagios/objects # cp timeperiods.cfg-sample timeperiods.cfg
root@OsradarBSD:/usr/local/etc/nagios/objects # cp templates.cfg-sample templates.cfg
root@OsradarBSD:/usr/local/etc/nagios/objects # cp switch.cfg-sample switch.cfg
root@OsradarBSD:/usr/local/etc/nagios/objects # cp printer.cfg-sample printer.cfg
root@OsradarBSD:/usr/local/etc/nagios/objects # cp localhost.cfg-sample localhost.cfg
root@OsradarBSD:/usr/local/etc/nagios/objects # cp contacts.cfg-sample contacts.cfg
root@OsradarBSD:/usr/local/etc/nagios/objects # cp commands.cfg-sample commands.cfg
root@OsradarBSD:/usr/local/etc/nagios/objects #

Check Nagios Configuration

#nagios -v /usr/local/etc/nagios/nagios.cfg


Create nagios admin user

root@OsradarBSD:/usr/local/etc/nagios/objects # htpasswd -c /usr/local/etc/nagios/htpasswd.userss nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
root@OsradarBSD:/usr/local/etc/nagios/objects #

Please remember the password to use it later to access the Nagios Console

Please see my httpd and php configs configs.

Nagios.conf file

root@OsradarBSD:~ # cat /usr/local/etc/apache24/Includes/nagios.conf

LoadModule cgi_module libexec/apache24/mod_cgi.so
LoadModule cgid_module libexec/apache24/mod_cgid.so
Options +ExecCGI
AddHandler cgi-script .cgi

<Directory />
Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
</Directory>
ScriptAlias /nagios/cgi-bin/ /usr/local/www/nagios/cgi-bin/

Alias /nagios /usr/local/www/nagios/
<Directory /usr/local/www/nagios>

Options None

AllowOverride None

Order allow,deny

Allow from all

AuthName   "Nagios Access"

AuthType Basic

AuthUSerFile /usr/local/etc/nagios/htpasswd.users

Require valid-user

</Directory>
<Directory /usr/local/www/nagios/cgi-bin>

Options ExecCGI

AllowOverride None

Order allow,deny

Allow from all

AuthName   "Nagios Access"

AuthType Basic

AuthUSerFile /usr/local/etc/nagios/htpasswd.users

Require valid-user

</Directory>

My PHP conf file

root@OsradarBSD:~ # cat /usr/local/etc/apache24/Includes/php.conf
<IfModule dir_module>
    DirectoryIndex index.php index.html
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
</IfModule>
root@OsradarBSD:~ #

My apache24 Config

The config is excluded Loadmodule lines and commented lines #

root@OsradarBSD:~ # cat /usr/local/etc/apache24/httpd.conf | grep -v LoadMo | grep -v #

ServerRoot "/usr/local"


Listen 80

<IfModule !mpm_prefork_module>
</IfModule>
<IfModule mpm_prefork_module>
</IfModule>

IncludeOptional etc/apache24/modules.d/[0-9][0-9][0-9]_*.conf

<IfModule unixd_module>
User www
Group www

</IfModule>


ServerAdmin you@example.com

ServerName osradarbsd:80

<Directory />
    AllowOverride none
    Require all granted
</Directory>


DocumentRoot "/usr/local/www/apache24/data"
<Directory "/usr/local/www/apache24/data">
    Options Indexes FollowSymLinks

    AllowOverride None

    Require all granted
</Directory>

<IfModule dir_module>
 DirectoryIndex index.php index.html index.php
 AddType application/x-httpd-php .php
 AddType application/x-httpd-php-source .phps
</IfModule>
<Files ".ht*">
    Require all denied
</Files>

ErrorLog "/var/log/httpd-error.log"

LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "/var/log/httpd-access.log" common

</IfModule>

<IfModule alias_module>


    ScriptAlias /cgi-bin/ "/usr/local/www/apache24/cgi-bin/"

</IfModule>

<IfModule cgid_module>
</IfModule>

<Directory "/usr/local/www/apache24/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule headers_module>
    RequestHeader unset Proxy early
</IfModule>

<IfModule mime_module>
    TypesConfig etc/apache24/mime.types

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz



</IfModule>



<IfModule proxy_html_module>
Include etc/apache24/extra/proxy-html.conf
</IfModule>

<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

Include etc/apache24/Includes/*.conf

root@OsradarBSD:~ #

Please restart Apache and nagios Services

root@OsradarBSD:~ # service apache24 restart
Performing sanity check on apache24 configuration:
Syntax OK
Stopping apache24.
Waiting for PIDS: 765.
Performing sanity check on apache24 configuration:
Syntax OK
Starting apache24.
root@OsradarBSD:~ # service nagios  restart
Performing sanity check of nagios configuration: OK
Stopping nagios.
Waiting for PIDS: 737.
Performing sanity check of nagios configuration: OK
Starting nagios.
root@OsradarBSD:~ #

Now access the Nagios Console from http://ip/nagios and put the user and password already generated before

Please use this tutorial and tell us your feedback and if we missed something that we can adjust or add.

Cheers

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

Monitoring Ubuntu 20.04 with Stacer

Normally if we use Linux on a production server, it is important to monitor it. On the other hand, in everyday use, many users...

How to get the Android 11 Notification Panel

It's no secret that even though Android is the most widely used mobile operating system. Not always our device has the latest...

How to create backups in Windows 10 with FileFort Backup

There is no doubt that the computer is an essential element in our lives. Indeed, its uses go beyond work or study....

Trisquel 9.0 available

Trisquel is a GNU/Linux distribution endorsed and supported by the Free Software Foundation. This means that in addition to incorporating the Linux...

How to install PandoraFMS on CentOS 8?

Worldwide many IT infrastructures are running Linux on one of their servers. This opens the door to an endless number of different...
x