Depois que compilamos o
Nagios e suas dependências, é necessário iniciarmos a configuração do servidor. Vamos criar o arquivo onde será armazenado os usuários que irão administrar o Nagios.
Se caso não existir, vamos criar um arquivo em branco chamado de
htpasswd.users no diretório do Nagios:
# vim /usr/local/nagios/etc/htpasswd.users
Salve e feche o arquivo em branco.
Vamos criar o usuário administrador do Nagios:
# htpasswd /usr/local/nagios/etc/htpasswd.users nagiosadmin
Crie uma senha e a confirme em seguida.
Após criar o usuário, vamos reiniciar os serviços do Nagios e do Apache:
# service nagios restart
# service apache2 restart
Vamos acessar o Nagios pela primeira vez e testar se está funcionando, abra o seu navegador predileto e acesse o HTTP://x.x.x.x/nagios (onde x.x.x.x é o IP do servidor do Nagios)
Note que o Nagios já está monitorando o próprio servidor Nagios. Vamos agora fazer com que Nagios inicie o monitoramento do demais ativos de rede.
Vamos fazer um backup dos arquivos originais para que possamos criar nossos próprios arquivos:
# cd /usr/local/nagios/etc/
# cp nagios.cfg nagios.cfg2
Edite o arquivo nagios.cfg conforme o exemplo:
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_file=/usr/local/nagios/etc/objects/objetos.cfg
cfg_file=/usr/local/nagios/etc/objects/servicos.cfg
Vamos fazer o mesmo com os arquivos localhost e templates:
# cd /objects
# mv localhost.cfg localhost.cfg2
# mv templates.cfg templates.cfg2
Vamos criar uma nova estrutura para arquivo templates:
# vim templates.cfg
Copie e cole as configurações abaixo:
###########################################
# TEMPLATES.CFG - SAMPLE OBJECT TEMPLATES
#
#
# NOTES: This config file provides you with some example object definition
# templates that are refered by other host, service, contact, etc.
# definitions in other config files.
#
# You don't need to keep these definitions in a separate file from your
# other object definitions. This has been done just to make things
# easier to understand.
#
##########################################
##########################################
##########################################
#
# CONTACT TEMPLATES
#
##########################################
##########################################
# Generic contact definition template - This is NOT a real contact, just a template!
define contact{
name generic-contact ; The name of this contact template
service_notification_period 24x7 ; service notifications can be sent anytime
host_notification_period 24x7 ; host notifications can be sent anytime
service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events
service_notification_commands notify-service-by-email ; send service notifications via email
host_notification_commands notify-host-by-email ; send host notifications via email
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}
#########################################
#########################################
#
# HOST TEMPLATES
#
#########################################
#########################################
# Generic host definition template - This is NOT a real host, just a template!
define host{
name generic-host ; The name of this host template
notifications_enabled 1 ; Host notifications are enabled
event_handler_enabled 1 ; Host event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
notification_period 24x7 ; Send host notifications at any time
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
max_check_attempts 4 ; Notification get sent out to everyone in the 'admins' group
}
########################################
########################################
#
# SERVICE TEMPLATES
#
########################################
########################################
# Generic service definition template - This is NOT a real service, just a template!
define service{
name generic-service ; The 'name' of this service template
active_checks_enabled 1 ; Active service checks are enabled
passive_checks_enabled 1 ; Passive service checks are enabled/accepted
parallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major performance problems)
obsess_over_service 1 ; We should obsess over this service (if necessary)
check_freshness 0 ; Default is to NOT check service 'freshness'
notifications_enabled 1 ; Service notifications are enabled
event_handler_enabled 1 ; Service event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
is_volatile 0 ; The service is not volatile
check_period 24x7 ; The service can be checked at any time of the day
max_check_attempts 3 ; Re-check the service up to 3 times in order to determine its final (hard) state
normal_check_interval 10 ; Check the service every 10 minutes under normal conditions
retry_check_interval 2 ; Re-check the service every two minutes until a hard state can be determined
contact_groups admins ; Notifications get sent out to everyone in the 'admins' group
notification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery events
notification_interval 60 ; Re-notify about service problems every hour
notification_period 24x7 ; Notifications can be sent out at any time
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}
Vamos agora criar o arquivo
objetos.cfg.
Esse arquivo é onde são armazenados as configurações de cada host monitorado. Você deve configura-lo conforme seu ambiente, ele é apenas um exemplo, porém de fácil entendimento.
# vim objetos.cfg
Cole o conteúdo abaixo e comece a configurar seguindo como exemplo:
#Ativos do nagios, configurado por Erik Pinheiro
define host{
use generic-host
host_name servidor2
alias Windows AD
address 192.168.0.xxx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name servidor3
alias Linux Firewall Matriz
address 192.168.0.xxx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name Servidor4
alias Totvs
address 192.168.0.xxx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name servidor5
alias SQL
address 192.168.0.xxx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name servidor6
alias BKP e ESET
address 192.168.0.xxx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name servidor_filial
alias Windows AD Sorocaba
address 192.168.1.xxx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name firewall_filial
alias Firewall Filial
address 201.xx.xxx.xx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name DIMEP_ADM
alias Ponto ADM
address 192.168.0.xxx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name DIMEP_PROD
alias Ponto Prod
address 192.168.0.xxx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name HP_LJ_2050_LAB_DES
alias Impressora Lab Des
address 192.168.0.xxx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name HP_LJ_4250_ADM
alias Impressora Adm
address 192.168.0.xxx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name LEXMARK_X364
alias Multifuncional
address 192.168.0.xxx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name HP_OJ_4250
alias Impressora Color
address 192.168.0.xxx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name WIFI_VIVO
alias Wifi Vivo
address 189.xx.xxx.xxx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name LINK_EBT
alias Link Primario
address 201.xx.xxx.xx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name LINK_CTI
alias Link Secundario
address 186.xxx.xxx.xxx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name LINK_FILIAL
alias Link Filial
address 201.xxx.xxx.xx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name HP_V1910_1
alias Switch CPD 1
address 192.168.0.xxx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name HP_V1910_2
alias Switch CPD 2
address 192.168.0.xxx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name HP_V1910_3
alias Switch CPD 3
address 192.168.0.xxx
check_command check-host-alive
contact_groups admins
}
define host{
use generic-host
host_name SRVPABX
alias PABX e SSD
address 192.168.0.xxx
check_command check-host-alive
contact_groups admins
}
Vamos agora criar os arquivo de serviços.cfg. É neste arquivo que apontamos o que Nagios vai monitorar em cada um dos hosts que configuramos acima, esse arquivo também deve ser configurado conforme seu ambiente, tratando-se apenas de um exemplo.
Comentei as linhas para facilitar um pouco a interpretação de cada um dos serviços:
# vim servicos.cfg
# Vai ficar pingando o host configurado, no meu caso eu coloquei para pingar tudo o que configurei no arquivo objetos, porém como é um exemplo, não digitei todos os servidores e serviços que quero pingar.
define service{
use generic-service
host_name servidor2,servidor3,servidor4...
service_description Ping
check_command check_ping!100.0,20%!500.0,60%
}
#Monitora o status da porta 3389
define service{
use generic-service
host_name servidor2
service_description TCP
check_command check_tcp!3389
}
#Monitora o uso de memória dos servidores Windows
define service{
use generic-service
host_name servidor2,servidor3,servidor4...
service_description Memory Usage
check_command check_nt!MEMUSE!-w 80 -c 90
}
#Monitora a CPU dos servidores Windows
define service{
use generic-service
host_name servidor2,servidor3,servidor4...
service_description CPU Load
check_command check_nt!CPULOAD!-l 5,80,90
}
#Monitora o espaço em disco C:\ dos servidores Windows
define service{
use generic-service
host_name servidor2,servidor3,servidor4...
service_description C:\ Drive Space
check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90
}
#Monitora o espaço em disco E:\ dos servidores Windows, note que unica mudança está na linha check_command ;)
define service{
use generic-service
host_name servidor2,servidor3,servidor4...
service_description E:\ Drive Space
check_command check_nt!USEDDISKSPACE!-l e -w 80 -c 90
}
#Checa o status das impressoras
define service{
use generic-service
host_name HP_LJ_2050_LAB_DES,HP_LJ_4250_ADM,HP_OJ_4250
service_description Printer Status
check_command check_hpjd!-C public
}
Vamos novamente reiniciar o serviço do Nagios:
# service nagios restart
Caso os tenha, trate os erros, ele irá informar onde está o erro (incluindo a linha) e em seguida reinicie o serviço do Nagios Acesse novamente pelo seu navegador o Nagios (HTTP://x.x.x.x/nagios).
Ao acessar, vamos notar que os serviços Windows estão com falha, isso ocorre porque é necessário instalar nos servidores Windows o Client do Nagios.