13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 3 ■ MONITORING AND UPDATINGdefine host{use generic-hosthost_name localhostalias localhostaddress 127.0.0.1}# Define a service to check the disk space of the root partition# Warning if < 20% free, critical if < 10% free space on partition.define service{usegeneric-servicehost_namelocalhostservice_description Disk Spacecheck_command check_all_disks!20%!10%}The use keyword is used in the definition to refer to a template. Templates mean that you can setyour service or host defaults in a single place rather than having to retype them constantly. Config reuse,like any other code reuse, is always a good idea—less hassle and more maintainability! You can think ofthe Nagios configuration as effectively object-oriented. It treats both services and hosts as objects andthen sets up relationships between them. As with OO code, objects (hosts or services) can inherit thingsfrom a “parent” object, which is the generic-host or generic-service template in this case. (You can alsoset up other templates and call them anything you like, of course!)The generic-host template lives in the conf.d/generic-host_nagios2.cfg file. It sets a bunch ofdefaults, including notification enablement, various aspects of dealing with notifications and events,and so on. However, in the individual host definition, you can override any of these simply by specifyingthem.generic-service works as a per-service (rather than per-host) template in the same way. Take a lookat conf.d/generic-service_nagios2.cfg to see what this looks like and what defaults are set.check_command is a command in the file /etc/nagios-plugins/config/disk.cfg. The plug-indirectory at /etc/nagios-plugins/config/ contains all the commands for checking various services, andthere are an enormous number of plug-ins that you can add on top of the ones that a default packageinstall will give you (if installing from source, you may need to get more of these by hand). See recipe 3-7for more on plug-ins.3-4. Using Hostgroups and Services in NagiosFrom the setup in the previous recipes, Nagios can see the monitored machine (cepheus in recipe 3-2)and check that it’s up, but there aren’t any specific service or status checks defined for it. You could addthem individually to the host config file in the same way that checks are defined in the localhost configfile that I covered initially. However, it would be a lot of hassle to have to go through this for every host.As with the templates, you want to type things once only. This means using hostgroups, which are exactlywhat the name says—they’re groups of hosts, allowing you then to define a service per hostgroup ratherthan per host.Edit conf.d/hostgroups_nagios2.cfg to add the short name of the host to the relevant groups. Youcan, if you want to, create a new group. For example, here’s how to create a server hostgroup:68Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!