Sunday, March 31, 2024

Define your first objects: host / command / service


https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/objectdefinitions.html

Nagios itself won't differentiate between the files you create or use to configure host monitoring. If you wanted you could create a separate file for each service and each command, though it would definitely create big mess. We start with this option here, to understand functioning.
Then you can rename your files to some other sort of extension like .cf_ or .cf*, so that nagios will ignore them. This way we can create a total new file like "touch nagios-server.cfg" and put all information into it. This way, we will have one .cfg file for each server we monitor.

----------------------------------------------------------

4 BASE NAGIOS ELEMENTS:
    PLUG-INs - nagios executable programs : binaries, Perl or Bash scripts, etc.
    COMMANDS - to launch plug-ins
    HOST - Supervisable equipment , most likely with an IP address
    SERVICE - something to supervise, like SSH, HTTP, DNS, DHCP etc.
----------------------------------------------------------
HOW TO DEFINE A COMMAND, exemple:
https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/objectdefinitions.html#command

    
    # go to the our commands directory
    cd /usr/local/nagios/nag_test_conf
    
    # create a config file
    nano command.cfg
    
    # you add this for instance:
        define command {
            command_name check-ping-localhost
            command_line $USER1$/check_ping -H localhost -w 40,40% -c 60,60%
        }    
        
    #if you've opened /usr/local/nagios/etc/resource.cfg
    # you would see that macro: $USER1$=/usr/local/nagios/libexec

----------------------------------------------------------   
HOW TO DEFINE A HOST, example:
https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/objectdefinitions.html#host
        
        # we will define for the moment simply our own server to probe
        # probe with the check ping service

        
        cd /usr/local/nagios/nag_test_conf
        nano nag_test.cfg
        
        define host {
                host_name        Nagios Server
                address            localhost
                check_command    check-ping-localhost
                max_check_attempts        3
                contacts         nagiosadmin
        }        
        
----------------------------------------------------------
HOW TO DEFINE A SERVICE, exemple:
https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/objectdefinitions.html#service


        cd /usr/local/nagios/nag_test_conf
        nano nag_test.cfg
        
        # we test adding an SSH service check
        
        define command {
            command_name check-ssh-localhost
            command_line $USER1$/check_ssh localhost
        }
        
        # we apply it to our desired host (nag_host.cfg)
        
        define service {
            service_description SSH sur Nagios Server
            host_name Nagios Server
            check_command check-ssh-localhost
            max_check_attempts 3
            contacts nagiosadmin
            check_period 24x7
            notification_period 24x7
        }
----------------------------------------------------------       
PUT EVERYTHING INTO ONE FILE:
        
define command {
        command_name check-ping-localhost
        command_line $USER1$/check_ping -H localhost -w 40,40% -c 60,60%
}
define command {
        command_name check-ssh-localhost
        command_line $USER1$/check_ssh localhost
}
define host {
        host_name Nagios Server
        address localhost
        check_command check-ping-localhost
        max_check_attempts 3
        contacts nagiosadmin
}
define service {
        service_description SSH sur Nagios Server
        host_name Nagios Server
        check_command check-ssh-localhost
        max_check_attempts 3
        contacts nagiosadmin
        check_period 24x7
        notification_period 24x7
}        
        
        

_dnhyper

Monday, March 25, 2024

Learn a little about NAGIOS folder structure

 


------------------------------------------------------------

CHECK YOUR FOLDERS TO KNOW YOUR NAGIOS
    cd /usr/local/nagios/
    ls -la
    
        bin - principal nagios program folder
        libexec - base plugin folder
        etc - all base configuration
        share + sbin - administration interface elements
        var - variables simply
        rw - nagios pipe

------------------------------------------------------------


CREATE OUR OWN CONFIG REPERTOIR:
    # you can give any name to it; mine is nag_test_conf
    cd /usr/local/nagios/
    mkdir nag_test_conf
    
ADD THIS REPERTOIR TO NAGIOS.CFG:
    # when nagios starts, it will run this folder and its .cfg files
    # this is where we will put our own configs
    
    nano /usr/local/nagios/etc/config.cfg
        # go to the end of the file and add this line

        # COMMENT: DIR -> CONFIG nag_test_conf
        cfg_dir=/usr/local/nagios/nag_test_conf
        
        or
        
        echo "#CONFIG nag_test_conf" >> /usr/local/nagios/etc/nagios.cfg
        echo "cfg_dir=/usr/local/nagios/nag_test_conf" >> /usr/local/nagios/etc/nagios.cfg
        

------------------------------------------------------------

Use nagios learning tools on their websites to better understand what is going on in case of it's internal structure. Later on if you worked seriously with nagios, you'll thank for the knowledge. Migrating, securitizing, virtual hosting, external plugins and so on are not that easy, except if you knew where to look for the info. 

What you can also do is use an internal private ai and feed the entire nagios documentation to it, so you can have all the answers you needed in just a matter of seconds, anytime, with no internet needed. 

_dnhyper

Install NAGIOS Core Plugins

Nagios basic plugins are obligatory to be able install later on the probes for the machines you wanted to observe. Sudo should be installed. I don't cover non-text but dbase based logging here, so no sql / mariadb is used or needed. In addition in certain cases, if mistakenly you installed mariadb server and it is up and running, it can cause compatibility issues, errors and hiccups and often even uninstalling won't help resolving the issues. In this case, you should restart with a clean Debian. 


****************************************

https://www.nagios.org/downloads/nagios-plugins/
https://support.nagios.com/kb/article/nagios-plugins-installing-nagios-plugins-from-source-569.html#Debian

****************************************

INSTALL COMMON PREREQUISITES for PLUGINS:

    apt-get install -y autoconf automake gcc libc6 libmcrypt-dev make libssl-dev wget bc gawk dc build-essential snmp libnet-snmp-perl gettext
    apt-get install -y libdlap2-dev
    apt-get install -y libdmysqlclient-dev
    apt-get install -y smbclient
    apt-get install -y libfreeradius-client-dev
    * apt-get install -y libmariadbclient-dev  libmariadbclient-dev-compat  (normally, no need for mariadb, unless we use database back and for logging)
    apt-get install -y dnsutils
    apt-get install -y qstat
    apt-get install -y fping
    apt-get install -y qmail-tools
    
DOWNLOAD PLUGINS:
    cd /home/nagios/downloads
    wget https://nagios-plugins.org/download/nagios-plugins-2.4.9.tar.gz
    
UNZIP PLUGINS:
    tar -zxvf nagios-plugins-2.4.9.tar.gz
        
ENTER DIRECTORY:
    cd nagios-plugins-2.4.9/
    
COMPILE PLUGINS AND INDICATE USER:
    ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd
    
    config log:
        more /home/nagios/downloads/nagios-plugins-2.4.9/config.log

COMPILE BINARIES:
    make

INSTALL PLUGINS:
    make install
    
--------------------------------
PLUGINS INSTALL MAJOR PART DONE    
--------------------------------


CHANGE the NAGIOS USER SHELL to BASH SH if needed:
    chsh -s /bin/bash nagios

TEST NAGIOS with -v:
    /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
    
CREATE COMMANDE SHORTCUT FOR TEST NAGIOS -> testNagios :    
    echo "alias testNagios='/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg'" >> /home/nagios/.bashrc    

AUTHORIZE FOR COMMANDE "systemctl restart nagios" for nagios user under linux with sudo priviliges:
    echo "nagios ALL=NOPASSWD:/bin/systemctl restart nagios" >> /etc/sudoers
    
CREATE SHORTCUT FOR RESTART NAGIOS:
    echo "alias restartNagios='sudo systemctl restart nagios'" >> /home/nagios/.bashrc
    
ENTER NAGIOS USER:
    su - nagios
    
-------------------------------------
EXECUTE:
    restartNagios
    testNagios
    systemctl status nagios | grep Active

-------------------------------------

YOU SHOULD SEE SOMETHING LIKE THIS:

    systemctl status nagios | grep Active

testNagios

 

                                                                   _dnhyper

Sunday, March 24, 2024

Install NAGIOS core on DEBIAN 12

First you must install Debian 12 with no GUI and no webserver. Just the base and the SSH server. Try using another username for the base linux than nagios.
Install sudo, as on debian it is not a base package like on ubuntu and later you'll need it.

If you used a virtual machine, I recommend to start first with a bridged adapter network controller, so you don't need to go through double routing or port forwarding straight for any apt upgrade/install/update. If you were a network guru, do as you wish. The non gui server needs no resource, so 1 or 2 processor, 2 gigs of ram and 20gigs of space would be more than enough.

To copy commands into a VM, simply use SSH connection on powershell or putty:
    ssh 192.168.1.55

NOTES

https://support.nagios.com/kb/article/nagios-core-installing-nagios-core-from-source-96.html#Debian

------------------------
LINUX USER DURING INSTALL:
    PSWD SU : Azerty

    user : DNHYPER
    pswd : Azerty
-------------------------
LINUX User NAGIOS:   
        user: nagios
        pswd: Azerty
-------------------------    
WEB LOGIN (set up later):
    user: nagiosadmin
    pswd: Azerty
-------------------------  

COMMANDS

 
INSTALL SUDO:

    apt-get install sudo
        
INSTALL APACHE2 PHP ETC:
    apt-get install apache2 php php-gd php-imap php-curl php-mcrypt
            
INSTALL PERL AND IT'S LIBRARIES:
    apt-get install libxml-libxml-perl libnet-snmp-perl libperl-dev libnumber-format-perl libconfig-inifiles-perl libdatetime-perl libnet-dns-perl

INSTALL GRAPHICAL LIBRARIES:
    apt-get install libpng-dev libjpeg-dev libgd-dev
    
INSTALL CoMPILATION UTILS of MAKE and AUTOCONF WITH OTHER UTILS:
    apt-get install -y autoconf gcc libc6 make wget unzip apache2 apache2-utils php libgd-dev
    apt-get install openssl libssl-dev    
    
CREATE USER NAGIOS + PSWD:
    useradd -m -p $(openssl passwd Azerty) nagios
    
CREATE GROUP NAGCMD:    
    groupadd nagcmd

Add user NAGIOS and user www-data to group NAGCMD    
    usermod -a -G nagcmd nagios
    usermod -a -G nagcmd www-data (it is running apache2)
    
CREATE A DOWNLOAD DIRECTORY:
    mkdir /home/nagios/downloads
    
DOWNLOAD NAGIOS to the DOWNLOAD DIRECTORY:
    cd /home/nagios/downloads
    wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.5.1.tar.gz
    
DECOMPRESS ARCHIVE NAGIOS:
    tar -zxvf nagios-4.5.1.tar.gz
        
ENTER DIRECTORY:
    cd nagios-4.5.1
    
DEFAULT WEB ACCESS + GROUP DIRECTORY:
    ./configure --with-httpd-conf=/etc/apache2/sites-enabled --with-command-group=nagcmd     

LAUNCH COMPILATION:
    make all

CREATE NAGIOS ARBORESCENCE:
    make install
            
INSTALL NAGIOS SERVICE:
    make install-daemoninit    
    
INSTALL NAGIOS PIPE:
    make install-commandmode
    
INSTALL CONFIG FILES:
    make install-config
    
INSTALL WEB-ADMIN INTERFACE:
    make install-webconf
    
MODULES REWRITE AND CGI OF APACHE ENABLE:
    a2enmod rewrite
    a2enmode cgi
    
CONFIGURE ADMIN ACCESS NAGIOS by APACHE - user:nagiosadmin pswd:Azerty:
    htpasswd -cb /usr/local/nagios/etc/htpasswd.users nagiosadmin Azerty
        
CONFIG the CONFIG RIGHTS to nagios USER:
    chown -R nagios:nagcmd /usr/local/nagios
    
RESTART APACHE and START NAGIOS:
    systemctl restart apache2
    systemctl start nagios

--------------------------------------------------

This is what you should see:

GET your IP address

Apache2 is running


Nagios is running

APACHE2 web access, by typing your ip in a browser, on the same network !


Nagios Asking for login: nagiosadmin + pswd


Nagios Core interface

If you went to "Reports >> Alerts >> History" there are errors. Don't worry about it for now.

_dnhyper

Sharepoint sync and lock issues - solutions

 Sharepoint synced down to your PC by onedrive can have a ton of errors. It is caused by the simple dis-functionality of this badly thought ...