www.it-ebooks.info Nagios www.it-ebooks.info www.it-ebooks.info Wolfgang Barth Nagios System and Network Monitoring Munich SanFrancisco www.it-ebooks.info NAGIOS. Copyright(cid:1)c 2006OpenSourcePressGmbH Allrightsreserved.Nopartofthisworkmaybereproducedortransmittedinanyformorbyanymeans,electronicor mechanical,includingphotocopying,recording,orbyanyinformationstorageorretrievalsystem,withouttheprior writtenpermissionofthecopyrightownerandthepublisher. PrintedonrecycledpaperintheUnitedStatesofAmerica. 12345678910—09080706 NoStarchPressandtheNoStarchPresslogoareregisteredtrademarksofNoStarchPress,Inc. Otherproductand companynamesmentionedhereinmaybethetrademarksoftheirrespectiveowners. Ratherthanuseatrademark symbolwitheveryoccurrenceofatrademarkedname,weareusingthenamesonlyinaneditorialfashionandtothe benefitofthetrademarkowner,withnointentionofinfringementofthetrademark. Publisher:WilliamPollock CoverDesign:OctopodStudios U.S.editionpublishedbyNoStarchPress,Inc. 555DeHaroStreet,Suite250,SanFrancisco,CA94107 phone:415.863.9900;fax:415.863.9950;[email protected];http://www.nostarch.com Originaledition(cid:1)c 2005OpenSourcePressGmbH PublishedbyOpenSourcePressGmbH,Munich,Germany Publisher:Dr.MarkusWirtz OriginalISBN3-937514-09-0 Forinformationontranslations,pleasecontact OpenSourcePressGmbH,Amalienstr.45Rg,80799Mu¨nchen,Germany phone+49.89.28755562;fax+49.89.28755563;[email protected];http://www.opensourcepress.de Theinformationinthisbookisdistributedonan“AsIs”basis,withoutwarranty. Whileeveryprecautionhasbeen takeninthepreparationofthiswork,neithertheauthornorOpenSourcePressGmbHnorNoStarchPress,Inc.shall haveanyliabilitytoanypersonorentitywithrespecttoanylossordamagecausedorallegedtobecauseddirectly orindirectlybytheinformationcontainedinit. LibraryofCongressCataloging-in-PublicationData Barth, Wolfgang Nagios : system and network monitoring / Wolfgang Barth.-- 1st ed. p. cm. Includes index. ISBN 1-59327-070-4 1. Computer networks--Management--Automation. I. Title. TK5105.5.B374 2005 004.6--dc22 2005026745 www.it-ebooks.info Contents Introduction 15 From Source Code to a Running Installation 23 1 Installation 25 1.1 CompilingtheSourceCode . . . . . . . . . . . . . . . . . . . . . . 26 1.2 InstallingandTestingPlugins . . . . . . . . . . . . . . . . . . . . . 30 1.2.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . 30 1.2.2 Plugintest . . . . . . . . . . . . . . . . . . . . . . . . . . 32 1.3 ConfigurationoftheWebInterface . . . . . . . . . . . . . . . . . 33 1.3.1 SettingUpApache . . . . . . . . . . . . . . . . . . . . . . 33 1.3.2 UserAuthentication . . . . . . . . . . . . . . . . . . . . . 34 2 NagiosConfiguration 37 2.1 TheMainConfigurationFilenagios.cfg . . . . . . . . . . . . . . . 38 2.2 Objects—anOverview . . . . . . . . . . . . . . . . . . . . . . . . . 41 2.3 DefiningtheMachinestoBeMonitored,withhost . . . . . . . . . 44 2.4 GroupingComputersTogetherwithhostgroup . . . . . . . . . . . 46 2.5 DefiningServicestoBeMonitoredwithservice . . . . . . . . . . . 47 2.6 GroupingServicesTogetherwithservicegroup . . . . . . . . . . . 50 2.7 DefiningAddresseesforErrorMessages:contact . . . . . . . . . . 50 2.8 TheMessageRecipient:contactgroup . . . . . . . . . . . . . . . . 52 2.9 WhenNagiosNeedstoDoSomething:thecommandObject . . . 53 2.10 DefiningaTimePeriodwithtimeperiod . . . . . . . . . . . . . . . 54 5 www.it-ebooks.info Contents 2.11 Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 2.12 ConfigurationAidsforThoseTooLazytoType . . . . . . . . . . . . 56 2.12.1 Definingservicesforseveralcomputers. . . . . . . . . . . 56 2.12.2 Onehostgroupforallcomputers . . . . . . . . . . . . . . 57 2.12.3 Otherconfigurationaids . . . . . . . . . . . . . . . . . . . 57 2.13 CGIConfigurationincgi.cfg . . . . . . . . . . . . . . . . . . . . . 57 2.14 TheResourcesFileresource.cfg . . . . . . . . . . . . . . . . . . . . 59 3 Startup 61 3.1 CheckingtheConfiguration . . . . . . . . . . . . . . . . . . . . . . 61 3.2 GettingMonitoringStarted . . . . . . . . . . . . . . . . . . . . . . 63 3.2.1 Manualstart . . . . . . . . . . . . . . . . . . . . . . . . . 63 3.2.2 Automaticstart. . . . . . . . . . . . . . . . . . . . . . . . 64 3.2.3 Makingconfigurationchangescomeintoeffect . . . . . . 64 3.3 OverviewoftheWebInterface . . . . . . . . . . . . . . . . . . . . 64 In More Detail... 69 4 NagiosBasics 71 4.1 TakingintoAccounttheNetworkTopology . . . . . . . . . . . . . 72 4.2 ForcedHostChecksvs.PeriodicReachabilityTests . . . . . . . . . . 75 4.3 StatesofHostsandServices . . . . . . . . . . . . . . . . . . . . . 75 5 ServiceChecksandHowTheyArePerformed 79 5.1 TestingNetworkServicesDirectly . . . . . . . . . . . . . . . . . . . 81 5.2 RunningPluginsviaSecureShellontheRemoteComputer . . . . 82 5.3 TheNagiosRemotePluginExecutor . . . . . . . . . . . . . . . . . 82 5.4 MonitoringviaSNMP . . . . . . . . . . . . . . . . . . . . . . . . . 83 5.5 TheNagiosServiceCheckAcceptor . . . . . . . . . . . . . . . . . . 84 6 PluginsforNetworkServices 85 6.1 StandardOptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 6.2 ReachabilityTestwithPing . . . . . . . . . . . . . . . . . . . . . . 88 6.2.1 check_icmpasaservicecheck . . . . . . . . . . . . . . . 90 6 www.it-ebooks.info Contents 6.2.2 check_icmpasahostcheck . . . . . . . . . . . . . . . . . 91 6.3 MonitoringMailServers . . . . . . . . . . . . . . . . . . . . . . . . 92 6.3.1 MonitoringSMTPwithcheck_smtp. . . . . . . . . . . . . 92 6.3.2 POPandIMAP . . . . . . . . . . . . . . . . . . . . . . . . 95 6.4 MonitoringFTPandWebServers . . . . . . . . . . . . . . . . . . . 97 6.4.1 FTPservices . . . . . . . . . . . . . . . . . . . . . . . . . . 97 6.4.2 WebservercontrolviaHTTP . . . . . . . . . . . . . . . . . 98 6.4.3 MonitoringWebproxies . . . . . . . . . . . . . . . . . . . 101 6.5 DomainNameServerunderControl . . . . . . . . . . . . . . . . . 105 6.5.1 DNScheckwithnslookup . . . . . . . . . . . . . . . . . . 106 6.5.2 Monitoringthenameserverwithdig . . . . . . . . . . . . 107 6.6 QueryingtheSecureShellServer . . . . . . . . . . . . . . . . . . . 108 6.7 GenericNetworkPlugins . . . . . . . . . . . . . . . . . . . . . . . 110 6.7.1 TestingTCPports . . . . . . . . . . . . . . . . . . . . . . . 110 6.7.2 MonitoringUDPports . . . . . . . . . . . . . . . . . . . . 112 6.8 MonitoringDatabases . . . . . . . . . . . . . . . . . . . . . . . . . 114 6.8.1 PostgreSQL . . . . . . . . . . . . . . . . . . . . . . . . . . 115 6.8.2 MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 6.9 MonitoringLDAPDirectoryServices . . . . . . . . . . . . . . . . . 121 6.10 CheckingaDHCPServer. . . . . . . . . . . . . . . . . . . . . . . . 124 6.11 MonitoringUPSwiththeNetworkUPSTools . . . . . . . . . . . . 126 7 TestingLocalResources 133 7.1 FreeHardDriveCapacity . . . . . . . . . . . . . . . . . . . . . . . 134 7.2 UtilizationoftheSwapSpace. . . . . . . . . . . . . . . . . . . . . 136 7.3 TestingtheSystemLoad. . . . . . . . . . . . . . . . . . . . . . . . 137 7.4 MonitoringProcesses . . . . . . . . . . . . . . . . . . . . . . . . . 138 7.5 CheckingLogFiles . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 7.5.1 Thestandardplugincheck_log . . . . . . . . . . . . . . . 142 7.5.2 Themodernvariation:check_logs.pl . . . . . . . . . . . . 143 7.6 KeepingTabsontheNumberofLogged-inUsers . . . . . . . . . . 144 7.7 CheckingtheSystemTime . . . . . . . . . . . . . . . . . . . . . . 145 7.7.1 CheckingthesystemtimeviaNTP. . . . . . . . . . . . . . 145 7 www.it-ebooks.info Contents 7.7.2 Checkingsystemtimewiththetimeprotocol . . . . . . . 146 7.8 RegularlyCheckingtheStatusoftheMailQueue . . . . . . . . . . 147 7.9 KeepinganEyeontheModificationDateofaFile . . . . . . . . . 148 7.10 MonitoringUPSswithapcupsd . . . . . . . . . . . . . . . . . . . . 149 7.11 NagiosMonitorsItself . . . . . . . . . . . . . . . . . . . . . . . . . 150 7.11.1 Runningthepluginmanuallywithascript . . . . . . . . . 151 7.11.2 check_nagiosasatoolforCGIprograms. . . . . . . . . . 152 7.12 HardwareCheckswithLMSensors . . . . . . . . . . . . . . . . . . 152 7.13 TheDummyPluginforTests . . . . . . . . . . . . . . . . . . . . . 154 8 ManipulatingPluginOutput 155 8.1 NegatingPluginResults . . . . . . . . . . . . . . . . . . . . . . . . 155 8.2 InsertingHyperlinkswithurlize . . . . . . . . . . . . . . . . . . . 156 9 ExecutingPluginsviaSSH 157 9.1 Thecheck_by_sshPlugin . . . . . . . . . . . . . . . . . . . . . . . 158 9.2 ConfiguringSSH . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 9.2.1 GeneratingSSHkeypairsontheNagiosserver . . . . . . . 160 9.2.2 Settinguptheusernagiosonthetargethost . . . . . . . 161 9.2.3 CheckingtheSSHconnectionandcheck_by_ssh . . . . . 161 9.3 NagiosConfiguration . . . . . . . . . . . . . . . . . . . . . . . . . 162 10 TheNagiosRemotePluginExecutor(NRPE) 165 10.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 10.1.1 Distribution-specificpackages . . . . . . . . . . . . . . . . 166 10.1.2 Installationfromthesourcecode . . . . . . . . . . . . . . 167 10.2 StartingviatheinetDaemon . . . . . . . . . . . . . . . . . . . . . 168 10.2.1 xinetdconfiguration . . . . . . . . . . . . . . . . . . . . . 168 10.2.2 inetdconfiguration . . . . . . . . . . . . . . . . . . . . . 169 10.3 NRPEConfigurationontheComputertoBeMonitored . . . . . . . 170 10.3.1 Passingparametersontolocalplugins . . . . . . . . . . . 171 10.4 NagiosConfiguration . . . . . . . . . . . . . . . . . . . . . . . . . 172 10.4.1 NRPEwithoutpassingparameterson . . . . . . . . . . . . 172 10.4.2 PassingparametersoninNRPE . . . . . . . . . . . . . . . 173 8 www.it-ebooks.info Contents 10.4.3 Optimizingtheconfiguration . . . . . . . . . . . . . . . . 173 10.5 IndirectChecks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 11 CollectingInformationRelevantforMonitoringwithSNMP 177 11.1 IntroductiontoSNMP . . . . . . . . . . . . . . . . . . . . . . . . . 178 11.1.1 TheManagementInformationBase . . . . . . . . . . . . . 179 11.1.2 SNMPprotocolversions . . . . . . . . . . . . . . . . . . . 183 11.2 NET-SNMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 11.2.1 ToolsforSNMPrequests . . . . . . . . . . . . . . . . . . . 184 11.2.2 TheNET-SNMPdaemon . . . . . . . . . . . . . . . . . . . 187 11.3 Nagios’sOwnSNMPPlugins . . . . . . . . . . . . . . . . . . . . . 196 11.3.1 ThegenericSNMPplugincheck_snmp . . . . . . . . . . . 196 11.3.2 Checkingseveralinterfacessimultaneously. . . . . . . . . 201 11.3.3 Testingtheoperatingstatusofindividualinterfaces . . . . 203 11.4 OtherSNMP-basedPlugins . . . . . . . . . . . . . . . . . . . . . . 205 11.4.1 Monitoringharddrive spaceandprocesseswith nagios- snmp-plugins . . . . . . . . . . . . . . . . . . . . . . . . 205 11.4.2 Observing the load on network interfaces with check- iftraffic . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 11.4.3 Themanubulon.compluginsforspecialapplicationpur- poses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 12 TheNagiosNotificationSystem 215 12.1 WhoShouldbeInformedofWhat,When? . . . . . . . . . . . . . . 216 12.2 WhenDoesaMessageOccur? . . . . . . . . . . . . . . . . . . . . 217 12.3 TheMessageFilter . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 12.3.1 Switchingmessagesonandoffsystemwide . . . . . . . . 218 12.3.2 Enabling and suppressing computer and service-related messages . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 12.3.3 Person-relatedfilteroptions . . . . . . . . . . . . . . . . . 221 12.3.4 Caseexamples . . . . . . . . . . . . . . . . . . . . . . . . 222 12.4 ExternalNotificationPrograms . . . . . . . . . . . . . . . . . . . . 224 12.4.1 Notificationviae-mail . . . . . . . . . . . . . . . . . . . . 225 12.4.2 NotificationviaSMS . . . . . . . . . . . . . . . . . . . . . 227 9 www.it-ebooks.info