From 0e9c1c4a02058830470824c4a570bf597d58e263 Mon Sep 17 00:00:00 2001 From: thurban Date: Fri, 31 Jan 2020 13:16:37 +0100 Subject: [PATCH 1/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f916ec3..afc63e4 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ See COPYING for the license under which php-weathermap is released. There is much more information, tutorials and updates available at: http://www.network-weathermap.com/ -*IMPORTANT NOTE*: This version only works with Cacti 0.8.8 (not 1.x.x) +*IMPORTANT NOTE*: This version only works with Cacti 1.x.x ------ From 646b91783520cd8beea5b2b36af58fab17ae0668 Mon Sep 17 00:00:00 2001 From: James Tate II Date: Thu, 9 Apr 2020 14:26:13 -0400 Subject: [PATCH 2/7] fixed schema in WeatherMapDataSource_cactithold.php to use new fields. rra_id -> local_data_id data_id -> data_template_rrd_id --- lib/datasources/WeatherMapDataSource_cactithold.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/datasources/WeatherMapDataSource_cactithold.php b/lib/datasources/WeatherMapDataSource_cactithold.php index 764e03a..22977e5 100644 --- a/lib/datasources/WeatherMapDataSource_cactithold.php +++ b/lib/datasources/WeatherMapDataSource_cactithold.php @@ -106,10 +106,10 @@ function ReadData($targetstring, &$map, &$item) // use target aggregation to build these up into a 'badness' percentage // takes the same two values that are visible in thold's own URLs (the actual thold ID isn't shown anywhere) - $rra_id = intval($matches[1]); - $data_id = intval($matches[2]); + $local_data_id = intval($matches[1]); + $data_template_rrd_id = intval($matches[2]); - $SQL2 = "select thold_alert from thold_data where rra_id=$rra_id and data_id=$data_id and thold_enabled='on'"; + $SQL2 = "select thold_alert from thold_data where local_data_id=$local_data_id and data_template_rrd_id=$data_template_rrd_id and thold_enabled='on'"; $result = db_fetch_row($SQL2); if(isset($result)) { @@ -179,13 +179,13 @@ function ReadData($targetstring, &$map, &$item) wm_debug("CactiTHold ReadData: Checking threshold states for host $id\n"); $numthresh = 0; $numfailing = 0; - $SQL2 = "select rra_id, data_id, thold_alert from thold_data,data_local where thold_data.rra_id=data_local.id and data_local.host_id=$id and thold_enabled='on'"; + $SQL2 = "select local_data_id, data_template_rrd_id, thold_alert from thold_data,data_local where thold_data.local_data_id=data_local.id and data_local.host_id=$id and thold_enabled='on'"; # $result = db_fetch_row($SQL2); $queryrows = db_fetch_assoc($SQL2); if( is_array($queryrows) ) { foreach ($queryrows as $th) { - $desc = $th['rra_id']."/".$th['data_id']; + $desc = $th['local_data_id']."/".$th['data_template_rrd_id']; $v = $th['thold_alert']; $numthresh++; if(intval($th['thold_alert']) > 0) From e2ad9f8689139bc5e972d8e8f3bc5c0b93f684c9 Mon Sep 17 00:00:00 2001 From: James Tate II Date: Tue, 14 Apr 2020 15:01:45 -0400 Subject: [PATCH 3/7] added printf arguments to the -f CLI argument of rrdtool to resolve bug in rrdtool version 1.4.8. rrdtool-1.4.8 is the version on RHEL7. This version enforces the three printf arguments being present in the fromat string. See: https://forum.network-weathermap.com/t/rrdtool-aggregate-target-has-no-valid-data-after-move-to-github-version/76/5 https://oss.oetiker.ch/rrdtool/doc/rrdgraph.en.html --- lib/datasources/WeatherMapDataSource_rrd.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/datasources/WeatherMapDataSource_rrd.php b/lib/datasources/WeatherMapDataSource_rrd.php index 9d6327d..8208e99 100644 --- a/lib/datasources/WeatherMapDataSource_rrd.php +++ b/lib/datasources/WeatherMapDataSource_rrd.php @@ -244,7 +244,7 @@ function wmrrd_read_from_real_rrdtool_aggregate($rrdfile,$cf,$aggregatefn,$start $args[] = "graph"; $args[] = "/dev/null"; $args[] = "-f"; - $args[] = "''"; + $args[] = "'%s %lu %lu'"; $args[] = "--start"; $args[] = $start; $args[] = "--end"; From d59c6c676b2114b674f39339f57970ec0233d529 Mon Sep 17 00:00:00 2001 From: thurban Date: Fri, 17 Apr 2020 10:15:14 +0200 Subject: [PATCH 4/7] Added default values for weathermap_data table This fixes the #1 issue --- setup.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/setup.php b/setup.php index f86a44e..ebc9b79 100644 --- a/setup.php +++ b/setup.php @@ -367,11 +367,20 @@ function weathermap_setup_table() } if ( !in_array( 'weathermap_data', $tables ) ) { - $sql[] = "CREATE TABLE IF NOT EXISTS weathermap_data (id int(11) NOT NULL auto_increment, - rrdfile varchar(255) NOT NULL,data_source_name varchar(19) NOT NULL, - last_time int(11) NOT NULL,last_value varchar(255) NOT NULL, - last_calc varchar(255) NOT NULL, sequence int(11) NOT NULL, local_data_id int(11) NOT NULL DEFAULT 0, PRIMARY KEY (id), KEY rrdfile (rrdfile), - KEY local_data_id (local_data_id), KEY data_source_name (data_source_name) ) ENGINE=MyISAM"; + $sql[] = "CREATE TABLE IF NOT EXISTS weathermap_data ( + id int(11) NOT NULL auto_increment, + rrdfile varchar(255) NOT NULL, + data_source_name varchar(19) NOT NULL, + last_time int(11) NOT NULL DEFAULT -1, + last_value varchar(255) NOT NULL DEFAULT '', + last_calc varchar(255) NOT NULL DEFAULT '', + sequence int(11) NOT NULL DEFAULT 0, + local_data_id int(11) NOT NULL DEFAULT 0, + PRIMARY KEY (id), + KEY rrdfile (rrdfile), + KEY local_data_id (local_data_id), + KEY data_source_name (data_source_name) + ) ENGINE=MyISAM"; } else { $stmt = $pdo->prepare( "show columns from weathermap_data" ); $stmt->execute(); From 693f840e8507928b8de3b3a98b65203c4a050dae Mon Sep 17 00:00:00 2001 From: thurban Date: Fri, 17 Apr 2020 10:18:16 +0200 Subject: [PATCH 5/7] Added default value for last_value The last_value was not being filled with a default value, causing an issue during inserts. --- lib/datasources/WeatherMapDataSource_rrd.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/datasources/WeatherMapDataSource_rrd.php b/lib/datasources/WeatherMapDataSource_rrd.php index 8208e99..8129033 100644 --- a/lib/datasources/WeatherMapDataSource_rrd.php +++ b/lib/datasources/WeatherMapDataSource_rrd.php @@ -139,8 +139,8 @@ function wmrrd_read_from_poller_output($rrdfile,$cf,$start,$end,$dsnames, &$data // Include the local_data_id as well, to make life easier in poller_output // (and to allow the cacti: DS plugin to use the same table, too) wm_debug("RRD ReadData: poller_output - Adding new weathermap_data row for data source ID " . $result['local_data_id'] . "\n"); - $statement_insert = $pdo->prepare("INSERT INTO weathermap_data (rrdfile, data_source_name, sequence, local_data_id) VALUES (?,?, 0,?)"); - $statement_insert->execute(array($db_rrdname, $dsnames[$dir], $result['local_data_id'])); + $statement_insert = $pdo->prepare("INSERT INTO weathermap_data (rrdfile, data_source_name, sequence, local_data_id, last_value) VALUES (?,?, 0,?,'')"); + $statement_insert->execute(array($db_rrdname, $dsnames[$dir], $result['local_data_id'])); // $SQLins = "insert into weathermap_data (rrdfile, data_source_name, sequence, local_data_id) values ('".mysql_real_escape_string($db_rrdname)."','".mysql_real_escape_string($dsnames[$dir])."', 0,".$result['local_data_id'].")"; // db_execute($SQLins); From 0ae51af13b11381a6f87741a2883b165f5d20a19 Mon Sep 17 00:00:00 2001 From: thurban Date: Fri, 17 Apr 2020 10:51:49 +0200 Subject: [PATCH 6/7] Changed default button to enable_icon.png button_go.gif has been removed from Cacti 1.x therefore changing to enable_icon.png as recommended by issue #2 --- weathermap-cacti-plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weathermap-cacti-plugin.php b/weathermap-cacti-plugin.php index a148627..f71195c 100644 --- a/weathermap-cacti-plugin.php +++ b/weathermap-cacti-plugin.php @@ -799,7 +799,7 @@ function weathermap_mapselector( $current_id = 0 ) } ?> -   From d276197434dd9f74898acf2c401c42db3bd6f9f4 Mon Sep 17 00:00:00 2001 From: thurban Date: Thu, 23 Apr 2020 08:08:40 +0200 Subject: [PATCH 7/7] Escaped column names for weathermap_data table creation The last_value column name is also a special keyword in MySQL. All column names have been escaped for table creation. last_value column name has been escaped in update statements --- setup.php | 66 +++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/setup.php b/setup.php index ebc9b79..2eca5b5 100644 --- a/setup.php +++ b/setup.php @@ -277,21 +277,21 @@ function weathermap_setup_table() if ( !in_array( 'weathermap_maps', $tables ) ) { $sql[] = "CREATE TABLE weathermap_maps ( - id int(11) NOT NULL auto_increment, - sortorder int(11) NOT NULL default 0, - group_id int(11) NOT NULL default 1, - active set('on','off') NOT NULL default 'on', - configfile text NOT NULL, - imagefile text NOT NULL, - htmlfile text NOT NULL, - titlecache text NOT NULL, - filehash varchar (40) NOT NULL default '', - warncount int(11) NOT NULL default 0, - config text NOT NULL, - thumb_width int(11) NOT NULL default 0, - thumb_height int(11) NOT NULL default 0, - schedule varchar(32) NOT NULL default '*', - archiving set('on','off') NOT NULL default 'off', + `id` int(11) NOT NULL auto_increment, + `sortorder` int(11) NOT NULL default 0, + `group_id` int(11) NOT NULL default 1, + `active` set('on','off') NOT NULL default 'on', + `configfile` text NOT NULL, + `imagefile` text NOT NULL, + `htmlfile` text NOT NULL, + `titlecache` text NOT NULL, + `filehash` varchar (40) NOT NULL default '', + `warncount` int(11) NOT NULL default 0, + `config` text NOT NULL, + `thumb_width` int(11) NOT NULL default 0, + `thumb_height` int(11) NOT NULL default 0, + `schedule` varchar(32) NOT NULL default '*', + `archiving` set('on','off') NOT NULL default 'off', PRIMARY KEY (id) ) ENGINE=MyISAM;"; } else { @@ -335,12 +335,12 @@ function weathermap_setup_table() } } - $sql[] = "update weathermap_maps set filehash=LEFT(MD5(concat(id,configfile,rand())),20) where filehash = '';"; + $sql[] = "update weathermap_maps set `filehash`=LEFT(MD5(concat(id,configfile,rand())),20) where `filehash` = '';"; if ( !in_array( 'weathermap_auth', $tables ) ) { $sql[] = "CREATE TABLE weathermap_auth ( - userid mediumint(9) NOT NULL default '0', - mapid int(11) NOT NULL default '0' + `userid` mediumint(9) NOT NULL default '0', + `mapid` int(11) NOT NULL default '0' ) ENGINE=MyISAM;"; } @@ -357,27 +357,27 @@ function weathermap_setup_table() if ( !in_array( 'weathermap_settings', $tables ) ) { $sql[] = "CREATE TABLE weathermap_settings ( - id int(11) NOT NULL auto_increment, - mapid int(11) NOT NULL default '0', - groupid int(11) NOT NULL default '0', - optname varchar(128) NOT NULL default '', - optvalue varchar(128) NOT NULL default '', + `id` int(11) NOT NULL auto_increment, + `mapid` int(11) NOT NULL default '0', + `groupid` int(11) NOT NULL default '0', + `optname` varchar(128) NOT NULL default '', + `optvalue` varchar(128) NOT NULL default '', PRIMARY KEY (id) ) ENGINE=MyISAM;"; } if ( !in_array( 'weathermap_data', $tables ) ) { $sql[] = "CREATE TABLE IF NOT EXISTS weathermap_data ( - id int(11) NOT NULL auto_increment, - rrdfile varchar(255) NOT NULL, - data_source_name varchar(19) NOT NULL, - last_time int(11) NOT NULL DEFAULT -1, - last_value varchar(255) NOT NULL DEFAULT '', - last_calc varchar(255) NOT NULL DEFAULT '', - sequence int(11) NOT NULL DEFAULT 0, - local_data_id int(11) NOT NULL DEFAULT 0, + `id` int(11) NOT NULL auto_increment, + `rrdfile` varchar(255) NOT NULL, + `data_source_name` varchar(19) NOT NULL, + `last_time` int(11) NOT NULL DEFAULT -1, + `last_value` varchar(255) NOT NULL DEFAULT '', + `last_calc` varchar(255) NOT NULL DEFAULT '', + `sequence` int(11) NOT NULL DEFAULT 0, + `local_data_id` int(11) NOT NULL DEFAULT 0, PRIMARY KEY (id), - KEY rrdfile (rrdfile), + KEY rrdfile (rrdfile(250)), KEY local_data_id (local_data_id), KEY data_source_name (data_source_name) ) ENGINE=MyISAM"; @@ -742,7 +742,7 @@ function weathermap_poller_output( $rrd_update_array ) break; } } - db_execute( "UPDATE weathermap_data SET last_time=$newtime, last_calc='$newvalue', last_value='$newlastvalue',sequence=sequence+1 where id = " . $required[ 'id' ] ); + db_execute( "UPDATE weathermap_data SET `last_time`=$newtime, `last_calc`='$newvalue', `last_value`='$newlastvalue',`sequence`=`sequence`+1 where `id` = " . $required[ 'id' ] ); if ( $logging >= POLLER_VERBOSITY_DEBUG ) cacti_log( "WM poller_output: Final value is $newvalue (was $lastval, period was $period)\n", TRUE, "WEATHERMAP" ); } else { if ( 1 == 0 && $logging >= POLLER_VERBOSITY_DEBUG ) {