Configurazione Nagios 2.10 parte 2
Dopo avere installato Nagios 2.10 con la guida della parte 1 procediamo ora a alcune personalizzazioni.<br />
Di Default con la parte 1 della guida vengono installati i plugin per PING,Current Load,Current Users,Root Partition e Total Processes .<br />
Vediamo ora come aggiungere qualche plugin, i plugin installati si trovano in /usr/lib64/nagios/plugins ( o per sistemi 32 bit /usr/lib/nagios/plugins )<br />
<br />
Supponiamo che vogliamo aggiungere gli utili plugins per http,ftp e smtp , andiamo cosi a editare il file localhost.cfg<br />
<br />
<div class="codeheader">Codice:</div>
<div class="code">
<pre style="margin-top: 0pt; display: inline;">vi /etc/nagios/localhost.cfg</pre>
</div>
<br />
nella sezione # Define a service to check the load on the local machine , aggiungiamo:<br />
<br />
define service{<br />
use local-service ; Name of service template to use<br />
host_name localhost<br />
service_description Http<br />
check_command check_http<br />
}<br />
<br />
define service{<br />
use local-service ; Name of service template to use<br />
host_name localhost<br />
service_description Ftp<br />
check_command check_ftp<br />
}<br />
<br />
define service{<br />
use local-service ; Name of service template to use<br />
host_name localhost<br />
service_description Smtp<br />
check_command check_smtp<br />
}<br />
<br />
Questi plugin hanno gia definito il check_command nel file /etc/nagios/command.cfg , quindi non e'neccessaria nessuna altra configurazione. <br />
Vediamo ora invece la configurazione di un plugin che non e' presente nel command.cfg , esempio vedremo check_ssh.<br />
<br />
Andiamo ad aprire il file commands.cfg<br />
<br />
Codice:
<div class="code">
<pre style="margin-top: 0pt; display: inline;">vi /etc/nagios/commands.cfg</pre>
</div>
<br />
visto che il comando check_ssh non e' definito dobbiamo aggiungerlo noi , trovate la sezione :<br />
<br />
################################################################################<br />
<br />
# NOTE: The following 'check_...' commands are used to monitor services on<br />
<br />
# both local and remote hosts.<br />
<br />
################################################################################<br />
<br />
e aggiungiamo:<br />
<br />
# 'check_ssh' command definition<br />
define command{<br />
command_name check_ssh<br />
command_line $USER1$/check_ssh -H $HOSTADDRESS$<br />
}<br />
<br />
salviamo il file , e come per i plugin precedenti andiamo a editare /etc/nagios/localhost.cfg<br />
<br />
troviamo la sezione :<br />
<br />
# Define a service to check the load on the local machine. <br />
<br />
e aggiungiamo:<br />
<br />
define service{<br />
use local-service ; Name of service template to use<br />
host_name localhost<br />
service_description Check ssh<br />
check_command check_ssh<br />
}<br />
<br />
Ogni volta che inseriamo un plugin e' buona norma prima testarlo in 2 modi , per prima cosa andiamo a vedere se esecuzione del plugin<br />
crea problemi , spostiamoci nella directory dei plugins per CentOS 5.1 64bit /usr/lib64/nagios/plugins ) e eseguiamo lo script :<br />
<br />
Codice:
<div class="code">
<pre style="margin-top: 0pt; display: inline;">./check_ssh -H 127.0.0.1</pre>
</div>
<br />
se avremo una risposta simile tutto e' ok :<br />
<br />
[root@centos plugins]# ./check_ssh -H 127.0.0.1<br />
SSH OK - OpenSSH_4.3 (protocol 2.0)<br />
<br />
secondo passo e' simulare nagios.cfg :<br />
<br />
Codice:
<div class="code">
<pre style="margin-top: 0pt; display: inline;">nagios -v nagios.cfg</pre>
</div>
<br />
questo e' un esempio di risposta positiva :<br />
<br />
[root@centos nagios]# nagios -v nagios.cfg<br />
Nagios 2.10<br />
Copyright (c) 1999-2007 Ethan Galstad (http://www.nagios.org)<br />
Last Modified: 10-21-2007<br />
License: GPL<br />
Reading configuration data...<br />
Running pre-flight check on configuration data...<br />
Checking services...<br />
Checked 10 services.<br />
Checking hosts...<br />
Checked 1 hosts.<br />
Checking host groups...<br />
Checked 1 host groups.<br />
Checking service groups...<br />
Checked 0 service groups.<br />
Checking contacts...<br />
Checked 1 contacts.<br />
Checking contact groups...<br />
Checked 1 contact groups.<br />
Checking service escalations...<br />
Checked 0 service escalations.<br />
Checking service dependencies...<br />
Checked 0 service dependencies.<br />
Checking host escalations...<br />
Checked 0 host escalations.<br />
Checking host dependencies...<br />
Checked 0 host dependencies.<br />
Checking commands...<br />
Checked 24 commands.<br />
Checking time periods...<br />
Checked 4 time periods.<br />
Checking extended host info definitions...<br />
Checked 0 extended host info definitions.<br />
Checking extended service info definitions...<br />
Checked 0 extended service info definitions.<br />
Checking for circular paths between hosts...<br />
Checking for circular host and service dependencies...<br />
Checking global event handlers...<br />
Checking obsessive compulsive processor commands...<br />
Checking misc settings...<br />
Total Warnings: 0<br />
Total Errors: 0<br />
Things look okay - No serious problems were detected during the pre-flight check<br />
<br />
<br />
Se questi 2 test sono positivi siamo pronti er rendere effettive le modifiche e riavviare nagios.<br />
<br />
<div class="codeheader">Codice:</div>
<div class="code">
<pre style="margin-top: 0pt; display: inline;">service nagios restartamp</pre>
</div>
<br />
Ora se puntiamo nagios ( http:IPDELSERVER/nagios/ ) vedremo i plugin inseriti ( servono circa 5 minuti per poterli visualizzare la prima volta ) .<br />
Un altro plugin di uso comune e' check_mysql anche lui non definito nel commands.cfg , quindi come per il plugin check_ssh andiamo a editare il commands.cfg<br />
<br />
<div class="codeheader">Codice:</div>
<div class="code">
<pre style="margin-top: 0pt; display: inline;">vi /etc/nagios/commands.cfg</pre>
</div>
<br />
e aggiungiamo<br />
<br />
# 'check_mysql' command definition<br />
define command{<br />
command_name check_mysql<br />
command_line $USER1$/check_mysql<br />
}<br />
<br />
proseguiamo poi editando il /etc/nagios/localhost.cfg aggiungendo :<br />
<br />
define service{<br />
use local-service ; Name of service template to use<br />
host_name localhost<br />
service_description Check mysql<br />
check_command check_mysql<br />
}<br />
<br />
Chiaramente questi sono solo opzioni base , Nagios e' abbastanza complesso per una maggiore personalizzazione vi rimando alla documentazione di nagios <br />
consultabile dal interfaccia web di nagios su http://IPDELSERVER/nagios/docs/toc.html , oppure scaricate la documentazione completa in <a href="http://nagios.sourceforge.net/docs/nagios-2.pdf">pdf</a> .<br />
Per accedere invece all help dei plugin digitiamo :<br />
<br />
./check_nomeplugin --help<br />
esempio:<br />
Codice:<br />
<div class="code"><br />
<pre style="margin-top: 0pt; display: inline;">[root@centos plugins]# ./check_http --help<br /><br />check_http v1861 (nagios-plugins 1.4.11)<br /><br />Copyright (c) 1999 Ethan Galstad <nagios@nagios.org><br /><br />Copyright (c) 1999-2006 Nagios Plugin Development Team<br /><br /> <nagiosplug-devel@lists.sourceforge.net><br /><br /><br /><br />This plugin tests the HTTP service on the specified host. It can test<br /><br />normal (http) and secure (https) servers, follow redirects, search for<br /><br />strings and regular expressions, check connection times, and report on<br /><br />certificate expiration times.<br /><br /><br /><br /><br /><br />Usage: check_http -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]<br /><br /> [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]<br /><br /> [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]<br /><br /> [-s string] [-l] [-r <regex> | -R <case-insensitive regex>] [-P string]<br /><br /> [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>] [-A string]<br /><br /> [-k string] [-S] [-C <age>] [-T <content-type>]<br /><br />NOTE: One or both of -H and -I must be specified<br /><br /><br /><br />Options:<br /><br /> -h, --help<br /><br /> Print detailed help screen<br /><br /> -V, --version<br /><br /> Print version information<br /><br /> -H, --hostname=ADDRESS<br /><br /> Host name argument for servers using host headers (virtual host)<br /><br /> Append a port to include it in the header (eg: example.com:5000)<br /><br /> -I, --IP-address=ADDRESS<br /><br /> IP address or name (use numeric address if possible to bypass DNS lookup).<br /><br /> -p, --port=INTEGER<br /><br /> Port number (default: 80)<br /><br /> -4, --use-ipv4<br /><br /> Use IPv4 connection<br /><br /> -6, --use-ipv6<br /><br /> Use IPv6 connection<br /><br /> -S, --ssl<br /><br /> Connect via SSL. Port defaults to 443<br /><br /> -C, --certificate=INTEGER<br /><br /> Minimum number of days a certificate has to be valid. Port defaults to 443<br /><br /> (when this option is used the url is not checked.)<br /><br /><br /><br /> -e, --expect=STRING<br /><br /> String to expect in first (status) line of server response (default: <br /><br />HTTP/1.)<br /><br /> If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)<br /><br /> -s, --string=STRING<br /><br /> String to expect in the content<br /><br /> -u, --url=PATH<br /><br /> URL to GET or POST (default: /)<br /><br /> -P, --post=STRING<br /><br /> URL encoded http POST data<br /><br /> -N, --no-body<br /><br /> Don't wait for document body: stop reading after headers.<br /><br /> (Note that this still does an HTTP GET or POST, not a HEAD.)<br /><br /> -M, --max-age=SECONDS<br /><br /> Warn if document is more than SECONDS old. the number can also be of<br /><br /> the form "10m" for minutes, "10h" for hours, or "10d" for days.<br /><br /> -T, --content-type=STRING<br /><br /> specify Content-Type header media type when POSTing<br /><br /><br /><br /> -l, --linespan<br /><br /> Allow regex to span newlines (must precede -r or -R)<br /><br /> -r, --regex, --ereg=STRING<br /><br /> Search page for regex STRING<br /><br /> -R, --eregi=STRING<br /><br /> Search page for case-insensitive regex STRING<br /><br /> --invert-regex<br /><br /> Return CRITICAL if found, OK if not<br /><br /><br /><br /> -a, --authorization=AUTH_PAIR<br /><br /> Username:password on sites with basic authentication<br /><br /> -A, --useragent=STRING<br /><br /> String to be sent in http header as "User Agent"<br /><br /> -k, --header=STRING<br /><br /> Any other tags to be sent in http header. Use multiple times for additional headers<br /><br /> -L, --link<br /><br /> Wrap output in HTML link (obsoleted by urlize)<br /><br /> -f, --onredirect=<ok|warning|critical|follow><br /><br /> How to handle redirected pages<br /><br /> -m, --pagesize=INTEGER<:INTEGER><br /><br /> Minimum page size required (bytes) : Maximum page size required (bytes)<br /><br /> -w, --warning=DOUBLE<br /><br /> Response time to result in warning status (seconds)<br /><br /> -c, --critical=DOUBLE<br /><br /> Response time to result in critical status (seconds)<br /><br /> -t, --timeout=INTEGER<br /><br /> Seconds before connection times out (default: 10)<br /><br /> -v, --verbose<br /><br /> Show details for command-line debugging (Nagios may truncate output)<br /><br />Notes: This plugin will attempt to open an HTTP connection with the host.<br /><br /> Successful connects return STATE_OK, refusals and timeouts return STATE_CRITICAL<br /><br /> other errors return STATE_UNKNOWN. Successful connects, but incorrect reponse<br /><br /> messages from the host result in STATE_WARNING return values. If you are<br /><br /> checking a virtual server that uses 'host headers' you must supply the FQDN<br /><br /> (fully qualified domain name) as the [host_name] argument.<br /><br /> This plugin can also check whether an SSL enabled web server is able to<br /><br /> serve content (optionally within a specified time) or whether the X509 <br /><br /> certificate is still valid for the specified number of days.<br /><br />Examples: CHECK CONTENT: check_http -w 5 -c 10 --ssl -H www.verisign.com<br /><br /><br /><br /> When the 'www.verisign.com' server returns its content within 5 seconds,<br /><br /> a STATE_OK will be returned. When the server returns its content but exceeds<br /><br /> the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,<br /><br /> a STATE_CRITICAL will be returned.<br /><br /><br /><br /> CHECK CERTIFICATE: check_http -H www.verisign.com -C 14<br /><br /><br /><br /> When the certificate of 'www.verisign.com' is valid for more than 14 days,<br /><br /> a STATE_OK is returned. When the certificate is still valid, but for less than<br /><br /> 14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when<br /><br /> the certificate is expired.<br /><br /><br /><br /><br /><br />Send email to nagios-users@lists.sourceforge.net if you have questions<br /><br />regarding use of this software. To submit patches or suggest improvements,<br /><br />send email to nagiosplug-devel@lists.sourceforge.net<br /><br /><br /><br />regarding use of this software. To submit patches or suggest improvements,<br /><br /><br /><br /><br /><br /><br /><br />send email to nagiosplug-devel@lists.sourceforge.net<\div><br /><br /><br /><br />Questa guida descrive solo alcune parti di nagios , la configurazione e le personalizzazioni per nagios sono tantissime , per queste<br /><br />vi lascio alla documentazione ufficiale e a gli help dei pugins .... e perche' no nel nostro forum :)) ....</pre>
<br />
</div>
<br />
Questa guida descrive solo alcune parti di nagios , la configurazione e le personalizzazioni per nagios sono tantissime , per queste vi lascio alla documentazione ufficiale e a gli help dei pugins .... e perche' no nel nostro forum :)) ....