Code:
[radar@test2 nagios]$ sudo nagios -v /etc/nagios/nagios.cfg
Nagios 2.2
Copyright (c) 1999-2006 Ethan Galstad (http://www.nagios.org)
Last Modified: 04-07-2006
License: GPL
Reading configuration data...
Running pre-flight check on configuration data...
Checking services...
Checked 5 services.
Checking hosts...
Warning: Host 'testbox' has no services associated with it!
Checked 2 hosts.
Checking host groups...
Checked 1 host groups.
Checking service groups...
Checked 0 service groups.
Checking contacts...
Checked 1 contacts.
Checking contact groups...
Checked 1 contact groups.
Checking service escalations...
Checked 0 service escalations.
Checking service dependencies...
Checked 0 service dependencies.
Checking host escalations...
Checked 0 host escalations.
Checking host dependencies...
Checked 0 host dependencies.
Checking commands...
Checked 22 commands.
Checking time periods...
Checked 1 time periods.
Checking extended host info definitions...
Checked 0 extended host info definitions.
Checking extended service info definitions...
Checked 0 extended service info definitions.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 1
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
If we had made a mistake, nagios would do its best to hint toward the problem. So all looks good for us to have a basic functioning setup. I will address the warning about no services set up for the testbox in a bit. We will now set up apache for authentication.
Configure HTTPD authentication and CGI accesses
Look at /etc/httpd/conf.d/nagios.conf to see how authentication files are set:
Code:
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /etc/nagios/htpasswd.users
Require valid-user
So we need to add nagiosadmin, who’s defined as a contact, in htpasswd.users:
Code:
sudo /usr/bin/htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
Make sure this file is readable by the apache user, if not already:
Code:
sudo chmod 644 /etc/nagios/htpasswd.users
Now edit cgi.cfg, uncommenting the lines containing allowed actions for the nagiosadmin user.
Configure Nagios and Apache Services for Start
Code:
[radar@test2 ~]$ sudo /sbin/chkconfig --level 35 httpd on
[radar@test2 ~]$ sudo /sbin/chkconfig --level 35 nagios on
Unfortunately, before we proceed, we have to disable SELinux. There is no policy (that I know of) created to allow nagios functionality with SELinux enabled apache. If anyone knows the solution, please see contact info at the end of this PET, and discuss. The easiest way to disable SELinux, is to go to applications, system settings, security level and select the selinux tab. Uncheck "Enabled (Modification Requires Reboot". Then click ok and reboot.
When the machine is up, we can point the browser to https://machine/nagios. We’ll see right away in the control panel that there’s an issue with the total processes check. By looking at /etc/nagios/services.cfg for check_local_procs we see the check definition:
Code:
check_local_procs!250!400
So lets look at our checkcommands.cfg file to see how that’s defined:
Code:
$USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
Right away, we see there’s a mismatch. The default service definition supplies only 2 arguments (delimited by the ‘!’), yet the command definition is looking for 3. Lets see what that -s is for:
Code:
cd /usr/lib/nagios/plugins
./check_procs -h | less
The help tells us that the -s is optional:
Optional Filters:
-s, –state=STATUSFLAGS
So we’ll remove that from the command definition for now:
Code:
define command{
command_name check_local_procs
command_line $USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
}
define command{
command_name check_local_procs
command_line $USER1$/check_procs -w $ARG1$ -c $ARG2$
}
We’ve removed the optional ps status flag.
Restart nagios:
Code:
[radar@test2 plugins]$ sudo /sbin/service nagios restart
Running configuration check...done
Stopping network monitor: nagios
Waiting for nagios to exit . done.
Starting network monitor: nagios
Now all is green! We have basic Nagios functionality and can start adding our customizations.
Adding Services To Nagios
Remember that when we verified nagios’s configuration, we got a warning about our testbox host not having any services associated with it. What this means is that, besides the obvious, nagios will not do any host alive checks against it. Nagios tries to spread out the checks in an efficient manner and will normally only check a host’s alive state when a service is failing. Once we establish a service for testbox. It will count the host as alive if the service associated with it succeeds. You can set up a service just to ping the box, but we’ll set up a custom command using one of the provided plugins.
Using a Supplied Plugin
I have started apache on our testbox, and will use the check_http plugin to define a command, and then from that, define a service to run against testbox. We can test the plugin directly so we know what to expect:
Code:
/usr/lib/nagios/plugins/check_http -h
Gives us the usage
Code:
[radar@test2 www]$ /usr/lib/nagios/plugins/check_http -H testbox -u /error/noindex.html
HTTP OK HTTP/1.1 200 OK - 4177 bytes in 0.007 seconds |time=0.006624s;;;0.000000 size=4177B;;;0
Gives us the default new install page. We can use that to set up a service to test whether apache is up on testbox. Create a new config file in /etc/nagios called custom_cmds.cfg and place the following in it:
Code:
define command{
command_name check_apache
command_line $USER1$/check_http -H $ARG1$ -S -u $ARG2$
}
Now open services.cfg in an editor and define a service to use this command definition:
Code:
define service{
use generic-service ; Name of service template to use
host_name testbox
service_description Check Apache
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_options w,u,c,r
notification_interval 960
notification_period 24x7
check_command check_apache!testbox!/error/noindex.html
We have to tell nagios that this new command file exists by adding the path to the file:
Code:
cfg_file=/etc/nagios/custom_cmds.cfg
I added that under the existing command definition. Now we can use this file to add custom command definitions. We need to verify that we did’nt make any mistakes:
Code:
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
Good. We can restart nagios:
Code:
sudo /sbin/service nagios restart
We see that the new service is there, but it’s pending. We can force it by rescheduling the next check and accepting the default time, which is immediate. We now can see that the service is working.
Pretty easy, but we may also want to write our own plugin and make a service check from that. Let’s emulate the functionality of the check_http plugin, for illustration purposes, using available tools and wrap it up in a bash script.
Create Custom Plugin
To use this example, curl needs to be installed. It is by default on RHEL.
Nagios expects plugins to return a code telling what the status of the check is. The following details what the codes are:
Code:
0 = OK
1 = WARNING
2 = CRITICAL
3 = UNKNOWN
The warning and critical exit codes are ideal for setting thresholds, such as CPU usage and load averages. But since our service is either on or off, we can use critical, ok, and unknown (for bad parameters passed).
This script takes arguments and passes them to the curl command. We’ll use it to get similar functionality as the check_http plugin.
Bookmarks