Nagios i dodavanje grafike za praćenje trendova

Najbolji “dodatak” za ovako nešto je programčić koji se zove Nagiosgraph (link).

Nagiosgraph instalacija
Šta su predhodno potrebne stvari (a koje obično nisu instalirane) :
perl-GD, RRD
Pre instalacije proveriti da li su svi preduslovi ispunjeni :
# ./install.pl –check-prereq
Pošto sam ja i Nagios instalirala iz source koda, isto MORA i sa Nagiosgraph-om da se uradi :
# tar xvfz nagiosgraph-1.4.4.tar.gz
# ./install.pl
checking required PERL modules
Carp…1.11
CGI…3.51
Data::Dumper…2.124
File::Basename…2.77
File::Find…1.14
MIME::Base64…3.08
POSIX…1.17
RRDs…1.3008
Time::HiRes…1.9721
checking optional PERL modules
GD…2.44
checking nagios installation
found nagios at /usr/local/nagios/bin/nagios
checking web server installation
found apache at /usr/sbin/httpd
Destination directory (prefix)? [/usr/local/nagiosgraph]
Destination directory (prefix)? [/usr/local/nagiosgraph]
Location of configuration files (etc-dir)? [/usr/local/nagiosgraph/etc]
Location of executables? [/usr/local/nagiosgraph/bin]
Location of CGI scripts? [/usr/local/nagiosgraph/cgi]
Location of documentation (doc-dir)? [/usr/local/nagiosgraph/doc]
Location of examples? [/usr/local/nagiosgraph/examples]
Location of CSS and JavaScript files? [/usr/local/nagiosgraph/share]
Location of utilities? [/usr/local/nagiosgraph/util]
Location of state files (var-dir)? [/usr/local/nagiosgraph/var]
Location of RRD files? [/usr/local/nagiosgraph/var/rrd]
Location of log files (log-dir)? [/usr/local/nagiosgraph/var]
Path of log file? [/usr/local/nagiosgraph/var/nagiosgraph.log]
Path of CGI log file? [/usr/local/nagiosgraph/var/nagiosgraph-cgi.log]
URL of CGI scripts? [/nagiosgraph/cgi-bin]
URL of CSS file? [/nagiosgraph/nagiosgraph.css]
URL of JavaScript file? [/nagiosgraph/nagiosgraph.js]
Path of Nagios performance data file? [/tmp/perfdata.log]
URL of Nagios CGI scripts? [/nagios/cgi-bin]
username or userid of Nagios user? [nagios]
username or userid of web server user? [apache]
Modify the Nagios configuration? [n]
Modify the Apache configuration? [n]

Izmene u konfiguracionim fajlovima
/usr/local/nagios/etc/nagios.cfg – samo dodati na kraj fajla
Napomena : Proveriti, jer neke stavke već postoje, i to sa drugim vrednostima!!!! Takođe hešovati stavke koje se odnose na host_perfdata_file i host_perfdata_command i service_perfdata_command (ne mešati sa service_perfdata_file_processing_command!!)
# process nagios performance data using nagiosgraph
process_performance_data=1
service_perfdata_file=/usr/local/nagios/var/perfdata.log
Ova lokacija MORA da se poklapa sa stavkom “perflog” u nagisgraph.cfg fajlu!!! Ako se one ne poklapaju u /usr/local/nagios&var/nagiosgraph.log se dobija greška o praznoj RRD bazi
service_perfdata_file_template=$LASTSERVICECHECK$||$HOSTNAME$||$SERVICEDESC$||$SERVICEOUTPUT$||$SERVICEPERFDATA$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=30
service_perfdata_file_processing_command=process-service-perfdata-for-nagiosgraph
Ovaj naziv komande mora se poklapati sa onim navedenim u commands.cfg fajlu

Napomena : ako se stavi pogrešna definicija u “service_perfdata_file_template” grafika neće biti a u nagiosgraph.log će se javljati čudna greška tipa :
“insert.pl warn processdata: no host found”
Opcija za “service_perfdata_file_template” koja može izazvati ovakvu grešku je :
SERVICEPERFDATA]\t$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$

nagiosgraph.cfg – izmena parametara :
perflog = /usr/local/nagios/var/perfdata.log
Ovo je lokacija gde Nagios stavlja svoje logove za grafiku, i u nagios.cfg fajlu to je stavka “service_perfdata_file, dakle uskladiti!
rrddir = /usr/local/nagiosgraph/var/rrd
Ako se ovo ne namesti ovamo, javljaće se stalno da je RRD baza prazna…..
rrdtool = /usr/bin/rrdtool
mapfile = /usr/local/nagiosgraph/etc/map
nagiosgraphcgiurl = /nagiosgraph/cgi-bin
javascript = /nagiosgraph/nagiosgraph.js
Obavezno provo proveriti na kojoj se putanji nalazi fajl nagiosgraph.js, i to uneti!
stylesheet = /nagiosgraph/nagiosgraph.css
logfile = /usr/local/nagios/var/nagiosgraph.log
cgilogfile = /usr/local/nagios/var/nagiosgraph-cgi.log

Napomena 1 : ako se stavke “javascript” i “stylesheet” ne nameste kako treba, na web strani će biti greške tipa :
JavaScript is disabled.
nagiosgraph.js is not installed or wrong version.

Napomena 2 : ako se stavka “nagiosgraphcgiurl” ne namesti kako treba, na web strani neće biti grafika, samo tekst.

Fajl koji definiše hostove (/usr/local/nagios/etc/hosts.cfg) treba za svaku stavku koju želimo da ide u Nagiosgraph da ima stavljeno : process_perf_data=1

/usr/local/nagios/etc/objects/commands.cfg i /usr/local/nagios/etc/commands.cfg – samo dodati na kraj fajla
define command {
command_name process-service-perfdata-for-nagiosgraph
Dakle komada se poklapa po nazivu sa navedenom u nagios.cfg fajlu
command_line /usr/local/nagiosgraph/bin/insert.pl
}

Napomena : u oba ova fajla postoje primeri komandi za Nagiosgraph, i njih treba hešovati!!!

U Nagios sidebar /usr/local/nagios/share/side.php dodati pod stavkom “Trends”
Napomena : Ovo može, a ne mora (to služi da bi se NagiosGraph-u moglo prići iz Nagios-a direktno).
nagiosgraph

httpd.conf – ovde se linija samo dodaje ispod već postojeće linije za Include
Include /usr/local/nagiosgraph/etc/nagiosgraph-apache.conf

U fajl /usr/local/nagios/etc/objects/templates.cfg dodati na kraj fajla :
define service {
name nagiosgraph
action_url /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$
register 0
}

Proveriti konfiguracione izmene
U nagios.cfg :
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Posle ovoga restartovati i Nagios i Apache servise.
Ručno pokrenuti insert :
# /usr/local/nagiosgraph/bin/insert.pl
Pratiti izlaz komande. Sada bi trebalo da se nešto nađe u rrd folderu.
Ručno pokrenuti :
# /usr/local/nagiosgraph/cgi/show.cgi
I pratiti izlaz komande.
Otići browser-om na lokaciju : http://IP-adresa-Nagios-servera/nagiosgraph/cgi-bin/show.cgi i proveriti izlaz.

Kada sve radi kako valja, slika se dobija pod : http://IP-adresa-Nagios-servera/nagiosgraph/cgi-bin/show.cgi

Napomena 1 : kako gledati sadržaj rrd fajlova u RRD bazi :
# rrdtool dump NRPE%20mailq%20provera___unsent.rrd
Ako se u izlazu dobije ovako nešto :
NaN NaN NaN NaN
NaN NaN NaN NaN
NaN NaN NaN NaN
To znači da za to vreme u bazi nema podataka (NaN).

Napomena 2 : ako se podaci u grafiku pojavljuju samo povremeno (iz potpuno neobjašnjivih razloga) proveriti da li je servis za koji je grafik, definisan kako treba pod /usr/local/nagios/etc/services.cfg :
define service {
host_name host1,host2
service_description NRPE mailq provera
check_command check_mailq_nrpe!/
check_period 24×7
max_check_attempts 5
check_interval 5
retry_interval 1
contact_groups IT-racunari
notification_interval 60
notification_period 24×7
notification_options w,u,c,r
}

Rotacija logova za NagiosGraph
U folder /etc/logrotate.d staviti fajl pod nazivom nagiosgraph :
/usr/local/nagiosgraph/var/log/nagiosgraph.log {
daily
missingok
rotate 30
compress
delaycompress
notifempty
create 644 nagios nagios
}

/usr/local/nagiosgraph/var/log/nagiosgraph-cgi.log {
daily
missingok
rotate 30
compress
delaycompress
notifempty
create 644 apache apache
}
Testiranje konfiguracije :
# logrotate -f /etc/logrotate.d/nagiosgraph
Ova komanda bi trebalo da izrotira postojece logove.