Easily link to Cacti or Perfparse graphs from Nagios
Nagios (http://www.nagios.org) is a great network monitoring tool. Cacti (http://www.cacti.net) is a great network graphing tool. Perfparse (http://perfparse.sourceforge.net/ is a great add-on to Nagios that collects host performance data as part of the Nagios check command. Perfparse is great at collecting performance data when you are running Nagios client software, but short of doing a lot of SNMP MIB and OID tweaking, it is easier to use Cacti to collect performance data on devices where you can’t run Nagios client software (on routers, switches or network appliances for example). But, having three different user interfaces can be annoying. I wanted a way to to link to the Cacti and Perfparse graphs for a host or device directly from Nagios using the Notes URL without having to enter a unique URL for each host or device. I created a PHP script to handle Cacti, and entered the URL for the scripts in the Notes URL in the Nagios configuration (extended information templates). In the extended information templates for Cacti hosts I entered:
http://yourhost/nagtocacti.php?hostip=$HOSTADDRESS$&hostname=$HOSTNAME$
And in the extended information template for Perfparse hosts I entered:
http://yourhost/path-to/perfparse.cgi?select_metric=1&host_name=$HOSTNAME$
This procedure assumes you have Nagios, Perfparse and Cacti installed on the same host, and that you have saved the code below in the web root of that server as nagtocacti.php and modified the dbhost, dbname, dbuser and dbpass values to match your environment.

Hello Mike:
I have been trying to use your php script but I keep getting an error in lines 20 and 32. There seems to be e problem with the ‘\’ characters or the ‘”‘ characters. I have no experience with php so if you have any tips on how to fix this I appreciate it. The errors are:
Warning: Unexpected character in input: ‘\’ (ASCII=92) state=1 in /usr/local/nagios/share/cacti/nagtocacti.php on line 20
Warning: Unexpected character in input: ‘\’ (ASCII=92) state=1 in /usr/local/nagios/share/cacti/nagtocacti.php on line 20
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /usr/local/nagios/share/cacti/nagtocacti.php on line 20
By the way I have intalled the script in the /usr/local/nagios/share/cacti directory that means that my cacti console is accessed in address:
http://localhost/nagios/cacti/
Do I have to change line 20 to fix this also??
Thanks
Marco
Marco,
I suggest you check your main Nagios configuration file to see if that character is allowed (see below excerpt from configuration file documentation):
Illegal Macro Output Characters
Format: illegal_macro_output_chars=
Example: illegal_macro_output_chars=`~$^&”|’
This option allows you to specify illegal characters that should be stripped from macros before being used in notifications, event handlers, and other commands. This DOES NOT affect macros used in service or host check commands. You can choose to not strip out the characters shown in the example above, but I recommend you do not do this. Some of these characters are interpreted by the shell (i.e. the backtick) and can lead to security problems.
You would need to confirm the backslash is allowed and restart nagios. Let me know whether that helps or not (but I believe it will).
Mike