Updated most files to use dbFacile

This commit is contained in:
laf
2014-01-13 17:43:58 +00:00
parent a0650f0547
commit 02792176fa
45 changed files with 334 additions and 346 deletions

View File

@@ -22,7 +22,7 @@ include("includes/functions.php");
$options = getopt("r");
if (isset($options['r'])) { echo("Clearing history table.\n"); mysql_query("TRUNCATE TABLE `bill_history`"); }
if (isset($options['r'])) { echo("Clearing history table.\n"); dbQuery("TRUNCATE TABLE `bill_history`"); }
foreach (dbFetchRows("SELECT * FROM `bills` ORDER BY `bill_id`") as $bill)
{

View File

@@ -1,5 +1,8 @@
<?php
// MYSQL Check - FIXME
// 1 UNKNOWN
include( "config.php" );
$sql_file = $sqlfile ?: 'build.sql';

View File

@@ -4,7 +4,7 @@ $param = array();
if ($vars['action'] == "expunge" && $_SESSION['userlevel'] >= '10')
{
mysql_query("TRUNCATE TABLE `eventlog`");
dbQuery("TRUNCATE TABLE `bill_history`");
print_message("Event log truncated");
}

View File

@@ -23,12 +23,12 @@ $count_boxes = 0;
// Device down boxes
if ($_SESSION['userlevel'] == '10')
{
$sql = mysql_query("SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'");
$sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'";
} else {
$sql = mysql_query("SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.status = '0' AND D.ignore = '0'");
$sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.status = '0' AND D.ignore = '0'";
}
while ($device = mysql_fetch_assoc($sql)) {
foreach (dbFetchRows($sql) as $device)
{
generate_front_box("device-down", generate_device_link($device, shorthost($device['hostname']))."<br />
<span class=list-device-down>Device Down</span> <br />
<span class=body-date-1>".truncate($device['location'], 20)."</span>");
@@ -37,9 +37,9 @@ while ($device = mysql_fetch_assoc($sql)) {
if ($_SESSION['userlevel'] == '10')
{
$sql = mysql_query("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'");
$sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'";
} else {
$sql = mysql_query("SELECT * FROM `ports` AS I, `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'");
$sql = "SELECT * FROM `ports` AS I, `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'";
}
// These things need to become more generic, and more manageable across different frontpages... rewrite inc :>
@@ -47,7 +47,7 @@ $sql = mysql_query("SELECT * FROM `ports` AS I, `devices` AS D, devices_perms AS
// Port down boxes
if ($config['warn']['ifdown'])
{
while ($interface = mysql_fetch_assoc($sql))
foreach (dbFetchRows($sql) as $interface)
{
if (!$interface['deleted'])
{
@@ -64,8 +64,8 @@ if ($config['warn']['ifdown'])
/* FIXME service permissions? seem nonexisting now.. */
// Service down boxes
$sql = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'");
while ($service = mysql_fetch_assoc($sql))
$sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'";
foreach (dbFetchRows($sql) as $service)
{
generate_front_box("service-down", generate_device_link($service, shorthost($service['hostname']))."<br />
<span class=service-down>Service Down</span>
@@ -79,11 +79,11 @@ if (isset($config['enable_bgp']) && $config['enable_bgp'])
{
if ($_SESSION['userlevel'] == '10')
{
$sql = mysql_query("SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0");
$sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0";
} else {
$sql = mysql_query("SELECT * FROM `devices` AS D, bgpPeers AS B, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0");
$sql = "SELECT * FROM `devices` AS D, bgpPeers AS B, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0";
}
while ($peer = mysql_fetch_assoc($sql))
foreach (dbFetchRows($sql) as $peer)
{
generate_front_box("bgp-down", generate_device_link($peer, shorthost($peer['hostname']))."<br />
<span class=bgp-down>BGP Down</span>
@@ -98,13 +98,13 @@ if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $c
{
if ($_SESSION['userlevel'] == '10')
{
$sql = mysql_query("SELECT * FROM `devices` AS D WHERE D.status = '1' AND D.uptime > 0 AND D.uptime < '" . $config['uptime_warning'] . "' AND D.ignore = 0");
$sql = "SELECT * FROM `devices` AS D WHERE D.status = '1' AND D.uptime > 0 AND D.uptime < '" . $config['uptime_warning'] . "' AND D.ignore = 0";
} else {
$sql = mysql_query("SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.status = '1' AND D.uptime > 0 AND D.uptime < '" .
$config['uptime_warning'] . "' AND D.ignore = 0");
$sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.status = '1' AND D.uptime > 0 AND D.uptime < '" .
$config['uptime_warning'] . "' AND D.ignore = 0";
}
while ($device = mysql_fetch_assoc($sql))
foreach (dbFetchRows($sql) as $device)
{
generate_front_box("device-rebooted", generate_device_link($device, shorthost($device['hostname']))."<br />
<span class=device-rebooted>Device Rebooted</span><br />
@@ -153,7 +153,7 @@ if ($config['enable_syslog'])
</div>
<table class="table table-hover table-condensed table-striped">');
while ($entry = mysql_fetch_assoc($query))
foreach (dbFetchRows($sql) as $entry)
{
$entry = array_merge($entry, device_by_id_cache($entry['device_id']));
@@ -191,7 +191,8 @@ if ($config['enable_syslog'])
</div>
<table class="table table-hover table-condensed table-striped">');
while ($entry = mysql_fetch_assoc($data)) {
foreach (dbFetchRows($query) as $entry)
{
include("includes/print-event.inc.php");
}

View File

@@ -65,9 +65,10 @@ echo("</tr></table>");
$nodes = array();
$sql = mysql_query("SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' AND A.attrib_value < '86400'");
$sql = "SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' AND A.attrib_value < '86400'";
while ($device = mysql_fetch_array($sql)) {
foreach (dbFetchRows($sql) as $device)
{
unset($already);
$i = 0;
while ($i <= count($nodes)) {
@@ -80,8 +81,9 @@ while ($device = mysql_fetch_array($sql)) {
if (!$already) { $nodes[] = $device['device_id']; }
}
$sql = mysql_query("SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'");
while ($device = mysql_fetch_array($sql)) {
$sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'";
foreach (dbFetchRows($sql) as $device)
{
if (device_permitted($device['device_id'])) {
echo("<div style='text-align: center; margin: 2px; border: solid 2px #d0D0D0; float: left; margin-right: 2px; padding: 3px; width: 118px; height: 85px; background: #ffbbbb;'>
<strong>".generate_device_link($device, shorthost($device['hostname']))."</strong><br />
@@ -93,8 +95,8 @@ while ($device = mysql_fetch_array($sql)) {
if ($config['warn']['ifdown'])
{
$sql = mysql_query("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'");
while ($interface = mysql_fetch_array($sql))
$sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'";
foreach (dbFetchRows($sql) as $interface)
{
if (port_permitted($interface['port_id']))
{
@@ -108,8 +110,8 @@ if ($config['warn']['ifdown'])
}
}
$sql = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'");
while ($service = mysql_fetch_array($sql))
$sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'";
foreach (dbFetchRows($sql) as $service)
{
if (device_permitted($service['device_id']))
{
@@ -122,8 +124,8 @@ while ($service = mysql_fetch_array($sql))
}
}
$sql = mysql_query("SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id");
while ($peer = mysql_fetch_array($sql))
$sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id";
foreach (dbFetchRows($sql) as $peer)
{
if (device_permitted($peer['device_id']))
{
@@ -138,9 +140,9 @@ while ($peer = mysql_fetch_array($sql))
if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0)
{
$sql = mysql_query("SELECT * FROM devices_attribs AS A, `devices` AS D WHERE
A.attrib_value < '" . $config['uptime_warning'] . "' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'");
while ($device = mysql_fetch_array($sql))
$sql = "SELECT * FROM devices_attribs AS A, `devices` AS D WHERE
A.attrib_value < '" . $config['uptime_warning'] . "' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'";
foreach (dbFetchRows($sql) as $device)
{
if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == "uptime")
{
@@ -160,9 +162,8 @@ echo("
");
$sql = "SELECT *, DATE_FORMAT(timestamp, '%D %b %T') AS date from `syslog` ORDER BY seq DESC LIMIT 20";
$query = mysql_query($sql);
echo("<table cellspacing=0 cellpadding=2 width=100%>");
while ($entry = mysql_fetch_array($query))
foreach (dbFetchRows($sql) as $entry)
{
$entry = array_merge($entry, device_by_id_cache($entry['device_id']));

View File

@@ -3,15 +3,16 @@
<tr>
<td bgcolor=#e5e5e5 valign=top>
<?php
# <table width=100% border=0><tr><td><div style="margin-bottom: 5px; font-size: 18px; font-weight: bold;">Devices with Alerts</div></td><td width=35 align=center><div class=tablehead>Host</div></td><td align=center width=35><div class=tablehead>Int</div></td><td align=center width=35><div class=tablehead>Srv</div></tr>
?>
<?php
$nodes = array();
$sql = mysql_query("SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' AND A.attrib_value < '86400'");
$sql = "SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' AND A.attrib_value < '86400'";
while ($device = mysql_fetch_assoc($sql))
foreach (dbFetchRows($sql) as $device)
{
unset($already);
$i = 0;
@@ -27,9 +28,9 @@ while ($device = mysql_fetch_assoc($sql))
if (!$already) { $nodes[] = $device['device_id']; }
}
$sql = mysql_query("SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'");
while ($device = mysql_fetch_assoc($sql)) {
$sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'";
foreach (dbFetchRows($sql) as $device)
{
echo("<div style='border: solid 2px #d0D0D0; float: left; padding: 5px; width: 120px; height: 90px; background: #ffbbbb; margin: 4px;'>
<center><strong>".generate_device_link($device, shorthost($device['hostname']))."</strong><br />
<span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>Device Down</span>
@@ -38,9 +39,9 @@ while ($device = mysql_fetch_assoc($sql)) {
}
$sql = mysql_query("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'");
while ($interface = mysql_fetch_assoc($sql)) {
$sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'";
foreach (dbFetchRows($sql) as $interface)
{
echo("<div style='border: solid 2px #D0D0D0; float: left; padding: 5px; width: 120px; height: 90px; background: #ffddaa; margin: 4px;'>
<center><strong>".generate_device_link($interface, shorthost($interface['hostname']))."</strong><br />
<span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>Port Down</span>
@@ -50,9 +51,9 @@ while ($interface = mysql_fetch_assoc($sql)) {
}
$sql = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'");
while ($service = mysql_fetch_assoc($sql)) {
$sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'";
foreach (dbFetchRows($sql) as $service)
{
echo("<div style='border: solid 2px #D0D0D0; float: left; padding: 5px; width: 120px; height: 90px; background: #ffddaa; margin: 4px;'>
<center><strong>".generate_device_link($service, shorthost($service['hostname']))."</strong><br />
<span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>Service Down</span>
@@ -62,9 +63,9 @@ while ($service = mysql_fetch_assoc($sql)) {
}
$sql = mysql_query("SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerState != 'established' AND B.device_id = D.device_id");
while ($peer = mysql_fetch_assoc($sql)) {
$sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerState != 'established' AND B.device_id = D.device_id";
foreach (dbFetchRows($sql) as $peer)
{
echo("<div style='border: solid 2px #d0D0D0; float: left; padding: 5px; width: 120px; height: 90px; background: #ffddaa; margin: 4px;'>
<center><strong>".generate_device_link($peer, shorthost($peer['hostname']))."</strong><br />
<span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>BGP Down</span>
@@ -76,9 +77,9 @@ while ($peer = mysql_fetch_assoc($sql)) {
if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0)
{
$sql = mysql_query("SELECT * FROM `devices` AS D, devices_attribs AS A WHERE A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value < '" . $config['uptime_warning'] . "'");
while ($device = mysql_fetch_assoc($sql)) {
$sql = "SELECT * FROM `devices` AS D, devices_attribs AS A WHERE A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value < '" . $config['uptime_warning'] . "'";
foreach (dbFetchRows($sql) as $device)
{
echo("<div style='border: solid 2px #d0D0D0; float: left; padding: 5px; width: 120px; height: 90px; background: #ddffdd; margin: 4px;'>
<center><strong>".generate_device_link($device, shorthost($device['hostname']))."</strong><br />
<span style='font-size: 14px; font-weight: bold; margin: 5px; color: #090;'>Device<br />Rebooted</span><br />
@@ -96,9 +97,11 @@ echo("
");
$sql = "SELECT *, DATE_FORMAT(timestamp, '%D %b %T') AS date from syslog ORDER BY timestamp DESC LIMIT 20";
$query = mysql_query($sql);
echo("<table cellspacing=0 cellpadding=2 width=100%>");
while ($entry = mysql_fetch_assoc($query)) { include("includes/print-syslog.inc.php"); }
foreach (dbFetchRows($sql) as $entry)
{
include("includes/print-syslog.inc.php");
}
echo("</table>");
echo("</div>
@@ -110,31 +113,28 @@ echo("</div>
if ($_SESSION['userlevel'] >= '5')
{
$sql = "select * from ports as I, devices as D WHERE `ifAlias` like 'L2TP: %' AND I.device_id = D.device_id AND D.hostname LIKE '%";
$sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'L2TP: %' AND I.device_id = D.device_id AND D.hostname LIKE '%";
$sql .= $config['mydomain'] . "' ORDER BY I.ifAlias";
$query = mysql_query($sql);
unset ($seperator);
while ($interface = mysql_fetch_assoc($query))
foreach (dbFetchRows($sql) as $interface)
{
$ports['l2tp'] .= $seperator . $interface['port_id'];
$seperator = ",";
}
$sql = "select * from ports as I, devices as D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id AND D.hostname LIKE '%";
$sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id AND D.hostname LIKE '%";
$sql .= $config['mydomain'] . "' ORDER BY I.ifAlias";
$query = mysql_query($sql);
unset ($seperator);
while ($interface = mysql_fetch_assoc($query))
foreach (dbFetchRows($sql) as $interface)
{
$ports['transit'] .= $seperator . $interface['port_id'];
$seperator = ",";
}
$sql = "select * from ports as I, devices as D WHERE `ifAlias` like 'Server: thlon-pbx%' AND I.device_id = D.device_id AND D.hostname LIKE '%";
$sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Server: thlon-pbx%' AND I.device_id = D.device_id AND D.hostname LIKE '%";
$sql .= $config['mydomain'] . "' ORDER BY I.ifAlias";
$query = mysql_query($sql);
unset ($seperator);
while ($interface = mysql_fetch_assoc($query))
foreach (dbFetchRows($sql) as $interface)
{
$ports['voip'] .= $seperator . $interface['port_id'];
$seperator = ",";

View File

@@ -78,12 +78,12 @@ echo("<div style='padding: 3px 10px; background: #fff;'>");
if ($_SESSION['userlevel'] == '10')
{
$sql = mysql_query("SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'");
$sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'";
} else {
$sql = mysql_query("SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.status = '0' AND D.ignore = '0'");
$sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.status = '0' AND D.ignore = '0'";
}
while ($device = mysql_fetch_assoc($sql)) {
foreach (dbFetchRows($sql) as $device)
{
generate_front_box("#ffaaaa", "<center><strong>".generate_device_link($device, shorthost($device['hostname']))."</strong><br />
<span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>Device Down</span> <br />
<span class=body-date-1>".truncate($device['location'], 20)."</span>
@@ -93,16 +93,16 @@ while ($device = mysql_fetch_assoc($sql)) {
if ($_SESSION['userlevel'] == '10')
{
$sql = mysql_query("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'");
$sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'";
} else {
$sql = mysql_query("SELECT * FROM `ports` AS I, `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'");
$sql = "SELECT * FROM `ports` AS I, `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'";
}
// These things need to become more generic, and more manageable across different frontpages... rewrite inc :>
if ($config['warn']['ifdown'])
{
while ($interface = mysql_fetch_assoc($sql))
foreach (dbFetchRows($sql) as $interface)
{
if (!$interface['deleted'])
{
@@ -118,8 +118,8 @@ if ($config['warn']['ifdown'])
}
/* FIXME service permissions? seem nonexisting now.. */
$sql = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'");
while ($service = mysql_fetch_assoc($sql))
$sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'";
foreach (dbFetchRows($sql) as $service)
{
generate_front_box("#ffaaaa", "<center><strong>".generate_device_link($service, shorthost($service['hostname']))."</strong><br />
<span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>Service Down</span>
@@ -132,11 +132,11 @@ if (isset($config['enable_bgp']) && $config['enable_bgp'])
{
if ($_SESSION['userlevel'] == '10')
{
$sql = mysql_query("SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0");
$sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0";
} else {
$sql = mysql_query("SELECT * FROM `devices` AS D, bgpPeers AS B, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0");
$sql = "SELECT * FROM `devices` AS D, bgpPeers AS B, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0";
}
while ($peer = mysql_fetch_assoc($sql))
foreach (dbFetchRows($sql) as $peer)
{
generate_front_box("#ffaaaa", "<center><strong>".generate_device_link($peer, shorthost($peer['hostname']))."</strong><br />
<span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>BGP Down</span>
@@ -150,13 +150,13 @@ if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $c
{
if ($_SESSION['userlevel'] == '10')
{
$sql = mysql_query("SELECT * FROM `devices` AS D WHERE D.status = '1' AND D.uptime > 0 AND D.uptime < '" . $config['uptime_warning'] . "' AND D.ignore = 0");
$sql = "SELECT * FROM `devices` AS D WHERE D.status = '1' AND D.uptime > 0 AND D.uptime < '" . $config['uptime_warning'] . "' AND D.ignore = 0";
} else {
$sql = mysql_query("SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.status = '1' AND D.uptime > 0 AND D.uptime < '" .
$config['uptime_warning'] . "' AND D.ignore = 0");
$sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.status = '1' AND D.uptime > 0 AND D.uptime < '" .
$config['uptime_warning'] . "' AND D.ignore = 0";
}
while ($device = mysql_fetch_assoc($sql))
foreach (dbFetchRows($sql) as $device)
{
generate_front_box("#aaffaa", "<center><strong>".generate_device_link($device, shorthost($device['hostname']))."</strong><br />
<span style='font-size: 14px; font-weight: bold; margin: 5px; color: #009;'>Device<br />Rebooted</span><br />
@@ -173,9 +173,8 @@ if ($config['enable_syslog'])
");
$sql = "SELECT *, DATE_FORMAT(timestamp, '%D %b %T') AS date from syslog ORDER BY timestamp DESC LIMIT 20";
$query = mysql_query($sql);
echo("<table cellspacing=0 cellpadding=2 width=100%>");
while ($entry = mysql_fetch_assoc($query))
foreach (dbFetchRows($sql) as $entry)
{
$entry = array_merge($entry, device_by_id_cache($entry['device_id']));
@@ -200,11 +199,9 @@ if ($config['enable_syslog'])
P.device_id AND P.user_id = " . $_SESSION['user_id'] . " ORDER BY `datetime` DESC LIMIT 0,15";
}
$data = mysql_query($query);
echo('<table cellspacing="0" cellpadding="1" width="100%">');
while ($entry = mysql_fetch_assoc($data)) {
foreach (dbFetchRows($query) as $entry) {
include("includes/print-event.inc.php");
}

View File

@@ -1,4 +1,3 @@
<table border=0 cellpadding=10 cellspacing=10 width=100%>
<tr>
<td bgcolor=#e5e5e5 valign=top>
@@ -12,9 +11,10 @@ if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $c
$uptimesql = " AND A.attrib_value < '" . $config['uptime_warning'] . "'";
}
$sql = mysql_query("SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' " . $uptimesql);
$sql = "SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' " . $uptimesql;
while ($device = mysql_fetch_assoc($sql)) {
foreach (dbFetchRows($sql) as $device)
{
unset($already);
$i = 0;
while ($i <= count($nodes)) {
@@ -27,8 +27,9 @@ while ($device = mysql_fetch_assoc($sql)) {
if (!$already) { $nodes[] = $device['device_id']; }
}
$sql = mysql_query("SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'");
while ($device = mysql_fetch_assoc($sql)) {
$sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'";
foreach (dbFetchRows($sql) as $device)
{
if (device_permitted($device['device_id'])) {
echo("<div style='text-align: center; margin: 2px; border: solid 2px #d0D0D0; float: left; margin-right: 2px; padding: 3px; width: 118px; height: 85px; background: #ffbbbb;'>
<strong>".generate_device_link($device, shorthost($device['hostname']))."</strong><br />
@@ -40,8 +41,9 @@ while ($device = mysql_fetch_assoc($sql)) {
if ($config['warn']['ifdown']) {
$sql = mysql_query("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'");
while ($interface = mysql_fetch_assoc($sql)) {
$sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'";
foreach (dbFetchRows($sql) as $interface)
{
if (port_permitted($interface['port_id'])) {
echo("<div style='text-align: center; margin: 2px; border: solid 2px #D0D0D0; float: left; margin-right: 2px; padding: 3px; width: 118px; height: 85px; background: #ffddaa;'>
<strong>".generate_device_link($interface, shorthost($interface['hostname']))."</strong><br />
@@ -54,8 +56,9 @@ while ($interface = mysql_fetch_assoc($sql)) {
}
$sql = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'");
while ($service = mysql_fetch_assoc($sql)) {
$sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'";
foreach (dbFetchRows($sql) as $service)
{
if (device_permitted($service['device_id'])) {
echo("<div style='text-align: center; margin: 2px; border: solid 2px #D0D0D0; float: left; margin-right: 2px; padding: 3px; width: 118px; height: 85px; background: #ffddaa;'>
<strong>".generate_device_link($service, shorthost($service['hostname']))."</strong><br />
@@ -66,8 +69,9 @@ while ($service = mysql_fetch_assoc($sql)) {
}
}
$sql = mysql_query("SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id");
while ($peer = mysql_fetch_assoc($sql)) {
$sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id";
foreach (dbFetchRows($sql) as $peer)
{
if (device_permitted($peer['device_id'])) {
echo("<div style='text-align: center; margin: 2px; border: solid 2px #D0D0D0; float: left; margin-right: 2px; padding: 3px; width: 118px; height: 85px; background: #ffddaa;'>
<strong>".generate_device_link($peer, shorthost($peer['hostname']))."</strong><br />
@@ -80,8 +84,8 @@ while ($peer = mysql_fetch_assoc($sql)) {
if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0)
{
$sql = mysql_query("SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < '" . $config['uptime_warning'] . "' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'");
while ($device = mysql_fetch_assoc($sql)) {
$sql = "SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < '" . $config['uptime_warning'] . "' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'";
foreach (dbFetchRows($sql) as $device) {
if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == "uptime") {
echo("<div style='text-align: center; margin: 2px; border: solid 2px #D0D0D0; float: left; margin-right: 2px; padding: 3px; width: 118px; height: 85px; background: #ddffdd;'>
<strong>".generate_device_link($device, shorthost($device['hostname']))."</strong><br />
@@ -101,9 +105,11 @@ echo("
");
$sql = "SELECT *, DATE_FORMAT(timestamp, '%D %b %T') AS date from syslog,devices WHERE syslog.device_id = devices.device_id ORDER BY seq DESC LIMIT 20";
$query = mysql_query($sql);
echo("<table cellspacing=0 cellpadding=2 width=100%>");
while ($entry = mysql_fetch_assoc($query)) { include("includes/print-syslog.inc.php"); }
foreach (dbFetchRows($sql) as $entry)
{
include("includes/print-syslog.inc.php");
}
echo("</table>");
echo("</div>
@@ -116,18 +122,18 @@ echo("</div>
if ($_SESSION['userlevel'] >= '5')
{
$sql = "select * from ports as I, devices as D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias";
$query = mysql_query($sql);
$sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias";
unset ($seperator);
while ($interface = mysql_fetch_assoc($query)) {
foreach (dbFetchRows($sql) as $interface)
{
$ports['transit'] .= $seperator . $interface['port_id'];
$seperator = ",";
}
$sql = "select * from ports as I, devices as D WHERE `ifAlias` like 'Peering: %' AND I.device_id = D.device_id ORDER BY I.ifAlias";
$query = mysql_query($sql);
$sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Peering: %' AND I.device_id = D.device_id ORDER BY I.ifAlias";
unset ($seperator);
while ($interface = mysql_fetch_assoc($query)) {
foreach (dbFetchRows($sql) as $interface)
{
$ports['peering'] .= $seperator . $interface['port_id'];
$seperator = ",";
}

View File

@@ -1,4 +1,3 @@
<table border=0 cellpadding=10 cellspacing=10 width=100%>
<tr>
<td bgcolor=#e5e5e5 valign=top>
@@ -100,9 +99,11 @@ echo("
");
$sql = "SELECT *, DATE_FORMAT(timestamp, '%D %b %T') AS date from syslog,devices WHERE syslog.device_id = devices.device_id ORDER BY seq DESC LIMIT 20";
$query = mysql_query($sql);
echo("<table cellspacing=0 cellpadding=2 width=100%>");
while ($entry = mysql_fetch_assoc($query)) { include("includes/print-syslog.inc.php"); }
foreach (dbFetchRows($sql) as $entry)
{
include("includes/print-syslog.inc.php");
}
echo("</table>");
echo("</div>
@@ -115,26 +116,26 @@ echo("</div>
if ($_SESSION['userlevel'] >= '5')
{
$sql = "select * from ports as I, devices as D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias";
$query = mysql_query($sql);
$sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias";
unset ($seperator);
while ($interface = mysql_fetch_assoc($query)) {
foreach (dbFetchRows($sql) as $interface)
{
$ports['transit'] .= $seperator . $interface['port_id'];
$seperator = ",";
}
$sql = "select * from ports as I, devices as D WHERE `ifAlias` like 'Peering: %' AND I.device_id = D.device_id ORDER BY I.ifAlias";
$query = mysql_query($sql);
$sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Peering: %' AND I.device_id = D.device_id ORDER BY I.ifAlias";
unset ($seperator);
while ($interface = mysql_fetch_assoc($query)) {
foreach (dbFetchRows($sql) as $interface)
{
$ports['peering'] .= $seperator . $interface['port_id'];
$seperator = ",";
}
$sql = "select * from ports as I, devices as D WHERE `ifAlias` like 'Core: %' AND I.device_id = D.device_id ORDER BY I.ifAlias";
$query = mysql_query($sql);
$sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Core: %' AND I.device_id = D.device_id ORDER BY I.ifAlias";
unset ($seperator);
while ($interface = mysql_fetch_assoc($query)) {
foreach (dbFetchRows($sql) as $interface)
{
$ports['core'] .= $seperator . $interface['port_id'];
$seperator = ",";
}

View File

@@ -15,7 +15,7 @@ foreach (explode("\n", $ipNetToMedia_data) as $data)
$ip = $first .".". $second .".". $third .".". $fourth;
if ($ip != '...')
{
$interface = mysql_fetch_assoc(mysql_query("SELECT * FROM ports WHERE device_id = '".$device['device_id']."' AND ifIndex = '".$if."'"));
$interface = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?",array($device['device_id'],$if));
list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(":", $mac);
$m_a = zeropad($m_a);$m_b = zeropad($m_b);$m_c = zeropad($m_c);$m_d = zeropad($m_d);$m_e = zeropad($m_e);$m_f = zeropad($m_f);
@@ -29,37 +29,37 @@ foreach (explode("\n", $ipNetToMedia_data) as $data)
$port_id = $interface['port_id'];
$mac_table[$port_id][$clean_mac] = 1;
if (mysql_result(mysql_query("SELECT COUNT(*) from ipv4_mac WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'"),0))
if (dbFetchCell("SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ?",array($interface['port_id'], $ip)))
{
$sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'";
$old_mac = mysql_fetch_row(mysql_query("SELECT mac_address from ipv4_mac WHERE ipv4_address='$ip' AND port_id = '".$interface['port_id']."'"));
// Commented below, no longer needed but leaving for reference.
//$sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'";
$old_mac = dbFetchCell("SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=?",array($ip,$interface['port_id']));
if ($clean_mac != $old_mac[0] && $clean_mac != '' && $old_mac[0] != '')
{
if ($debug) { echo("Changed mac address for $ip from $old_mac[0] to $clean_mac\n"); }
log_event("MAC change: $ip : " . mac_clean_to_readable($old_mac[0]) . " -> " . mac_clean_to_readable($clean_mac), $device, "interface", $interface['port_id']);
}
mysql_query($sql);
dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=?',array($interface['port_id'],$ip));
echo(".");
}
else
{
echo("+");
#echo("Add MAC $mac\n");
mysql_query("INSERT INTO `ipv4_mac` (port_id, mac_address, ipv4_address) VALUES ('".$interface['port_id']."','$clean_mac','$ip')");
dbInsert(array('port_id' => $interface['port_id'], 'mac_address' => $clean_mac, 'ipv4_address' => $ip), 'ipv4_mac');
}
}
}
$sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = '".$device['device_id']."'";
$query = mysql_query($sql);
while ($entry = mysql_fetch_assoc($query))
foreach (dbFetchRows($sql) as $entry)
{
$entry_mac = $entry['mac_address'];
$entry_if = $entry['port_id'];
if (!$mac_table[$entry_if][$entry_mac])
{
mysql_query("DELETE FROM ipv4_mac WHERE port_id = '".$entry_if."' AND mac_address = '".$entry_mac."'");
dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ?', array($entry_if,$entry_mac));
if ($debug) { echo("Removing MAC $entry_mac from interface ".$interface['ifName']); }
echo("-");
}
@@ -68,4 +68,4 @@ while ($entry = mysql_fetch_assoc($query))
echo("\n");
unset($mac);
?>
?>

View File

@@ -16,7 +16,8 @@ if ($config['enable_bgp'])
if ($bgpLocalAs != $device['bgpLocalAs'])
{
mysql_query("UPDATE devices SET bgpLocalAs = '$bgpLocalAs' WHERE device_id = '".$device['device_id']."'"); echo("Updated AS ");
dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?',array($device['device_id']));
echo("Updated AS ");
}
$peers_data = snmp_walk($device, "BGP4-MIB::bgpPeerRemoteAs", "-Oq", "BGP4-MIB", $config['mibdir']);
@@ -61,7 +62,8 @@ if ($config['enable_bgp'])
echo("No BGP on host");
if ($device['bgpLocalAs'])
{
mysql_query("UPDATE devices SET bgpLocalAs = NULL WHERE device_id = '".$device['device_id']."'"); echo(" (Removed ASN) ");
dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?',array($device['device_id']));
echo(" (Removed ASN) ");
} # End if
} # End if
@@ -73,12 +75,12 @@ if ($config['enable_bgp'])
{
$astext = get_astext($peer['as']);
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `bgpPeers` WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'"),0) < '1')
if (dbFetchCell("SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?",array($device['device_id'], $peer['ip'])) < '1')
{
$add = mysql_query("INSERT INTO bgpPeers (`device_id`, `bgpPeerIdentifier`, `bgpPeerRemoteAS`) VALUES ('".$device['device_id']."','".$peer['ip']."','".$peer['as']."')");
$add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as']), 'bgpPeers');
echo("+");
} else {
$update = mysql_query("UPDATE `bgpPeers` SET bgpPeerRemoteAs = " . $peer['as'] . ", astext = '" . mres($astext) . "' WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'");
$update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?',array($device['device_id'],$peer['ip']));
echo(".");
}
@@ -102,9 +104,9 @@ if ($config['enable_bgp'])
if ($afi && $safi)
{
$af_list[$afi][$safi] = 1;
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `bgpPeers_cbgp` WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."' AND afi = '$afi' AND safi = '$safi'"),0) == 0)
if (dbFetchCell("SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=?",array($device['device_id'], $peer['ip'],$afi,$safi)) == 0)
{
mysql_query("INSERT INTO `bgpPeers_cbgp` (device_id,bgpPeerIdentifier, afi, safi) VALUES ('".$device['device_id']."','".$peer['ip']."','$afi','$safi')");
dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp');
}
}
}
@@ -156,21 +158,21 @@ if ($config['enable_bgp'])
{
list ($afi,$safi) = explode('.',$afisafi); $safi = $safis[$safi];
$af_list[$afi][$safi] = 1;
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `bgpPeers_cbgp` WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."' AND afi = '$afi' AND safi = '$safi'"),0) == 0)
if (dbFetchCell("SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=?",array($device['device_id'], $peer['ip'],$afi,$safi)) == 0)
{
mysql_query("INSERT INTO `bgpPeers_cbgp` (device_id,bgpPeerIdentifier, afi, safi) VALUES ('".$device['device_id']."','".$peer['ip']."','$afi','$safi')");
dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp');
}
}
} # os=junos
$af_query = mysql_query("SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'");
while ($entry = mysql_fetch_assoc($af_query))
$af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'";
foreach (dbFetchRows($af_query) as $entry)
{
$afi = $entry['afi'];
$safi = $entry['safi'];
if (!$af_list[$afi][$safi])
{
mysql_query("DELETE FROM `bgpPeers_cbgp` WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."' AND afi = '$afi' AND safi = '$safi'");
dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=?', array($device['device_id'],$peer['ip'],$afi,$safi));
}
} # AF list
} # os=cisco|junos
@@ -185,9 +187,8 @@ if ($config['enable_bgp'])
// Delete removed peers
$sql = "SELECT * FROM bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id AND D.device_id = '".$device['device_id']."'";
$query = mysql_query($sql);
while ($entry = mysql_fetch_assoc($query))
foreach (dbFetchRows($sql) as $entry)
{
unset($exists);
$i = 0;
@@ -200,8 +201,8 @@ if ($config['enable_bgp'])
if (!isset($exists))
{
mysql_query("DELETE FROM bgpPeers WHERE bgpPeer_id = '" . $entry['bgpPeer_id'] . "'");
mysql_query("DELETE FROM bgpPeers_cbgp WHERE bgpPeer_id = '" . $entry['bgpPeer_id'] . "'");
dbDelete('bgpPeers', '`bgpPeer_id` = ?', array($entry['bgpPeer_id']));
dbDelete('bgpPeers_cbgp', '`bgpPeer_id` = ?', array($entry['bgpPeer_id']));
echo("-");
}
}

View File

@@ -31,12 +31,9 @@ if (is_array($cefs))
echo(" | |-".$path.": ".$path_name['cefSwitchingPath']."\n");
$cef_exists[$device['device_id']][$entity][$afi][$path] = 1;
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `cef` WHERE `device_id` = '".$device['device_id']."' AND `entPhysicalIndex` = '".$entity."'
AND `afi` = '".$afi."' AND `cef_index` = '".$path."'"),0) != "1")
if (dbFetchCell("SELECT COUNT(*) from `cef` WHERE device_id = ? AND entPhysicalIndex = ?, AND afi=? AND cef_index=?",array($device['device_id'], $entity,$afi,$path)) != "1")
{
$sql = "INSERT INTO `cef` (`device_id`, `entPhysicalIndex`, `afi`, `cef_index`, `cef_path`)
VALUES ('".$device['device_id']."', '".$entity."', '".$afi."', '".$path."', '".$path_name['cefSwitchingPath']."')";
mysql_query($sql);
dbInsert(array('device_id' => $device['device_id'], 'entPhysicalIndex' => $entity, 'afi' => $afi, 'cef_path' => $path), 'cef');
echo("+");
}

View File

@@ -13,7 +13,7 @@ if ($device['os_group'] == "cisco")
list($if, $direction, $a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(".", $oid);
$oid = "$a_a.$a_b.$a_c.$a_d.$a_e.$a_f";
unset($interface);
$interface = mysql_fetch_assoc(mysql_query("SELECT * FROM ports WHERE device_id = '".$device['device_id']."' AND ifIndex = '".$if."'"));
$interface = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?",array($device['device_id'],$if));
$ah_a = zeropad(dechex($a_a));
$ah_b = zeropad(dechex($a_b));
$ah_c = zeropad(dechex($a_c));
@@ -28,7 +28,8 @@ if ($device['os_group'] == "cisco")
if ($ip && $interface) {
$new_mac = str_replace(":", "", $mac);
#echo($interface['ifDescr'] . " ($if) -> $mac ($oid) -> $ip");
if (mysql_result(mysql_query("SELECT COUNT(*) from mac_accounting WHERE port_id = '".$interface['port_id']."' AND mac = '$clean_mac'"),0)) {
if (dbFetchCell("SELECT COUNT(*) from mac_accounting WHERE port_id = ? AND mac = ?",array($interface['port_id'], $clean_mac)))
{
#$sql = "UPDATE `mac_accounting` SET `mac` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND `mac` = '$clean_mac'";
#mysql_query($sql);
#if (mysql_affected_rows()) { echo(" UPDATED!"); }
@@ -36,7 +37,7 @@ if ($device['os_group'] == "cisco")
echo(".");
} else {
#echo(" Not Exists!");
mysql_query("INSERT INTO `mac_accounting` (port_id, mac) VALUES ('".$interface['port_id']."','$clean_mac')");
dbInsert(array('port_id' => $interface['port_id'], 'mac' => $clean_mac), 'mac_accounting');
echo("+");
}
#echo("\n");

View File

@@ -27,9 +27,8 @@ if ($config['enable_pseudowires'] && $device['os_group'] == "cisco")
foreach ($pws as $pw_id => $pw)
{
list($cpw_remote_id) = explode(":", $pw['cpwVcMplsPeerLdpID']);
$cpw_remote_device = @mysql_result(mysql_query("SELECT device_id FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = '".$cpw_remote_id."' AND A.port_id = I.port_id"),0);
$if_id = @mysql_result(mysql_query("SELECT `port_id` FROM `ports` WHERE `ifDescr` = '".$pw['cpwVcName']."' AND `device_id` = '".$device['device_id']."'"),0);
$cpw_remote_device = dbFetchCell("SELECT device_id from ipv4_addresses AS A, ports AS I WHERE A.ipv4_address=? AND A.port_id=I.port_id",array($cpw_remote_id));
$if_id = dbFetchCell("SELECT port_id from ports WHERE `ifDescr`=? AND `device_id`=?",array($pw['cpwVcName'],$device['device_id']));
if (!empty($device['pws_db'][$pw['cpwVcID']]))
{
$pseudowire_id = $device['pws_db'][$pw['cpwVcID']];

View File

@@ -90,29 +90,24 @@ if ($config['enable_vrfs'])
echo "\n [VRF $vrf_name] RD - $vrf_rd";
echo "\n [VRF $vrf_name] DESC - ".$descr_table[$vrf_oid];
if (@mysql_result(mysql_query("SELECT count(*) FROM vrfs WHERE `device_id` = '".$device['device_id']."'
AND `vrf_oid`='$vrf_oid'"),0))
if (dbFetchCell("SELECT COUNT(*) FROM vrfs WHERE device_id = ? AND `vrf_oid`=?",array($device['device_id'],$vrf_oid)))
{
$update_query = "UPDATE `vrfs` SET `mplsVpnVrfDescription` = '$descr_table[$vrf_oid]', `mplsVpnVrfRouteDistinguisher` = '$vrf_rd' ";
$update_query .= "WHERE device_id = '".$device['device_id']."' AND vrf_oid = '$vrf_oid'";
mysql_query($update_query);
dbUpdate(array('mplsVpnVrfDescription' => $descr_table[$vrf_oid], 'mplsVpnVrfRouteDistinguisher' => $vrf_rd), 'vrfs', 'device_id=? AND vrf_oid=?',array($device['device_id'],$vrf_oid));
}
else
{
$insert_query = "INSERT INTO `vrfs` (`vrf_oid`,`vrf_name`,`mplsVpnVrfRouteDistinguisher`,`mplsVpnVrfDescription`,`device_id`) ";
$insert_query .= "VALUES ('$vrf_oid','$vrf_name','$vrf_rd','".$descr_table[$vrf_oid]."','".$device['device_id']."')";
mysql_query($insert_query);
dbInsert(array('`vrf_oid`' => $vrf_oid, '`vrf_name`' => $vrf_name, '`mplsVpnVrfRouteDistinguisher`' => $vrf_rd,'`mplsVpnVrfDescription`' => $descr_table[$vrf_oid], '`device_id`' => $device['device_id']), 'vrfs');
}
$vrf_id = @mysql_result(mysql_query("SELECT vrf_id FROM vrfs WHERE `device_id` = '".$device['device_id']."' AND `vrf_oid`='$vrf_oid'"),0);
$vrf_id = dbFetchCell("SELECT vrf_id FROM vrfs WHERE device_id = ? AND `vrf_oid`=?",array($device['device_id'],$vrf_oid));
$valid_vrf[$vrf_id] = 1;
echo "\n [VRF $vrf_name] PORTS - ";
foreach ($port_table[$vrf_oid] as $if_id)
{
$interface = mysql_fetch_assoc(mysql_query("SELECT * FROM ports WHERE ifIndex = '$if_id' AND device_id = '" . $device['device_id'] . "'"));
$interface = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?",array($device['device_id'],$if_id));
echo(makeshortif($interface['ifDescr']) . " ");
mysql_query("UPDATE ports SET ifVrf = '$vrf_id' WHERE port_id = '".$interface['port_id']."'");
dbUpdate(array('ifVrf' => $vrf_id), 'ports', 'port_id=?',array($interface['port_id']));
$if = $interface['port_id'];
$valid_vrf_if[$vrf_id][$if] = 1;
}
@@ -122,8 +117,7 @@ if ($config['enable_vrfs'])
echo "\n";
$sql = "SELECT * FROM ports WHERE device_id = '" . $device['device_id'] . "'";
$data = mysql_query($sql);
while ($row = mysql_fetch_assoc($data))
foreach (dbFetchRows($sql) as $row)
{
$if = $row['port_id'];
$vrf_id = $row['ifVrf'];
@@ -132,7 +126,7 @@ if ($config['enable_vrfs'])
if (!$valid_vrf_if[$vrf_id][$if])
{
echo("-");
$query = @mysql_query("UPDATE ports SET `ifVrf` = NULL WHERE port_id = '$if'");
dbUpdate(array('ifVrf' => 'NULL'), 'ports', 'port_id=?',array($if));
}
else
{
@@ -142,14 +136,13 @@ if ($config['enable_vrfs'])
}
$sql = "SELECT * FROM vrfs WHERE device_id = '" . $device['device_id'] . "'";
$data = mysql_query($sql);
while ($row = mysql_fetch_assoc($data))
foreach (dbFetchRows($sql) as $row)
{
$vrf_id = $row['vrf_id'];
if (!$valid_vrf[$vrf_id])
{
echo("-");
$query = @mysql_query("DELETE FROM vrfs WHERE vrf_id = '$vrf_id'");
dbDelete('vrfs', '`vrf_id` = ?', array($vrf_id));
}
else
{

View File

@@ -15,12 +15,12 @@ if ($device['os'] == "ironware")
unset($fdp_links);
foreach (array_keys($fdp_array) as $key)
{
$interface = mysql_fetch_assoc(mysql_query("SELECT * FROM `ports` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '".$key."'"));
$interface = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?",array($device['device_id'],$key));
$fdp_if_array = $fdp_array[$key];
foreach (array_keys($fdp_if_array) as $entry_key)
{
$fdp = $fdp_if_array[$entry_key];
$remote_device_id = @mysql_result(mysql_query("SELECT `device_id` FROM `devices` WHERE `sysName` = '".$fdp['snFdpCacheDeviceId']."' OR `hostname`='".$fdp['snFdpCacheDeviceId']."'"), 0);
$remote_device_id = dbFetchCell("SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?",array($fdp['snFdpCacheDeviceId'], $fdp['snFdpCacheDeviceId']));
if (!$remote_device_id)
{
@@ -35,7 +35,7 @@ if ($device['os'] == "ironware")
if ($remote_device_id)
{
$if = $fdp['snFdpCacheDevicePort'];
$remote_port_id = @mysql_result(mysql_query("SELECT port_id FROM `ports` WHERE (`ifDescr` = '$if' OR `ifName`='$if') AND `device_id` = '".$remote_device_id."'"),0);
$remote_port_id = dbFetchCell("SELECT port_id FROM `ports` WHERE (`ifDescr` = ? OR `ifName = ?) AND `device_id` = ?",array($if,$if,$remote_device_id));
} else { $remote_port_id = "0"; }
discover_link($interface['port_id'], $fdp['snFdpCacheVendorId'], $remote_port_id, $fdp['snFdpCacheDeviceId'], $fdp['snFdpCacheDevicePort'], $fdp['snFdpCachePlatform'], $fdp['snFdpCacheVersion']);
@@ -110,12 +110,12 @@ if ($lldp_array)
} else {
$ifIndex = $entry_key;
}
$interface = mysql_fetch_assoc(mysql_query("SELECT * FROM `ports` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '".$ifIndex."'"));
$interface = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?",array($device['device_id'],$ifIndex));
$lldp_instance = $lldp_if_array[$entry_key];
foreach (array_keys($lldp_instance) as $entry_instance)
{
$lldp = $lldp_instance[$entry_instance];
$remote_device_id = @mysql_result(mysql_query("SELECT `device_id` FROM `devices` WHERE `sysName` = '".$lldp['lldpRemSysName']."' OR `hostname`='".$lldp['lldpRemSysName']."'"), 0);
$remote_device_id = dbFetchCell("SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?",array($lldp['lldpRemSysName'], $lldp['lldpRemSysName']));
if (!$remote_device_id && is_valid_hostname($lldp['lldpRemSysName']))
{
@@ -130,7 +130,7 @@ if ($lldp_array)
if ($remote_device_id)
{
$if = $lldp['lldpRemPortDesc']; $id = $lldp['lldpRemPortId'];
$remote_port_id = @mysql_result(mysql_query("SELECT port_id FROM `ports` WHERE (`ifDescr` = '$if' OR `ifName`='$if' OR `ifDescr`= '$id' OR `ifName`='$id') AND `device_id` = '".$remote_device_id."'"),0);
$remote_port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ? OR `ifDescr` = ? OR `ifName` = ?) AND `device_id` = ?",array($if,$if,$id,$id,$remote_device_id));
} else {
$remote_port_id = "0";
}
@@ -147,9 +147,7 @@ if ($lldp_array)
if ($debug) { print_r($link_exists); }
$sql = "SELECT * FROM `links` AS L, `ports` AS I WHERE L.local_port_id = I.port_id AND I.device_id = '".$device['device_id']."'";
if ($query = mysql_query($sql))
{
while ($test = mysql_fetch_assoc($query))
foreach (dbFetchRows($sql) as $test)
{
$local_port_id = $test['local_port_id'];
$remote_hostname = $test['remote_hostname'];
@@ -158,11 +156,10 @@ if ($query = mysql_query($sql))
if (!$link_exists[$local_port_id][$remote_hostname][$remote_port])
{
echo("-");
mysql_query("DELETE FROM `links` WHERE id = '" . $test['id'] . "'");
if ($debug) { echo(mysql_affected_rows()." deleted "); }
$rows = dbDelete('links', '`id` = ?', array($test['id']));
if ($debug) { echo("$rows deleted "); }
}
}
}
unset($link_exists);
echo("\n");

View File

@@ -44,23 +44,13 @@
if ($entPhysicalDescr || $entPhysicalName)
{
$entPhysical_id = @mysql_result(mysql_query("SELECT entPhysical_id FROM `entPhysical` WHERE device_id = '".$device['device_id']."' AND entPhysicalIndex = '$entPhysicalIndex'"),0);
$entPhysical_id = dbFetchCell("SELECT entPhysical_id FROM `entPhysical` WHERE devicee_id = ? AND entPhysicalIndex = ?",array($device['device_id'], $entPhysicalIndex));
if ($entPhysical_id) {
$sql = "UPDATE `entPhysical` SET `ifIndex` = '$ifIndex'";
$sql .= ", entPhysicalIndex = '$entPhysicalIndex', entPhysicalDescr = '$entPhysicalDescr', entPhysicalClass = '$entPhysicalClass', entPhysicalName = '$entPhysicalName'";
$sql .= ", entPhysicalModelName = '$entPhysicalModelName', entPhysicalSerialNum = '$entPhysicalSerialNum', entPhysicalContainedIn = '$entPhysicalContainedIn'";
$sql .= ", entPhysicalMfgName = '$entPhysicalMfgName', entPhysicalParentRelPos = '$entPhysicalParentRelPos', entPhysicalVendorType = '$entPhysicalVendorType'";
$sql .= ", entPhysicalHardwareRev = '$entPhysicalHardwareRev', entPhysicalFirmwareRev = '$entPhysicalFirmwareRev', entPhysicalSoftwareRev = '$entPhysicalSoftwareRev'";
$sql .= ", entPhysicalIsFRU = '$entPhysicalIsFRU', entPhysicalAlias = '$entPhysicalAlias', entPhysicalAssetID = '$entPhysicalAssetID'";
$sql .= " WHERE device_id = '".$device['device_id']."' AND entPhysicalIndex = '$entPhysicalIndex'";
mysql_query($sql);
dbUpdate(array('entPhysicalIndex' => $entPhysicalIndex, 'entPhysicalDescr' => $entPhysicalDescr, 'entPhysicalClass' => $entPhysicalClass, 'entPhysicalName' => $entPhysicalName, 'entPhysicalModelName' => $entPhysicalModelName, 'entPhysicalSerialNum' => $entPhysicalSerialNum, 'entPhysicalContainedIn' => $entPhysicalContainedIn, 'entPhysicalMfgName' => $entPhysicalMfgName, 'entPhysicalParentRelPos' => $entPhysicalParentRelPos, 'entPhysicalVendorType' => $entPhysicalVendorType, 'entPhysicalHardwareRev' => $entPhysicalHardwareRev, 'entPhysicalFirmwareRev' => $entPhysicalFirmwareRev, 'entPhysicalSoftwareRev' => $entPhysicalSoftwareRev, 'entPhysicalIsFRU' => $entPhysicalIsFRU, 'entPhysicalAlias' => $entPhysicalAlias, 'entPhysicalAssetID' => $entPhysicalAssetID), 'entPhysical', 'device_id=? AND entPhysicalIndex=?',array($device['device_id'],$entPhysicalIndex));
echo(".");
} else {
$sql = "INSERT INTO `entPhysical` (`device_id` , `entPhysicalIndex` , `entPhysicalDescr` , `entPhysicalClass` , `entPhysicalName` , `entPhysicalModelName` , `entPhysicalSerialNum` , `entPhysicalContainedIn`, `entPhysicalMfgName`, `entPhysicalParentRelPos`, `entPhysicalVendorType`, `entPhysicalHardwareRev`,`entPhysicalFirmwareRev`,`entPhysicalSoftwareRev`,`entPhysicalIsFRU`,`entPhysicalAlias`,`entPhysicalAssetID`, `ifIndex`) ";
$sql .= "VALUES ( '" . $device['device_id'] . "', '$entPhysicalIndex', '$entPhysicalDescr', '$entPhysicalClass', '$entPhysicalName', '$entPhysicalModelName', '$entPhysicalSerialNum', '$entPhysicalContainedIn', '$entPhysicalMfgName','$entPhysicalParentRelPos' , '$entPhysicalVendorType', '$entPhysicalHardwareRev', '$entPhysicalFirmwareRev', '$entPhysicalSoftwareRev', '$entPhysicalIsFRU', '$entPhysicalAlias', '$entPhysicalAssetID', '$ifIndex')";
mysql_query($sql);
dbInsert(array('`device_id`' => $device['device_id'], '`entPhysicalIndex`' => $entPhysicalIndex, '`entPhysicalDescr`' => $entPhysicalDescr,'`entPhysicalClass`' => $entPhysicalClass, '`entPhysicalName`' => $entPhysicalName, '`entPhysicalModelName`' => $entPhysicalModelName, '`entPhysicalSerialNum`' => $entPhysicalSerialNum, '`entPhysicalContainedIn`' => $entPhysicalContainedIn, '`entPhysicalMfgName`' => $entPhysicalMfgName, '`entPhysicalParentRelPos`' => $entPhysicalParentRelPos, '`entPhysicalVendorType`' => $entPhysicalVendorType, '`entPhysicalHardwareRev`' => $entPhysicalHardwareRev, '`entPhysicalFirmwareRev`' => $entPhysicalFirmwareRev, '`entPhysicalSoftwareRev`' => $entPhysicalSoftwareRev, '`entPhysicalIsFRU`' => $entPhysicalIsFRU, '`entPhysicalAlias`' => $entPhysicalAlias, '`entPhysicalAssetID`' => $entPhysicalAssetID, '`ifIndex`' => $ifIndex), '`entPhysical`');
echo("+");
}
@@ -71,12 +61,12 @@
} else { echo("Disabled!"); }
$sql = "SELECT * FROM `entPhysical` WHERE `device_id` = '".$device['device_id']."'";
$query = mysql_query($sql);
while ($test = mysql_fetch_assoc($query)) {
foreach (dbFetchRows($sql) as $test)
{
$id = $test['entPhysicalIndex'];
if (!$valid[$id]) {
echo("-");
mysql_query("DELETE FROM `entPhysical` WHERE entPhysical_id = '".$test['entPhysical_id']."'");
dbDelete('`entPhysical`', '`entPhysical_id` = ?', array($test['entPhysical_id']));
}
}

View File

@@ -79,7 +79,7 @@ if (is_array($oids))
if ($current == "-127") { $thisisnotbullshit = FALSE; }
if ($thisisnotbullshit && mysql_result(mysql_query("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = '".$device['device_id']."' AND `sensor_class` = '".$type."' AND `sensor_type` = 'cisco-entity-sensor' AND `sensor_index` = '".$index."'"),0) == "0")
if ($thisisnotbullshit && dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE device_id = ? AND `sensor_class` = ? AND `sensor_type` = 'cisco-entity-sensor' AND `sensor_index` = ?",array($device['device_id'], $type,$index)) == "0")
// Check to make sure we've not already seen this sensor via cisco's entity sensor mib
{
discover_sensor($valid['sensor'], $type, $device, $oid, $index, 'entity-sensor', $descr, $divisor, $multiplier, NULL, NULL, NULL, NULL, $current);

View File

@@ -155,7 +155,7 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
if ($debug) { echo("( $inserted inserted )\n"); }
echo("+");
log_event("Sensor Added: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr), $device, 'sensor', mysql_insert_id());
log_event("Sensor Added: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr), $device, 'sensor', $inserted);
}
else
{
@@ -351,7 +351,7 @@ function discover_juniAtmVp(&$valid, $port_id, $vp_id, $vp_descr)
$inserted = dbInsert(array('port_id' => $port_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($port_id)." vp ".mres($vp_id)." descr". mres($vp_descr), 'juniAtmVp', mysql_insert_id());
log_event("Juniper ATM VP Added: port ".mres($port_id)." vp ".mres($vp_id)." descr". mres($vp_descr), 'juniAtmVp', $inserted);
}
else
{
@@ -421,21 +421,17 @@ function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $prec
if ($descr)
{
$descr = trim(str_replace("\"", "", $descr));
if (mysql_result(mysql_query("SELECT count(processor_id) FROM `processors` WHERE `processor_index` = '$index' AND `device_id` = '".$device['device_id']."' AND `processor_type` = '$type'"),0) == '0')
if (dbFetchCell("SELECT COUNT(processor_id) FROM `processors` WHERE `processor_index` = ? AND `device_id` = ? AND `processor_type` = ?",array($index,$device['device_id'], $type)) == '0')
{
$query = "INSERT INTO processors (`entPhysicalIndex`, `hrDeviceIndex`, `device_id`, `processor_descr`, `processor_index`, `processor_oid`, `processor_usage`, `processor_type`, `processor_precision`)
values ('$entPhysicalIndex', '$hrDeviceIndex', '".$device['device_id']."', '$descr', '$index', '$oid', '$current', '$type','$precision')";
mysql_query($query);
$inserted = dbInsert(array('`entPhysicalIndex`' => $entPhysicalIndex, '`hrDeviceIndex`' => $hrDeviceIndex, '`device_id`' => $device['device_id'],'`processor_descr`' => $descr, '`processor_index`' => $index, '`processor_oid`' => $oid, '`processor_usage`' => $current, '`processor_type`' => $type, '`processor_precision`' => $precision), 'processors');
if ($debug) { print $query . "\n"; }
echo("+");
log_event("Processor added: type ".mres($type)." index ".mres($index)." descr ". mres($descr), $device, 'processor', mysql_insert_id());
log_event("Processor added: type ".mres($type)." index ".mres($index)." descr ". mres($descr), $device, 'processor', $inserted);
}
else
{
echo(".");
$query = "UPDATE `processors` SET `processor_descr` = '".$descr."', `processor_oid` = '".$oid."', `processor_precision` = '".$precision."'
WHERE `device_id` = '".$device['device_id']."' AND `processor_index` = '".$index."' AND `processor_type` = '".$type."'";
mysql_query($query);
dbUpdate(array('`processor_descr`' => $descr, '`processor_oid`' => $oid, '`processor_precision`' => $precision), 'processors', '`device_id`=? AND `processor_index`=? AND `processor_type`=?',array($device['device_id'],$index,$type));
if ($debug) { print $query . "\n"; }
}
$valid[$type][$index] = 1;
@@ -449,22 +445,17 @@ function discover_mempool(&$valid, $device, $index, $type, $descr, $precision =
if ($debug) { echo("$device, $oid, $index, $type, $descr, $precision, $current, $entPhysicalIndex, $hrDeviceIndex\n"); }
if ($descr)
{
if (mysql_result(mysql_query("SELECT count(mempool_id) FROM `mempools` WHERE `mempool_index` = '$index' AND `device_id` = '".$device['device_id']."' AND `mempool_type` = '$type'"),0) == '0')
if (dbFetchCell("SELECT COUNT(mempool_id) FROM `mempools` WHERE `mempool_index` = ? AND `device_id` = ? AND `mempool_type` = ?",array($index,$device['device_id'], $type)) == '0')
{
$query = "INSERT INTO mempools (`entPhysicalIndex`, `hrDeviceIndex`, `device_id`, `mempool_descr`, `mempool_index`, `mempool_type`, `mempool_precision`)
values ('$entPhysicalIndex', '$hrDeviceIndex', '".$device['device_id']."', '$descr', '$index', '$type','$precision')";
mysql_query($query);
$inserted = dbInsert(array('`entPhysicalIndex`' => $entPhysicalIndex, '`hrDeviceIndex`' => $hrDeviceIndex, '`device_id`' => $device['device_id'],'`mempool_descr`' => $descr, '`mempool_index`' => $index, '`mempool_type`' => $type, '`mempool_precision`' => $precision), 'mempools');
if ($debug) { print $query . "\n"; }
echo("+");
log_event("Memory pool added: type ".mres($type)." index ".mres($index)." descr ". mres($descr), $device, 'mempool', mysql_insert_id());
log_event("Memory pool added: type ".mres($type)." index ".mres($index)." descr ". mres($descr), $device, 'mempool', $inserted);
}
else
{
echo(".");
$query = "UPDATE `mempools` SET `mempool_descr` = '".$descr."', `entPhysicalIndex` = '".$entPhysicalIndex."'";
$query .= ", `hrDeviceIndex` = '$hrDeviceIndex' ";
$query .= "WHERE `device_id` = '".$device['device_id']."' AND `mempool_index` = '".$index."' AND `mempool_type` = '".$type."'";
mysql_query($query);
dbUpdate(array('`mempool_descr`' => $descr, '`entPhysicalIndex`' => $entPhysicalIndex, '`hrDeviceIndex`' => $hrDeviceIndex), '`mempools`', 'device_id=? AND mempool_index=? AND mempool_type',array($device['device_id'],$index,$type));
if ($debug) { print $query . "\n"; }
}
$valid[$type][$index] = 1;
@@ -475,26 +466,25 @@ function discover_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity
{
global $config, $debug;
if ($debug) { echo("$oid, $index, $type, $descr, $capacity, $capacity_oid\n"); }
if (mysql_result(mysql_query("SELECT count(toner_id) FROM `toner` WHERE device_id = '".$device['device_id']."' AND toner_type = '$type' AND `toner_index` = '$index' AND `toner_capacity_oid` = '$capacity_oid'"),0) == '0')
if ($debug) {
echo("$oid, $index, $type, $descr, $capacity, $capacity_oid\n");
}
if (dbFetchCell("SELECT COUNT(toner_id) FROM `toner` WHERE device_id = ? AND toner_type = ? AND `toner_index` = ? AND `toner_capacity_oid` =?",array($device['device_id'], $type,$index,$capacity_oid)) == '0')
{
$query = "INSERT INTO toner (`device_id`, `toner_oid`, `toner_capacity_oid`, `toner_index`, `toner_type`, `toner_descr`, `toner_capacity`, `toner_current`) ";
$query .= " VALUES ('".$device['device_id']."', '$oid', '$capacity_oid', '$index', '$type', '$descr', '$capacity', '$current')";
mysql_query($query);
$inserted = dbInsert(array('`device_id`' => $device['device_id'], '`toner_oid`' => $oid, '`toner_capacity_oid`' => $capacity_oid, '`toner_index`' => $index, '`toner_type`' => $type, '`toner_descr`' => $descr, '`toner_capacity`' => $capacity, '`toner_current`' => $current), 'toner');
echo("+");
log_event("Toner added: type ".mres($type)." index ".mres($index)." descr ". mres($descr), $device, 'toner', mysql_insert_id());
log_event("Toner added: type ".mres($type)." index ".mres($index)." descr ". mres($descr), $device, 'toner', $inserted);
}
else
{
$toner_entry = mysql_fetch_assoc(mysql_query("SELECT * FROM `toner` WHERE device_id = '".$device['device_id']."' AND toner_type = '$type' AND `toner_index` = '$index'"));
$toner_entry = dbFetchRow("SELECT * FROM `toner` WHERE `device_id` = ? AND `toner_type` = ? AND `toner_index` =?",array($device['device_id'],$type,$index));
if ($oid == $toner_entry['toner_oid'] && $descr == $toner_entry['toner_descr'] && $capacity == $toner_entry['toner_capacity'] && $capacity_oid == $toner_entry['toner_capacity_oid'])
{
echo(".");
}
else
{
mysql_query("UPDATE toner SET `toner_descr` = '$descr', `toner_oid` = '$oid', `toner_capacity_oid` = '$capacity_oid', `toner_capacity` = '$capacity' WHERE `device_id` = '".$device['device_id']."' AND toner_type = '$type' AND `toner_index` = '$index' ");
dbUpdate(array('toner_descr' => $descr, 'toner_oid' => $oid, '`toner_capacity_oid`' => $capacity_oid, '`toner_capacity`' => $capacity), 'toner', 'device_id=? AND toner_type=? AND `toner_index`=?',array($device['device_id'],$type,$index));
echo("U");
}
}
@@ -514,29 +504,27 @@ function discover_process_ipv6(&$valid, $ifIndex,$ipv6_address,$ipv6_prefixlen,$
return;
}
if (mysql_result(mysql_query("SELECT count(*) FROM `ports`
WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1')
if (dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?",array($device['device_id'], $ifIndex)) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1')
{
$i_query = "SELECT port_id FROM `ports` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'";
$port_id = mysql_result(mysql_query($i_query), 0);
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1')
$port_id = dbFetchCell("SELECT port_id FROM `ports` WHERE device_id = ? AND ifIndex = ?",array($devices['device_id'], $ifIndex));
if (dbFetchCell("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?",array($ipv6_network)) < '1')
{
mysql_query("INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES ('$ipv6_network')");
dbInsert(array('`ipv6_network`' => $ipv6_network), 'ipv6_networks');
echo("N");
}
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1')
// Below looks like a duplicate of the above FIXME
if (dbFetchCell("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?",array($ipv6_network)) < '1')
{
mysql_query("INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES ('$ipv6_network')");
dbInsert(array('`ipv6_network`' => $ipv6_network), 'ipv6_networks');
echo("N");
}
$ipv6_network_id = @mysql_result(mysql_query("SELECT `ipv6_network_id` from `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0);
$ipv6_network_id = dbFetchCell("SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network = ?",array($ipv6_network));
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = '$ipv6_address' AND `ipv6_prefixlen` = '$ipv6_prefixlen' AND `port_id` = '$port_id'"), 0) == '0')
if (dbFetchCell("SELECT COUNT(*) FROM `ipv6_addresses WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?",array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0')
{
mysql_query("INSERT INTO `ipv6_addresses` (`ipv6_address`, `ipv6_compressed`, `ipv6_prefixlen`, `ipv6_origin`, `ipv6_network_id`, `port_id`)
VALUES ('$ipv6_address', '$ipv6_compressed', '$ipv6_prefixlen', '$ipv6_origin', '$ipv6_network_id', '$port_id')");
dbInsert(array('`ipv6_address`' => $ipv6_address, '`ipv6_compressed`' => $ipv6_compressed, '`ipv6_prefixlen`' => $ipv6_prefixlen,'`ipv6_origin`' => $ipv6_origin, '`ipv6_network_id`' => $ipv6_network_idm, '`port_id`' => $port_id), 'ipv6_addresses');
echo("+");
}
else

View File

@@ -16,26 +16,24 @@ if (is_array($hrDevices))
{
if (is_array($hrDevice) && is_numeric($hrDevice['hrDeviceIndex']))
{
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `hrDevice` WHERE device_id = '".$device['device_id']."' AND hrDeviceIndex = '".$hrDevice['hrDeviceIndex']."'"),0))
if (dbFetchCell("SELECT COUNT(*) FROM `hrDevice` WHERE device_id = ? AND hrDeviceIndex = ?",array($device['device_id'], $hrDevice['hrDeviceIndex'])))
{
$update_query = "UPDATE `hrDevice` SET";
$update_query .= " `hrDeviceType` = '".mres($hrDevice[hrDeviceType])."'";
$update_query .= ", `hrDeviceDescr` = '".mres($hrDevice[hrDeviceDescr])."'";
$update_query .= ", `hrDeviceStatus` = '".mres($hrDevice[hrDeviceStatus])."'";
$update_query .= ", `hrDeviceErrors` = '".mres($hrDevice[hrDeviceErrors])."'";
$update_array = array('`hrDeviceType`' => mres($hrDevice['hrDeviceType']),
'`hrDeviceDescr`' => mres($hrDevice['hrDeviceDescr']),
'`hrDeviceStatus`' => mres($hrDevice['hrDeviceStatus']),
'`hrDeviceErrors`' => mres($hrDevice['hrDeviceErrors']));
if ($hrDevice['hrDeviceType'] == "hrDeviceProcessor")
{
$update_query .= ", `hrProcessorLoad` = '".mres($hrDevice[hrProcessorLoad])."'";
$update_array['hrProcessorLoad'] = mres($hrDevice['hrProcessorLoad']);
}
$update_query .= " WHERE device_id = '".$device['device_id']."' AND hrDeviceIndex = '".$hrDevice['hrDeviceIndex']."'";
@mysql_query($update_query); echo(".");
dbUpdate($update_array, '`hrDevice`', 'device_id=? AND hrDeviceIndex=?',array($device['device_id'],$hrDevice['hrDeviceIndex']));
echo(".");
}
else
{
$insert_query = "INSERT INTO `hrDevice` (`hrDeviceIndex`,`device_id`,`hrDeviceType`,`hrDeviceDescr`,`hrDeviceStatus`,`hrDeviceErrors`) ";
$insert_query .= " VALUES ('".mres($hrDevice[hrDeviceIndex])."','".mres($device[device_id])."','".mres($hrDevice[hrDeviceType])."','".mres($hrDevice[hrDeviceDescr])."','".mres($hrDevice[hrDeviceStatus])."','".mres($hrDevice[hrDeviceErrors])."')";
@mysql_query($insert_query); echo("+");
if ($debug) { print_r($hrDevice); echo("$insert_query" . mysql_affected_rows() . " row inserted"); }
$inserted_rows = dbInsert(array('`hrDeviceIndex`' => mres($hrDevice['hrDeviceIndex']), '`device_id`' => mres($device['device_id']), '`hrDeviceType`' => mres($hrDevice['hrDeviceType']),'`hrDeviceDescr`' => mres($hrDevice['hrDeviceDescr']), '`hrDeviceStatus`' => mres($hrDevice['hrDeviceStatus']), '`hrDeviceErrors`' => mres($hrDevice['hrDeviceErrors'])), 'hrDevice');
echo("+");
if ($debug) { print_r($hrDevice); echo("$inserted_rows row inserted"); }
}
$valid_hrDevice[$hrDevice['hrDeviceIndex']] = 1;
}
@@ -43,14 +41,14 @@ if (is_array($hrDevices))
}
$sql = "SELECT * FROM `hrDevice` WHERE `device_id` = '".$device['device_id']."'";
$query = mysql_query($sql);
while ($test_hrDevice = mysql_fetch_assoc($query))
foreach (dbFetchRows($sql) as $test_hrDevice)
{
if (!$valid_hrDevice[$test_hrDevice['hrDeviceIndex']])
{
echo("-");
mysql_query("DELETE FROM `hrDevice` WHERE hrDevice_id = '" . $test_hrDevice['hrDevice_id'] . "'");
dbDelete('hrDevice', '`hrDevice_id` = ?', array($test_hrDevice['hrDevice_id']));
if ($debug) { print_r($test_hrDevice); echo(mysql_affected_rows() . " row deleted"); }
}
}
@@ -58,4 +56,4 @@ while ($test_hrDevice = mysql_fetch_assoc($query))
unset($valid_hrDevice);
echo("\n");
?>
?>

View File

@@ -13,23 +13,22 @@ foreach (explode("\n", $oids) as $data)
$network = $addr->network . "/" . $addr->bitmask;
$cidr = $addr->bitmask;
if (mysql_result(mysql_query("SELECT count(*) FROM `ports` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0' && $oid != "0.0.0.0" && $oid != 'ipAdEntIfIndex')
if (dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?",array($device['device_id'], $ifIndex)) != '0' && $oid != "0.0.0.0" && $oid != 'ipAdEntIfIndex')
{
$i_query = "SELECT port_id FROM `ports` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'";
$port_id = mysql_result(mysql_query($i_query), 0);
$port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex = ?",array($device['device_id'], $ifIndex));
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = '$network'"), 0) < '1')
if (dbFetchCell("SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ?",array($network)) < '1')
{
mysql_query("INSERT INTO `ipv4_networks` (`ipv4_network`) VALUES ('$network')");
dbInsert(array('`ipv4_network`' => $network), 'ipv4_networks');
#echo("Create Subnet $network\n");
echo("S");
}
$ipv4_network_id = @mysql_result(mysql_query("SELECT `ipv4_network_id` from `ipv4_networks` WHERE `ipv4_network` = '$network'"), 0);
$ipv4_network_id = dbFetchCell("SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ?",array($network));
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = '$oid' AND `ipv4_prefixlen` = '$cidr' AND `port_id` = '$port_id'"), 0) == '0')
if (dbFetchCell("SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ?",array($oid,$cidr,$port_id)) == '0')
{
mysql_query("INSERT INTO `ipv4_addresses` (`ipv4_address`, `ipv4_prefixlen`, `ipv4_network_id`, `port_id`) VALUES ('$oid', '$cidr', '$ipv4_network_id', '$port_id')");
dbInsert(array('`ipv4_address`' => $oid, '`ipv4_prefixlen`' => $cidr, '`ipv4_network_id`' => $ipv4_network_id,'`port_id`' => $port_id), 'ipv4_addresses');
#echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n");
echo("+");
} else { echo("."); }
@@ -40,19 +39,17 @@ foreach (explode("\n", $oids) as $data)
}
$sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id";
$data = mysql_query($sql);
while ($row = mysql_fetch_assoc($data))
foreach (dbFetchRows($sql) as $row)
{
$full_address = $row['ipv4_address'] . "/" . $row['ipv4_prefixlen'] . "|" . $row['ifIndex'];
if (!$valid_v4[$full_address])
{
echo("-");
$query = @mysql_query("DELETE FROM `ipv4_addresses` WHERE `ipv4_address_id` = '".$row['ipv4_address_id']."'");
if (!mysql_result(mysql_query("SELECT count(*) FROM ipv4_addresses WHERE ipv4_network_id = '".$row['ipv4_network_id']."'"),0))
$query = dbDelete('ipv4_addresses', '`ipv4_address_id` = ?', array($row['ipv4_address_id']));
if (!dbFetchCell("SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_network_id` = ?",array($row['ipv4_network_id'])))
{
$query = @mysql_query("DELETE FROM `ipv4_networks` WHERE `ipv4_network_id` = '".$row['ipv4_network_id']."'");
$query = dbDelete('`ipv4_networks`', '`ipv4_network_id` = ?', array($row['ipv4_network_id']));
}
}
}
@@ -61,4 +58,4 @@ echo("\n");
unset($valid_v4);
?>
?>

View File

@@ -59,9 +59,8 @@ if (!$oids)
} // if $oids
$sql = "SELECT * FROM ipv6_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id";
$data = mysql_query($sql);
while ($row = mysql_fetch_assoc($data))
foreach (dbFetchRows($sql) as $row)
{
$full_address = $row['ipv6_address'] . "/" . $row['ipv6_prefixlen'];
$port_id = $row['port_id'];
@@ -69,10 +68,10 @@ while ($row = mysql_fetch_assoc($data))
if (!$valid['ipv6'][$valid_address])
{
echo("-");
$query = @mysql_query("DELETE FROM `ipv6_addresses` WHERE `ipv6_address_id` = '".$row['ipv6_address_id']."'");
if (!mysql_result(mysql_query("SELECT count(*) FROM ipv6_addresses WHERE ipv6_network_id = '".$row['ipv6_network_id']."'"),0))
$query = dbDelete('ipv6_addresses', '`ipv6_address_id` = ?', array($row['ipv6_address_id']));
if (!dbFetchCell("SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_network_id` = ?",array($row['ipv6_network_id'])))
{
$query = @mysql_query("DELETE FROM `ipv6_networks` WHERE `ipv6_network_id` = '".$row['ipv6_network_id']."'");
$query = dbDelete('ipv6_networks', '`ipv6_network_id` = ?', array($row['ipv6_network_id']));
}
}
}

View File

@@ -17,7 +17,7 @@ if ($device['os'] == "junose" && $config['enable_ports_junoseatmvp'])
{
list($ifIndex,$vp_id)= explode('.', $index);
$port_id = mysql_result(mysql_query("SELECT `port_id` FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '".$ifIndex."'"),0);
$port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?",array($device['device_id'], $ifIndex));
if (is_numeric($port_id) && is_numeric($vp_id))
{
@@ -31,11 +31,10 @@ if ($device['os'] == "junose" && $config['enable_ports_junoseatmvp'])
// Remove ATM vps which weren't redetected here
$sql = "SELECT * FROM `ports` AS P, `juniAtmVp` AS J WHERE P.`device_id` = '".$device['device_id']."' AND J.port_id = P.port_id";
$query = mysql_query($sql);
if ($debug) { print_r ($valid_vp); }
while ($test = mysql_fetch_assoc($query))
foreach (dbFetchRows($sql) as $test)
{
$port_id = $test['port_id'];
$vp_id = $test['vp_id'];
@@ -43,7 +42,7 @@ if ($device['os'] == "junose" && $config['enable_ports_junoseatmvp'])
if (!$valid_vp[$port_id][$vp_id])
{
echo("-");
mysql_query("DELETE FROM `juniAtmvp` WHERE `juniAtmVp` = '" . $test['juniAtmvp'] . "'");
dbDelete('juniAtmvp', '`juniAtmVp` = ?', array($test['juniAtmvp']));
}
unset($port_id); unset($vp_id);
@@ -53,4 +52,4 @@ if ($device['os'] == "junose" && $config['enable_ports_junoseatmvp'])
echo("\n");
}
?>
?>

View File

@@ -76,23 +76,20 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == "linux" )
$vmwVmCpus = $xml->vcpu;
# Check whether the Virtual Machine is already known for this host.
$result = mysql_query("SELECT * FROM vminfo WHERE device_id = '" . $device["device_id"] . "' AND vmwVmVMID = '" . $dom_id . "' AND vm_type='libvirt'");
if (mysql_num_rows($result) == 0)
$result = dbFetchRow("SELECT * FROM `vminfo` WHERE `device_id` = ? AND `vmwVmVMID` = ? AND `vm_type` = 'libvirt'",array($device['device_id'],$dom_id));
if (count($result['device_id']) == 0)
{
mysql_query("INSERT INTO vminfo (device_id, vm_type, vmwVmVMID, vmwVmDisplayName, vmwVmGuestOS, vmwVmMemSize, vmwVmCpus, vmwVmState) VALUES (" . $device["device_id"] . ", 'libvirt',
'" . $dom_id . "', '" . mres($vmwVmDisplayName) . "', '" . mres($vmwVmGuestOS) . "', '" . $vmwVmMemSize . "', '" . $vmwVmCpus . "', '" . mres($vmwVmState) . "')");
$inserted_id = dbInsert(array('`device_id`' => $device['device_id'], '`vm_type`' => 'libvirt', '`vmwVmVMID`' => $dom_id,'`vmwVmDisplayName`' => mres($vmwVmDisplayName), '`vmwVmGuestOS`' => mres($vmwVmGuestOS), '`vmwVmMemSize`' => mres($vmwVmMemSize), '`vmwVmCpus`' => mres($vmwVmCpus), '`vmwVmState`' => mres($vmwVmState)), 'vminfo');
echo("+");
log_event("Virtual Machine added: $vmwVmDisplayName ($vmwVmMemSize MB)", $device, 'vm', mysql_insert_id());
log_event("Virtual Machine added: $vmwVmDisplayName ($vmwVmMemSize MB)", $device, 'vm', $inserted_id);
} else {
$row = mysql_fetch_assoc($result);
if ($row['vmwVmState'] != $vmwVmState
|| $row['vmwVmDisplayName'] != $vmwVmDisplayName
|| $row['vmwVmCpus'] != $vmwVmCpus
|| $row['vmwVmGuestOS'] != $vmwVmGuestOS
|| $row['vmwVmMemSize'] != $vmwVmMemSize)
if ($result['vmwVmState'] != $vmwVmState
|| $result['vmwVmDisplayName'] != $vmwVmDisplayName
|| $result['vmwVmCpus'] != $vmwVmCpus
|| $result['vmwVmGuestOS'] != $vmwVmGuestOS
|| $result['vmwVmMemSize'] != $vmwVmMemSize)
{
mysql_query("UPDATE vminfo SET vmwVmState='" . mres($vmwVmState) . "', vmwVmGuestOS='" . mres($vmwVmGuestOS) . "', vmwVmDisplayName='". mres($vmwVmDisplayName) . "',
vmwVmMemSize='" . mres($vmwVmMemSize) . "', vmwVmCpus='" . mres($vmwVmCpus) . "' WHERE device_id='" . $device["device_id"] . "' AND vm_type='libvirt' AND vmwVmVMID='" . $dom_id . "'");
dbUpdate(array('vmwVmState' => mres($vmwVmState), '`vmwVmGuestOS' => mres($vmwVmGuestOS), '`vmwVmDisplayName`' => mres($vmwVmDisplayName), '`vmwVmMemSize`' => mres($vmwVmMemSize), '`vmwVmCpus`' => mres($vmwVmCpus)), 'vminfo', "device_id=? AND vm_type='libvirt' AND vmwVmVMID=?",array($device['device_id'],$dom_id));
echo("U");
// FIXME eventlog
}
@@ -113,15 +110,15 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == "linux" )
}
# Get a list of all the known Virtual Machines for this host.
$db_vm_list = mysql_query("SELECT id, vmwVmVMID, vmwVmDisplayName FROM vminfo WHERE device_id = '" . $device["device_id"] . "' AND vm_type='libvirt'");
$sql = "SELECT id, vmwVmVMID, vmwVmDisplayName FROM vminfo WHERE device_id = '" . $device["device_id"] . "' AND vm_type='libvirt'";
while ($db_vm = mysql_fetch_assoc($db_vm_list))
foreach (dbFetchRows($sql) as $db_vm)
{
# Delete the Virtual Machines that are removed from the host.
if (!in_array($db_vm["vmwVmVMID"], $libvirt_vmlist))
{
mysql_query("DELETE FROM vminfo WHERE id = '" . $db_vm["id"] . "'");
dbDelete('vminfo', '`id` = ?', array($db_vm['id']));
echo("-");
log_event("Virtual Machine removed: " . $db_vm['vmwVmDisplayName'], $device, 'vm', $db_vm['id']);
}
@@ -130,4 +127,4 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == "linux" )
echo("\n");
}
?>
?>

View File

@@ -10,11 +10,10 @@ include("includes/include-dir.inc.php");
// Remove memory pools which weren't redetected here
$sql = "SELECT * FROM `mempools` WHERE `device_id` = '".$device['device_id']."'";
$query = mysql_query($sql);
if ($debug) { print_r ($valid_mempool); }
while ($test_mempool = mysql_fetch_assoc($query))
foreach (dbFetchRows($sql) as $test_mempool)
{
$mempool_index = $test_mempool['mempool_index'];
$mempool_type = $test_mempool['mempool_type'];
@@ -23,7 +22,7 @@ while ($test_mempool = mysql_fetch_assoc($query))
if (!$valid_mempool[$mempool_type][$mempool_index])
{
echo("-");
mysql_query("DELETE FROM `mempools` WHERE mempool_id = '" . $test_mempool['mempool_id'] . "'");
dbDelete('mempools', '`mempool_id` = ?', array($test_mempool['mempool_id']));
}
unset($mempool_oid); unset($mempool_type);

View File

@@ -2,7 +2,7 @@
// Ignore this discovery module if we have already discovered things in CISCO-ENHANCED-MEMPOOL-MIB. Dirty duplication.
$cemp_count = mysql_result(mysql_query("SELECT COUNT(*) FROM `mempools` WHERE `device_id` = '".$device['device_id']."' AND `mempool_type` = 'cemp'"),0);
$cemp_count = dbFetchCell("SELECT COUNT(*) FROM `mempools` WHERE `device_id` = ? AND `mempool_type` = 'cemp'",array($device['device_id']));
if (($device['os_group'] == "cisco") && $cemp_count == "0")
{

View File

@@ -1,13 +1,16 @@
<?php
// MYSQL Check - FIXME
// 1 UPDATE
$os = getHostOS($device);
if ($os != $device['os'])
{
$sql = mysql_query("UPDATE `devices` SET `os` = '$os' WHERE `device_id` = '".$device['device_id']."'");
$sql = dbUpdate(array('`os`' => $os), 'devices', 'device_id=?',array($device['device_id']));
echo("Changed OS! : $os\n");
log_event("Device OS changed ".$device['os']." => $os", $device, 'system');
$device['os'] = $os;
}
?>
?>

View File

@@ -3,8 +3,8 @@
echo("Port Stack: ");
$sql = "SELECT * FROM `ports_stack` WHERE `device_id` = '".$device['device_id']."'";
$query = mysql_query($sql);
while ($entry = mysql_fetch_assoc($query))
foreach (dbFetchRows($sql) as $entry)
{
$stack_db_array[$entry['port_id_high']][$entry['port_id_low']]['ifStackStatus'] = $entry['ifStackStatus'];
}
@@ -22,13 +22,13 @@ foreach ($stack_poll_array as $port_id_high => $entry_high)
{
echo(".");
} else {
mysql_query("UPDATE `ports_stack` SET `ifStackStatus` = '".$ifStackStatus."' WHERE `device_id` = '".$device['device_id']."' AND `port_id_high` = '".$port_id_high."' AND `port_id_low` = '".$port_id_low."'");
dbUpdate(array('`ifStackStatus`' => $ifStackStatus), 'ports_stack', 'device_id=? AND port_id_high=? AND `port_id_low`=?',array($device['device_id'],$port_id_high,$port_id_low));
echo("U");
if ($debug) { echo(mysql_error()); }
}
unset($stack_db_array[$port_id_high][$port_id_low]);
} else {
mysql_query("INSERT INTO `ports_stack` (`device_id`,`port_id_high`,`port_id_low`,`ifStackStatus`) VALUES ('".$device['device_id']."','".$port_id_high."','".$port_id_low."','".$ifStackStatus."')");
dbInsert(array('`device_id`' => $device['device_id'], '`port_id_high`' => $port_id_high, '`port_id_low`' => $port_id_low,'`ifStackStatus`' => $ifStackStatus), 'ports_stack');
echo("+");
if ($debug) { echo(mysql_error()); }
}

View File

@@ -1,6 +1,6 @@
<?php
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM processors WHERE device_id = '".$device['device_id']."' AND processor_type != 'ucd-old'"),0);
$count = dbFetchCell("SELECT COUNT(*) FROM `processors` WHERE `device_id` = ? AND `processor_type` != 'ucd-old'",array($device['device_id']));
if ($device['os_group'] == "unix" && $count == "0")
{

View File

@@ -14,11 +14,10 @@ include("processors-ucd-old.inc.php");
// Remove processors which weren't redetected here
$sql = "SELECT * FROM `processors` WHERE `device_id` = '".$device['device_id']."'";
$query = mysql_query($sql);
if ($debug) { print_r ($valid['processor']); }
while ($test_processor = mysql_fetch_assoc($query))
foreach (dbFetchRows($sql) as $test_processor)
{
$processor_index = $test_processor['processor_index'];
$processor_type = $test_processor['processor_type'];
@@ -26,7 +25,7 @@ while ($test_processor = mysql_fetch_assoc($query))
if (!$valid['processor'][$processor_type][$processor_index])
{
echo("-");
mysql_query("DELETE FROM `processors` WHERE processor_id = '" . $test_processor['processor_id'] . "'");
dbDelete('Processors', '`processor_id` = ?', array($test_processor['processor_id']));
log_event("Processor removed: type ".$processor_type." index ".$processor_index." descr ". $test_processor['processor_descr'], $device, 'processor', $test_processor['processor_id']);
}
unset($processor_oid); unset($processor_type);

View File

@@ -1,6 +1,6 @@
<?php
if ($device['os'] == "screenos" && mysql_result(mysql_query("SELECT COUNT(*) FROM processors WHERE device_id = '".$device['device_id']."' AND processor_type != 'screenos'"),0) == "0")
if ($device['os'] == "screenos" && dbFetchCell("SELECT COUNT(*) FROM `processors` WHERE `device_id` = ? AND `processor_type` != 'screenos'",array($device['device_id'])) == "0")
{
# .1.3.6.1.4.1.3224.16.1.3.0 Cpu Last 5 Minutes
# discover_processor(&$valid, $device, $oid, $index, $type, $descr, $precision = "1", $current = NULL, $entPhysicalIndex = NULL, $hrDeviceIndex = NULL)

View File

@@ -10,11 +10,10 @@ include("includes/include-dir.inc.php");
// Remove storage which weren't redetected here
$sql = "SELECT * FROM `storage` WHERE `device_id` = '".$device['device_id']."'";
$query = mysql_query($sql);
if ($debug) { print_r ($valid_storage); }
while ($test_storage = mysql_fetch_assoc($query))
foreach (dbFetchRows($sql) as $test_storage)
{
$storage_index = $test_storage['storage_index'];
$storage_mib = $test_storage['storage_mib'];
@@ -23,7 +22,7 @@ while ($test_storage = mysql_fetch_assoc($query))
if (!$valid_storage[$storage_mib][$storage_index])
{
echo("-");
mysql_query("DELETE FROM `storage` WHERE storage_id = '" . $test_storage['storage_id'] . "'");
dbDelete('storage', '`storage_id` = ?', array($test_storage['storage_id']));
}
unset($storage_index); unset($storage_mib);

View File

@@ -1,4 +1,10 @@
<?php
// MYSQL Check - FIXME
// 5 SELECTS
// 4 INSERTS
// 4 UPDATES
/*
Disabled needing rewrite

View File

@@ -2,7 +2,7 @@
// FIXME - dbFacile and fewer SNMP_GETs
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = '".$device['device_id']."' AND `sensor_class` = 'temperature' AND (`sensor_type` = 'cisco-entity-sensor' OR `sensor_type` = 'entity-sensor')"),0) == "0" && ($device['os_group'] == "cisco"))
if (dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ? AND `sensor_class` = 'temperature' AND (`sensor_type` = 'cisco-entity-sensor' OR `sensor_type` = 'entity-sensor'",array($device['device_id'])) == "0" && ($device['os_group'] == "cisco"))
{
echo("CISCO-ENVMON-MIB: ");
$oids = snmp_walk($device, ".1.3.6.1.4.1.9.9.13.1.3.1.2", "-Osqn", "CISCO-ENVMON-MIB");

View File

@@ -49,21 +49,18 @@ if ($config['enable_printers'])
if ($debug) { echo("\n Checking ... \n"); print_r($valid_toner); }
$sql = "SELECT * FROM toner WHERE device_id = '".$device['device_id']."'";
if ($query = mysql_query($sql))
{
while ($test_toner = mysql_fetch_assoc($query))
foreach (dbFetchRows($sql) as $test_toner)
{
$toner_index = $test_toner['toner_index'];
$toner_type = $test_toner['toner_type'];
if (!$valid_toner[$toner_type][$toner_index])
{
echo("-");
mysql_query("DELETE FROM `toner` WHERE toner_id = '" . $test_toner['toner_id'] . "'");
dbDelete('toner', '`toner_id` = ?', array($test_toner['toner_id']));
}
}
}
unset($valid_toner); echo("\n");
} # if ($config['enable_printers'])
?>
?>

View File

@@ -13,11 +13,11 @@ if (is_array($diskio_array))
{
if ($debug) { echo("$index ".$entry['diskIODevice']."\n"); }
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ucd_diskio` WHERE `device_id` = '".$device['device_id']."' AND `diskio_index` = '".$index."'"),0) == "0")
if (dbFetchCell("SELECT COUNT(*) FROM `ucd_diskio` WHERE `device_id` = ? AND `diskio_index` = ?",array($device['device_id'], $index)) == "0")
{
$sql = "INSERT INTO `ucd_diskio` (`device_id`,`diskio_index`,`diskio_descr`) VALUES ('".$device['device_id']."','".$index."','".$entry['diskIODevice']."')";
mysql_query($sql); echo("+");
if ($debug) { echo($sql . " - " . mysql_affected_rows() . "inserted "); }
$inserted = dbInsert(array('`device_id`' => $device['device_id'], '`diskio_index`' => $index, '`diskio_descr`' => $entry['diskIODevice']), 'ucd_diskio');
echo("+");
if ($debug) { echo($sql . " - $inserted inserted "); }
}
else
{
@@ -33,17 +33,16 @@ if (is_array($diskio_array))
// Remove diskio entries which weren't redetected here
$sql = "SELECT * FROM `ucd_diskio` where `device_id` = '".$device['device_id']."'";
$query = mysql_query($sql);
if ($debug) { print_r ($valid_diskio); }
while ($test = mysql_fetch_assoc($query))
foreach (dbFetchRows($sql) as $test)
{
if ($debug) { echo($test['diskio_index'] . " -> " . $test['diskio_descr'] . "\n"); }
if (!$valid_diskio[$test['diskio_index']])
{
echo("-");
mysql_query("DELETE FROM `ucd_diskio` WHERE `diskio_id` = '" . $test['diskio_id'] . "'");
dbDelete('ucd_diskio', '`diskio_id` = ?', array($test['diskio_id']));
}
}

View File

@@ -72,9 +72,9 @@ if (($device['os'] == "vmware") || ($device['os'] == "linux"))
* Check whether the Virtual Machine is already known for this host.
*/
if (mysql_result(mysql_query("SELECT COUNT(id) FROM vminfo WHERE device_id = '" . $device["device_id"] . "' AND vmwVmVMID = '" . $oid . "' AND vm_type='vmware'"), 0) == 0)
if (dbFetchCell("SELECT COUNT(id) FROM `vminfo` WHERE `device_id` = ? AND `vmwVmVMID` = ? AND vm_type='vmware'",array($device['device_id'], $oid)) == 0)
{
mysql_query("INSERT INTO vminfo (device_id, vm_type, vmwVmVMID, vmwVmDisplayName, vmwVmGuestOS, vmwVmMemSize, vmwVmCpus, vmwVmState) VALUES (" . $device["device_id"] . ",'vmware', " . $oid . ", '" . mres($vmwVmDisplayName) . "', '" . mres($vmwVmGuestOS) . "', " . $vmwVmMemSize . ", " . $vmwVmCpus . ", '" . mres($vmwVmState) . "')");
dbInsert(array('`device_id`' => $device['device_id'], '`vm_type`' => 'vmware', '`vmwVmVMID`' => $oid,'`vmwVmDisplayName`' => mres($vmwVmDisplayName), '`vmwVmGuestOS`' => mres($vmwVmGuestOS), '`vmwVmMemSize`' => mres($vmwVmMemSize), '`vmwVmCpus`' => mres($vmwVmCpus), '`vmwVmState`' => mres($vmwVmState)), 'vminfo');
echo("+");
// FIXME eventlog
} else {
@@ -94,9 +94,9 @@ if (($device['os'] == "vmware") || ($device['os'] == "linux"))
* Get a list of all the known Virtual Machines for this host.
*/
$db_vm_list = mysql_query("SELECT id, vmwVmVMID FROM vminfo WHERE device_id = '" . $device["device_id"] . "' AND vm_type='vmware'");
$sql = "SELECT id, vmwVmVMID FROM vminfo WHERE device_id = '" . $device["device_id"] . "' AND vm_type='vmware'";
while ($db_vm = mysql_fetch_assoc($db_vm_list))
foreach (dbFetchRows($sql) as $db_vm)
{
/*
* Delete the Virtual Machines that are removed from the host.
@@ -104,7 +104,7 @@ if (($device['os'] == "vmware") || ($device['os'] == "linux"))
if (!in_array($db_vm["vmwVmVMID"], $vmw_vmlist))
{
mysql_query("DELETE FROM vminfo WHERE id = '" . $db_vm["id"] . "'");
dbDelete('vminfo', '`id` = ?', array($db_vm['id']));
echo("-");
// FIXME eventlog
}
@@ -117,4 +117,4 @@ if (($device['os'] == "vmware") || ($device['os'] == "linux"))
echo("\n");
}
?>
?>

View File

@@ -1,6 +1,6 @@
<?php
$interface = mysql_fetch_assoc(mysql_query("SELECT * FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '".$entry[2]."'"));
$interface = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?",array($device['device_id'],$entry[2]));
if (!$interface) { exit; }
@@ -16,7 +16,7 @@ log_event("SNMP Trap: linkDown " . $interface['ifDescr'], $device, "interface",
if ($ifOperStatus != $interface['ifOperStatus'])
{
log_event("Interface went Down : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['port_id']);
mysql_query("UPDATE `ports` SET ifOperStatus = 'down' WHERE `port_id` = '".$interface['port_id']."'");
dbUpdate(array('`ifOperStatus`' => 'down'), 'ports', 'port_id=?',array($interface['port_id']));
}
?>
?>

View File

@@ -1,6 +1,6 @@
<?php
$interface = mysql_fetch_assoc(mysql_query("SELECT * FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '".$entry[2]."'"));
$interface = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?",array($device['device_id'],$entry[2]));
if (!$interface) { exit; }
@@ -12,14 +12,13 @@ log_event("SNMP Trap: linkUp $ifAdminStatus/$ifOperStatus " . $interface['ifDesc
if ($ifAdminStatus != $interface['ifAdminStatus'])
{
log_event("Interface Enabled : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['port_id']);
mysql_query("UPDATE `ports` SET ifAdminStatus = 'up' WHERE `port_id` = '".$interface['port_id']."'");
dbUpdate(array('`ifAdminStatus`' => 'up'), 'ports', 'port_id=?',array($interface['port_id']));
}
if ($ifOperStatus != $interface['ifOperStatus'])
{
log_event("Interface went Up : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['port_id']);
mysql_query("UPDATE `ports` SET ifOperStatus = 'up' WHERE `port_id` = '".$interface['port_id']."'");
dbUpdate(array('`ifOperStatus`' => 'up'), 'ports', 'port_id=?',array($interface['port_id']));
}
?>
?>

View File

@@ -1,5 +1,8 @@
<?php
// MYSQL Check - FIXME
// 1 UNKNOWN
/* Observium Network Management and Monitoring System
* Copyright (C) 2006-2012, Observium Developers - http://www.observium.org
*

View File

@@ -1,6 +1,9 @@
#!/usr/bin/php
<?php
// MYSQL Check - FIXME
// 1 UNKNOWN
### This script requires php-cli and php-mysql packages
# ============================================================================

View File

@@ -1,5 +1,8 @@
<?php
// MYSQL Check - FIXME
// 1 UNKNOWN
# ============================================================================
# This is a script to retrieve information from a MySQL server for input to a
# Cacti graphing process. It is hosted at

View File

@@ -1,6 +1,9 @@
#!/usr/bin/env php
<?php
// MYSQL Check - FIXME
// 1 UPDATE
include("config.php");
include("includes/functions.php");
@@ -24,4 +27,4 @@ else
echo("ERROR: Could not open file \"$argv[1]\".\n");
}
?>
?>

View File

@@ -1,5 +1,10 @@
<?php
// MYSQL Check - FIXME
// 1 DROP
// 1 CREATE
// 25 ALTERS
include("includes/defaults.inc.php");
include("config.php");

View File

@@ -1,5 +1,10 @@
<?php
// MYSQL Check - FIXME
// 3 ALTERS
// 1 SELECT
// 1 UPDATE
mysql_query("ALTER TABLE `eventlog` DROP `id`");
mysql_query("ALTER TABLE `eventlog` ADD `event_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
@@ -17,4 +22,4 @@ while ($event = mysql_fetch_assoc($q))
mysql_query("ALTER TABLE `eventlog` DROP `interface`");
?>
?>