Monitoraggio passivo di sistemi con Nagios: Difference between revisions
No edit summary |
|||
| (9 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
{{Stub}} | {{Stub}} | ||
==Riferimenti== | Si vuole monitorare una macchina che non è direttamente raggiungibile da nagios, che è solo in grado di inviare risultati. | ||
== Monitoraggio tramite un'istanza locale di nagios == | |||
Il "Server_A" è la console centrale di nagios. | |||
Il "Server_B" è la macchina da monitorare, o quella che farà i veri controlli. | |||
=== Installazione pacchetti === | |||
Installare nagios sul Server_B: | |||
sudo apt-get install nagios-text nsca | |||
=== Configurazione di nagios === | |||
Dire al Server_B che deve comunicare i suoi risultati ad un server esterno, tramite un comando che definiamo noi: | |||
<pre> | |||
sudoedit /etc/nagios/nagios.cfg | |||
... | |||
obsess_over_services=1 | |||
... | |||
ocsp_command=submit_custom_check_result | |||
... | |||
</pre> | |||
===Creazione del file di invio dei check results === | |||
Creare il file submit_custom_check_result. | |||
Tale file è richiamato ogni volta che si ha un risultato di un check, ed il check viene inviato al Server_A (support.rvmgroup.it) | |||
<pre> | |||
cat >> /usr/lib/nagios/plugins/eventhandlers/submit_custom_check_result <<'EOFile'' | |||
#!/bin/sh | |||
# Arguments: | |||
# $1 = <host_name> | |||
# $2 = <svc_description> | |||
# $3 = <return_code> | |||
# $4 = <plugin_output> | |||
# | |||
# pipe the service check info into the send_nsca program, which | |||
# in turn transmits the data to the nsca daemon on the central monitoring server | |||
/usr/bin/printf "%s\t%s\t%s\t%s\n" "$1" "$2" "$3" "$4" | /usr/sbin/send_nsca -H support.rvmgroup.it -c /etc/send_nsca.cfg | |||
#echo $@ > /tmp/send_debug | |||
#<host_name>[tab]<svc_description>[tab]<return_code>[tab]<plugin_output>[newline] | |||
#lemserver PING OK 'Stato Servizio DOK' | |||
EOFile | |||
</pre> | |||
Renderlo eseguibile e sistemare le permission: | |||
sudo chmod +x /usr/lib/nagios/plugins/eventhandlers/submit_custom_check_result | |||
sudo chown root: /usr/lib/nagios/plugins/eventhandlers/submit_custom_check_result | |||
=== Definizione dei servizi Attivi === | |||
Definire l'host: | |||
<pre> | |||
define host{ | |||
use generic-host ; Name of host template to use | |||
host_name lemserver | |||
alias LEM Server | |||
address 127.0.0.1 | |||
max_check_attempts 20 | |||
notification_interval 60 | |||
notification_period 24x7 | |||
notification_options d,u,r | |||
} | |||
</pre> | |||
Sul Server_B definire normalmente i servizi da monitorare e verificarne il corretto funzionamento, avendo cura di aggiungere per i servizi che devono essere mandati al Server_A: | |||
passive_checks_enabled 1 | |||
obsess_over_service 1 | |||
<pre> | |||
define service{ | |||
use generic-service ; Name of service template to use | |||
host_name lemserver | |||
service_description PING | |||
is_volatile 0 | |||
check_period 24x7 | |||
max_check_attempts 3 | |||
normal_check_interval 5 | |||
retry_check_interval 1 | |||
contact_groups router-admins | |||
notification_interval 240 | |||
notification_period 24x7 | |||
notification_options c,r | |||
check_command check_ping!100.0,20%!500.0,60% | |||
active_checks_enabled 1 | |||
passive_checks_enabled 1 | |||
obsess_over_service 1 | |||
} | |||
</pre> | |||
Se un servizio non deve essere mandato al Server_A, metterci la direttiva: | |||
*non è vero, li manda sempre tutti | |||
passive_checks_enabled 0 | |||
obsess_over_service 0 | |||
=== Definizione dei servizi passivi === | |||
Sul Server_A definire l'host senza indirizzo: | |||
<pre> | |||
define host{ | |||
use generic-host | |||
host_name lemserver | |||
alias LEMServer | |||
parents fire.leman.it | |||
} | |||
</pre> | |||
Occorre solo ridefinire gli stessi servizi definiti sul Server_B, avendo cura di sostituire/aggiungere: | |||
<pre> | |||
define service{ | |||
use generic-service | |||
host_name lemserver | |||
service_description PING | |||
passive_checks_enabled 1 | |||
active_checks_enabled 1 | |||
check_freshness 1 | |||
check_command check_dummy!1 | |||
check_period none | |||
} | |||
</pre> | |||
In questo modo verificando la freshenss del risultato, se non lo è, si esegue il check attivo dummy, con parametro 1 che dà un errore critico. | |||
L'intervallo di freshness può essere impostato a poco più del check interval sul Server_B, usando sul Server_A l'opzione: | |||
*verificare | |||
freshness_theresold | |||
(se non si mette active_checks enabled, nella tactical overview, si ha il servizio come disabilitato.) | |||
Riavviare nagios, e verificare nagios.log. | |||
Per i servizi non replicati sul Server_A, si avrà un warning: | |||
[1165628960] Warning: Message queue contained results for service 'PING' on host 'lemgateway'. The service could not be found! | |||
Pazienza. | |||
===Riferimenti=== | |||
*[http://www.nagios-forum.co.uk/forum/viewtopic.php?t=604 Nagios-Forum.co.uk - Distributed nagios install, or passive host check HOW-TO] | |||
*[http://www.nagios.org/faqs/viewfaq.php?faq_id=271 Nagios: FAQs : Passive only checks with NSCA] | |||
*[http://hepuser.ucsd.edu/twiki/bin/view/UCSDTier2/NagiosPassiveCheckGuide NagiosPassiveCheckGuide < UCSDTier2] | *[http://hepuser.ucsd.edu/twiki/bin/view/UCSDTier2/NagiosPassiveCheckGuide NagiosPassiveCheckGuide < UCSDTier2] | ||
*[ | |||
== Monitoraggio tramite il solo client nsca == | |||
===Installazione Server=== | |||
* Installare il demone nsca sul server nagios, ed impostarlo allo startup: | |||
sudo apt-get install nsca | |||
<pre> | |||
Should the nsca daemon be enabled by default? │ | |||
│ │ | |||
│ <Yes> | |||
</pre> | |||
* Configurare i parametri: | |||
sudoedit /etc/nsca.cfg | |||
password=SecretPassword | |||
debug=1 | |||
* Avviare il daemon: | |||
sudo invoke-rc.d nsca restart | |||
* Verificare che sia in ascolto: | |||
sudo netstat -anp | grep 5667 | |||
tcp 0 0 0.0.0.0:5667 0.0.0.0:* LISTEN 31508/nsca | |||
* Sbloccare la porta di ingresso 5667 in iptables | |||
* Verificare che il server nagios abbia i parametri per i passive check abilitati: | |||
sudoedit /etc/nagios3/nagios.cfg | |||
check_external_commands=1 | |||
command_check_interval=-1 | |||
log_passive_checks=1 | |||
accept_passive_service_checks=1 | |||
accept_passive_host_checks=1 | |||
* Nel caso, restartare nagios | |||
====Test nsca daemon==== | |||
Sul server, impostare i paramentri del client per effettuare un test: | |||
sudoedit /etc/send_nsca.cfg | |||
password=SecretPassword | |||
* Creare un file con un messaggio di test, '''SEPARANDO GLI ARGOMENTI CON TAB''': | |||
vi /tmp/testfile | |||
localhost TestMessage 0 This is a test message. | |||
* Provare ad inviare il test: | |||
send_nsca localhost -c /etc/send_nsca.cfg < /tmp/testfile | |||
* Si deve ottenere la risposta: | |||
1 data packet(s) sent to host successfully. | |||
* E nel syslog: | |||
<pre> | |||
Feb 25 12:58:58 myhost nsca[6108]: Connection from 127.0.0.1 port 23171 | |||
Feb 25 12:58:58 myhost nsca[6108]: Handling the connection... | |||
Feb 25 12:58:58 myhost nsca[6108]: SERVICE CHECK -> Host Name: 'localhost', Service Description: 'TestMessage', Return Code: '0', Output: 'This is a test message.' | |||
Feb 25 12:58:58 myhost nsca[6108]: End of connection... | |||
</pre> | |||
====Servizio passivo di esempio==== | |||
* Definiamo prima i comandi a supporto: | |||
sudoedit /etc/nagios3/conf.d/commands.cfg | |||
<pre> | |||
define command{ | |||
command_name check_dummy | |||
command_line $USER1$/check_dummy $ARG1$ "$ARG2$" | |||
} | |||
</pre> | |||
* Definiamo ora il servizio passivo : | |||
sudoedit /etc/nagios3/conf.d/example.cfg | |||
<pre> | |||
define service{ | |||
use generic-service | |||
host_name myclient | |||
service_description MYSERVICE | |||
active_checks_enabled 0 | |||
passive_checks_enabled 1 | |||
check_command check_dummy!0!Message | |||
} | |||
</pre> | |||
* Restartare nagios e verificare che il servizio creato sia in stato | |||
PENDING | |||
* Testare ora in locale come fatto in precedenza, ma con un file con i dati del servizio: | |||
vi /tmp/testfile | |||
myclient MYSERVICE 0 This is a test message. | |||
send_nsca localhost -c /etc/send_nsca.cfg < /tmp/testfile | |||
* Ora il servizio dovrebbe essere in | |||
OK | |||
* Cambiamo lo 0 in 1, e inviamo il check | |||
myclient MYSERVICE 1 This is a test message. | |||
send_nsca localhost -c /etc/send_nsca.cfg < /tmp/testfile | |||
* Ora sarà in | |||
WARNING | |||
====Scadenza del check passivo==== | |||
* n questo modo, il servizio rimarrà nel suo stato, sino a che non verrà di nuovo inviato. Se però vogliamofare in modo che dopo un intervallo di tempo "scada", impostiamo la soglia di scadenza alla quale lo stato verrà forzato in critical | |||
sudoedit /etc/nagios3/conf.d/example.cfg | |||
<pre> | |||
define service{ | |||
use generic-service | |||
host_name myclient | |||
service_description MYSERVICE | |||
active_checks_enabled 0 | |||
passive_checks_enabled 1 | |||
check_freshness 1 | |||
freshness_threshold 60 # Time in second it will recheck and if not get result will alert as Critical | |||
check_command check_dummy!2!"NO REPORT FOR MYSERVICE" | |||
} | |||
</pre> | |||
* Attendere i 60 secondi, ed il servizio andrà in | |||
CRITICAL | |||
* Al restart di nagios, il servizio potrebbe andare in CRITICAL. Forzare il passive check da interfaccia web. | |||
===Configurazione del client=== | |||
* ATTENZIONE: la versione di nsca deve essere la stessa su client e server. Eventualmente usare i backports. Vedi [https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=670373 #670373 - nsca 2.7.2 / nsca-client 2.9.1: do not communicate - Debian Bug report logs] | |||
* Installiamo sul client nsca, per Squeeze: | |||
sudo apt-get install nsca | |||
<pre> | |||
Should the nsca daemon be enabled by default? │ | |||
│ │ | |||
│ <No> | |||
</pre> | |||
* Per Wheezy: | |||
sudo apt-get install nsca-client | |||
* Inseriamo la password: | |||
sudoedit /etc/send_nsca.cfg | |||
password=SecretPassword | |||
* Sblocchiamo in uscita la porta 5667 verso il server Nagios | |||
* Effettuiamo lo stesso test di prima, utilizzando questa volta l'indirizzo del server nagios: | |||
vi /tmp/testfile | |||
myclient MYSERVICE 0 This is a test message. | |||
send_nsca nagios.example.priv -c /etc/send_nsca.cfg < /tmp/testfile | |||
* Ora il servizio dovrebbe essere in | |||
OK | |||
===Creazione di un check passivo asincrono=== | |||
* Ipotizziamo di voler fare un check dello spazio libero un disco USB che viene montato per eseguire solo un backup. Questo check potrà essere eseguito alla fine del job di backup. Allo scopo si può utilizzare già anche il plugin di nagios | |||
* Creaimo il wrapper: | |||
sudoedit /usr/local/bin/check_disk_nsca | |||
<pre> | |||
#!/bin/bash | |||
CFG="/etc/send_nsca.cfg" | |||
HOSTNAME="myclient" | |||
SERVICE="MYSERVICE" | |||
NAGIOS="nagios.example.com" | |||
RESULT=$(/usr/lib/nagios/plugins/check_disk -w 10% -c 5% -p /mypath) | |||
CODE=$? | |||
CMD="${HOSTNAME};${SERVICE};${CODE};${RESULT}" | |||
/bin/echo $CMD | /usr/sbin/send_nsca -H $NAGIOS -d ';' -c $CFG | |||
echo $RESULT | |||
</pre> | |||
* Renderlo eseguibile | |||
sudo chmod +x /usr/local/bin/check_disk_nsca | |||
* Eseguirlo: | |||
/usr/local/bin/check_disk_nsca | |||
* Il servizio dovrebbe acquisire lo stato del check | |||
===Comando richiamabile da script=== | |||
* Se si vuole inviare un risultato da uno script (esempio un backup), si può utilizzare questo: | |||
sudoedit /usr/local/bin/nagios-passive-check | |||
<pre> | |||
#!/bin/bash | |||
CFG="/etc/send_nsca.cfg" | |||
HOSTNAME=$1 | |||
SERVICE=$2 | |||
CODE=$3 | |||
# 0 OK | |||
# 1 WARNING | |||
# 2 CRITICAL | |||
# 3 UNKNOWN | |||
RESULT=$4 | |||
NAGIOS=$5 | |||
# nagios-passive-check myserver.example.priv BACKUP 0 "Backup OK" localhost | |||
CMD="${HOSTNAME};${SERVICE};${CODE};${RESULT}" | |||
/bin/echo $CMD | /usr/sbin/send_nsca -H $NAGIOS -d ';' -c $CFG | |||
echo $RESULT | |||
</pre> | |||
sudo chmod +x /usr/local/bin/nagios-passive-check | |||
* Per inviare un OK, con messaggio "Backup OK" al server nagios che risponde su localhost, per il servizio BACKUP associato all'host myserver.example.priv: | |||
nagios-passive-check myserver.example.priv BACKUP 0 "Backup OK" nagios.example.priv | |||
===Riferimenti=== | |||
*[http://beginlinux.com/blog/2009/09/nagios-passive-checks-with-nsca/ Nagios Training: Passive Checks with NSCA] | |||
*[https://sachinsharm.wordpress.com/2013/08/11/setup-and-configure-nagios-client-nsca-on-centosrhel-6-3/ Setup and configure Nagios Client (NSCA) on CentOS/RHEL 6.3 | Sachin Sharma] | |||
*[https://wiki.icinga.org/display/howtos/NSCA+Example+Scripts NSCA Example Scripts - HowTos - Icinga Wiki] | |||
*[http://www.debmon.org/instructions Debmon / Instructions] | |||
*[http://nagios.sourceforge.net/docs/3_0/passivechecks.html Passive Checks] | |||
Latest revision as of 09:34, 19 June 2015
| Attenzione questo articolo è ancora incompleto. Sentiti libero di contribuire cliccando sul tasto edit. |
Si vuole monitorare una macchina che non è direttamente raggiungibile da nagios, che è solo in grado di inviare risultati.
Monitoraggio tramite un'istanza locale di nagios
Il "Server_A" è la console centrale di nagios.
Il "Server_B" è la macchina da monitorare, o quella che farà i veri controlli.
Installazione pacchetti
Installare nagios sul Server_B:
sudo apt-get install nagios-text nsca
Configurazione di nagios
Dire al Server_B che deve comunicare i suoi risultati ad un server esterno, tramite un comando che definiamo noi:
sudoedit /etc/nagios/nagios.cfg ... obsess_over_services=1 ... ocsp_command=submit_custom_check_result ...
Creazione del file di invio dei check results
Creare il file submit_custom_check_result.
Tale file è richiamato ogni volta che si ha un risultato di un check, ed il check viene inviato al Server_A (support.rvmgroup.it)
cat >> /usr/lib/nagios/plugins/eventhandlers/submit_custom_check_result <<'EOFile'' #!/bin/sh # Arguments: # $1 = <host_name> # $2 = <svc_description> # $3 = <return_code> # $4 = <plugin_output> # # pipe the service check info into the send_nsca program, which # in turn transmits the data to the nsca daemon on the central monitoring server /usr/bin/printf "%s\t%s\t%s\t%s\n" "$1" "$2" "$3" "$4" | /usr/sbin/send_nsca -H support.rvmgroup.it -c /etc/send_nsca.cfg #echo $@ > /tmp/send_debug #<host_name>[tab]<svc_description>[tab]<return_code>[tab]<plugin_output>[newline] #lemserver PING OK 'Stato Servizio DOK' EOFile
Renderlo eseguibile e sistemare le permission:
sudo chmod +x /usr/lib/nagios/plugins/eventhandlers/submit_custom_check_result sudo chown root: /usr/lib/nagios/plugins/eventhandlers/submit_custom_check_result
Definizione dei servizi Attivi
Definire l'host:
define host{
use generic-host ; Name of host template to use
host_name lemserver
alias LEM Server
address 127.0.0.1
max_check_attempts 20
notification_interval 60
notification_period 24x7
notification_options d,u,r
}
Sul Server_B definire normalmente i servizi da monitorare e verificarne il corretto funzionamento, avendo cura di aggiungere per i servizi che devono essere mandati al Server_A:
passive_checks_enabled 1 obsess_over_service 1
define service{
use generic-service ; Name of service template to use
host_name lemserver
service_description PING
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 5
retry_check_interval 1
contact_groups router-admins
notification_interval 240
notification_period 24x7
notification_options c,r
check_command check_ping!100.0,20%!500.0,60%
active_checks_enabled 1
passive_checks_enabled 1
obsess_over_service 1
}
Se un servizio non deve essere mandato al Server_A, metterci la direttiva:
- non è vero, li manda sempre tutti
passive_checks_enabled 0 obsess_over_service 0
Definizione dei servizi passivi
Sul Server_A definire l'host senza indirizzo:
define host{
use generic-host
host_name lemserver
alias LEMServer
parents fire.leman.it
}
Occorre solo ridefinire gli stessi servizi definiti sul Server_B, avendo cura di sostituire/aggiungere:
define service{
use generic-service
host_name lemserver
service_description PING
passive_checks_enabled 1
active_checks_enabled 1
check_freshness 1
check_command check_dummy!1
check_period none
}
In questo modo verificando la freshenss del risultato, se non lo è, si esegue il check attivo dummy, con parametro 1 che dà un errore critico. L'intervallo di freshness può essere impostato a poco più del check interval sul Server_B, usando sul Server_A l'opzione:
- verificare
freshness_theresold
(se non si mette active_checks enabled, nella tactical overview, si ha il servizio come disabilitato.)
Riavviare nagios, e verificare nagios.log.
Per i servizi non replicati sul Server_A, si avrà un warning:
[1165628960] Warning: Message queue contained results for service 'PING' on host 'lemgateway'. The service could not be found!
Pazienza.
Riferimenti
Monitoraggio tramite il solo client nsca
Installazione Server
- Installare il demone nsca sul server nagios, ed impostarlo allo startup:
sudo apt-get install nsca
Should the nsca daemon be enabled by default? │ │ │ │ <Yes>
- Configurare i parametri:
sudoedit /etc/nsca.cfg
password=SecretPassword debug=1
- Avviare il daemon:
sudo invoke-rc.d nsca restart
- Verificare che sia in ascolto:
sudo netstat -anp | grep 5667
tcp 0 0 0.0.0.0:5667 0.0.0.0:* LISTEN 31508/nsca
- Sbloccare la porta di ingresso 5667 in iptables
- Verificare che il server nagios abbia i parametri per i passive check abilitati:
sudoedit /etc/nagios3/nagios.cfg
check_external_commands=1 command_check_interval=-1 log_passive_checks=1 accept_passive_service_checks=1 accept_passive_host_checks=1
- Nel caso, restartare nagios
Test nsca daemon
Sul server, impostare i paramentri del client per effettuare un test:
sudoedit /etc/send_nsca.cfg
password=SecretPassword
- Creare un file con un messaggio di test, SEPARANDO GLI ARGOMENTI CON TAB:
vi /tmp/testfile
localhost TestMessage 0 This is a test message.
- Provare ad inviare il test:
send_nsca localhost -c /etc/send_nsca.cfg < /tmp/testfile
- Si deve ottenere la risposta:
1 data packet(s) sent to host successfully.
- E nel syslog:
Feb 25 12:58:58 myhost nsca[6108]: Connection from 127.0.0.1 port 23171 Feb 25 12:58:58 myhost nsca[6108]: Handling the connection... Feb 25 12:58:58 myhost nsca[6108]: SERVICE CHECK -> Host Name: 'localhost', Service Description: 'TestMessage', Return Code: '0', Output: 'This is a test message.' Feb 25 12:58:58 myhost nsca[6108]: End of connection...
Servizio passivo di esempio
- Definiamo prima i comandi a supporto:
sudoedit /etc/nagios3/conf.d/commands.cfg
define command{
command_name check_dummy
command_line $USER1$/check_dummy $ARG1$ "$ARG2$"
}
- Definiamo ora il servizio passivo :
sudoedit /etc/nagios3/conf.d/example.cfg
define service{
use generic-service
host_name myclient
service_description MYSERVICE
active_checks_enabled 0
passive_checks_enabled 1
check_command check_dummy!0!Message
}
- Restartare nagios e verificare che il servizio creato sia in stato
PENDING
- Testare ora in locale come fatto in precedenza, ma con un file con i dati del servizio:
vi /tmp/testfile
myclient MYSERVICE 0 This is a test message.
send_nsca localhost -c /etc/send_nsca.cfg < /tmp/testfile
- Ora il servizio dovrebbe essere in
OK
- Cambiamo lo 0 in 1, e inviamo il check
myclient MYSERVICE 1 This is a test message.
send_nsca localhost -c /etc/send_nsca.cfg < /tmp/testfile
- Ora sarà in
WARNING
Scadenza del check passivo
- n questo modo, il servizio rimarrà nel suo stato, sino a che non verrà di nuovo inviato. Se però vogliamofare in modo che dopo un intervallo di tempo "scada", impostiamo la soglia di scadenza alla quale lo stato verrà forzato in critical
sudoedit /etc/nagios3/conf.d/example.cfg
define service{
use generic-service
host_name myclient
service_description MYSERVICE
active_checks_enabled 0
passive_checks_enabled 1
check_freshness 1
freshness_threshold 60 # Time in second it will recheck and if not get result will alert as Critical
check_command check_dummy!2!"NO REPORT FOR MYSERVICE"
}
- Attendere i 60 secondi, ed il servizio andrà in
CRITICAL
- Al restart di nagios, il servizio potrebbe andare in CRITICAL. Forzare il passive check da interfaccia web.
Configurazione del client
- ATTENZIONE: la versione di nsca deve essere la stessa su client e server. Eventualmente usare i backports. Vedi #670373 - nsca 2.7.2 / nsca-client 2.9.1: do not communicate - Debian Bug report logs
- Installiamo sul client nsca, per Squeeze:
sudo apt-get install nsca
Should the nsca daemon be enabled by default? │ │ │ │ <No>
- Per Wheezy:
sudo apt-get install nsca-client
- Inseriamo la password:
sudoedit /etc/send_nsca.cfg
password=SecretPassword
- Sblocchiamo in uscita la porta 5667 verso il server Nagios
- Effettuiamo lo stesso test di prima, utilizzando questa volta l'indirizzo del server nagios:
vi /tmp/testfile
myclient MYSERVICE 0 This is a test message.
send_nsca nagios.example.priv -c /etc/send_nsca.cfg < /tmp/testfile
- Ora il servizio dovrebbe essere in
OK
Creazione di un check passivo asincrono
- Ipotizziamo di voler fare un check dello spazio libero un disco USB che viene montato per eseguire solo un backup. Questo check potrà essere eseguito alla fine del job di backup. Allo scopo si può utilizzare già anche il plugin di nagios
- Creaimo il wrapper:
sudoedit /usr/local/bin/check_disk_nsca
#!/bin/bash
CFG="/etc/send_nsca.cfg"
HOSTNAME="myclient"
SERVICE="MYSERVICE"
NAGIOS="nagios.example.com"
RESULT=$(/usr/lib/nagios/plugins/check_disk -w 10% -c 5% -p /mypath)
CODE=$?
CMD="${HOSTNAME};${SERVICE};${CODE};${RESULT}"
/bin/echo $CMD | /usr/sbin/send_nsca -H $NAGIOS -d ';' -c $CFG
echo $RESULT
- Renderlo eseguibile
sudo chmod +x /usr/local/bin/check_disk_nsca
- Eseguirlo:
/usr/local/bin/check_disk_nsca
- Il servizio dovrebbe acquisire lo stato del check
Comando richiamabile da script
- Se si vuole inviare un risultato da uno script (esempio un backup), si può utilizzare questo:
sudoedit /usr/local/bin/nagios-passive-check
#!/bin/bash
CFG="/etc/send_nsca.cfg"
HOSTNAME=$1
SERVICE=$2
CODE=$3
# 0 OK
# 1 WARNING
# 2 CRITICAL
# 3 UNKNOWN
RESULT=$4
NAGIOS=$5
# nagios-passive-check myserver.example.priv BACKUP 0 "Backup OK" localhost
CMD="${HOSTNAME};${SERVICE};${CODE};${RESULT}"
/bin/echo $CMD | /usr/sbin/send_nsca -H $NAGIOS -d ';' -c $CFG
echo $RESULT
sudo chmod +x /usr/local/bin/nagios-passive-check
- Per inviare un OK, con messaggio "Backup OK" al server nagios che risponde su localhost, per il servizio BACKUP associato all'host myserver.example.priv:
nagios-passive-check myserver.example.priv BACKUP 0 "Backup OK" nagios.example.priv