Archivo de la etiqueta: nagios

Configurando nagios 4

En esta guía vamos a ver como configurar nagios 4 instalado compilando las fuentes siguiendo este manual.

También debemos tener instalada la suite LAMP ( linux, apache, mysql, php )

El directorio base de indtalación será /usr/local/nagios

En el directorio libexec tenemos algunos módulos, otros se han descargado desde diferentes sitios, ya que nagios tiene una comunidad activa muy amplia.

En el directorio etc, tenemos el archivo nagios.cfg donde tendremos que poner los archivos de configuración que vamos a utilizar:

# OBJECT CONFIGURATION FILE(S)
# These are the object configuration files in which you define hosts,
# host groups, contacts, contact groups, services, etc.
# You can split your object definitions across several config files
# if you wish (as shown below), or keep them all in a single config file.

# You can specify individual object config files as shown below:
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg

# Definitions for monitoring the local (Linux) host
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg

# Definitions for monitoring a Windows machine
#cfg_file=/usr/local/nagios/etc/objects/windows.cfg

# Definitions for monitoring a router/switch
#cfg_file=/usr/local/nagios/etc/objects/switch.cfg

# Definitions for monitoring a network printer
#cfg_file=/usr/local/nagios/etc/objects/printer.cfg

Vamos al directorio siempre a partir de la base etc/objects paar ver ejemplos de configuración.

commands.cfg, donde especificaremos como llamar al plugin y los parámetros a pasar ( ej -w ( warning ) -c ( critical ) esto se especifica con la variable $ARGS$ y -H $HOSTNAME$ para el host ):

# 'check_local_disk' command definition
define command{
command_name check_local_disk
command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
}

# 'check_local_load' command definition
define command{
command_name check_local_load
command_line $USER1$/check_load -w $ARG1$ -c $ARG2$
}

# 'check_local_procs' command definition
define command{
command_name check_local_procs
command_line $USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
}
define command{
command_name check_cpu
command_line $USER1$/check_cpu.sh -w $ARG1$ -c $ARG2$
}

# check_nrpe_memory
define command {
command_name check_nrpe_memory
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c memory
}

define command {
command_name check_tomcat
command_line $USER1$/check_tomcat.pl
}

define command{
command_name check_ntp_time
command_line $USER1$/check_ntp_time -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$

....

cearemos uno o mas archivos ( siempre hay que poner la ruta en basedir/etc/nagios ). Para grandes infraestructuras es mejor ponerlo en archivos diferenetes.

hostgroups.cfg:

###############################################################################
###############################################################################
#
# HOST GROUP DEFINITION
#
###############################################################################
###############################################################################

# Define an optional hostgroup for Linux machines

define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members systal,systal2 ; Comma separated list of hosts that belong to this group
}

define hostgroup{
hostgroup_name ssh-servers ; The name of the hostgroup
alias SSH Servers ; Long name of the group
members systal2 ; Comma separated list of hosts that belong to this group
}

define hostgroup{
hostgroup_name app-servers ; The name of the hostgroup
alias App Servers ; Long name of the group
members systal ; Comma separated list of hosts that belong to this group
}

define hostgroup{
hostgroup_name http-servers ; The name of the hostgroup
alias HTTP Servers ; Long name of the group
members systal ; Comma separated list of hosts that belong to this group
}

hosts.cfg:

###############################################################################
###############################################################################
#
# HOST DEFINITION
#
###############################################################################
###############################################################################

# Define a host for the local machine

define host{
use linux-server
host_name systal
alias systal
address 127.0.0.1
}

define host{
use linux-server
host_name systal2
alias systal2
address 188.226.140.96
}

services.cfg, donde se llama al comando con los parámetros. Cada ! es un parámetro:

define service{
use generic-service ; Name of service template to use
hostgroup_name linux-servers
service_description Root Partition
check_command check_local_disk!20%!10%!/
}

# Define a service to check the number of currently logged in
# users on the local machine. Warning if > 20 users, critical
# if > 50 users.

define service{
use generic-service ; Name of service template to use
hostgroup_name linux-servers
service_description Current Users
check_command check_local_users!20!50
}

# Define a service to check the number of currently running procs
# on the local machine. Warning if > 250 processes, critical if
# > 400 users.

define service{
use generic-service ; Name of service template to use
hostgroup_name linux-servers
service_description Total Processes
check_command check_local_procs!250!400!RSZDT
}

define service{
use generic-service ; Name of service template to use
hostgroup_name linux-servers
service_description Current Load
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}

# Define a service to check the swap usage the local machine.
# Critical if less than 10% of swap is free, warning if less than 20% is free

define service{
use generic-service ; Name of service template to use
hostgroup_name linux-servers
service_description Swap Usage
check_command check_local_swap!20!10
}

define service{
use generic-service ; Name of service template to use
hostgroup_name ssh-servers
service_description SSH Server
check_command check_ssh
notifications_enabled 1
}

define service{
use generic-service ; Name of service template to use
hostgroup_name http-servers
service_description HTTP Server
check_command check_http
notifications_enabled 0
}

define service{
use generic-service ; Name of service template to use
host_name systal2
service_description CPU Usage
check_command check_cpu!80!90
notifications_enabled 1
}

define service{
use generic-service ; Name of service template to use
host_name systal2
service_description RAM Usage
check_command check_nrpe_memory
notifications_enabled 1
}

define service{
use generic-service ; Name of service template to use
host_name systal2
service_description NTP
check_command check_ntp_time!2!3
notifications_enabled 1
}

define service{
use generic-service ; Name of service template to use
hostgroup_name app-servers
service_description Tomcat
check_command check_tomcat
notifications_enabled 1
}

En las máquinas destino hay que instalar el plugin nrpe, en este caso desde CentOS/RHEL:

# yum install nrpe

Editamos el archivo /etc/nagios/nrpe.cfg en las máquinas destino:

allowed_hosts=127.0.0.1,<- Aquí la IP del servidor nagios
dont_blame_nrpe=1

Reiniciamos el agente:

# service nrpe restart

Añadimos una regla a iptables:

iptables -A INPUT -i eth0 -p tcp --dport 5666 -m state --state NEW,ESTABLISHED -j ACCEPT

Ahora en el servidor nagios reniciamos el servicio:

# service nagios restart

Y con esto ya tenemos algunos servicios y procesos monitorizados. Hay infinidad de plugins y opciones de confiuravión en nagios.

Para ver la interfaz web tenemos que abrir el navegador y escribir:

http://ipservidornagios/nagios

Nos pedirá las credenciales que hemos configurado en la instalación con el comando:

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Selección_002