Friday, 2 September 2016

Install Nagiosgraph for Nagios Core on CentOS 7

Install Nagiosgraph for Nagios Core on CentOS 7

Nagios Core has limited native support for graphical representation of metrics. Nagiosgraph is very useful plugin, that extends the functionality of Nagios Core and display historical graphs. Nagiosgraph parses output and performance data collected by Nagios and stores that data in RRD (Round Robin Data) files. Nagiosgraph creates graphs and generates HTML pages with graphical reports from the data.

In this article, we will install Nagiosgraph plugin to our preconfigured Nagios Core server on CentOS 7.

Before moving forward, it is required to have basic concepts of Nagios Core 4. Therefore, it is highly recommended that you should have Learning Nagios - Third Edition. It will be really helpful for you during your Nagios journey.

 

System Specification:

We have configured a CentOS 7 virtual machine with Nagios Core 4.2 Server and following specifications.

CPU: 2.4 Ghz (2 Core)
Memory: 1 GB
Storage: 20 GB
Swap: 2 GB
Operating System: CentOS 7.6
Nagios Version: Nagios Core 4.4

Read Also: Install & Configure Nagios Core 4.4 on CentOS 7
  Install & Configure Nagios Core 4.2 on CentOS 6

 

Install Nagiosgraph on CentOS 7:

Access the Nagios Core’s web interface to check its status.

Nagios Core - Current Network Status

Install the prerequisite packages using yum command.

[root@nagios01 nagios]# yum -y install perl-GD php-gd rrdtool-perl rrdtool-php rrdtool perl-CGI perl-Time-HiRes

Create a directory and download Nagiosgraph 1.5.2 (the latest version at the time of this writeup) from Nagiosgraph - Official Page.

[root@nagios01 ~]# mkdir -p /soft/nagios [root@nagios01 ~]# cd /soft/nagios [root@nagios01 nagios]# wget https://sourceforge.net/projects/nagiosgraph/files/nagiosgraph/1.5.2/nagiosgraph-1.5.2.tar.gz

Extract the contents of Nagiosgraph tarball.

[root@nagios01 ~]# cd /soft/nagios [root@nagios01 nagios]# tar xvf nagiosgraph-1.5.2.tar.gz

Check prerequisites and install Nagiosgraph.

[root@nagios01 nagios]# cd /soft/nagios/nagiosgraph-1.5.2 [root@nagios01 nagiosgraph-1.5.2]# ./install.pl --check-prereq [root@nagios01 nagiosgraph-1.5.2]# ./install.pl --layout overlay --prefix /usr/local/nagios

During the installation, set the paths as follows:
(If you define the paths correctly, then most of the configurations will be automatically make by Nagiosgraph installer)

Destination directory (prefix)? [/usr/local/nagios] Location of configuration files (etc-dir)? [/usr/local/nagios/etc/nagiosgraph] Location of executables? [/usr/local/nagios/libexec] Location of CGI scripts? [/usr/local/nagios/sbin] Location of documentation (doc-dir)? [/usr/local/nagios/docs/nagiosgraph] Location of examples? [/usr/local/nagios/docs/nagiosgraph/examples] Location of CSS and JavaScript files? [/usr/local/nagios/share] Location of utilities? [/usr/local/nagios/docs/nagiosgraph/util] Location of state files (var-dir)? [/var/nagios] /usr/local/nagios/var Location of RRD files? [/usr/local/nagios/var/rrd] Location of log files (log-dir)? [/var/nagios] /usr/local/nagios/var Path of log file? [/usr/local/nagios/var/nagiosgraph.log] Path of CGI log file? [/usr/local/nagios/var/nagiosgraph-cgi.log] Base URL? [/nagios] URL of CGI scripts? [/nagios/cgi-bin] URL of CSS file? [/nagios/nagiosgraph.css] URL of JavaScript file? [/nagios/nagiosgraph.js] URL of Nagios CGI scripts? [/nagios/cgi-bin] Path of Nagios performance data file? [/tmp/perfdata.log] /usr/local/nagios/var/service-perfdata.log username or userid of Nagios user? [nagios] username or userid of web server user? [apache]

Edit /usr/local/nagios/etc/nagios.cfg file and comment (#) all the performance related parameters.

[root@nagios01 nagiosgraph-1.5.2]# vi /usr/local/nagios/etc/nagios.cfg

Set following parameters, to enable Nagios to keep history of performance data.

# process nagios performance data using nagiosgraph process_performance_data=1 service_perfdata_file=/usr/local/nagios/var/service-perfdata.log service_perfdata_file_template=$LASTSERVICECHECK$||$HOSTNAME$||$SERVICEDESC$||$SERVICEOUTPUT$||$SERVICEPERFDATA$ service_perfdata_file_mode=a service_perfdata_file_processing_interval=30 service_perfdata_file_processing_command=process-service-perfdata-for-nagiosgraph

Edit /usr/local/nagios/etc/objects/commands.cfg.

[root@nagios01 nagiosgraph-1.5.2]# vi /usr/local/nagios/etc/objects/commands.cfg

Add following command to to enable storage of performance metrics.

define command { command_name process-service-perfdata-for-nagiosgraph command_line /usr/local/nagios/libexec/insert.pl }

Check Nagios configurations now.

[root@nagios01 nagiosgraph-1.5.2]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg Nagios Core 4.2.0 Copyright (c) 2009-present Nagios Core Development Team and Community Contributors Copyright (c) 1999-2009 Ethan Galstad Last Modified: 08-01-2016 License: GPL Website: https://www.nagios.org Reading configuration data... Read main config file okay... Read object config files okay... Running pre-flight check on configuration data... Checking objects... Checked 8 services. Checked 1 hosts. Checked 1 host groups. Checked 0 service groups. Checked 1 contacts. Checked 1 contact groups. Checked 25 commands. Checked 5 time periods. Checked 0 host escalations. Checked 0 service escalations. Checking for circular paths... Checked 1 hosts Checked 0 service dependencies Checked 0 host dependencies Checked 5 timeperiods Checking global event handlers... Checking obsessive compulsive processor commands... Checking misc settings... Total Warnings: 0 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check [root@nagios01 nagiosgraph-1.5.2]#

Restart nagios and httpd services to reload new configurations.

[root@nagios01 nagiosgraph-1.5.2]# systemctl restart nagios [root@nagios01 nagiosgraph-1.5.2]# systemctl restart httpd

Open URL  http://192.168.229.129/nagios/cgi-bin/showconfig.cgi in the browser, to see the configurations. (Replace the IP address in the URL, with your CentOS 7 Server IP address).

Nagios Core Configurations - showconfig.cgi

You can see that Nagiosgraph has been integrated with Nagios Core.

Edit /usr/local/nagios/etc/objects/templates.cfg file.

[root@nagios01 nagiosgraph-1.5.2]# vi /usr/local/nagios/etc/objects/templates.cfg

Add following code to define a service graphed-service to be used to display Nagiosgraph graphs.

define service { name graphed-service action_url /nagios/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&period=week&rrdopts=-w+450+-j register 0 }

And append graphed-service in use parameter of the services, for which you want to draw graphs. We have added it to some services, one service syntax is given below for reference.

define service{ use local-service,graphed-service ; Name of service template to use host_name localhost service_description HTTP check_command check_http notifications_enabled 0 }

Restart nagios service.

[root@nagios01 nagiosgraph-1.5.2]# systemctl restart nagios

Now, open the Nagios web interface in browser, you may see the small graph icon infront of the services for which you have enabled graphs.

Nagios Core Current Network Status with Nagiosgraph Icons

Click on the graph icon to open graphs’ page.

Nagiosgraph Details Webpage

Adjust the parameters on the top right side panel to draw graphs according to your needs.

We have successfully installed Nagiosgraph plugin for Nagios Core on CentOS 7. PNP4Nagios is another addon to display graphs in Nagios Core server. You might like our next article Install PNP4Nagios on Nagios Core over CentOS 7.

Install Nagiosgraph for Nagios Core on CentOS 7


YOU MIGHT ALSO LIKE:

28 comments:

  1. Hi! I'm stuck on the step:
    "Execute http://192.168.229.129/nagios/cgi-bin/showconfig.cgi in the browser to see, the configurations."

    The next message appear on webrowser:
    "Forbidden

    You don't have permission to access /nagiosgraph/cgi-bin/showconfig.cgi on this server."

    can someone help me please?

    ReplyDelete
    Replies
    1. Please ensure the Directory /nagiosgraph/cgi-bin/ has necessary permissions in Apache Configurations. Also check the OS Level File/Folder permissions and SELinux fcontexts.

      Delete
  2. Hello,
    I'm getting the following error.

    No data in rrd directory /usr/local/nagios/var/rrd

    ReplyDelete
  3. Hello,
    I'm getting the following error, after install while to trying access a graph.

    ReplyDelete
    Replies
    1. Pls verify that the Parameter process_performance_data=1 is defined only once in the nagios.cfg.

      Delete
  4. process_performance_data=1 is only defined once in nagios.cfg. The original is comments out. I can send you a copy of my nagios.cfg

    ReplyDelete
  5. great Sir, Thanks alot for your blog.

    ReplyDelete
  6. i monitor the remote linux host with using nrpe. The graph is empty for cpu only. The graph show for memory. how should i do? Thanks Sir

    ReplyDelete
    Replies
    1. Hi naylinn, You should recheck the above steps. May be you have missed something.

      Delete
  7. I receive the error graphed-service not define? How can I solve it? Thanks sir!

    ReplyDelete
    Replies
    1. Thanks for highlighting the problem. I have updated the Post and added another step to define the graphed-service therein. Hopefully, it will resolve the error.

      Delete
  8. Hi..
    I'm getting the following error [nagios::config Fail]

    OS -- Centos 6.9Final

    ReplyDelete
    Replies
    1. Hi Chethan. Above error is not enough to troubleshoot the issue. Please give the complete error log.

      Delete
  9. Ahmer,

    Thanks for your documentation, it prooved to be rather helpful.

    Thanks very much.

    Alex

    ReplyDelete
    Replies
    1. Hi Alex,

      I am glad that, this post is useful for you.
      Thanks for appreciation.

      Delete
  10. hello, i have followed all the steps but when i open nagios i don't have any graphic icon in front of each service. any idea? i have installed nagios 4.4.2

    ReplyDelete
  11. Hi Ahmer, thanks for your job! i have installed nagios 4.4.2. I followed all steps above but when i open my web-interface, i'm not able to see any graphic icon in front of each service. Do you have any idea?
    Thanks

    ReplyDelete
    Replies
    1. Hi Pedro,
      Thanks for appreciation.
      I suggest you to please recheck above steps. Besides that for Nagios 4.4.2, you should visit nagiosgraph official website.

      Delete
  12. I am a little bit confused here (new to Nagios)

    Edit /usr/local/nagios/etc/objects/templates.cfg file.
    vi /usr/local/nagios/etc/objects/templates.cfg
    Define a service graphed-service to be used to display Nagiosgraph graphs.

    What do you enter in templates.cfg ?

    ReplyDelete
    Replies
    1. Hi,
      Thanks for highlighting this drafting mistake.
      Post has been corrected accordingly.

      Delete
  13. hello sir i am getting miss configuration error on browser and getting below mentioned error in logs and please suggest me :

    [Wed Dec 26 13:11:22.928377 2018] [cgi:error] [pid 9112] [client 192.168.43.17:63406] AH01215: Can't locate RRDs.pm in @INC (@INC contains: /usr/local/nagios/etc/nagiosgraph /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/nagios/etc/nagiosgraph/ngshared.pm line 30., referer: http://192.168.43.10/nagios/cgi-bin/status.cgi?host=all
    [Wed Dec 26 13:11:22.928454 2018] [cgi:error] [pid 9112] [client 192.168.43.17:63406] AH01215: BEGIN failed--compilation aborted at /usr/local/nagios/etc/nagiosgraph/ngshared.pm line 30., referer: http://192.168.43.10/nagios/cgi-bin/status.cgi?host=all
    [Wed Dec 26 13:11:22.928484 2018] [cgi:error] [pid 9112] [client 192.168.43.17:63406] AH01215: Compilation failed in require at /usr/local/nagios/sbin/show.cgi line 12., referer: http://192.168.43.10/nagios/cgi-bin/status.cgi?host=all
    [Wed Dec 26 13:11:22.928515 2018] [cgi:error] [pid 9112] [client 192.168.43.17:63406] AH01215: BEGIN failed--compilation aborted at /usr/local/nagios/sbin/show.cgi line 12., referer: http://192.168.43.10/nagios/cgi-bin/status.cgi?host=all
    [Wed Dec 26 13:11:22.929567 2018] [cgi:error] [pid 9112] [client 192.168.43.17:63406] End of script output before headers: show.cgi, referer: http://192.168.43.10/nagios/cgi-bin/status.cgi?host=all

    ReplyDelete
    Replies
    1. You might have missed prerequisites. Please install rrdtool & rrdtool-perl packages and check again.

      Delete
  14. hi Sir,
    I am getting a Nagios graph errors.
    JavaScript is disabled.
    nagiosgraph.js is not installed or wrong version.

    for that no data populating on graphs.

    Thanks
    Laggoni

    ReplyDelete
    Replies
    1. Please check:
      Is JavaScript enabled in Browser?
      Is nagiosgraph.js exist at /usr/local/nagios/share?

      Delete