Error: A template with that Data Source already exists!

Support questions about the Threshold plugin

Moderators: Developers, Moderators

Post Reply
etienne66
Posts: 38
Joined: Wed Apr 19, 2006 12:26 pm

Error: A template with that Data Source already exists!

Post by etienne66 »

I just installed the Threshold plugin for the umpteenth time. I keep getting "Error: A template with that Data Source already exists!" when trying to add a new template on the thold_templates.php page. I have tracked down the line that writes the error to line 192 of that file. I decided to turn on logging on MySQL and found the offending query was

Code: Select all

INSERT INTO thold_template (data_template_id,data_template_name,data_source_id,data_source_name,data_source_friendly,thold_enabled,bl_enabled,repeat_alert,notify_default) VALUES ("51","Generic - Uptime","309","uptime","uptime","on","off","12","NULL")
When executed in the query analyzer it returns "Data truncated for column 'notify_default' at row 1 Error 1265"

The problem is that NULL value is actually a text string and 'notify_default' is a boolean field.

The query should be

Code: Select all

INSERT INTO thold_template (data_template_id,data_template_name,data_source_id,data_source_name,data_source_friendly,thold_enabled,bl_enabled,repeat_alert,notify_default) VALUES ("51","Generic - Uptime","309","uptime","uptime","on","off","12",NULL)
So the real culprit is in either line 185 or 186

Code: Select all

		$save["notify_default"] = "NULL";
		$id = sql_save($save, "thold_template");
I don't know if it is a problem in the declaration of 'notify_default' or in the sql_save function. If I change line 185 to

Code: Select all

$save["notify_default"] = NULL;
It sends a null string, "", instead of a NULL value. So I suspect that it is a problem with database.php on line 220 to 222

Code: Select all

	while (list ($key, $value) = each ($array_items)) {
		$array_items[$key] = "\"" . sql_sanitize($value) . "\"";
	}
This section of code appears to put quotes around every value, so how are you supposed to set something to a true NULL value?

There are several other places in the Threshold plugin that try to use sql_save to set a NULL value and would need to be addressed as well.

I am surpirsed that I have seen no one else mentioning this problem. Perhaps it is just me and some setting I have wrong?

Thanks,
Etienne
Cacti Version - 0.8.6j
Plugin Architecture - 1.1
Poller Type - Cactid v0.8.6i
Server Info - Windows NT 5.1 (aka Windows XP SP2)
Web Server - Microsoft-IIS/5.1
PHP - 5.2.0
PHP Extensions - bcmath, calendar, com_dotnet, ctype, session, filter, ftp, hash, iconv, json, odbc, pcre, Reflection, date, libxml, standard, tokenizer, zlib, SimpleXML, dom, SPL, wddx, xml, xmlreader, xmlwriter, ISAPI, gd, mysql, snmp, sockets
MySQL - 5.0.27-community-nt-log
RRDTool - 1.2.15
SNMP - 5.2.2
Plugins
  • Thresholds (thold - v0.3.2)
    Host Info (hostinfo - v0.1)
etienne66
Posts: 38
Joined: Wed Apr 19, 2006 12:26 pm

Post by etienne66 »

Submitted Bug Report 74
etienne66
Posts: 38
Joined: Wed Apr 19, 2006 12:26 pm

Possible solution

Post by etienne66 »

I seriously doubt that everyone is having this problem, but I wonder if it is just a windows issue. At any rate I implemented my own workaround, but it isn't in the Threshold plugin.
In database.php on line 220 to 222

Code: Select all

   while (list ($key, $value) = each ($array_items)) { 
      $array_items[$key] = "\"" . sql_sanitize($value) . "\""; 
   }
Changing it to the following resolves the problem for me.

Code: Select all

	while (list ($key, $value) = each ($array_items)) {
		if ($array_items[$key] != "NULL") {
			$array_items[$key] = "\"" . sql_sanitize($value) . "\"";
		}
	}
Should I create a bug report for Cati itself? Is this a viable soution or should something else be changed? Is anyone else experiencing this problem and if so what is your envionement (i.e. OS, PHP version, etc...)?

Thanks,
Etienne
luckyksc
Posts: 22
Joined: Tue Apr 19, 2005 5:24 pm

Post by luckyksc »

Thanks etienne66, I thought you put it as a bug but didn't read on that you had a temp. solution. I have window too and upgrade it to the lastest version and plugin architecture 1.1 with thold 3.2 and I had the same error msg. But just changing the database.php file did work.

Thanks,
Luckyksc
Bazou
Posts: 28
Joined: Tue Apr 10, 2007 7:45 am
Location: Brussels/Belgium

Post by Bazou »

Hi everyone,

same error here. I changed the database.php as mentionned but didn't work.


My Linux server is running:

Code: Select all

Cacti Version - 0.8.6i
Plugin Architecture - 1.1 
Poller Type - cmd.php
Server Info - GNU/Debian stable
Web Server - Apache 2.2.3
PHP - 4.4.4-8+etch4 
MySQL - 5.0.32-Debian_7etch1-log 
RRDTool - 1.2.15 
SNMP - 5.2.3
Plugins
Thresholds (thold - v0.3.4) 
On the thresholds page the host status are correctly shown.

Can please anyone help me to create some thresholds?

Thanks,

Gilles
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests