Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent error with multiple proxmox #9770

Merged
merged 1 commit into from
Feb 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 35 additions & 31 deletions includes/polling/applications/proxmox.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,45 @@

use LibreNMS\RRD\RrdDefinition;

/**
* Check if a port on a Proxmox VM exists
* @param string $p Port name
* @param string $c Clustername
* @param integer $i VM ID
* @return integer|boolean The port-ID if the port exists, false if it doesn't exist
*/
function proxmox_port_exists($i, $c, $p)
{
if ($row = dbFetchRow("SELECT pmp.id FROM proxmox_ports pmp, proxmox pm WHERE pm.id = pmp.vm_id AND pmp.port = ? AND pm.cluster = ? AND pm.vmid = ?", array($p, $c, $i))) {
return $row['id'];
}
if (!function_exists('proxmox_port_exists')) {
/**
* Check if a port on a Proxmox VM exists
* @param string $p Port name
* @param string $c Clustername
* @param integer $i VM ID
* @return integer|boolean The port-ID if the port exists, false if it doesn't exist
*/
function proxmox_port_exists($i, $c, $p)
{
if ($row = dbFetchRow("SELECT pmp.id FROM proxmox_ports pmp, proxmox pm WHERE pm.id = pmp.vm_id AND pmp.port = ? AND pm.cluster = ? AND pm.vmid = ?", [$p, $c, $i])) {
return $row['id'];
}

return false;
return false;
}
}

/**
* Check if a Proxmox VM exists
* @param integer $i VM ID
* @param string $c Clustername
* @param array $pmxcache Reference to the Proxmox VM Cache
* @return boolean true if the VM exists, false if it doesn't
*/
function proxmox_vm_exists($i, $c, &$pmxcache)
{

if (isset($pmxcache[$c][$i]) && $pmxcache[$c][$i] > 0) {
return true;
}
if ($row = dbFetchRow("SELECT id FROM proxmox WHERE vmid = ? AND cluster = ?", array($i, $c))) {
$pmxcache[$c][$i] = (integer) $row['id'];
return true;
}
if (!function_exists('proxmox_vm_exists')) {
/**
* Check if a Proxmox VM exists
* @param integer $i VM ID
* @param string $c Clustername
* @param array $pmxcache Reference to the Proxmox VM Cache
* @return boolean true if the VM exists, false if it doesn't
*/
function proxmox_vm_exists($i, $c, &$pmxcache)
{

if (isset($pmxcache[$c][$i]) && $pmxcache[$c][$i] > 0) {
return true;
}
if ($row = dbFetchRow("SELECT id FROM proxmox WHERE vmid = ? AND cluster = ?", [$i, $c])) {
$pmxcache[$c][$i] = (integer)$row['id'];
return true;
}

return false;
return false;
}
}

$name = 'proxmox';
Expand Down