THold Legend and HRULEs

Support questions about the Threshold plugin

Moderators: Developers, Moderators

Post Reply
User avatar
jt555
Cacti User
Posts: 56
Joined: Sat Nov 17, 2007 3:37 pm
Location: Atlanta, Ga

THold Legend and HRULEs

Post by jt555 »

I modified rrd.php so that if there is an associated thold then it will be displayed as a legend and hrules.

It's some of the first php I ever wrote. I'm sure there is a better way to do this but once it suited my needs I stopped working on it.


around line 718:

Code: Select all

/* need to suppress if is an aggregate graph ($graph["host_id"] != 0) */
	if ($graph["host_id"] != 0){
		$sql = "SELECT DISTINCT 
					graph_templates_item.local_graph_id, 
					data_template_rrd.id as data_template_rrd_id, 
					data_template_rrd.local_data_id, 
					data_template_rrd.data_source_name,
					thold_data.id as thold_id, thold_data.thold_hi, thold_data.thold_low 
				FROM data_template_rrd, graph_templates_item, thold_data
				WHERE graph_templates_item.local_graph_id = $local_graph_id
				AND data_template_rrd.id = thold_data.data_id
				AND thold_data.rra_id=data_template_rrd.local_data_id
				AND graph_templates_item.task_item_id = data_template_rrd.id LIMIT 1";
				
		$aaThold = db_fetch_assoc($sql);
		 if (isset($aaThold[0]['local_data_id'])){
			$commenthead = "Thresholds for " . $aaThold[0]['data_source_name'] . "\:\\n\"";			
			 if (is_numeric($aaThold[0]['thold_hi'])){	
				$graph_tholds  = RRD_NL . "COMMENT:\"\\n\"" . RRD_NL . "COMMENT:\" \\n\"" . RRD_NL . "COMMENT:\"$commenthead";
				$graph_tholds .= RRD_NL . "COMMENT:\" \"";
				
				if (is_numeric($aaThold[0]['thold_hi'])){
					$graph_tholds .= RRD_NL . "HRULE:" . $aaThold[0]['thold_hi']  . "#FF0000FF:\"High\: " . $aaThold[0]['thold_hi'] . "\\n\"";
				}
				
				$graph_tholds .= RRD_NL . "COMMENT:\" \"" . RRD_NL;
				
				if (is_numeric($aaThold[0]['thold_low'])){
					$graph_tholds .= "HRULE:" . $aaThold[0]['thold_low'] . "#0000FFFF:\"Low\:  " . $aaThold[0]['thold_low']  . "\"" . RRD_NL;
				}
				
			}else{
				$graph_tholds .= RRD_NL .  "COMMENT:\"thold fail\"" . RRD_NL;
			}
		}else{
			//debug //$graph_tholds .= RRD_NL .  "COMMENT:\"($datatemplaterrdid)\"" . RRD_NL;
		}

	}
	//$graph_tholds .= RRD_NL . "COMMENT:\"(lgi\:$local_graph_id, dtri\:" . $aaThold[0]["data_template_rrd_id"] . ", ldi\:" . $aaThold[0]["local_data_id"] . ", thi\:" . $aaThold[0]["thold_id"] . ")\"" . RRD_NL;


and line 1208:

Code: Select all

		//thold hrules
		$txt_graph_items .= $graph_tholds;
Attachments
Thold Legend Example
Thold Legend Example
watts-thold.png (23.48 KiB) Viewed 3404 times
weetos
Posts: 11
Joined: Tue Jul 15, 2008 9:47 am

Re: THold Legend and HRULEs

Post by weetos »

Just my two cents :

As is, threshold HRULES are displayed to all users, despite the fact some of them may not have the permission to display thresholds (See User Management > Realm Permissions > Plugin -> View Thresholds)

Here's what I've changed in jt555's code to fix this issue :

Replace this (first line of code) :

Code: Select all

if ($graph["host_id"] != 0) {
By this :

Code: Select all

if (($graph["host_id"] != 0) and (db_fetch_cell("select realm_id from user_auth_realm where user_id = ".$_SESSION["sess_user_id"]." and realm_id in (select id+100 from plugin_realms where display='Plugin -> View Thresholds')"))){
Thanks to jt555 for the his code
User avatar
jt555
Cacti User
Posts: 56
Joined: Sat Nov 17, 2007 3:37 pm
Location: Atlanta, Ga

Re: THold Legend and HRULEs

Post by jt555 »

Nice.

Hiding tholds wasn't an issue in my environment. Everybody needs to see them but only a few are allowed to edit them.

Thanks
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests