当前位置: 首页>>代码示例>>PHP>>正文


PHP Subnets::calculate_subnet_usage方法代码示例

本文整理汇总了PHP中Subnets::calculate_subnet_usage方法的典型用法代码示例。如果您正苦于以下问题:PHP Subnets::calculate_subnet_usage方法的具体用法?PHP Subnets::calculate_subnet_usage怎么用?PHP Subnets::calculate_subnet_usage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Subnets的用法示例。


在下文中一共展示了Subnets::calculate_subnet_usage方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Subnets

$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);
}
开发者ID:korhaldragonir,项目名称:phpipam,代码行数:31,代码来源:find_full_subnets.php

示例2: Subnets

# 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);
}
开发者ID:routenull0,项目名称:phpipam,代码行数:31,代码来源:find_full_subnets.php

示例3: foreach

         // 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) {
开发者ID:korhaldragonir,项目名称:phpipam,代码行数:31,代码来源:threshold.php

示例4: elseif

    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
开发者ID:routenull0,项目名称:phpipam,代码行数:31,代码来源:threshold.php

示例5:

         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>";
开发者ID:netbuild,项目名称:phpipam,代码行数:31,代码来源:favourite_subnets.php


注:本文中的Subnets::calculate_subnet_usage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。