check_mrtgtraf: Unable to open MRTG log file

Discussion in 'Installation/Configuration' started by gads, Sep 2, 2010.

  1. gads

    gads New Member

    hi, I have installed nagios on centOS and I monitor switch but the Port1 Bandwidth Usage has this error "check_mrtgtraf: Unable to open MRTG log file ". I had already installed mrtg but it has the same error.
    do anyone can help me about this problem? thanks in advance...

    here is the script of my switch.cfg:

    define service{
    use generic-service ; Inherit values from a template
    host_name distributed_switch
    service_description Port 1 Bandwidth Usage
    check_command check_local_mrtgtraf!/var/lib/mrtg/192.168.1.253_1.log!AVG!1000000,1000000!5000000,5000000!10
    }
     
  2. Mark_NL

    Mark_NL New Member

    Code:
    ls -al /var/lib/mrtg/192.168.1.253_1.log
    Code:
    ps flax | grep nagios
     
  3. gads

    gads New Member

    thanks for the reply Mark_NL, when I try the code you gave this is the result:

    [root@localhost ~]# ls -al /var/lib/mrtg/192.168.1.253_1.log
    ls: /var/lib/mrtg/192.168.1.253_1.log: No such file or directory
    [root@localhost ~]# ps flax | grep nagios
    0 0 18909 12276 17 0 3916 664 stext S+ pts/0 0:00 | \_ grep nagios
    1 100 2860 1 18 0 6780 484 335550 Ss ? 0:00 /usr/sbin/ndo2db -c /etc/nagios/ndo2db.cfg
    1 100 16191 2860 15 0 6780 1268 - S ? 0:01 \_ /usr/sbin/ndo2db -c /etc/nagios/ndo2db.cfg
    1 100 16188 1 15 0 13716 984 stext Ssl ? 0:00 /usr/bin/nagios -d /etc/nagios/nagios.cfg

    I wonder what is 192.168.1.253_1.log because when i go to /var/lib/mrtg/ directory, it is not there? what should i do about this?

    thanks in advance..
     
  4. Mark_NL

    Mark_NL New Member

    what IS in that mrtg dir?

    Code:
    ls -al /var/lib/mrtg/
     
  5. kheimbuch

    kheimbuch New Member

    Hey Mark I am having the same problem as Gads. The only file I have in the /var/lib/mrtg/ directory is:

    _etc_mrtg.cfg
     
  6. gads

    gads New Member

    hi Mark, thanks for the reply, sorry for the late response... here is the result of the command " ls -al /var/lib/mrtg/ " :

    [root@localhost ~]# ls -al /var/lib/mrtg/
    total 12
    drwxr-xr-x 2 root root 4096 Jan 10 2007 .
    drwxrwxr-x 22 apache nagios 4096 Sep 1 13:21 ..
    -rw-r--r-- 1 nagios nagios 0 Sep 3 10:15 mrtg.ok
    [root@localhost ~]#

    what should I do next? thanks in advance...
     
  7. falko

    falko Super Moderator ISPConfig Developer

    Can you try
    Code:
    chown nagios:nagios /var/lib/mrtg/
    ?
     
  8. kheimbuch

    kheimbuch New Member

    Nothing for me. Still the same error. I had even tried creating the file itself and giving nagios full access to it.
     
  9. falko

    falko Super Moderator ISPConfig Developer

    Does a
    Code:
    chmod 777 /var/lib/mrtg/
    work?
     
  10. gads

    gads New Member

    hi, i have solved this problem, this is the things that i did:

    Install MRTG:
    To monitor bandwidth usages of router/switch you must have mrtg installed on system. Before installation please make sure you have install gd, libpng, zlib packages.

    1. Download MRTG using yum install mrtg

    2. Now you need not to create mrtg configuration file. Use cfgmaker.
    cfgmaker --global 'WorkDir: /var/www/html/mymrtg' --global 'Options[_]: bits,growright' --output /etc/httpd/conf/mrtg.cfg public@<ip address of the switch>
    6. Go to respective location and make sure that above command has created respective files.
    cd /var/www/html/mrtg;
    ls -al /etc/httpd/conf/mrtg.cfg

    7. Run this command to update mrtg log file.
    env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg


    10. Set cron to run above command every 5 minute.
    crontab -e

    11. insert the code below and save,
    */5 * * * * /usr/bin/env LANG=C /usr/bin/mrtg /etc/mrtg/mymrtg.cfg –logging /var/log/mrtg.log
    */5 * * * * /usr/bin/env LANG=C /usr/bin/mrtg /etc/httpd/conf/mrtg.cfg --logging /var/log/mrtg.log

    12. Restart cron service.
    /etc/init.d/crond restart

    13. Confirm that it is been configured.
    http://localhost/mymrtg/{name of html file}

    Actually when you run mrtg command it searches for respective router community collects all data from router. Accordingly it creates log file. Like in my case it has found port 2 running on router and hence created file 172.17.42.22_2.log, 172.17.42.22_2.html. So I can access my graph through this link,
    http://localhost/mymrtg/<ip address of the switch>_2.html

    Procedure to monitor Bandwidth Usages in Nagios:
    1. Default installation directory of nagios is /usr/local/nagios/.

    2. Open switch.cfg file
    nano /etc/nagios/objects/switch.cfg

    3. Make changes according to your router specifications. Like,
    define host{
    use generic-switch
    host_name Router_1
    alias Router 1
    address 172.17.42.22
    hostgroups switches
    }
    4. You can also set PING, Uptime, Ports Link Status etc.
    define service{
    use generic-service ; Inherit values from a template
    host_name Router_1 ; The name of the host the service is associated with
    service_description PING ; The service description
    check_command check_ping!200.0,20%!600.0,60% ; The command used to monitor the service
    normal_check_interval 5 ; Check the service every 5 minutes under normal conditions
    retry_check_interval 1 ; Re-check the service every minute until its final/hard state is determined
    }

    define service{
    use generic-service ; Inherit values from a template
    host_name Router_1
    service_description Uptime
    check_command check_snmp!-C public -o sysUpTime.0 -H 172.17.42.22
    }

    define service{
    use generic-service ; Inherit values from a template
    host_name Router_1
    service_description Port 2 Link Status
    check_command check_snmp!-C public -o ifOperStatus.2 -r 1 -H 172.17.42.22
    }

    define service{
    use generic-service ; Inherit values from a template
    host_name Router_1
    service_description Port 2 Bandwidth Usage
    check_command check_local_mrtgtraf!/var/www/html/mymrtg/172.17.42.22_2.log!AVG!1000000,1000000!5000000,5000000!10
    }

    5. Verify the configuration of nagios
    /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

    6. Restart nagios service.
    /etc/init.d/nagios restart
     
  11. kheimbuch

    kheimbuch New Member

    falko- No I had tried that already and it did not work... Thanks for the suggestion though.

    Gads - This worked out for me as well. The only thing I had to do was modify some of the file location paths. Since I am monitoring multiple switches I had to modify some things.

    Using the "env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg" command would not work for multiple switches. I had to change the output to look something like this "env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg_252.cfg". This was done for each switch so that I knew which output file to point the nagios check_mrtgtraf command to in the switch.cfg file.

    I also had to make the appropriate change within the crontab file as well. Other wise it would not update that file and it would give the error "MRTG data has expired".

    Only thing I have noticed is that the output files from mrtg only list ports that are listed as being up. Well I shouldn't say that, they are in the log file but are commented out so in nagios it will still show the error: "check_mrtgtraf: Unable to open MRTG log file". Once something is plugged into the port it will start reading the bandwidth once it refreshes.

    Awesome job figuring this out gads.
     
  12. chiragvaidya

    chiragvaidya New Member

    graphs not geting generated in pnp nagios

    Hi,

    i m making graph for my 2950 cisco switch, i can able to get data but still graphs not getting generated. here im attaching some screenshots so taht u can help me better.
     

    Attached Files:

  13. RAYNM3N

    RAYNM3N New Member

    Hi!


    No need to have a different config file for every switch.
    Just append the following configs to the same mrtg.conf file and then point to the ip_port on Nagios.
    There is also no need to extra add any line in crontab.

    Hope this helped!
     
  14. RAYNM3N

    RAYNM3N New Member

    Hi!

    I have written a reply - at the bottom of all messages - in response to your message.
    I hope that will help you get rid on some extra work.

    Cheers.
     
  15. ilyar

    ilyar New Member

    still having trouble

    Hello All!

    I need some help. I followed gads instructions and still receiving the error: check_mrtgtraf: Unable to open MRTG log file

    I don't understand what is going on at this point. Please help. I checked the following:

    The html file works
    http://10.0.1.85/mymrtg/10.0.1.1_2.html

    The switch.cfg is configured
    define service{
    use generic-service ; Inherit values from a template
    host_name Router_San_Rafael
    service_description Port 2 Bandwidth Usage
    check_command check_local_mrtgtraf!/var/www/html/mymrtg/10.0.1.1_2.log!AVG!1000000,1000000!5000000,5000000!10
    }

    The commands.cfg is configured
    # 'check_local_mrtgtraf' command definition
    define command{
    command_name check_local_mrtgtraf
    command_line $USER1$/check_mrtgtraf -F $LOGFILE$ -a $ARG1$ -w $ARG3$ -c $ARG4$ -e $ARG5$
    }
     
  16. Mark_NL

    Mark_NL New Member

    What output does this command give you?
    Code:
    ls -al /var/www/html/mymrtg/10.0.1.1_2.log
     
  17. ilyar

    ilyar New Member


    -rw-r--r--. 1 root root 55171 Nov 21 09:40 /var/www/html/mymrtg/10.0.1.1_2.log
     
  18. Mark_NL

    Mark_NL New Member

    What happens when you run the check command from a shell:

    Code:
    /usr/lib/nagios/plugins/check_local_mrtgtraf -F /var/www/html/mymrtg/10.0.1.1_2.log -a AVG -w 1000000,1000000 -c 5000000,5000000 -e 10
     
  19. ilyar

    ilyar New Member


    after I run this i get:

    -bash: /usr/lib/nagios/plugins/check_local_mrtgtraf: No such file or directory

    by the way when i installed nagios i ran this command:

    yum install nagios nagios-devel nagios-plugins* gd gd-devel httpd php gcc glibc glibc-common

    so i am not sure where the plugins are located if they were installed. i believe my nagios is installed in /etc/nagios but i don't see a plugins directory there.

    thanks.
     
  20. Mark_NL

    Mark_NL New Member

    ow damn, the command is wrong, should be "check_mrtgtraf"

    try to cd into /usr/lib/nagios/plugins, does that dir exist?

    find your nagios plugin dir (should be defined in your nagios config somewhere)
    then correct the command to reflect the correct location and run it.
     

Share This Page