replace mysql_ with db* (update with caution, it works for me but...)

git-svn-id: http://www.observium.org/svn/observer/trunk@2282 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2011-05-12 17:59:00 +00:00
parent 66ca98fa63
commit 2522421528
8 changed files with 96 additions and 161 deletions
+21 -56
View File
@@ -33,7 +33,7 @@ function get_port_by_id($port_id)
{
if (is_numeric($port_id))
{
$port = mysql_fetch_assoc(mysql_query("SELECT * FROM `ports` WHERE `interface_id` = '".$port_id."'"));
$port = dbFetchRow("SELECT * FROM `ports` WHERE `interface_id` = ?", array($port_id));
}
if (is_array($port))
{
@@ -47,7 +47,7 @@ function get_application_by_id($application_id)
{
if (is_numeric($application_id))
{
$application = mysql_fetch_assoc(mysql_query("SELECT * FROM `applications` WHERE `app_id` = '".$application_id."'"));
$application = dbFetchRow("SELECT * FROM `applications` WHERE `app_id` = ?", array($application_id));
}
if (is_array($application))
{
@@ -61,7 +61,7 @@ function get_sensor_by_id($sensor_id)
{
if (is_numeric($sensor_id))
{
$sensor = mysql_fetch_assoc(mysql_query("SELECT * FROM `sensors` WHERE `sensor_id` = '".$sensor_id."'"));
$sensor = dbFetchRow("SELECT * FROM `sensors` WHERE `sensor_id` = ?", array($sensor_id));
}
if (is_array($sensor))
{
@@ -75,7 +75,7 @@ function get_device_id_by_interface_id($interface_id)
{
if (is_numeric($interface_id))
{
$device_id = mysql_result(mysql_query("SELECT `device_id` FROM `ports` WHERE `interface_id` = '".$interface_id."'"),0);
$device_id = dbFetchCell("SELECT `device_id` FROM `ports` WHERE `interface_id` = ?", array($interface_id));
}
if (is_numeric($device_id))
{
@@ -104,7 +104,7 @@ function device_by_id_cache($device_id)
{
$device = $device_cache[$device_id];
} else {
$device = mysql_fetch_assoc(mysql_query("SELECT * FROM `devices` WHERE `device_id` = '".$device_id."'"));
$device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device_id));
if (get_dev_attrib($device,'override_sysLocation_bool'))
{
$device['real_location'] = $device['location'];
@@ -130,18 +130,12 @@ function mres($string)
function getifhost($id)
{
$sql = mysql_query("SELECT `device_id` from `ports` WHERE `interface_id` = '$id'");
$result = @mysql_result($sql, 0);
return $result;
return dbFetchCell("SELECT `device_id` from `ports` WHERE `interface_id` = ?", array($id));
}
function gethostbyid($id)
{
$sql = mysql_query("SELECT `hostname` FROM `devices` WHERE `device_id` = '$id'");
$result = @mysql_result($sql, 0);
return $result;
return dbFetchCell("SELECT `hostname` FROM `devices` WHERE `device_id` = ?", array($id));
}
function strgen ($length = 16)
@@ -163,58 +157,37 @@ function strgen ($length = 16)
function getpeerhost($id)
{
$sql = mysql_query("SELECT `device_id` from `bgpPeers` WHERE `bgpPeer_id` = '$id'");
$result = @mysql_result($sql, 0);
return $result;
return dbFetchCell("SELECT `device_id` from `bgpPeers` WHERE `bgpPeer_id` = ?", array($id));
}
function getifindexbyid($id)
{
$sql = mysql_query("SELECT `ifIndex` FROM `ports` WHERE `interface_id` = '$id'");
$result = @mysql_result($sql, 0);
return $result;
return dbFetchCell("SELECT `ifIndex` FROM `ports` WHERE `interface_id` = ?", array($id));
}
function get_port_by_ifIndex($device, $ifIndex)
{
$sql = mysql_query("SELECT * FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'");
$result = @mysql_fetch_assoc($sql);
return $result;
return dbFetchCell("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?", array($device['device_id'], $ifIndex));
}
function getifbyid($id)
{
$sql = mysql_query("SELECT * FROM `ports` WHERE `interface_id` = '$id'");
$result = @mysql_fetch_assoc($sql);
return $result;
return dbFetchCell("SELECT * FROM `ports` WHERE `interface_id` = ?", array($id));
}
function getifdescrbyid($id)
{
$sql = mysql_query("SELECT `ifDescr` FROM `ports` WHERE `interface_id` = '$id'");
$result = @mysql_result($sql, 0);
return $result;
return dbFetchCell("SELECT `ifDescr` FROM `ports` WHERE `interface_id` = ?", array($id));
}
function getidbyname($domain)
{
$sql = mysql_query("SELECT `device_id` FROM `devices` WHERE `hostname` = '$domain'");
$result = @mysql_result($sql, 0);
return $result;
return dbFetchCell("SELECT `device_id` FROM `devices` WHERE `hostname` = ?", mres($domain));
}
function gethostosbyid($id)
{
$sql = mysql_query("SELECT `os` FROM `devices` WHERE `device_id` = '$id'");
$result = @mysql_result($sql, 0);
return $result;
return dbFetchCell("SELECT `os` FROM `devices` WHERE `device_id` = ?", array($id));
}
function safename($name)
@@ -234,27 +207,21 @@ function zeropad($num, $length = 2)
function set_dev_attrib($device, $attrib_type, $attrib_value)
{
$count_sql = "SELECT COUNT(*) FROM devices_attribs WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'";
if (mysql_result(mysql_query($count_sql),0))
if (dbFetchCell("SELECT COUNT(*) FROM devices_attribs WHERE `device_id` = ? AND `attrib_type` = ?", array($device['device_id'],$attrib_type)))
{
$update_sql = "UPDATE devices_attribs SET attrib_value = '$attrib_value' WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'";
mysql_query($update_sql);
$return = dbUpdate(array('attrib_value' => $attrib_value), 'devices_attribs', 'device_id=? and attrib_type=?', array($device['device_id'], $attrib_type));
}
else
{
$insert_sql = "INSERT INTO devices_attribs (`device_id`, `attrib_type`, `attrib_value`) VALUES ('" . mres($device['device_id'])."', '$attrib_type', '$attrib_value')";
mysql_query($insert_sql);
$return = dbInsert(array('device_id' => $device['device_id'], 'attrib_type' => $attrib_type, 'attrib_value' => $attrib_value), 'devices_attribs');
}
return mysql_affected_rows();
return $return;
}
function get_dev_attribs($device)
{
$attribs = array();
$sql = "SELECT * FROM devices_attribs WHERE `device_id` = '" . mres($device) . "'";
$query = mysql_query($sql);
while($entry = mysql_fetch_assoc($query))
foreach(dbFetch("SELECT * FROM devices_attribs WHERE `device_id` = ?", array($device)) as $entry)
{
$attribs[$entry['attrib_type']] = $entry['attrib_value'];
}
@@ -263,8 +230,7 @@ function get_dev_attribs($device)
function get_dev_attrib($device, $attrib_type)
{
$sql = "SELECT attrib_value FROM devices_attribs WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'";
if ($row = mysql_fetch_assoc(mysql_query($sql)))
if ($row = dbFetchRow("SELECT attrib_value FROM devices_attribs WHERE `device_id` = ? AND `attrib_type` = ?", array($device['device_id'], $attrib_type)))
{
return $row['attrib_value'];
}
@@ -276,8 +242,7 @@ function get_dev_attrib($device, $attrib_type)
function del_dev_attrib($device, $attrib_type)
{
$sql = "DELETE FROM devices_attribs WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'";
return mysql_query($sql);
return dbDelete('devices_attribs', "`device_id` = ? AND `attrib_type` = ?", array($device['device_id'], $attrib_type));
}
function formatRates($rate)
+38 -52
View File
@@ -109,9 +109,10 @@ function interface_errors($rrd_file, $period = '-1d') // Returns the last in/out
function getImage($host)
{
## FIXME why not pass $device? (my shitty ancient code here!)
global $config;
$sql = "SELECT * FROM `devices` WHERE `device_id` = '$host'";
$data = mysql_fetch_assoc(mysql_query($sql));
$data = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($host));
$type = strtolower($data['os']);
if ($config['os'][$type]['icon'] && file_exists($config['html_dir'] . "/images/os/" . $config['os'][$type]['icon'] . ".png"))
{
@@ -138,9 +139,9 @@ function renamehost($id, $new, $source = 'console')
{
global $config;
$host = dbFetchCell("SELECT hostname FROM devices WHERE device_id = '$id'");
$host = dbFetchCell("SELECT `hostname` FROM `devices` WHERE `device_id` = ?", array($id));
rename($config['rrd_dir']."/$host",$config['rrd_dir']."/$new");
mysql_query("UPDATE devices SET hostname = '$new' WHERE device_id = '$id'");
$return = dbUpdate(array('hostname' => $new), 'devices', 'device_id=?', array($id));
log_event("Hostname changed -> $new ($source)", $id, 'system');
}
@@ -148,17 +149,18 @@ function delete_port($int_id)
{
global $config;
$interface = mysql_fetch_assoc(mysql_query("SELECT * FROM `ports` AS P, `devices` AS D WHERE P.interface_id = '".$int_id."' AND D.device_id = P.device_id"));
mysql_query("DELETE from `adjacencies` WHERE `interface_id` = '$int_id'");
mysql_query("DELETE from `links` WHERE `local_interface_id` = '$int_id'");
mysql_query("DELETE from `links` WHERE `remote_interface_id` = '$int_id'");
mysql_query("DELETE from `ipaddr` WHERE `interface_id` = '$int_id'");
mysql_query("DELETE from `ip6adjacencies` WHERE `interface_id` = '$int_id'");
mysql_query("DELETE from `ip6addr` WHERE `interface_id` = '$int_id'");
mysql_query("DELETE from `mac_accounting` WHERE `interface_id` = '$int_id'");
mysql_query("DELETE FROM `bill_ports` WHERE `port_id` = '$int_id'");
mysql_query("DELETE from `pseudowires` WHERE `interface_id` = '$int_id'");
mysql_query("DELETE FROM `ports` WHERE `interface_id` = '$int_id'");
$interface = dbFetchRow("SELECT * FROM `ports` AS P, `devices` AS D WHERE P.interface_id = ? AND D.device_id = P.device_id", array($int_id));
$interface_tables = array('adjacencies', 'ipaddr', 'ip6adjacencies', 'ip6addr', 'mac_accounting', 'bill_ports', 'pseudowires', 'ports');
foreach($interface_tables as $table) {
dbDelete($table, "`interface_id` = ?", array($int_id));
}
dbDelete('links', "`local_interface_id` = ?", array($int_id));
dbDelete('links', "`remote_interface_id` = ?", array($int_id));
dbDelete('bill_ports', "`port_id` = ?", array($int_id));
unlink(trim($config['rrd_dir'])."/".trim($interface['hostname'])."/".$interface['ifIndex'].".rrd");
}
@@ -166,34 +168,25 @@ function delete_device($id)
{
global $config;
$host = dbFetchCell("SELECT hostname FROM devices WHERE device_id = '$id'");
mysql_query("DELETE FROM `devices` WHERE `device_id` = '$id'");
$int_query = mysql_query("SELECT * FROM `ports` WHERE `device_id` = '$id'");
while ($int_data = mysql_fetch_assoc($int_query))
$host = dbFetchCell("SELECT hostname FROM devices WHERE device_id = ?", array($id));
dbDelete('devices', "`device_id` = ?", array($id));
foreach (dbFetch("SELECT * FROM `ports` WHERE `device_id` = ?", array($id)) as $int_data)
{
$int_if = $int_data['ifDescr'];
$int_id = $int_data['interface_id'];
delete_port($int_id);
$ret .= "Removed interface $int_id ($int_if)\n";
}
$device_tables = array('entPhysical', 'devices_attribs', 'devices_perms', 'bgpPeers', 'vlans', 'vrfs', 'storage', 'alerts', 'eventlog',
'syslog', 'ports', 'services', 'alerts', 'toner', 'frequency', 'current', 'sensors');
foreach($device_tables as $table) {
dbDelete($table, "`device_id` = ?", array($id));
}
mysql_query("DELETE FROM `entPhysical` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `devices_attribs` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `devices_perms` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `bgpPeers` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `vlans` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `vrfs` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `storage` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `alerts` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `eventlog` WHERE `host` = '$id'");
mysql_query("DELETE FROM `syslog` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `ports` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `services` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `alerts` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `toner` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `frequency` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `current` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `sensors` WHERE `device_id` = '$id'");
shell_exec("rm -rf ".trim($config['rrd_dir'])."/$host");
$ret = "Removed Device $host\n";
@@ -395,10 +388,7 @@ function isDomainResolves($domain)
function hoststatus($id)
{
$sql = mysql_query("SELECT `status` FROM `devices` WHERE `device_id` = '$id'");
$result = @mysql_result($sql, 0);
return $result;
return dbFetchCell("SELECT `status` FROM `devices` WHERE `device_id` = ?", array($id));
}
function match_network($nets, $ip, $first=false)
@@ -478,14 +468,6 @@ function get_astext($asn)
}
}
# FIXME DEPRECATED -- only used in dead file includes/polling/interfaces.inc.php - if we no longer need that one, this can go too.
function eventlog($eventtext,$device_id = "", $interface_id = "")
{
$event_query = "INSERT INTO eventlog (host, interface, datetime, message) VALUES (" . ($device_id ? $device_id : "NULL");
$event_query .= ", " . ($interface_id ? $interface_id : "NULL") . ", NOW(), '" . mysql_escape_string($eventtext) . "')";
mysql_query($event_query);
}
# Use this function to write to the eventlog table
function log_event($text, $device = NULL, $type = NULL, $reference = NULL)
{
@@ -493,10 +475,14 @@ function log_event($text, $device = NULL, $type = NULL, $reference = NULL)
if (!is_array($device)) { $device = device_by_id_cache($device); }
$event_query = "INSERT INTO eventlog (host, reference, type, datetime, message) VALUES (" . ($device['device_id'] ? $device['device_id'] : "NULL");
$event_query .= ", '" . ($reference ? $reference : "NULL") . "', '" . ($type ? $type : "NULL") . "', NOW(), '" . mres($text) . "')";
if ($debug) { echo($event_query . "\n"); }
mysql_query($event_query);
$insert = array('host' => ($device['device_id'] ? $device['device_id'] : "NULL"),
'reference' => ($reference ? $reference : "NULL"),
'type' => ($type ? $type : "NULL"),
'datetime' => array("NOW()"),
'message' => $text);
return $dbInsert($insert, 'eventlog');
}
function notify($device,$title,$message)
+10 -4
View File
@@ -1,14 +1,20 @@
<?php
## FIXME who wrote this? so ugly :)
function add_service($service) {
global $id;
global $hostname;
echo("$service ");
$sql = "INSERT INTO `services` (`device_id`,`service_ip`,`service_type`,`service_desc`,`service_param`,`service_ignore`)
VALUES ('" . mres($id). "','" . mres($hostname) . "','" . mres($service) . "',
'" . mres("auto discovered: $service") . "','" . mres("") . "','0')";
$query = mysql_query($sql);
#$sql = "INSERT INTO `services` (`device_id`,`service_ip`,`service_type`,`service_desc`,`service_param`,`service_ignore`)
# VALUES ('" . mres($id). "','" . mres($hostname) . "','" . mres($service) . "',
# '" . mres("auto discovered: $service") . "','" . mres("") . "','0')";
$insert = array('device_id' => $id, 'service_ip' => $hostname, 'service_type' => $service, 'service_desc' => "auto discovered: $service", 'service_param' => "", 'service_ignore' => "0");
return $dbInsert($insert, 'services');
}
-9
View File
@@ -914,15 +914,6 @@ if (!isset($config['mibdir']))
}
$config['mib_dir'] = $config['mibdir'];
if (isset($config['enable_nagios']) && $config['enable_nagios']) {
$nagios_link = mysql_connect($config['nagios_db_host'], $config['nagios_db_user'], $config['nagios_db_pass']);
if (!$nagios_link) {
echo("<h2>Nagios MySQL Error</h2>");
die;
}
$nagios_db = mysql_select_db($config['nagios_db_name'], $nagios_link);
}
# If we're on SSL, let's properly detect it
if (isset($_SERVER['HTTPS']))
{
+7 -6
View File
@@ -25,8 +25,7 @@ function process_syslog ($entry, $update)
}
else
{
$device_id_ip = @dbFetchCell("SELECT device_id FROM ipv4_addresses AS A, ports AS I WHERE
A.ipv4_address = '" . $entry['host']."' AND I.interface_id = A.interface_id");
$device_id_ip = @dbFetchCell("SELECT device_id FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = '" . $entry['host']."' AND I.interface_id = A.interface_id");
if ($device_id_ip)
{
$entry['device_id'] = $device_id_ip;
@@ -87,10 +86,12 @@ function process_syslog ($entry, $update)
# }
}
$entry['program'] = strtoupper($entry['program']);
$x = "UPDATE `syslog` set `device_id` = '".$entry['device_id']."', `program` = '".$entry['program']."', `msg` = '" . mres($entry['msg']) . "', processed = '1' WHERE `seq` = '" . $entry['seq'] . "'";
$x = "INSERT INTO `syslog` (`device_id`,`program`,`facility`,`priority`, `level`, `tag`, `msg`, `timestamp`) ";
$x .= "VALUES ('".$entry['device_id']."','".$entry['program']."','".$entry['facility']."','".$entry['priority']."', '".$entry['level']."', '".$entry['tag']."', '".$entry['msg']."','".$entry['timestamp']."')";
if ($update && $entry['device_id']) { mysql_query($x); }
#$x = "UPDATE `syslog` set `device_id` = '".$entry['device_id']."', `program` = '".$entry['program']."', `msg` = '" . mres($entry['msg']) . "', processed = '1' WHERE `seq` = '" . $entry['seq'] . "'";
$insert_array = array('device_id' => $entry['device_id'], 'program' => $entry['program'], 'facility' => $entry['facility'], 'priority' => $entry['priority'],
'level' => $entry['level'], 'tag' => $entry['tag'], 'msg' => $entry['msg'], 'timestamp' => $entry['timestamp']);
if ($update && $entry['device_id']) { $dbInsert($insert_array, 'syslog'); }
unset ($fix);
} else { print_r($entry); echo("D-$delete"); }
-386
View File
@@ -1,386 +0,0 @@
<?php
## FIXME not used, do we still need this?
function mailerrorgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $config, $installdir;
$database = $config['rrd_dir'] . "/" . $rrd;
$period = $to - $from;
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
$range = $to - $from;
$points_per_sample = 3;
$xpoints = '540';
$step = $range*$points_per_sample/$xpoints;
$database = $config['rrd_dir'] . "/" . $rrd . "-mailstats.rrd";
$options .= " DEF:rejected=$database:reject:AVERAGE";
$options .= " DEF:mrejected=$database:reject:MAX";
$options .= " CDEF:rrejected=rejected,60,*";
$options .= " CDEF:drejected=rejected,UN,0,rejected,IF,$step,*";
$options .= " CDEF:srejected=PREV,UN,drejected,PREV,IF,drejected,+";
$options .= " CDEF:rmrejected=mrejected,60,*";
$options .= " DEF:bounced=$database:bounced:AVERAGE";
$options .= " DEF:mbounced=$database:bounced:MAX";
$options .= " CDEF:rbounced=bounced,60,*";
$options .= " CDEF:dbounced=bounced,UN,0,bounced,IF,$step,*";
$options .= " CDEF:sbounced=PREV,UN,dbounced,PREV,IF,dbounced,+";
$options .= " CDEF:rmbounced=mbounced,60,*";
$options .= " DEF:virus=$database:virus:AVERAGE";
$options .= " DEF:mvirus=$database:virus:MAX";
$options .= " CDEF:rvirus=virus,60,*";
$options .= " CDEF:dvirus=virus,UN,0,virus,IF,$step,*";
$options .= " CDEF:svirus=PREV,UN,dvirus,PREV,IF,dvirus,+";
$options .= " CDEF:rmvirus=mvirus,60,*";
$options .= " DEF:spam=$database:spam:AVERAGE";
$options .= " DEF:mspam=$database:spam:MAX";
$options .= " CDEF:rspam=spam,60,*";
$options .= " CDEF:dspam=spam,UN,0,spam,IF,$step,*";
$options .= " CDEF:sspam=PREV,UN,dspam,PREV,IF,dspam,+";
$options .= " CDEF:rmspam=mspam,60,*";
$options .= " COMMENT:Errors\ \ \ \ \ \ \ Total\ \ \ \ \ \ Average\ \ \ \ \ Maximum\\\\n";
$options .= " LINE1.25:rrejected#cc0000:reject";
$options .= " GPRINT:srejected:MAX:\ %6.0lf";
$options .= " GPRINT:rrejected:AVERAGE:\ \ %5.2lf/min";
$options .= " GPRINT:rmrejected:MAX:\ %5.2lf/min\\\\l";
$options .= " AREA:rbounced#0000cc:bounce";
$options .= " GPRINT:sbounced:MAX:\ %6.0lf";
$options .= " GPRINT:rbounced:AVERAGE:\ \ %5.2lf/min";
$options .= " GPRINT:rmbounced:MAX:\ %5.2lf/min\\\\l";
$options .= " STACK:rvirus#000000:virus\ ";
$options .= " GPRINT:svirus:MAX:\ %6.0lf";
$options .= " GPRINT:rvirus:AVERAGE:\ \ %5.2lf/min";
$options .= " GPRINT:rmvirus:MAX:\ %5.2lf/min\\\\l";
$options .= " STACK:rspam#00cc00:spam\ \ ";
$options .= " GPRINT:sspam:MAX:\ %6.0lf";
$options .= " GPRINT:rspam:AVERAGE:\ \ %5.2lf/min";
$options .= " GPRINT:rmspam:MAX:\ %5.2lf/min\\\\l";
shell_exec($config['rrdtool'] . " graph $graph $options");
return $graph;
}
function mailsgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $config, $installdir;
$database = $config['rrd_dir'] . "/" . $rrd;
$period = $to - $from;
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
$range = $to - $from;
$points_per_sample = 3;
$xpoints = '540';
$step = $range*$points_per_sample/$xpoints;
$rrd = $config['rrd_dir'] . "/" . $rrd;
$options .= " DEF:sent=$rrd:sent:AVERAGE";
$options .= " DEF:msent=$rrd:sent:MAX";
$options .= " CDEF:rsent=sent,60,*";
$options .= " CDEF:rmsent=msent,60,*";
$options .= " CDEF:dsent=sent,UN,0,sent,IF,$step,*";
$options .= " CDEF:ssent=PREV,UN,dsent,PREV,IF,dsent,+";
$options .= " DEF:recv=$rrd:rcvd:AVERAGE";
$options .= " DEF:mrecv=$rrd:rcvd:MAX";
$options .= " CDEF:rrecv=recv,60,*";
$options .= " CDEF:rmrecv=mrecv,60,*";
$options .= " CDEF:drecv=recv,UN,0,recv,IF,$step,*";
$options .= " CDEF:srecv=PREV,UN,drecv,PREV,IF,drecv,+";
$options .= " COMMENT:Mails\ \ \ \ \ \ Total\ \ \ \ \ \ \ Average\ \ \ \ \ Maximum\\\\n";
$options .= " AREA:rsent#00c000:sent";
$options .= " LINE1.25:rsent#005000:";
$options .= " GPRINT:ssent:MAX:\ \ %6.0lf";
$options .= " GPRINT:rsent:AVERAGE:\ \ %5.2lf/min";
$options .= " GPRINT:rmsent:MAX:\ %5.2lf/min\\\\l";
$options .= " LINE1.25:rrecv#cc0000:rcvd";
$options .= " GPRINT:srecv:MAX:\ \ %6.0lf";
$options .= " GPRINT:rrecv:AVERAGE:\ \ %5.2lf/min";
$options .= " GPRINT:rmrecv:MAX:\ %5.2lf/min\\\\l";
shell_exec($config['rrdtool'] . " graph $graph $options");
return $graph;
}
function memgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $config, $installdir;
$database = $config['rrd_dir'] . "/" . $rrd;
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height -b 1024";
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
$options .= " DEF:atotalswap=$database:totalswap:AVERAGE";
$options .= " DEF:aavailswap=$database:availswap:AVERAGE";
$options .= " DEF:atotalreal=$database:totalreal:AVERAGE";
$options .= " DEF:aavailreal=$database:availreal:AVERAGE";
$options .= " DEF:atotalfree=$database:totalfree:AVERAGE";
$options .= " DEF:ashared=$database:shared:AVERAGE";
$options .= " DEF:abuffered=$database:buffered:AVERAGE";
$options .= " DEF:acached=$database:cached:AVERAGE";
$options .= " CDEF:totalswap=atotalswap,1024,*";
$options .= " CDEF:availswap=aavailswap,1024,*";
$options .= " CDEF:totalreal=atotalreal,1024,*";
$options .= " CDEF:availreal=aavailreal,1024,*";
$options .= " CDEF:totalfree=atotalfree,1024,*";
$options .= " CDEF:shared=ashared,1024,*";
$options .= " CDEF:buffered=abuffered,1024,*";
$options .= " CDEF:cached=acached,1024,*";
$options .= " CDEF:usedreal=totalreal,availreal,-";
$options .= " CDEF:usedswap=totalswap,availswap,-";
$options .= " CDEF:cusedswap=usedswap,-1,*";
$options .= " CDEF:cdeftot=availreal,shared,buffered,usedreal,cached,usedswap,+,+,+,+,+";
$options .= " COMMENT:Bytes\ \ \ \ \ \ \ Current\ \ \ \ Average\ \ \ \ \ Maximum\\n";
$options .= " LINE1:usedreal#d0b080:";
$options .= " AREA:usedreal#f0e0a0:used";
$options .= " GPRINT:usedreal:LAST:\ \ \ %7.2lf%sB";
$options .= " GPRINT:usedreal:AVERAGE:%7.2lf%sB";
$options .= " GPRINT:usedreal:MAX:%7.2lf%sB\\\\n";
$options .= " STACK:availreal#e5e5e5:free";
$options .= " GPRINT:availreal:LAST:\ \ \ %7.2lf%sB";
$options .= " GPRINT:availreal:AVERAGE:%7.2lf%sB";
$options .= " GPRINT:availreal:MAX:%7.2lf%sB\\\\n";
$options .= " LINE1:usedreal#d0b080:";
$options .= " AREA:shared#afeced::";
$options .= " AREA:buffered#cc0000::STACK";
$options .= " AREA:cached#ffaa66::STACK";
$options .= " LINE1.25:shared#008fea:shared";
$options .= " GPRINT:shared:LAST:\ %7.2lf%sB";
$options .= " GPRINT:shared:AVERAGE:%7.2lf%sB";
$options .= " GPRINT:shared:MAX:%7.2lf%sB\\\\n";
$options .= " LINE1.25:buffered#ff1a00:buffers:STACK";
$options .= " GPRINT:buffered:LAST:%7.2lf%sB";
$options .= " GPRINT:buffered:AVERAGE:%7.2lf%sB";
$options .= " GPRINT:buffered:MAX:%7.2lf%sB\\\\n";
$options .= " LINE1.25:cached#ea8f00:cached:STACK";
$options .= " GPRINT:cached:LAST:\ %7.2lf%sB";
$options .= " GPRINT:cached:AVERAGE:%7.2lf%sB";
$options .= " GPRINT:cached:MAX:%7.2lf%sB\\\\n";
$options .= " LINE1:totalreal#050505:";
$options .= " AREA:cusedswap#C3D9FF:swap";
$options .= " LINE1.25:cusedswap#356AA0:";
$options .= " GPRINT:usedswap:LAST:\ \ \ %7.2lf%sB";
$options .= " GPRINT:usedswap:AVERAGE:%7.2lf%sB";
$options .= " GPRINT:usedswap:MAX:%7.2lf%sB\\\\n";
$options .= " LINE1:totalreal#050505:total";
$options .= " GPRINT:totalreal:AVERAGE:\ \ %7.2lf%sB";
shell_exec($config['rrdtool'] . " graph $graph $options");
return $graph;
}
function loadgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $config, $installdir;
$database = $config['rrd_dir'] . "/" . $rrd;
$period = $to - $from;
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
$options .= " DEF:1min=$database:1min:AVERAGE";
$options .= " DEF:5min=$database:5min:AVERAGE";
$options .= " DEF:15min=$database:15min:AVERAGE";
$options .= " CDEF:a=1min,100,/";
$options .= " CDEF:b=5min,100,/";
$options .= " CDEF:c=15min,100,/";
$options .= " CDEF:cdefd=a,b,c,+,+";
$options .= " COMMENT:Load\ Average\ \ Current\ \ \ \ Average\ \ \ \ Maximum\\\\n";
$options .= " AREA:a#ffeeaa:1\ Min:";
$options .= " LINE1:a#c5aa00:";
$options .= " GPRINT:a:LAST:\ \ \ \ %7.2lf";
$options .= " GPRINT:a:AVERAGE:\ \ %7.2lf";
$options .= " GPRINT:a:MAX:\ \ %7.2lf\\\\n";
$options .= " LINE1.25:b#ea8f00:5\ Min:";
$options .= " GPRINT:b:LAST:\ \ \ \ %7.2lf";
$options .= " GPRINT:b:AVERAGE:\ \ %7.2lf";
$options .= " GPRINT:b:MAX:\ \ %7.2lf\\\\n";
$options .= " LINE1.25:c#cc0000:15\ Min";
$options .= " GPRINT:c:LAST:\ \ \ %7.2lf";
$options .= " GPRINT:c:AVERAGE:\ \ %7.2lf";
$options .= " GPRINT:c:MAX:\ \ %7.2lf\\\\n";
shell_exec($config['rrdtool'] . " graph $graph $options");
return $graph;
}
function usersgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $config, $installdir;
$database = $config['rrd_dir'] . "/" . $rrd;
$period = $to - $from;
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height -l 0";
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
$options .= " DEF:users=$database:users:AVERAGE";
$options .= " COMMENT:Users\ \ \ \ \ \ \ Cur\ \ \ \ \ Ave\ \ \ \ \ \ Min\ \ \ \ \ Max\\\\n";
$options .= " AREA:users#CDEB8B:";
$options .= " LINE1.25:users#008C00:\ ";
$options .= " GPRINT:users:LAST:\ \ \ \ %6.2lf";
$options .= " GPRINT:users:AVERAGE:%6.2lf";
$options .= " GPRINT:users:MIN:%6.2lf";
$options .= " GPRINT:users:MAX:%6.2lf\\\\n";
shell_exec($config['rrdtool'] . " graph $graph $options");
return $graph;
}
function procsgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $config, $installdir;
$database = $config['rrd_dir'] . "/" . $rrd;
$period = $to - $from;
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height -l 0";
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
$options .= " DEF:procs=$database:procs:AVERAGE";
$options .= " COMMENT:Processes\ \ \ \ Cur\ \ \ \ \ Ave\ \ \ \ \ \ Min\ \ \ \ \ Max\\\\n";
$options .= " AREA:procs#CDEB8B:";
$options .= " LINE1.25:procs#008C00:\ ";
$options .= " GPRINT:procs:LAST:\ \ \ \ %6.2lf";
$options .= " GPRINT:procs:AVERAGE:%6.2lf";
$options .= " GPRINT:procs:MIN:%6.2lf";
$options .= " GPRINT:procs:MAX:%6.2lf\\\\n";
shell_exec($config['rrdtool'] . " graph $graph $options");
return $graph;
}
function cpugraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $config;
$database = $config['rrd_dir'] . "/" . $rrd;
$period = $to - $from;
$options = "-l 0 --alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
$options .= " DEF:user=$database:user:AVERAGE";
$options .= " DEF:nice=$database:nice:AVERAGE";
$options .= " DEF:system=$database:system:AVERAGE";
$options .= " DEF:idle=$database:idle:AVERAGE";
$options .= " CDEF:total=user,nice,system,idle,+,+,+";
$options .= " CDEF:user_perc=user,total,/,100,*";
$options .= " CDEF:nice_perc=nice,total,/,100,*";
$options .= " CDEF:system_perc=system,total,/,100,*";
$options .= " CDEF:idle_perc=idle,total,/,100,*";
$options .= " COMMENT:Usage\ \ \ \ \ \ \ Current\ \ \ \ \ Average\ \ \ \ Maximum\\\\n";
$options .= " AREA:user_perc#c02020:user";
$options .= " GPRINT:user_perc:LAST:\ \ \ \ \ %5.2lf%%";
$options .= " GPRINT:user_perc:AVERAGE:\ \ \ %5.2lf%%";
$options .= " GPRINT:user_perc:MAX:\ \ \ %5.2lf%%\\\\n";
$options .= " AREA:nice_perc#008f00:nice:STACK";
$options .= " GPRINT:nice_perc:LAST:\ \ \ \ \ %5.2lf%%";
$options .= " GPRINT:nice_perc:AVERAGE:\ \ \ %5.2lf%%";
$options .= " GPRINT:nice_perc:MAX:\ \ \ %5.2lf%%\\\\n";
$options .= " AREA:system_perc#ea8f00:system:STACK";
$options .= " GPRINT:system_perc:LAST:\ \ \ %5.2lf%%";
$options .= " GPRINT:system_perc:AVERAGE:\ \ \ %5.2lf%%";
$options .= " GPRINT:system_perc:MAX:\ \ \ %5.2lf%%\\\\n";
$options .= " AREA:idle_perc#f5f5e5:idle:STACK";
$options .= " GPRINT:idle_perc:LAST:\ \ \ \ \ %5.2lf%%";
$options .= " GPRINT:idle_perc:AVERAGE:\ \ \ %5.2lf%%";
$options .= " GPRINT:idle_perc:MAX:\ \ \ %5.2lf%%\\\\n";
shell_exec($config['rrdtool'] . " graph $graph $options");
return $graph;
}
function couriergraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $config, $installdir;
$database = $config['rrd_dir'] . "/" . $rrd;
$period = $to - $from;
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
$points_per_sample = 3;
$range = $to - $from;
$options .= " DEF:pop3d_login=$database:pop3:AVERAGE";
$options .= " DEF:mpop3d_login=$database:pop3:MAX";
$options .= " DEF:imapd_login=$database:imap:AVERAGE";
$options .= " DEF:mimapd_login=$database:imap:MAX";
$options .= " CDEF:rpop3d_login=pop3d_login,60,*";
$options .= " CDEF:vpop3d_login=pop3d_login,UN,0,pop3d_login,IF,$range,*";
$options .= " CDEF:rmpop3d_login=mpop3d_login,60,*";
$options .= " CDEF:rimapd_login=imapd_login,60,*";
$options .= " CDEF:vimapd_login=imapd_login,UN,0,imapd_login,IF,$range,*";
$options .= " CDEF:rmimapd_login=mimapd_login,60,*";
$options .= " DEF:pop3d_ssl_login=$database:pop3ssl:AVERAGE";
$options .= " DEF:mpop3d_ssl_login=$database:pop3ssl:MAX";
$options .= " DEF:imapd_ssl_login=$database:imapssl:AVERAGE";
$options .= " DEF:mimapd_ssl_login=$database:imapssl:MAX";
$options .= " CDEF:rpop3d_ssl_login=pop3d_ssl_login,60,*";
$options .= " CDEF:vpop3d_ssl_login=pop3d_ssl_login,UN,0,pop3d_ssl_login,IF,$range,*";
$options .= " CDEF:rmpop3d_ssl_login=mpop3d_ssl_login,60,*";
$options .= " CDEF:rimapd_ssl_login=imapd_ssl_login,60,*";
$options .= " CDEF:rmimapd_ssl_login=mimapd_ssl_login,60,*";
$options .= " CDEF:vimapd_ssl_login=imapd_ssl_login,UN,0,imapd_ssl_login,IF,$range,*";
$options .= " COMMENT:Logins\ \ \ \ \ \ \ \ \ Total\ \ \ \ Average\ \ \ \ Maximum\\\\n";
$options .= " LINE1.25:rpop3d_login#BB0000:pop3";
$options .= " GPRINT:vpop3d_login:AVERAGE:\ \ \ \ \ %6.0lf";
$options .= " GPRINT:rpop3d_login:AVERAGE:%5.2lf/min";
$options .= " GPRINT:rmpop3d_login:MAX:%5.2lf/min\\\\l";
$options .= " LINE1.25:rimapd_login#009900:imap";
$options .= " GPRINT:vimapd_login:AVERAGE:\ \ \ \ \ %6.0lf";
$options .= " GPRINT:rimapd_login:AVERAGE:%5.2lf/min";
$options .= " GPRINT:rmimapd_login:MAX:%5.2lf/min\\\\l";
$options .= " LINE1.25:rpop3d_ssl_login#000000:pop3-ssl";
$options .= " GPRINT:vpop3d_ssl_login:AVERAGE:\ %6.0lf";
$options .= " GPRINT:rpop3d_ssl_login:AVERAGE:%5.2lf/min";
$options .= " GPRINT:rmpop3d_ssl_login:MAX:%5.2lf/min\\\\l";
$options .= " LINE1.25:rimapd_ssl_login#000099:imap-ssl";
$options .= " GPRINT:vimapd_ssl_login:AVERAGE:\ %6.0lf";
$options .= " GPRINT:rimapd_ssl_login:AVERAGE:%5.2lf/min";
$options .= " GPRINT:rmimapd_ssl_login:MAX:%5.2lf/min\\\\l";
shell_exec($config['rrdtool'] . " graph $graph $options");
return $graph;
}
function apachehitsgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $config, $installdir;
$database = $config['rrd_dir'] . "/" . $rrd;
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height -l 0";
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
$options .= " DEF:hits=$database:hits:AVERAGE";
$options .= " COMMENT:\ \ \ \ \ \ \ \ \ \ \ \ Current\ \ \ \ \ Average\ \ \ \ \ Maximum\\\\n";
$options .= " AREA:hits#ff9933:";
$options .= " LINE1.25:hits#FF6600:Hits";
$options .= " GPRINT:hits:LAST:\ %6.2lf/sec";
$options .= " GPRINT:hits:AVERAGE:%6.2lf/sec";
$options .= " GPRINT:hits:MAX:%6.2lf/sec\\\\n";
shell_exec($config['rrdtool'] . " graph $graph $options");
return $graph;
}
function unixfsgraph ($id, $graph, $from, $to, $width, $height, $title, $vertical) {
global $config, $installdir;
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height -b 1024 -l 0";
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
$hostname = gethostbyid($device);
$iter = "1";
$sql = mysql_query("SELECT * FROM storage where storage_id = '$id'");
$options .= "COMMENT:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Size\ \ \ \ \ \ Used\ \ \ \ %age\l";
while($fs = mysql_fetch_array($sql)) {
$hostname = gethostbyid($fs['device_id']);
if($iter=="1") {$colour="CC0000";} elseif($iter=="2") {$colour="008C00";} elseif($iter=="3") {$colour="4096EE";
} elseif($iter=="4") {$colour="73880A";} elseif($iter=="5") {$colour="D01F3C";} elseif($iter=="6") {$colour="36393D";
} elseif($iter=="7") {$colour="FF0084"; $iter = "0"; }
$descr = str_pad($fs[storage_descr], 14);
$descr = substr($descr,0,14);
$text = str_replace("/", "_", $fs['storage_descr']);
$rrd = $config['rrd_dir'] . "/$hostname/storage-$text.rrd";
$options .= " DEF:$fs[storage_id]=$rrd:used:AVERAGE";
$options .= " DEF:$fs[storage_id]s=$rrd:size:AVERAGE";
$options .= " DEF:$fs[storage_id]p=$rrd:perc:AVERAGE";
$options .= " LINE1.25:$fs[storage_id]p#" . $colour . ":'$descr'";
$options .= " GPRINT:$fs[storage_id]s:LAST:%6.2lf%SB";
$options .= " GPRINT:$fs[storage_id]:LAST:%6.2lf%SB";
$options .= " GPRINT:$fs[storage_id]p:LAST:%5.2lf%%\\\\l";
$iter++;
}
shell_exec($config['rrdtool'] . " graph $graph $options");
return $graph;
}
function apachebitsgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $config, $installdir;
$database = $config['rrd_dir'] . "/" . $rrd;
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height -l 0";
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
$options .= " DEF:bits=$database:bits:AVERAGE";
$options .= " COMMENT:\ \ \ \ \ \ \ \ \ \ \ \ Current\ \ \ \ \ Average\ \ \ \ \ Maximum\\\\n";
$options .= " AREA:bits#cccc00:";
$options .= " LINE1.25:bits#9900:Bits";
$options .= " GPRINT:bits:LAST:\ %6.2lf/sec";
$options .= " GPRINT:bits:AVERAGE:%6.2lf/sec";
$options .= " GPRINT:bits:MAX:%6.2lf/sec\\\\n";
shell_exec($config['rrdtool'] . " graph $graph $options");
return $graph;
}