Nastavljamo sa izmenama u konfiguraciji Nagios-a. Prvi deo uputstva možete videti ovde.

Za osnovnu instalaciju Nagios Core i Nagios plugin videti uputstvo na https://kompjuteras.com/osnovna-instalacija-i-konfiguracija-nagios-4-na-centos-7-korak-po-korak/.
U ovom drugom delu ćemo definisati izmene osnovnih konfiguracionih fajlova i pripremiti sve za monitoring servisa na Windows hostu i za definisanje komandi i servisa koje ćemo obraditi u trećem delu.

Menjamo sledeće:

  • nagios.cfg – glavni konfiguracioni fajl, putanja je /usr/local/nagios/etc

nano /usr/local/nagios/etc/nagios.cfg

dodajemo sledeće linije:

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
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

nećemo još stavljati tarabu (#) ispred localhost.cfg. Ostavićemo liniju

cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

pri instalaciji nagiosgrapha vec definisali perfdata.log i service_perfdata_file_template

service_perfdata_file=/usr/local/nagios/var/perfdata.log
service_perfdata_file_template=$LASTSERVICECHECK$||$HOSTNAME$||$SERVICEDESC$||$SERVICEOUTPUT$||$SERVICEPERFDATA$
  • resources.cfg – pomoćni konfiguracioni fajl, putanja je /usr/local/nagios/etc

nano /usr/local/nagios/etc/resource.cfg

$USER1$=/usr/local/nagios/libexec
$USER2$=/usr/local/nagios/libexec/eventhandlers
#$USER3$=someuser
#$USER4$=somepassword
$USER7$=-C communitystring1
$USER8$=-C communitystring2

Ovde umesto communitystring1 i communitystring2 upisati odgovarajuće SNMP community string-ove sa rutera i sa servera. (Biće objašnjeno gde se postavlja na WinServeru malo kasnije.)

  • menjamo i object fajlove na putanji /usr/local/nagios/etc/objects/

prvo podešavamo parametre u opštim object konfiguracionim fajlovima

timeperiods.cfg
contacts.cfg
templates.cfg

1) timeperiods.cfg

nano /usr/local/nagios/etc/objects/timeperiods.cfg

Definišemo vremenski period kada ćemo da vršimo nadgledanje hostova i servisa. Imamo predefinisan period 24×7 koji obuhvata neprestani monitoring. Možemo da definišemo i dodatni vremenski period kako bi monitorisali samo, na primer, tokom radnog vremena.

Primer 1 – već definisan vremenski period u fajlu

# This defines a timeperiod where all times are valid for checks,
# notifications, etc. The classic "24x7"

define timeperiod{
timeperiod_name 24x7
alias 24 Hours A Day, 7 Days A Week
sunday 00:00-24:00
monday 00:00-24:00
tuesday 00:00-24:00
wednesday 00:00-24:00
thursday 00:00-24:00
friday 00:00-24:00
saturday 00:00-24:00
}

Primer 2 – i ovo je već definisano ali menjamo radne sate ako je drugačije kod nas

# 'workhours' timeperiod definition

define timeperiod{
timeperiod_name workhours
alias Normal Work Hours
monday 07:30-17:00
tuesday 07:30-17:00
wednesday 07:30-17:00
thursday 07:30-17:00
friday 07:30-17:00
}

2) contacts.cfg

nano /usr/local/nagios/etc/objects/contacts.cfg

Postavljamo kontakte koji će biti obavešteni putem mejla o promenama (otkaz ili oporavak) servisa i hostova.

Primer 1:

define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Definisano u fajlu templates.cfg
alias Nagios Admin ; Full name of user

email nagiosadmin@admin.co.rs ; <<*CHANGE THIS TO YOUR EMAIL ADDRESS ******
}

Primer 2:

# 'administrator' contact definition
define contact{
contact_name administrator
alias Admin Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,c,u,r
host_notification_options d,u,r
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email admin@admin.co.rs ; promeniti u svoj mejl
}

Ako imamo više definisanih kontakata onda definišemo i kontakt grupe

define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin,administrator
}

3) templates.cfg
nano /usr/local/nagios/etc/objects/templates.cfg

Definišemo obrasce za proveru hostova i servisa koje posle koristimo u definicijama hostova i servisa kao i obrazac za kontakt. Generic-contact, generic-host, linux-server i windows-server su već definisani u fajlu templates.cfg

Primer 1 – generic contact:

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
host_notification_options d,u,r,f,s ; send notifications for all host states
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
}

Primer 2 – generic host:

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
}

Primer 3 – linux server:

define host{
name linux-server ; The name of this host template
use generic-host ; Koristimo vrednosti generic-host template
check_period 24x7 ; By default, Linux hosts are checked round the clock
check_interval 5 ; Actively check the host every 5 minutes
retry_interval 1 ; Schedule host check retries at 1 minute intervals
max_check_attempts 10 ; Check each Linux host 10 times (max)
check_command check-host-alive ; Default command to check Linux hosts
notification_period workhours ; Send notification workhours, potire se jer koristimo generic host vrednost za notification period
notification_interval 120 ; Resend notifications every 30 minutes
notification_options d,u,r ; Only send notifications for specific host states (downtime, uptime, recovery)
notifications_enabled 1
contact_groups admins ; Notifications get sent to the admins by default
icon_image linux40.png
icon_image_alt Linux
vrml_image linux40.png
statusmap_image linux40.gd2
2d_coords 100,250
3d_coords 100.0,50.0,75.0
register 0
}

Primer 4 – windows server:

define host{
name windows-server ; The name of this host template
use generic-host ; Inherit default values from the generic-host template
check_period 24x7 ; By default, Windows servers are monitored round the clock
check_interval 5 ; Actively check the server every 5 minutes
retry_interval 1 ; Schedule host check retries at 1 minute intervals
max_check_attempts 10 ; Check each server 10 times (max)
check_command check-host-alive ; Default command to check if servers are "alive"
notification_period 24x7 ; Send notification out at any time - day or night
notification_interval 30 ; Resend notifications every 30 minutes
notification_options d,u,r ; Only send notifications for specific host states
notifications_enabled 1
contact_groups admins ; Notifications get sent to the admins by default
hostgroups windows-servers
icon_image win40.png
icon_image_alt Windows
vrml_image win40.png
statusmap_image win40.gd2
2d_coords 100,250
3d_coords 100.0,50.0,75.0
register 0
}

Primer 5 – generic service

# 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'
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
}

Primer 6

# Template definicija dummy hosta, nepostojeceg hosta koji se uvode samo u cilju povecanja preglednosti

define host{
name dummy-generic-template
alias logicka predstava prostorija(ovo nije realan host)
notifications_enabled 0
event_handler_enabled 1 ; Host event handler is enabled
flap_detection_enabled 0 ; Flap detection is enabled
process_perf_data 0 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
check_command check-host-alive
check_period 24x7 ; By default, Linux hosts are checked round the clock
check_interval 60 ; Actively check the host every 60 minutes
retry_interval 1 ; Schedule host check retries at 1 minute intervals
max_check_attempts 10 ; Check each dummy host 10 times (max)
contact_groups admins ; Notifications get sent to the admins by default
hostgroups dummy-hosts
icon_image_alt Nepostojeci virtuelni host
icon_image netcloud.jpg
statusmap_image netcloud.jpg
vrml_image netcloud.jpg
register 0
}

Definiciju service-graph smo uneli pri konfiguraciji nagiosgrapha.
Videti uputstvo na: https://kompjuteras.com/nagiosgraph-grafici-u-nagiosu-instalacija/
Ostale template ne razmatramo jer nam, za sada, nisu potrebni. To su generic-printer, generic-switch.

Definisanje Windows Server-a kao host-a
Kreiramo fajl i dopunimo ga dole definisanim parametrima
nano /usr/local/nagios/etc/objects/hosts.cfg

##########################################################################
#
# HOST DEFINITIONS
#
################################################################################
#dodajemo win server WinServer1
define host{
use windows-server ; koristimo već definsan template windows-server
host_name WinServer1 ; ime našeg servera
alias server1.domen.co.rs ; domensko ime servera
parents Beograd-Centrala ; dummy-host, nepostojeći host koji služi za status mapu
address XXX.XXX.XXX.XXX ; Ip adresa našeg servera
}
define host{
use dummy-generic-template; već definisan template
host_name Beograd-Centrala; ime nepostojećeg hosta
alias Serveri u centrali
address xxx.xxx.xxx.xxx ; ip adresa localhosta za dummy-host
}

Definisanje hostgroup-a
Kreiramo fajl i dopunimo ga dole definisanim parametrima
Definicija linux grupe nam je već definisana u fajlu localhost.cfg pa je sad ne definišemo (samo su tarabe # ispred definicija)
nano /usr/local/nagios/etc/objects/hostsgroups.cfg

##############################################
#
#HOST GROUP DEFINITIONS
#
##############################################

# definicija 'linux-serveri'
#define hostgroup{
#hostgroup_name linux-servers
#alias Linux Serveri
#members localhost
#}

# definicija 'dummy-hosts'
define hostgroup{
hostgroup_name dummy-hosts
alias Dummy Hosts
members Beograd-Centrala
}

# definicija 'windows-serveri'
define hostgroup{
hostgroup_name windows-servers
alias Windows Serveri
members WinServer1
}

Sada već možemo da proverimo konfiguraciju nagios-a da vidimo da li smo dodali u hostove novi windows server.
Komanda je:

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

Treba da dobijemo sledeću sliku ako nema grešaka:

verification

Restart Nagios-a

/etc/init.d/nagios restart

Posle primene treba da dobijemo sledeći prikaz u našem web browseru:
config1
Status mapa treba da izgleda kao na sledećoj slici:
mapa1
Ovim smo završili i drugi deo naše konfiguracije.
Preostaje još treći deo u kome ćemo definisanti i proveriti komande i definisati i proveriti servise koje monitorišemo.

<<< NAZAD NA 1. DEO UPUTSTVA | PREĐITE NA 3. DEO UPUTSTVA >>>