jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [setup.php] - Blame information for rev 107

 

Line No. Rev Author Line
11simandl<?php
2/*******************************************************************************
3 
4 Author ......... Howard Jones
5 Contact ........ howie@thingy.com
6 Home Site ...... http://wotsit.thingy.com/haj/
7 Program ........ Network Weathermap for Cacti
8 Version ........ See code below
9 Purpose ........ Network Usage Overview
10 
11*******************************************************************************/
12 
1385simandl// who knows why this changed... not me.
14function disabled_plugin_weathermap_version()
15{
16 return(weathermap_version());
17}
18 
191simandlfunction weathermap_version () {
20 return array( 'name' => 'weathermap',
2185simandl 'version' => '0.97a',
221simandl 'longname' => 'PHP Network Weathermap',
23 'author' => 'Howard Jones',
2485simandl 'homepage' => 'http://www.network-weathermap.com/',
25 'webpage' => 'http://www.network-weathermap.com/',
261simandl 'email' => 'howie@thingy.com',
2785simandl 'url' => 'http://www.network-weathermap.com/versions.php'
281simandl );
29}
30 
3185simandlfunction disabled_plugin_weathermap_uninstall() {
32 // doesn't really do anything. Here to remind me.
33 
34 // not sure what it should really do.
35}
36 
37function disabled_plugin_weathermap_check_config() {
38 // doesn't really do anything either because it's not implemented yet in PIA. Would be handy if it was.
39 
40 if(!function_exists("imagecreate")) return FALSE;
41 if(!function_exists("preg_match")) return FALSE;
42 if(!function_exists("imagecreatetruecolor")) return FALSE;
43 if(!function_exists("imagecreatefrompng")) return FALSE;
44 if(!function_exists("imagepng")) return FALSE;
45 if(!function_exists("imageSaveAlpha")) return FALSE;
46 if(!function_exists("imagealphablending")) return FALSE;
47 
48// if(!function_exists("imagecopyresampled")) return FALSE;
49 
50 return TRUE;
51}
52 
53function disabled_plugin_weathermap_install () {
54 
55 api_plugin_register_hook('weathermap', 'config_arrays', 'weathermap_config_arrays', 'setup.php');
56 api_plugin_register_hook('weathermap', 'draw_navigation_text', 'weathermap_draw_navigation_text', 'setup.php');
57 api_plugin_register_hook('weathermap', 'config_settings', 'weathermap_config_settings', 'setup.php');
58 api_plugin_register_hook('weathermap', 'top_header_tabs', 'weathermap_show_tab', 'setup.php');
59 api_plugin_register_hook('weathermap', 'top_graph_header_tabs', 'weathermap_show_tab', 'setup.php');
60 
61 api_plugin_register_hook('weathermap', 'poller_bottom', 'weathermap_poller_bottom', 'setup.php');
62 api_plugin_register_hook('weathermap', 'poller_top', 'weathermap_poller_top', 'setup.php');
63 api_plugin_register_hook('weathermap', 'poller_output', 'weathermap_poller_output', 'setup.php');
64 
65 api_plugin_register_hook('weathermap', 'top_graph_refresh', 'weathermap_top_graph_refresh', 'setup.php');
66 api_plugin_register_hook('weathermap', 'page_title', 'weathermap_page_title', 'setup.php');
67 api_plugin_register_hook('weathermap', 'page_head', 'weathermap_page_head', 'setup.php');
68 
69 weathermap_setup_table ();
70}
71 
72 
731simandlfunction plugin_init_weathermap() {
74 global $plugin_hooks;
75 $plugin_hooks['top_header_tabs']['weathermap'] = 'weathermap_show_tab';
76 $plugin_hooks['top_graph_header_tabs']['weathermap'] = 'weathermap_show_tab';
77 $plugin_hooks['config_arrays']['weathermap'] = 'weathermap_config_arrays';
78 $plugin_hooks['draw_navigation_text']['weathermap'] = 'weathermap_draw_navigation_text';
79 $plugin_hooks['config_settings']['weathermap'] = 'weathermap_config_settings';
8085simandl 
811simandl $plugin_hooks['poller_bottom']['weathermap'] = 'weathermap_poller_bottom';
8285simandl $plugin_hooks['poller_top']['weathermap'] = 'weathermap_poller_top';
83 $plugin_hooks['poller_output']['weathermap'] = 'weathermap_poller_output';
84 
851simandl $plugin_hooks['top_graph_refresh']['weathermap'] = 'weathermap_top_graph_refresh';
8685simandl $plugin_hooks['page_title']['weathermap'] = 'weathermap_page_title';
87 $plugin_hooks['page_head']['weathermap'] = 'weathermap_page_head';
881simandl}
89 
9085simandl// figure out if this poller run is hitting the 'cron' entry for any maps.
91function weathermap_poller_top()
92{
93 global $weathermap_poller_start_time;
94 
95 $n = time();
96 
97 // round to the nearest minute, since that's all we need for the crontab-style stuff
98 $weathermap_poller_start_time = $n - ($n%60);
99 
100}
101 
102function weathermap_page_head()
103{
104 global $config;
105 
106 // Add in a Media RSS link on the thumbnail view
107 // - format isn't quite right, so it's disabled for now.
108 // if(preg_match('/plugins\/weathermap\/weathermap\-cacti\-plugin\.php/',$_SERVER['REQUEST_URI'] ,$matches))
109 // {
110 // print '<link id="media-rss" title="My Network Weathermaps" rel="alternate" href="?action=mrss" type="application/rss+xml">';
111 // }
112 if(preg_match('/plugins\/weathermap\//',$_SERVER['REQUEST_URI'] ,$matches))
113 {
114 print '<LINK rel="stylesheet" type="text/css" media="screen" href="weathermap-cacti-plugin.css">';
115 }
116}
117 
118function weathermap_page_title( $t )
119{
120 if(preg_match('/plugins\/weathermap\//',$_SERVER['REQUEST_URI'] ,$matches))
121 {
122 $t .= " - Weathermap";
123 
124 if(preg_match('/plugins\/weathermap\/weathermap-cacti-plugin.php\?action=viewmap&id=([^&]+)/',$_SERVER['REQUEST_URI'],$matches))
125 {
126 $mapid = $matches[1];
127 if(preg_match("/^\d+$/",$mapid))
128 {
129 $title = db_fetch_cell("SELECT titlecache from weathermap_maps where ID=".intval($mapid));
130 }
131 else
132 {
133 $title = db_fetch_cell("SELECT titlecache from weathermap_maps where filehash='".mysql_real_escape_string($mapid)."'");
134 }
135 if(isset($title)) $t .= " - $title";
136 }
137 
138 }
139 return($t);
140}
141 
142 
143 
1441simandlfunction weathermap_top_graph_refresh($refresh)
145{
146 if (basename($_SERVER["PHP_SELF"]) != "weathermap-cacti-plugin.php")
147 return $refresh;
148 
149 // if we're cycling maps, then we want to handle reloads ourselves, thanks
15085simandl if(isset($_REQUEST["action"]) && $_REQUEST["action"] == 'viewmapcycle')
1511simandl {
152 return(86400);
153 }
154 return ($refresh);
155}
156 
157function weathermap_config_settings () {
158 global $tabs, $settings;
159 $tabs["misc"] = "Misc";
160 
161 $temp = array(
162 "weathermap_header" => array(
163 "friendly_name" => "Network Weathermap",
164 "method" => "spacer",
165 ),
166 "weathermap_pagestyle" => array(
167 "friendly_name" => "Page style",
168 "description" => "How to display multiple maps.",
169 "method" => "drop_array",
17085simandl "array" => array(0 => "Thumbnail Overview", 1 => "Full Images", 2 => "Show Only First")
1711simandl ),
172 "weathermap_thumbsize" => array(
173 "friendly_name" => "Thumbnail Maximum Size",
174 "description" => "The maximum width or height for thumbnails in thumbnail view, in pixels. Takes effect after the next poller run.",
175 "method" => "textbox",
176 "max_length" => 5,
177 ),
178 "weathermap_cycle_refresh" => array(
179 "friendly_name" => "Refresh Time",
180 "description" => "How often to refresh the page in Cycle mode. Automatic makes all available maps fit into 5 minutes.",
181 "method" => "drop_array",
182 "array" => array(0 => "Automatic", 5 => "5 Seconds",
183 15 => '15 Seconds',
184 30 => '30 Seconds',
185 60 => '1 Minute',
186 120 => '2 Minutes',
187 300 => '5 Minutes',
188 )
189 ),
190 "weathermap_output_format" => array(
191 "friendly_name" => "Output Format",
192 "description" => "What format do you prefer for the generated map images and thumbnails?",
193 "method" => "drop_array",
194 "array" => array('png' => "PNG (default)",
195 'jpg' => "JPEG",
196 'gif' => 'GIF'
197 )
198),
199"weathermap_render_period" => array(
200 "friendly_name" => "Map Rendering Interval",
201 "description" => "How often do you want Weathermap to recalculate it's maps? You should not touch this unless you know what you are doing! It is mainly needed for people with non-standard polling setups.",
202 "method" => "drop_array",
203 "array" => array(-1 => "Never (manual updates)",
204 
205 2 => 'Every 2 Poller Cycles',
206 3 => 'Every 3 Poller Cycles',
207 4 => 'Every 4 Poller Cycles',
208 5 => 'Every 5 Poller Cycles',
209 10 => 'Every 10 Poller Cycles',
210 12 => 'Every 12 Poller Cycles',
211 24 => 'Every 24 Poller Cycles',
212 36 => 'Every 36 Poller Cycles',
213 48 => 'Every 48 Poller Cycles',
214 72 => 'Every 72 Poller Cycles',
215 288 => 'Every 288 Poller Cycles',
216 ),
217 ),
218 
21985simandl "weathermap_all_tab" => array(
220 "friendly_name" => "Show 'All' Tab",
221 "description" => "When using groups, add an 'All Maps' tab to the tab bar.",
222 "method" => "drop_array",
223 "array" => array(0=>"No (default)",1=>"Yes")
224 ),
225 "weathermap_map_selector" => array(
226 "friendly_name" => "Show Map Selector",
227 "description" => "Show a combo-box map selector on the full-screen map view.",
228 "method" => "drop_array",
229 "array" => array(0=>"No",1=>"Yes (default)")
230 ),
2311simandl "weathermap_quiet_logging" => array(
232 "friendly_name" => "Quiet Logging",
233 "description" => "By default, even in LOW level logging, Weathermap logs normal activity. This makes it REALLY log only errors in LOW mode.",
234 "method" => "drop_array",
235 "array" => array(0=>"Chatty (default)",1=>"Quiet")
236 )
237 );
238 if (isset($settings["misc"]))
239 $settings["misc"] = array_merge($settings["misc"], $temp);
240 else
241 $settings["misc"]=$temp;
242}
243 
244 
245function weathermap_setup_table () {
246 global $config, $database_default;
24785simandl global $WEATHERMAP_VERSION;
2481simandl include_once($config["library_path"] . DIRECTORY_SEPARATOR . "database.php");
249 
25085simandl $dbversion = read_config_option("weathermap_db_version");
2511simandl 
25285simandl $myversioninfo = weathermap_version();
253 $myversion = $myversioninfo['version'];
254 
255 // only bother with all this if it's a new install, a new version, or we're in a development version
256 // - saves a handful of db hits per request!
257 if( ($dbversion=="") || (preg_match("/dev$/",$myversion)) || ($dbversion != $myversion) )
258 {
259 # cacti_log("Doing setup_table() \n",true,"WEATHERMAP");
260 $sql = "show tables";
261 $result = db_fetch_assoc($sql) or die (mysql_error());
2621simandl 
26385simandl $tables = array();
264 $sql = array();
265 
266 foreach($result as $index => $arr) {
267 foreach ($arr as $t) {
268 $tables[] = $t;
269 }
2701simandl }
271 
27285simandl $sql[] = "update weathermap_maps set sortorder=id where sortorder is null;";
273 
274 if (!in_array('weathermap_maps', $tables)) {
275 $sql[] = "CREATE TABLE weathermap_maps (
276 id int(11) NOT NULL auto_increment,
277 sortorder int(11) NOT NULL default 0,
278 group_id int(11) NOT NULL default 1,
279 active set('on','off') NOT NULL default 'on',
280 configfile text NOT NULL,
281 imagefile text NOT NULL,
282 htmlfile text NOT NULL,
283 titlecache text NOT NULL,
284 filehash varchar (40) NOT NULL default '',
285 warncount int(11) NOT NULL default 0,
286 config text NOT NULL default '',
287 thumb_width int(11) NOT NULL default 0,
288 thumb_height int(11) NOT NULL default 0,
289 schedule varchar(32) NOT NULL default '*',
290 archiving set('on','off') NOT NULL default 'off',
291 PRIMARY KEY (id)
292 ) TYPE=MyISAM;";
293 }
294 else
295 {
296 $colsql = "show columns from weathermap_maps from " . $database_default;
297 $result = mysql_query($colsql) or die (mysql_error());
298 $found_so = false; $found_fh = false;
299 $found_wc = false; $found_cf = false;
300 $found_96changes = false;
301 $found_96bchanges = false;
302 
303 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
304 if ($row['Field'] == 'sortorder') $found_so = true;
305 if ($row['Field'] == 'filehash') $found_fh = true;
306 if ($row['Field'] == 'warncount') $found_wc = true;
307 if ($row['Field'] == 'config') $found_cf = true;
308 
309 if ($row['Field'] == 'thumb_width') $found_96changes = true;
310 if ($row['Field'] == 'group_id') $found_96bchanges = true;
311 }
312 if (!$found_so) $sql[] = "alter table weathermap_maps add sortorder int(11) NOT NULL default 0 after id";
313 if (!$found_fh) $sql[] = "alter table weathermap_maps add filehash varchar(40) NOT NULL default '' after titlecache";
314 if (!$found_wc) $sql[] = "alter table weathermap_maps add warncount int(11) NOT NULL default 0 after filehash";
315 if (!$found_cf) $sql[] = "alter table weathermap_maps add config text NOT NULL default '' after warncount";
316 if (!$found_96changes)
317 {
318 $sql[] = "alter table weathermap_maps add thumb_width int(11) NOT NULL default 0 after config";
319 $sql[] = "alter table weathermap_maps add thumb_height int(11) NOT NULL default 0 after thumb_width";
320 $sql[] = "alter table weathermap_maps add schedule varchar(32) NOT NULL default '*' after thumb_height";
321 $sql[] = "alter table weathermap_maps add archiving set('on','off') NOT NULL default 'off' after schedule";
322 }
323 if (!$found_96bchanges)
324 {
325 $sql[] = "alter table weathermap_maps add group_id int(11) NOT NULL default 1 after sortorder";
326 $sql[] = "ALTER TABLE `weathermap_settings` ADD `groupid` INT NOT NULL DEFAULT '0' AFTER `mapid`";
327 }
328 }
3291simandl 
33085simandl $sql[] = "update weathermap_maps set filehash=LEFT(MD5(concat(id,configfile,rand())),20) where filehash = '';";
331 
332 if (!in_array('weathermap_auth', $tables)) {
333 $sql[] = "CREATE TABLE weathermap_auth (
334 userid mediumint(9) NOT NULL default '0',
335 mapid int(11) NOT NULL default '0'
336 ) TYPE=MyISAM;";
3371simandl }
33885simandl 
339 
340 if (!in_array('weathermap_groups', $tables)) {
341 $sql[] = "CREATE TABLE weathermap_groups (
342 `id` INT(11) NOT NULL auto_increment,
343 `name` VARCHAR( 128 ) NOT NULL default '',
344 `sortorder` INT(11) NOT NULL default 0,
345 PRIMARY KEY (id)
346 ) TYPE=MyISAM;";
347 $sql[] = "INSERT INTO weathermap_groups (id,name,sortorder) VALUES (1,'Weathermaps',1)";
348 }
349 
350 if (!in_array('weathermap_settings', $tables)) {
351 $sql[] = "CREATE TABLE weathermap_settings (
352 id int(11) NOT NULL auto_increment,
353 mapid int(11) NOT NULL default '0',
354 groupid int(11) NOT NULL default '0',
355 optname varchar(128) NOT NULL default '',
356 optvalue varchar(128) NOT NULL default '',
357 PRIMARY KEY (id)
358 ) TYPE=MyISAM;";
359 }
360 
361 if (!in_array('weathermap_data', $tables)) {
362 $sql[] = "CREATE TABLE IF NOT EXISTS weathermap_data (id int(11) NOT NULL auto_increment,
363 rrdfile varchar(255) NOT NULL,data_source_name varchar(19) NOT NULL,
364 last_time int(11) NOT NULL,last_value varchar(255) NOT NULL,
365 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),
366 KEY local_data_id (local_data_id), KEY data_source_name (data_source_name) ) TYPE=MyISAM";
367 }
368 else
3691simandl {
37085simandl $colsql = "show columns from weathermap_data from " . $database_default;
371 $result = mysql_query($colsql) or die (mysql_error());
372 $found_ldi = false;
373 
374 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
375 if ($row['Field'] == 'local_data_id') $found_ldi = true;
376 }
377 if (!$found_ldi)
378 {
379 $sql[] = "alter table weathermap_data add local_data_id int(11) NOT NULL default 0 after sequence";
380 $sql[] = "alter table weathermap_data add index ( `local_data_id` )";
381 # if there is existing data without a local_data_id, ditch it
382 $sql[] = "delete from weathermap_data";
383 }
3841simandl }
385 
38685simandl // create the settings entries, if necessary
3871simandl 
38885simandl $pagestyle = read_config_option("weathermap_pagestyle");
389 if($pagestyle == '' or $pagestyle < 0 or $pagestyle >2)
390 {
391 $sql[] = "replace into settings values('weathermap_pagestyle',0)";
392 }
3931simandl 
39485simandl $cycledelay = read_config_option("weathermap_cycle_refresh");
395 if($cycledelay == '' or intval($cycledelay < 0) )
396 {
397 $sql[] = "replace into settings values('weathermap_cycle_refresh',0)";
398 }
3991simandl 
40085simandl $renderperiod = read_config_option("weathermap_render_period");
401 if($renderperiod == '' or intval($renderperiod < -1) )
402 {
403 $sql[] = "replace into settings values('weathermap_render_period',0)";
404 }
405 
406 $quietlogging = read_config_option("weathermap_quiet_logging");
407 if($quietlogging == '' or intval($quietlogging < -1) )
408 {
409 $sql[] = "replace into settings values('weathermap_quiet_logging',0)";
410 }
4111simandl 
41285simandl $rendercounter = read_config_option("weathermap_render_counter");
413 if($rendercounter == '' or intval($rendercounter < 0) )
414 {
415 $sql[] = "replace into settings values('weathermap_render_counter',0)";
416 }
417 
418 $outputformat = read_config_option("weathermap_output_format");
419 if($outputformat == '' )
420 {
421 $sql[] = "replace into settings values('weathermap_output_format','png')";
422 }
423 
424 $tsize = read_config_option("weathermap_thumbsize");
425 if($tsize == '' or $tsize < 1)
426 {
427 $sql[] = "replace into settings values('weathermap_thumbsize',250)";
428 }
429 
430 $ms = read_config_option("weathermap_map_selector");
431 if($ms == '' or intval($ms) < 0 or intval($ms) > 1)
432 {
433 $sql[] = "replace into settings values('weathermap_map_selector',1)";
434 }
435 
436 $at = read_config_option("weathermap_all_tab");
437 if($at == '' or intval($at) < 0 or intval($at) > 1)
438 {
439 $sql[] = "replace into settings values('weathermap_all_tab',0)";
440 }
441 
442 // update the version, so we can skip this next time
443 $sql[] = "replace into settings values('weathermap_db_version','$myversion')";
444 
445 // patch up the sortorder for any maps that don't have one.
446 $sql[] = "update weathermap_maps set sortorder=id where sortorder is null or sortorder=0;";
447 
448 if (!empty($sql)) {
449 for ($a = 0; $a < count($sql); $a++) {
450 # cacti_log("Executing SQL: ".$sql[$a]."\n",true,"WEATHERMAP");
451 $result = db_execute($sql[$a]);
452 }
453 }
4541simandl }
45585simandl else
4561simandl {
45785simandl # cacti_log("Skipping SQL updates\n",true,"WEATHERMAP");
4581simandl }
45985simandl}
4601simandl 
46185simandlfunction weathermap_config_arrays () {
462 global $user_auth_realms, $user_auth_realm_filenames, $menu;
463 global $tree_item_types, $tree_item_handlers;
4641simandl 
46585simandl if (function_exists('api_plugin_register_realm')) {
466 api_plugin_register_realm('weathermap', 'weathermap-cacti-plugin.php', 'Plugin -> Weathermap: View', 1);
467 api_plugin_register_realm('weathermap', 'weathermap-cacti-plugin-mgmt.php', 'Plugin -> Weathermap: Configure/Manage', 1);
468 } else {
469 $user_auth_realms[42]='Plugin -> Weathermap: Configure/Manage';
470 $user_auth_realms[43]='Plugin -> Weathermap: View';
471 $user_auth_realm_filenames['weathermap-cacti-plugin.php'] = 43;
472 $user_auth_realm_filenames['weathermap-cacti-plugin-mgmt.php'] = 42;
473# $user_auth_realm_filenames['weathermap-cacti-plugin-mgmt-groups.php'] = 42;
4741simandl }
47585simandl // if there is support for custom graph tree types, then register ourselves
476 if(isset($tree_item_handlers))
4771simandl {
47885simandl $tree_item_types[10] = "Weathermap";
479 $tree_item_handlers[10] = array("render" => "weathermap_tree_item_render",
480 "name" => "weathermap_tree_item_name",
481 "edit" => "weathermap_tree_item_edit");
4821simandl }
483 
48485simandl $wm_menu = array(
485 'plugins/weathermap/weathermap-cacti-plugin-mgmt.php' => "Weathermaps",
486 'plugins/weathermap/weathermap-cacti-plugin-mgmt-groups.php' => "Groups"
487 );
488 
489 $menu["Management"]['plugins/weathermap/weathermap-cacti-plugin-mgmt.php'] = $wm_menu;
490 
491}
4921simandl 
49385simandlfunction weathermap_tree_item_render($leaf)
494{
495 global $colors;
496 
497 $outdir = dirname(__FILE__).'/output/';
498 $confdir = dirname(__FILE__).'/configs/';
499 
500 $map = db_fetch_assoc("select weathermap_maps.* from weathermap_auth,weathermap_maps where weathermap_maps.id=weathermap_auth.mapid and active='on' and (userid=".$_SESSION["sess_user_id"]." or userid=0) and weathermap_maps.id=".$leaf['item_id']);
501 
502 if(sizeof($map))
503 {
504 $htmlfile = $outdir."weathermap_".$map[0]['id'].".html";
505 $maptitle = $map[0]['titlecache'];
506 if($maptitle == '') $maptitle= "Map for config file: ".$map[0]['configfile'];
507 
508 html_graph_start_box(1,true);
509?>
510<tr bgcolor="<?php print $colors["panel"];?>">
511 <td>
512 <table width="100%" cellpadding="0" cellspacing="0">
513 <tr>
514 <td class="textHeader" nowrap><?php print $maptitle; ?></td>
515 </tr>
516 </table>
517 </td>
518</tr>
519<?php
520 print "<tr><td>";
521 
522 if(file_exists($htmlfile))
523 {
524 include($htmlfile);
5251simandl }
52685simandl print "</td></tr>";
527 html_graph_end_box();
528 
5291simandl }
530}
531 
53285simandl// calculate the name that cacti will use for this item in the tree views
533function weathermap_tree_item_name($item_id)
534{
535 $description = db_fetch_cell("select titlecache from weathermap_maps where id=".intval($item_id));
536 if($description == '')
537 {
538 $configfile = db_fetch_cell("select configfile from weathermap_maps where id=".intval($item_id));
539 $description = "Map for config file: ".$configfile;
540 }
541 
5421simandl 
54385simandl return $description;
544}
5451simandl 
54685simandl// the edit form, for when you add or edit a map in a graph tree
547function weathermap_tree_item_edit($tree_item)
548{
549 global $colors;
550 
551 form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],0);
552 print "<td width='50%'><font class='textEditTitle'>Map</font><br />Choose which weathermap to add to the tree.</td><td>";
553 form_dropdown("item_id", db_fetch_assoc("select id,CONCAT_WS('',titlecache,' (',configfile,')') as name from weathermap_maps where active='on' order by titlecache, configfile"), "name", "id", $tree_item['item_id'], "", "0");
554 print "</td></tr>";
555 form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],1);
556 print "<td width='50%'><font class='textEditTitle'>Style</font><br />How should the map be displayed?</td><td>";
557 print "<select name='item_options'><option value=1>Thumbnail</option><option value=2>Full Size</option></select>";
558 print "</td></tr>";
5591simandl}
560 
56185simandl 
5621simandlfunction weathermap_show_tab () {
563 global $config, $user_auth_realms, $user_auth_realm_filenames;
564 $realm_id2 = 0;
565 
566 if (isset($user_auth_realm_filenames[basename('weathermap-cacti-plugin.php')])) {
567 $realm_id2 = $user_auth_realm_filenames[basename('weathermap-cacti-plugin.php')];
568 }
569 
57085simandl $tabstyle = intval(read_config_option("superlinks_tabstyle"));
571 $userid = (isset($_SESSION["sess_user_id"]) ? intval($_SESSION["sess_user_id"]) : 1);
572 
573 if ((db_fetch_assoc("select user_auth_realm.realm_id from user_auth_realm where user_auth_realm.user_id='" . $userid . "' and user_auth_realm.realm_id='$realm_id2'")) || (empty($realm_id2))) {
5741simandl 
57585simandl if($tabstyle>0)
576 {
577 $prefix="s_";
578 }
579 else
580 {
581 $prefix="";
582 }
5831simandl 
58485simandl print '<a href="' . $config['url_path'] . 'plugins/weathermap/weathermap-cacti-plugin.php"><img src="' . $config['url_path'] . 'plugins/weathermap/images/'.$prefix.'tab_weathermap';
585 // if we're ON a weathermap page, print '_red'
586 if(preg_match('/plugins\/weathermap\/weathermap-cacti-plugin.php/',$_SERVER['REQUEST_URI'] ,$matches))
587 {
588 print "_red";
589 }
590 print '.gif" alt="weathermap" align="absmiddle" border="0"></a>';
591 
5921simandl }
593 
594 weathermap_setup_table();
595}
596 
597function weathermap_draw_navigation_text ($nav) {
598 $nav["weathermap-cacti-plugin.php:"] = array("title" => "Weathermap", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin.php", "level" => "1");
599 $nav["weathermap-cacti-plugin.php:viewmap"] = array("title" => "Weathermap", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin.php", "level" => "1");
60085simandl $nav["weathermap-cacti-plugin.php:liveview"] = array("title" => "Weathermap", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin.php", "level" => "1");
601 $nav["weathermap-cacti-plugin.php:liveviewimage"] = array("title" => "Weathermap", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin.php", "level" => "1");
6021simandl $nav["weathermap-cacti-plugin.php:viewmapcycle"] = array("title" => "Weathermap", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin.php", "level" => "1");
60385simandl $nav["weathermap-cacti-plugin.php:mrss"] = array("title" => "Weathermap", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin.php", "level" => "1");
604 $nav["weathermap-cacti-plugin.php:viewimage"] = array("title" => "Weathermap", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin.php", "level" => "1");
605 $nav["weathermap-cacti-plugin.php:viewthumb"] = array("title" => "Weathermap", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin.php", "level" => "1");
6061simandl 
607 $nav["weathermap-cacti-plugin-mgmt.php:"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
608 // $nav["weathermap-cacti-plugin-mgmt.php:addmap_picker"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
609 $nav["weathermap-cacti-plugin-mgmt.php:viewconfig"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
610 $nav["weathermap-cacti-plugin-mgmt.php:addmap"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
611 $nav["weathermap-cacti-plugin-mgmt.php:editmap"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
612 $nav["weathermap-cacti-plugin-mgmt.php:editor"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
613 
614 // "graphs.php:graph_edit" => array("title" => "(Edit)", "mapping" => "index.php:,graphs.php:", "url" => "", "level" => "2"),
615 
616 $nav["weathermap-cacti-plugin-mgmt.php:perms_edit"] = array("title" => "Edit Permissions", "mapping" => "index.php:,weathermap-cacti-plugin-mgmt.php:", "url" => "", "level" => "2");
617 $nav["weathermap-cacti-plugin-mgmt.php:addmap_picker"] = array("title" => "Add Map", "mapping" => "index.php:,weathermap-cacti-plugin-mgmt.php:", "url" => "", "level" => "2");
61885simandl $nav["weathermap-cacti-plugin-mgmt.php:map_settings"] = array("title" => "Map Settings", "mapping" => "index.php:,weathermap-cacti-plugin-mgmt.php:", "url" => "", "level" => "2");
619 $nav["weathermap-cacti-plugin-mgmt.php:map_settings_form"] = array("title" => "Map Settings", "mapping" => "index.php:,weathermap-cacti-plugin-mgmt.php:", "url" => "", "level" => "2");
620 $nav["weathermap-cacti-plugin-mgmt.php:map_settings_delete"] = array("title" => "Map Settings", "mapping" => "index.php:,weathermap-cacti-plugin-mgmt.php:", "url" => "", "level" => "2");
621 $nav["weathermap-cacti-plugin-mgmt.php:map_settings_update"] = array("title" => "Map Settings", "mapping" => "index.php:,weathermap-cacti-plugin-mgmt.php:", "url" => "", "level" => "2");
622 $nav["weathermap-cacti-plugin-mgmt.php:map_settings_add"] = array("title" => "Map Settings", "mapping" => "index.php:,weathermap-cacti-plugin-mgmt.php:", "url" => "", "level" => "2");
6231simandl 
624 
625 // $nav["weathermap-cacti-plugin-mgmt.php:perms_edit"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
626 $nav["weathermap-cacti-plugin-mgmt.php:perms_add_user"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
627 $nav["weathermap-cacti-plugin-mgmt.php:perms_delete_user"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
628 $nav["weathermap-cacti-plugin-mgmt.php:delete_map"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
629 $nav["weathermap-cacti-plugin-mgmt.php:move_map_down"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
630 $nav["weathermap-cacti-plugin-mgmt.php:move_map_up"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
63185simandl $nav["weathermap-cacti-plugin-mgmt.php:move_group_down"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
632 $nav["weathermap-cacti-plugin-mgmt.php:move_group_up"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
633 $nav["weathermap-cacti-plugin-mgmt.php:group_form"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
634 $nav["weathermap-cacti-plugin-mgmt.php:group_update"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
6351simandl $nav["weathermap-cacti-plugin-mgmt.php:activate_map"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
636 $nav["weathermap-cacti-plugin-mgmt.php:deactivate_map"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
637 $nav["weathermap-cacti-plugin-mgmt.php:rebuildnow"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
63885simandl $nav["weathermap-cacti-plugin-mgmt.php:rebuildnow2"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
639 
640 $nav["weathermap-cacti-plugin-mgmt.php:chgroup"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
641 $nav["weathermap-cacti-plugin-mgmt.php:chgroup_update"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
642 $nav["weathermap-cacti-plugin-mgmt.php:groupadmin"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
643 $nav["weathermap-cacti-plugin-mgmt.php:groupadmin_delete"] = array("title" => "Weathermap Management", "mapping" => "index.php:", "url" => "weathermap-cacti-plugin-mgmt.php", "level" => "1");
644 
6451simandl return $nav;
646}
647 
64885simandlfunction weathermap_poller_output($rrd_update_array) {
649 global $config;
650 // global $weathermap_debugging;
6511simandl 
65285simandl $logging = read_config_option("log_verbosity");
653 
654 if($logging >= POLLER_VERBOSITY_DEBUG) cacti_log("WM poller_output: STARTING\n",true,"WEATHERMAP");
655 
656 // partially borrowed from Jimmy Conner's THold plugin.
657 // (although I do things slightly differently - I go from filenames, and don't use the poller_interval)
658 
659 
660 // $requiredlist = db_fetch_assoc("select distinct weathermap_data.*, data_template_data.local_data_id, data_template_rrd.data_source_type_id from weathermap_data, data_template_data, data_template_rrd where weathermap_data.rrdfile=data_template_data.data_source_path and data_template_rrd.local_data_id=data_template_data.local_data_id");
661 // new version works with *either* a local_data_id or rrdfile in the weathermap_data table, and returns BOTH
662 $requiredlist = db_fetch_assoc("select distinct weathermap_data.id, weathermap_data.last_value, weathermap_data.last_time, weathermap_data.data_source_name, data_template_data.data_source_path, data_template_data.local_data_id, data_template_rrd.data_source_type_id from weathermap_data, data_template_data, data_template_rrd where weathermap_data.local_data_id=data_template_data.local_data_id and data_template_rrd.local_data_id=data_template_data.local_data_id and weathermap_data.local_data_id<>0;");
663 
664 $path_rra = $config["rra_path"];
665 
666 # especially on Windows, it seems that filenames are not reliable (sometimes \ and sometimes / even though path_rra is always /) .
667 # let's make an index from local_data_id to filename, and then use local_data_id as the key...
668 
669 foreach (array_keys($rrd_update_array) as $key)
670 {
671 if(isset( $rrd_update_array[$key]['times']) && is_array($rrd_update_array[$key]['times']) )
672 {
673 # if($logging >= POLLER_VERBOSITY_DEBUG) cacti_log("WM poller_output: Adding $key",true,"WEATHERMAP");
674 $knownfiles[ $rrd_update_array[$key]["local_data_id"] ] = $key;
675 
676 }
677 }
678 
679 foreach ($requiredlist as $required)
680 {
681 $file = str_replace("<path_rra>", $path_rra, $required['data_source_path']);
682 $dsname = $required['data_source_name'];
683 $local_data_id = $required['local_data_id'];
684 
685 if(isset($knownfiles[$local_data_id]))
686 {
687 $file2 = $knownfiles[$local_data_id];
688 if($file2 != '') $file = $file2;
689 }
690 
691 if($logging >= POLLER_VERBOSITY_DEBUG) cacti_log("WM poller_output: Looking for $file ($local_data_id) (".$required['data_source_path'].")\n",true,"WEATHERMAP");
692 
693 if( isset($rrd_update_array[$file]) && is_array($rrd_update_array[$file]) && isset($rrd_update_array[$file]['times']) && is_array($rrd_update_array[$file]['times']) && isset( $rrd_update_array{$file}['times'][key($rrd_update_array[$file]['times'])]{$dsname} ) )
694 {
695 $value = $rrd_update_array{$file}['times'][key($rrd_update_array[$file]['times'])]{$dsname};
696 $time = key($rrd_update_array[$file]['times']);
697 if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_MEDIUM)
698 cacti_log("WM poller_output: Got one! $file:$dsname -> $time $value\n",true,"WEATHERMAP");
699 
700 $period = $time - $required['last_time'];
701 $lastval = $required['last_value'];
702 
703 // if the new value is a NaN, we'll give 0 instead, and pretend it didn't happen from the point
704 // of view of the counter etc. That way, we don't get those enormous spikes. Still doesn't deal with
705 // reboots very well, but it should improve it for drops.
706 if($value == 'U')
707 {
708 $newvalue = 0;
709 $newlastvalue = $lastval;
710 $newtime = $required['last_time'];
711 }
712 else
713 {
714 $newlastvalue = $value;
715 $newtime = $time;
716 
717 switch($required['data_source_type_id'])
718 {
719 case 1: //GAUGE
720 $newvalue = $value;
721 break;
722 
723 case 2: //COUNTER
724 if ($value >= $lastval) {
725 // Everything is normal
726 $newvalue = $value - $lastval;
727 } else {
728 // Possible overflow, see if its 32bit or 64bit
729 if ($lastval > 4294967295) {
730 $newvalue = (18446744073709551615 - $lastval) + $value;
731 } else {
732 $newvalue = (4294967295 - $lastval) + $value;
733 }
734 }
735 $newvalue = $newvalue / $period;
736 break;
737 
738 case 3: //DERIVE
739 $newvalue = ($value-$lastval) / $period;
740 break;
741 
742 case 4: //ABSOLUTE
743 $newvalue = $value / $period;
744 break;
745 
746 default: // do something somewhat sensible in case something odd happens
747 $newvalue = $value;
748 warn("poller_output found an unknown data_source_type_id for $file:$dsname");
749 break;
750 }
751 }
752 db_execute("UPDATE weathermap_data SET last_time=$newtime, last_calc='$newvalue', last_value='$newlastvalue',sequence=sequence+1 where id = " . $required['id']);
753 if($logging >= POLLER_VERBOSITY_DEBUG) cacti_log("WM poller_output: Final value is $newvalue (was $lastval, period was $period)\n",true,"WEATHERMAP");
754 }
755 else
756 {
757 if(1==0 && $logging >= POLLER_VERBOSITY_DEBUG)
758 {
759 # cacti_log("WM poller_output: ENDING\n",true,"WEATHERMAP");
760 cacti_log("WM poller_output: Didn't find it.\n",true,"WEATHERMAP");
761 cacti_log("WM poller_output: DID find these:\n",true,"WEATHERMAP");
762 
763 foreach (array_keys($rrd_update_array) as $key)
764 {
765 $local_data_id = $rrd_update_array[$key]["local_data_id"];
766 cacti_log("WM poller_output: $key ($local_data_id)\n",true,"WEATHERMAP");
767 }
768 }
769 }
770 }
771 
772 if($logging >= POLLER_VERBOSITY_DEBUG) cacti_log("WM poller_output: ENDING\n",true,"WEATHERMAP");
773 
774 return $rrd_update_array;
775}
776 
777function weathermap_poller_bottom() {
7781simandl global $config;
779 global $weathermap_debugging, $WEATHERMAP_VERSION;
780 
781 include_once($config["library_path"] . DIRECTORY_SEPARATOR."database.php");
782 include_once(dirname(__FILE__).DIRECTORY_SEPARATOR."lib".DIRECTORY_SEPARATOR."poller-common.php");
783 
784 weathermap_setup_table();
785 
786 $renderperiod = read_config_option("weathermap_render_period");
787 $rendercounter = read_config_option("weathermap_render_counter");
788 $quietlogging = read_config_option("weathermap_quiet_logging");
789 
790 if($renderperiod<0)
791 {
792 // manual updates only
793 if($quietlogging==0) cacti_log("Weathermap $WEATHERMAP_VERSION - no updates ever",true,"WEATHERMAP");
794 return;
795 }
796 else
797 {
798 // if we're due, run the render updates
79985simandl if( ( $renderperiod == 0) || ( ($rendercounter % $renderperiod) == 0) )
8001simandl {
801 weathermap_run_maps(dirname(__FILE__) );
802 }
803 else
804 {
805 if($quietlogging==0) cacti_log("Weathermap $WEATHERMAP_VERSION - no update in this cycle ($rendercounter)",true,"WEATHERMAP");
806 }
807 # cacti_log("Weathermap counter is $rendercounter. period is $renderperiod.", true, "WEATHERMAP");
808 // increment the counter
809 $newcount = ($rendercounter+1)%1000;
810 db_execute("replace into settings values('weathermap_render_counter',".$newcount.")");
811 }
812}
813 
814// vim:ts=4:sw=4:
81513simandl?>

Powered by WebSVN 2.2.1