Install / Setup Nagios on Fedora 7

These are supplement notes I had taken down a while back doing an install of nagios and n2rrd on a Fedora-7 box and recently came very handy when doing the install in a redhat (RHEL-3) box as well:

Nagios Install:

# yum install nagios nagios-plugins nagios-plugins-http nagios-plugins-icmp nagios-plugins-ping

On RHEL3, I used (dags rpms) rpmforge. Here is my yum.conf for rpmforge:

[rpmforge]
name = Red Hat Enterprise $releasever - RPMforge.net - dag
baseurl = http://apt.sw.be/redhat/el3/en/$basearch/dag

Notes: I settled for icmp instead of ping, as it is a lot faster. However, icmp required setting setuid for "/usr/lib/nagios/plugins/check_icmp" for it to work. Also, had to rebuild nagios-plugins from source as root in order for the plugin to be installed.

  1. Edit "etc/httpd/conf.d/nagios" and add the IPs and users to allow access.

    Here is what it looks like:

    ScriptAlias /nagios/cgi-bin "/usr/lib/nagios/cgi";
    <Directory "/usr/lib/nagios/cgi";>
       SSLRequireSSL
       Options ExecCGI
       AllowOverride None
       Order deny,allow
       Deny from all
       Allow from xxx.xxx.xxx.xxx
       AuthUserFile /var/www/.htpasswd
       AuthGroupFile /var/www/.htgroup
       AuthName "Protected"
       AuthType Basic
       <Limit GET>
         require group administrator
       </Limit>
       satisfy all
    </Directory>

    Alias /nagios "/usr/share/nagios"<br /><Directory "/usr/share/nagios"&gt;
       SSLRequireSSL
       Options None
       AllowOverride None
       Order deny,allow
       Deny from all
       Allow from xxx.xxx.xxx.xxx
       AuthUserFile /var/www/.htpasswd
       AuthGroupFile /var/www/.htgroup
       AuthName "Protected"
       AuthType Basic
       <Limit GET>
         require group  administrator
       </Limit>
       satisfy all
    </Directory>
  2. Reload httpd.
  3. Edit "/etc/nagios/nagios.cfg":

    Below are the main setting to look for:

    # cfg_file=/etc/nagios/localhost.cfg
    cfg_file=/etc/nagios/contactgroups.cfg
    cfg_file=/etc/nagios/contacts.cfg
    #cfg_file=/etc/nagios/dependencies.cfg
    #cfg_file=/etc/nagios/escalations.cfg
    cfg_file=/etc/nagios/hostgroups.cfg
    cfg_file=/etc/nagios/hosts.cfg
    cfg_file=/etc/nagios/services.cfg
    cfg_file=/etc/nagios/timeperiods.cfg
    cfg_file=/etc/nagios/serviceextinfo.cfg
    process_performance_data=1r />host_perfdata_command=process-host-perfdata-n2rrd
    service_perfdata_command=process-service-perfdata-n2rrd />enable_flap_detection=1

    Here is what the config file looks like:

    # egrep -v "#|^$" /etc/nagios/nagios.cfg
    log_file=/var/log/nagios/nagios.log
    cfg_file=/etc/nagios/commands.cfg
    cfg_file=/etc/nagios/contactgroups.cfg
    cfg_file=/etc/nagios/contacts.cfg
    cfg_file=/etc/nagios/hostgroups.cfg
    cfg_file=/etc/nagios/hosts.cfg
    cfg_file=/etc/nagios/services.cfg
    cfg_file=/etc/nagios/timeperiods.cfg
    cfg_file=/etc/nagios/serviceextinfo.cfg
    object_cache_file=/var/log/nagios/objects.cache
    resource_file=/etc/nagios/resource.cfg
    status_file=/var/log/nagios/status.dat
    nagios_user=nagios
    nagios_group=nagios
    check_external_commands=0 />command_check_interval=-1 />command_file=/var/log/nagios/rw/nagios.cmd
    external_command_buffer_slots=4096
    comment_file=/var/log/nagios/comments.dat
    downtime_file=/var/log/nagios/downtime.dat
    lock_file=/var/run/nagios.pid
    temp_file=/var/log/nagios/nagios.tmp
    event_broker_options=-1
    log_rotation_method=d
    log_archive_path=/var/log/nagios/archives
    use_syslog=1
    log_notifications=1
    log_service_retries=1
    log_host_retries=1
    log_event_handlers=1
    log_initial_states=0
    log_external_commands=1
    log_passive_checks=1
    service_inter_check_delay_method=s
    max_service_check_spread=30<br />service_interleave_factor=s<br />host_inter_check_delay_method=s
    max_host_check_spread=30
    max_concurrent_checks=0
    service_reaper_frequency=10<br />check_result_buffer_slots=4096
    auto_reschedule_checks=0
    auto_rescheduling_interval=30
    auto_rescheduling_window=180
    sleep_time=0.25
    service_check_timeout=60
    host_check_timeout=30
    event_handler_timeout=30
    notification_timeout=30
    ocsp_timeout=5
    perfdata_timeout=5
    retain_state_information=1r />state_retention_file=/var/log/nagios/retention.dat
    retention_update_interval=60
    use_retained_program_state=1
    use_retained_scheduling_info=0
    interval_length=60
    use_aggressive_host_checking=0
    execute_service_checks=1
    accept_passive_service_checks=1
    execute_host_checks=1
    accept_passive_host_checks=1
    enable_notifications=1
    enable_event_handlers=1
    process_performance_data=1r />host_perfdata_command=process-host-perfdata
    service_perfdata_command=process-service-perfdata
    obsess_over_services=0
    check_for_orphaned_services=1
    check_service_freshness=1 />service_freshness_check_interval=60
    check_host_freshness=0
    host_freshness_check_interval=60
    aggregate_status_updates=1r />status_update_interval=15 />enable_flap_detection=1
    low_service_flap_threshold=5.0
    high_service_flap_threshold=20.0
    low_host_flap_threshold=5.0<br />high_host_flap_threshold=20.0
    date_format=us
    p1_file=/usr/bin/p1.pl
    illegal_object_name_chars=`~!$%^&*|'"<>;?,()=
    illegal_macro_output_chars=`~$&|'"<>r />use_regexp_matching=0
    use_true_regexp_matching=0r />admin_email=nagios
    admin_pager=pagenagios
    daemon_dumps_core=0

  4. Since I've separated out the config files, I copied the samples from "/etc/nagios/localhost.cfg" and setup the configurations from the example file. Make sure to use "cp -a" so the user/group permissions is maintained.

    Basically, hosts.cfg describes the hosts you want to monitor, services.cfg describes the services you want to monitor on each host, commands.cfg is the check commands used by services.cfg to check the services. If you want to check a service you probably have to add a command to do so. contacts.cfg is the people who will be contacted in case of a problem, contactgroups.cfg is the groups of people, hostgroups.cfg is the groups of hosts. nagios.cfg is the master config file.

    To add a new machine you will need to edit hosts.cfg (add the machine), hostgroups.cfg (put it in a hostgroup), services.cfg (add the services to be checked on the machine).

    To add a new administrator, you will need to edit contacts.cfg (add the new person) and contactgroups.cfg (put them in a contact group or create one).

  5. Create the corresponding users with htpasswd command, also setup group.
    # htpasswd -c /var/www/.htpasswd <nagiosadmin>
  6. Add user to the admin group.
    # cat <<EOF > /var/www/.htgroup
    > administrator: <nagiosadmin>
    > EOF
  7. Edit "/etc/nagios/cgi.cfg" to include the user to have additional authorization.
    # egrep -v "#|^$" /etc/nagios/cgi.cfg
    main_config_file=/etc/nagios/nagios.cfg
    physical_html_path=/usr/share/nagios
    url_html_path=/nagios
    show_context_help=0
    use_authentication=1
    authorized_for_system_information=<nagiosadmin>
    authorized_for_configuration_information=<nagiosadmin&gt;
    authorized_for_system_commands=<nagiosadmin>
    authorized_for_all_services=<nagiosadmin>
    authorized_for_all_hosts=<;nagiosadmin>
    authorized_for_all_service_commands=<nagiosadmin> />authorized_for_all_host_commands=<nagiosadmin>
    default_statusmap_layout=5r />default_statuswrl_layout=4r />ping_syntax=/bin/ping -n -U -c 5 $HOSTADDRESS$
    refresh_rate=90

n2rrd install:

  1. See install notes at: n2rrd.diglinks.com

    Run below commands to install, create required directories and setup the right directory permissions:

    # yum install rrdtool rrdtool-perl
    # wget http://n2rrd.diglinks.com/download/n2rrd-1.3.1.tar.gz
    # tar -xvzf n2rrd-1.3.1.tar.gz
    # cd n2rrd-1.3.1
    # sh ./install.sh
    # for fdist in `find /etc/n2rrd -name dist-*`; do fnew=`echo $fdist | sed 's/dist-//'`; mv $fdist $fnew; done
    # mkdir /var/www/html/n2rrd
    # chown apache /var/www/html/n2rrd
    # mkdir /var/log/nagios/rra
    # chown nagios:nagios /var/log/nagios/rra
    # cp rrd2graph.cgi /var/www/cgi-bin/

  2. Edit "/etc/n2rd/n2rrd.conf"
    # egrep -v "#|^$" /etc/n2rrd/n2rrd.conf
    CONF_DIR = /etc/n2rrd
    RRA_DIR = /var/log/nagios/rra
    TEMPLATES_DIR = templates
    SERVICE_NAME_MAPS = templates/maps/service_name_maps
    LOGFILE   &nbsp; = /var/log/nagios/rra/n2rrd.log<br />DOCUMENT_ROOT = /var/www/html
    CACHE_DIR = n2rrd
    TMPDIR=/tmp
    RRDTOOL = /usr/bin/rrdtool
    RRD_PATH_HIDDEN=1
    NAGIOS_HOST_URL=0
    CGIBIN = cgi-bin
    NAGIOS_CGIBIN = nagios/cgi-bin
    THUMB_DISPLAY = Daily
    THUMB_DISPLAY_COLUMNS = 3
    THUMB_HEIGHT = 100
    THUMB_WIDTH = 200
    ZOOM_JS = js/zoom.js
    SAVE_NAGIOS_ENVIRONMENT_VARS = 1
  3. Add the process-host and process-service performance commands for n2rrd in "/etc/nagios/commang.cfg":
    #### n2rrd ####
    # Host Performance processing command
    define command{
      command_name process-host-perfdata-n2rrd />  command_line /usr/local/bin/n2rrd.pl -d -c /etc/n2rrd/n2rrd.conf -e $SERVICEEXECUTIONTIME$ \
      -l $SERVICELATENCY$ -T $LASTHOSTCHECK$ -H $HOSTNAME$ -s "check_ping" -o "$HOSTOUTPUT$"
    }
    # Service Performance processing command
    define command{
      command_name process-service-perfdata-n2rrd
      command_line /usr/local/bin/n2rrd.pl -d -c /etc/n2rrd/n2rrd.conf -e $SERVICEEXECUTIONTIME$ \
      -l $SERVICELATENCY$ -T $LASTSERVICECHECK$ -H $HOSTNAME$ -s "$SERVICEDESC$" -o "$SERVICEPERFDATA$"<br />}
  4. Create templates if not already existing for the particular service.
  5. Edit "/etc/n2rrd/templates/maps/service_name_maps" and add the necessary maps.
    HTTP: http
    ICMP: icmp
  6. Check the setup with:
    # nagios -v /etc/nagios/nagios.cfg
  7. Once the configs are sorted out and without errors, start nagios via:
    # /etc/init.d/nagios start

Notes:

  • If building rpm package for nagios-plugins, build as root so it will build the root plugins - eg. check_icmp which is much faster that using check_ping
    # chmod u+s /var/lib/nagios/plugins/check_icmp
  • Install vrml plugin to view 3D model.

    To install freewrl In ubuntu:

    $ sudo apt-get install lesstif2

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Some good links

Very nice tutorial. You can also check some more details in the link given below.

http://howtosetup.in/component/content/article/2-subversion/9-how-to-setup-nagios-.html

Comment