Title: nagios debian stable setup notes Subject: Setup nagios-1.3 /w mysql on debian, and nagiosgraph create custom check program and tie into nagios, add nagiosgraph, add paginger notitication Author: John Stile License: GPL ############################## # # Install packages # ############################### aptitude update aptitude install nagios-mysql \ nagios-common \ nagios-plugins \ nagios-statd-client \ nagios-statd-server \ nagios-stat-client \ iputils-ping \ nsca \ nagios-nrpe-plugin \ nagios-nrpe-server \ nagios-nrpe-doc \ qstat fping libnet-snmp-perl libradius1 ntpdate \ radiusclient1 samba-common smbclient Configuring nagios-common Automatically configure apache for Nagios? Apache2 Nagios web administration password? FooBar Enable Nagios external command interface on web?? #------------------------------- # backup original config files # cd /etc/nagios/ tar -czvpf Original_cfg.tar.gz *.cfg #------------------------------ # Fix perms on nagios-plugins # chown -R nagios:www-data /etc/nagios-plugins #------------------------------------ # Setup and alias for watching logs # cat >> /root/.bashrc <> /etc/nagios/contacts.cfg <> /etc/nagios/contactgroups.cfg < /etc/nagios/cgi.cfg.johns1 #-------------------------------------------- # Create and populate nagios MySQL database # mysqladmin -u root -p create nagios zcat /usr/share/doc/nagios-mysql/create_mysql.gz | mysql -u root -p nagios cat > mysql nagios -uroot -p </etc/nagios/cgi.cfg.johns2 sed 's/^#nagios_check_command=\/etc/nagios_check_command=\/etc/' /etc/nagios/cgi.cfg.johns2 > /etc/nagios/cgi.cfg.john3 sed 's/^#x/x/' /etc/nagios/cgi.cfg.john3 > /etc/nagios/cgi.cfg.john4 sed 's/somehost/localhost/' /etc/nagios/cgi.cfg.john4 > /etc/nagios/cgi.cfg.john5 sed 's/someuser/nagios/' /etc/nagios/cgi.cfg.john5 > /etc/nagios/cgi.cfg.john6 sed 's/somepassword/nagios/' /etc/nagios/cgi.cfg.john6 > /etc/nagios/cgi.cfg.john7 sed 's/somedatabase/nagios/' /etc/nagios/cgi.cfg.john7 > /etc/nagios/cgi.cfg.john8 sed 's/^\(x.*someport\)$/#\1/' /etc/nagios/cgi.cfg.john8 > /etc/nagios/cgi.cfg cp /etc/nagios/resource.cfg /etc/nagios/resource.cfg.orig sed 's/^#x/x/' /etc/nagios/resource.cfg > /etc/nagios/resource.cfg.john1 sed 's/somehost/localhost/' /etc/nagios/resource.cfg.john1 > /etc/nagios/resource.cfg.john2 sed 's/someuser/nagios/' /etc/nagios/resource.cfg.john2 > /etc/nagios/resource.cfg.john3 sed 's/somepassword/nagios/' /etc/nagios/resource.cfg.john3 > /etc/nagios/resource.cfg.john4 sed 's/somedatabase/nagios/' /etc/nagios/resource.cfg.john4 > /etc/nagios/resource.cfg.john5 sed 's/^\(x.*someport\)$/#\1/' /etc/nagios/resource.cfg.john5 > /etc/nagios/resource.cfg #-------------------------------------------------------------------------------------- # nagios.conf -activate events, log perfdata, and name defenition for handler program # sed 's/log_event_handlers=0/log_event_handlers=1/' /etc/nagios/nagios.cfg > /etc/nagios/nagios.cfg.john1 sed 's/process_performance_data=0/process_performance_data=1/' /etc/nagios/nagios.cfg.john1 > /etc/nagios/nagios.cfg.john2 sed 's/#\(service_perfdata_command=process-service-perfdata\)/\1/' /etc/nagios/nagios.cfg.john2 > /etc/nagios/nagios.cfg.john3 #-------------------------------------------- # Allow Nagios to see it's onw process info # cp /usr/share/doc/nagios-common/check_nagios_db /etc/nagios/check_nagios_db chown nagios:www-data /etc/nagios/check_nagios_db chmod +x /etc/nagios/check_nagios_db #------------------------------------------- # Fix check_procs_httpd to look for apache2, not httpd cp /etc/nagios-plugins/config/procs.cfg /etc/nagios-plugins/config/procs.cfg.orig vi /etc/nagios-plugins/config/procs.cfg # Change: # command_line /usr/lib/nagios/plugins/check_procs -w 5:$ARG1$ -c 1:$ARG2$ -C httpd # To: # command_line /usr/lib/nagios/plugins/check_procs -w 5:$ARG1$ -c 1:$ARG2$ -C apache2 #-------------------- # Create some hosts # cp /etc/nagios/hosts.cfg /etc/nagios/hosts.cfg.orig cat >> /etc/nagios/hosts.cfg <> /etc/nagios/hostgroups.cfg <> /etc/nagios/services.cfg <> escalations.cfg < /etc/nagios/nrpe.cfg.john1 sed 's/^\(dont_blame_nrpe=\).*/\11/' /etc/nagios/nrpe.cfg.john1 > /etc/nagios/nrpe.cfg.john2 sed 's/^\(debug=\).*/\11/' /etc/nagios/nrpe.cfg.john2 > /etc/nagios/nrpe.cfg.john3 cp /etc/nagios/nrpe.cfg.john3 /etc/nagios/nrpe.cfg #------------------------- # Edit these commands for proper disk configuration. (run df -k, mount -l) # vi /etc/nagios/nrpe.cfg # # command[check_disk1]=/usr/lib/nagios/plugins/check_disk -w 20 -c 10 -p /dev/sda1 # command[check_disk2]=/usr/lib/nagios/plugins/check_disk -w 20 -c 10 -p /dev/sda3 # command[check_disk3]=/usr/lib/nagios/plugins/check_disk -w 20 -c 10 -p /dev/sdb1 # command[check_disk4]=/usr/lib/nagios/plugins/check_disk -w 20 -c 10 -p /dev/sdb2 #------------------------- # Add firewall rule to firewall to allow remote nrpe checks # vi /etc/init.d/rc.firewall.mapp # # ## NAGIOS (NRPE): Allow nagios server to get stats # iptables -A INPUT -s 192.168.0.102 -d $PUBLIC_IP -p tcp --dport 5666 -j ACCEPT # # NOTE: For a redhat system, I had to edit a different file: /etc/sysconfig/iptables # -A INPUT -s 192.168.0.102/255.255.255.0 -p tcp -m tcp --dport 5666 -j ACCEPT #------------------------- # Reload nagios # # DEBIAN /etc/init.d/nagios-nrpe-server restart # SUSE9.2 /etc/init.d/xinetd restart #------------------------- # Reload firewall # /etc/init.d/rc.firewall restart #------------------------- # FROM NOW ON, BACK TO THE SERVER, #-------------------------- # Connect to NRPE daemon on our remote host # /usr/lib/nagios/plugins/check_nrpe -H daman.stilen.com # NRPE v2.0 #---------------------------------------- # Setup service records for host to check: # cat >> /etc/nagios/service.cfg <> /var/log/nagios/host-perfdata.out } #-------------------- # Fixing nagios to handle perfdata # vi /etc/apt/sources.list # deb-src http://ftp.us.debian.org/debian/ sarge main cd /tmp/ apt-get update apt-get source nagios-mysql cd ../nagios-1.3-cvs.20050402/ # # Add graphs to main window (part 1) # vi cgi/status.c # Find area that looks like this: # temp_serviceextinfo=find_serviceextinfo(temp_service->host_name,temp_service->description); # if(temp_serviceextinfo!=NULL){ # if(temp_serviceextinfo->icon_image!=NULL){ # printf(""); # if(temp_serviceextinfo->notes_url!=NULL){ # printf(""); # } # Change: printf("' TARGET='_blank'>"); # To: printf("' TARGET='main'>"); # # After the next compile and make steps, copy the new status.cgi into place: # cp /usr/lib/cgi-bin/nagios/status.cgi /usr/lib/cgi-bin/nagios/status.cgi.orig # cp ./cgi/status.cgi /usr/lib/cgi-bin/nagios/status.cgi # Compile flags are listed in debian/rules # Rebuild with proper options # The only new option that matters is --with-default-perfdata ./configure --prefix=/usr/share/nagios \ --prefix=/usr \ --mandir=/usr/share/man \ --bindir=/usr/sbin \ --sbindir=/usr/lib/cgi-bin/nagios \ --datadir=/usr/share/nagios/htdocs \ --libexecdir=/usr/lib/nagios/plugins \ --sysconfdir=/etc/nagios \ --mandir=/usr/share/man \ --infodir=/usr/share/info \ --localstatedir=/var/log/nagios \ --with-ping-command="/bin/ping -n %s -c %d" \ --with-mail=/usr/bin/mail \ --with-perlcache \ --with-cgiurl=/nagios/cgi-bin \ --with-htmurl=/nagios \ --with-nagios-user=nagios \ --with-nagios-grp=nagios \ --with-default-perfdata \ --with-mysql-downtime \ --with-mysql-comments \ --with-mysql-status \ --with-mysql-retention \ --with-mysql-extinfo # make it make all # # Add graphs to main window (part 2) # cp /usr/lib/cgi-bin/nagios/status.cgi /usr/lib/cgi-bin/nagios/status.cgi.orig cp ./cgi/status.cgi /usr/lib/cgi-bin/nagios/status.cgi # backup old nagios, and copy new into place mv /usr/sbin/nagios /usr/sbin/nagios.debian cp base/nagios /usr/sbin/nagios.john cp /usr/sbin/nagios.john /usr/sbin/nagios ls -alF /usr/lib/cgi-bin/nagios/status.cgi* /usr/sbin/nagios* # -rwsr-xr-x 1 nagios root 568755 2005-10-11 22:09 /usr/lib/cgi-bin/nagios/status.cgi* # -rwsr-xr-x 1 root root 179248 2005-10-11 22:09 /usr/lib/cgi-bin/nagios/status.cgi.orig* # -rwxr-xr-x 1 root root 915637 2005-10-11 22:09 /usr/sbin/nagios* # -rwxr-xr-x 1 root root 286128 2005-09-24 20:11 /usr/sbin/nagios.debian* # -rwxr-xr-x 1 root root 915637 2005-10-11 22:09 /usr/sbin/nagios.john* # -rwxr-xr-x 1 root root 9336 2004-09-01 17:02 /usr/sbin/nagios-statd* # Now check what nagios says is running nagios -m # Nagios 1.3 # Copyright (c) 1999-2004 Ethan Galstad (nagios@nagios.org) # Last Modified: 10-24-2004 # License: GPL # # External Data I/O # ----------------- # Object Data: TEMPLATE # Status Data: DATABASE (MySQL) # Retention Data: DATABASE (MySQL) # Comment Data: DATABASE (MySQL) # Downtime Data: DATABASE (MySQL) # Performance Data: DEFAULT # # Options # ------- /etc/init.d/nagios restart # Now we have Data! YAY! ########################################## # Adding nagiosgraph ( w/ RRDTool ) # ########################################## aptitude install rrdtool cd /usr/share/nagios/ wget http://easynews.dl.sourceforge.net/sourceforge/nagiosgraph/nagiosgraph-0.5.tar.gz tar xzvpf nagiosgraph-0.5.tar.gz cd nagiosgraph vi nagiosgraph.conf # debug = 2 # logfile = /var/log/nagiosgraph/nagiosgraph.log # rrddir = /usr/share/nagios/nagiosgraph/rrd # mapfile = /usr/share/nagios/nagiosgraph/map # rrdtool = /usr/bin/rrdtool # colorscheme = 1 # heartbeat = 600 vi show.cgi # Change: # my $configfile = '/usr/local/etc/nagiosgraph.conf'; # To: # #my $configfile = '/etc/nagios/nagiosgraph.conf'; # my $configfile = '/usr/share/nagios/nagiosgraph/nagiosgraph.conf'; vi ./insert_fast.pl # Change: # my $configfile = '/usr/local/etc/nagiosgraph.conf'; # To: # #my $configfile = '/etc/nagios/nagiosgraph.conf'; # my $configfile = '/usr/share/nagios/nagiosgraph/nagiosgraph.conf'; vi insert.pl # Change: # my $configfile = '/usr/local/etc/nagiosgraph.conf'; # To: # #my $configfile = '/etc/nagios/nagiosgraph.conf'; # my $configfile = '/usr/share/nagios/nagiosgraph/nagiosgraph.conf'; mkdir rrd chown -R nagios:www-data rrd chmod 775 rrd touch /var/log/nagios/nagiosgraph.log chown -R nagios:www-data /var/log/nagiosgraph chmod 777 rrd vi /etc/nagios/nagios.cfg # Change: # process_performance_data=0 # #service_perfdata_command=process-service-perfdata # To: # process_performance_data=1 # service_perfdata_command=process-service-perfdata # cfg_file=/etc/nagios/serviceextinfo.cfg vi /etc/nagios/misccommands.cfg # Change: # define command{ # command_name process-service-perfdata # command_line /usr/bin/printf "%b" "$LASTCHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$STATETYPE$\t$EXECUTIONTIME$\t$LATENCY$\t$OUTPUT$\t$PERFDATA$" >> /var/log/nagios/service-perfdata.out # } # To: # define command { # command_name process-service-perfdata # command_line /usr/share/nagios/nagiosgraph/insert_fast.pl "$LASTCHECK$||$HOSTNAME$||$SERVICEDESC$||$OUTPUT$||$PERFDATA$" # } #Created a small icon about 40x40: #Placed it in here: # /usr/share/nagios/htdocs/images/logos/graph.png vi /etc/nagios/cgi.cfg # Append: # xedtemplate_config_file=/etc/nagios/serviceextinfo.cfg vi /etc/nagios/apache.conf # Append: # Include /usr/share/nagios/nagiosgraph/apache2.conf vi /usr/share/nagios/nagiosgraph/apache2.conf # Enter: # ScriptAlias /nagiosgraph/ /usr/share/nagios/nagiosgraph/ # # Options ExecCGI # # AllowOverride AuthConfig # Order Allow,Deny # Allow From All # # AuthName "Nagios Access" # AuthType Basic # AuthUserFile /etc/nagios/htpasswd.users # require valid-user # # # Add icon to the nagios status line: # mysql nagios -unagios -pnagios insert into serviceextinfo set host_name='mother.stilen.com', service_description='PING', notes_url='/nagiosgraph/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$', icon_image='graph.png', icon_image_alt='View graphs'; quit; INSERT INTO `serviceextinfo` ( `host_name` , `service_description` , `notes_url` , `icon_image` , `icon_image_alt` ) VALUES ( 'mother', '/dev/sda1 Free Space', '/nagiosgraph/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$', 'graph.png', 'View Graph' ); ################################## # # Setup Notification # ################################## cp /etc/nagios/escalations.cfg{,.orig} vi /etc/nagios/escalations.cfg # Serviceescalation definition define serviceescalation{ host_name gw2 service_description PING first_notification 2 last_notification 6 contact_groups linux-admins notification_interval 0 } # Serviceescalation definition define serviceescalation{ host_name gw1 service_description PING first_notification 2 last_notification 6 contact_groups linux-admins notification_interval 0 } # Serviceescalation definition define serviceescalation{ host_name gw1 service_description PING first_notification 2 last_notification 6 contact_groups linux-admins notification_interval 0 } # Serviceescalation definition define serviceescalation{ host_name mother service_description PING first_notification 2 last_notification 6 contact_groups linux-admins notification_interval 0 } vi /etc/nagios/contactgroups.cfg # just verify you have a contact you want to notify vi /etc/nagios/contacts.cfg # 'johns' contact definition define contact{ contact_name johns alias Nagios Admin service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r host_notification_options d,u,r service_notification_commands notify-by-email,notify-by-epager host_notification_commands host-notify-by-email,host-notify-by-epager email johns@foo.com pager 5101003280@mmode.com } ----------------------------------- 20051014 jstile: Add tweek to increase host checking performance The check_ping takes 1 second The check_icmp takes .1 seconds Creating a soft link from check_cimp to check_host causes it to behave as a replacement for check_ping ln -s /usr/lib/nagios/plugins/check_icmp /usr/lib/nagios/plugins/check_host /usr/lib/nagios/plugins/check_host daman.stilen.com mode: 1 mode: 1 mode: 1 mode: 1 mode: 1 mode: 1 mode: 1 mode: 1 mode: 1 ttl set to 64 Setting alarm timeout to 10 seconds packets: 5, targets: 9 target_interval: 0.000, pkt_interval 1000.000 crit.rta: 1000.000 max_completion_time: 91000.000 max_completion_time: 91000000 timeout: 10 Timout must be at lest 92 crit = {1000000, 100%}, warn = {1000000, 100%} pkt_interval: 1000000 target_interval: 0 retry_interval: 0 icmp_pkt_size: 64 timeout: 10 Segmentation fault engfirewall:/usr/lib/nagios/plugins# ./check_host daman.stilen.com mode: 1 OK - daman.stilen.com responds to ICMP. Packet 1, rta 0.254ms|pkt=1;;0;5 rta=0.254;1000.000;1000.000;;