Old:Nagios: monitorare server e servizi: differenze tra le versioni

m
→‎I Comandi: inizio...
m (→‎I Comandi: inizio...)
Riga 220: Riga 220:


=== I Comandi ===
=== I Comandi ===
I comandi rappresentano i mattoni su cui costruire i check dei sistemi. Essi possono essere specifici (ad esempio il check di funzionamento di un server [[IMAP]]) o generici (come il test dell'apertura di una porta [[TCP]]).
I comandi base sono definiti in <tt>/etc/nagios2/commands.cfg</tt>, mentre quelli installati tramite i plugin (i pacchetti ''nagios-plugins*'') sono contenuti in <tt>/etc/nagios-plugins/config/</tt>.
La sintassi per la definizione di un comando è la seguente:
<pre>define command{
  template      <templatename>
  name          <objectname>
  command_name  <commandname>
  command_line  <commandline>
}</pre>
Dove
; template <templatename> : permette di caricare un template (cioè un altra definizone di comando da cui attingere i valori opzionali)
; command_name  <commandname> : il nome (univoco) del comando. Per convenzione, non potendo inserire spazi all'interno del nome, sostituiremo quest'ultimi con dei '''-'''.
; command_line  <commandline> : il percorso completo del comando (script o eseguibile) da lanciare, con gli eventuali parametri specificati.
==== Utilizzare quelli esistenti ====
==== Utilizzare quelli esistenti ====
Carpire il corretto utilizzo dei comandi può essere, a volte, un po' complesso. Per capire come utilizzare quelli definiti, possiamo adottare la seguente strategia:
* identifichiamo il percorso completo del comando da eseguire. In questo esempio ci riferiremo ai comandi contenuti in <tt>/etc/nagios-plugins/config/http.cfg</tt>. Il path del comando che viene richiamato è <tt>/usr/lib/nagios/plugins/check_http</tt>.
* visualizziamo l'output dell'help del comando:
<pre>
# /usr/lib/nagios/plugins/check_http -h
check_http (nagios-plugins 1.4.5) 1.96
Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>
Copyright (c) 1999-2006 Nagios Plugin Development Team
        <nagiosplug-devel@lists.sourceforge.net>
This plugin tests the HTTP service on the specified host. It can test
normal (http) and secure (https) servers, follow redirects, search for
strings and regular expressions, check connection times, and report on
certificate expiration times.
Usage: check_http -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]
      [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]
      [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]
      [-s string] [-l] [-r <regex> | -R <case-insensitive regex>] [-P string]
      [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>] [-A string] [-k string]
NOTE: One or both of -H and -I must be specified
Options:
-h, --help
    Print detailed help screen
-V, --version
    Print version information
-H, --hostname=ADDRESS
    Host name argument for servers using host headers (virtual host)
    Append a port to include it in the header (eg: example.com:5000)
-I, --IP-address=ADDRESS
    IP address or name (use numeric address if possible to bypass DNS lookup).
-p, --port=INTEGER
Port number (default: 80)
-4, --use-ipv4
    Use IPv4 connection
-6, --use-ipv6
    Use IPv6 connection
-S, --ssl
  Connect via SSL
-C, --certificate=INTEGER
  Minimum number of days a certificate has to be valid.
  (when this option is used the url is not checked.)
-e, --expect=STRING
    String to expect in first (status) line of server response (default:
HTTP/1.
    If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)
-s, --string=STRING
    String to expect in the content
-u, --url=PATH
    URL to GET or POST (default: /)
URL to GET or POST (default: /)
,-P, --post=STRING    URL encoded http POST data
-N, --no-body
    Don't wait for document body: stop reading after headers.
    (Note that this still does an HTTP GET or POST, not a HEAD.)
-M, --max-age=SECONDS
    Warn if document is more than SECONDS old. the number can also be of
    the form "10m" for minutes, "10h" for hours, or "10d" for days.
-T, --content-type=STRING
    specify Content-Type header media type when POSTing
-l, --linespan
    Allow regex to span newlines (must precede -r or -R)
-r, --regex, --ereg=STRING
    Search page for regex STRING
-R, --eregi=STRING
    Search page for case-insensitive regex STRING
--invert-regex
    Return CRITICAL if found, OK if not
-a, --authorization=AUTH_PAIR
    Username:password on sites with basic authentication
-A, --useragent=STRING
    String to be sent in http header as "User Agent"
-k, --header=STRING
    Any other tags to be sent in http header. Use multiple times for additional headers
-L, --link=URL
    Wrap output in HTML link (obsoleted by urlize)
-f, --onredirect=<ok|warning|critical|follow>
    How to handle redirected pages
-m, --pagesize=INTEGER<:INTEGER>
    Minimum page size required (bytes) : Maximum page size required (bytes)
-w, --warning=DOUBLE
    Response time to result in warning status (seconds)
-c, --critical=DOUBLE
    Response time to result in critical status (seconds)
-t, --timeout=INTEGER
    Seconds before connection times out (default: 10)
-v, --verbose
    Show details for command-line debugging (Nagios may truncate output)
Notes: This plugin will attempt to open an HTTP connection with the host.
Successful connects return STATE_OK, refusals and timeouts return STATE_CRITICAL
other errors return STATE_UNKNOWN.  Successful connects, but incorrect reponse
messages from the host result in STATE_WARNING return values.  If you are
checking a virtual server that uses 'host headers' you must supply the FQDN
(fully qualified domain name) as the [host_name] argument.
This plugin can also check whether an SSL enabled web server is able to
serve content (optionally within a specified time) or whether the X509
certificate is still valid for the specified number of days.
Examples: CHECK CONTENT: check_http -w 5 -c 10 --ssl www.verisign.com
When the 'www.verisign.com' server returns its content within 5 seconds,
a STATE_OK will be returned. When the server returns its content but exceeds
the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,
a STATE_CRITICAL will be returned.
CHECK CERTIFICATE: check_http www.verisign.com -C 14
When the certificate of 'www.verisign.com' is valid for more than 14 days,
a STATE_OK is returned. When the certificate is still valid, but for less than
14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when
the certificate is expired.
Send email to nagios-users@lists.sourceforge.net if you have questions
regarding use of this software. To submit patches or suggest improvements,
send email to nagiosplug-devel@lists.sourceforge.net
</pre>
* confrontiamo la definizione del comando con l'help appena ottenuto:
<pre>
define command{
  command_name    check_http
  command_line    /usr/lib/nagios/plugins/check_http -H $HOSTADDRESS$ -I $HOSTADDRESS$
}</pre>
in questo caso, si occuperà di controllare che ci sia un [[webserver]] funzionante sulla porta 80 dell'host di cui stiamo eseguendo il check (<tt>$HOSTADDRESS$</tt> e <tt>$HOSTADDRESS$</tt> sono delle Macro. Per approfondimenti consultare il paragrafo [[#Le Macro]]).
---- da completare ----
==== Creare nuovi comandi ====
==== Creare nuovi comandi ====
Per semplicità (e convenzione di questa guida) i comandi ''personalizzati'' verranno salvati in <tt>/etc/nagios2/conf.d/commands.cfg</tt> in modo da non modificare il file di configurazione di default di Nagios (cosa che tornerà utile in caso di aggiornamenti e/o migrazioni).
=== I Gruppi di Host (hostgroup) ===
=== I Gruppi di Host (hostgroup) ===
Un '''hostgroup''' è semplicemente un sistema per raggruppare più host in base a delle caratteristiche comuni (che spaziano dall'appartenenza ad una stessa sottorete all'erogazione di uno stesso tipo di servizio, ...).
Un '''hostgroup''' è semplicemente un sistema per raggruppare più host in base a delle caratteristiche comuni (che spaziano dall'appartenenza ad una stessa sottorete all'erogazione di uno stesso tipo di servizio, ...).
1 487

contributi