From 1b956853ad018bf64665971ca187a89a66effd05 Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Tue, 17 May 2011 19:21:20 +0000 Subject: [PATCH] cleanups git-svn-id: http://www.observium.org/svn/observer/trunk@2340 61d68cd4-352d-0410-923a-c4978735b2b8 --- attic/cisco-entity-sensors.inc.php | 51 ++++++++++ attic/temperatures.inc.php | 66 +++++++++++++ attic/voltages.inc.php | 54 +++++++++++ database-update.sql | 3 + html/includes/functions.inc.php | 42 ++++---- html/includes/print-interface-adsl.inc.php | 53 ++-------- html/includes/print-interface-graphs.inc.php | 4 +- html/includes/print-interface.inc.php | 29 +----- html/includes/print-menubar.php | 9 +- html/includes/print-quadgraphs.inc.php | 6 +- html/includes/print-service.inc.php | 6 +- html/index.php | 2 + html/pages/customers.inc.php | 17 ++-- html/pages/device/collectd.inc.php | 16 ++-- html/pages/device/health/diskio.inc.php | 15 ++- html/pages/device/hrdevice.inc.php | 2 +- .../device/overview/generic/sensor.inc.php | 14 +-- html/pages/device/overview/ports.inc.php | 8 +- html/pages/graphs.inc.php | 47 +++++---- html/pages/health/storage.inc.php | 41 ++++---- includes/dbFacile.php | 4 +- includes/discovery/functions.inc.php | 96 +++++++++---------- includes/static-config.php | 26 +++-- 23 files changed, 384 insertions(+), 227 deletions(-) create mode 100755 attic/cisco-entity-sensors.inc.php create mode 100755 attic/temperatures.inc.php create mode 100755 attic/voltages.inc.php diff --git a/attic/cisco-entity-sensors.inc.php b/attic/cisco-entity-sensors.inc.php new file mode 100755 index 000000000..fb62bc06b --- /dev/null +++ b/attic/cisco-entity-sensors.inc.php @@ -0,0 +1,51 @@ + \ No newline at end of file diff --git a/attic/temperatures.inc.php b/attic/temperatures.inc.php new file mode 100755 index 000000000..7244ddac1 --- /dev/null +++ b/attic/temperatures.inc.php @@ -0,0 +1,66 @@ += $sensor['sensor_limit']) + { + $msg = "Temp Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'] . " is " . $sensor_value . " (Limit " . $sensor['sensor_limit']; + $msg .= ") at " . date($config['timestamp_format']); + notify($device, "Temp Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'], $msg); + echo("Alerting for " . $device['hostname'] . " " . $sensor['sensor_descr'] . "\n"); + log_event('Temperature ' . $sensor['sensor_descr'] . " over threshold: " . $sensor_value . " " . html_entity_decode('°') . "$unit (>= " . $sensor['sensor_limit'] . " " . html_entity_decode('°') . "$unit)", $device, $class, $sensor['sensor_id']); + } + + mysql_query("UPDATE sensors SET sensor_current = '$sensor_value' WHERE sensor_class='$class' AND sensor_id = '" . $sensor['sensor_id'] . "'"); +} + +?> diff --git a/attic/voltages.inc.php b/attic/voltages.inc.php new file mode 100755 index 000000000..709636fec --- /dev/null +++ b/attic/voltages.inc.php @@ -0,0 +1,54 @@ + $sensor['sensor_limit_low'] && $sensor_value <= $sensor['sensor_limit_low']) + { + $msg = $class_text . " Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'] . " is " . $sensor_value . "$unit (Limit " . $sensor['sensor_limit']; + $msg .= "$unit) at " . date($config['timestamp_format']); + notify($device, $class_text" Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'], $msg); + echo("Alerting for " . $device['hostname'] . " " . $sensor['sensor_descr'] . "\n"); + log_event($class_text.' '.$sensor['sensor_descr'] . " under threshold: " . $sensor_value . " $unit (< " . $sensor['sensor_limit_low'] . " $unit)", $device, $class, $sensor['sensor_id']); + } + else if ($sensor['sensor_limit'] != "" && $sensor['sensor_current'] < $sensor['sensor_limit'] && $sensor_value >= $sensor['sensor_limit']) + { + $msg = $class_text." Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'] . " is " . $sensor_value . "$unit (Limit " . $sensor['sensor_limit']; + $msg .= "$unit) at " . date($config['timestamp_format']); + notify($device, $class_text." Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'], $msg); + echo("Alerting for " . $device['hostname'] . " " . $sensor['sensor_descr'] . "\n"); + log_event($class_text." ". $sensor['sensor_descr'] . " above threshold: " . $sensor_value . " $unit (> " . $sensor['sensor_limit'] . " $unit)", $device, $class, $sensor['sensor_id']); + } + dbUpdate(array('sensor_current' => $sensor_value), 'sensors', '`sensor_id` = ', array($sensor['sensor_id'])); +} + +?> diff --git a/database-update.sql b/database-update.sql index 42c8261db..59e82c630 100644 --- a/database-update.sql +++ b/database-update.sql @@ -1 +1,4 @@ ALTER TABLE users ADD can_modify_passwd TINYINT NOT NULL DEFAULT 1; +ALTER TABLE `observer_dev`.`storage` ADD UNIQUE `index_unique` ( `device_id` , `storage_mib` , `storage_index` ); +ALTER TABLE `bgpPeers_cbgp` ADD `AcceptedPrefixes` INT NOT NULL ,ADD `DeniedPrefixes` INT NOT NULL ,ADD `PrefixAdminLimit` INT NOT NULL ,ADD `PrefixThreshold` INT NOT NULL ,ADD `PrefixClearThreshold` INT NOT NULL ,ADD `AdvertisedPrefixes` INT NOT NULL ,ADD `SuppressedPrefixes` INT NOT NULL ,ADD `WithdrawnPrefixes` INT NOT NULL; +ALTER TABLE `observer_dev`.`bgpPeers_cbgp` ADD UNIQUE `unique_index` ( `device_id` , `bgpPeerIdentifier` , `afi` , `safi` ); diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index 7dec3cfa5..c959d8e31 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -13,12 +13,18 @@ function get_percentage_colours($percentage) } +function generate_device_url($device, $linksuffix="") +{ + return "device/" . $device['device_id'] . "/" . $linksuffix; +} + function generate_device_link($device, $text=0, $linksuffix="", $start=0, $end=0) { - global $twoday, $day, $now, $config; + global $config; + + if (!$start) { $start = $config['time']['day']; } + if (!$end) { $end = $config['time']['now']; } - if (!$start) { $start = $day; } - if (!$end) { $end = $now; } $class = devclass($device); if (!$text) { $text = $device['hostname']; } @@ -35,7 +41,7 @@ function generate_device_link($device, $text=0, $linksuffix="", $start=0, $end=0 $graphs = $config['os']['default']['over']; } - $url = "device/" . $device['device_id'] . "/" . $linksuffix; + $url = generate_device_url($device, $linksuffix); $contents = "
".$device['hostname']; if ($device['hardware']) { $contents .= " - ".$device['hardware']; } $contents .= "
"; @@ -55,7 +61,7 @@ function generate_device_link($device, $text=0, $linksuffix="", $start=0, $end=0 $contents .= '
'; $contents .= ''.$graphhead.'
'; $contents .= "'; - $contents .= "'; + $contents .= "'; $contents .= '
'; } @@ -95,13 +101,13 @@ function generate_graph_popup($graph_array) $graph_array['legend'] = "yes"; $graph_array['height'] = "100"; $graph_array['width'] = "340"; - $graph_array['from'] = $config['day']; + $graph_array['from'] = $config['time']['day']; $content .= generate_graph_tag($graph_array); - $graph_array['from'] = $config['week']; + $graph_array['from'] = $config['time']['week']; $content .= generate_graph_tag($graph_array); - $graph_array['from'] = $config['month']; + $graph_array['from'] = $config['time']['month']; $content .= generate_graph_tag($graph_array); - $graph_array['from'] = $config['year']; + $graph_array['from'] = $config['time']['year']; $content .= generate_graph_tag($graph_array); $content .= ""; @@ -236,7 +242,7 @@ function print_percentage_bar($width, $height, $percent, $left_text, $left_colou function generate_port_link($args, $text = NULL, $type = NULL) { - global $twoday, $now, $config, $day, $month; + global $config; $args = ifNameDescr($args); if (!$text) { $text = fixIfName($args['label']); } @@ -253,19 +259,19 @@ function generate_port_link($args, $text = NULL, $type = NULL) $graph_array['legend'] = "yes"; $graph_array['height'] = "100"; $graph_array['width'] = "340"; - $graph_array['to'] = $config['now']; - $graph_array['from'] = $config['day']; + $graph_array['to'] = $config['time']['now']; + $graph_array['from'] = $config['time']['day']; $graph_array['id'] = $args['interface_id']; $content .= generate_graph_tag($graph_array); - $graph_array['from'] = $config['week']; + $graph_array['from'] = $config['time']['week']; $content .= generate_graph_tag($graph_array); - $graph_array['from'] = $config['month']; + $graph_array['from'] = $config['time']['month']; $content .= generate_graph_tag($graph_array); - $graph_array['from'] = $config['year']; + $graph_array['from'] = $config['time']['year']; $content .= generate_graph_tag($graph_array); $content .= ""; - $url = "device/".$args['device_id']."/port/" . $args['interface_id'] . "/"; + $url = generate_port_url($args); if (port_permitted($args['interface_id'])) { return overlib_link($url, $text, $content, $class); @@ -274,6 +280,10 @@ function generate_port_link($args, $text = NULL, $type = NULL) } } +function generate_port_url($args) { + return $url = "device/".$args['device_id']."/port/" . $args['interface_id'] . "/"; +} + function generate_port_thumbnail($args) { if (!$args['bg']) { $args['bg'] = "FFFFF"; } diff --git a/html/includes/print-interface-adsl.inc.php b/html/includes/print-interface-adsl.inc.php index 456990f3a..2aef4ef5f 100644 --- a/html/includes/print-interface-adsl.inc.php +++ b/html/includes/print-interface-adsl.inc.php @@ -35,7 +35,7 @@ if ($port_details) echo("$break ".$ip['ipv4_address']."/".$ip['ipv4_prefixlen'].""); $break = ","; } - foreach (dbFetchRows("SELECT * FROM `ipv6_addresses` WHERE `interface_id` = ?", array($interface['interface_id']) as $ip6); + foreach (dbFetchRows("SELECT * FROM `ipv6_addresses` WHERE `interface_id` = ?", array($interface['interface_id'])) as $ip6); { echo("$break ".Net_IPv6::compress($ip6['ipv6_address'])."/".$ip6['ipv6_prefixlen'].""); $break = ","; @@ -44,48 +44,48 @@ if ($port_details) echo(""); -$width="120"; $height="40"; $from = $day; +$width="120"; $height="40"; $from = $config['time']['day']; echo(""); echo(formatRates($interface['ifInOctets_rate'] * 8)." ".formatRates($interface['ifOutOctets_rate'] * 8)); echo("
"); $interface['graph_type'] = "port_bits"; -echo(generate_port_link($interface, "", $interface['graph_type'])); echo(""); echo("".formatRates($interface['adslAturChanCurrTxRate']) . "/". formatRates($interface['adslAtucChanCurrTxRate'])); echo("
"); $interface['graph_type'] = "port_adsl_speed"; -echo(generate_port_link($interface, "", $interface['graph_type'])); echo(""); echo("".formatRates($interface['adslAturCurrAttainableRate']) . "/". formatRates($interface['adslAtucCurrAttainableRate'])); echo("
"); $interface['graph_type'] = "port_adsl_attainable"; -echo(generate_port_link($interface, "", $interface['graph_type'])); echo(""); echo("".$interface['adslAturCurrAtn'] . "dB/". $interface['adslAtucCurrAtn'] . "dB"); echo("
"); $interface['graph_type'] = "port_adsl_attenuation"; -echo(generate_port_link($interface, "", $interface['graph_type'])); echo(""); echo("".$interface['adslAturCurrSnrMgn'] . "dB/". $interface['adslAtucCurrSnrMgn'] . "dB"); echo("
"); $interface['graph_type'] = "port_adsl_snr"; -echo(generate_port_link($interface, "", $interface['graph_type'])); echo(""); echo("".$interface['adslAturCurrOutputPwr'] . "dBm/". $interface['adslAtucCurrOutputPwr'] . "dBm"); echo("
"); $interface['graph_type'] = "port_adsl_power"; -echo(generate_port_link($interface, "", $interface['graph_type'])); # if ($interface[ifDuplex] != unknown) { echo("Duplex " . $interface['ifDuplex'] . ""); } else { echo("-"); } @@ -103,41 +103,4 @@ str_replace("#","", $row_colour)."'>", $interface['graph_type'])); echo(""); -if ($graph_type == "etherlike") -{ - $graph_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/etherlike-". safename($interface['ifIndex']) . ".rrd"; -} else { - $graph_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/". safename($interface['ifIndex']) . ".rrd"; -} - -if ($graph_type && is_file($graph_file)) -{ - $type = $graph_type; - - $daily_traffic = "graph.php?port=$if_id&type=" . $graph_type . "&from=$from&to=$now&width=210&height=100"; - $daily_url = "graph.php?port=$if_id&type=" . $graph_type . "&from=$from&to=$now&width=500&height=150"; - - $weekly_traffic = "graph.php?port=$if_id&type=" . $graph_type . "&from=$week&to=$now&width=210&height=100"; - $weekly_url = "graph.php?port=$if_id&type=" . $graph_type . "&from=$week&to=$now&width=500&height=150"; - - $monthly_traffic = "graph.php?port=$if_id&type=" . $graph_type . "&from=$month&to=$now&width=210&height=100"; - $monthly_url = "graph.php?port=$if_id&type=" . $graph_type . "&from=$month&to=$now&width=500&height=150"; - - $yearly_traffic = "graph.php?port=$if_id&type=" . $graph_type . "&from=$year&to=$now&width=210&height=100"; - $yearly_url = "graph.php?port=$if_id&type=" . $graph_type . "&from=$year&to=$now&width=500&height=150"; - - echo(""); - - echo("', LEFT".$config['overlib_defaults'].");\" - onmouseout=\"return nd();\"> "); - echo("', LEFT".$config['overlib_defaults'].");\" - onmouseout=\"return nd();\"> "); - echo("', LEFT, WIDTH, 350".$config['overlib_defaults'].");\" - onmouseout=\"return nd();\"> "); - echo("', LEFT, WIDTH, 350".$config['overlib_defaults'].");\" - onmouseout=\"return nd();\"> "); - - echo(""); -} - ?> diff --git a/html/includes/print-interface-graphs.inc.php b/html/includes/print-interface-graphs.inc.php index 1482f3340..b90e03101 100644 --- a/html/includes/print-interface-graphs.inc.php +++ b/html/includes/print-interface-graphs.inc.php @@ -4,10 +4,10 @@ global $config; $graph_array['height'] = "100"; $graph_array['width'] = "215"; -$graph_array['to'] = $now; +$graph_array['to'] = $config['time']['now']; $graph_array['id'] = $interface['interface_id']; $graph_array['type'] = $graph_type; include("includes/print-quadgraphs.inc.php"); -?> \ No newline at end of file +?> diff --git a/html/includes/print-interface.inc.php b/html/includes/print-interface.inc.php index 78660fa8c..7d530de01 100644 --- a/html/includes/print-interface.inc.php +++ b/html/includes/print-interface.inc.php @@ -59,11 +59,11 @@ echo(""); if ($port_details) { $interface['graph_type'] = "port_bits"; - echo(generate_port_link($interface, "")); + echo(generate_port_link($interface, "")); $interface['graph_type'] = "port_upkts"; - echo(generate_port_link($interface, "")); + echo(generate_port_link($interface, "")); $interface['graph_type'] = "port_errors"; - echo(generate_port_link($interface, "")); + echo(generate_port_link($interface, "")); } echo(""); @@ -259,31 +259,10 @@ if ($graph_type && is_file($graph_file)) { $type = $graph_type; - $daily_traffic = "graph.php?id=$if_id&type=" . $graph_type . "&from=$day&to=$now&width=210&height=100"; - $daily_url = "graph.php?id=$if_id&type=" . $graph_type . "&from=$day&to=$now&width=500&height=150"; - - $weekly_traffic = "graph.php?id=$if_id&type=" . $graph_type . "&from=$week&to=$now&width=210&height=100"; - $weekly_url = "graph.php?id=$if_id&type=" . $graph_type . "&from=$week&to=$now&width=500&height=150"; - - $monthly_traffic = "graph.php?id=$if_id&type=" . $graph_type . "&from=$month&to=$now&width=210&height=100"; - $monthly_url = "graph.php?id=$if_id&type=" . $graph_type . "&from=$month&to=$now&width=500&height=150"; - - $yearly_traffic = "graph.php?id=$if_id&type=" . $graph_type . "&from=$year&to=$now&width=210&height=100"; - $yearly_url = "graph.php?id=$if_id&type=" . $graph_type . "&from=$year&to=$now&width=500&height=150"; - - echo(""); + echo(""); include("includes/print-interface-graphs.inc.php"); -# echo("', LEFT".$config['overlib_defaults'].");\" -# onmouseout=\"return nd();\"> "); -# echo("', LEFT".$config['overlib_defaults'].");\" -# onmouseout=\"return nd();\"> "); -# echo("', LEFT, WIDTH, 350".$config['overlib_defaults'].");\" -# onmouseout=\"return nd();\"> "); -# echo("', LEFT, WIDTH, 350".$config['overlib_defaults'].");\" -# onmouseout=\"return nd();\"> "); - echo(""); } diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 33af9d873..82f3e5989 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -1,7 +1,7 @@ ".$device['hostname']." - ".$service['service_type']; -$popup .= ""; +$popup .= ""; $popup .= "', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\""; echo(" @@ -59,4 +59,4 @@ echo(" $i++; -?> \ No newline at end of file +?> diff --git a/html/index.php b/html/index.php index d0d7445e8..eabc78826 100755 --- a/html/index.php +++ b/html/index.php @@ -26,7 +26,9 @@ include("../includes/functions.php"); include("includes/functions.inc.php"); $start = utime(); + $now = time(); +$fourhour = time() - (4 * 60 * 60); $day = time() - (24 * 60 * 60); $twoday = time() - (2 * 24 * 60 * 60); $week = time() - (7 * 24 * 60 * 60); diff --git a/html/pages/customers.inc.php b/html/pages/customers.inc.php index ff597ade8..a3f63f3f6 100644 --- a/html/pages/customers.inc.php +++ b/html/pages/customers.inc.php @@ -56,12 +56,17 @@ foreach (dbFetchRows("SELECT * FROM `ports` WHERE `port_descr_type` = 'cust' GRO unset($customer_name); } - echo(" - - - - - "); + echo(""); + + $graph_array['type'] = "customer_bits"; + $graph_array['height'] = "100"; + $graph_array['width'] = "220"; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $customer['port_descr_descr']; + + include("includes/print-quadgraphs.inc.php"); + + echo(""); } echo(""); diff --git a/html/pages/device/collectd.inc.php b/html/pages/device/collectd.inc.php index 196d06cff..83979ade5 100644 --- a/html/pages/device/collectd.inc.php +++ b/html/pages/device/collectd.inc.php @@ -89,24 +89,24 @@ print_optionbar_end(); } echo(""); - $daily_traffic = "collectd-graph.php?host=" . $device['hostname'] . "&plugin=".$_GET['opta']."&type=".$_GET['opta']."&plugin_instance=".$instance."&type=".$type."&type_instance=".$tinst."&from=$day&to=$now&width=215&height=100"; + $daily_traffic = "collectd-graph.php?host=" . $device['hostname'] . "&plugin=".$_GET['opta']."&type=".$_GET['opta']."&plugin_instance=".$instance."&type=".$type."&type_instance=".$tinst."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=215&height=100"; $daily_traffic .= $args; - $daily_url = "collectd-graph.php?host=" . $device['hostname'] . "&plugin=".$_GET['opta']."&type=".$_GET['opta']."&plugin_instance=".$instance."&type=".$type."&type_instance=".$tinst."&from=$day&to=$now&width=400&height=150"; + $daily_url = "collectd-graph.php?host=" . $device['hostname'] . "&plugin=".$_GET['opta']."&type=".$_GET['opta']."&plugin_instance=".$instance."&type=".$type."&type_instance=".$tinst."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=400&height=150"; $daily_url .= $args; - $weekly_traffic = "collectd-graph.php?host=" . $device['hostname'] . "&plugin=".$_GET['opta']."&type=".$_GET['opta']."&plugin_instance=".$instance."&type=".$type."&type_instance=".$tinst."&from=$week&to=$now&width=215&height=100"; + $weekly_traffic = "collectd-graph.php?host=" . $device['hostname'] . "&plugin=".$_GET['opta']."&type=".$_GET['opta']."&plugin_instance=".$instance."&type=".$type."&type_instance=".$tinst."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=215&height=100"; $weekly_traffic .= $args; - $weekly_url = "collectd-graph.php?host=" . $device['hostname'] . "&plugin=".$_GET['opta']."&type=".$_GET['opta']."&plugin_instance=".$instance."&type=".$type."&type_instance=".$tinst."&from=$week&to=$now&width=400&height=150"; + $weekly_url = "collectd-graph.php?host=" . $device['hostname'] . "&plugin=".$_GET['opta']."&type=".$_GET['opta']."&plugin_instance=".$instance."&type=".$type."&type_instance=".$tinst."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=400&height=150"; $weekly_url .= $args; - $monthly_traffic = "collectd-graph.php?host=" . $device['hostname'] . "&plugin=".$_GET['opta']."&type=".$_GET['opta']."&plugin_instance=".$instance."&type=".$type."&type_instance=".$tinst."&from=$month&to=$now&width=215&height=100"; + $monthly_traffic = "collectd-graph.php?host=" . $device['hostname'] . "&plugin=".$_GET['opta']."&type=".$_GET['opta']."&plugin_instance=".$instance."&type=".$type."&type_instance=".$tinst."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=215&height=100"; $monthly_traffic .= $args; - $monthly_url = "collectd-graph.php?host=" . $device['hostname'] . "&plugin=".$_GET['opta']."&type=".$_GET['opta']."&plugin_instance=".$instance."&type=".$type."&type_instance=".$tinst."&from=$month&to=$now&width=400&height=150"; + $monthly_url = "collectd-graph.php?host=" . $device['hostname'] . "&plugin=".$_GET['opta']."&type=".$_GET['opta']."&plugin_instance=".$instance."&type=".$type."&type_instance=".$tinst."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=400&height=150"; $monthly_url .= $args; - $yearly_traffic = "collectd-graph.php?host=" . $device['hostname'] . "&plugin=".$_GET['opta']."&type=".$_GET['opta']."&plugin_instance=".$instance."&type=".$type."&type_instance=".$tinst."&from=$year&to=$now&width=215&height=100"; + $yearly_traffic = "collectd-graph.php?host=" . $device['hostname'] . "&plugin=".$_GET['opta']."&type=".$_GET['opta']."&plugin_instance=".$instance."&type=".$type."&type_instance=".$tinst."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=215&height=100"; $yearly_traffic .= $args; - $yearly_url = "collectd-graph.php?host=" . $device['hostname'] . "&plugin=".$_GET['opta']."&type=".$_GET['opta']."&plugin_instance=".$instance."&type=".$type."&type_instance=".$tinst."&from=$year&to=$now&width=400&height=150"; + $yearly_url = "collectd-graph.php?host=" . $device['hostname'] . "&plugin=".$_GET['opta']."&type=".$_GET['opta']."&plugin_instance=".$instance."&type=".$type."&type_instance=".$tinst."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=400&height=150"; $yearly_url .= $args; diff --git a/html/pages/device/health/diskio.inc.php b/html/pages/device/health/diskio.inc.php index 3e8ddfced..d58fcabbf 100644 --- a/html/pages/device/health/diskio.inc.php +++ b/html/pages/device/health/diskio.inc.php @@ -17,11 +17,17 @@ foreach (dbFetchRows("SELECT * FROM `ucd_diskio` WHERE device_id = ? ORDER BY di $fs_url = "device/".$device['device_id']."/health/diskio/"; - $fs_popup = "onmouseover=\"return overlib('
".$device['hostname']." - ".$drive['diskio_descr']; - $fs_popup .= "
"; - $fs_popup .= "', RIGHT, FGCOLOR, '#e5e5e5');\" onmouseout=\"return nd();\""; + $graph_array_zoom['id'] = $drive['diskio_id']; + $graph_array_zoom['type'] = "diskio_ops"; + $graph_array_zoom['width'] = "400"; + $graph_array_zoom['height'] = "125"; + $graph_array_zoom['from'] = $config['time']['twoday']; + $graph_array_zoom['to'] = $config['time']['now']; + - echo("" . $drive['diskio_descr'] . ""); + echo(""); + echo(overlib_link($fs_url, $drive['diskio_descr'], generate_graph_tag($graph_array_zoom), NULL)); + echo(""); $types = array("diskio_bits", "diskio_ops"); @@ -29,6 +35,7 @@ foreach (dbFetchRows("SELECT * FROM `ucd_diskio` WHERE device_id = ? ORDER BY di { echo(''); + $graph_array = array(); $graph_array['id'] = $drive['diskio_id']; $graph_array['type'] = $graph_type; diff --git a/html/pages/device/hrdevice.inc.php b/html/pages/device/hrdevice.inc.php index e5a63dab0..a668e0bdf 100644 --- a/html/pages/device/hrdevice.inc.php +++ b/html/pages/device/hrdevice.inc.php @@ -44,7 +44,7 @@ foreach (dbFetchRows("SELECT * FROM `hrDevice` WHERE `device_id` = ? ORDER BY `h $graph_array_zoom = $graph_array; $graph_array_zoom['height'] = "150"; $graph_array_zoom['width'] = "400"; # FIXME click on graph should also link to port, but can't use generate_port_link here... - $mini_graph = overlib_link("#", generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL); + $mini_graph = overlib_link(generate_port_url($interface), generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL); echo("$mini_graph"); } else { diff --git a/html/pages/device/overview/generic/sensor.inc.php b/html/pages/device/overview/generic/sensor.inc.php index c6d54c6b9..8d2573e14 100644 --- a/html/pages/device/overview/generic/sensor.inc.php +++ b/html/pages/device/overview/generic/sensor.inc.php @@ -12,17 +12,19 @@ if (count($sensors)) { if (is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } + ### FIXME - make this "four graphs in popup" a function/include and "small graph" a function. + $graph_colour = str_replace("#", "", $row_colour); - $sensor_day = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=$day&to=$now&width=300&height=100"; - $sensor_week = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=$week&to=$now&width=300&height=100"; - $sensor_month = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=$month&to=$now&width=300&height=100"; - $sensor_year = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=$year&to=$now&width=300&height=100"; - $sensor_minigraph = ""; + $sensor_day = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=210&height=100"; + $sensor_week = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['week']."&to=".$config['time']['now']."&width=210&height=100"; + $sensor_month = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['month']."&to=".$config['time']['now']."&width=210&height=100"; + $sensor_year = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['year']."&to=".$config['time']['now']."&width=210&height=100"; + $sensor_minigraph = ""; $sensor_link = ""; + $sensor_link .= "
', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\" >"; $sensor_link_c = $sensor_link . " $sensor['sensor_limit'] ? "style='color: red'" : '') . '>' . $sensor['sensor_current'] . $sensor_unit . "
"; $sensor_link_b = $sensor_link . $sensor_minigraph . ""; diff --git a/html/pages/device/overview/ports.inc.php b/html/pages/device/overview/ports.inc.php index 7a711f7e7..227aeea22 100644 --- a/html/pages/device/overview/ports.inc.php +++ b/html/pages/device/overview/ports.inc.php @@ -17,13 +17,13 @@ if ($ports['total']) $content .= "
"; $graph_array['legend'] = "yes"; $graph_array['width'] = "340"; - $graph_array['from'] = $day; + $graph_array['from'] = $config['time']['day']; $content .= generate_graph_tag($graph_array); - $graph_array['from'] = $week; + $graph_array['from'] = $config['time']['week']; $content .= generate_graph_tag($graph_array); - $graph_array['from'] = $month; + $graph_array['from'] = $config['time']['month']; $content .= generate_graph_tag($graph_array); - $graph_array['from'] = $year; + $graph_array['from'] = $config['time']['year']; $content .= generate_graph_tag($graph_array); $content .= "
"; diff --git a/html/pages/graphs.inc.php b/html/pages/graphs.inc.php index f4d689da0..8616c9921 100644 --- a/html/pages/graphs.inc.php +++ b/html/pages/graphs.inc.php @@ -2,8 +2,8 @@ $id = $_GET['opta']; $graph_type = $_GET['optb']; -if (is_numeric($_GET['optc'])) { $from = $_GET['optc']; } else { $from = $day; } -if (is_numeric($_GET['optd'])) { $to = $_GET['optd']; } else { $to = $now; } +if (is_numeric($_GET['optc'])) { $from = $_GET['optc']; } else { $from = $config['time']['day']; } +if (is_numeric($_GET['optd'])) { $to = $_GET['optd']; } else { $to = $config['time']['now']; } preg_match('/^(?P[A-Za-z0-9]+)_(?P.+)/', mres($graph_type), $graphtype); @@ -28,13 +28,15 @@ if (!$auth) if (isset($config['graph_types'][$type][$subtype]['descr'])) { $title .= " :: ".$config['graph_types'][$type][$subtype]['descr']; } else { $title .= " :: ".$graph_type; } $graph_array['height'] = "60"; - $graph_array['width'] = "150"; + $graph_array['width'] = "125"; $graph_array['legend'] = "no"; $graph_array['to'] = $now; $graph_array['id'] = $id; $graph_array['type'] = $graph_type; - $graph_array['from'] = $day; - $graph_array_zoom = $graph_array; $graph_array_zoom['height'] = "150"; $graph_array_zoom['width'] = "400"; + + $graph_array_zoom = $graph_array; + $graph_array_zoom['height'] = "150"; + $graph_array_zoom['width'] = "400"; print_optionbar_start(); echo($title); @@ -44,55 +46,64 @@ if (!$auth) echo("
"); - echo("
+ $graph_array['from'] = $config['time']['sixhour']; + echo(""); + + $graph_array['from'] = $config['time']['day']; + echo(""); - $graph_array['from'] = $twoday; - echo("
+ $graph_array['from'] = $config['time']['twoday']; + echo(""); - $graph_array['from'] = $week; - echo("
+ $graph_array['from'] = $config['time']['week']; + echo(""); - $graph_array['from'] = $config['twoweek']; - echo("
+ $graph_array['from'] = $config['time']['twoweek']; + echo(""); - $graph_array['from'] = $month; - echo("
+ $graph_array['from'] = $config['time']['month']; + echo(""); - $graph_array['from'] = $config['twomonth']; - echo("
+ $graph_array['from'] = $config['time']['twomonth']; + echo(""); - $graph_array['from'] = $year; - echo("
+ $graph_array['from'] = $config['time']['year']; + echo("
Year
"); echo(generate_graph_tag($graph_array)); diff --git a/html/pages/health/storage.inc.php b/html/pages/health/storage.inc.php index 3b7a5c7f4..323353472 100644 --- a/html/pages/health/storage.inc.php +++ b/html/pages/health/storage.inc.php @@ -52,15 +52,22 @@ foreach (dbFetchRows("SELECT * FROM `storage` AS S, `devices` AS D WHERE S.devic $free = formatStorage($drive['storage_free']); $used = formatStorage($drive['storage_used']); - $store_url = "graph.php?id=" . $drive['storage_id'] . "&type=".$graph_type."&from=$month&to=$now&width=400&height=125"; - $store_popup = "onmouseover=\"return overlib('', LEFT);\" onmouseout=\"return nd();\""; - - $mini_graph = $config['base_url'] . "/graph.php?id=".$drive['storage_id']."&type=".$graph_type."&from=".$day."&to=".$now."&width=80&height=20&bg=f4f4f4"; + $graph_array['type'] = $graph_type; + $graph_array['id'] = $drive['storage_id']; + $graph_array['from'] = $config['time']['day']; + $graph_array['to'] = $config['time']['now']; + $graph_array['height'] = "20"; + $graph_array['width'] = "80"; + $graph_array_zoom = $graph_array; + $graph_array_zoom['height'] = "150"; + $graph_array_zoom['width'] = "400"; + $link = "graphs/" . $graph_array['id'] . "/" . $graph_array['type'] . "/" . $graph_array['from'] . "/" . $graph_array['to'] . "/"; + $mini_graph = overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL); $background = get_percentage_colours($perc); echo("" . generate_device_link($drive) . "" . $drive['storage_descr'] . " - + $mini_graph ".print_percentage_bar (400, 20, $perc, "$used / $total", "ffffff", $background['left'], $free, "ffffff", $background['right'])." $perc"."%"); @@ -70,26 +77,14 @@ foreach (dbFetchRows("SELECT * FROM `storage` AS S, `devices` AS D WHERE S.devic echo(""); - $daily_graph = "graph.php?id=" . $drive['storage_id'] . "&type=".$graph_type."&from=$day&to=$now&width=211&height=100"; - $daily_url = "graph.php?id=" . $drive['storage_id'] . "&type=".$graph_type."&from=$day&to=$now&width=400&height=150"; + $graph_array['height'] = "100"; + $graph_array['width'] = "216"; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $drive['storage_id']; + $graph_array['type'] = $graph_type; - $weekly_graph = "graph.php?id=" . $drive['storage_id'] . "&type=".$graph_type."&from=$week&to=$now&width=211&height=100"; - $weekly_url = "graph.php?id=" . $drive['storage_id'] . "&type=".$graph_type."&from=$week&to=$now&width=400&height=150"; + include("includes/print-quadgraphs.inc.php"); - $monthly_graph = "graph.php?id=" . $drive['storage_id'] . "&type=".$graph_type."&from=$month&to=$now&width=211&height=100"; - $monthly_url = "graph.php?id=" . $drive['storage_id'] . "&type=".$graph_type."&from=$month&to=$now&width=400&height=150"; - - $yearly_graph = "graph.php?id=" . $drive['storage_id'] . "&type=".$graph_type."&from=$year&to=$now&width=211&height=100"; - $yearly_url = "graph.php?id=" . $drive['storage_id'] . "&type=".$graph_type."&from=$year&to=$now&width=400&height=150"; - - echo("', LEFT);\" onmouseout=\"return nd();\"> - "); - echo("', LEFT);\" onmouseout=\"return nd();\"> - "); - echo("', LEFT);\" onmouseout=\"return nd();\"> - "); - echo("', LEFT);\" onmouseout=\"return nd();\"> - "); echo(""); } # endif graphs diff --git a/includes/dbFacile.php b/includes/dbFacile.php index 3b32757ac..a99318b35 100644 --- a/includes/dbFacile.php +++ b/includes/dbFacile.php @@ -72,7 +72,7 @@ function dbInsert($data, $table) { return $id; } else { if($table != 'Contact') { - trigger_error('QDB - Insert failed.', E_WARNING); + trigger_error('QDB - Insert failed.', E_USER_WARNING); } dbRollbackTransaction(); return false; @@ -113,7 +113,7 @@ function dbUpdate($data, $table, $where = null, $parameters = array()) { return mysql_affected_rows(); } else { #echo("$fullSql"); - trigger_error('QDB - Update failed.', E_WARNING); + trigger_error('QDB - Update failed.', E_USER_WARNING); return false; } } diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 2990e1b70..0f37f9b6e 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -7,21 +7,23 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, if ($debug) { echo("Discover sensor: $oid, $index, $type, $descr, $precision\n"); } - if (mysql_result(mysql_query("SELECT count(sensor_id) FROM `sensors` WHERE poller_type='" . mres($poller_type) . "' AND sensor_class='" . mres($class) . "' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'"),0) == '0') + if (dbFetchCell("SELECT COUNT(sensor_id) FROM `sensors` WHERE `poller_type`= ? AND `sensor_class` = ? AND `device_id` = ? AND sensor_type = ? AND `sensor_index` = ?", array($poller_type, $class, $device['device_id'], $type, $index)) == '0') { if (!$high_limit) { $high_limit = sensor_limit($class, $current); } if (!$low_limit) { $low_limit = sensor_low_limit($class, $current); } - $query = "INSERT INTO sensors (`poller_type`,`sensor_class`, `device_id`, `sensor_oid`, `sensor_index`, `sensor_type`, `sensor_descr`, `sensor_divisor`, `sensor_multiplier`, `sensor_limit`, `sensor_limit_warn`, `sensor_limit_low`, `sensor_limit_low_warn`, `sensor_current`) "; - $query .= " VALUES ('" . mres($poller_type) . "','" . mres($class) . "', '".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$divisor', '$multiplier', '$high_limit', '$warn_limit', '$low_limit', '$low_warn_limit', '$current')"; - mysql_query($query); - if ($debug) { echo("$query\n". mysql_affected_rows() . " inserted\n"); } + $insert = array('poller_type' => $poller_type, 'sensor_class' => $class, 'device_id' => $device['device_id'], 'sensor_oid' => $oid, 'sensor_index' => $index, 'sensor_type' => $type, 'sensor_descr' => $descr, + 'sensor_divisor' => $divisor, 'sensor_multiplier' => $multiplier, 'sensor_limit' => $high_limit, 'sensor_limit_warn' => $warn_limit, 'sensor_limit_low' => $low_limit, 'sensor_limit_low_warn' => $low_warn_limit, 'current' => $current); + + $inserted = dbInsert($insert, 'sensors'); + + if ($debug) { echo("( $inserted inserted )\n"); } echo("+"); log_event("Sensor Added: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr), $device, 'sensor', mysql_insert_id()); } else { - $sensor_entry = mysql_fetch_assoc(mysql_query("SELECT * FROM `sensors` WHERE sensor_class='" . mres($class) . "' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'")); + $sensor_entry = dbFetchRow("SELECT * FROM `sensors` WHERE `sensor_class` = ? AND `device_id` = ? AND `sensor_type` = ? AND `sensor_index` = ?", array($class, $device['device_id'], $type, $index)); if (!$high_limit) { @@ -35,9 +37,10 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, if ($high_limit != $sensor_entry['sensor_limit']) { - $query = "UPDATE sensors SET `sensor_limit` = " . ($high_limit == NULL ? 'NULL' : "'".$high_limit."'") . " WHERE `sensor_id` = '".$sensor_entry['sensor_id']."'"; - mysql_query($query); - if ($debug) { echo("$query\n". mysql_affected_rows() . " updated\n"); } + + $update = array('sensor_limit' => ($high_limit == NULL ? NULL : $high_limit)); + $updated = dbUpdate($update, '`sensor_id` = ?', array($sensor_entry['sensor_id'])); + if ($debug) { echo("( $updated updated )\n"); } echo("H"); log_event("Sensor High Limit Updated: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr)." (".$high_limit.")", $device, 'sensor', $sensor_id); } @@ -54,9 +57,9 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, if ($sensor_entry['sensor_limit_low'] != $low_limit) { - $query = "UPDATE sensors SET `sensor_limit_low` = " . ($low_limit == NULL ? 'NULL' : "'".$low_limit."'") . " WHERE `sensor_id` = '".$sensor_entry['sensor_id']."'"; - mysql_query($query); - if ($debug) { echo("$query\n". mysql_affected_rows() . " updated\n"); } + $update = array('sensor_limit_low' => ($low_limit == NULL ? NULL : $low_limit)); + $updated = dbUpdate($update, '`sensor_id` = ?', array($sensor_entry['sensor_id'])); + if ($debug) { echo("( $updated updated )\n"); } echo("L"); log_event("Sensor Low Limit Updated: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr)." (".$low_limit.")", $device, 'sensor', $sensor_id); } @@ -67,11 +70,12 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, } else { - $query = "UPDATE sensors SET `sensor_descr` = '$descr', `sensor_oid` = '$oid', `sensor_multiplier` = '$multiplier', `sensor_divisor` = '$divisor' WHERE `sensor_class` = '" . mres($class) . "' AND `device_id` = '" . $device['device_id'] . "' AND sensor_type = '$type' AND `sensor_index` = '$index'"; - mysql_query($query); - echo("U"); + + $update = array('sensor_oid' => $oid, 'sensor_descr' => $descr, 'sensor_multiplier' => $multiplier, 'sensor_divisor' => $divisor); + $updated = dbUpdate($update, '`sensor_id` = ?', array($sensor_entry['sensor_id'])); + echo("U"); log_event("Sensor Updated: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr), $device, 'sensor', $sensor_id); - if ($debug) { echo("$query\n". mysql_affected_rows() . " updated\n"); } + if ($debug) { echo("( $updated updated )\n"); } } } $valid[$class][$type][$index] = 1; @@ -142,19 +146,20 @@ function sensor_limit($class, $current) function check_valid_sensors($device, $class, $valid) { - $sql = "SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class='".$class."' AND S.device_id = D.device_id AND D.device_id = '".$device['device_id']."'"; - if ($query = mysql_query($sql)) + $entries = dbFetchRows("SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class=? AND S.device_id = D.device_id AND D.device_id = ?", array($class, $device['device_id'])); + + if (count($entries)) { - while ($test = mysql_fetch_assoc($query)) + foreach ($entries as $entry) { - $index = $test['sensor_index']; - $type = $test['sensor_type']; + $index = $entry['sensor_index']; + $type = $entry['sensor_type']; if ($debug) { echo($index . " -> " . $type . "\n"); } if (!$valid[$class][$type][$index]) { echo("-"); - mysql_query("DELETE FROM `sensors` WHERE sensor_class='".$class."' AND sensor_id = '" . $test['sensor_id'] . "'"); - log_event("Sensor Deleted: ".$test['sensor_class']." ".$test['sensor_type']." ". $test['sensor_index']." ".$test['sensor_descr'], $device, 'sensor', $sensor_id); + dbDelete('sensors', "`sensor_id` = ?", array($entry['sensor_id'])); + log_event("Sensor Deleted: ".$entry['sensor_class']." ".$entry['sensor_type']." ". $entry['sensor_index']." ".$entry['sensor_descr'], $device, 'sensor', $sensor_id); } unset($oid); unset($type); } @@ -165,11 +170,10 @@ function discover_juniAtmVp(&$valid, $interface_id, $vp_id, $vp_descr) { global $config, $debug; - if (mysql_result(mysql_query("SELECT COUNT(*) FROM `juniAtmVp` WHERE `interface_id` = '".$interface_id."' AND `vp_id` = '".$vp_id."'"),0) == "0") + if (dbFetchCell("SELECT COUNT(*) FROM `juniAtmVp` WHERE `interface_id` = ? AND `vp_id` = ?", array($interface_id, $vp_id)) == "0") { - $sql = "INSERT INTO `juniAtmVp` (`interface_id`,`vp_id`,`vp_descr`) VALUES ('".$interface_id."','".$vp_id."','".$vp_descr."')"; - mysql_query($sql); echo("+"); - if ($debug) { echo($sql . " - " . mysql_affected_rows() . "inserted "); } + $inserted = dbInsert(array('interface_id' => $interface_id,'vp_id' => $vp_id,'vp_descr' => $vp_descr), 'juniAtmVp'); + if ($debug) { echo("( $inserted inserted )\n"); } #FIXME vv no $device! log_event("Juniper ATM VP Added: port ".mres($interface_id)." vp ".mres($vp_id)." descr". mres($vp_descr), 'juniAtmVp', mysql_insert_id()); } @@ -184,27 +188,26 @@ function discover_link($local_interface_id, $protocol, $remote_interface_id, $re { global $config, $debug, $link_exists; - if (mysql_result(mysql_query("SELECT COUNT(*) FROM `links` WHERE `remote_hostname` = '$remote_hostname' AND `local_interface_id` = '$local_interface_id' - AND `protocol` = '$protocol' AND `remote_port` = '$remote_port'"),0) == "0") + if (dbFetchCell("SELECT COUNT(*) FROM `links` WHERE `remote_hostname` = ? AND `local_interface_id` = ? AND `protocol` = ? AND `remote_port` = ?", + array($remote_hostname, $local_interface_id, $protocol, $remote_port)) == "0") { - $sql = "INSERT INTO `links` (`local_interface_id`,`protocol`,`remote_interface_id`,`remote_hostname`,`remote_port`,`remote_platform`,`remote_version`) - VALUES ('$local_interface_id','$protocol','$remote_interface_id','$remote_hostname','$remote_port','$remote_platform','$remote_version')"; - mysql_query($sql); - echo("+"); if ($debug) { echo("$sql"); } + + $inserted = dbInsert(array('local_interface_id' => $local_interface_id,'protocol' => $protocol,'remote_interface_id' => $remote_interface_id,'remote_hostname' => $remote_hostname, + 'remote_port' => $remote_port,'remote_platform' => $remote_platform,'remote_version' => $remote_version), 'links'); + + echo("+"); if ($debug) { echo("( $inserted inserted )"); } } else { - $data = mysql_fetch_assoc(mysql_query("SELECT * FROM `links` WHERE `remote_hostname` = '$remote_hostname' AND `local_interface_id` = '$local_interface_id' - AND `protocol` = '$protocol' AND `remote_port` = '$remote_port'")); + $data = dbFetchRow("SELECT * FROM `links` WHERE `remote_hostname` = ? AND `local_interface_id` = ? AND `protocol` = ? AND `remote_port` = ?", array($remote_hostname, $local_interface_id, $protocol, $remote_port)); if ($data['remote_interface_id'] == $remote_interface_id && $data['remote_platform'] == $remote_platform && $remote_version == $remote_version) { echo("."); } else { - $sql = "UPDATE `links` SET `remote_interface_id` = $remote_interface_id, `remote_platform` = '$remote_platform', `remote_version` = '$remote_version' WHERE `id` = '".$data['id']."'"; - mysql_query($sql); - echo("U"); if ($debug) {echo("$sql"); } + $updated = dbUpdate(array('remote_interface_id' => $remote_interface_id, 'remote_platform' => $remote_platform, 'remote_version' => $remote_version), 'links', '`id` = ?', array($data['id'])); + echo("U"); if ($debug) { echo("( $updated updated )"); } } } $link_exists[$local_interface_id][$remote_hostname][$remote_port] = 1; @@ -217,21 +220,18 @@ function discover_storage(&$valid, $device, $index, $type, $mib, $descr, $size, if ($debug) { echo("$device, $index, $type, $mib, $descr, $units, $used, $size\n"); } if ($descr && $size > "0") { - if (mysql_result(mysql_query("SELECT count(storage_id) FROM `storage` WHERE `storage_index` = '$index' AND `device_id` = '".$device['device_id']."' AND `storage_mib` = '$mib'"),0) == '0') + $storage = dbFetchRow("SELECT * FROM `storage` WHERE `storage_index` = ? AND `device_id` = ? AND `storage_mib` = ?", array($index, $device['device_id'], $mib)); + if (!count($storage)) { - $query = "INSERT INTO storage (`device_id`, `storage_descr`, `storage_index`, `storage_mib`, `storage_type`, `storage_units`,`storage_size`,`storage_used`) - values ('".$device['device_id']."', '$descr', '$index', '$mib','$type', '$units', '$size', '$used')"; - mysql_query($query); - if ($debug) { print $query . "\n"; mysql_error(); } + $insert = dbInsert(array('device_id' => $device['device_id'], 'storage_descr' => $descr, 'storage_index' => $index, 'storage_mib' => $mib, 'storage_type' => $type, + 'storage_units' => $units, 'storage_size' => $size, 'storage_used' => $used), 'storage'); + if ($debug) { mysql_error(); } echo("+"); } else { - echo("."); - $query = "UPDATE `storage` SET `storage_descr` = '".$descr."', `storage_type` = '".$type."', `storage_units` = '".$units."', `storage_size` = '".$size."' - WHERE `device_id` = '".$device['device_id']."' AND `storage_index` = '".$index."' AND `storage_mib` = '".$mib."'"; - mysql_query($query); - if ($debug) { print $query . "\n"; } + $updated = dbUpdate(array('storage_descr' => $descr, 'storage_type' => $type, 'storage_units' => $units, 'storage_size' => $size), 'storage', '`device_id` = ? AND `storage_index` = ? AND `storage_mib` = ?', array($device['device_id'], $index, $mib)); + if($updated) { echo("U"); } else { echo("."); } } $valid[$mib][$index] = 1; } diff --git a/includes/static-config.php b/includes/static-config.php index 965f9bc74..fcf57581b 100644 --- a/includes/static-config.php +++ b/includes/static-config.php @@ -938,6 +938,8 @@ $observium_db = mysql_select_db($config['db_name'], $observium_link); # Set some times needed by loads of scripts (it's dynamic, so we do it here!) +## Please remove these where found replacing with $config['time'] + $now = time(); $day = time() - (24 * 60 * 60); $twoday = time() - (2 * 24 * 60 * 60); @@ -945,16 +947,20 @@ $week = time() - (7 * 24 * 60 * 60); $month = time() - (31 * 24 * 60 * 60); $year = time() - (365 * 24 * 60 * 60); -$config['now'] = time(); -$config['day'] = time() - (24 * 60 * 60); -$config['twoday'] = time() - (2 * 24 * 60 * 60); -$config['week'] = time() - (7 * 24 * 60 * 60); -$config['twoweek'] = time() - (2 * 7 * 24 * 60 * 60); -$config['month'] = time() - (31 * 24 * 60 * 60); -$config['twomonth'] = time() - (2 * 31 * 24 * 60 * 60); -$config['threemonth'] = time() - (3 * 31 * 24 * 60 * 60); -$config['sixmonth'] = time() - (6 * 31 * 24 * 60 * 60); -$config['year'] = time() - (365 * 24 * 60 * 60); + +$config['time']['now'] = time(); +$config['time']['fourhour'] = time() - (4 * 60 * 60); +$config['time']['sixhour'] = time() - (6 * 60 * 60); +$config['time']['twelvehour'] = time() - (12 * 60 * 60); +$config['time']['day'] = time() - (24 * 60 * 60); +$config['time']['twoday'] = time() - (2 * 24 * 60 * 60); +$config['time']['week'] = time() - (7 * 24 * 60 * 60); +$config['time']['twoweek'] = time() - (2 * 7 * 24 * 60 * 60); +$config['time']['month'] = time() - (31 * 24 * 60 * 60); +$config['time']['twomonth'] = time() - (2 * 31 * 24 * 60 * 60); +$config['time']['threemonth'] = time() - (3 * 31 * 24 * 60 * 60); +$config['time']['sixmonth'] = time() - (6 * 31 * 24 * 60 * 60); +$config['time']['year'] = time() - (365 * 24 * 60 * 60); # IPMI sensor type mappings $config['ipmi_unit']['Volts'] = 'voltage';