Nagios ( Core & XI )

Some basic usage examples of Nagios Core (XI) monitoring system

Add new user ( cli way)

htpasswd -c /tmp/rouser rouser
cat /tmp/rouser >> /usr/local/nagios/etc/htpasswd.users

/usr/local/nagios/etc/cgi.cfg
authorized_for_all_services=nagiosadmin,rouser
authorized_for_all_hosts=nagiosadmin,rouser

Adding new custom check ( e.g. your script) (cli way)

1. Define command

/usr/local/nagios/etc/commands.cfg

define command {
       command_name                             check_name
       command_line                             /path/to/your/executable/script.py
}

2. Define service with this command
In /usr/local/nagios/etc/ may be one *.cfg file named just «services» where will be all services
OR there will be a folder «services» with many *.cfg files for each host

/usr/local/nagios/etc/services/hostname.cfg

define service {
        host_name                       hostname
        service_description             check_description
        use                             local-service
        check_command                   check_name
        check_interval                  5 # min
        retry_interval                  1 # min
        check_period                    24x7 # default name of interval 
        register                        1
        }

3. Define host for service ( if it doesn’t exist yet)
If you still doesn’t add host in monitoring

/usr/local/nagios/etc/hosts/hostname.cfg
define host {
        host_name                       hostname
        address                         192.168.1.1
        max_check_attempts              5
        check_interval                  5
        retry_interval                  1
        register                        1
        }

NSClient custom check (WINDOWS)

Assume that you already have working nsclient and want to add new custom check that will execute in remote host

1. Place executable script in
C:\Program Files\NSClient++\scripts
2. Edit nsclient.ini file ( NSC.ini in old version)
uncomment modules

CheckExternalScripts.dll
NRPEListener.dll

Define new command

[/settings/external scripts/scripts]
check_tz=scripts\custom_check_name.bat

OR fol old versions

[External Scripts]
check_tz=scripts\custom_check_name.bat

3. Define new Nagios service

$USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c check_tz 

Perfdata handling

If you want visualizations for your custom date in graph format your script must return special perfdata format

for example, your script return string «Server uptime is $(uptime)»
that these data will be graphed, your output string sould be «Server uptime is $(uptime)|uptime=$(uptime)»

i.e. after simple output just set pipe ‘|’ and list perfadta by a space in format «variable=value»
______________________________________________________________

Ask any other questions about custom checks and perfdata handling in comments

 

____

AskDevops —> https://t.me/ithangouts

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *