Internet, UNIX, Video, Leisure…
Patching Cacti Threshold plugin for Nagios notification
This is the first part of a post about setting up and patching the threshold plugin so it can trigger passive checks into Nagios.
The patch is in the download section here.
First of all, install Cacti. As for now the latest version is 0.8.6j.
Then install the Plugin Architecture for Cacti (some docs here). OK, the website is a crap and not really working either with Firefox or Safari… You can use the menu on the right to reach the downloads.
You just have to untar the file and copy recursively all files in it (according to the same version as Cacti) into Cacti, overwriting existing files.
You can then apply my Ldap patch.
You can also change the config file and define you database name and user. Don’t forget to set the « URL path to cacti » which is introduced by the plugins arch. See config file later in the post.
Then download the Thold (Threshold) plugin and untar it in your « cacti/plugins » directory. Don’t use the version 0.3.5.1 which is online as it apply to a future revision of Cacti and Plugin Architecture. You have to download the version 0.3.4 here.
Then apply the patch.
You can also add more plugins, like Tools Settings , Host Info or Links. If you do so, don’t forget to enable it for each users in the user management page of Cacti.
Then, enable plugins in the config file. Edit file in cacti/include/config.php :
/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "user";
$database_password = "pass";
$database_port = "3306";
$plugins = array();
$plugins[] = 'thold';
$plugins[] = 'update';
$plugins[] = 'hostinfo';
$plugins[] = 'settings';
$plugins[] = 'tools';
$plugins[] = 'dataquery';
$plugins[] = 'links';
$plugins[] = 'weathermap';
/* Do not edit this line */
$config = array();
/*
This is full URL Path to the Cacti installation
For example, if your cacti was accessible by http://server/cacti/ you would user '/cacti/'
as the url path. For just http://server/ use '/'
*/
$config['url_path'] = '/cacti/';
Of course, you already have a working version of Nagios
Once applied, the Nagios patch will give you 2 more things :
- a new config option in the Settings -> Alerting/Thold to enable Nagios or not. Just enable it or not and add the script (shell, perl, python) which will be executed.

For example, my script is like :
# cat /opt/monitor/scripts/cacti-to-nagios.sh
#!/bin/sh
# this script copy the data in argument to the Nagios external command file
NAGIOS_FILE="/opt/monitor/nagios/var/rw/nagios.cmd"
echo $1 >> ${NAGIOS_FILE}
exit 0
- a new parameter for each threshold you define

Here you have to give the name of the Host defined in Nagios, and the name of the Service (with Passive check enabled) in Nagios.
For example, here is the part of my Nagios config :
define service{
use generic-service ; Name of service template to use
host_name antlia
service_description ANTLIA_INODES
is_volatile 0
check_period 24x7
max_check_attempts 1
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_options w,u,c,r
notification_interval 960
notification_period 24x7
active_checks_enabled 0
check_command check_dummy
}
Be carefull of access rights, execution rights and most of all, PHP Safe_Mode or exec_dir.
And there you go !
Maybe next release will allow to change the output line, so it is not bound to Nagios and can be run against any monitoring/alerting software.
Maybe I will also add something so Cacti can send SMS directly : we are using opensource smsd with a SMS modem on a serial port. For now it is Nagios wich is using it. The only gain is that Nagios can do some sort of escalation and schedule, so we only get the SMS during the non working hours. We’ll see
16 novembre 2007 - 04:41
Any chance you will update this for the most current cacti and thold plugins, cacti-0.8.7 and thold-0.3.7 sometime soon?
16 novembre 2007 - 10:32
Yes
Maybe next when I have some time. I don’t know why nobody want’s to add this kind of feature to the main tree… this is simple and pretty usefull.
I let you know as soon as it’s done.
21 novembre 2007 - 17:50
Main reason it has not been added to the main tree is that the future version I am working on makes it completely irrelevant. Thold v1.0 has the option to allow script execution, paging, or anything else (you can write another plugin to hook into thold to add support for whatever you want).
As it is now, the patch is for a specialized use, for people that use nagios. I’m trying not to add too many features to the current stable version until I can start back porting a lot of the neat changes in v1.0.
16 décembre 2007 - 00:20
very interesting, but I don’t agree with you
Idetrorce
8 janvier 2008 - 10:38
many thanks, been looking for something like this.. Have tried to request it many times in the cactiusers forum, they just ignore my post
:p
8 janvier 2008 - 11:51
As you can see in a previous comment from Jimmy, it should be included in the next version.
For the moment it’s still actual.
Thanks for the comment.
19 septembre 2008 - 22:01
Problem: used the latest ver of cacti, skipped the ldap part and downloaded the 0.3.4 Thold version linked above and applied the patch. Results:
1 out of 5 hunks FAILED — saving rejects to file check-thold.php.rej
patching file setup.php
Hunk #1 FAILED at 629.
1 out of 1 hunk FAILED — saving rejects to file setup.php.rej
patching file thold-functions.php
patching file thold.php
Hunk #2 FAILED at 481.
1 out of 2 hunks FAILED — saving rejects to file thold.php.rej
patching file thold_templates.php
Hunk #2 FAILED at 605.
1 out of 2 hunks FAILED — saving rejects to file thold_templates.php.rej
[root@nagios01 thold]# patch -p1 -N < cacti-thold.patch
patching file check-thold.php
Hunk #5 FAILED at 264.
1 out of 5 hunks FAILED — saving rejects to file check-thold.php.rej
patching file setup.php
Hunk #1 FAILED at 629.
1 out of 1 hunk FAILED — saving rejects to file setup.php.rej
patching file thold-functions.php
patching file thold.php
Hunk #2 FAILED at 481.
1 out of 2 hunks FAILED — saving rejects to file thold.php.rej
patching file thold_templates.php
Hunk #2 FAILED at 605.
1 out of 2 hunks FAILED — saving rejects to file thold_templates.php.rej
I manually added the changes to setup.php per the diff. The rest of the failed hunks have .rej files like this:
***************
*** 584,587 ****
print « \n »;
}
- ?>
— 605,608 —-
print « \n »;
}
+ ?>
to me that looks like it’s not intended to be an actual change, but maybe just a code validation check.
The end result is that when I click Data Sources, the rows under the Templates column is no longer a hyperlink.
26 janvier 2009 - 09:54
this post makes it all sound so easy… i know i’m not the only person who couldn’t get the latest nagios, cacti, or thold running without hacking my way through several dozen bugs and installing countless dependencies….
does any of this software actually work for anyone?
imho, the code needs a complete overhaul.
26 janvier 2009 - 10:10
threshold plugin is working fine. Hacking it so it can talk to Nagios was what I needed, and I did it the easyiest way I found.
New releases of Cacti sure break the code given here. I will have a look when I upgrade to new Nagios and new Cacti.
You’re free to re-write the code if you need it
5 août 2010 - 14:46
Thanks for the patch. Despite this being a patch for a much older version of (everything) that I am running, this still doesn’t exist in thold. Hopefully I can scrub it up a tad to make it work for us here.
2 and a half years to add this to main branch?
6 août 2010 - 17:08
People from Cacti, Plugins framework for Cacti and specialy the Threshold plugin dev team DONT WANT to add this feature. They argue they are « in the process or re-writing » the whole thing… In the meantime, 3 years now, you just can’t have this option…
Or you can use my patch, which is not maintained as I’m not using it anymore… (I’m doing something else than monitoring)