$Subnets = new Subnets($Database);
$Addresses = new Addresses($Database);
$Tools = new Tools($Database);
$Result = new Result();
# fetch all subnets
$all_subnets = $Tools->fetch_all_objects("subnets");
# loop and check usage for each, make sure it does not have any parent
foreach ($all_subnets as $k => $s) {
    // marked as full should not be checked
    if ($s->isFull != 1) {
        // parent check
        if (!$Subnets->has_slaves($s->id)) {
            // count number of addresses
            $cnt = $Addresses->count_subnet_addresses($s->id);
            // calculate usage
            $usage = $Subnets->calculate_subnet_usage($cnt, $s->mask, $s->subnet, $s->isFull);
            // if more than $threshold report
            if ($usage['freehosts_percent'] < 100 - $limit) {
                // this subnet has high usage, save it to array
                $out[$k]['subnet'] = $Subnets->transform_address($s->subnet, "dotted") . "/" . $s->mask;
                $out[$k]['description'] = $s->description;
                $out[$k]['usage'] = $usage;
            }
        }
    }
}
# any fount
if (isset($out)) {
    // do something with output
    print_r($out);
}
# initialize objects
$Database = new Database_PDO();
$Subnets = new Subnets($Database);
$Addresses = new Addresses($Database);
$Tools = new Tools($Database);
$Result = new Result();
# fetch all subnets
$all_subnets = $Tools->fetch_all_objects("subnets");
# loop and check usage for each, make sure it does not have any parent
foreach ($all_subnets as $k => $s) {
    // marked as full should not be checked
    if ($s->isFull != 1) {
        // parent check
        if (!$Subnets->has_slaves($s->id)) {
            // calculate usage
            $usage = $Subnets->calculate_subnet_usage($s);
            // if more than $threshold report
            if ($usage['freehosts_percent'] < 100 - $limit) {
                // this subnet has high usage, save it to array
                $out[$k]['subnet'] = $Subnets->transform_address($s->subnet, "dotted") . "/" . $s->mask;
                $out[$k]['description'] = $s->description;
                $out[$k]['usage'] = $usage;
            }
        }
    }
}
# any fount
if (isset($out)) {
    // do something with output
    print_r($out);
}
Beispiel #3
0
         // save count
         $addresses_cnt = gmp_strval(sizeof($addresses));
         # full ?
         if (sizeof($slave_subnets) > 0) {
             foreach ($slave_subnets as $ss) {
                 if ($ss->isFull == 1) {
                     # calculate max
                     $max_hosts = $Subnets->get_max_hosts($ss->mask, $Subnets->identify_address($ss->subnet), true);
                     # count
                     $count_hosts = $Addresses->count_subnet_addresses($ss->id);
                     # add
                     $addresses_cnt = gmp_strval(gmp_add($addresses_cnt, gmp_sub($max_hosts, $count_hosts)));
                 }
             }
         }
         $subnet_usage = $Subnets->calculate_subnet_usage($addresses_cnt, $s->mask, $s->subnet, $s->isFull);
         //Calculate free/used etc
     } else {
         # fetch addresses in subnet
         $addresses_cnt = $Addresses->count_subnet_addresses($s->id);
         # calculate usage
         $subnet_usage = $Subnets->calculate_subnet_usage($addresses_cnt, $s->mask, $s->subnet, $s->isFull);
     }
     # set additional threshold parameters
     $subnet_usage['usedhosts_percent'] = gmp_strval(gmp_sub(100, (int) round($subnet_usage['freehosts_percent'], 0)));
     $subnet_usage['until_threshold'] = gmp_strval(gmp_sub($s->threshold, $subnet_usage['usedhosts_percent']));
     # save
     $out[$k]->usage = (object) $subnet_usage;
 }
 // reorder - highest usage to lowest
 foreach ($out as $k => $v) {
Beispiel #4
0
    print "<blockquote style='margin-top:20px;margin-left:20px;'>";
    print "<p>" . _("No subnet is selected for threshold check") . "</p>";
    print "<small>" . _("You can set threshold for subnets under subnet settings") . "</small>";
    print "</blockquote>";
} elseif (!isset($out)) {
    print "<hr>";
    print "<blockquote style='margin-top:20px;margin-left:20px;'>";
    print "<p>" . _("No subnet selected for threshold check available") . "</p>";
    print "<small>" . _("No subnet with threshold check available") . "</small>";
    print "</blockquote>";
} else {
    print "<div class='hContent' style='padding:10px;'>";
    // count usage
    foreach ($out as $k => $s) {
        // calculate usage
        $subnet_usage = $Subnets->calculate_subnet_usage($s, false);
        //Calculate free/used etc
        # set additional threshold parameters
        $subnet_usage['usedhosts_percent'] = gmp_strval(gmp_sub(100, (int) round($subnet_usage['freehosts_percent'], 0)));
        $subnet_usage['until_threshold'] = gmp_strval(gmp_sub($s->threshold, $subnet_usage['usedhosts_percent']));
        # save
        $out[$k]->usage = (object) $subnet_usage;
    }
    // reorder - highest usage to lowest
    foreach ($out as $k => $v) {
        $used[$k] = $v->usage->usedhosts_percent;
    }
    array_multisort($used, SORT_DESC, $out);
    // table
    print "<table class='table table-threshold table-noborder'>";
    // print
Beispiel #5
0
         print "\t<td><a href='" . create_link("subnets", $f['sectionId'], $f['subnetId']) . "'><i class='fa fa-sfolder fa-sitemap' ></i>" . $Subnets->transform_to_dotted($f['subnet']) . "/{$f['mask']}</a></td>";
     }
 }
 print "\t<td>{$f['description']}</td>";
 print "\t<td><a href='" . create_link("subnets", $f['sectionId']) . "'>{$f['section']}</a></td>";
 # get vlan info
 if (strlen($f['vlanId']) > 0 && $f['vlanId'] != 0) {
     $vlan = $Tools->fetch_object("vlans", "vlanId", $f['vlanId']);
     print "\t<td>{$vlan->number}</td>";
 } else {
     print "\t<td>/</td>";
 }
 # usage
 if (!$master) {
     $address_count = $Addresses->count_subnet_addresses($f['subnetId']);
     $subnet_usage = $Subnets->calculate_subnet_usage(gmp_strval($address_count), $f['mask'], $f['subnet']);
 }
 # add address
 if ($master === true || $f['isFolder'] == 1 || $Subnets->reformat_number($subnet_usage['freehosts']) == "0") {
     $disabled = "disabled";
 } else {
     $disabled = "";
 }
 # remove
 print "\t<td class='actions'>";
 print "\t<div class='btn-group'>";
 print "\t<a class='btn btn-xs btn-default modIPaddr btn-success {$disabled}' href='' data-container='body' rel='tooltip' title='" . _('Add new IP address') . "' data-subnetId='{$f['subnetId']}' data-action='add' data-id=''><i class='fa fa-plus'></i></a>";
 print "\t<a class='btn btn-xs btn-default editFavourite' data-subnetId='{$f['subnetId']}' data-action='remove' data-from='widget'><i class='fa fa-star favourite-{$f['subnetId']}' rel='tooltip' title='" . _('Click to remove from favourites') . "'></i></a>";
 print "\t</div>";
 print " </td>";
 print "</tr>";