Index: html/pages/front/default.php
===================================================================
--- html/pages/front/default.php (revision 5223)
+++ html/pages/front/default.php (working copy)
@@ -368,24 +368,21 @@
// FIXME - This is not how we do port types.
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);
unset ($seperator);
- while ($interface = mysql_fetch_assoc($query)) {
+ foreach (dbFetchRows("SELECT * FROM ports as I, devices as D WHERE `ifAlias` LIKE 'Transit:%' AND I.device_id = D.device_id AND I.deleted = 0 ORDER BY I.ifAlias") 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);
unset ($seperator);
- while ($interface = mysql_fetch_assoc($query)) {
+ foreach (dbFetchRows("SELECT * FROM ports as I, devices as D WHERE `ifAlias` LIKE 'Peering:%' AND I.device_id = D.device_id AND I.deleted = 0 ORDER BY I.ifAlias") 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);
unset ($seperator);
- while ($interface = mysql_fetch_assoc($query)) {
+ foreach (dbFetchRows("SELECT * FROM ports as I, devices as D WHERE `ifAlias` LIKE 'Core:%' AND I.device_id = D.device_id AND I.deleted = 0 ORDER BY I.ifAlias") as $interface)
+ {
$ports['core'] .= $seperator . $interface['port_id'];
$seperator = ",";
}
Index: includes/discovery/libvirt-vminfo.inc.php
===================================================================
--- includes/discovery/libvirt-vminfo.inc.php (revision 5223)
+++ includes/discovery/libvirt-vminfo.inc.php (working copy)
@@ -76,25 +76,19 @@
$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)
+ if (dbFetchCell("SELECT COUNT(`id`) FROM `vminfo` WHERE `device_id` = ? AND `vmwVmVMID` = ? AND `vm_type` = 'libvirt'", array($device['device_id'], $dom_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) . "')");
+ $libvirt_insert = array('device_id' => $device['device_id'], 'vm_type' => 'libvirt', 'vmwVmVMID' => $dom_id, 'vmwVmDisplayName' => $vmwVmDisplayName, 'vmwVmGuestOS' => $vmwVmGuestOS, 'vmwVmMemSize' => $vmwVmMemSize, 'vmwVmCpus' => $vmwVmCpus, 'vmwVmState' => $vmwVmState);
+ $inserted = dbInsert($libvirt_insert, '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);
if (is_valid_hostname($vmwVmDisplayName) && $vmwVmState == 'Running') { discover_new_device($vmwVmDisplayName, 'libvirt'); }
} else {
- $row = mysql_fetch_assoc($result);
- if ($row['vmwVmState'] != $vmwVmState
- || $row['vmwVmDisplayName'] != $vmwVmDisplayName
- || $row['vmwVmCpus'] != $vmwVmCpus
- || $row['vmwVmGuestOS'] != $vmwVmGuestOS
- || $row['vmwVmMemSize'] != $vmwVmMemSize)
+ $libvirt = dbFetchRow("SELECT * FROM `vminfo` WHERE `device_id` = ? AND `vmwVmVMID` = ? AND `vm_type` = 'libvirt'", array($device['device_id'], $dom_id));
+ if ($libvirt['vmwVmState'] != $vmwVmState || $libvirt['vmwVmDisplayName'] != $vmwVmDisplayName || $libvirt['vmwVmCpus'] != $vmwVmCpus || $libvirt['vmwVmGuestOS'] != $vmwVmGuestOS || $libvirt['vmwVmMemSize'] != $vmwVmMemSize)
{
- /// FIXME dbFacile
- 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 . "'");
+ $update = array('vmwVmState' => $vmwVmState, 'vmwVmGuestOS' => $vmwVmGuestOS, 'vmwVmDisplayName' => $vmwVmDisplayName,'vmwVmMemSize' => $vmwVmMemSize,'vmwVmCpus' => $vmwVmCpus);
+ dbUpdate($update, 'vminfo', 'device_id = ? AND vm_type = \'libvirt\' AND vmwVmVMID = ?', array($device['device_id'], $dom_id));
echo("U");
/// FIXME eventlog changed fields
}
@@ -115,21 +109,19 @@
}
# 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'");
-
- while ($db_vm = mysql_fetch_assoc($db_vm_list))
+ foreach (dbFetchRows("SELECT id, vmwVmVMID, vmwVmDisplayName FROM `vminfo` WHERE `device_id` = ? AND `vm_type` = 'libvirt'", array($device['device_id'])) as $db_vm)
{
# Delete the Virtual Machines that are removed from the host.
- if (!in_array($db_vm["vmwVmVMID"], $libvirt_vmlist))
+ 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']);
}
}
- echo("\n");
+ echo(PHP_EOL);
}
-?>
+// EOF
Index: includes/discovery/sensors/entity-sensor-mib.inc.php
===================================================================
--- includes/discovery/sensors/entity-sensor-mib.inc.php (revision 5223)
+++ includes/discovery/sensors/entity-sensor-mib.inc.php (working copy)
@@ -118,7 +118,7 @@
# have a flag value for "the device has no limit for this sensor".
}
- 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, $lowlimit, $lowwarn, $highwarn, $highlimit, $current);