Homepage

Wednesday, July 6, 2016

MRTG with NAGIOS

Hi, All Here is some document relate system that it will can help you all to build  system monitor network traffic. you can follow the instruction step by step below:

Install MRTG. 
Configure and setup MRTG. 
Add new definitions to Nagios. (Part 2) 
Setup and restart Nagios to view new bandwidth defined services. (Part 2)

Part 1 - Install MRTG on CentOS
We will cover in this initial article the MRTG installation for CentOS 6.4, it works too in CentOS 6.3 and other distro.
First install the snmp tools needed.
# yum install net-snmp net-snmp-utils rrdtool
Afterwards install the MRTG
#yum install mrtg
Now it's time to decide where do you want to see your graphs and infos. Maybe in a MRTG dir in  wwwroot where you will find all the datas in the future. 
mkdir /var/www/html/mrtg
Now let's go an create a good mrtg.conf file. It's important, so take a while doing the correct settings.
Used command cfgmaker to create log file relate with information of device
cfgmaker --ifref=descr --ifdesc=descr --snmp-options=:::::2 --global 'WorkDir: /var/www/html/mrtg/router_name/' --global 'Options[_]: bits' --output /etc/mrtg/mrtg_router_name.cfg "snmp commnunity"@x.x.x.x":::::2"
  • Snmp-options=:::::2 used for data graphing over 100Mb/s
And then we need to create index file for storing data information by using command below
# indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg_router_name.cfg
You can you command to show graph manually after 5 minute
# /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok
Then we need to create crontab in order to to run command to generate data every 5 minutes by
# vim /etc/cron.d/mrtg
*/5 * * * * root LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok
Note: one command just can execute for only one device, if you have many device you need to create files more to execute to trap data from other devices.
#service httpd restart
Then you can access by http://x.x.x.x/mrtg
 
  1. Part 2 - Monitoring bandwidth with Nagios - Settings alerts.
Add a service to Nagios to monitor port bandwidth 
check_local_mrtgtraf uses the MRTG. So, first install MRTG for this to work properly. The *.log file mentioned below should point to the MRTG log file on your system, the MRTG work directory we have created. The check_local_mrtgtraf is included in Nagios plugins.
#vim /usr/local/nagios/object/router_name.cfg
And add this parameter below:
define service{
use           generic-service
host_name   core-switch
service_description Port 1 Bandwidth Usage
check_command  check_local_mrtgtraf!/var/www/mrtg/router_name_interface.log!AVG!1000000,2000000!5000000,5000000!10
}
The "AVG" option tells it that it should use average bandwidth statistics.
The "1000000,2000000" options are the warning thresholds (in bytes) for incoming traffic rates.
The "5000000,5000000" are critical thresholds (in bytes) for outgoing traffic rates.
The "10" option causes the plugin to return a CRITICAL state if the MRTG log file is older than 10 minutes (it should be updated every 5 minutes). 
For more check_local_mrtgtraf properties, run the plugin help.  
Remember to validate Nagios settings and restart if all settings are ok.
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# /etc/init.d/nagios restart

Thursday, June 23, 2016

How to Install Nagvis with Check_mk

In nagvis need to have backend to create data from Nagios Server to Nagvis, so before install Nagvis we must install check_mk first by follow the instruction below:

Prerequisites.

Check_mk GUI need a python apache module that is not included in distro repositories actually. It can be installed from EPEL repositories.

# Install EPEL Repositories (if needed it)
rpm --import https://fedoraproject.org/static/0608B895.txt
wget 
http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

yum localinstall epel-release-6-8.noarch.rpm

# Install python module for apache
yum install mod_python gcc gcc-c++ rsync php
Install
tar zxfv check_mk-1.2.5i2p1.tar.gz
cd check_mk-1.2.5i2p1
./setup
Check_mk install is quite easy. It may be even easier if you copy next text in a file named “.check_mk_setup.conf” in your home root (first character file name is “.”).  
# just follow this step to setup check_mk
bindir=’/usr/bin’
confdir=’/etc/check_mk’
sharedir=’/usr/share/check_mk’
docdir=’/usr/share/doc/check_mk’
checkmandir=’/usr/share/doc/check_mk/checks’
vardir=’/var/lib/check_mk’
agentslibdir=’/usr/lib/check_mk_agent’
agentsconfdir=’/etc/check_mk’
nagiosuser=’nagios’
wwwuser=’apache’
wwwgroup=’nagcmd’
nagios_binary=’/usr/local/nagios/bin/nagios’
nagios_config_file=’/usr/local/nagios/etc/nagios.cfg’
nagconfdir=’/usr/local/nagios/etc/check_mk.d’
nagios_startscript=’/etc/init.d/nagios’
nagpipe=’/usr/local/nagios/var/rw/nagios.cmd’
check_result_path=’/usr/local/nagios/var/spool/checkresults’
nagios_status_file=’/usr/local/nagios/var/status.dat’
check_icmp_path=’/usr/local/nagios/libexec/check_icmp’
url_prefix=’/’
apache_config_dir=’/etc/httpd/conf.d’
htpasswd_file=’/usr/local/nagios/etc/htpasswd.users’
nagios_auth_name=’Nagios Access’
pnptemplates=’/usr/local/pnp4nagios/share/templates’
rrd_path=’/var/lib/nagios/rrd’
rrdcached_socket=’/tmp/rrdcached.sock’
enable_livestatus=’yes’
nagios_version=’4.0.5
libdir=’/usr/lib/check_mk’
livesock=’/usr/local/nagios/var/rw/live’
livebackendsdir=’/usr/share/check_mk/livestatus’
enable_mkeventd=’yes’
mkeventdstatedir=’/var/lib/mkeventd’
# Load Livestatus Module
broker_module=/usr/lib/check_mk/livestatus.o /usr/local/nagios/var/rw/live
event_broker_options=-1
We can test check_mk in URI http://server/check_mk.

chmod 0770 /var/lib/check_mk/wato/ -R
 chown apache:nagios -R /var/lib/check_mk/wato/
 chmod 777 -R /etc/check_mk/conf.d/wato/
chmod 777 -R /etc/check_mk/multisite.d/wato/
 chown apache:nagios -R /var/lib/check_mk/web/

If you find any problem with check_mk livestatus connect to Nagios, first to look is correct load of livestatus in nagios.log:

> tail /usr/local/nagios/var/nagios.log
[1396806973] livestatus: Livestatus 1.2.5i2 by Mathias Kettner. Socket: '/usr/local/nagios/var/rw/live'
[1396806973] livestatus: Please visit us at http://mathias-kettner.de/
[1396806973] livestatus: Hint: please try out OMD - the Open Monitoring Distribution
[1396806973] livestatus: Please visit OMD at http://omdistro.org
[1396806973] livestatus: Finished initialization. Further log messages go to /usr/local/nagios/var/livestatus.log
[1396806973] Event broker module '/usr/lib/check_mk/livestatus.o' initialized successfully.
[1396806974] Successfully launched command file worker with pid 4873
Example localhost in check_mk…
Nagvis

Prerequisites.

yum install php-mbstring php-pdo graphviz

Installation

tar zxfv nagvis-1.8b3.tar.gz
cd nagvis-1.8b3
./install.sh


Main questions from install are about paths and users but Nagvis install discover so good all important values. We must select only “backend mklivestatus”
+——————————————————————————+
| Welcome to NagVis Installer 1.8b3 |
+——————————————————————————+
| This script is built to facilitate the NagVis installation and update |
| procedure for you. The installer has been tested on the following systems: |
– Debian, since Etch (4.0) |
– Ubuntu, since Hardy (8.04) |
– SuSE Linux Enterprise Server 10 and 11 |
| |
| Similar distributions to the ones mentioned above should work as well. |
| That (hopefully) includes RedHat, Fedora, CentOS, OpenSuSE |
| |
| If you experience any problems using these or other distributions, please |
| report that to the NagVis team. |
+——————————————————————————+
| Do you want to proceed? [y]: y
+——————————————————————————+
| Starting installation of NagVis 1.8b3 |
+——————————————————————————+
| OS : CentOS release 6.5 (Final) |
| |
+— Checking for tools ——————————————————-+
| Using packet manager /bin/rpm found |
| |
+— Checking paths ———————————————————–+
| Please enter the path to the nagios base directory [/usr/local/nagios]:
| nagios path /usr/local/nagios found |
| Please enter the path to NagVis base [/usr/local/nagvis]:
| |
+— Checking prerequisites —————————————————+
| PHP 5.3 found |
| PHP Module: gd php found |
| PHP Module: mbstring php found |
| PHP Module: gettext compiled_in found |
| PHP Module: session compiled_in found |
| PHP Module: xml compiled_in found |
| PHP Module: pdo php found |
| Apache mod_php found |
| Checking Backends. (Available: mklivestatus,ndo2db,ido2db,merlinmy) |
| Do you want to use backend mklivestatus? [y]: y
| Do you want to use backend ndo2db? [n]:
| Do you want to use backend ido2db? [n]:
| Do you want to use backend merlinmy? [n]:
| Livestatus Socket (/usr/local/nagios/var/rw/live) found |
| PHP Module: sockets compiled_in found |
….
+— Trying to detect Apache settings —————————————–+
| Please enter the web path to NagVis [/nagvis]:
| Please enter the name of the web-server user [apache]:
| Please enter the name of the web-server group [apache]:
| create Apache config file [y]:
| |
+— Checking for existing NagVis ———————————————+
| |
+——————————————————————————+
| Summary |
+——————————————————————————+
| NagVis home will be: /usr/local/nagvis |
| Owner of NagVis files will be: apache |
| Group of NagVis files will be: apache |
| Path to Apache config dir is: /etc/httpd/conf.d |
| Apache config will be created: yes |
| |
| Installation mode: install |
| |
| Do you really want to continue? [y]:
+——————————————————————————+
| Installation complete |
| |
| You can safely remove this source directory. |
| |
| For later update/upgrade you may use this command to have a faster update: |
| ./install.sh -n /usr/local/nagios -p /usr/local/nagvis -l “unix:/usr/local/nagios/var/rw/live” -b mklivestatus -u apache -g apache -w /etc/httpd/conf.d -a y
| |
| What to do next? |
– Read the documentation |
– Maybe you want to edit the main configuration file? |
| Its location is: /usr/local/nagvis/etc/nagvis.ini.php |
– Configure NagVis via browser |
– Initial admin credentials: |
| Username: admin |
| Password: admin |
+——————————————————————————+
service httpd reload
service nagios restart
chmod 777 /usr/local/nagios/var/rw -R (to allow Mklivestatus to create file to store data)
Test your new Nagivis web site: http://server/nagvis/ (admin/admin)