コード例 #1
0
function fetchBackendPortList($sql_where_clause, $query_params = array())
{
    $query = <<<END
SELECT
\tPort.id,
\tPort.name,
\tPort.object_id,
\tObject.name AS object_name,
\tPort.l2address,
\tPort.label,
\tPort.reservation_comment,
\tPort.iif_id,
\tPort.type AS oif_id,
\t(SELECT PortInnerInterface.iif_name FROM PortInnerInterface WHERE PortInnerInterface.id = Port.iif_id) AS iif_name,
\t(SELECT Dictionary.dict_value FROM Dictionary WHERE Dictionary.dict_key = Port.type) AS oif_name,
\tIF(lba.porta, lba.cable, lbb.cable) AS cableid,
\tIF(lba.porta, pa.id, pb.id) AS remote_id,
\tIF(lba.porta, pa.name, pb.name) AS remote_name,
\tIF(lba.porta, pa.object_id, pb.object_id) AS remote_object_id,
\tIF(lba.porta, oa.name, ob.name) AS remote_object_name,
\t(SELECT COUNT(*) FROM PortLog WHERE PortLog.port_id = Port.id) AS log_count,
\tPortLog.user,
\tUNIX_TIMESTAMP(PortLog.date) as time
FROM
\tPort
\tINNER JOIN Object ON Port.object_id = Object.id
\tLEFT JOIN LinkBackend AS lba ON lba.porta = Port.id
\tLEFT JOIN Port AS pa ON pa.id = lba.portb
\tLEFT JOIN Object AS oa ON pa.object_id = oa.id
\tLEFT JOIN LinkBackend AS lbb on lbb.portb = Port.id
\tLEFT JOIN Port AS pb ON pb.id = lbb.porta
\tLEFT JOIN Object AS ob ON pb.object_id = ob.id
\tLEFT JOIN PortLog ON PortLog.id = (SELECT id FROM PortLog WHERE PortLog.port_id = Port.id ORDER BY date DESC LIMIT 1)
WHERE
\t{$sql_where_clause}
END;
    $result = usePreparedSelectBlade($query, $query_params);
    $ret = array();
    while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
        $row['l2address'] = l2addressFromDatabase($row['l2address']);
        $row['linked'] = isset($row['remote_id']) ? 1 : 0;
        // last changed log
        $row['last_log'] = array();
        if ($row['log_count']) {
            $row['last_log']['user'] = $row['user'];
            $row['last_log']['time'] = $row['time'];
        }
        unset($row['user']);
        unset($row['time']);
        $ret[] = $row;
    }
    return $ret;
}
コード例 #2
0
ファイル: snmp.php プロジェクト: xtha/salt
function generatePortsForCatModule($object_id, $slotno = 1, $mtype = 'X6748', $mac_address = '')
{
    global $dbxlink;
    $mac_address = l2addressFromDatabase(l2addressForDatabase($mac_address));
    switch ($mtype) {
        case 'WS-X6748-GE-TX':
            $dbxlink->beginTransaction();
            for ($i = 1; $i <= 48; $i++) {
                commitAddPort($object_id, "gi{$slotno}/{$i}", '1-24', "slot {$slotno} port {$i}", $mac_address);
                $mac_address = nextMACAddress($mac_address);
            }
            $dbxlink->commit();
            break;
        case 'WS-X6708-10GE':
            for ($i = 1; $i <= 8; $i++) {
                commitAddPort($object_id, "te{$slotno}/{$i}", '6-1080', "slot {$slotno} port {$i}", $mac_address);
                $mac_address = nextMACAddress($mac_address);
            }
            break;
        case 'WS-X6704-10GE':
            for ($i = 1; $i <= 4; $i++) {
                commitAddPort($object_id, "te{$slotno}/{$i}", '5-1079', "slot {$slotno} port {$i}", $mac_address);
                $mac_address = nextMACAddress($mac_address);
            }
            break;
        case 'VS-S720-10G':
            commitAddPort($object_id, "gi{$slotno}/1", '4-1077', "slot {$slotno} port 1", $mac_address);
            $mac_address = nextMACAddress($mac_address);
            commitAddPort($object_id, "gi{$slotno}/2", '4-1077', "slot {$slotno} port 2", $mac_address);
            $mac_address = nextMACAddress($mac_address);
            commitAddPort($object_id, "gi{$slotno}/3", '1-24', "slot {$slotno} port 3", $mac_address);
            $mac_address = nextMACAddress($mac_address);
            commitAddPort($object_id, "te{$slotno}/4", '6-1080', "slot {$slotno} port 4", $mac_address);
            $mac_address = nextMACAddress($mac_address);
            commitAddPort($object_id, "te{$slotno}/5", '6-1080', "slot {$slotno} port 5", $mac_address);
            break;
        case '3750G-24TS':
            // MAC address of 1st port is the next one after switch's address
            $mac_address = nextMACAddress($mac_address);
            for ($i = 1; $i <= 24; $i++) {
                commitAddPort($object_id, "gi{$slotno}/0/{$i}", '1-24', "unit {$slotno} port {$i}", $mac_address);
                $mac_address = nextMACAddress($mac_address);
            }
            for ($i = 25; $i <= 28; $i++) {
                commitAddPort($object_id, "gi{$slotno}/0/{$i}", '4-1077', "unit {$slotno} port {$i}", $mac_address);
                $mac_address = nextMACAddress($mac_address);
            }
            break;
        case '3750G-24T':
            $mac_address = nextMACAddress($mac_address);
            for ($i = 1; $i <= 24; $i++) {
                commitAddPort($object_id, "gi{$slotno}/0/{$i}", '1-24', "unit {$slotno} port {$i}", $mac_address);
                $mac_address = nextMACAddress($mac_address);
            }
            break;
        case '3750G-16TD':
            $mac_address = nextMACAddress($mac_address);
            for ($i = 1; $i <= 16; $i++) {
                commitAddPort($object_id, "gi{$slotno}/0/{$i}", '1-24', "unit {$slotno} port {$i}", $mac_address);
                $mac_address = nextMACAddress($mac_address);
            }
            commitAddPort($object_id, "te{$slotno}/0/1", '5-1079', "unit {$slotno} port {$i}", $mac_address);
            break;
        case 'LE02G48TA':
            for ($i = 0; $i <= 47; $i++) {
                commitAddPort($object_id, "gi{$slotno}/0/{$i}", '1-24', "slot {$slotno} port {$i}", $mac_address);
            }
            break;
        case 'LE02X12SA':
            for ($i = 0; $i <= 11; $i++) {
                commitAddPort($object_id, "gi{$slotno}/0/{$i}", '9-1084', "slot {$slotno} port {$i}", $mac_address);
            }
            break;
    }
}