$devices_used = $Tools->fetch_multiple_objects("devices", "snmp_queries", "%get_routing_table%", "id", true, true);
# recolaculate ids for info
foreach ($devices_used as $d) {
    $devices_info[$d->id] = $d;
}
// if none set die
if ($devices_used === false) {
    $Result->show("danger", "No devices for SNMP route table query available" . "!", true, $ajax_loaded);
}
// ok, we have devices, connect to each device and do query
foreach ($devices_used as $d) {
    // init
    $Snmp->set_snmp_device($d);
    // execute
    try {
        $res = $Snmp->get_query("get_routing_table");
        // remove those not in subnet
        if (sizeof($res) > 0) {
            // save for debug
            $debug[$d->hostname][$q] = $res;
            // save result
            $found[$d->id]["get_vlan_table"] = $res;
        }
    } catch (Exception $e) {
        // save for debug
        $debug[$d->hostname]["get_vlan_table"] = $res;
        $errors[] = $e->getMessage();
    }
}
# none and errors
if (sizeof($found) == 0 && isset($errors)) {
示例#2
0
        }
    }
}
// if none set die
if (!isset($scan_devices)) {
    $Result->show("danger", _("No devices for SNMP VRF query available"), true);
}
// init result array
$new_vrfs = array();
// ok, we have devices, connect to each device and do query
foreach ($scan_devices as $d) {
    // init
    $Snmp->set_snmp_device($d);
    // fetch arp table
    try {
        $res = $Snmp->get_query("get_vrf_table");
        // remove those not in subnet
        if (sizeof($res) > 0) {
            // save for debug
            $debug[$d->hostname]["get_vrf_table"] = $res;
            // loop and save
            foreach ($res as $k => $r) {
                if (!array_key_exists($k, $new_vrfs) && !array_key_exists($k, $ex_vrfs)) {
                    $new_vrfs[$k] = $r;
                }
            }
        }
    } catch (Exception $e) {
        // save for debug
        $debug[$d->hostname]["get_vrf_table"] = $res;
        $errors[] = $e->getMessage();
    }
}
// if none set die
if (!isset($permitted_devices_arp)) {
    $Result->show("danger", _("No devices for SNMP ARP query available"), true);
}
if (!isset($permitted_devices_mac)) {
    $Result->show("danger", _("No devices for SNMP MAC address query available"), true);
}
// first we need ARP table to fetchIP <> MAC mappings
foreach ($permitted_devices_arp as $d) {
    // init
    $Snmp->set_snmp_device($d);
    // fetch arp table
    try {
        $res = $Snmp->get_query("get_arp_table");
        // remove those not in subnet
        if (sizeof($res) > 0) {
            // save for debug
            $debug[$d->hostname]["get_arp_table"] = $res;
            // check
            foreach ($res as $kr => $r) {
                // if is inside subnet
                if ($Subnets->is_subnet_inside_subnet($r['ip'] . "/32", $Subnets->transform_address($subnet->subnet, "dotted") . "/" . $subnet->mask) === false) {
                } elseif (in_array($r['ip'], $subnet_ip_addresses)) {
                } else {
                    $found_arp[] = $r;
                }
            }
        }
    } catch (Exception $e) {
示例#4
0
        }
    }
}
// if none set die
if (!isset($scan_devices)) {
    $Result->show("danger", _("No devices for SNMP VLAN query available"), true);
}
// init result array
$new_vlans = array();
// ok, we have devices, connect to each device and do query
foreach ($scan_devices as $d) {
    // init
    $Snmp->set_snmp_device($d);
    // fetch arp table
    try {
        $res = $Snmp->get_query("get_vlan_table");
        // remove those not in subnet
        if (sizeof($res) > 0) {
            // save for debug
            $debug[$d->hostname]["get_vlan_table"] = $res;
            // loop and save
            foreach ($res as $k => $r) {
                if (!array_key_exists($k, $new_vlans) && !array_key_exists($k, $ex_vlans)) {
                    $new_vlans[$k] = $r;
                }
            }
        }
    } catch (Exception $e) {
        // save for debug
        $debug[$d->hostname]["get_vlan_table"] = $res;
        $errors[] = $e->getMessage();
示例#5
0
            $queries[] = substr($k, 6);
        }
    }
}
# fake as device queries
$device->snmp_queries = implode(";", $queries);
# open connection
if (isset($queries)) {
    // set device
    $Snmp->set_snmp_device($device);
    // loop
    foreach ($queries as $query) {
        try {
            // overrides for MAC table query - we need to test with some vlan number, so we need vlan first
            if ($query == "get_mac_table") {
                $Snmp->get_query("get_vlan_table");
                if (is_array($Snmp->last_result)) {
                    foreach ($Snmp->last_result as $k => $r) {
                        if (is_numeric($k)) {
                            // ok, we have vlan, set query
                            $Snmp->set_snmp_device($device, $k);
                            try {
                                $Snmp->get_query($query);
                                $vlan_set = true;
                                break;
                            } catch (Exception $e) {
                            }
                        }
                    }
                }
            } else {
        if (in_array($subnet->sectionId, $permitted_sections)) {
            $permitted_devices[] = $d;
        }
    }
}
// if none set die
if (!isset($permitted_devices)) {
    $Result->show("danger", _("No devices for SNMP ARP query available"), true);
}
// ok, we have devices, connect to each device and do query
foreach ($permitted_devices as $d) {
    // init
    $Snmp->set_snmp_device($d);
    // fetch arp table
    try {
        $res = $Snmp->get_query("get_arp_table");
        // remove those not in subnet
        if (sizeof($res) > 0) {
            // save for debug
            $debug[$d->hostname]["get_arp_table"] = $res;
            // check
            foreach ($res as $kr => $r) {
                // if is inside subnet
                if ($Subnets->is_subnet_inside_subnet($r['ip'] . "/32", $Subnets->transform_address($subnet->subnet, "dotted") . "/" . $subnet->mask) === false) {
                } elseif (in_array($r['ip'], $subnet_ip_addresses)) {
                } else {
                    $found[$d->id][] = $r;
                }
            }
        }
        // get interfaces