Sunteți pe pagina 1din 8

MonitorizareahosturilorutilizandNagios

Precizari
:

1.Sevorstergecomplet

pacheteledejainstalate,inclusivfisierelelordeconfigurare:
sudoaptgetpurge
nagios3icinganagiosnrpeservernagiosnrpeplugin
sau
sudosynaptic,cautatipachetul
nagios
lastatusinstalledsauresidualconfig,alegeti
markforcompleteremoval
.

2.Noileparolesetatevorfi
admin

3. Pe parcursul lucrarii, pentru troubleshooting se vatinecontsi de comenzispecifice


mentionatein(*).

Aplicatia de monitorizare va fi de tip client server: statia care va efectua


monitorizarea (PCx) va avea instalat SW client, iar statia monitorizata (PCy) va avea
instalatSWserver.

PlaformacuprindedouavariantedemonitorizareaunorstatiidistanteutilizandNagios:
1. MonitorizareautilizandNagios+NRPEaddon
2. MonitorizareutilizandNagios+SNMP.

A. Nagios+NRPEaddon

NRPE addon permite executia pluginurilor Nagios pe statii distante. Se monitorizeaza, astfel,
resurse de tip CPU load, memory usage, etc., agentul NRPE, instalat pe statia monitorizata,
permitandaccesareadeladistantaaacestorresurse.

1.NAGIOS+NRPEconfigurationonthemonitoringstation:
You willinstallnagios3on themonitoring PC, togetherwith remote NRPE execution
plugin:

sudoaptgetinstallnagios3nagiosnrpeplugin
YouwilldefineandconfigureanewhosttemplateforPCy:

Configfileedit:

Anewfileneedstobecreatedfor
PCy.cfg
,bycopyinginformationfromthetemplate
1

file
/etc/nagios3/conf.d/localhost_nagios2.cfg
,andandeditingthevalues:
host_name,aliasandaddresstomatchthemonitoredstation(youcanuse
ifconfig
and
hostname
onthemonitoredstationtofindthecorrectvalues):

definehost{

use
generichost

host_namePC142

alias
PC142

address
142.85.43.142

Nameofhosttemplatetouse

Configurationofmonitoredservices.AllthecommandsthatwillberunthroughNRPE
willbeprefixedwith
check_nrpe!
:

defineservice{

use
genericservice
Nameofservicetemplatetouse

host_namePC142

service_descriptionDiskSpace

check_commandcheck_nrpe!check_all_disks!20%!10%

Theconfigfilewillbesavedandnagios3servicewillberestarted:
sudo/etc/init.d/nagios3restart

2.ConfigurationofNAGIOS+NRPEonthemonitoredPC:

NRPEserverwillbeinstalledonPC1:
sudoaptgetinstallnagiosnrpeservernagiosplugins

NRPEserverwillbeconfiguredtoacceptexternalcommandsfromthemonitoring
station.

Edittheconfigfile/etc/nagios/nrpe.cfg
:

a) CommunicationwithNagioshostwillbeallowed:

#ALLOWEDHOSTADDRESSES
#ThisisanoptionalcommadelimitedlistofIPaddressorhostnames
#thatareallowedtotalktotheNRPEdaemon.
#
#Note:Thedaemononlydoesrudimentarycheckingoftheclient'sIP

#address.Iwouldhighlyrecommendaddingentriesinyour/etc/hosts.allow
#filetoallowonlythespecifiedhosttoconnecttotheport
#youarerunningthisdaemonon.
#
#NOTE:ThisoptionisignoredifNRPEisrunningundereitherinetdorxinetd

allowed_hosts=141.85.43.141

b) Configparameter
dont_blame_nrpe
willbesetwith1
#COMMANDARGUMENTPROCESSING
#ThisoptiondetermineswhetherornottheNRPEdaemonwillallowclients
#tospecifyargumentstocommandsthatareexecuted.Thisoptiononlyworks
#ifthedaemonwasconfiguredwiththeenablecommandargsconfigurescript
#option.
#
#***ENABLINGTHISOPTIONISASECURITYRISK!***
#ReadtheSECURITYfileforinformationonsomeofthesecurityimplications
#ofenablingthisvariable.
#
#Values:0=donotallowarguments,1=allowcommandarguments

dont_blame_nrpe=1

c) Adjustmentoflocalandremotecommanddefinitioncanbeneeded(,,hardcoded
commandargumentscouldbeprefered):

#COMMANDDEFINITIONS
#Commanddefinitionsthatthisdaemonwillrun.Definitions
#areinthefollowingformat:
#
#command[<command_name>]=<command_line>
#
#Whenthedaemonreceivesarequesttoreturntheresultsof<command_name>
#itwillexecutethecommandspecifiedbythe<command_line>argument.
#

#UnlikeNagios,thecommandlinecannotcontainmacrositmustbe
#typedexactlyasitshouldbeexecuted.
#
#Note:Anypluginsthatareusedinthecommandlinesmustreside
#onthemachinethatthisdaemonisrunningon!Theexamplesbelow
#assumethatyouhavepluginsinstalledina/usr/local/nagios/libexec
#directory.Alsonotethatyouwillhavetomodifythedefinitionsbelow
#tomatchtheargumentformatthepluginsexpect.Remember,theseare
#examplesonly!

#Thefollowingexamplesusehardcodedcommandarguments...

command[check_users]=/usr/lib/nagios/plugins/check_usersw5c10
command[check_load]=/usr/lib/nagios/plugins/check_loadw15,10,5c30,25,20
command[check_hda1]=/usr/lib/nagios/plugins/check_diskw20%c10%p/dev/hda1
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procsw5c10sZ
command[check_total_procs]=/usr/lib/nagios/plugins/check_procsw150c200

#Thefollowingexamplesallowusersuppliedargumentsandcan
#onlybeusediftheNRPEdaemonwascompiledwithsupportfor
#commandarguments*AND*thedont_blame_nrpedirectiveinthis

#configfileissetto'1'.Thisposesapotentialsecurityrisk,so
#makesureyoureadtheSECURITYfilebeforedoingthis.

#command[check_users]=/usr/lib/nagios/plugins/check_usersw$ARG1$c$ARG2$
#command[check_load]=/usr/lib/nagios/plugins/check_loadw$ARG1$c$ARG2$
#command[check_disk]=/usr/lib/nagios/plugins/check_diskw$ARG1$c$ARG2$p$ARG3$
#command[check_procs]=/usr/lib/nagios/plugins/check_procsw$ARG1$c$ARG2$s$ARG3$


ConfigfilewillbesavedandNagiosservicewillberestarted:

sudo/etc/init.d/nagiosnrpeserverrestart

3.Operatiademonitorizare
NRPEcommunicationcanbetestedonthemonitoringstationwithNRPE
demon:
student@PC141:/etc$/usr/lib/nagios/plugins/check_nrpeH141.85.43.142

Anoutputsimilarwith
NRPEv2.15
shouldbeobtained.
Opentheaddresshttp://localhost/nagios3inthewebbrowser
Ifnecesarry,thenagiospasswordcanberesetwith:
sudohtpasswd/etc/nagios3/htpasswd.usersnagiosadmin

PestatiademonitorizareseidentificaserviciilemonitorizatealestatieiPCy.
Careestatusulacestorservicii?
Analizati fiecare serviciumonitorizatsi,acoloundeavetimesajedeeroare,identificati
cauzele siremediati disfunctionalitatea(
Precizare
:Invedereaaccelerariioperatiuniide
troubleshooting pentru fiecare serviciu urmarit, reduceti intervalul de timp
check
interval
pecarestatia demonitorizareilutilizeazaatuncicandinterogheaza,prin
nrpe
,
situatia de pe statia PCx consultati, in acest sens, sectiunea sectiunea de definire a
serviciuluidepe
http://nagios.sourceforge.net/docs/3_0/objectdefinitions.html
).
Testati, in cazul serviciilor de pe PCy unde este posibil acest lucru, depasirea
thresholdurilorsi reactia lanivelul statieidemonitorizare(ex.:deschidereaunuinumar
4

maimaredesesiunideterminalvaconducecatreaparitiauneiavertizari
warning
).
Monitorizarea statiei distante PCy are loc utilizand argumentele (semnificand
thresholduri) comenzilordefinite pe PCy.Cetrebuiefacutpentruamonitorizaserviciile
statiei distante utilizand thresholduri impuse de statia de monitorizare ? Efectuati
modificarilenecesaresiverificati,dinnou,monitorizarea.
Semarestenumaruldestatiimonitorizatedecatreosingurastatiedemonitorizare.
Cetrebuiefacut?Efectuatimodificarilenecesareastfelincat,lafiecareranddemese
delucru,ostatiesamonitorizezecelelaltestatii.

(*)Pentrutroubleshooting,sepotutiliza:
tailf/var/log/syslog
tailf/var/log/nagios3/nagios.log(pestatiademonitorizare)
netstatat|grepnrpe
tcpdumpieth0

Nota,eroarea(bug)
DISKCRITICAL/home/rdp/.gvfsisnotaccessible:Permissiondenied
seremediazaconforminstructiunilordin:
https://help.ubuntu.com/community/Nagios3

Pentruagrabiverificareaactivatiinnagios.cfgcheck_externals_commandssicreati
fiseruldecomenzi.

Seseteazadebug=1infisieruldeconfigurarenrpe.cfg,pentruavizualizamesajeleaferente
NAGIOSului.

Lafinal,sedezinstaleazapacheteleinstalatelainceputullucrarii.Sesterg
fisiereledeconfigurareaferenteNagios.

B.
Nagios+SNMP
5

Topologieretea:

1)ConfigurareswitchHuawei:
activatimoduldeconfigurare:
>
systemview
verificatistareaSNMPcurenta:
>displaysnmpagentsysinfoversion

activatiagentulSNMP:
>snmpagentsysinfoversionall

creaticomunitateareadonly:
>snmpagentcommunityreadpublic

salvaticonfiguratia:
setatiIPpeinterfatademanagementaferentaVLAN1:
>interfaceVlanif1
>ipaddress
Atentie
!verificatiporturilemembreVLAN1peswitchsiconectatiechipamenteleinele:
>displayvlan1

2)ConfigurareroutereCisco:activatiSNMPconform
Laborator4ASI

3)Seinstaleazapachetele
nagios3nagiossnmpplugins

In/etc/nagios3/nagios.cfgseseteaza:check_external_commands=1

#EXTERNALCOMMANDOPTION
#ThisoptionallowsyoutospecifywhetherornotNagiosshouldcheck
#forexternalcommands(inthecommandfiledefinedbelow).Bydefault
#Nagioswill*not*checkforexternalcommands,justtobeonthe
#cautiousside.IfyouwanttobeabletousetheCGIcommandinterface
#youwillhavetoenablethis.
#Values:0=disablecommands,1=enablecommands
check_external_commands=1

Secreeazafisieruldeconfigurarecarepermitemonitorizareaunuiechipamentderetea.Pentru
6

aceasta,seutilizeazatemplateulswitch.cfgexistentindirectorul
/usr/share/doc/nagios3/examples/templateobject.

student@PC145:$cp/usr/share/doc/nagios3/examples/templateobject/switch.cfg
/etc/nagios3/conf.d

Redenumiticorespunzator(deex.:router_x.cfg)fisieruldeconfigurareaferentechipamentuluide
reteasiefectuatiurmatoarelemodificari:

genericswitch=>generichost
host_name=>hostnameaferentechipamentuluideretea(deex.:R6).
address=>adresaIPaechipamentuluimonitorizat

Indefinireaserviciilor,introduceticomadacheck_snmp.SevaintroducevaloareaOID
corespunzatoarededusacuajutorul(**):

defineservice{
use
genericservice;Inheritvaluesfromatemplate
host_name R5
service_descriptionImagename
check_command
check_snmp!public!
OID
}

Salvatifisieruldeconfigurare.Restartatiserviciul:
etc/init.d/nagios3restart

Cemesajedeeroareapar?Dece?

Lafinalulfisieruluideconfigurare,adaugatidefinireacomenziicheck_snmp:

definecommand{
command_name<>check_snmp
command_line<>/usr/lib/nagios/plugins/check_snmpH$HOSTADDRESS$C$ARG1$o
$ARG2$
}

Restartatiserviciul.Ceerorisuplimentareapar?

Pornitiaplicatiademonitorizaresianalizatidateleobtinute.

(**)Comenziutile:
snmpwalkv1cpublic192.168.1.2
snmpwalkv2Ccpublic192.168.1.21.3.6.1.4.1.9.2.1.73
7

/usr/lib/nagios/plugins/check_snmpH192.168.1.2o1.3.6.1.2.1.16.19.6.0

C.MRTG+SNMP

Seconfigureazamrtgpelinuxtinandcontdedatelementionatein
Laborator4ASI
.

aptgetinstallmrtg

Seefectueazaurmatoarelemodificariinfisieruldeconfigurare/etc/mrtg.cfg:

RunAsDaemon:yes
EnableIPv6:no
WorkDir:/var/www/mrtg
Options[_]:bits,growright

Target[141.85.43.12]:/141.84.43.12:public@141.85.43.12
MaxBytes[141.85.43.12]:1250000
Title[141.85.43.12]:Router141.85.43.12
PageTop[141.85.43.12]:<h1>Router141.85.43.12</h1>

Sepornesteserviciulprincomanda:
mrtg