Monitoraggio di sistemi Windows con Nagios: Difference between revisions

From RVM Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(25 intermediate revisions by the same user not shown)
Line 1: Line 1:
Configurazione dell'agente sulla macchina Windows da monitorare:
==Configurazione dell'agente sulla macchina Windows da monitorare==


* Da prompt di DOS (su suppone Cygwin installato con wget e unzip)
* Installare il pacchetto 32 o 64 bit:
:*https://github.com/mickem/nscp/releases/download/0.4.4.19/NSCP-0.4.4.19-Win32.msi
:*https://github.com/mickem/nscp/releases/download/0.4.4.19/NSCP-0.4.4.19-x64.msi


* Scaricare il client Windows ed installarlo:
* Selezionare tipo installazione
  cd %TEMP%
  Complete
wget http://files.nsclient.org/x-0.3.x/NSClient%2B%2B-Win32-0.3.5.zip
mkdir %SYSTEMDRIVE%\NSClient++
"%PROGRAMFILES%\7-zip\7z" x -o%SYSTEMDRIVE%\NSClient++ NSClient++-Win32-0.3.5.zip
DEL NSClient++-Win32-0.3.5.zip


cd %SYSTEMDRIVE%\NSClient++
* Selezionare Configuration:
nsclient++ /install
:* ini://${exe-path}/nsclient.ini
:* Install sample configurations
* Open the '''services manager''' and make sure the '''NSClientpp service''' is allowed to '''interact with the desktop''' (see the ''''Log On'''' tab of the services manager). If it isn't already allowed to interact with the desktop, check the box to allow it to.
* Edit the '''NSC.INI''' file (located in the C:\NSClient++ directory) and make the following changes:
** Uncomment all the modules listed in the '''[modules]''' section, '''except for CheckWMI.dll and RemoteConfiguration.dll'''
** Optionally require a password for clients by changing the 'password' option in the [Settings] section.
**In the '''[Settings]''' section, uncomment the ''''allowed_hosts'''' option. Add the IP address of the Nagios server to this line, or leave it blank to allow all hosts to connect.
**In the '''[NSClient]''' section, make sure the ''''port'''' option  is uncommented and set to ''''12489'''' (the default port).


*Avviare l'agente in test
* Inserire l'ip con cui viene visto il server NRPE più vicino in
nsclient++.exe /test
:* Allowed hosts
Se non ci sono messaggi di errore, digitare
exit


*Avviare l'agente
* Inserire la password nrpe (non usata) in
nsclient++.exe /start
:* password


Si deve vedere l'icona nella Systray
*Selezionare:
:* Enable common check plugins
*: Enable nsclient server (check_nt)
:* Enable NRPE server (check_nrpe)
::* Insecure legacy mode
:* Enable NSCA client
:* Enable Web server
 
 
* Abilitare i defaults nel file config
 
cd %programfiles%
cd "nsclient++"
nscp settings --activate-module CheckExternalScripts --add-defaults
 
* Edit the
%PROGRAMFILES%\NSClient++\nsclient.ini
 
* Abilitare gli argomenti per NRPE
 
notepad  %PROGRAMFILES%\NSClient++\nsclient.ini
 
<pre>
[/settings/NRPE/server]
allow arguments = 1
allow nasty characters = 1
insecure = true
; questo sopra serve per compatibilità con check_nrpe di debian squeeze
</pre>
 
* Stoppare il servizio
net stop nscp
 
* Lanciare da cmd
nscp test --debug
 
* Riavviare il servizio Nsclient++
 
==Utilizzo di script esterni per i check ==
 
Esempio per check_ntp
 
* Copiare il file cmd da usare per il check ([http://exchange.nagios.org/directory/Plugins/Network-Protocols/NTP-and-Time/Check-Windows-Time-Offset-(check_windows_time-2Ebat)/details Check Windows Time Offset (check_windows_time.bat) - Nagios Exchange]) in:
%PROGRAMFILES%\NSClient++\scripts\check_windows_time.bat
 
* Aggiungere nella sezione di
  %PROGRAMFILES%\NSClient++\nsclient.ini
 
<pre>
[/settings/external scripts/scripts]
;...
check_ntp=scripts\\check_windows_time.bat pool.ntp.org 180 300
</pre>
 
* Riavviare il servizio, controllare il log
net stop nscp
net start nscp
 
* Richiamare il check via nrpe con il nome
check_ntp
 
===Riferimenti===
*[http://www.appdelivery.com/2012/09/monitoring-windows-time-with-nagios/ Monitoring Windows Time with Nagios | AppDelivery]
*[http://www.medin.name/blog/2013/01/28/scripting-on-the-windows-side/ Scripting on the Windows side | Michael Medin]
 
==Invio di check passivi ad un server NSCA==
 
* NSCLient++ può essere anche usato come client NSCA
* Ad esempio per inviare un risposta con questi parametri:
:* server nsca = nagios.example.com
:* porta server nsca = 5667
:* nome host in nagios = myhost
:* nome servizio in nagios = MYSERVICE
:* risultato del check = WARNING
:* password del server nsca = nscaPassword
:* cifratura server nagios = xor (vedi il file di configurazione del server nagios decryption_method)
 
* Utilizzare il comando:
 
C:\Program Files\NSClient++> nscp.exe nsca --command MYSERVICE --result WARNING --message "TEST" --host nagios.example.com --log debug --source-host myhost --password nscaPassword --port 5667 --encryption=xor
 
* Per l'help:
C:\Program Files\NSClient++> nscp.exe nsca --help
===Riferimenti===
*[http://serverfault.com/questions/627784/call-nsca-from-windows-batch-script-using-nsclient icinga - Call NSCA from windows batch script (using NSClient++) - Server Fault]
 
==Installazione Plugin Windows aggiuntivi ==
 
* Prelevare i plugin da [http://sourceforge.net/project/showfiles.php?group_id=222224&package_id=268500&release_id=682531 Nagios Plugin Collection]
 
* Scompattarli in
%SYSTEMDRIVE%\NSClient++\scripts
 
* Modificare NSC.INI, scommentando i valori di default per NRPE:
<pre>
[NRPE]
port=5666
command_timeout=60
allow_arguments=0
use_ssl=1
script_dir=scripts\
socket_timeout=30
</pre>
 
*Definire il comando da richiamare ('''Bug della 0.3.6: tutti i comandi presenti in scripts\ dovrebbero essere disponibili senza essere dichiarati qui''')
[NRPE Handlers]
command[check_virusscan.exe]=scripts\check_virusscan.exe
 
* Verificare che il plugin funzioni ('''Versione minima 8.5''')
cd \NSClient++\scripts
check_virusscan
 
*Definizione del comando sulla macchina Linux NRPE intermedia.
Installare il plugin NRPE:
sudo apt-get install nagios-nrpe-plugin
 
Il plugin va richiamato con il nome completo del file, esempio:
check_virusscan.exe
Esempio:
command[check-mansrv01-mcafee]=/usr/lib/nagios/plugins/check_nrpe -H mansrv01 -c check_virusscan.exe


== Configurazione dell'agente monitorante Linux==
== Configurazione dell'agente monitorante Linux==
Line 86: Line 195:
* Riavviare nrpe
* Riavviare nrpe
  sudo /etc/init.d/nagios-nrpe-server restart
  sudo /etc/init.d/nagios-nrpe-server restart
==Plugin Windowsupdate==
* Inizializzare il DB lanciando:
C:\NSClient++\scripts\inspect_onlineupdates.exe -d C:\NSClient++\scripts\onlineupdates.db
*Schedulare ogni 15 minuti sul server windows l'esecuzione del comando
C:\NSClient++\scripts\inspect_onlineupdates.exe -d C:\NSClient++\scripts\onlineupdates.db
* Configurare il comando nrpe
command[check-nrpe]=/usr/lib/nagios/plugins/check_nrpe -H $ARG1$ -c $ARG2$
* Richiamare da server nagios il check con:
<pre>
define service{
        use                            generic-service
        host_name                      ronchett-nt.ronchetti.priv
        service_description            WINUPDATE
        check_command                  check-nrpe-remote!check_onlineupdates.exe
        }
</pre>


==Configurazione del Server Nagios==
==Configurazione del Server Nagios==
Line 196: Line 326:
==Riferimenti==
==Riferimenti==
* [http://nagios.sourceforge.net/docs/3_0/monitoring-windows.html Monitoring Windows Machines]
* [http://nagios.sourceforge.net/docs/3_0/monitoring-windows.html Monitoring Windows Machines]
*[http://www.psychoticwolf.net/blog/2007/07/nagios_plugins_for_windows.php Wolf's Lair :: Nagios Plugins for Windows]
*[http://sapper4ever.net/stillwaiting/?p=67 Web development and stuff » Blog Archive » Compiling nagios plugins with cygwin: handling ./configure problem with ICMP]

Latest revision as of 17:43, 17 March 2016

Configurazione dell'agente sulla macchina Windows da monitorare

  • Installare il pacchetto 32 o 64 bit:
  • Selezionare tipo installazione
Complete
  • Selezionare Configuration:
  • ini://${exe-path}/nsclient.ini
  • Install sample configurations
  • Inserire l'ip con cui viene visto il server NRPE più vicino in
  • Allowed hosts
  • Inserire la password nrpe (non usata) in
  • password
  • Selezionare:
  • Enable common check plugins
  • Enable nsclient server (check_nt)
  • Enable NRPE server (check_nrpe)
  • Insecure legacy mode
  • Enable NSCA client
  • Enable Web server


  • Abilitare i defaults nel file config
cd %programfiles%
cd "nsclient++"
nscp settings --activate-module CheckExternalScripts --add-defaults
  • Edit the
%PROGRAMFILES%\NSClient++\nsclient.ini
  • Abilitare gli argomenti per NRPE
notepad  %PROGRAMFILES%\NSClient++\nsclient.ini
[/settings/NRPE/server]
allow arguments = 1
allow nasty characters = 1
insecure = true
; questo sopra serve per compatibilità con check_nrpe di debian squeeze
  • Stoppare il servizio
net stop nscp
  • Lanciare da cmd
nscp test --debug
  • Riavviare il servizio Nsclient++

Utilizzo di script esterni per i check

Esempio per check_ntp

%PROGRAMFILES%\NSClient++\scripts\check_windows_time.bat
  • Aggiungere nella sezione di
 %PROGRAMFILES%\NSClient++\nsclient.ini
[/settings/external scripts/scripts]
;...
check_ntp=scripts\\check_windows_time.bat pool.ntp.org 180 300 
  • Riavviare il servizio, controllare il log
net stop nscp
net start nscp
  • Richiamare il check via nrpe con il nome
check_ntp

Riferimenti

Invio di check passivi ad un server NSCA

  • NSCLient++ può essere anche usato come client NSCA
  • Ad esempio per inviare un risposta con questi parametri:
  • server nsca = nagios.example.com
  • porta server nsca = 5667
  • nome host in nagios = myhost
  • nome servizio in nagios = MYSERVICE
  • risultato del check = WARNING
  • password del server nsca = nscaPassword
  • cifratura server nagios = xor (vedi il file di configurazione del server nagios decryption_method)
  • Utilizzare il comando:
C:\Program Files\NSClient++> nscp.exe nsca --command MYSERVICE --result WARNING --message "TEST" --host nagios.example.com --log debug --source-host myhost --password nscaPassword --port 5667 --encryption=xor
  • Per l'help:
C:\Program Files\NSClient++> nscp.exe nsca --help

Riferimenti

Installazione Plugin Windows aggiuntivi

  • Scompattarli in
%SYSTEMDRIVE%\NSClient++\scripts
  • Modificare NSC.INI, scommentando i valori di default per NRPE:
[NRPE]
port=5666
command_timeout=60
allow_arguments=0
use_ssl=1
script_dir=scripts\
socket_timeout=30
  • Definire il comando da richiamare (Bug della 0.3.6: tutti i comandi presenti in scripts\ dovrebbero essere disponibili senza essere dichiarati qui)
[NRPE Handlers]
command[check_virusscan.exe]=scripts\check_virusscan.exe
  • Verificare che il plugin funzioni (Versione minima 8.5)
cd \NSClient++\scripts
check_virusscan
  • Definizione del comando sulla macchina Linux NRPE intermedia.

Installare il plugin NRPE:

sudo apt-get install nagios-nrpe-plugin

Il plugin va richiamato con il nome completo del file, esempio:

check_virusscan.exe

Esempio:

command[check-mansrv01-mcafee]=/usr/lib/nagios/plugins/check_nrpe -H mansrv01 -c check_virusscan.exe

Configurazione dell'agente monitorante Linux

SI suppone di voler monitorare il tutto da una macchina linux, la quale è interrgata poi via NRPE da un server centrale Nagios.

  • Verificare che si stata completata la configurazione dei NRPE
HOSTTOCHECK=192.168.1.100
  • Testare il ping
/usr/lib/nagios/plugins/check_fping $HOSTTOCHECK
FPING OK - $HOSTTOCHECK (loss=0%, rta=0.380000 ms)|loss=0%;;;0;100 rta=0.000380s;;;0.000000
  • Testare che NSClient++ sia accessibile da questa macchina Linux:
/usr/lib/nagios/plugins/check_nt -H $HOSTTOCHECK -v CLIENTVERSION -p 12489
NSClient++ 0.3.2.9 2008-05-17

Testare anche i comandi che si vorranno monitorare:

  • Per verificare che l'agente sia attivo:
/usr/lib/nagios/plugins/check_nt -H $HOSTTOCHECK -v CLIENTVERSION -p 12489 
NSClient++ 0.3.2.9 2008-05-17
  • Per l'Uptime
/usr/lib/nagios/plugins/check_nt -H $HOSTTOCHECK -v UPTIME -p 12489
System Uptime - 85 day(s) 16 hour(s) 34 minute(s)
  • Per il CPU Load
/usr/lib/nagios/plugins/check_nt -H $HOSTTOCHECK -p 12489 -v CPULOAD -l 5,80,90
CPU Load 14% (5 min average) |   '5 min avg Load'=14%;80;90;0;100
  • Per l'utilizzo di memoria
/usr/lib/nagios/plugins/check_nt -H $HOSTTOCHECK -p 12489 -v MEMUSE -w 80 -c 90
Memory usage: total:1255.98 Mb - used: 651.92 Mb (52%) - free: 604.06 Mb (48%) | 'Memory usage'=651.92Mb;1004.78;1130.38;0.00;1255.98
  • Per lo spazio sul disco C:
/usr/lib/nagios/plugins/check_nt -H $HOSTTOCHECK -p 12489 -v USEDDISKSPACE -l c -w 80 -c 90
c:\ - total: 4.88 Gb - used: 4.48 Gb (92%) - free 0.40 Gb (8%) | 'c:\ Used Space'=4.48Gb;3.90;4.39;0.00;4.88
  • Per lo spazio sul disco D:
/usr/lib/nagios/plugins/check_nt -H $HOSTTOCHECK -p 12489 -v USEDDISKSPACE -l d -w 80 -c 90
d:\ - total: 29.00 Gb - used: 22.10 Gb (76%) - free 6.90 Gb (24%) | 'd:\ Used Space'=22.10Gb;23.20;26.10;0.00;29.00
  • Se tutto è corretto, aggiungere i comandi in nrpe_local.cfg
sudoedit /etc/nagios/nrpe_local.cfg

command[check-manserver-ping]=/usr/lib/nagios/plugins/check_fping 192.168.1.100
command[check-manserver-nsclient]=/usr/lib/nagios/plugins/check_nt -H 192.168.1.100 -p 12489 -v CLIENTVERSION
command[check-manserver-uptime]=/usr/lib/nagios/plugins/check_nt -H 192.168.1.100 -p 12489 -v UPTIME p 12489
command[check-manserver-cpuload]=/usr/lib/nagios/plugins/check_nt -H 192.168.1.100 -p 12489 -v CPULOAD -l 5,80,90
command[check-manserver-memuse]=/usr/lib/nagios/plugins/check_nt -H 192.168.1.100 -p 12489 -v MEMUSE -w 80 -c 90
command[check-manserver-disk-c]=/usr/lib/nagios/plugins/check_nt -H 192.168.1.100 -p 12489 -v USEDDISKSPACE -l c -w 80 -c 90
command[check-manserver-disk-d]=/usr/lib/nagios/plugins/check_nt -H 192.168.1.100 -p 12489 -v USEDDISKSPACE -l d -w 80 -c 90
  • Riavviare nrpe
sudo /etc/init.d/nagios-nrpe-server restart

Plugin Windowsupdate

  • Inizializzare il DB lanciando:
C:\NSClient++\scripts\inspect_onlineupdates.exe -d C:\NSClient++\scripts\onlineupdates.db
  • Schedulare ogni 15 minuti sul server windows l'esecuzione del comando
C:\NSClient++\scripts\inspect_onlineupdates.exe -d C:\NSClient++\scripts\onlineupdates.db
  • Configurare il comando nrpe
command[check-nrpe]=/usr/lib/nagios/plugins/check_nrpe -H $ARG1$ -c $ARG2$
  • Richiamare da server nagios il check con:
define service{
        use                             generic-service
        host_name                       ronchett-nt.ronchetti.priv
        service_description             WINUPDATE
        check_command                   check-nrpe-remote!check_onlineupdates.exe
        }

Configurazione del Server Nagios

  • Testare se nrpe riesce ad colloquiare con l'host linux monitorante:
/usr/lib/nagios/plugins/check_nrpe -H man.rvmgroup.it -c check-manserver-ping
FPING OK - 192.168.1.100 (loss=0%, rta=0.380000 ms)|loss=0%;;;0;100 rta=0.000380s;;;0.000000
  • Definire l'host: dato che l'host Windows da monitorare non è raggiungibile, si deve definire l'host con un comando di monitoraggio fittizio che dia sempre host up, e dargli l'IP pubblico raggiungibile della macchina linux monitorante:


    • Definire il comando di host checking:

sudoedit /etc/nagios/misccommands.cfg

define command{
        command_name    check-host-dummy-up
        command_line    $USER1$/check_dummy 0 -H $HOSTADDRESS$
        }
    • Definire quindi l'host:
sudoedit /etc/nagios/hosts.cfg

define host{
        use                     generic-host
        host_name               manserver.mannesmann.priv
        alias                   Mannesmann Server
        address                 man.rvmgroup.it
        check_command           check-host-dummy-up
        }

Assegnare l'host ad un nuovo gruppo:

sudoedit /etc/nagios/hostgroups.cfg

define hostgroup{
        hostgroup_name  Mannesmann
        alias           Thyssenkrupp Mannex
        contact_groups  nagios-admins
        members         manserver.mannesmann.priv
        }

Definire i servizi da monitorare:

sudoedit /etc/nagios/services.cfg

define service{
        use                             generic-service
        host_name                       manserver.mannesmann.priv
        service_description             PING
        check_command                   check-nrpe!check-manserver-ping
        }
define service{
        use                             generic-service
        host_name                       manserver.mannesmann.priv
        service_description             NSCLIENT
        check_command                   check-nrpe!check-manserver-nsclient
        }

define service{
        use                             generic-service
        host_name                       manserver.mannesmann.priv
        service_description             UPTIME
        check_command                   check-nrpe!check-manserver-uptime
        }

define service{
        use                             generic-service
        host_name                       manserver.mannesmann.priv
        service_description             CPULOAD
        check_command                   check-nrpe!check-manserver-ping
        }
define service{
        use                             generic-service
        host_name                       manserver.mannesmann.priv
        service_description             MEMUSE
        check_command                   check-nrpe!check-manserver-memuse
        }

define service{
        use                             generic-service
        host_name                       manserver.mannesmann.priv
        service_description             DISK-C
        check_command                   check-nrpe!check-manserver-disk-c
        }

define service{
        use                             generic-service
        host_name                       manserver.mannesmann.priv
        service_description             DISK-D
        check_command                   check-nrpe!check-manserver-disk-d
        }


  • Testare la configurazione e riavviare:
sudo nagios -v /etc/nagios/nagios.cfg
sudo /etc/init.d/nagios restart

Riferimenti