Nagios Core is easy to install and it gives a nice interface to monitor the infrastructure. But as its the free version, it gives limited options to configure it. Still the configuration files are very easy to understand and helps to ramp up the things in faster way if get hold of them. Here we bring another tutorial which uncovers some special features of Nagios.
The config files might look a little confusing to you, but we guarantee that they are not. Just go to /usr/local/nagios/etc/ folder and see what all is present there. All those file with .cfg extension are nagios configuration files.
Config files rules:
- ‘#’ Hash in starting of any lines means its a commented line.
- Variables names are case sensitive and must begin at the start of line without any white space before them.
- Paths provided in config files can be absolute or relative. Relative paths starts from the main config file location.
Type of Config Files:
- Main Config file (nagios.cfg): The main config files contain core setting key values which affect the way Nagios daemon works. This file has so many settings and they are well explained in the setting files itself. But still the most important one is Object Configuration Files settings. You can just add a line which points to Object definition config file. Ex:
Here we have added a new system for monitoring in nagios and its config file is remote.cfg which requires to be added into nagios.cfg by providing its location. For Other multiple options check this official document.
- Resource Config file (resource.cfg): Resource files have user defined macros and sensitive information like passwords. It has $USERn$ macros which can be used to store user information like passwords and other details. It shouldn’t be accessible to CGIs. One should set its permission as 600 or 660(In case you want to learn about file permissions check this).
- CGI Config file(cgi.cfg): Its the main config file for the operation for CGIs. You can develop your own CGIs and use this file to provide them vital details that how Nagios is configured. Its official document is here.
- Object Definition files(objects folder files): This is the important config on which we want to focus, as you are going to use this one a lot for the settings and configurations of Nagios instance. You can define hosts, services, hostgroups, contacts, contact groups, commands, etc.
- Hosts – These are the machines which you add to monitor in the Nagios. Its simple to add a machine into Nagios. Just copy localhost.cfg with new name and then edit it. You just have to update host_name to new name which you want to have and address to IP of remote machine.
use linux-server ; Name of host template to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
- Host Group – This just groups the host into one group and you can check all machine’s status under one head. Its simple you just have to define one group and add host names into. This can be added into same file where you have added the host.
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members localhost,remote1 ; Comma separated list of hosts that belong to this group
- Services – These are those services which are scheduled by the Nagios and these exploits the commands of Nagios to get the status of particular parameter which we are monitoring. Usually they are kept similar to monitored service like HTTP service, SSH service running on remote machine. The host host_name should be equal to the host_name of any machine.
The command should be existing in the command file and should accepts parameters passed after exclamation(!) mark.This can be added into same file where you have added the host.
use local-service ; Name of service template to use
- Service Groups – These are similar to Host groups, where you can group your services under one group which help in monitoring the similar services running on different machines.This can be added into same file where you have added the host.
alias Database Services
members ms1,SQL Server,ms1,SQL Server Agent,ms1,SQL DTC
- Contacts – These are used for defining the contacts which are to be contacted in case of some changes in service state or host status. There is a contacts.cfg which can be used for this.
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template
alias Nagios Admin ; Full name of user
email [email protected] ; Your email address
- Contacts groups – Similar thing to service group and host group, can be used to group a set of contacts and those groups can be notified. Contacts.cfg file can be used for this.
alias Nagios Administrators
- Commands – This is the file where we define the commands and define how plugins can be called. How to best use their parameters. What we usually do is to create our own commands with the exiting plugins and call them in the service defined for a host. Commands gives us a common gateway to call a plugin for a different services as it uses macros. And when Service calls a Command it provides the values for those macros. This file is in etc folder.
command_line /usr/local/nagios/libexec/check_pop -H $HOSTADDRESS$
- Time Periods – This config file helps in defining support for the Nagios monitored services. Like when whom to notify or what kind of alert has to be send to which set of contacts. For what time period notifications shouldn’t be send. When matters should be escalated. This is found at timeperiods.cfg file in objects folder. If you want to tweak this just read this.
So till now you would have understood many things about Nagios config files. But this can be tricky if you won’t understand how you can use Nagios Config’s to the full. So for that just have a look at this small document which give tricks about Nagios config files. Still you feel you need to know more then check this official doc.
We are at help as always, for that just drop your comment below 🙂 .